summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward O'Callaghan <quasisec@google.com>2023-03-14 20:32:05 +1100
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-03-31 20:57:30 +0000
commit3d95a15696638404ce7b67ad5ad288b5c24c4179 (patch)
tree4248783407a035e7ef929128adc4e4f78d408457
parent5517a3562d5fdcb2c1e635713adf3aaaac67aa4f (diff)
downloadvboot-3d95a15696638404ce7b67ad5ad288b5c24c4179.tar.gz
futility/cmd_*.c: Use ERROR() macro consistently
Fix grammatical issues in ERROR() usage and over usage of contractions. Now errors shall now be prefixed with "ERROR:" and the function name. BUG=b:268397597 TEST=`emerge-nissa vboot_reference`. TEST=`cros_run_unit_tests --host --packages vboot_reference`. TEST=`cros_run_unit_tests --board nissa --packages vboot_reference`. Change-Id: Ieac1f312c2e02133228ba4560197d009aed0324c Signed-off-by: Edward O'Callaghan <quasisec@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/4349560 Reviewed-by: Sam McNally <sammc@chromium.org> Auto-Submit: Edward O'Callaghan <quasisec@chromium.org> Tested-by: Edward O'Callaghan <quasisec@chromium.org> Commit-Queue: Edward O'Callaghan <quasisec@chromium.org>
-rw-r--r--futility/cmd_create.c58
-rw-r--r--futility/cmd_dump_fmap.c23
-rw-r--r--futility/cmd_dump_kernel_config.c6
-rw-r--r--futility/cmd_gbb_utility.c124
-rw-r--r--futility/cmd_load_fmap.c27
-rw-r--r--futility/cmd_pcr.c12
-rw-r--r--futility/cmd_read.c2
-rw-r--r--futility/cmd_show.c43
-rw-r--r--futility/cmd_sign.c78
-rw-r--r--futility/cmd_vbutil_firmware.c8
-rw-r--r--futility/cmd_vbutil_kernel.c23
-rw-r--r--futility/cmd_vbutil_key.c12
-rw-r--r--futility/cmd_vbutil_keyblock.c48
13 files changed, 198 insertions, 266 deletions
diff --git a/futility/cmd_create.c b/futility/cmd_create.c
index 1ef35c86..a3b10bba 100644
--- a/futility/cmd_create.c
+++ b/futility/cmd_create.c
@@ -92,7 +92,7 @@ static int vb1_make_keypair(void)
FILE *fp = fopen(infile, "rb");
if (!fp) {
- fprintf(stderr, "Unable to open %s\n", infile);
+ ERROR("Unable to open %s\n", infile);
goto done;
}
@@ -101,13 +101,13 @@ static int vb1_make_keypair(void)
rsa_key = PEM_read_RSAPrivateKey(fp, NULL, NULL, NULL);
fclose(fp);
if (!rsa_key) {
- fprintf(stderr, "Unable to read RSA key from %s\n", infile);
+ ERROR("Unable to read RSA key from %s\n", infile);
goto done;
}
enum vb2_signature_algorithm sig_alg = vb2_rsa_sig_alg(rsa_key);
if (sig_alg == VB2_SIG_INVALID) {
- fprintf(stderr, "Unsupported sig algorithm in RSA key\n");
+ ERROR("Unsupported sig algorithm in RSA key\n");
goto done;
}
@@ -127,7 +127,7 @@ static int vb1_make_keypair(void)
/* Write it out */
strcpy(outext, ".vbprivk");
if (0 != vb2_write_private_key(outfile, privkey)) {
- fprintf(stderr, "unable to write private key\n");
+ ERROR("Unable to write private key\n");
goto done;
}
printf("wrote %s\n", outfile);
@@ -135,7 +135,7 @@ static int vb1_make_keypair(void)
/* Create the public key */
ret = vb_keyb_from_rsa(rsa_key, &keyb_data, &keyb_size);
if (ret) {
- fprintf(stderr, "couldn't extract the public key\n");
+ ERROR("Couldn't extract the public key\n");
goto done;
}
@@ -147,7 +147,7 @@ static int vb1_make_keypair(void)
/* Write it out */
strcpy(outext, ".vbpubk");
if (VB2_SUCCESS != vb2_write_packed_key(outfile, pubkey)) {
- fprintf(stderr, "unable to write public key\n");
+ ERROR("Unable to write public key\n");
goto done;
}
printf("wrote %s\n", outfile);
@@ -179,7 +179,7 @@ static int vb2_make_keypair(void)
fp = fopen(infile, "rb");
if (!fp) {
- fprintf(stderr, "Unable to open %s\n", infile);
+ ERROR("Unable to open %s\n", infile);
goto done;
}
@@ -188,25 +188,25 @@ static int vb2_make_keypair(void)
if (!rsa_key) {
/* Check if the PEM contains only a public key */
if (0 != fseek(fp, 0, SEEK_SET)) {
- fprintf(stderr, "Error seeking in %s\n", infile);
+ ERROR("Seeking in %s\n", infile);
goto done;
}
rsa_key = PEM_read_RSA_PUBKEY(fp, NULL, NULL, NULL);
}
fclose(fp);
if (!rsa_key) {
- fprintf(stderr, "Unable to read RSA key from %s\n", infile);
+ ERROR("Unable to read RSA key from %s\n", infile);
goto done;
}
/* Public keys doesn't have the private exponent */
RSA_get0_key(rsa_key, NULL, NULL, &rsa_d);
has_priv = !!rsa_d;
if (!has_priv)
- fprintf(stderr, "%s has a public key only.\n", infile);
+ ERROR("%s has a public key only.\n", infile);
sig_alg = vb2_rsa_sig_alg(rsa_key);
if (sig_alg == VB2_SIG_INVALID) {
- fprintf(stderr, "Unsupported sig algorithm in RSA key\n");
+ ERROR("Unsupported sig algorithm in RSA key\n");
goto done;
}
@@ -214,7 +214,7 @@ static int vb2_make_keypair(void)
/* Create the private key */
privkey = calloc(1, sizeof(*privkey));
if (!privkey) {
- fprintf(stderr, "Unable to allocate the private key\n");
+ ERROR("Unable to allocate the private key\n");
goto done;
}
@@ -222,21 +222,20 @@ static int vb2_make_keypair(void)
privkey->sig_alg = sig_alg;
privkey->hash_alg = opt_hash_alg;
if (opt_desc && vb2_private_key_set_desc(privkey, opt_desc)) {
- fprintf(stderr,
- "Unable to set the private key description\n");
+ ERROR("Unable to set the private key description\n");
goto done;
}
}
/* Create the public key */
if (vb2_public_key_alloc(&pubkey, sig_alg)) {
- fprintf(stderr, "Unable to allocate the public key\n");
+ ERROR("Unable to allocate the public key\n");
goto done;
}
/* Extract the keyb blob */
if (vb_keyb_from_rsa(rsa_key, &keyb_data, &keyb_size)) {
- fprintf(stderr, "Couldn't extract the public key\n");
+ ERROR("Couldn't extract the public key\n");
goto done;
}
@@ -249,14 +248,14 @@ static int vb2_make_keypair(void)
/* Fill in the internal struct pointers */
if (vb2_unpack_key_data(pubkey, pubkey_buf, keyb_size)) {
- fprintf(stderr, "Unable to unpack the public key blob\n");
+ ERROR("Unable to unpack the public key blob\n");
goto done;
}
pubkey->hash_alg = opt_hash_alg;
pubkey->version = opt_version;
if (opt_desc && vb2_public_key_set_desc(pubkey, opt_desc)) {
- fprintf(stderr, "Unable to set pubkey description\n");
+ ERROR("Unable to set pubkey description\n");
goto done;
}
@@ -275,7 +274,7 @@ static int vb2_make_keypair(void)
privkey->id = opt_id;
strcpy(outext, ".vbprik2");
if (vb21_private_key_write(privkey, outfile)) {
- fprintf(stderr, "unable to write private key\n");
+ ERROR("Unable to write private key\n");
goto done;
}
printf("wrote %s\n", outfile);
@@ -283,7 +282,7 @@ static int vb2_make_keypair(void)
strcpy(outext, ".vbpubk2");
if (vb21_public_key_write(pubkey, outfile)) {
- fprintf(stderr, "unable to write public key\n");
+ ERROR("Unable to write public key\n");
goto done;
}
printf("wrote %s\n", outfile);
@@ -312,8 +311,7 @@ static int do_create(int argc, char *argv[])
case OPT_VERSION:
opt_version = strtoul(optarg, &e, 0);
if (!*optarg || (e && *e)) {
- fprintf(stderr,
- "invalid version \"%s\"\n", optarg);
+ ERROR("Invalid version \"%s\"\n", optarg);
errorcnt = 1;
}
break;
@@ -324,8 +322,7 @@ static int do_create(int argc, char *argv[])
case OPT_ID:
if (VB2_SUCCESS != vb2_str_to_id(optarg, &opt_id)) {
- fprintf(stderr, "invalid id \"%s\"\n",
- optarg);
+ ERROR("Invalid id \"%s\"\n", optarg);
errorcnt = 1;
}
force_id = 1;
@@ -333,8 +330,7 @@ static int do_create(int argc, char *argv[])
case OPT_HASH_ALG:
if (!vb2_lookup_hash_alg(optarg, &opt_hash_alg)) {
- fprintf(stderr,
- "invalid hash_alg \"%s\"\n", optarg);
+ ERROR("Invalid hash_alg \"%s\"\n", optarg);
errorcnt++;
}
break;
@@ -345,14 +341,14 @@ static int do_create(int argc, char *argv[])
case '?':
if (optopt)
- fprintf(stderr, "Unrecognized option: -%c\n",
+ ERROR("Unrecognized option: -%c\n",
optopt);
else
- fprintf(stderr, "Unrecognized option\n");
+ ERROR("Unrecognized option\n");
errorcnt++;
break;
case ':':
- fprintf(stderr, "Missing argument to -%c\n", optopt);
+ ERROR("Missing argument to -%c\n", optopt);
errorcnt++;
break;
case 0: /* handled option */
@@ -365,7 +361,7 @@ static int do_create(int argc, char *argv[])
/* If we don't have an input file already, we need one */
if (!infile) {
if (argc - optind <= 0) {
- fprintf(stderr, "ERROR: missing input filename\n");
+ ERROR("Missing input filename\n");
errorcnt++;
} else {
infile = argv[optind++];
@@ -389,7 +385,7 @@ static int do_create(int argc, char *argv[])
len = strlen(s) + 20;
outfile = (char *)malloc(len);
if (!outfile) {
- fprintf(stderr, "ERROR: malloc() failed\n");
+ ERROR("malloc() failed\n");
return 1;
}
strcpy(outfile, s);
diff --git a/futility/cmd_dump_fmap.c b/futility/cmd_dump_fmap.c
index 1e5c29c0..f5e172e7 100644
--- a/futility/cmd_dump_fmap.c
+++ b/futility/cmd_dump_fmap.c
@@ -50,8 +50,7 @@ static int normal_fmap(const FmapHeader *fmh, int argc, char *argv[])
if (!f)
continue;
if (a == f || *(f+1) == '\0') {
- fprintf(stderr,
- "argument \"%s\" is bogus\n", a);
+ ERROR("argument \"%s\" is bogus\n", a);
retval = 1;
continue;
}
@@ -121,21 +120,21 @@ static int normal_fmap(const FmapHeader *fmh, int argc, char *argv[])
}
FILE *fp = fopen(outname, "wb");
if (!fp) {
- fprintf(stderr, "%s: can't open %s: %s\n",
+ ERROR("%s: can't open %s: %s\n",
argv[0], outname, strerror(errno));
retval = 1;
} else if (!ah->area_size) {
- fprintf(stderr,
+ ERROR(
"%s: section %s has zero size\n",
argv[0], buf);
} else if (ah->area_offset + ah->area_size >
size_of_rom) {
- fprintf(stderr, "%s: section %s is larger"
+ ERROR("%s: section %s is larger"
" than the image\n", argv[0], buf);
retval = 1;
} else if (1 != fwrite(base_of_rom + ah->area_offset,
ah->area_size, 1, fp)) {
- fprintf(stderr, "%s: can't write %s: %s\n",
+ ERROR("%s: can't write %s: %s\n",
argv[0], buf, strerror(errno));
retval = 1;
} else {
@@ -454,12 +453,12 @@ static int do_dump_fmap(int argc, char *argv[])
print_help(argc, argv);
return 0;
case '?':
- fprintf(stderr, "%s: unrecognized switch: -%c\n",
+ ERROR("%s: unrecognized switch: -%c\n",
argv[0], optopt);
errorcnt++;
break;
case ':':
- fprintf(stderr, "%s: missing argument to -%c\n",
+ ERROR("%s: missing argument to -%c\n",
argv[0], optopt);
errorcnt++;
break;
@@ -476,13 +475,13 @@ static int do_dump_fmap(int argc, char *argv[])
fd = open(argv[optind], O_RDONLY);
if (fd < 0) {
- fprintf(stderr, "%s: can't open %s: %s\n",
+ ERROR("%s: can't open %s: %s\n",
argv[0], argv[optind], strerror(errno));
return 1;
}
if (0 != fstat(fd, &sb)) {
- fprintf(stderr, "%s: can't stat %s: %s\n",
+ ERROR("%s: can't stat %s: %s\n",
argv[0], argv[optind], strerror(errno));
close(fd);
return 1;
@@ -491,7 +490,7 @@ static int do_dump_fmap(int argc, char *argv[])
base_of_rom =
mmap(0, sb.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
if (base_of_rom == (char *)-1) {
- fprintf(stderr, "%s: can't mmap %s: %s\n",
+ ERROR("%s: can't mmap %s: %s\n",
argv[0], argv[optind], strerror(errno));
close(fd);
return 1;
@@ -517,7 +516,7 @@ static int do_dump_fmap(int argc, char *argv[])
}
if (0 != munmap(base_of_rom, sb.st_size)) {
- fprintf(stderr, "%s: can't munmap %s: %s\n",
+ ERROR("%s: can't munmap %s: %s\n",
argv[0], argv[optind], strerror(errno));
return 1;
}
diff --git a/futility/cmd_dump_kernel_config.c b/futility/cmd_dump_kernel_config.c
index 5dd23a58..6896062c 100644
--- a/futility/cmd_dump_kernel_config.c
+++ b/futility/cmd_dump_kernel_config.c
@@ -56,7 +56,7 @@ static int do_dump_kern_cfg(int argc, char *argv[])
case OPT_KLOADADDR:
kernel_body_load_address = strtoul(optarg, &e, 0);
if (!*optarg || (e && *e)) {
- fprintf(stderr, "Invalid --kloadaddr\n");
+ ERROR("Invalid --kloadaddr\n");
parse_error = 1;
}
break;
@@ -68,7 +68,7 @@ static int do_dump_kern_cfg(int argc, char *argv[])
}
if (optind >= argc) {
- fprintf(stderr, "Expected argument after options\n");
+ ERROR("Expected argument after options\n");
parse_error = 1;
} else
infile = argv[optind];
@@ -79,7 +79,7 @@ static int do_dump_kern_cfg(int argc, char *argv[])
}
if (!infile || !*infile) {
- fprintf(stderr, "Must specify filename\n");
+ ERROR("Must specify filename\n");
return 1;
}
diff --git a/futility/cmd_gbb_utility.c b/futility/cmd_gbb_utility.c
index 79c14130..fedb43b4 100644
--- a/futility/cmd_gbb_utility.c
+++ b/futility/cmd_gbb_utility.c
@@ -159,7 +159,7 @@ static struct vb2_gbb_header *FindGbbHeader(uint8_t *ptr, size_t size)
case 1:
return gbb_header;
default:
- fprintf(stderr, "ERROR: multiple GBB headers found\n");
+ ERROR("Multiple GBB headers found\n");
errorcnt++;
return NULL;
}
@@ -178,8 +178,7 @@ static uint8_t *create_gbb(const char *desc, off_t *sizeptr)
sizes = strdup(desc);
if (!sizes) {
errorcnt++;
- fprintf(stderr, "ERROR: strdup() failed: %s\n",
- strerror(errno));
+ ERROR("strdup() failed: %s\n", strerror(errno));
return NULL;
}
@@ -187,9 +186,7 @@ static uint8_t *create_gbb(const char *desc, off_t *sizeptr)
val[i] = (uint32_t) strtoul(param, &e, 0);
if (e && *e) {
errorcnt++;
- fprintf(stderr,
- "ERROR: invalid creation parameter: \"%s\"\n",
- param);
+ ERROR("Invalid creation parameter: \"%s\"\n", param);
free(sizes);
return NULL;
}
@@ -201,8 +198,7 @@ static uint8_t *create_gbb(const char *desc, off_t *sizeptr)
buf = (uint8_t *) calloc(1, size);
if (!buf) {
errorcnt++;
- fprintf(stderr, "ERROR: can't malloc %zu bytes: %s\n",
- size, strerror(errno));
+ ERROR("Can't malloc %zu bytes: %s\n", size, strerror(errno));
free(sizes);
return NULL;
}
@@ -245,14 +241,13 @@ static uint8_t *read_entire_file(const char *filename, off_t *sizeptr)
fp = fopen(filename, "rb");
if (!fp) {
- fprintf(stderr, "ERROR: Unable to open %s for reading: %s\n",
- filename, strerror(errno));
+ ERROR("Unable to open %s for reading: %s\n", filename,
+ strerror(errno));
goto fail;
}
if (0 != fstat(fileno(fp), &sb)) {
- fprintf(stderr, "ERROR: can't fstat %s: %s\n",
- filename, strerror(errno));
+ ERROR("Can't fstat %s: %s\n", filename, strerror(errno));
goto fail;
}
if (sizeptr)
@@ -260,20 +255,19 @@ static uint8_t *read_entire_file(const char *filename, off_t *sizeptr)
buf = (uint8_t *) malloc(sb.st_size);
if (!buf) {
- fprintf(stderr, "ERROR: can't malloc %" PRIi64 " bytes: %s\n",
- sb.st_size, strerror(errno));
+ ERROR("Can't malloc %" PRIi64 " bytes: %s\n", sb.st_size,
+ strerror(errno));
goto fail;
}
if (1 != fread(buf, sb.st_size, 1, fp)) {
- fprintf(stderr, "ERROR: Unable to read from %s: %s\n",
- filename, strerror(errno));
+ ERROR("Unable to read from %s: %s\n", filename,
+ strerror(errno));
goto fail;
}
if (0 != fclose(fp)) {
- fprintf(stderr, "ERROR: Unable to close %s: %s\n",
- filename, strerror(errno));
+ ERROR("Unable to close %s: %s\n", filename, strerror(errno));
fp = NULL; /* Don't try to close it again */
goto fail;
}
@@ -287,8 +281,7 @@ fail:
free(buf);
if (fp && 0 != fclose(fp))
- fprintf(stderr, "ERROR: Unable to close %s: %s\n",
- filename, strerror(errno));
+ ERROR("Unable to close %s: %s\n", filename, strerror(errno));
return NULL;
}
@@ -303,24 +296,20 @@ static int read_from_file(const char *msg, const char *filename,
fp = fopen(filename, "rb");
if (!fp) {
r = errno;
- fprintf(stderr, "ERROR: Unable to open %s for reading: %s\n",
- filename, strerror(r));
+ ERROR("Unable to open %s for reading: %s\n", filename, strerror(r));
errorcnt++;
return r;
}
if (0 != fstat(fileno(fp), &sb)) {
r = errno;
- fprintf(stderr, "ERROR: can't fstat %s: %s\n", filename,
- strerror(r));
+ ERROR("Can't fstat %s: %s\n", filename, strerror(r));
errorcnt++;
goto done_close;
}
if (sb.st_size > size) {
- fprintf(stderr,
- "ERROR: file %s exceeds capacity (%" PRIu32 ")\n",
- filename, size);
+ ERROR("File %s exceeds capacity (%" PRIu32 ")\n", filename, size);
errorcnt++;
r = -1;
goto done_close;
@@ -333,17 +322,15 @@ static int read_from_file(const char *msg, const char *filename,
count = fread(start, 1, size, fp);
if (ferror(fp)) {
r = errno;
- fprintf(stderr,
- "ERROR: Read %zu/%" PRIi64 " bytes from %s: %s\n",
- count, sb.st_size, filename, strerror(r));
+ ERROR("Read %zu/%" PRIi64 " bytes from %s: %s\n", count,
+ sb.st_size, filename, strerror(r));
errorcnt++;
}
done_close:
if (0 != fclose(fp)) {
int e = errno;
- fprintf(stderr, "ERROR: Unable to close %s: %s\n", filename,
- strerror(e));
+ ERROR("Unable to close %s: %s\n", filename, strerror(e));
errorcnt++;
if (!r)
r = e;
@@ -368,15 +355,14 @@ static int setup_flash(struct updater_config **cfg,
*prepare_ctrl_name = NULL;
*cfg = updater_new_config();
if (!*cfg) {
- fprintf(stderr, "\nERROR: Out of memory\n");
+ ERROR("Out of memory\n");
return 1;
}
if (args->detect_servo) {
char *servo_programmer = host_detect_servo(prepare_ctrl_name);
if (!servo_programmer) {
- fprintf(stderr,
- "\nERROR: Problem communicating with servo\n");
+ ERROR("Problem communicating with servo\n");
goto errdelete;
}
@@ -387,7 +373,7 @@ static int setup_flash(struct updater_config **cfg,
}
int ignored;
if (updater_setup_config(*cfg, args, &ignored)) {
- fprintf(stderr, "\nERROR: Bad servo options\n");
+ ERROR("Bad servo options\n");
goto errdelete;
}
prepare_servo_control(*prepare_ctrl_name, 1);
@@ -471,7 +457,7 @@ static int parse_flag_value(const char *s, vb2_gbb_flags_t *val)
char *e = NULL;
*val = strtoul(ss, &e, 0);
if (e && *e) {
- fprintf(stderr, "ERROR: invalid flags value: %s\n", ss);
+ ERROR("Invalid flags value: %s\n", ss);
return -1;
}
@@ -556,8 +542,7 @@ static int do_gbb(int argc, char *argv[])
break;
case OPT_FLASH:
#ifndef USE_FLASHROM
- fprintf(stderr, "ERROR: futility was built without "
- "flashrom support\n");
+ ERROR("futility was built without flashrom support\n");
return 1;
#endif
args.use_flash = 1;
@@ -569,32 +554,24 @@ static int do_gbb(int argc, char *argv[])
case '?':
errorcnt++;
if (optopt)
- fprintf(stderr,
- "ERROR: unrecognized option: -%c\n",
- optopt);
+ ERROR("Unrecognized option: -%c\n", optopt);
else if (argv[optind - 1])
- fprintf(stderr,
- "ERROR: unrecognized option "
- "(possibly \"%s\")\n",
- argv[optind - 1]);
+ ERROR("Unrecognized option (possibly \"%s\")\n",
+ argv[optind - 1]);
else
- fprintf(stderr, "ERROR: unrecognized option\n");
+ ERROR("Unrecognized option\n");
break;
case ':':
errorcnt++;
if (argv[optind - 1])
- fprintf(stderr,
- "ERROR: missing argument to -%c (%s)\n",
- optopt, argv[optind - 1]);
+ ERROR("Missing argument to -%c (%s)\n", optopt,
+ argv[optind - 1]);
else
- fprintf(stderr,
- "ERROR: missing argument to -%c\n",
- optopt);
+ ERROR("Missing argument to -%c\n", optopt);
break;
default:
errorcnt++;
- fprintf(stderr,
- "ERROR: error while parsing options\n");
+ ERROR("While parsing options\n");
}
}
@@ -606,8 +583,7 @@ static int do_gbb(int argc, char *argv[])
if (args.use_flash) {
if (setup_flash(&cfg, &args, &prepare_ctrl_name)) {
- fprintf(stderr,
- "ERROR: error while preparing flash\n");
+ ERROR("While preparing flash\n");
return 1;
}
}
@@ -619,15 +595,13 @@ static int do_gbb(int argc, char *argv[])
inbuf = read_from_flash(cfg, &filesize);
} else {
if (argc - optind < 1) {
- fprintf(stderr,
- "\nERROR: missing input filename\n");
+ ERROR("Missing input filename\n");
print_help(argc, argv);
errorcnt++;
break;
}
infile = argv[optind++];
inbuf = read_entire_file(infile, &filesize);
-
}
if (!inbuf) {
errorcnt++;
@@ -641,7 +615,7 @@ static int do_gbb(int argc, char *argv[])
gbb = FindGbbHeader(inbuf, filesize);
if (!gbb) {
- fprintf(stderr, "ERROR: No GBB found in %s\n", infile);
+ ERROR("No GBB found in %s\n", infile);
errorcnt++;
break;
}
@@ -707,8 +681,7 @@ static int do_gbb(int argc, char *argv[])
inbuf = read_from_flash(cfg, &filesize);
} else {
if (argc - optind < 1) {
- fprintf(stderr,
- "\nERROR: missing input filename\n");
+ ERROR("Missing input filename\n");
print_help(argc, argv);
errorcnt++;
break;
@@ -725,13 +698,13 @@ static int do_gbb(int argc, char *argv[])
}
if (sel_hwid && !opt_hwid) {
- fprintf(stderr, "\nERROR: missing new HWID value\n");
+ ERROR("Missing new HWID value\n");
print_help(argc, argv);
errorcnt++;
break;
}
if (sel_flags && (!opt_flags || !*opt_flags)) {
- fprintf(stderr, "\nERROR: missing new flags value\n");
+ ERROR("Missing new flags value\n");
print_help(argc, argv);
errorcnt++;
break;
@@ -739,7 +712,7 @@ static int do_gbb(int argc, char *argv[])
gbb = FindGbbHeader(inbuf, filesize);
if (!gbb) {
- fprintf(stderr, "ERROR: No GBB found in %s\n", infile);
+ ERROR("No GBB found in %s\n", infile);
errorcnt++;
break;
}
@@ -747,9 +720,8 @@ static int do_gbb(int argc, char *argv[])
outbuf = (uint8_t *) malloc(filesize);
if (!outbuf) {
- fprintf(stderr,
- "ERROR: can't malloc %" PRIi64 " bytes: %s\n",
- filesize, strerror(errno));
+ ERROR("Can't malloc %" PRIi64 " bytes: %s\n", filesize,
+ strerror(errno));
errorcnt++;
break;
}
@@ -758,8 +730,7 @@ static int do_gbb(int argc, char *argv[])
memcpy(outbuf, inbuf, filesize);
gbb = FindGbbHeader(outbuf, filesize);
if (!gbb) {
- fprintf(stderr,
- "INTERNAL ERROR: No GBB found in outbuf\n");
+ ERROR("INTERNAL ERROR: No GBB found in outbuf\n");
errorcnt++;
break;
}
@@ -767,9 +738,7 @@ static int do_gbb(int argc, char *argv[])
if (opt_hwid) {
if (strlen(opt_hwid) + 1 > gbb->hwid_size) {
- fprintf(stderr,
- "ERROR: null-terminated HWID"
- " exceeds capacity (%d)\n",
+ ERROR("null-terminated HWID exceeds capacity (%d)\n",
gbb->hwid_size);
errorcnt++;
break;
@@ -838,8 +807,7 @@ static int do_gbb(int argc, char *argv[])
case DO_CREATE:
if (!outfile) {
if (argc - optind < 1) {
- fprintf(stderr,
- "\nERROR: missing output filename\n");
+ ERROR("Missing output filename\n");
print_help(argc, argv);
errorcnt++;
break;
@@ -849,9 +817,7 @@ static int do_gbb(int argc, char *argv[])
/* Parse the creation args */
outbuf = create_gbb(opt_create, &filesize);
if (!outbuf) {
- fprintf(stderr,
- "\nERROR: unable to parse creation spec (%s)\n",
- opt_create);
+ ERROR("Unable to parse creation spec (%s)\n", opt_create);
print_help(argc, argv);
errorcnt++;
break;
diff --git a/futility/cmd_load_fmap.c b/futility/cmd_load_fmap.c
index 220070a2..4828415c 100644
--- a/futility/cmd_load_fmap.c
+++ b/futility/cmd_load_fmap.c
@@ -62,7 +62,7 @@ static int copy_to_area(char *file, uint8_t *buf, uint32_t len, char *area)
fp = fopen(file, "r");
if (!fp) {
- fprintf(stderr, "area %s: can't open %s for reading: %s\n",
+ ERROR("area %s: can't open %s for reading: %s\n",
area, file, strerror(errno));
return 1;
}
@@ -70,19 +70,18 @@ static int copy_to_area(char *file, uint8_t *buf, uint32_t len, char *area)
n = fread(buf, 1, len, fp);
if (n == 0) {
if (feof(fp))
- fprintf(stderr, "area %s: unexpected EOF on %s\n",
- area, file);
+ ERROR("area %s: unexpected EOF on %s\n", area, file);
if (ferror(fp))
- fprintf(stderr, "area %s: can't read from %s: %s\n",
+ ERROR("area %s: can't read from %s: %s\n",
area, file, strerror(errno));
retval = 1;
} else if (n < len) {
- fprintf(stderr, "Warning on area %s: only read %d "
+ ERROR("Warning on area %s: only read %d "
"(not %d) from %s\n", area, n, len, file);
}
if (0 != fclose(fp)) {
- fprintf(stderr, "area %s: error closing %s: %s\n",
+ ERROR("area %s: error closing %s: %s\n",
area, file, strerror(errno));
retval = 1;
}
@@ -113,14 +112,14 @@ static int do_load_fmap(int argc, char *argv[])
return !!errorcnt;
case '?':
if (optopt)
- fprintf(stderr, "Unrecognized option: -%c\n",
+ ERROR("Unrecognized option: -%c\n",
optopt);
else
- fprintf(stderr, "Unrecognized option\n");
+ ERROR("Unrecognized option\n");
errorcnt++;
break;
case ':':
- fprintf(stderr, "Missing argument to -%c\n", optopt);
+ ERROR("Missing argument to -%c\n", optopt);
errorcnt++;
break;
default:
@@ -134,8 +133,7 @@ static int do_load_fmap(int argc, char *argv[])
}
if (argc - optind < 2) {
- fprintf(stderr,
- "You must specify an input file"
+ ERROR("You must specify an input file"
" and at least one AREA:file argument\n");
print_help(argc, argv);
return 1;
@@ -151,13 +149,12 @@ static int do_load_fmap(int argc, char *argv[])
exit(1);
errorcnt |= futil_open_and_map_file(outfile, &fd, FILE_RW, &buf, &len);
-
if (errorcnt)
goto done;
fmap = fmap_find(buf, len);
if (!fmap) {
- fprintf(stderr, "Can't find an FMAP in %s\n", infile);
+ ERROR("Can't find an FMAP in %s\n", infile);
errorcnt++;
goto done;
}
@@ -167,14 +164,14 @@ static int do_load_fmap(int argc, char *argv[])
char *f = strchr(a, ':');
if (!f || a == f || *(f+1) == '\0') {
- fprintf(stderr, "argument \"%s\" is bogus\n", a);
+ ERROR("argument \"%s\" is bogus\n", a);
errorcnt++;
break;
}
*f++ = '\0';
uint8_t *area_buf = fmap_find_by_name(buf, len, fmap, a, &ah);
if (!area_buf) {
- fprintf(stderr, "Can't find area \"%s\" in FMAP\n", a);
+ ERROR("Can't find area \"%s\" in FMAP\n", a);
errorcnt++;
break;
}
diff --git a/futility/cmd_pcr.c b/futility/cmd_pcr.c
index ba86321e..eb514b3d 100644
--- a/futility/cmd_pcr.c
+++ b/futility/cmd_pcr.c
@@ -78,14 +78,14 @@ static int do_pcr(int argc, char *argv[])
return !!errorcnt;
case '?':
if (optopt)
- fprintf(stderr, "Unrecognized option: -%c\n",
+ ERROR("Unrecognized option: -%c\n",
optopt);
else
- fprintf(stderr, "Unrecognized option\n");
+ ERROR("Unrecognized option\n");
errorcnt++;
break;
case ':':
- fprintf(stderr, "Missing argument to -%c\n", optopt);
+ ERROR("Missing argument to -%c\n", optopt);
errorcnt++;
break;
default:
@@ -99,7 +99,7 @@ static int do_pcr(int argc, char *argv[])
}
if (argc - optind < 1 + opt_init) {
- fprintf(stderr, "You must extend at least one DIGEST\n");
+ ERROR("You must extend at least one DIGEST\n");
print_help(argc, argv);
return 1;
}
@@ -108,7 +108,7 @@ static int do_pcr(int argc, char *argv[])
digest_size = vb2_digest_size(digest_alg);
if (!digest_size) {
- fprintf(stderr, "Error determining digest size!\n");
+ ERROR("Cannot determine digest size!\n");
return 1;
}
@@ -133,7 +133,7 @@ static int do_pcr(int argc, char *argv[])
if (VB2_SUCCESS != vb2_hash_calculate(false, accum,
digest_size * 2,
digest_alg, &hash)) {
- fprintf(stderr, "Error computing digest!\n");
+ ERROR("Cannot compute digest!\n");
return 1;
}
memcpy(pcr, hash.raw, digest_size);
diff --git a/futility/cmd_read.c b/futility/cmd_read.c
index 1461ba7f..46f4bfdb 100644
--- a/futility/cmd_read.c
+++ b/futility/cmd_read.c
@@ -87,7 +87,7 @@ static int do_read(int argc, char *argv[])
}
}
if (argc - optind < 1) {
- fprintf(stderr, "\nERROR: missing output filename\n");
+ ERROR("Missing output filename\n");
print_help(argc, argv);
return 1;
}
diff --git a/futility/cmd_show.c b/futility/cmd_show.c
index 13461c07..7fb1c849 100644
--- a/futility/cmd_show.c
+++ b/futility/cmd_show.c
@@ -192,8 +192,7 @@ static int fw_show_metadata_hash(const char *name, enum bios_component body_c,
if (!bhsize || pre->body_signature.sig_size <
offsetof(struct vb2_hash, raw) + bhsize) {
- fprintf(stderr, "Body signature data is too small to "
- "fit metadata hash.\n");
+ ERROR("Body signature data is too small to fit metadata hash.\n");
return 1;
}
@@ -209,8 +208,8 @@ static int fw_show_metadata_hash(const char *name, enum bios_component body_c,
if (cbfstool_get_metadata_hash(name, fmap_name[body_c], &real_hash) !=
VB2_SUCCESS ||
real_hash.algo == VB2_HASH_INVALID) {
- fprintf(stderr, "Failed to get metadata hash. Firmware body is"
- " corrupted or is not a valid CBFS.\n");
+ ERROR("Failed to get metadata hash. Firmware body is"
+ " corrupted or is not a valid CBFS.\n");
return 1;
}
@@ -222,8 +221,8 @@ static int fw_show_metadata_hash(const char *name, enum bios_component body_c,
vb2_get_hash_algorithm_name(real_hash.algo));
print_bytes(&real_hash.raw, vb2_digest_size(real_hash.algo));
putchar('\n');
- fprintf(stderr, "Signature hash does not match with"
- " real metadata hash.\n");
+ ERROR("Signature hash does not match with"
+ " real metadata hash.\n");
return 1;
}
return 0;
@@ -283,7 +282,7 @@ int show_fw_preamble_buf(const char *name, uint8_t *buf, uint32_t len,
struct vb2_public_key data_key;
if (VB2_SUCCESS != vb2_unpack_key(&data_key, &keyblock->data_key)) {
- fprintf(stderr, "Error parsing data key in %s\n", name);
+ ERROR("Parsing data key in %s\n", name);
return 1;
}
@@ -339,7 +338,7 @@ int show_fw_preamble_buf(const char *name, uint8_t *buf, uint32_t len,
if (pre2->body_signature.data_size) {
if (vb2_verify_data(fv_data, fv_size, &pre2->body_signature,
&data_key, &wb) != VB2_SUCCESS) {
- fprintf(stderr, "Error verifying firmware body.\n");
+ ERROR("Verifying firmware body.\n");
return 1;
}
} else if (state) { /* Only works for images with at least FW_MAIN_A */
@@ -411,7 +410,7 @@ int ft_show_kernel_preamble(const char *name, void *data)
struct vb2_public_key data_key;
if (VB2_SUCCESS != vb2_unpack_key(&data_key, &keyblock->data_key)) {
- fprintf(stderr, "Error parsing data key in %s\n", name);
+ ERROR("Parsing data key in %s\n", name);
goto done;
}
@@ -468,14 +467,14 @@ int ft_show_kernel_preamble(const char *name, void *data)
if (!kernel_blob) {
/* TODO: Is this always a failure? The preamble is okay. */
- fprintf(stderr, "No kernel blob available to verify.\n");
+ ERROR("No kernel blob available to verify.\n");
goto done;
}
if (VB2_SUCCESS !=
vb2_verify_data(kernel_blob, kernel_size, &pre2->body_signature,
&data_key, &wb)) {
- fprintf(stderr, "Error verifying kernel body.\n");
+ ERROR("Verifying kernel body.\n");
goto done;
}
@@ -598,7 +597,7 @@ static int do_show(int argc, char *argv[])
show_option.fv = ReadFile(optarg,
&show_option.fv_size);
if (!show_option.fv) {
- fprintf(stderr, "Error reading %s: %s\n",
+ ERROR("Reading %s: %s\n",
optarg, strerror(errno));
errorcnt++;
}
@@ -606,14 +605,14 @@ static int do_show(int argc, char *argv[])
case 'k':
if (VB2_SUCCESS !=
vb2_read_file(optarg, &pubkbuf, &len)) {
- fprintf(stderr, "Error reading %s\n", optarg);
+ ERROR("Reading %s\n", optarg);
errorcnt++;
break;
}
if (VB2_SUCCESS !=
vb2_unpack_key_buffer(&pubk2, pubkbuf, len)) {
- fprintf(stderr, "Error unpacking %s\n", optarg);
+ ERROR("Unpacking %s\n", optarg);
errorcnt++;
break;
}
@@ -626,8 +625,7 @@ static int do_show(int argc, char *argv[])
case OPT_PADDING:
show_option.padding = strtoul(optarg, &e, 0);
if (!*optarg || (e && *e)) {
- fprintf(stderr,
- "Invalid --padding \"%s\"\n", optarg);
+ ERROR("Invalid --padding \"%s\"\n", optarg);
errorcnt++;
}
break;
@@ -636,15 +634,14 @@ static int do_show(int argc, char *argv[])
&show_option.type)) {
if (!strcasecmp("help", optarg))
print_file_types_and_exit(errorcnt);
- fprintf(stderr,
- "Invalid --type \"%s\"\n", optarg);
+ ERROR("Invalid --type \"%s\"\n", optarg);
errorcnt++;
}
type_override = 1;
break;
case OPT_PUBKEY:
if (vb21_packed_key_read(&show_option.pkey, optarg)) {
- fprintf(stderr, "Error reading %s\n", optarg);
+ ERROR("Reading %s\n", optarg);
errorcnt++;
}
break;
@@ -654,14 +651,14 @@ static int do_show(int argc, char *argv[])
case '?':
if (optopt)
- fprintf(stderr, "Unrecognized option: -%c\n",
+ ERROR("Unrecognized option: -%c\n",
optopt);
else
- fprintf(stderr, "Unrecognized option\n");
+ ERROR("Unrecognized option\n");
errorcnt++;
break;
case ':':
- fprintf(stderr, "Missing argument to -%c\n", optopt);
+ ERROR("Missing argument to -%c\n", optopt);
errorcnt++;
break;
case 0: /* handled option */
@@ -677,7 +674,7 @@ static int do_show(int argc, char *argv[])
}
if (argc - optind < 1) {
- fprintf(stderr, "ERROR: missing input filename\n");
+ ERROR("Missing input filename\n");
print_help(argc, argv);
return 1;
}
diff --git a/futility/cmd_sign.c b/futility/cmd_sign.c
index 4126717d..e5a4bcc2 100644
--- a/futility/cmd_sign.c
+++ b/futility/cmd_sign.c
@@ -51,7 +51,7 @@ struct sign_option_s sign_option = {
static int no_opt_if(int expr, const char *optname)
{
if (expr) {
- fprintf(stderr, "Missing --%s option\n", optname);
+ ERROR("Missing --%s option\n", optname);
return 1;
}
return 0;
@@ -71,7 +71,7 @@ int ft_sign_pubkey(const char *name, void *data)
return 1;
if (vb2_packed_key_looks_ok(data_key, data_len)) {
- fprintf(stderr, "Public key looks bad.\n");
+ ERROR("Public key looks bad.\n");
goto done;
}
@@ -89,7 +89,7 @@ int ft_sign_pubkey(const char *name, void *data)
sign_option.pem_signpriv,
sign_option.pem_algo);
if (!sign_option.signprivate) {
- fprintf(stderr,
+ ERROR(
"Unable to read PEM signing key: %s\n",
strerror(errno));
goto done;
@@ -131,7 +131,7 @@ int ft_sign_raw_kernel(const char *name, void *data)
sign_option.bootloader_data, sign_option.bootloader_size,
&kblob_size);
if (!kblob_data) {
- fprintf(stderr, "Unable to create kernel blob\n");
+ ERROR("Unable to create kernel blob\n");
goto done;
}
VB2_DEBUG("kblob_size = %#x\n", kblob_size);
@@ -144,7 +144,7 @@ int ft_sign_raw_kernel(const char *name, void *data)
sign_option.signprivate,
sign_option.flags, &vblock_size);
if (!vblock_data) {
- fprintf(stderr, "Unable to sign kernel blob\n");
+ ERROR("Unable to sign kernel blob\n");
goto done;
}
VB2_DEBUG("vblock_size = %#x\n", vblock_size);
@@ -190,7 +190,7 @@ int ft_sign_kern_preamble(const char *name, void *data)
&keyblock, &preamble, &kblob_size);
if (!kblob_data) {
- fprintf(stderr, "Unable to unpack kernel partition\n");
+ ERROR("Unable to unpack kernel partition\n");
goto done;
}
@@ -208,7 +208,7 @@ int ft_sign_kern_preamble(const char *name, void *data)
0 != UpdateKernelBlobConfig(kblob_data, kblob_size,
sign_option.config_data,
sign_option.config_size)) {
- fprintf(stderr, "Unable to update config\n");
+ ERROR("Unable to update config\n");
goto done;
}
@@ -235,7 +235,7 @@ int ft_sign_kern_preamble(const char *name, void *data)
sign_option.flags,
&vblock_size);
if (!vblock_data) {
- fprintf(stderr, "Unable to sign kernel blob\n");
+ ERROR("Unable to sign kernel blob\n");
goto done;
}
VB2_DEBUG("vblock_size = %#x\n", vblock_size);
@@ -280,7 +280,7 @@ int ft_sign_raw_firmware(const char *name, void *data)
body_sig = vb2_calculate_signature(buf, len, sign_option.signprivate);
if (!body_sig) {
- fprintf(stderr, "Error calculating body signature\n");
+ ERROR("Calculating body signature\n");
goto done;
}
@@ -291,7 +291,7 @@ int ft_sign_raw_firmware(const char *name, void *data)
sign_option.signprivate,
sign_option.flags);
if (!preamble) {
- fprintf(stderr, "Error creating firmware preamble.\n");
+ ERROR("Creating firmware preamble.\n");
goto done;
}
@@ -353,7 +353,7 @@ static int load_keyset(void)
INFO("Loading private data key from default keyset: %s\n", buf);
sign_option.signprivate = vb2_read_private_key(buf);
if (!sign_option.signprivate) {
- ERROR("Error reading %s\n", buf);
+ ERROR("Reading %s\n", buf);
errorcnt++;
}
free(buf);
@@ -366,7 +366,7 @@ static int load_keyset(void)
INFO("Loading keyblock from default keyset: %s\n", buf);
sign_option.keyblock = vb2_read_keyblock(buf);
if (!sign_option.keyblock) {
- ERROR("Error reading %s\n", buf);
+ ERROR("Reading %s\n", buf);
errorcnt++;
}
free(buf);
@@ -379,7 +379,7 @@ static int load_keyset(void)
INFO("Loading kernel subkey from default keyset: %s\n", buf);
sign_option.kernel_subkey = vb2_read_packed_key(buf);
if (!sign_option.kernel_subkey) {
- ERROR("Error reading %s\n", buf);
+ ERROR("Reading %s\n", buf);
errorcnt++;
}
free(buf);
@@ -776,7 +776,7 @@ static int parse_number_opt(const char *arg, const char *name, uint32_t *dest)
char *e;
uint32_t val = strtoul(arg, &e, 0);
if (!*arg || (e && *e)) {
- fprintf(stderr, "Invalid --%s \"%s\"\n", name, arg);
+ ERROR("Invalid --%s \"%s\"\n", name, arg);
return 1;
}
*dest = val;
@@ -799,21 +799,21 @@ static int do_sign(int argc, char *argv[])
case 's':
sign_option.signprivate = vb2_read_private_key(optarg);
if (!sign_option.signprivate) {
- fprintf(stderr, "Error reading %s\n", optarg);
+ ERROR("Reading %s\n", optarg);
errorcnt++;
}
break;
case 'b':
sign_option.keyblock = vb2_read_keyblock(optarg);
if (!sign_option.keyblock) {
- fprintf(stderr, "Error reading %s\n", optarg);
+ ERROR("Reading %s\n", optarg);
errorcnt++;
}
break;
case 'k':
sign_option.kernel_subkey = vb2_read_packed_key(optarg);
if (!sign_option.kernel_subkey) {
- fprintf(stderr, "Error reading %s\n", optarg);
+ ERROR("Reading %s\n", optarg);
errorcnt++;
}
break;
@@ -821,8 +821,7 @@ static int do_sign(int argc, char *argv[])
sign_option.version_specified = 1;
sign_option.version = strtoul(optarg, &e, 0);
if (!*optarg || (e && *e)) {
- fprintf(stderr,
- "Invalid --version \"%s\"\n", optarg);
+ ERROR("Invalid --version \"%s\"\n", optarg);
errorcnt++;
}
break;
@@ -856,8 +855,7 @@ static int do_sign(int argc, char *argv[])
sign_option.bootloader_data = ReadFile(
optarg, &sign_option.bootloader_size);
if (!sign_option.bootloader_data) {
- fprintf(stderr,
- "Error reading bootloader file: %s\n",
+ ERROR("Error reading bootloader file: %s\n",
strerror(errno));
errorcnt++;
}
@@ -868,8 +866,7 @@ static int do_sign(int argc, char *argv[])
sign_option.config_data = ReadConfigFile(
optarg, &sign_option.config_size);
if (!sign_option.config_data) {
- fprintf(stderr,
- "Error reading config file: %s\n",
+ ERROR("Error reading config file: %s\n",
strerror(errno));
errorcnt++;
}
@@ -885,8 +882,7 @@ static int do_sign(int argc, char *argv[])
else if (!strcasecmp(optarg, "mips"))
sign_option.arch = ARCH_MIPS;
else {
- fprintf(stderr,
- "Unknown architecture: \"%s\"\n",
+ ERROR("Unknown architecture: \"%s\"\n",
optarg);
errorcnt++;
}
@@ -931,16 +927,14 @@ static int do_sign(int argc, char *argv[])
sign_option.pem_algo = strtoul(optarg, &e, 0);
if (!*optarg || (e && *e) ||
(sign_option.pem_algo >= VB2_ALG_COUNT)) {
- fprintf(stderr,
- "Invalid --pem_algo \"%s\"\n", optarg);
+ ERROR("Invalid --pem_algo \"%s\"\n", optarg);
errorcnt++;
}
break;
case OPT_HASH_ALG:
if (!vb2_lookup_hash_alg(optarg,
&sign_option.hash_alg)) {
- fprintf(stderr,
- "invalid hash_alg \"%s\"\n", optarg);
+ ERROR("Invalid hash_alg \"%s\"\n", optarg);
errorcnt++;
}
break;
@@ -952,15 +946,14 @@ static int do_sign(int argc, char *argv[])
&sign_option.type)) {
if (!strcasecmp("help", optarg))
print_file_types_and_exit(errorcnt);
- fprintf(stderr,
- "Invalid --type \"%s\"\n", optarg);
+ ERROR("Invalid --type \"%s\"\n", optarg);
errorcnt++;
}
break;
case OPT_PRIKEY:
if (vb21_private_key_read(&sign_option.prikey,
optarg)) {
- fprintf(stderr, "Error reading %s\n", optarg);
+ ERROR("Reading %s\n", optarg);
errorcnt++;
}
break;
@@ -970,15 +963,15 @@ static int do_sign(int argc, char *argv[])
case '?':
if (optopt)
- fprintf(stderr, "Unrecognized option: -%c\n",
+ ERROR("Unrecognized option: -%c\n",
optopt);
else
- fprintf(stderr, "Unrecognized option: %s\n",
+ ERROR("Unrecognized option: %s\n",
argv[optind - 1]);
errorcnt++;
break;
case ':':
- fprintf(stderr, "Missing argument to -%c\n", optopt);
+ ERROR("Missing argument to -%c\n", optopt);
errorcnt++;
break;
case 0: /* handled option */
@@ -1002,7 +995,7 @@ static int do_sign(int argc, char *argv[])
if (!infile) {
if (argc - optind <= 0) {
errorcnt++;
- fprintf(stderr, "ERROR: missing input filename\n");
+ ERROR("Missing input filename\n");
goto done;
} else {
sign_option.inout_file_count++;
@@ -1043,8 +1036,7 @@ static int do_sign(int argc, char *argv[])
case FILE_TYPE_PUBKEY:
sign_option.create_new_outfile = 1;
if (sign_option.signprivate && sign_option.pem_signpriv) {
- fprintf(stderr,
- "Only one of --signprivate and --pem_signpriv"
+ ERROR("Only one of --signprivate and --pem_signpriv"
" can be specified\n");
errorcnt++;
}
@@ -1052,12 +1044,12 @@ static int do_sign(int argc, char *argv[])
sign_option.pem_algo_specified) ||
(sign_option.pem_signpriv &&
!sign_option.pem_algo_specified)) {
- fprintf(stderr, "--pem_algo must be used with"
+ ERROR("--pem_algo must be used with"
" --pem_signpriv\n");
errorcnt++;
}
if (sign_option.pem_external && !sign_option.pem_signpriv) {
- fprintf(stderr, "--pem_external must be used with"
+ ERROR("--pem_external must be used with"
" --pem_signpriv\n");
errorcnt++;
}
@@ -1119,7 +1111,7 @@ static int do_sign(int argc, char *argv[])
if (!sign_option.outfile) {
if (sign_option.create_new_outfile) {
errorcnt++;
- fprintf(stderr, "Missing output filename\n");
+ ERROR("Missing output filename\n");
goto done;
} else {
sign_option.outfile = infile;
@@ -1130,7 +1122,7 @@ static int do_sign(int argc, char *argv[])
if (argc - optind > 0) {
errorcnt++;
- fprintf(stderr, "ERROR: too many arguments left over\n");
+ ERROR("Too many arguments left over\n");
}
if (errorcnt)
@@ -1153,7 +1145,7 @@ done:
vb2_private_key_free(sign_option.prikey);
if (errorcnt)
- fprintf(stderr, "Use --help for usage instructions\n");
+ ERROR("Use --help for usage instructions\n");
return !!errorcnt;
}
diff --git a/futility/cmd_vbutil_firmware.c b/futility/cmd_vbutil_firmware.c
index f31413c4..9e3298ac 100644
--- a/futility/cmd_vbutil_firmware.c
+++ b/futility/cmd_vbutil_firmware.c
@@ -207,11 +207,11 @@ static int do_verify(const char *infile, const char *signpubkey,
uint32_t pubklen;
struct vb2_public_key sign_key;
if (VB2_SUCCESS != vb2_read_file(signpubkey, &pubkbuf, &pubklen)) {
- fprintf(stderr, "Error reading signpubkey.\n");
+ ERROR("Reading signpubkey.\n");
goto verify_cleanup;
}
if (VB2_SUCCESS != vb2_unpack_key_buffer(&sign_key, pubkbuf, pubklen)) {
- fprintf(stderr, "Error unpacking signpubkey.\n");
+ ERROR("Unpacking signpubkey.\n");
goto verify_cleanup;
}
@@ -254,7 +254,7 @@ static int do_verify(const char *infile, const char *signpubkey,
struct vb2_public_key data_key;
if (VB2_SUCCESS !=
vb2_unpack_key(&data_key, &keyblock->data_key)) {
- fprintf(stderr, "Error parsing data key.\n");
+ ERROR("Parsing data key.\n");
goto verify_cleanup;
}
@@ -405,7 +405,7 @@ static int do_vbutil_firmware(int argc, char *argv[])
case OPT_MODE_VERIFY:
return do_verify(filename, signpubkey, fv_file, kernelkey_file);
default:
- fprintf(stderr, "Must specify a mode.\n");
+ ERROR("Must specify a mode.\n");
print_help(argc, argv);
return 1;
}
diff --git a/futility/cmd_vbutil_kernel.c b/futility/cmd_vbutil_kernel.c
index e0397cf5..0f470ccc 100644
--- a/futility/cmd_vbutil_kernel.c
+++ b/futility/cmd_vbutil_kernel.c
@@ -272,8 +272,7 @@ static int do_vbutil_kernel(int argc, char *argv[])
case OPT_MODE_VERIFY:
case OPT_MODE_GET_VMLINUZ:
if (mode && (mode != i)) {
- fprintf(stderr,
- "Only one mode can be specified\n");
+ ERROR("Only one mode can be specified\n");
parse_error = 1;
break;
}
@@ -293,9 +292,7 @@ static int do_vbutil_kernel(int argc, char *argv[])
else if (!strcasecmp(optarg, "mips"))
arch = ARCH_MIPS;
else {
- fprintf(stderr,
- "Unknown architecture string: %s\n",
- optarg);
+ ERROR("Unknown architecture string: %s\n", optarg);
parse_error = 1;
}
break;
@@ -307,7 +304,7 @@ static int do_vbutil_kernel(int argc, char *argv[])
case OPT_KLOADADDR:
kernel_body_load_address = strtoul(optarg, &e, 0);
if (!*optarg || (e && *e)) {
- fprintf(stderr, "Invalid --kloadaddr\n");
+ ERROR("Invalid --kloadaddr\n");
parse_error = 1;
}
break;
@@ -331,7 +328,7 @@ static int do_vbutil_kernel(int argc, char *argv[])
case OPT_FLAGS:
flags = (uint32_t)strtoul(optarg, &e, 0);
if (!*optarg || (e && *e)) {
- fprintf(stderr, "Invalid --flags\n");
+ ERROR("Invalid --flags\n");
parse_error = 1;
}
break;
@@ -352,7 +349,7 @@ static int do_vbutil_kernel(int argc, char *argv[])
version_str = optarg;
version = strtoul(optarg, &e, 0);
if (!*optarg || (e && *e)) {
- fprintf(stderr, "Invalid --version\n");
+ ERROR("Invalid --version\n");
parse_error = 1;
}
break;
@@ -360,7 +357,7 @@ static int do_vbutil_kernel(int argc, char *argv[])
case OPT_MINVERSION:
min_version = strtoul(optarg, &e, 0);
if (!*optarg || (e && *e)) {
- fprintf(stderr, "Invalid --minversion\n");
+ ERROR("Invalid --minversion\n");
parse_error = 1;
}
break;
@@ -368,7 +365,7 @@ static int do_vbutil_kernel(int argc, char *argv[])
case OPT_PAD:
opt_pad = strtoul(optarg, &e, 0);
if (!*optarg || (e && *e)) {
- fprintf(stderr, "Invalid --pad\n");
+ ERROR("Invalid --pad\n");
parse_error = 1;
}
break;
@@ -571,8 +568,7 @@ static int do_vbutil_kernel(int argc, char *argv[])
case OPT_MODE_GET_VMLINUZ:
if (!vmlinuz_out_file) {
- fprintf(stderr,
- "USE: vbutil_kernel --get-vmlinuz <file> "
+ ERROR("USE: vbutil_kernel --get-vmlinuz <file> "
"--vmlinuz-out <file>\n");
print_help(argc, argv);
return 1;
@@ -641,8 +637,7 @@ static int do_vbutil_kernel(int argc, char *argv[])
return 0;
}
- fprintf(stderr,
- "You must specify a mode: "
+ ERROR("You must specify a mode: "
"--pack, --repack, --verify, or --get-vmlinuz\n");
print_help(argc, argv);
return 1;
diff --git a/futility/cmd_vbutil_key.c b/futility/cmd_vbutil_key.c
index eeda603b..e98066c1 100644
--- a/futility/cmd_vbutil_key.c
+++ b/futility/cmd_vbutil_key.c
@@ -73,7 +73,7 @@ static int do_pack(const char *infile, const char *outfile, uint32_t algorithm,
uint32_t version)
{
if (!infile || !outfile) {
- fprintf(stderr, "vbutil_key: Must specify --in and --out\n");
+ ERROR("vbutil_key: Must specify --in and --out\n");
return 1;
}
@@ -81,7 +81,7 @@ static int do_pack(const char *infile, const char *outfile, uint32_t algorithm,
vb2_read_packed_keyb(infile, algorithm, version);
if (pubkey) {
if (0 != vb2_write_packed_key(outfile, pubkey)) {
- fprintf(stderr, "vbutil_key: Error writing key.\n");
+ ERROR("vbutil_key: Error writing key.\n");
free(pubkey);
return 1;
}
@@ -93,7 +93,7 @@ static int do_pack(const char *infile, const char *outfile, uint32_t algorithm,
vb2_read_private_key_pem(infile, algorithm);
if (privkey) {
if (VB2_SUCCESS != vb2_write_private_key(outfile, privkey)) {
- fprintf(stderr, "vbutil_key: Error writing key.\n");
+ ERROR("vbutil_key: Error writing key.\n");
free(privkey);
return 1;
}
@@ -111,7 +111,7 @@ static int do_unpack(const char *infile, const char *outfile)
struct vb2_packed_key *pubkey;
if (!infile) {
- fprintf(stderr, "Need file to unpack\n");
+ ERROR("Need file to unpack\n");
return 1;
}
@@ -125,7 +125,7 @@ static int do_unpack(const char *infile, const char *outfile)
packed_key_sha1_string(pubkey));
if (outfile &&
VB2_SUCCESS != vb2_write_packed_key(outfile, pubkey)) {
- fprintf(stderr, "butil_key: Error writing key copy\n");
+ ERROR("butil_key: Error writing key copy\n");
free(pubkey);
return 1;
}
@@ -144,7 +144,7 @@ static int do_unpack(const char *infile, const char *outfile)
vb2_get_crypto_algorithm_name(alg));
if (outfile &&
VB2_SUCCESS != vb2_write_private_key(outfile, privkey)) {
- fprintf(stderr,"vbutil_key: Error writing key copy\n");
+ ERROR("vbutil_key: Error writing key copy\n");
free(privkey);
return 1;
}
diff --git a/futility/cmd_vbutil_keyblock.c b/futility/cmd_vbutil_keyblock.c
index 197c0337..55734e16 100644
--- a/futility/cmd_vbutil_keyblock.c
+++ b/futility/cmd_vbutil_keyblock.c
@@ -91,26 +91,23 @@ static int Pack(const char *outfile, const char *datapubkey,
struct vb2_keyblock *block;
if (!outfile) {
- fprintf(stderr,
- "vbutil_keyblock: Must specify output filename.\n");
+ ERROR("vbutil_keyblock: Must specify output filename.\n");
return 1;
}
if (!datapubkey) {
- fprintf(stderr,
- "vbutil_keyblock: Must specify data public key.\n");
+ ERROR("vbutil_keyblock: Must specify data public key.\n");
return 1;
}
struct vb2_packed_key *data_key = vb2_read_packed_key(datapubkey);
if (!data_key) {
- fprintf(stderr, "vbutil_keyblock: Error reading data key.\n");
+ ERROR("vbutil_keyblock: Error reading data key.\n");
return 1;
}
if (signprivate_pem) {
if (pem_algorithm >= VB2_ALG_COUNT) {
- fprintf(stderr,
- "vbutil_keyblock: Invalid --pem_algorithm %"
+ ERROR("vbutil_keyblock: Invalid --pem_algorithm %"
PRIu64 "\n", pem_algorithm);
return 1;
}
@@ -126,7 +123,7 @@ static int Pack(const char *outfile, const char *datapubkey,
vb2_read_private_key_pem(signprivate_pem,
pem_algorithm);
if (!signing_key) {
- fprintf(stderr, "vbutil_keyblock:"
+ ERROR("vbutil_keyblock:"
" Error reading signing key.\n");
return 1;
}
@@ -137,7 +134,7 @@ static int Pack(const char *outfile, const char *datapubkey,
if (signprivate) {
signing_key = vb2_read_private_key(signprivate);
if (!signing_key) {
- fprintf(stderr, "vbutil_keyblock:"
+ ERROR("vbutil_keyblock:"
" Error reading signing key.\n");
return 1;
}
@@ -150,7 +147,7 @@ static int Pack(const char *outfile, const char *datapubkey,
free(signing_key);
if (VB2_SUCCESS != vb2_write_keyblock(outfile, block)) {
- fprintf(stderr, "vbutil_keyblock: Error writing keyblock.\n");
+ ERROR("vbutil_keyblock: Error writing keyblock.\n");
return 1;
}
free(block);
@@ -163,13 +160,13 @@ static int Unpack(const char *infile, const char *datapubkey,
struct vb2_packed_key *sign_key = NULL;
if (!infile) {
- fprintf(stderr, "vbutil_keyblock: Must specify filename\n");
+ ERROR("vbutil_keyblock: Must specify filename\n");
return 1;
}
struct vb2_keyblock *block = vb2_read_keyblock(infile);
if (!block) {
- fprintf(stderr, "vbutil_keyblock: Error reading keyblock.\n");
+ ERROR("vbutil_keyblock: Error reading keyblock.\n");
return 1;
}
@@ -181,8 +178,7 @@ static int Unpack(const char *infile, const char *datapubkey,
static struct vb2_workbuf wb;
if (block->keyblock_signature.sig_size == 0) {
- fprintf(stderr,
- "vbutil_keyblock: signpubkey provided but keyblock is not signed.\n");
+ ERROR("vbutil_keyblock: signpubkey provided but keyblock is not signed.\n");
return 1;
}
@@ -190,22 +186,19 @@ static int Unpack(const char *infile, const char *datapubkey,
sign_key = vb2_read_packed_key(signpubkey);
if (!sign_key) {
- fprintf(stderr,
- "vbutil_keyblock: Error reading signpubkey.\n");
+ ERROR("vbutil_keyblock: Error reading signpubkey.\n");
return 1;
}
struct vb2_public_key key;
if (VB2_SUCCESS != vb2_unpack_key(&key, sign_key)) {
- fprintf(stderr,
- "vbutil_keyblock: Error reading signpubkey.\n");
+ ERROR("vbutil_keyblock: Error reading signpubkey.\n");
return 1;
}
if (VB2_SUCCESS !=
vb2_verify_keyblock(block, block->keyblock_size,
&key, &wb)) {
- fprintf(stderr, "vbutil_keyblock:"
- " Error verifying keyblock.\n");
+ ERROR("vbutil_keyblock: Error verifying keyblock.\n");
return 1;
}
free(sign_key);
@@ -237,7 +230,7 @@ static int Unpack(const char *infile, const char *datapubkey,
if (datapubkey &&
VB2_SUCCESS != vb2_write_packed_key(datapubkey, data_key)) {
- fprintf(stderr, "vbutil_keyblock: error writing public key\n");
+ ERROR("vbutil_keyblock: error writing public key\n");
return 1;
}
@@ -298,7 +291,7 @@ static int do_vbutil_keyblock(int argc, char *argv[])
case OPT_PEM_ALGORITHM:
pem_algorithm = strtoul(optarg, &e, 0);
if (!*optarg || (e && *e)) {
- fprintf(stderr, "Invalid --pem_algorithm\n");
+ ERROR("Invalid --pem_algorithm\n");
parse_error = 1;
} else {
is_pem_algorithm = 1;
@@ -312,7 +305,7 @@ static int do_vbutil_keyblock(int argc, char *argv[])
case OPT_FLAGS:
flags = strtoul(optarg, &e, 0);
if (!*optarg || (e && *e)) {
- fprintf(stderr, "Invalid --flags\n");
+ ERROR("Invalid --flags\n");
parse_error = 1;
}
break;
@@ -321,22 +314,19 @@ static int do_vbutil_keyblock(int argc, char *argv[])
/* Check if the right combination of options was provided. */
if (signprivate && signprivate_pem) {
- fprintf(stderr,
- "Only one of --signprivate or --signprivate_pem must"
+ ERROR("Only one of --signprivate or --signprivate_pem must"
" be specified\n");
parse_error = 1;
}
if (signprivate_pem && !is_pem_algorithm) {
- fprintf(stderr, "--pem_algorithm must be used with"
+ ERROR("--pem_algorithm must be used with"
" --signprivate_pem\n");
parse_error = 1;
}
if (external_signer && !signprivate_pem) {
- fprintf(stderr,
- "--externalsigner must be used with --signprivate_pem"
- "\n");
+ ERROR("--externalsigner must be used with --signprivate_pem\n");
parse_error = 1;
}