Hello Zheng Bao,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/45895
to review the following change.
Change subject: amdfwtool: Change all error output to fprintf stderr ......................................................................
amdfwtool: Change all error output to fprintf stderr
Change-Id: Ie4ce0f1fb3aea8f12dfae9e5d16589262e7d6ab0 Signed-off-by: Zheng Bao fishbaozi@gmail.com --- M util/amdfwtool/amdfwtool.c M util/amdfwtool/data_parse.c 2 files changed, 32 insertions(+), 32 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/95/45895/1
diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c index 03afc46..c87f1b4 100644 --- a/util/amdfwtool/amdfwtool.c +++ b/util/amdfwtool/amdfwtool.c @@ -523,19 +523,19 @@
fd = open(src_file, O_RDONLY); if (fd < 0) { - printf("Error opening file: %s: %s\n", + fprintf(stderr, "Error opening file: %s: %s\n", src_file, strerror(errno)); return -1; }
if (fstat(fd, &fd_stat)) { - printf("fstat error: %s\n", strerror(errno)); + fprintf(stderr, "fstat error: %s\n", strerror(errno)); close(fd); return -2; }
if ((size_t)fd_stat.st_size > room) { - printf("Error: %s will not fit. Exiting.\n", src_file); + fprintf(stderr, "Error: %s will not fit. Exiting.\n", src_file); close(fd); return -3; } @@ -543,7 +543,7 @@ bytes = read(fd, dest, (size_t)fd_stat.st_size); close(fd); if (bytes != (ssize_t)fd_stat.st_size) { - printf("Error while reading %s\n", src_file); + fprintf(stderr, "Error while reading %s\n", src_file); return -4; }
@@ -746,7 +746,7 @@ }
if (count > MAX_PSP_ENTRIES) { - printf("Error: PSP entries exceed max allowed items\n"); + fprintf(stderr, "Error: PSP entries exceed max allowed items\n"); free(ctx->rom); exit(1); } @@ -862,7 +862,7 @@ if (!fw_table[i].size && !fw_table[i].src) continue; /* APOB_NV not used */ if (fw_table[i].src && !fw_table[i].size) { - printf("Error: APOB NV address provided, but no size\n"); + fprintf(stderr, "Error: APOB NV address provided, but no size\n"); free(ctx->rom); exit(1); } @@ -874,7 +874,7 @@
/* APOB_DATA needs destination */ if (fw_table[i].type == AMD_BIOS_APOB && !fw_table[i].dest) { - printf("Error: APOB destination not provided\n"); + fprintf(stderr, "Error: APOB destination not provided\n"); free(ctx->rom); exit(1); } @@ -884,12 +884,12 @@ */ if (fw_table[i].type == AMD_BIOS_BIN) { if (!fw_table[i].dest || !fw_table[i].size) { - printf("Error: BIOS binary destination and uncompressed size are required\n"); + fprintf(stderr, "Error: BIOS binary destination and uncompressed size are required\n"); free(ctx->rom); exit(1); } if (!fw_table[i].filename && !fw_table[i].src) { - printf("Error: BIOS binary assumed outside amdfw.rom but no source address given\n"); + fprintf(stderr, "Error: BIOS binary assumed outside amdfw.rom but no source address given\n"); free(ctx->rom); exit(1); } @@ -1006,7 +1006,7 @@ }
if (count > MAX_BIOS_ENTRIES) { - printf("Error: BIOS entries (%d) exceeds max allowed items " + fprintf(stderr, "Error: BIOS entries (%d) exceeds max allowed items " "(%d)\n", count, MAX_BIOS_ENTRIES); free(ctx->rom); exit(1); @@ -1166,7 +1166,7 @@ uint8_t efs_spi_micron_flag) { if ((efs_spi_readmode == 0xFF) || (efs_spi_speed == 0xFF)) { - printf("Error: EFS read mode and SPI speed must be set\n"); + fprintf(stderr, "Error: EFS read mode and SPI speed must be set\n"); return 1; } switch (soc_id) { @@ -1188,7 +1188,7 @@ amd_romsig->qpr_dummy_cycle_f17_mod_00_2f = 0xa; break; default: - printf("Error: EFS Micron flag must be correctly set.\n\n"); + fprintf(stderr, "Error: EFS Micron flag must be correctly set.\n\n"); return 1; } break; @@ -1208,13 +1208,13 @@ amd_romsig->micron_detect_f17_mod_30_3f = 0x55; break; default: - printf("Error: EFS Micron flag must be correctly set.\n\n"); + fprintf(stderr, "Error: EFS Micron flag must be correctly set.\n\n"); return 1; } break; case PLATFORM_UNKNOWN: default: - printf("Error: Invalid SOC name.\n\n"); + fprintf(stderr, "Error: Invalid SOC name.\n\n"); return 1; } return 0; @@ -1384,7 +1384,7 @@ case 'C': soc_id = identify_platform(optarg); if (soc_id == PLATFORM_UNKNOWN) { - printf("Error: Invalid SOC name specified\n\n"); + fprintf(stderr, "Error: Invalid SOC name specified\n\n"); retval = 1; } sub = instance = 0; @@ -1407,7 +1407,7 @@ case 'f': ctx.rom_size = (uint32_t)strtoul(optarg, &tmp, 16); if (*tmp != '\0') { - printf("Error: ROM size specified" + fprintf(stderr, "Error: ROM size specified" " incorrectly (%s)\n\n", optarg); retval = 1; } @@ -1415,7 +1415,7 @@ case 'l': dir_location = (uint32_t)strtoul(optarg, &tmp, 16); if (*tmp != '\0') { - printf("Error: Directory Location specified" + fprintf(stderr, "Error: Directory Location specified" " incorrectly (%s)\n\n", optarg); retval = 1; } @@ -1468,18 +1468,18 @@ register_fw_fuse(DEFAULT_SOFT_FUSE_CHAIN);
if (!output) { - printf("Error: Output value is not specified.\n\n"); + fprintf(stderr, "Error: Output value is not specified.\n\n"); retval = 1; }
if (ctx.rom_size % 1024 != 0) { - printf("Error: ROM Size (%d bytes) should be a multiple of" + fprintf(stderr, "Error: ROM Size (%d bytes) should be a multiple of" " 1024 bytes.\n\n", ctx.rom_size); retval = 1; }
if (ctx.rom_size < MIN_ROM_KB * 1024) { - printf("Error: ROM Size (%dKB) must be at least %dKB.\n\n", + fprintf(stderr, "Error: ROM Size (%dKB) must be at least %dKB.\n\n", ctx.rom_size / 1024, MIN_ROM_KB); retval = 1; } @@ -1493,14 +1493,14 @@
rom_base_address = 0xFFFFFFFF - ctx.rom_size + 1; if (dir_location && (dir_location < rom_base_address)) { - printf("Error: Directory location outside of ROM.\n\n"); + fprintf(stderr, "Error: Directory location outside of ROM.\n\n"); return 1; }
if (any_location) { if (dir_location & 0x3f) { - printf("Error: Invalid Directory location.\n"); - printf(" Valid locations are 64-byte aligned\n"); + fprintf(stderr, "Error: Invalid Directory location.\n"); + fprintf(stderr, " Valid locations are 64-byte aligned\n"); return 1; } } else { @@ -1514,16 +1514,16 @@ case 0xFF020000: /* Fall through */ break; default: - printf("Error: Invalid Directory location.\n"); - printf(" Valid locations are 0xFFFA0000, 0xFFF20000,\n"); - printf(" 0xFFE20000, 0xFFC20000, 0xFF820000, 0xFF020000\n"); + fprintf(stderr, "Error: Invalid Directory location.\n"); + fprintf(stderr, " Valid locations are 0xFFFA0000, 0xFFF20000,\n"); + fprintf(stderr, " 0xFFE20000, 0xFFC20000, 0xFF820000, 0xFF020000\n"); return 1; } }
ctx.rom = malloc(ctx.rom_size); if (!ctx.rom) { - printf("Error: Failed to allocate memory\n"); + fprintf(stderr, "Error: Failed to allocate memory\n"); return 1; } memset(ctx.rom, 0xFF, ctx.rom_size); @@ -1545,11 +1545,11 @@ retval = set_efs_table(soc_id, amd_romsig, efs_spi_readmode, efs_spi_speed, efs_spi_micron_flag); if (retval) { - printf("ERROR: Failed to initialize EFS table!\n"); + fprintf(stderr, "ERROR: Failed to initialize EFS table!\n"); return retval; } } else { - printf("WARNING: No SOC name specified.\n"); + fprintf(stderr, "WARNING: No SOC name specified.\n"); }
integrate_firmwares(&ctx, amd_romsig, amd_fw_table); @@ -1623,7 +1623,7 @@ retval = 1; close(targetfd); } else { - printf("Error: could not open file: %s\n", output); + fprintf(stderr, "Error: could not open file: %s\n", output); retval = 1; }
diff --git a/util/amdfwtool/data_parse.c b/util/amdfwtool/data_parse.c index 7d27e52..98453ac 100644 --- a/util/amdfwtool/data_parse.c +++ b/util/amdfwtool/data_parse.c @@ -38,7 +38,7 @@ result = regcomp(reg, expr, cflags); if (result != 0) { regerror(result, reg, error_msg, ERROR_BUF_SIZE); - printf("%s\n", error_msg); + fprintf(stderr, "%s\n", error_msg); } }
@@ -291,7 +291,7 @@ line[strlen(line) - 1] = '\0';
if (strlen(line) == ((size_t) (line_buf_size - 1))) { - printf("The line size in config file should be lower than %d bytes.\n", + fprintf(stderr, "The line size in config file should be lower than %d bytes.\n", MAX_LINE_SIZE); exit(1); }