Attention is currently required from: Zheng Bao.
Hello Zheng Bao,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/84338?usp=email
to review the following change.
Change subject: amdfwtool: Check fletcher of each header ......................................................................
amdfwtool: Check fletcher of each header
Change-Id: Ie7540386027c6449317e9b7c0b4fd22d09d4a3a3 Signed-off-by: Zheng Bao fishbaozi@gmail.com --- M util/amdfwtool/amdfwtool.c 1 file changed, 91 insertions(+), 10 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/38/84338/1
diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c index b43d374..f2116f3 100644 --- a/util/amdfwtool/amdfwtool.c +++ b/util/amdfwtool/amdfwtool.c @@ -527,6 +527,55 @@ memcpy(bak, orig, count * sizeof(bios_directory_entry) + sizeof(psp_directory_table)); }
+static bool check_dir_header(void *directory) +{ + psp_combo_directory *cdir = directory; + psp_directory_table *dir = directory; + bios_directory_table *bdir = directory; + ish_directory_table *ish = directory; + /* The cookies have same offsets. */ + uint32_t cookie = ((psp_directory_table *)directory)->header.cookie; + uint32_t count; + bool fletcher_match = false; + + /* Empty */ + if (directory == NULL) + return false; + + switch (cookie) { + case PSP2_COOKIE: + case BHD2_COOKIE: + count = cdir->header.num_entries; + fletcher_match = 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])); + break; + case PSP_COOKIE: + case PSPL2_COOKIE: + count = dir->header.num_entries; + fletcher_match = dir->header.checksum == fletcher32(&dir->header.num_entries, + count * sizeof(psp_directory_entry) + + sizeof(dir->header.num_entries) + + sizeof(dir->header.additional_info)); + break; + case BHD_COOKIE: + case BHDL2_COOKIE: + count = bdir->header.num_entries; + fletcher_match = bdir->header.checksum == fletcher32(&bdir->header.num_entries, + count * sizeof(bios_directory_entry) + + sizeof(bdir->header.num_entries) + + sizeof(bdir->header.additional_info)); + break; + default: /* ISH */ + fletcher_match = ish->checksum == fletcher32(&ish->boot_priority, + sizeof(ish_directory_table) - sizeof(uint32_t)); + break; + } + return fletcher_match; +} + static void fill_dir_header(void *directory, uint32_t count, context *ctx) { psp_combo_directory *cdir = directory; @@ -832,26 +881,58 @@ { printf("romsig offset:%lx\n", BUFF_TO_RUN(*ctx, ctx->amd_romsig_ptr)); printf("PSP L1 offset:%lx\n", BUFF_TO_RUN(*ctx, ctx->pspdir)); - if (ctx->pspdir_bak != NULL) + if (check_dir_header(ctx->pspdir)) + printf("--match\n"); + if (ctx->pspdir_bak != NULL) { printf("PSP L1 backup offset:%lx\n", BUFF_TO_RUN(*ctx, ctx->pspdir_bak)); - if (ctx->pspdir2 != NULL) + if (check_dir_header(ctx->pspdir_bak)) + printf("--match\n"); + } + if (ctx->pspdir2 != NULL) { printf("PSP L2(A) offset:%lx\n", BUFF_TO_RUN(*ctx, ctx->pspdir2)); - if (ctx->ish_a_dir != NULL) + if (check_dir_header(ctx->pspdir2)) + printf("--match\n"); + } + if (ctx->ish_a_dir != NULL) { printf("ISHA offset:%lx\n", BUFF_TO_RUN(*ctx, ctx->ish_a_dir)); - if (ctx->ish_b_dir != NULL) + if (check_dir_header(ctx->ish_a_dir)) + printf("--match\n"); + } + if (ctx->ish_b_dir != NULL) { printf("ISHB offset:%lx\n", BUFF_TO_RUN(*ctx, ctx->ish_b_dir)); - if (ctx->pspdir2_b != NULL) + if (check_dir_header(ctx->ish_b_dir)) + printf("--match\n"); + } + if (ctx->pspdir2_b != NULL) { printf("PSP L2B offset:%lx\n", BUFF_TO_RUN(*ctx, ctx->pspdir2_b)); - if (ctx->biosdir != NULL) + if (check_dir_header(ctx->pspdir2_b)) + printf("--match\n"); + } + if (ctx->biosdir != NULL) { printf("BHD offset:%lx\n", BUFF_TO_RUN(*ctx, ctx->biosdir)); - if (ctx->biosdir2 != NULL) + if (check_dir_header(ctx->biosdir)) + printf("--match\n"); + } + if (ctx->biosdir2 != NULL) { printf("BHD L2(A) offset:%lx\n", BUFF_TO_RUN(*ctx, ctx->biosdir2)); - if (ctx->biosdir2_b != NULL) + if (check_dir_header(ctx->biosdir2)) + printf("--match\n"); + } + if (ctx->biosdir2_b != NULL) { printf("BHD L2B offset:%lx\n", BUFF_TO_RUN(*ctx, ctx->biosdir2_b)); - if (ctx->psp_combo_dir != NULL) + if (check_dir_header(ctx->biosdir2_b)) + printf("--match\n"); + } + if (ctx->psp_combo_dir != NULL) { printf("PSP combo offset:%lx\n", BUFF_TO_RUN(*ctx, ctx->psp_combo_dir)); - if (ctx->bhd_combo_dir != NULL) + if (check_dir_header(ctx->psp_combo_dir)) + printf("--match\n"); + } + if (ctx->bhd_combo_dir != NULL) { printf("BHD combo offset:%lx\n", BUFF_TO_RUN(*ctx, ctx->bhd_combo_dir)); + if (check_dir_header(ctx->bhd_combo_dir)) + printf("--match\n"); + } }
static void integrate_psp_ab(context *ctx, psp_directory_table *pspdir,