summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorMarshall Dawson <marshalldawson3rd@gmail.com>2019-03-04 16:52:07 -0700
committerMartin Roth <martinroth@google.com>2019-03-07 16:02:10 +0000
commita378c22f77a127abb9bf0532bd37fa072732b85b (patch)
treee3af39d280dc874ba212fdd27c13e6c53e5d877e /util
parent0e02ce83a1080f6740177b1a26cdd88b39baf083 (diff)
util/amdfwtool: Combine table header population
Rename psp_fill_head() and call it with the cookie to populate the header. The combo header and PSP directory header are similar and should be calculated the same way. Change-Id: I7e634542de65576addadbe683596cbe572de3dcd Signed-off-by: Marshall Dawson <marshalldawson3rd@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/31732 Reviewed-by: Martin Roth <martinroth@google.com> Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'util')
-rw-r--r--util/amdfwtool/amdfwtool.c48
1 files changed, 26 insertions, 22 deletions
diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c
index 58069d30c1..774eefef52 100644
--- a/util/amdfwtool/amdfwtool.c
+++ b/util/amdfwtool/amdfwtool.c
@@ -294,17 +294,32 @@ typedef struct _psp_combo_directory {
psp_combo_entry entries[];
} __attribute__((packed)) psp_combo_directory;
-static void fill_psp_head(psp_directory_table *pspdir, uint32_t count)
+static void fill_dir_header(void *directory, uint32_t count, uint32_t cookie)
{
- pspdir->header.cookie = PSP_COOKIE;
- pspdir->header.num_entries = count;
- pspdir->header.reserved = 0;
- /* checksum everything that comes after the Checksum field */
- pspdir->header.checksum = fletcher32(
- (void *)&pspdir->header.num_entries,
+ if (cookie == PSP2_COOKIE) {
+ /* caller is responsible for lookup mode */
+ psp_combo_directory *cdir = directory;
+ cdir->header.cookie = cookie;
+ cdir->header.num_entries = count;
+ cdir->header.reserved[0] = 0;
+ cdir->header.reserved[1] = 0;
+ /* checksum everything that comes after the Checksum field */
+ cdir->header.checksum = fletcher32(&cdir->header.num_entries,
+ count * sizeof(psp_combo_entry)
+ + sizeof(cdir->header.num_entries)
+ + sizeof(cdir->header.lookup)
+ + 2 * sizeof(cdir->header.reserved[0]));
+ } else {
+ psp_directory_table *dir = directory;
+ dir->header.cookie = cookie;
+ dir->header.num_entries = count;
+ dir->header.reserved = 0;
+ /* checksum everything that comes after the Checksum field */
+ dir->header.checksum = fletcher32(&dir->header.num_entries,
count * sizeof(psp_directory_entry)
- + sizeof(pspdir->header.num_entries)
- + sizeof(pspdir->header.reserved));
+ + sizeof(dir->header.num_entries)
+ + sizeof(dir->header.reserved));
+ }
}
static uint32_t integrate_firmwares(char *base, uint32_t pos,
@@ -434,7 +449,7 @@ static uint32_t integrate_psp_firmwares(char *base, uint32_t pos,
/* This APU doesn't have this firmware. */
}
}
- fill_psp_head(pspdir, count);
+ fill_dir_header(pspdir, count, PSP_COOKIE);
return pos;
}
@@ -690,19 +705,8 @@ int main(int argc, char **argv)
combo_dir->entries[0].id = 0x10220B00;
combo_dir->entries[0].lvl2_addr = current + rom_base_address;
- /* fill the PSP combo head */
- combo_dir->header.cookie = PSP2_COOKIE;
- combo_dir->header.num_entries = 1;
combo_dir->header.lookup = 1;
- combo_dir->header.reserved[0] = 0;
- combo_dir->header.reserved[1] = 0;
- combo_dir->header.checksum = fletcher32(
- (void *)&combo_dir->header.num_entries,
- 1 * sizeof(psp_directory_entry)
- + sizeof(combo_dir->header.num_entries)
- + sizeof(combo_dir->header.lookup)
- + sizeof(combo_dir->header.reserved[0])
- + sizeof(combo_dir->header.reserved[1]));
+ fill_dir_header(combo_dir, 1, PSP2_COOKIE);
#endif
pspdir = (void *)(rom + current);