soc: Remove copyright notices
[coreboot.git] / src / soc / amd / common / block / pi / image.c
blob38a20898cb69cde9e02edf53dcb11a1aa13240e5
1 /*
2 * This file is part of the coreboot project.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <agesa_headers.h>
16 #include <amdblocks/image.h>
18 /* Check if the image has the desired module. */
19 static bool validate_image(void *module_chain, const char module_signature[8])
21 AMD_MODULE_HEADER *mod_ptr = (AMD_MODULE_HEADER *)module_chain;
22 uint64_t signature = *(uint64_t *)module_signature;
23 char *checking_str;
25 while ((mod_ptr != NULL) &&
26 (MODULE_SIGNATURE == *(uint32_t *)&mod_ptr->ModuleHeaderSignature)) {
27 checking_str = (char *)&mod_ptr->ModuleIdentifier;
28 if (signature == *(uint64_t *)checking_str)
29 return true;
30 mod_ptr = (AMD_MODULE_HEADER *)mod_ptr->NextBlock;
32 return false;
36 * Find an image that has the desired module. The image is aligned within
37 * a given range.
39 void *amd_find_image(const void *start_address, const void *end_address,
40 uint32_t alignment, const char name[8])
42 uint8_t *current_ptr = (uint8_t *)start_address;
43 uint8_t *start = (uint8_t *)start_address;
44 uint8_t *end = (uint8_t *)end_address;
45 AMD_IMAGE_HEADER *image_ptr;
47 while ((current_ptr >= start) && (current_ptr < end)) {
48 if (IMAGE_SIGNATURE == *((uint32_t *)current_ptr)) {
49 image_ptr = (AMD_IMAGE_HEADER *) current_ptr;
51 /* Check if the image has the desired module */
52 if (validate_image((void *)image_ptr->ModuleInfoOffset,
53 name))
54 return current_ptr;
56 current_ptr += alignment;
58 return NULL;