From ba9df2aa09deeae5d851c59469d782b1a7a0efe4 Mon Sep 17 00:00:00 2001 From: Jack Rosenthal Date: Fri, 8 Jan 2021 15:07:05 -0700 Subject: zephyr: switch to platform/ec printf format implementation Prior to this change, the cprints and cprintf shim implementations used Zephyr's printk to do the output formatting. Our EC code has some custom printf specifiers not supported by Zephyr's printk. We've already attempted to send some of our custom specifiers upstream, but upstream does not want them: https://github.com/zephyrproject-rtos/zephyr/pull/28882 The logical thing to do would be to bring in the vfnprintf function from our EC to the Zephyr build, and use that to do the output formatting instead. That's what this CL does. The binary cost of brining in this second printf implementation appears to be minimal (952 bytes on volteer). BUG=b:177065615 BRANCH=none TEST=on posix-ec and volteer, run gettime and observe output no longer contains %.6lld, but instead the correct system time Signed-off-by: Jack Rosenthal Change-Id: I53cd4edf129223c12a2c5e7d0519623a8d07a328 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2618575 --- common/printf.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'common/printf.c') diff --git a/common/printf.c b/common/printf.c index f876a1da19..039a83a92f 100644 --- a/common/printf.c +++ b/common/printf.c @@ -275,7 +275,9 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context, continue; /* %pT - print a timestamp. */ if (ptrspec == 'T' && - !IS_ENABLED(NO_UINT64_SUPPORT)) { + !IS_ENABLED(NO_UINT64_SUPPORT) && + (!IS_ENABLED(CONFIG_ZEPHYR) || + IS_ENABLED(CONFIG_PLATFORM_EC_TIMER))) { flags |= PF_64BIT; if (ptrval == PRINTF_TIMESTAMP_NOW) v = get_time().val; @@ -461,6 +463,12 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context, return EC_SUCCESS; } +/* + * These symbols are already defined by the Zephyr OS kernel, and we + * don't want to use the EC implementation. + */ +#ifndef CONFIG_ZEPHYR + /* Context for snprintf() */ struct snprintf_context { char *str; @@ -516,3 +524,5 @@ int vsnprintf(char *str, int size, const char *format, va_list args) return (rv == EC_SUCCESS) ? (ctx.str - str) : -rv; } + +#endif /* !CONFIG_ZEPHYR */ -- cgit v1.2.1