1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <agesa_headers.h>
4 #include <amdblocks/image.h>
7 /* Check if the image has the desired module. */
8 static bool validate_image(void *module_chain
, const char module_signature
[8])
10 AMD_MODULE_HEADER
*mod_ptr
= (AMD_MODULE_HEADER
*)module_chain
;
11 uint64_t signature
= *(uint64_t *)module_signature
;
14 while ((mod_ptr
!= NULL
) &&
15 (MODULE_SIGNATURE
== *(uint32_t *)&mod_ptr
->ModuleHeaderSignature
)) {
16 checking_str
= (char *)&mod_ptr
->ModuleIdentifier
;
17 if (signature
== *(uint64_t *)checking_str
)
19 mod_ptr
= (AMD_MODULE_HEADER
*)mod_ptr
->NextBlock
;
25 * Find an image that has the desired module. The image is aligned within
28 void *amd_find_image(const void *start_address
, const void *end_address
,
29 uint32_t alignment
, const char name
[8])
31 uint8_t *current_ptr
= (uint8_t *)start_address
;
32 uint8_t *start
= (uint8_t *)start_address
;
33 uint8_t *end
= (uint8_t *)end_address
;
34 AMD_IMAGE_HEADER
*image_ptr
;
36 while ((current_ptr
>= start
) && (current_ptr
< end
)) {
37 if (IMAGE_SIGNATURE
== *((uint32_t *)current_ptr
)) {
38 image_ptr
= (AMD_IMAGE_HEADER
*)current_ptr
;
40 /* Check if the image has the desired module */
41 if (validate_image((void *)image_ptr
->ModuleInfoOffset
,
45 current_ptr
+= alignment
;