[U-Boot] [PATCH 0/2] Small fixes to SPL/TPL logging

These two patches fix small issues I encountered when enabling debugging output for U-Boot's TPL.
The first fixes a typo in the description of the TPL_LOG_CONSOLE configuration option.
The second adds a simple implementation of vsnprintf() to the tiny-printf library. Without this, enabling either SPL or TPL logging for systems (such as the PINE64 ROCK64) that also use the tiny printf() implementation causes the build to fail with error messages like
aarch64-linux-gnu-ld.bfd: common/built-in.o: in function `_log': (...)/u-boot/common/log.c:212: undefined reference to `vsnprintf' make[1]: *** [scripts/Makefile.spl:404: spl/u-boot-spl] Error 1 make: *** [Makefile:1762: spl/u-boot-spl] Error 2
To minimize the impact on code size, the function is built only when logging is enabled, as it appears to be unneeded otherwise.
Note we could probably shave off a few bytes by having the existing sprintf() and snprintf() functions call vsnprintf() when it's available. I haven't made this change only because it isn't how the existing code is written (printf() could call vprintf(), and snprintf() could call sprintf(), yet neither do) and I assume this is for a reason.
Simon South (2): common: Kconfig: Fix typo in TPL_LOG_CONSOLE description tiny-printf: Support vsnprintf()
common/Kconfig | 2 +- lib/tiny-printf.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-)

Signed-off-by: Simon South simon@simonsouth.net --- common/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/Kconfig b/common/Kconfig index 28d5e9a0cc..d9ecf79e0a 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -764,7 +764,7 @@ config SPL_LOG_CONSOLE line number are omitted.
config TPL_LOG_CONSOLE - bool "Allow log output to the console in SPL" + bool "Allow log output to the console in TPL" depends on TPL_LOG default y help

On Wed, Oct 02, 2019 at 10:55:06AM -0400, Simon South wrote:
Signed-off-by: Simon South simon@simonsouth.net
Applied to u-boot/master, thanks!

Add a simple implementation of this function, to allow logging to be enabled in the SPL or TPL for systems that rely on the tiny printf() implementation.
To keep the code size small,
- The function is built only when logging is enabled, as it (currently) is not needed otherwise; and - Like the existing implementation of snprintf(), its buffer-size parameter is ignored.
Signed-off-by: Simon South simon@simonsouth.net --- lib/tiny-printf.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c index ebef92fc9f..62e6381961 100644 --- a/lib/tiny-printf.c +++ b/lib/tiny-printf.c @@ -366,6 +366,22 @@ int sprintf(char *buf, const char *fmt, ...) return ret; }
+#if CONFIG_IS_ENABLED(LOG) +/* Note that size is ignored */ +int vsnprintf(char *buf, size_t size, const char *fmt, va_list va) +{ + struct printf_info info; + int ret; + + info.outstr = buf; + info.putc = putc_outstr; + ret = _vprintf(&info, fmt, va); + *info.outstr = '\0'; + + return ret; +} +#endif + /* Note that size is ignored */ int snprintf(char *buf, size_t size, const char *fmt, ...) {

On Wed, Oct 02, 2019 at 10:55:07AM -0400, Simon South wrote:
Add a simple implementation of this function, to allow logging to be enabled in the SPL or TPL for systems that rely on the tiny printf() implementation.
To keep the code size small,
- The function is built only when logging is enabled, as it (currently) is not needed otherwise; and
- Like the existing implementation of snprintf(), its buffer-size parameter is ignored.
Signed-off-by: Simon South simon@simonsouth.net
Applied to u-boot/master, thanks!
participants (2)
-
Simon South
-
Tom Rini