summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2022-07-08 13:14:15 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-07-12 17:04:22 +0000
commitebbbdf1a29296004acaa87b57de2059c146e3a3e (patch)
tree61c28e3aaa4519a74f48f5c9c307fb598d201093
parentc0f4b8bec7ccb755fb1151b01816d6cf5d26fdfa (diff)
downloadchrome-ec-ebbbdf1a29296004acaa87b57de2059c146e3a3e.tar.gz
tree: Remove non-standard %pb printf format
The binary printf format doesn't provide much over printing hex, so change existing binary prints to hex. Using standard format specifiers makes it easier to switch between the "builtin" EC standard library and the C standard library provided by the toolchain (or Zephyr). BRANCH=none BUG=b:238433667, b:234181908 TEST=make buildall Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I55153f0ea1a4864e7819cee0e0f35368baa3f682 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3756176 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
-rw-r--r--common/charger.c2
-rw-r--r--common/printf.c14
-rw-r--r--driver/charger/sy21612.c2
-rw-r--r--driver/led/is31fl3743b.c2
-rw-r--r--driver/nfc/ctn730.c1
-rw-r--r--driver/temp_sensor/adt7481.c11
-rw-r--r--driver/temp_sensor/g753.c7
-rw-r--r--driver/temp_sensor/g78x.c9
-rw-r--r--driver/temp_sensor/tmp411.c7
-rw-r--r--driver/temp_sensor/tmp432.c9
-rw-r--r--include/console.h14
-rw-r--r--test/printf.c19
12 files changed, 30 insertions, 67 deletions
diff --git a/common/charger.c b/common/charger.c
index c3f032f908..307e04dd8c 100644
--- a/common/charger.c
+++ b/common/charger.c
@@ -146,7 +146,7 @@ void print_charger_debug(int chgnum)
/* option */
print_item_name("Option:");
if (check_print_error(charger_get_option(&d)))
- ccprintf("%pb (0x%04x)\n", BINARY_VALUE(d, 16), d);
+ ccprintf("(0x%04x)\n", d);
/* manufacturer id */
print_item_name("Man id:");
diff --git a/common/printf.c b/common/printf.c
index 610a2da94f..f19e6d3b21 100644
--- a/common/printf.c
+++ b/common/printf.c
@@ -273,8 +273,8 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context,
ptrspec = *format++;
ptrval = va_arg(args, void *);
/*
- * Avoid null pointer dereference for %ph and
- * %pb. %pT and %pP can accept null.
+ * Avoid null pointer dereference for %ph.
+ * %pT and %pP can accept null.
*/
if (ptrval == NULL && ptrspec != 'T' &&
ptrspec != 'P')
@@ -322,16 +322,6 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context,
sizeof(uint64_t))
flags |= PF_64BIT;
- } else if (ptrspec == 'b') {
- /* %pb - Print a binary integer */
- struct binary_print_params *binary =
- ptrval;
-
- v = binary->value;
- pad_width = binary->count;
- flags |= PF_PADZERO;
- base = 2;
-
} else {
return EC_ERROR_INVAL;
}
diff --git a/driver/charger/sy21612.c b/driver/charger/sy21612.c
index 394be47fdc..6089de1ee7 100644
--- a/driver/charger/sy21612.c
+++ b/driver/charger/sy21612.c
@@ -195,7 +195,7 @@ static int command_sy21612(int argc, char **argv)
if (rv)
ccprintf(" x (%d)\n", rv);
else
- ccprintf("%02x - %pb\n", val, BINARY_VALUE(val, 8));
+ ccprintf("%02x\n", val);
}
ccprintf("vbat voltage: %d mV\n", sy21612_get_vbat_voltage());
diff --git a/driver/led/is31fl3743b.c b/driver/led/is31fl3743b.c
index eed9c80acc..f9c86284d1 100644
--- a/driver/led/is31fl3743b.c
+++ b/driver/led/is31fl3743b.c
@@ -83,7 +83,7 @@ static int is31fl3743b_enable(struct rgbkbd *ctx, bool enable)
{
uint8_t u8 =
IS31FL3743B_CONFIG(IS31FL3743B_CFG_SWS_1_11, 0, enable ? 1 : 0);
- CPRINTS("Setting config register to 0b%pb", BINARY_VALUE(u8, 8));
+ CPRINTS("Setting config register to 0x%x", u8);
return is31fl3743b_write(ctx, IS31FL3743B_REG_CONFIG, u8);
}
diff --git a/driver/nfc/ctn730.c b/driver/nfc/ctn730.c
index 45598f76b9..16ab40d025 100644
--- a/driver/nfc/ctn730.c
+++ b/driver/nfc/ctn730.c
@@ -40,7 +40,6 @@ BUILD_ASSERT(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__);
static const char *_text_instruction(uint8_t instruction)
{
- /* TODO: For normal build, use %pb and BINARY_VALUE(res->inst, 6) */
switch (instruction) {
case WLC_HOST_CTRL_RESET:
return "RESET";
diff --git a/driver/temp_sensor/adt7481.c b/driver/temp_sensor/adt7481.c
index f9f771271f..c26247f80c 100644
--- a/driver/temp_sensor/adt7481.c
+++ b/driver/temp_sensor/adt7481.c
@@ -240,16 +240,16 @@ static int print_status(void)
ccprintf("\n");
if (raw_read8(ADT7481_STATUS1_R, &value) == EC_SUCCESS)
- ccprintf("STATUS1: %pb\n", BINARY_VALUE(value, 8));
+ ccprintf("STATUS1: 0x%x\n", value);
if (raw_read8(ADT7481_STATUS2_R, &value) == EC_SUCCESS)
- ccprintf("STATUS2: %pb\n", BINARY_VALUE(value, 8));
+ ccprintf("STATUS2: 0x%x\n", value);
if (raw_read8(ADT7481_CONFIGURATION1_R, &value) == EC_SUCCESS)
- ccprintf("CONFIG1: %pb\n", BINARY_VALUE(value, 8));
+ ccprintf("CONFIG1: 0x%x\n", value);
if (raw_read8(ADT7481_CONFIGURATION2, &value) == EC_SUCCESS)
- ccprintf("CONFIG2: %pb\n", BINARY_VALUE(value, 8));
+ ccprintf("CONFIG2: 0x%x\n", value);
return EC_SUCCESS;
}
@@ -299,8 +299,7 @@ static int command_adt7481(int argc, char **argv)
rv = raw_read8(offset, &data);
if (rv < 0)
return rv;
- ccprintf("Byte at offset 0x%02x is %pb\n", offset,
- BINARY_VALUE(data, 8));
+ ccprintf("Byte at offset 0x%02x is 0x%x\n", offset, data);
return rv;
}
diff --git a/driver/temp_sensor/g753.c b/driver/temp_sensor/g753.c
index c98c54bd3d..5dbc47064a 100644
--- a/driver/temp_sensor/g753.c
+++ b/driver/temp_sensor/g753.c
@@ -120,10 +120,10 @@ static int print_status(void)
ccprintf("\n");
if (raw_read8(G753_STATUS, &value) == EC_SUCCESS)
- ccprintf("STATUS: %pb\n", BINARY_VALUE(value, 8));
+ ccprintf("STATUS: 0x%x\n", value);
if (raw_read8(G753_CONFIGURATION_R, &value) == EC_SUCCESS)
- ccprintf("CONFIG: %pb\n", BINARY_VALUE(value, 8));
+ ccprintf("CONFIG: 0x%x\n", value);
return EC_SUCCESS;
}
@@ -157,8 +157,7 @@ static int command_g753(int argc, char **argv)
rv = raw_read8(offset, &data);
if (rv < 0)
return rv;
- ccprintf("Byte at offset 0x%02x is %pb\n", offset,
- BINARY_VALUE(data, 8));
+ ccprintf("Byte at offset 0x%02x is 0x%x\n", offset, data);
return rv;
}
diff --git a/driver/temp_sensor/g78x.c b/driver/temp_sensor/g78x.c
index 84bddfe719..22af57c2d8 100644
--- a/driver/temp_sensor/g78x.c
+++ b/driver/temp_sensor/g78x.c
@@ -158,15 +158,15 @@ static int print_status(void)
ccprintf("\n");
if (raw_read8(G78X_STATUS, &value) == EC_SUCCESS)
- ccprintf("STATUS: %pb\n", BINARY_VALUE(value, 8));
+ ccprintf("STATUS: 0x%x\n", value);
#ifdef CONFIG_TEMP_SENSOR_G782
if (raw_read8(G78X_STATUS1, &value) == EC_SUCCESS)
- ccprintf("STATUS1: %pb\n", BINARY_VALUE(value, 8));
+ ccprintf("STATUS1: 0x%x\n", value);
#endif
if (raw_read8(G78X_CONFIGURATION_R, &value) == EC_SUCCESS)
- ccprintf("CONFIG: %pb\n", BINARY_VALUE(value, 8));
+ ccprintf("CONFIG: 0x%x\n", value);
return EC_SUCCESS;
}
@@ -200,8 +200,7 @@ static int command_g78x(int argc, char **argv)
rv = raw_read8(offset, &data);
if (rv < 0)
return rv;
- ccprintf("Byte at offset 0x%02x is %pb\n", offset,
- BINARY_VALUE(data, 8));
+ ccprintf("Byte at offset 0x%02x is 0x%x\n", offset, data);
return rv;
}
diff --git a/driver/temp_sensor/tmp411.c b/driver/temp_sensor/tmp411.c
index 482f31a9c6..804fa30644 100644
--- a/driver/temp_sensor/tmp411.c
+++ b/driver/temp_sensor/tmp411.c
@@ -225,10 +225,10 @@ static int print_status(void)
ccprintf("\n");
if (raw_read8(TMP411_STATUS_R, &value) == EC_SUCCESS)
- ccprintf("STATUS: %pb\n", BINARY_VALUE(value, 8));
+ ccprintf("STATUS: 0x%x\n", value);
if (raw_read8(TMP411_CONFIGURATION1_R, &value) == EC_SUCCESS)
- ccprintf("CONFIG1: %pb\n", BINARY_VALUE(value, 8));
+ ccprintf("CONFIG1: 0x%x\n", value);
return EC_SUCCESS;
}
@@ -278,8 +278,7 @@ static int command_tmp411(int argc, char **argv)
rv = raw_read8(offset, &data);
if (rv < 0)
return rv;
- ccprintf("Byte at offset 0x%02x is %pb\n", offset,
- BINARY_VALUE(data, 8));
+ ccprintf("Byte at offset 0x%02x is 0x%x\n", offset, data);
return rv;
}
diff --git a/driver/temp_sensor/tmp432.c b/driver/temp_sensor/tmp432.c
index b05e986ade..54414a2f3e 100644
--- a/driver/temp_sensor/tmp432.c
+++ b/driver/temp_sensor/tmp432.c
@@ -286,13 +286,13 @@ static int print_status(void)
ccprintf("\n");
if (raw_read8(TMP432_STATUS, &value) == EC_SUCCESS)
- ccprintf("STATUS: %pb\n", BINARY_VALUE(value, 8));
+ ccprintf("STATUS: 0x%x\n", value);
if (raw_read8(TMP432_CONFIGURATION1_R, &value) == EC_SUCCESS)
- ccprintf("CONFIG1: %pb\n", BINARY_VALUE(value, 8));
+ ccprintf("CONFIG1: 0x%x\n", value);
if (raw_read8(TMP432_CONFIGURATION2_R, &value) == EC_SUCCESS)
- ccprintf("CONFIG2: %pb\n", BINARY_VALUE(value, 8));
+ ccprintf("CONFIG2: 0x%x\n", value);
return EC_SUCCESS;
}
@@ -342,8 +342,7 @@ static int command_tmp432(int argc, char **argv)
rv = raw_read8(offset, &data);
if (rv < 0)
return rv;
- ccprintf("Byte at offset 0x%02x is %pb\n", offset,
- BINARY_VALUE(data, 8));
+ ccprintf("Byte at offset 0x%02x is 0x%x\n", offset, data);
return rv;
}
diff --git a/include/console.h b/include/console.h
index addee30386..7adbb1d77c 100644
--- a/include/console.h
+++ b/include/console.h
@@ -58,20 +58,6 @@ struct hex_buffer_params {
(&(const struct hex_buffer_params){ .buffer = (_buffer), \
.size = (_size) })
-/*
- * Define parameters to printing in binary: the value to print, and the number
- * of digits to print.
- */
-
-struct binary_print_params {
- unsigned int value;
- uint8_t count;
-};
-
-#define BINARY_VALUE(_value, _count) \
- (&(const struct binary_print_params){ .value = (_value), \
- .count = (_count) })
-
#define PRINTF_TIMESTAMP_NOW NULL
/* Console command; used by DECLARE_CONSOLE_COMMAND macro. */
diff --git a/test/printf.c b/test/printf.c
index 8ad84f46c4..90d146b45d 100644
--- a/test/printf.c
+++ b/test/printf.c
@@ -286,7 +286,6 @@ test_static int test_vsnprintf_long(void)
test_static int test_vsnprintf_pointers(void)
{
void *ptr = (void *)0x55005E00;
- unsigned int val = 0;
T(expect_success("55005e00", "%pP", ptr));
T(expect_success(err_str, "%P", ptr));
@@ -297,18 +296,12 @@ test_static int test_vsnprintf_pointers(void)
/* %p with an unknown suffix is invalid */
T(expect(EC_ERROR_INVAL, "", false, sizeof(output), "%pQ"));
- /* Test %pb, binary format */
- T(expect_success("0", "%pb", BINARY_VALUE(val, 0)));
- val = 0x5E;
- T(expect_success("1011110", "%pb", BINARY_VALUE(val, 0)));
- T(expect_success("0000000001011110", "%pb", BINARY_VALUE(val, 16)));
- val = 0x12345678;
- T(expect_success("10010001101000101011001111000", "%pb",
- BINARY_VALUE(val, 0)));
- val = 0xFEDCBA90;
- /* Test a number that makes the longest string possible */
- T(expect_success("11111110110111001011101010010000", "%pb",
- BINARY_VALUE(val, 0)));
+ /*
+ * Test %pb, which used to print binary, but is non-standard and no
+ * longer supported.
+ */
+ T(expect(EC_ERROR_INVAL, "", false, sizeof(output), "%pb", 0xff));
+
return EC_SUCCESS;
}