summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/2lib/2stub.c2
-rw-r--r--firmware/2lib/include/2common.h9
-rw-r--r--futility/cmd_sign.c27
-rw-r--r--futility/cmd_vbutil_kernel.c20
-rw-r--r--futility/file_type_bios.c19
-rw-r--r--futility/file_type_rwsig.c54
-rw-r--r--futility/file_type_usbpd1.c34
-rw-r--r--futility/futility.c6
-rw-r--r--futility/futility.h1
-rw-r--r--futility/misc.c6
-rw-r--r--futility/vb1_helper.c100
11 files changed, 135 insertions, 143 deletions
diff --git a/firmware/2lib/2stub.c b/firmware/2lib/2stub.c
index 2e08de97..0ff1997e 100644
--- a/firmware/2lib/2stub.c
+++ b/firmware/2lib/2stub.c
@@ -14,12 +14,14 @@
__attribute__((weak))
void vb2ex_printf(const char *func, const char *fmt, ...)
{
+#ifdef VBOOT_DEBUG
va_list ap;
va_start(ap, fmt);
if (func)
fprintf(stderr, "%s: ", func);
vfprintf(stderr, fmt, ap);
va_end(ap);
+#endif
}
__attribute__((weak))
diff --git a/firmware/2lib/include/2common.h b/firmware/2lib/include/2common.h
index 7bd89075..0a6dccd2 100644
--- a/firmware/2lib/include/2common.h
+++ b/firmware/2lib/include/2common.h
@@ -30,13 +30,8 @@ struct vb2_public_key;
#endif
/* Platform-dependent debug output macros. */
-#if defined(VBOOT_DEBUG)
-# define VB2_DEBUG(format, args...) vb2ex_printf(__func__, format, ## args)
-# define VB2_DEBUG_RAW(format, args...) vb2ex_printf(NULL, format, ## args)
-#else
-# define VB2_DEBUG(format, args...)
-# define VB2_DEBUG_RAW(format, args...)
-#endif
+#define VB2_DEBUG(format, args...) vb2ex_printf(__func__, format, ## args)
+#define VB2_DEBUG_RAW(format, args...) vb2ex_printf(NULL, format, ## args)
/*
* Define test_mockable and for mocking functions when compiled for Chrome OS
diff --git a/futility/cmd_sign.c b/futility/cmd_sign.c
index e084cb27..cc2b3e62 100644
--- a/futility/cmd_sign.c
+++ b/futility/cmd_sign.c
@@ -124,7 +124,7 @@ int ft_sign_raw_kernel(const char *name, uint8_t *buf, uint32_t len,
fprintf(stderr, "Unable to create kernel blob\n");
return 1;
}
- Debug("kblob_size = 0x%x\n", kblob_size);
+ VB2_DEBUG("kblob_size = 0x%x\n", kblob_size);
vblock_data = SignKernelBlob(kblob_data, kblob_size,
sign_option.padding,
@@ -138,7 +138,7 @@ int ft_sign_raw_kernel(const char *name, uint8_t *buf, uint32_t len,
free(kblob_data);
return 1;
}
- Debug("vblock_size = 0x%x\n", vblock_size);
+ VB2_DEBUG("vblock_size = 0x%x\n", vblock_size);
/* We should be creating a completely new output file.
* If not, something's wrong. */
@@ -225,7 +225,7 @@ int ft_sign_kern_preamble(const char *name, uint8_t *buf, uint32_t len,
fprintf(stderr, "Unable to sign kernel blob\n");
return 1;
}
- Debug("vblock_size = 0x%" PRIx64 "\n", vblock_size);
+ VB2_DEBUG("vblock_size = 0x%" PRIx64 "\n", vblock_size);
if (sign_option.create_new_outfile) {
/* Write out what we've been asked for */
@@ -739,7 +739,7 @@ static int do_sign(int argc, char *argv[])
strerror(errno));
errorcnt++;
}
- Debug("bootloader file size=0x%" PRIx64 "\n",
+ VB2_DEBUG("bootloader file size=0x%" PRIx64 "\n",
sign_option.bootloader_size);
break;
case OPT_CONFIG:
@@ -862,7 +862,7 @@ static int do_sign(int argc, char *argv[])
case 0: /* handled option */
break;
default:
- Debug("i=%d\n", i);
+ VB2_DEBUG("i=%d\n", i);
DIE;
}
}
@@ -911,7 +911,7 @@ static int do_sign(int argc, char *argv[])
sign_option.type = FILE_TYPE_RAW_FIRMWARE;
}
- Debug("type=%s\n", futil_file_type_name(sign_option.type));
+ VB2_DEBUG("type=%s\n", futil_file_type_name(sign_option.type));
/* Check the arguments for the type of thing we want to sign */
switch (sign_option.type) {
@@ -985,10 +985,11 @@ static int do_sign(int argc, char *argv[])
break;
}
- Debug("infile=%s\n", infile);
- Debug("sign_option.inout_file_count=%d\n", sign_option.inout_file_count);
- Debug("sign_option.create_new_outfile=%d\n",
- sign_option.create_new_outfile);
+ VB2_DEBUG("infile=%s\n", infile);
+ VB2_DEBUG("sign_option.inout_file_count=%d\n",
+ sign_option.inout_file_count);
+ VB2_DEBUG("sign_option.create_new_outfile=%d\n",
+ sign_option.create_new_outfile);
/* Make sure we have an output file if one is needed */
if (!sign_option.outfile) {
@@ -1001,7 +1002,7 @@ static int do_sign(int argc, char *argv[])
}
}
- Debug("sign_option.outfile=%s\n", sign_option.outfile);
+ VB2_DEBUG("sign_option.outfile=%s\n", sign_option.outfile);
if (argc - optind > 0) {
errorcnt++;
@@ -1014,7 +1015,7 @@ static int do_sign(int argc, char *argv[])
if (sign_option.create_new_outfile) {
/* The input is read-only, the output is write-only. */
mapping = MAP_RO;
- Debug("open RO %s\n", infile);
+ VB2_DEBUG("open RO %s\n", infile);
ifd = open(infile, O_RDONLY);
if (ifd < 0) {
errorcnt++;
@@ -1027,7 +1028,7 @@ static int do_sign(int argc, char *argv[])
mapping = MAP_RW;
if (sign_option.inout_file_count > 1)
futil_copy_file_or_die(infile, sign_option.outfile);
- Debug("open RW %s\n", sign_option.outfile);
+ VB2_DEBUG("open RW %s\n", sign_option.outfile);
infile = sign_option.outfile;
ifd = open(sign_option.outfile, O_RDWR);
if (ifd < 0) {
diff --git a/futility/cmd_vbutil_kernel.c b/futility/cmd_vbutil_kernel.c
index 0f6502a7..a5bacdda 100644
--- a/futility/cmd_vbutil_kernel.c
+++ b/futility/cmd_vbutil_kernel.c
@@ -195,11 +195,11 @@ static uint8_t *ReadOldKPartFromFileOrDie(const char *filename,
} else {
file_size = statbuf.st_size;
}
- Debug("%s size is 0x%x\n", filename, file_size);
+ VB2_DEBUG("%s size is 0x%x\n", filename, file_size);
if (file_size < opt_pad)
Fatal("%s is too small to be a valid kernel blob\n", filename);
- Debug("Reading %s\n", filename);
+ VB2_DEBUG("Reading %s\n", filename);
fp = fopen(filename, "rb");
if (!fp)
Fatal("Unable to open file %s: %s\n", filename,
@@ -415,7 +415,7 @@ static int do_vbutil_kernel(int argc, char *argv[])
if (!config_file)
Fatal("Missing required config file.\n");
- Debug("Reading %s\n", config_file);
+ VB2_DEBUG("Reading %s\n", config_file);
t_config_data =
ReadConfigFile(config_file, &t_config_size);
if (!t_config_data)
@@ -424,23 +424,23 @@ static int do_vbutil_kernel(int argc, char *argv[])
if (!bootloader_file)
Fatal("Missing required bootloader file.\n");
- Debug("Reading %s\n", bootloader_file);
+ VB2_DEBUG("Reading %s\n", bootloader_file);
if (VB2_SUCCESS != vb2_read_file(bootloader_file,
&t_bootloader_data,
&t_bootloader_size))
Fatal("Error reading bootloader file.\n");
- Debug(" bootloader file size=0x%x\n", t_bootloader_size);
+ VB2_DEBUG(" bootloader file size=0x%x\n", t_bootloader_size);
if (!vmlinuz_file)
Fatal("Missing required vmlinuz file.\n");
- Debug("Reading %s\n", vmlinuz_file);
+ VB2_DEBUG("Reading %s\n", vmlinuz_file);
if (VB2_SUCCESS !=
vb2_read_file(vmlinuz_file, &vmlinuz_buf, &vmlinuz_size))
Fatal("Error reading vmlinuz file.\n");
- Debug(" vmlinuz file size=0x%x\n", vmlinuz_size);
+ VB2_DEBUG(" vmlinuz file size=0x%x\n", vmlinuz_size);
if (!vmlinuz_size)
Fatal("Empty vmlinuz file\n");
@@ -453,7 +453,7 @@ static int do_vbutil_kernel(int argc, char *argv[])
if (!kblob_data)
Fatal("Unable to create kernel blob\n");
- Debug("kblob_size = 0x%x\n", kblob_size);
+ VB2_DEBUG("kblob_size = 0x%x\n", kblob_size);
vblock_data = SignKernelBlob(kblob_data, kblob_size, opt_pad,
version, kernel_body_load_address,
@@ -462,7 +462,7 @@ static int do_vbutil_kernel(int argc, char *argv[])
if (!vblock_data)
Fatal("Unable to sign kernel blob\n");
- Debug("vblock_size = 0x%x\n", vblock_size);
+ VB2_DEBUG("vblock_size = 0x%x\n", vblock_size);
if (opt_vblockonly)
rv = WriteSomeParts(filename,
@@ -513,7 +513,7 @@ static int do_vbutil_kernel(int argc, char *argv[])
/* Update the config if asked */
if (config_file) {
- Debug("Reading %s\n", config_file);
+ VB2_DEBUG("Reading %s\n", config_file);
t_config_data =
ReadConfigFile(config_file, &t_config_size);
if (!t_config_data)
diff --git a/futility/file_type_bios.c b/futility/file_type_bios.c
index ce6371d2..e9e0b772 100644
--- a/futility/file_type_bios.c
+++ b/futility/file_type_bios.c
@@ -42,9 +42,8 @@ static void fmap_limit_area(FmapAreaHeader *ah, uint32_t len)
{
uint32_t sum = ah->area_offset + ah->area_size;
if (sum < ah->area_size || sum > len) {
- Debug("%s(%s) 0x%x + 0x%x > 0x%x\n",
- __func__, ah->area_name,
- ah->area_offset, ah->area_size, len);
+ VB2_DEBUG("%s 0x%x + 0x%x > 0x%x\n",
+ ah->area_name, ah->area_offset, ah->area_size, len);
ah->area_offset = 0;
ah->area_size = 0;
}
@@ -222,10 +221,9 @@ int ft_show_bios(const char *name, uint8_t *buf, uint32_t len, void *data)
state.area[c].buf = buf + ah->area_offset;
state.area[c].len = ah->area_size;
- Debug("%s() showing FMAP area %d (%s),"
- " offset=0x%08x len=0x%08x\n",
- __func__, c, ah_name,
- ah->area_offset, ah->area_size);
+ VB2_DEBUG("showing FMAP area %d (%s),"
+ " offset=0x%08x len=0x%08x\n",
+ c, ah_name, ah->area_offset, ah->area_size);
/* Go look at it. */
if (fmap_show_fn[c])
@@ -483,10 +481,9 @@ int ft_sign_bios(const char *name, uint8_t *buf, uint32_t len, void *data)
state.area[c].buf = buf + ah->area_offset;
state.area[c].len = ah->area_size;
- Debug("%s() examining FMAP area %d (%s),"
- " offset=0x%08x len=0x%08x\n",
- __func__, c, ah_name,
- ah->area_offset, ah->area_size);
+ VB2_DEBUG("%s() examining FMAP area %d (%s),"
+ " offset=0x%08x len=0x%08x\n",
+ c, ah_name, ah->area_offset, ah->area_size);
/* Go look at it, but abort on error */
if (fmap_sign_fn[c])
diff --git a/futility/file_type_rwsig.c b/futility/file_type_rwsig.c
index e2288f15..0776f26d 100644
--- a/futility/file_type_rwsig.c
+++ b/futility/file_type_rwsig.c
@@ -75,11 +75,10 @@ int ft_show_rwsig(const char *name, uint8_t *buf, uint32_t len, void *nuthin)
FmapHeader *fmap;
int i;
- Debug("%s(): name %s\n", __func__, name);
- Debug("%s(): len 0x%08x (%d)\n", __func__, len, len);
+ VB2_DEBUG("name %s len 0x%08x (%d)\n", name, len, len);
/* Am I just looking at a signature file? */
- Debug("Looking for signature at 0x0\n");
+ VB2_DEBUG("Looking for signature at 0x0\n");
sig = (const struct vb21_signature *)buf;
if (VB2_SUCCESS == vb21_verify_signature(sig, len)) {
show_sig(name, sig);
@@ -94,7 +93,7 @@ int ft_show_rwsig(const char *name, uint8_t *buf, uint32_t len, void *nuthin)
/* This looks like a full image. */
FmapAreaHeader *fmaparea;
- Debug("Found an FMAP!\n");
+ VB2_DEBUG("Found an FMAP!\n");
/* If no public key is provided, use the one packed in RO
* image, and print that. */
@@ -110,14 +109,14 @@ int ft_show_rwsig(const char *name, uint8_t *buf, uint32_t len, void *nuthin)
sig = (const struct vb21_signature *)
fmap_find_by_name(buf, len, fmap, "SIG_RW", &fmaparea);
if (!sig) {
- Debug("No SIG_RW in FMAP.\n");
+ VB2_DEBUG("No SIG_RW in FMAP.\n");
return 1;
}
sig_size = fmaparea->area_size;
- Debug("Looking for signature at 0x%x (0x%x)\n",
- (uint8_t*)sig - buf, sig_size);
+ VB2_DEBUG("Looking for signature at 0x%x (0x%x)\n",
+ (uint8_t*)sig - buf, sig_size);
if (VB2_SUCCESS != vb21_verify_signature(sig, sig_size))
return 1;
@@ -132,7 +131,7 @@ int ft_show_rwsig(const char *name, uint8_t *buf, uint32_t len, void *nuthin)
total_data_size = fmaparea->area_size-sig_size;
if (!data) {
- Debug("No EC_RW in FMAP.\n");
+ VB2_DEBUG("No EC_RW in FMAP.\n");
return 1;
}
} else {
@@ -141,10 +140,10 @@ int ft_show_rwsig(const char *name, uint8_t *buf, uint32_t len, void *nuthin)
if (show_option.sig_size)
sig_size = show_option.sig_size;
- Debug("Looking for signature at 0x%x\n", len - sig_size);
+ VB2_DEBUG("Looking for signature at 0x%x\n", len - sig_size);
if (len < sig_size) {
- Debug("File is too small\n");
+ VB2_DEBUG("File is too small\n");
return 1;
}
@@ -168,12 +167,12 @@ int ft_show_rwsig(const char *name, uint8_t *buf, uint32_t len, void *nuthin)
if (vb21_unpack_key(&key,
(const uint8_t *)pkey,
pkey->c.total_size)) {
- Debug("Can't unpack pubkey\n");
+ VB2_DEBUG("Can't unpack pubkey\n");
return 1;
}
if (data_size > total_data_size) {
- Debug("Invalid signature data_size: bigger than total area size.\n");
+ VB2_DEBUG("Invalid signature data_size: bigger than total area size.\n");
return 1;
}
@@ -219,8 +218,7 @@ int ft_sign_rwsig(const char *name, uint8_t *buf, uint32_t len, void *nuthin)
FmapAreaHeader *fmaparea;
struct vb21_signature *old_sig = 0;
- Debug("%s(): name %s\n", __func__, name);
- Debug("%s(): len 0x%08x (%d)\n", __func__, len, len);
+ VB2_DEBUG("name %s len 0x%08x (%d)\n", name, len, len);
/* If we don't have a distinct OUTFILE, look for an existing sig */
if (sign_option.inout_file_count < 2) {
@@ -228,25 +226,25 @@ int ft_sign_rwsig(const char *name, uint8_t *buf, uint32_t len, void *nuthin)
if (fmap) {
/* This looks like a full image. */
- Debug("Found an FMAP!\n");
+ VB2_DEBUG("Found an FMAP!\n");
old_sig = (struct vb21_signature *)
fmap_find_by_name(buf, len, fmap, "SIG_RW",
&fmaparea);
if (!old_sig) {
- Debug("No SIG_RW in FMAP.\n");
+ VB2_DEBUG("No SIG_RW in FMAP.\n");
goto done;
}
sig_size = fmaparea->area_size;
- Debug("Looking for signature at 0x%x (0x%x)\n",
- (uint8_t*)old_sig - buf, sig_size);
+ VB2_DEBUG("Looking for signature at 0x%x (0x%x)\n",
+ (uint8_t*)old_sig - buf, sig_size);
data = fmap_find_by_name(buf, len, fmap, "EC_RW",
&fmaparea);
if (!data) {
- Debug("No EC_RW in FMAP.\n");
+ VB2_DEBUG("No EC_RW in FMAP.\n");
goto done;
}
} else {
@@ -255,8 +253,8 @@ int ft_sign_rwsig(const char *name, uint8_t *buf, uint32_t len, void *nuthin)
if (sign_option.sig_size)
sig_size = sign_option.sig_size;
- Debug("Looking for old signature at 0x%x\n",
- len - sig_size);
+ VB2_DEBUG("Looking for old signature at 0x%x\n",
+ len - sig_size);
if (len < sig_size) {
fprintf(stderr, "File is too small\n");
@@ -276,8 +274,8 @@ int ft_sign_rwsig(const char *name, uint8_t *buf, uint32_t len, void *nuthin)
/* Use the same extent again */
data_size = old_sig->data_size;
- Debug("Found sig: data_size is 0x%x (%d)\n", data_size,
- data_size);
+ VB2_DEBUG("Found sig: data_size is 0x%x (%d)\n", data_size,
+ data_size);
}
/* Unless overridden */
@@ -294,7 +292,7 @@ int ft_sign_rwsig(const char *name, uint8_t *buf, uint32_t len, void *nuthin)
goto done;
}
} else {
- Debug("Private key not provided. Copying previous signature\n");
+ VB2_DEBUG("Private key not provided. Copying previous signature\n");
if (!old_sig) {
/* This isn't necessary because no prikey mode runs only
* for fmap input or RW input */
@@ -314,12 +312,12 @@ int ft_sign_rwsig(const char *name, uint8_t *buf, uint32_t len, void *nuthin)
tmp_sig->c.total_size, sig_size);
goto done;
}
- Debug("Replacing old signature with new one\n");
+ VB2_DEBUG("Replacing old signature with new one\n");
memset(old_sig, 0xff, sig_size);
memcpy(old_sig, tmp_sig, tmp_sig->c.total_size);
if (fmap) {
- Debug("Writing %s (size=%d)\n",
- EC_RW_FILENAME, fmaparea->area_size);
+ VB2_DEBUG("Writing %s (size=%d)\n",
+ EC_RW_FILENAME, fmaparea->area_size);
if (vb2_write_file(EC_RW_FILENAME,
data, fmaparea->area_size))
goto done;
@@ -383,7 +381,7 @@ int ft_sign_rwsig(const char *name, uint8_t *buf, uint32_t len, void *nuthin)
new_pubkey = fmap_find_by_name(buf, len, fmap, "KEY_RO",
&fmaparea);
if (!new_pubkey) {
- Debug("No KEY_RO in FMAP.\n");
+ VB2_DEBUG("No KEY_RO in FMAP.\n");
goto done;
}
/* Overwrite the old signature */
diff --git a/futility/file_type_usbpd1.c b/futility/file_type_usbpd1.c
index 131e0033..d285ff86 100644
--- a/futility/file_type_usbpd1.c
+++ b/futility/file_type_usbpd1.c
@@ -61,10 +61,10 @@ static int parse_size_opts(uint32_t len,
if (sign_option.rw_offset != 0xffffffff)
rw_offset = sign_option.rw_offset;
- Debug("ro_size 0x%08x\n", ro_size);
- Debug("ro_offset 0x%08x\n", ro_offset);
- Debug("rw_size 0x%08x\n", rw_size);
- Debug("rw_offset 0x%08x\n", rw_offset);
+ VB2_DEBUG("ro_size 0x%08x\n", ro_size);
+ VB2_DEBUG("ro_offset 0x%08x\n", ro_offset);
+ VB2_DEBUG("rw_size 0x%08x\n", rw_size);
+ VB2_DEBUG("rw_offset 0x%08x\n", rw_offset);
/* Now let's do some sanity checks. */
if (ro_size > len || ro_offset > len - ro_size ||
@@ -98,8 +98,7 @@ int ft_sign_usbpd1(const char *name, uint8_t *buf, uint32_t len, void *data)
uint32_t rw_offset;
uint32_t r;
- Debug("%s(): name %s\n", __func__, name);
- Debug("%s(): len 0x%08x (%d)\n", __func__, len, len);
+ VB2_DEBUG("%s(): name %s len 0x%08x (%d)\n", name, len, len);
/* Get image locations */
if (!parse_size_opts(len, &ro_size, &rw_size, &ro_offset, &rw_offset))
@@ -131,10 +130,10 @@ int ft_sign_usbpd1(const char *name, uint8_t *buf, uint32_t len, void *data)
rw_size -= sig_size;
sig_offset = rw_offset + rw_size;
- Debug("rw_size => 0x%08x\n", rw_size);
- Debug("rw_offset => 0x%08x\n", rw_offset);
- Debug("sig_size 0x%08x\n", sig_size);
- Debug("sig_offset 0x%08x\n", sig_offset);
+ VB2_DEBUG("rw_size => 0x%08x\n", rw_size);
+ VB2_DEBUG("rw_offset => 0x%08x\n", rw_offset);
+ VB2_DEBUG("sig_size 0x%08x\n", sig_size);
+ VB2_DEBUG("sig_offset 0x%08x\n", sig_offset);
/* Sign the blob */
r = vb21_sign_data(&sig_ptr, buf + rw_offset, rw_size, key_ptr, "Bah");
@@ -171,7 +170,7 @@ int ft_sign_usbpd1(const char *name, uint8_t *buf, uint32_t len, void *data)
fprintf(stderr, "Couldn't extract the public key\n");
goto done;
}
- Debug("keyb_size is 0x%x (%d):\n", keyb_size, keyb_size);
+ VB2_DEBUG("keyb_size is 0x%x (%d):\n", keyb_size, keyb_size);
/*
* Of course the packed public key format is different. Why would you
@@ -217,11 +216,11 @@ int ft_sign_usbpd1(const char *name, uint8_t *buf, uint32_t len, void *data)
uint32_t dst_ofs_rr = dst_ofs_n + nbytes;
uint32_t dst_ofs_n0inv = dst_ofs_rr + nbytes;
- Debug("len 0x%08x ro_size 0x%08x ro_offset 0x%08x\n",
- len, ro_size, ro_offset);
- Debug("pub_size 0x%08x pub_offset 0x%08x nbytes 0x%08x\n",
- pub_size, pub_offset, nbytes);
- Debug("pub_pad 0x%08x\n", pub_pad);
+ VB2_DEBUG("len 0x%08x ro_size 0x%08x ro_offset 0x%08x\n",
+ len, ro_size, ro_offset);
+ VB2_DEBUG("pub_size 0x%08x pub_offset 0x%08x nbytes 0x%08x\n",
+ pub_size, pub_offset, nbytes);
+ VB2_DEBUG("pub_pad 0x%08x\n", pub_pad);
/* Copy n[nwords] */
memcpy(buf + dst_ofs_n,
@@ -435,8 +434,7 @@ int ft_show_usbpd1(const char *name, uint8_t *buf, uint32_t len, void *data)
uint32_t ro_size, rw_size, ro_offset, rw_offset;
int s, h;
- Debug("%s(): name %s\n", __func__, name);
- Debug("%s(): len 0x%08x (%d)\n", __func__, len, len);
+ VB2_DEBUG("name %s len 0x%08x (%d)\n", name, len, len);
/* Get image locations */
if (!parse_size_opts(len, &ro_size, &rw_size, &ro_offset, &rw_offset))
diff --git a/futility/futility.c b/futility/futility.c
index 6cea6814..f0a42e20 100644
--- a/futility/futility.c
+++ b/futility/futility.c
@@ -220,9 +220,9 @@ static void list_commands(void)
static int run_command(const struct futil_cmd_t *cmd, int argc, char *argv[])
{
int i;
- Debug("%s(\"%s\") ...\n", __func__, cmd->name);
+ VB2_DEBUG("\"%s\" ...\n", cmd->name);
for (i = 0; i < argc; i++)
- Debug(" argv[%d] = \"%s\"\n", i, argv[i]);
+ VB2_DEBUG(" argv[%d] = \"%s\"\n", i, argv[i]);
return cmd->handler(argc, argv);
}
@@ -347,7 +347,7 @@ int main(int argc, char *argv[], char *envp[])
case 0: /* handled option */
break;
default:
- Debug("i=%d\n", i);
+ VB2_DEBUG("i=%d\n", i);
DIE;
}
}
diff --git a/futility/futility.h b/futility/futility.h
index f5f6877e..d6f0bacf 100644
--- a/futility/futility.h
+++ b/futility/futility.h
@@ -96,7 +96,6 @@ extern const struct futil_cmd_t *const futil_cmds[];
/* Debug output (off by default) */
extern int debugging_enabled;
-void Debug(const char *format, ...);
/* Returns true if this looks enough like a GBB header to proceed. */
int futil_looks_like_gbb(GoogleBinaryBlockHeader *gbb, uint32_t len);
diff --git a/futility/misc.c b/futility/misc.c
index af291a49..cef04b06 100644
--- a/futility/misc.c
+++ b/futility/misc.c
@@ -34,14 +34,14 @@
enum vboot_version vboot_version = VBOOT_VERSION_ALL;
int debugging_enabled;
-void Debug(const char *format, ...)
+void vb2ex_printf(const char *func, const char *format, ...)
{
if (!debugging_enabled)
return;
va_list ap;
va_start(ap, format);
- fprintf(stdout, "DEBUG: ");
+ fprintf(stdout, "DEBUG:%s() ", func);
vfprintf(stdout, format, ap);
va_end(ap);
}
@@ -215,7 +215,7 @@ void futil_copy_file_or_die(const char *infile, const char *outfile)
pid_t pid;
int status;
- Debug("%s(%s, %s)\n", __func__, infile, outfile);
+ VB2_DEBUG("%s -> %s\n", infile, outfile);
pid = fork();
diff --git a/futility/vb1_helper.c b/futility/vb1_helper.c
index 18caf1f3..92cdda16 100644
--- a/futility/vb1_helper.c
+++ b/futility/vb1_helper.c
@@ -71,7 +71,7 @@ uint8_t *ReadConfigFile(const char *config_file, uint32_t *config_size)
if (VB2_SUCCESS != vb2_read_file(config_file, &config_buf, config_size))
return NULL;
- Debug(" config file size=0x%x\n", *config_size);
+ VB2_DEBUG(" config file size=0x%x\n", *config_size);
if (CROS_CONFIG_SIZE <= *config_size) { /* room for trailing '\0' */
fprintf(stderr, "Config file %s is too large (>= %d bytes)\n",
config_file, CROS_CONFIG_SIZE);
@@ -147,7 +147,7 @@ static int KernelSize(uint8_t *kernel_buf,
* a real-mode boot stub. We only want the 32-bit part. */
lh = (struct linux_kernel_params *)kernel_buf;
if (lh->header != VMLINUZ_HEADER_SIG) {
- Debug("Not a linux kernel image\n");
+ VB2_DEBUG("Not a linux kernel image\n");
return kernel_size;
}
kernel32_start = (lh->setup_sects + 1) << 9;
@@ -176,7 +176,7 @@ static int PickApartVmlinuz(uint8_t *kernel_buf,
* a real-mode boot stub. We only want the 32-bit part. */
lh = (struct linux_kernel_params *)kernel_buf;
if (lh->header != VMLINUZ_HEADER_SIG) {
- Debug("Not a linux kernel image\n");
+ VB2_DEBUG("Not a linux kernel image\n");
break;
}
kernel32_start = (lh->setup_sects + 1) << 9;
@@ -186,8 +186,8 @@ static int PickApartVmlinuz(uint8_t *kernel_buf,
}
kernel32_size = kernel_size - kernel32_start;
- Debug(" kernel16_start=0x%" PRIx64 "\n", 0);
- Debug(" kernel16_size=0x%" PRIx64 "\n", kernel32_start);
+ VB2_DEBUG(" kernel16_start=0x%" PRIx64 "\n", 0);
+ VB2_DEBUG(" kernel16_size=0x%" PRIx64 "\n", kernel32_start);
/* Copy the original zeropage data from kernel_buf into
* g_param_data, then tweak a few fields for our purposes */
@@ -204,10 +204,11 @@ static int PickApartVmlinuz(uint8_t *kernel_buf,
params->cmd_line_ptr = kernel_body_load_address +
roundup(kernel32_size, CROS_ALIGN) +
find_cmdline_start(g_config_data, g_config_size);
- Debug(" cmdline_addr=0x%x\n", params->cmd_line_ptr);
- Debug(" version=0x%x\n", params->version);
- Debug(" kernel_alignment=0x%x\n", params->kernel_alignment);
- Debug(" relocatable_kernel=0x%x\n", params->relocatable_kernel);
+ VB2_DEBUG(" cmdline_addr=0x%x\n", params->cmd_line_ptr);
+ VB2_DEBUG(" version=0x%x\n", params->version);
+ VB2_DEBUG(" kernel_alignment=0x%x\n", params->kernel_alignment);
+ VB2_DEBUG(" relocatable_kernel=0x%x\n",
+ params->relocatable_kernel);
/* Add a fake e820 memory map with 2 entries. */
params->n_e820_entry = 2;
params->e820_entries[0].start_addr = 0x00000000;
@@ -221,8 +222,8 @@ static int PickApartVmlinuz(uint8_t *kernel_buf,
break;
}
- Debug(" kernel32_start=0x%" PRIx64 "\n", kernel32_start);
- Debug(" kernel32_size=0x%" PRIx64 "\n", kernel32_size);
+ VB2_DEBUG(" kernel32_start=0x%" PRIx64 "\n", kernel32_start);
+ VB2_DEBUG(" kernel32_size=0x%" PRIx64 "\n", kernel32_size);
/* Keep just the 32-bit kernel. */
if (kernel32_size) {
@@ -255,9 +256,9 @@ static void UnpackKernelBlob(uint8_t *kernel_blob_data)
g_vmlinuz_header_size = vmlinuz_header_size;
g_vmlinuz_header_data = kernel_blob_data + now;
- Debug("vmlinuz_header_size = 0x%x\n",
- g_vmlinuz_header_size);
- Debug("vmlinuz_header_ofs = 0x%x\n", now);
+ VB2_DEBUG("vmlinuz_header_size = 0x%x\n",
+ g_vmlinuz_header_size);
+ VB2_DEBUG("vmlinuz_header_ofs = 0x%x\n", now);
}
/* Where does the bootloader stub begin? */
@@ -268,25 +269,25 @@ static void UnpackKernelBlob(uint8_t *kernel_blob_data)
g_bootloader_data = kernel_blob_data + now;
/* TODO: What to do if this is beyond the end of the blob? */
- Debug("bootloader_size = 0x%x\n", g_bootloader_size);
- Debug("bootloader_ofs = 0x%x\n", now);
+ VB2_DEBUG("bootloader_size = 0x%x\n", g_bootloader_size);
+ VB2_DEBUG("bootloader_ofs = 0x%x\n", now);
/* Before that is the params */
now -= CROS_PARAMS_SIZE;
g_param_size = CROS_PARAMS_SIZE;
g_param_data = kernel_blob_data + now;
- Debug("param_ofs = 0x%x\n", now);
+ VB2_DEBUG("param_ofs = 0x%x\n", now);
/* Before that is the config */
now -= CROS_CONFIG_SIZE;
g_config_size = CROS_CONFIG_SIZE;
g_config_data = kernel_blob_data + now;
- Debug("config_ofs = 0x%x\n", now);
+ VB2_DEBUG("config_ofs = 0x%x\n", now);
/* The kernel starts at offset 0 and extends up to the config */
g_kernel_data = kernel_blob_data;
g_kernel_size = now;
- Debug("kernel_size = 0x%x\n", g_kernel_size);
+ VB2_DEBUG("kernel_size = 0x%x\n", g_kernel_size);
}
@@ -324,7 +325,7 @@ uint8_t *unpack_kernel_partition(uint8_t *kpart_data,
/* Sanity-check the keyblock */
struct vb2_keyblock *keyblock = (struct vb2_keyblock *)kpart_data;
- Debug("Keyblock is 0x%x bytes\n", keyblock->keyblock_size);
+ VB2_DEBUG("Keyblock is 0x%x bytes\n", keyblock->keyblock_size);
now += keyblock->keyblock_size;
if (now > kpart_size) {
fprintf(stderr,
@@ -343,7 +344,7 @@ uint8_t *unpack_kernel_partition(uint8_t *kpart_data,
/* And the preamble */
preamble = (struct vb2_kernel_preamble *)(kpart_data + now);
- Debug("Preamble is 0x%x bytes\n", preamble->preamble_size);
+ VB2_DEBUG("Preamble is 0x%x bytes\n", preamble->preamble_size);
now += preamble->preamble_size;
if (now > kpart_size) {
fprintf(stderr,
@@ -356,14 +357,15 @@ uint8_t *unpack_kernel_partition(uint8_t *kpart_data,
return NULL;
}
/* LGTM */
- Debug(" kernel_version = %d\n", preamble->kernel_version);
- Debug(" bootloader_address = 0x%" PRIx64 "\n",
- preamble->bootloader_address);
- Debug(" bootloader_size = 0x%x\n", preamble->bootloader_size);
- Debug(" kern_blob_size = 0x%x\n", preamble->body_signature.data_size);
+ VB2_DEBUG(" kernel_version = %d\n", preamble->kernel_version);
+ VB2_DEBUG(" bootloader_address = 0x%" PRIx64 "\n",
+ preamble->bootloader_address);
+ VB2_DEBUG(" bootloader_size = 0x%x\n", preamble->bootloader_size);
+ VB2_DEBUG(" kern_blob_size = 0x%x\n",
+ preamble->body_signature.data_size);
uint32_t flags = vb2_kernel_get_flags(preamble);
- Debug(" flags = 0x%x\n", flags);
+ VB2_DEBUG(" flags = 0x%x\n", flags);
g_preamble = preamble;
g_ondisk_bootloader_addr = g_preamble->bootloader_address;
@@ -372,13 +374,13 @@ uint8_t *unpack_kernel_partition(uint8_t *kpart_data,
&vmlinuz_header_address,
&vmlinuz_header_size);
if (vmlinuz_header_size) {
- Debug(" vmlinuz_header_address = 0x%" PRIx64 "\n",
- vmlinuz_header_address);
- Debug(" vmlinuz_header_size = 0x%x\n", vmlinuz_header_size);
+ VB2_DEBUG(" vmlinuz_header_address = 0x%" PRIx64 "\n",
+ vmlinuz_header_address);
+ VB2_DEBUG(" vmlinuz_header_size = 0x%x\n", vmlinuz_header_size);
g_ondisk_vmlinuz_header_addr = vmlinuz_header_address;
}
- Debug("kernel blob is at offset 0x%x\n", now);
+ VB2_DEBUG("kernel blob is at offset 0x%x\n", now);
g_kernel_blob_data = kpart_data + now;
g_kernel_blob_size = preamble->body_signature.data_size;
@@ -460,8 +462,8 @@ int WriteSomeParts(const char *outfile,
FILE *f;
/* Write the output file */
- Debug("writing %s with 0x%" PRIx64 ", 0x%" PRIx64 "\n",
- outfile, part1_size, part2_size);
+ VB2_DEBUG("writing %s with 0x%" PRIx64 ", 0x%" PRIx64 "\n",
+ outfile, part1_size, part2_size);
f = fopen(outfile, "wb");
if (!f) {
@@ -666,7 +668,7 @@ uint8_t *CreateKernelBlob(uint8_t *vmlinuz_buf, uint32_t vmlinuz_size,
g_param_size +
g_bootloader_size +
g_vmlinuz_header_size;
- Debug("g_kernel_blob_size 0x%" PRIx64 "\n", g_kernel_blob_size);
+ VB2_DEBUG("g_kernel_blob_size 0x%" PRIx64 "\n", g_kernel_blob_size);
/* Allocate space for the blob. */
g_kernel_blob_data = malloc(g_kernel_blob_size);
@@ -674,38 +676,38 @@ uint8_t *CreateKernelBlob(uint8_t *vmlinuz_buf, uint32_t vmlinuz_size,
/* Assign the sub-pointers */
g_kernel_data = g_kernel_blob_data + now;
- Debug("g_kernel_size 0x%" PRIx64 " ofs 0x%" PRIx64 "\n",
- g_kernel_size, now);
+ VB2_DEBUG("g_kernel_size 0x%" PRIx64 " ofs 0x%" PRIx64 "\n",
+ g_kernel_size, now);
now += roundup(g_kernel_size, CROS_ALIGN);
g_config_data = g_kernel_blob_data + now;
- Debug("g_config_size 0x%" PRIx64 " ofs 0x%" PRIx64 "\n",
- g_config_size, now);
+ VB2_DEBUG("g_config_size 0x%" PRIx64 " ofs 0x%" PRIx64 "\n",
+ g_config_size, now);
now += g_config_size;
g_param_data = g_kernel_blob_data + now;
- Debug("g_param_size 0x%" PRIx64 " ofs 0x%" PRIx64 "\n",
- g_param_size, now);
+ VB2_DEBUG("g_param_size 0x%" PRIx64 " ofs 0x%" PRIx64 "\n",
+ g_param_size, now);
now += g_param_size;
g_bootloader_data = g_kernel_blob_data + now;
- Debug("g_bootloader_size 0x%" PRIx64 " ofs 0x%" PRIx64 "\n",
- g_bootloader_size, now);
+ VB2_DEBUG("g_bootloader_size 0x%" PRIx64 " ofs 0x%" PRIx64 "\n",
+ g_bootloader_size, now);
g_ondisk_bootloader_addr = kernel_body_load_address + now;
- Debug("g_ondisk_bootloader_addr 0x%" PRIx64 "\n",
- g_ondisk_bootloader_addr);
+ VB2_DEBUG("g_ondisk_bootloader_addr 0x%" PRIx64 "\n",
+ g_ondisk_bootloader_addr);
now += g_bootloader_size;
if (g_vmlinuz_header_size) {
g_vmlinuz_header_data = g_kernel_blob_data + now;
- Debug("g_vmlinuz_header_size 0x%" PRIx64 " ofs 0x%" PRIx64 "\n",
- g_vmlinuz_header_size, now);
+ VB2_DEBUG("g_vmlinuz_header_size 0x%" PRIx64 " ofs 0x%" PRIx64 "\n",
+ g_vmlinuz_header_size, now);
g_ondisk_vmlinuz_header_addr = kernel_body_load_address + now;
- Debug("g_ondisk_vmlinuz_header_addr 0x%" PRIx64 "\n",
- g_ondisk_vmlinuz_header_addr);
+ VB2_DEBUG("g_ondisk_vmlinuz_header_addr 0x%" PRIx64 "\n",
+ g_ondisk_vmlinuz_header_addr);
}
- Debug("end of kern_blob at kern_blob+0x%" PRIx64 "\n", now);
+ VB2_DEBUG("end of kern_blob at kern_blob+0x%" PRIx64 "\n", now);
/* Copy the kernel and params bits into the correct places */
if (0 != PickApartVmlinuz(vmlinuz_buf, vmlinuz_size,