From b343c963b38b03df97a1bc57f201e26640c89e47 Mon Sep 17 00:00:00 2001 From: Joel Kitching Date: Wed, 28 Nov 2018 17:34:22 +0800 Subject: gsctool: verbose flag should print debug messages Currently the verbose flag is stored in `verbose_mode` but never used. Print conditionally on this flag within a new `debug` function. BUG=None TEST=try running various commands with --verbose check for verbose output BRANCH=master Change-Id: Iadaf1a91ea1b02b0638e6364077c2c148f26e03c Reviewed-on: https://chromium-review.googlesource.com/1351926 Commit-Ready: Joel Kitching Tested-by: Joel Kitching Reviewed-by: Vadim Bendebury --- extra/usb_updater/gsctool.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/extra/usb_updater/gsctool.c b/extra/usb_updater/gsctool.c index 5193df039e..358e10a6de 100644 --- a/extra/usb_updater/gsctool.c +++ b/extra/usb_updater/gsctool.c @@ -36,12 +36,6 @@ #include "usb_descriptor.h" #include "verify_ro.h" -#ifdef DEBUG -#define debug printf -#else -#define debug(fmt, args...) -#endif - /* * This file contains the source code of a Linux application used to update * CR50 device firmware. @@ -245,6 +239,17 @@ static const struct option long_opts[] = { }; +/* Helper to print debug messages when verbose flag is specified. */ +static void debug(const char *fmt, ...) +{ + va_list args; + + if (verbose_mode) { + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); + } +} /* Helpers to convert between binary and hex ascii and back. */ static char to_hexascii(uint8_t c) @@ -471,7 +476,6 @@ static int tpm_send_pkt(struct transfer_descriptor *td, unsigned int digest, break; } -#ifdef DEBUG debug("Read %d bytes from TPM\n", len); if (len > 0) { int i; @@ -480,7 +484,6 @@ static int tpm_send_pkt(struct transfer_descriptor *td, unsigned int digest, debug("%2.2x ", outbuf[i]); debug("\n"); } -#endif len = len - response_offset; if (len < 0) { fprintf(stderr, "Problems reading from TPM, got %d bytes\n", -- cgit v1.2.1