From b46bd95ccdec355d446b3fd49ace89710cb4d6f2 Mon Sep 17 00:00:00 2001 From: Zheng Bao Date: Fri, 5 Apr 2024 18:33:02 +0800 Subject: [PATCH] amdfwtool: Set the fields when the header is created The fields spi_block_size and base_addr of regular PSP header, lookup and reserved of combo header, are constants. So we move the setting statements to the creation functions. Only update the count, size and fletcher in later function file_dir_header. TEST=Binary identical test on all AMD SOC platforms Change-Id: I55c400e45536a57841b01d7c90d3fef9afa53e78 Signed-off-by: Zheng Bao Reviewed-on: https://review.coreboot.org/c/coreboot/+/84130 Tested-by: build bot (Jenkins) Reviewed-by: Felix Held --- util/amdfwtool/amdfwtool.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c index 7ed13c9764..434e4523ec 100644 --- a/util/amdfwtool/amdfwtool.c +++ b/util/amdfwtool/amdfwtool.c @@ -492,6 +492,8 @@ static void *new_psp_dir(context *ctx, int multi, uint32_t cookie) ((psp_directory_header *)ptr)->num_entries = 0; ((psp_directory_header *)ptr)->additional_info = 0; ((psp_directory_header *)ptr)->additional_info_fields.address_mode = ctx->address_mode; + ((psp_directory_header *)ptr)->additional_info_fields.spi_block_size = 1; + ((psp_directory_header *)ptr)->additional_info_fields.base_addr = 0; adjust_current_pointer(ctx, sizeof(psp_directory_header) + MAX_PSP_ENTRIES * sizeof(psp_directory_entry), 1); @@ -515,6 +517,11 @@ static void *new_combo_dir(context *ctx, uint32_t cookie) adjust_current_pointer(ctx, 0, TABLE_ALIGNMENT); ptr = BUFF_CURRENT(*ctx); ((psp_combo_header *)ptr)->cookie = cookie; + /* lookup mode is hardcoded for now. */ + ((psp_combo_header *)ptr)->lookup = 1; + ((psp_combo_header *)ptr)->reserved[0] = 0; + ((psp_combo_header *)ptr)->reserved[1] = 0; + adjust_current_pointer(ctx, sizeof(psp_combo_header) + MAX_COMBO_ENTRIES * sizeof(psp_combo_entry), 1); @@ -541,11 +548,7 @@ static void fill_dir_header(void *directory, uint32_t count, context *ctx) switch (cookie) { case PSP2_COOKIE: case BHD2_COOKIE: - /* lookup mode is hardcoded for now. */ - cdir->header.lookup = 1; 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) @@ -569,8 +572,6 @@ static void fill_dir_header(void *directory, uint32_t count, context *ctx) table_size / TABLE_ALIGNMENT; } dir->header.num_entries = count; - dir->header.additional_info_fields.spi_block_size = 1; - dir->header.additional_info_fields.base_addr = 0; /* checksum everything that comes after the Checksum field */ dir->header.checksum = fletcher32(&dir->header.num_entries, count * sizeof(psp_directory_entry) @@ -591,8 +592,6 @@ static void fill_dir_header(void *directory, uint32_t count, context *ctx) table_size / TABLE_ALIGNMENT; } bdir->header.num_entries = count; - bdir->header.additional_info_fields.spi_block_size = 1; - bdir->header.additional_info_fields.base_addr = 0; /* checksum everything that comes after the Checksum field */ bdir->header.checksum = fletcher32(&bdir->header.num_entries, count * sizeof(bios_directory_entry) @@ -600,7 +599,6 @@ static void fill_dir_header(void *directory, uint32_t count, context *ctx) + sizeof(bdir->header.additional_info)); break; } - } static void fill_psp_directory_to_efs(embedded_firmware *amd_romsig, void *pspdir, @@ -1132,6 +1130,8 @@ static void *new_bios_dir(context *ctx, bool multi, uint32_t cookie) ((bios_directory_hdr *) ptr)->cookie = cookie; ((bios_directory_hdr *) ptr)->additional_info = 0; ((bios_directory_hdr *) ptr)->additional_info_fields.address_mode = ctx->address_mode; + ((bios_directory_hdr *) ptr)->additional_info_fields.spi_block_size = 1; + ((bios_directory_hdr *) ptr)->additional_info_fields.base_addr = 0; adjust_current_pointer(ctx, sizeof(bios_directory_hdr) + MAX_BIOS_ENTRIES * sizeof(bios_directory_entry), 1);