From 4e8fb3503cc1791d3812d5bd5792d4ff44ad10d5 Mon Sep 17 00:00:00 2001 From: Zheng Bao Date: Mon, 21 Nov 2022 21:34:45 +0800 Subject: amdfwtool: Allow the location to be a relative address When the BIOS size is more than 32M, the physical address of EFS header will be complicated, like 0xfe020000 or 0xfc020000. So we make it simpler to allow to use relative address. This CL works with https://review.coreboot.org/c/coreboot/+/69852 TEST=Result image is binary same on amd/birman amd/majolica amd/gardina amd/mandolin Change-Id: I4308ec9ea05a87329aba0b409508c79ebf42325c Signed-off-by: Zheng Bao Reviewed-on: https://review.coreboot.org/c/coreboot/+/69856 Tested-by: build bot (Jenkins) Reviewed-by: Fred Reitberger --- util/amdfwtool/amdfwtool.c | 48 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) (limited to 'util') diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c index 9b250b52b7..e1e689dddb 100644 --- a/util/amdfwtool/amdfwtool.c +++ b/util/amdfwtool/amdfwtool.c @@ -2478,6 +2478,10 @@ int main(int argc, char **argv) fprintf(stderr, " Require safe spacing of 256 bytes\n"); return 1; } + if (efs_location & 0xFF000000) + efs_location = efs_location - rom_base_address; + if (body_location & 0xFF000000) + body_location = body_location - rom_base_address; if (any_location) { if ((body_location & 0x3f) || (efs_location & 0x3f)) { @@ -2486,19 +2490,43 @@ int main(int argc, char **argv) return 1; } } else { + /* efs_location is relative address now. */ switch (efs_location) { case 0: - case 0xFFFA0000: - case 0xFFF20000: - case 0xFFE20000: - case 0xFFC20000: - case 0xFF820000: - case 0xFF020000: + case 0xFA0000: + case 0xF20000: + case 0xE20000: + case 0xC20000: + case 0x820000: + case 0x020000: + break; + case 0x7A0000: + case 0x720000: + case 0x620000: + case 0x420000: + /* Special cases for 8M. */ + if (ctx.rom_size != 0x800000) { + fprintf(stderr, "Error: Invalid Directory location.\n"); + fprintf(stderr, "%x is only for 8M image size.", efs_location); + return 1; + } + break; + case 0x3A0000: + case 0x320000: + case 0x220000: + /* Special cases for 4M. */ + if (ctx.rom_size != 0x400000) { + fprintf(stderr, "Error: Invalid Directory location.\n"); + fprintf(stderr, "%x is only for 4M image size.", efs_location); + return 1; + } break; default: fprintf(stderr, "Error: Invalid Directory location.\n"); fprintf(stderr, " Valid locations are 0xFFFA0000, 0xFFF20000,\n"); fprintf(stderr, " 0xFFE20000, 0xFFC20000, 0xFF820000, 0xFF020000\n"); + fprintf(stderr, " 0xFA0000, 0xF20000, 0xE20000, 0xC20000,\n"); + fprintf(stderr, " 0x820000, 0x020000\n"); return 1; } } @@ -2511,10 +2539,10 @@ int main(int argc, char **argv) if (efs_location) { if (efs_location != body_location) { - romsig_offset = efs_location - rom_base_address; - ctx.current = body_location - rom_base_address; + romsig_offset = efs_location; + ctx.current = body_location; } else { - romsig_offset = efs_location - rom_base_address; + romsig_offset = efs_location; ctx.current = romsig_offset + sizeof(embedded_firmware); } } else { @@ -2671,7 +2699,7 @@ int main(int argc, char **argv) targetfd = open(output, O_RDWR | O_CREAT | O_TRUNC, 0666); if (targetfd >= 0) { ssize_t bytes; - uint32_t offset = body_location ? body_location - rom_base_address : AMD_ROMSIG_OFFSET; + uint32_t offset = body_location ? body_location : AMD_ROMSIG_OFFSET; bytes = write(targetfd, BUFF_OFFSET(ctx, offset), ctx.current - offset); if (bytes != ctx.current - offset) { -- cgit v1.2.3