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/+/85467?usp=email
to review the following change.
Change subject: amdfwtool: Split the A/B level 2 with PSP level 1 ......................................................................
amdfwtool: Split the A/B level 2 with PSP level 1
Change-Id: Ie9230e333dc5b1eca5beee1d3a57e815764c3cf3 Signed-off-by: Zheng Bao fishbaozi@gmail.com --- M util/amdfwtool/amdfwtool.c M util/amdfwtool/amdfwtool.h M util/amdfwtool/handle_file.c M util/amdfwtool/opts.c 4 files changed, 49 insertions(+), 7 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/67/85467/1
diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c index 24eaaf9..ae5ac14 100644 --- a/util/amdfwtool/amdfwtool.c +++ b/util/amdfwtool/amdfwtool.c @@ -1070,11 +1070,15 @@ ctx->pspdir_bak = new_psp_dir(ctx, cb_config->multi_level, cookie); } else if (cookie == PSPL2_COOKIE) { if (ctx->pspdir2 == NULL) { + if (cb_config->ral2_location != 0) + set_current_pointer(ctx, cb_config->ral2_location); if (cb_config->need_ish && ctx->ish_a_dir == NULL) /* Need ISH */ ctx->ish_a_dir = new_ish_dir(ctx); pspdir = new_psp_dir(ctx, cb_config->multi_level, cookie); ctx->pspdir2 = pspdir; } else if (ctx->pspdir2_b == NULL) { + if (cb_config->rbl2_location != 0) + set_current_pointer(ctx, cb_config->rbl2_location); if (cb_config->need_ish && ctx->ish_b_dir == NULL) /* Need ISH */ ctx->ish_b_dir = new_ish_dir(ctx); pspdir = new_psp_dir(ctx, cb_config->multi_level, cookie); @@ -1970,6 +1974,8 @@ ctx.current - offset : sizeof(embedded_firmware); uint32_t ret_bytes;
+ if (cb_config.ral2_location != 0 && cb_config.rbl2_location != 0) + bytes = (void *)ctx.pspdir - (void *)ctx.amd_romsig_ptr + AMDFW_TABLE_SIZE(ctx.pspdir); ret_bytes = write_from_buf_to_file(targetfd, BUFF_OFFSET(ctx, offset), bytes); if (bytes != ret_bytes) { fprintf(stderr, "Error: Writing to file %s failed\n", cb_config.output); @@ -1985,13 +1991,31 @@ ssize_t bytes;
bytes = write_body(cb_config.output, BUFF_OFFSET(ctx, cb_config.body_location), - ctx.current - cb_config.body_location); + ctx.current - cb_config.body_location, BODY_FILE_SUFFIX); if (bytes != ctx.current - cb_config.body_location) { fprintf(stderr, "Error: Writing body\n"); retval = 1; } }
+ if (cb_config.recovery_ab && cb_config.ral2_location && cb_config.rbl2_location) { + ssize_t abytes = 0, bbytes = 0; + if (ctx.biosdir2 != NULL) { + abytes = (void *)ctx.biosdir2 - (void *)ctx.pspdir2 + + AMDFW_TABLE_SIZE(ctx.biosdir2); + write_body(cb_config.output, BUFF_OFFSET(ctx, cb_config.ral2_location), + abytes, RA_FILE_SUFFIX); + } + if (ctx.biosdir2_b != NULL) { + bbytes = (void *)ctx.biosdir2_b - (void *)ctx.pspdir2_b + + AMDFW_TABLE_SIZE(ctx.biosdir2_b); + write_body(cb_config.output, BUFF_OFFSET(ctx, cb_config.rbl2_location), + bbytes, RB_FILE_SUFFIX); + } + if (abytes != bbytes) + fprintf(stderr, "Warning: The size of A and B tables are not the same\n"); + } + if (cb_config.manifest_file) { dump_blob_version(cb_config.manifest_file, amd_psp_fw_table); } diff --git a/util/amdfwtool/amdfwtool.h b/util/amdfwtool/amdfwtool.h index f87fbf5..0328a6e 100644 --- a/util/amdfwtool/amdfwtool.h +++ b/util/amdfwtool/amdfwtool.h @@ -431,7 +431,7 @@ enum platform soc_id;
uint8_t efs_spi_readmode, efs_spi_speed, efs_spi_micron_flag; - uint32_t body_location, efs_location; + uint32_t body_location, efs_location, ral2_location, rbl2_location; uint64_t signed_start_addr; char *manifest_file; const char *signed_output_file; @@ -461,6 +461,9 @@ ish_directory_table *ish_a_dir, *ish_b_dir; } context;
+#define AMDFW_TABLE_SIZE(tb) (((psp_directory_table *)(tb))-> \ + header.additional_info_fields.dir_size * TABLE_ALIGNMENT) + uint8_t process_config(FILE *config, amd_cb_config *cb_config); void process_signed_psp_firmwares(const char *signed_rom, amd_fw_entry *fw_table, @@ -472,11 +475,13 @@ #define EFS_FILE_SUFFIX ".efs" #define TMP_FILE_SUFFIX ".tmp" #define BODY_FILE_SUFFIX ".body" +#define RA_FILE_SUFFIX ".ra" +#define RB_FILE_SUFFIX ".rb"
void write_or_fail(int fd, void *ptr, size_t size); ssize_t read_from_file_to_buf(int fd, void *buf, size_t buf_size); ssize_t write_from_buf_to_file(int fd, const void *buf, size_t buf_size); -ssize_t write_body(char *output, void *body_offset, ssize_t body_size); +ssize_t write_body(char *output, void *body_offset, ssize_t body_size, char *suffix); ssize_t copy_blob(void *dest, const char *src_file, size_t room); #define OK 0
diff --git a/util/amdfwtool/handle_file.c b/util/amdfwtool/handle_file.c index c37bb2c..bc16ff5 100644 --- a/util/amdfwtool/handle_file.c +++ b/util/amdfwtool/handle_file.c @@ -83,7 +83,7 @@ return buf_size; }
-ssize_t write_body(char *output, void *body_offset, ssize_t body_size) +ssize_t write_body(char *output, void *body_offset, ssize_t body_size, char *suffix) { char body_name[PATH_MAX], body_tmp_name[PATH_MAX]; int ret; @@ -93,7 +93,7 @@ /* Create a tmp file and rename it at the end so that make does not get confused if amdfwtool is killed for some unexpected reasons. */ ret = snprintf(body_tmp_name, sizeof(body_tmp_name), "%s%s%s", - output, BODY_FILE_SUFFIX, TMP_FILE_SUFFIX); + output, suffix, TMP_FILE_SUFFIX); if (ret < 0) { fprintf(stderr, "Error %s forming BODY tmp file name: %d\n", strerror(errno), ret); @@ -117,7 +117,7 @@ close(fd);
/* Rename the tmp file */ - ret = snprintf(body_name, sizeof(body_name), "%s%s", output, BODY_FILE_SUFFIX); + ret = snprintf(body_name, sizeof(body_name), "%s%s", output, suffix); if (ret < 0) { fprintf(stderr, "Error %s forming BODY file name: %d\n", strerror(errno), ret); return -1; diff --git a/util/amdfwtool/opts.c b/util/amdfwtool/opts.c index 62bbc97..1e460a1 100644 --- a/util/amdfwtool/opts.c +++ b/util/amdfwtool/opts.c @@ -61,6 +61,8 @@ AMDFW_OPT_SIGNED_OUTPUT, AMDFW_OPT_SIGNED_ADDR, AMDFW_OPT_BODY_LOCATION, + AMDFW_OPT_RECOVERY_A_LOCATION, + AMDFW_OPT_RECOVERY_B_LOCATION, /* begin after ASCII characters */ LONGOPT_SPI_READ_MODE = 256, LONGOPT_SPI_SPEED = 257, @@ -120,6 +122,8 @@ {"spi-speed", required_argument, 0, LONGOPT_SPI_SPEED }, {"spi-micron-flag", required_argument, 0, LONGOPT_SPI_MICRON_FLAG }, {"body-location", required_argument, 0, AMDFW_OPT_BODY_LOCATION }, + {"recovery-a-location", required_argument, 0, AMDFW_OPT_RECOVERY_A_LOCATION }, + {"recovery-b-location", required_argument, 0, AMDFW_OPT_RECOVERY_B_LOCATION }, /* other */ {"output", required_argument, 0, AMDFW_OPT_OUTPUT }, {"flashsize", required_argument, 0, AMDFW_OPT_FLASHSIZE }, @@ -611,7 +615,12 @@ retval = 1; } break; - + case AMDFW_OPT_RECOVERY_A_LOCATION: + cb_config->ral2_location = (uint32_t)strtoul(optarg, &tmp, 16); + break; + case AMDFW_OPT_RECOVERY_B_LOCATION: + cb_config->rbl2_location = (uint32_t)strtoul(optarg, &tmp, 16); + break; default: break; } @@ -647,6 +656,10 @@ cb_config->efs_location = cb_config->efs_location - rom_base_address; if (cb_config->body_location & ~MAX_MAPPED_WINDOW_MASK) cb_config->body_location = cb_config->body_location - rom_base_address; + if (cb_config->ral2_location & ~MAX_MAPPED_WINDOW_MASK) + cb_config->ral2_location = cb_config->ral2_location - rom_base_address; + if (cb_config->rbl2_location & ~MAX_MAPPED_WINDOW_MASK) + cb_config->rbl2_location = cb_config->rbl2_location - rom_base_address; }
/* If the flash size is larger than 16M, we assume the given