coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
image.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <agesa_headers.h>
4 #include <amdblocks/image.h>
5 #include <types.h>
6 
7 /* Check if the image has the desired module. */
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  * Find an image that has the desired module. The image is aligned within
26  * a given range.
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  /* Check if the image has the desired module */
41  if (validate_image((void *)image_ptr->ModuleInfoOffset,
42  name))
43  return current_ptr;
44  }
45  current_ptr += alignment;
46  }
47  return NULL;
48 }
#define IMAGE_SIGNATURE
Definition: Amd.h:34
const char * name
Definition: mmu.c:92
static bool validate_image(void *module_chain, const char module_signature[8])
Definition: image.c:8
void * amd_find_image(const void *start_address, const void *end_address, uint32_t alignment, const char name[8])
Definition: image.c:28
#define NULL
Definition: stddef.h:19
unsigned int uint32_t
Definition: stdint.h:14
unsigned long long uint64_t
Definition: stdint.h:17
unsigned char uint8_t
Definition: stdint.h:8
AGESA Binary module header structure.
Definition: Amd.h:87
IN unsigned int ModuleInfoOffset
Offset of module.
Definition: Amd.h:91
AGESA Binary module header structure.
Definition: Amd.h:102
IN signed char ModuleIdentifier[8]
8 characters ID
Definition: Amd.h:104
IN unsigned int ModuleHeaderSignature
Module signature.
Definition: Amd.h:103