diff options
author | Martin Roth <martinroth@chromium.org> | 2016-11-08 11:22:12 -0700 |
---|---|---|
committer | Martin Roth <martinroth@google.com> | 2016-11-10 00:26:45 +0100 |
commit | 31d95a2eb2cae1667ab89200d7c2887c3ef8076a (patch) | |
tree | beb687b0373e72592c85d1ade49cbb68c821b6d4 /util/amdfwtool | |
parent | 2fe70b69c07b77dd83e261fc98eea97d078c1097 (diff) |
util/amdfwtool: unify return values, verify the file open
- Return an error if the specified file could not be opened. To do this
cleanly, the return value was added.
- Since there's now a unified return value, use it where it makes sense.
- Don't return an error from --help. If you've asked for usage, it's
not an error.
Change-Id: I7c712d1e1927c2d4957b044b87ad26475b7a0e3b
Signed-off-by: Martin Roth <martinroth@chromium.org>
Reviewed-on: https://review.coreboot.org/17324
Tested-by: build bot (Jenkins)
Reviewed-by: Marc Jones <marc@marcjonesconsulting.com>
Reviewed-by: Marshall Dawson <marshalldawson3rd@gmail.com>
Diffstat (limited to 'util/amdfwtool')
-rw-r--r-- | util/amdfwtool/amdfwtool.c | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/util/amdfwtool/amdfwtool.c b/util/amdfwtool/amdfwtool.c index 5cd0f285f5..d2975c8e27 100644 --- a/util/amdfwtool/amdfwtool.c +++ b/util/amdfwtool/amdfwtool.c @@ -442,6 +442,7 @@ static void register_fw_filename(amd_fw_type type, char filename[], int pspflag) int main(int argc, char **argv) { int c, pspflag = 0; + int retval = 0; #if PSP2 int psp2flag = 0; uint32_t *psp2dir; @@ -584,33 +585,42 @@ int main(int argc, char **argv) if (*tmp != '\0') { printf("Error: ROM size specified" " incorrectly (%s)\n\n", optarg); - return 1; + retval = 1; } break; case 'h': usage(); - return 1; + return 0; default: break; } } if (!output) { - printf("Error: Output value is not specified.\n"); - usage(); - exit(1); + printf("Error: Output value is not specified.\n\n"); + retval = 1; + } + + if (!rom_size) { + printf("Error: ROM Size is not specified.\n\n"); + retval = 1; } if (rom_size % 1024 != 0) { printf("Error: ROM Size (%d bytes) should be a multiple of" - " 1024 bytes.\n", rom_size); - exit(1); + " 1024 bytes.\n\n", rom_size); + retval = 1; } if (rom_size < MIN_ROM_KB * 1024) { - printf("Error: ROM Size (%dKB) must be at least %dKB.\n", + printf("Error: ROM Size (%dKB) must be at least %dKB.\n\n", rom_size / 1024, MIN_ROM_KB); - exit(1); + retval = 1; + } + + if (retval) { + usage(); + return retval; } printf(" AMDFWTOOL Using ROM size of %dKB\n", rom_size / 1024); @@ -618,7 +628,7 @@ int main(int argc, char **argv) rom_base_address = 0xFFFFFFFF - rom_size + 1; rom = malloc(rom_size); if (!rom) - exit(1); + return 1; memset (rom, 0xFF, rom_size); current = AMD_ROMSIG_OFFSET; @@ -679,9 +689,14 @@ int main(int argc, char **argv) #endif targetfd = open(output, O_RDWR | O_CREAT | O_TRUNC, 0666); - write(targetfd, amd_romsig, current - AMD_ROMSIG_OFFSET); - close(targetfd); - free(rom); + if (targetfd >= 0) { + write(targetfd, amd_romsig, current - AMD_ROMSIG_OFFSET); + close(targetfd); + } else { + printf("Error: could not open file: %s\n", output); + retval = 1; + } - return 0; + free(rom); + return retval; } |