| 1 |
|
| 2 |
|
| 3 |
#include <agesa_headers.h> |
| 4 |
#include <amdblocks/image.h> |
| 5 |
#include <types.h> |
| 6 |
|
| 7 |
|
| 8 |
static bool validate_image(void *module_chain, const char module_signature[8]) |
| 9 |
{ |
| 10 |
AMD_MODULE_HEADER *mod_ptr = (AMD_MODULE_HEADER *)module_chain; |
| 11 |
uint64_t signature = *(uint64_t *)module_signature; |
| 12 |
char *checking_str; |
| 13 |
|
| 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) |
| 18 |
return true; |
| 19 |
mod_ptr = (AMD_MODULE_HEADER *)mod_ptr->NextBlock; |
| 20 |
} |
| 21 |
return false; |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
void *amd_find_image(const void *start_address, const void *end_address, |
| 29 |
uint32_t alignment, const char name[8]) |
| 30 |
{ |
| 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; |
| 35 |
|
| 36 |
while ((current_ptr >= start) && (current_ptr < end)) { |
| 37 |
if (IMAGE_SIGNATURE == *((uint32_t *)current_ptr)) { |
| 38 |
image_ptr = (AMD_IMAGE_HEADER *)current_ptr; |
| 39 |
|
| 40 |
|
| 41 |
if (validate_image((void *)image_ptr->ModuleInfoOffset, |
| 42 |
name)) |
| 43 |
return current_ptr; |
| 44 |
} |
| 45 |
current_ptr += alignment; |
| 46 |
} |
| 47 |
return NULL; |
| 48 |
} |