From c091f65234cfed79cfe738a7a6e0e1bd574ba9e2 Mon Sep 17 00:00:00 2001 From: "Matwey V. Kornilov" Date: Thu, 5 Aug 2021 22:06:05 +0300 Subject: tiny-printf: Handle %pM format when CONFIG_SPL_NET_SUPPORT is enabled %pM format string is used to print MAC-address and this is required while SPL network boot. This patch fixes the SPL boot issues like the following: Trying to boot from USB eth ## Error: flags type check failure for "ethaddr" <= "40309614M" (type: m) ## Error inserting "ethaddr" variable, errno=1 eth0: eth_cpsw## Error: flags type check failure for "eth1addr" <= "81f01114M" (type: m) ## Error inserting "eth1addr" variable, errno=1 , eth1: usb_ether eth_cpsw Waiting for PHY auto negotiation to complete......... TIMEOUT ! Problem booting with BOOTP SPL: failed to boot from all boot devices ### ERROR ### Please RESET the board ### Signed-off-by: Matwey V. Kornilov Reviewed-by: Simon Glass --- lib/tiny-printf.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'lib') diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c index 8fc7e48d994..89aaa854771 100644 --- a/lib/tiny-printf.c +++ b/lib/tiny-printf.c @@ -9,8 +9,9 @@ */ #include -#include +#include #include +#include #include struct printf_info { @@ -269,20 +270,19 @@ static int _vprintf(struct printf_info *info, const char *fmt, va_list va) } break; case 'p': -#ifdef DEBUG - pointer(info, fmt, va_arg(va, void *)); - /* - * Skip this because it pulls in _ctype which is - * 256 bytes, and we don't generally implement - * pointer anyway - */ - while (isalnum(fmt[0])) - fmt++; - break; -#else + if (CONFIG_IS_ENABLED(NET_SUPPORT) || _DEBUG) { + pointer(info, fmt, va_arg(va, void *)); + /* + * Skip this because it pulls in _ctype which is + * 256 bytes, and we don't generally implement + * pointer anyway + */ + while (isalnum(fmt[0])) + fmt++; + break; + } islong = true; /* no break */ -#endif case 'x': if (islong) { num = va_arg(va, unsigned long); -- cgit v1.2.3 From f52352f65e359c91f69faaa6f6cd1ea34f8adf6d Mon Sep 17 00:00:00 2001 From: "Matwey V. Kornilov" Date: Fri, 6 Aug 2021 00:22:58 +0300 Subject: display_options: Do not use %llu in print_size tiny-printf variant doesn't know how to handle %llu format string, but both tiny-printf and print_size can meet in SPL when TFTP is used to obtain main u-boot image. This is known to lead to critical boot issue at AM335x platform when printf is catched in infinite loop. To avoid such issues and make print_size function tiny-printf friendly, use %u instead of %luu. Note, that the size value is guaranteed to be less than 1024 in this conditional branch, so the cast to unsigned int is safe. Signed-off-by: Matwey V. Kornilov Reviewed-by: Simon Glass --- lib/display_options.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/display_options.c b/lib/display_options.c index c08a87e3162..4da1f5244f3 100644 --- a/lib/display_options.c +++ b/lib/display_options.c @@ -107,7 +107,12 @@ void print_size(uint64_t size, const char *s) } if (!c) { - printf("%llu Bytes%s", size, s); + /* + * SPL tiny-printf is not capable for printing uint64_t. + * We have just checked that the size is small enought to fit + * unsigned int safely. + */ + printf("%u Bytes%s", (unsigned int)size, s); return; } -- cgit v1.2.3