tiny-printf: Handle formatting of %p with an extra Kconfig
PATCH v3 1/1 tiny-printf: Handle formatting of %p with an extra Kconfig
The formatting with %pa / %pap behaves like %x, which results in an incorrect value being output. To improve this, a new fine-tuning Kconfig SPL_USE_TINY_PRINTF_POINTER_SUPPORT for pointer formatting has been added. If it is enabled, the output of %pa / %pap should be correct, and if it is disabled, the pointer formatting is completely unsupported. In addition to indicate unsupported formatting, '?' will be output. This allows enabling pointer formatting only when needed. For SPL_NET and NET_LWIP it is selected by default. Then it also supports the formatting with %pm, %pM and %pI4.
In summery this level of %p support for tiny printf is possible now:
1) The standard tiny printf won't have support for pointer formatting. So it doesn't print misleading values for %pa, instead '?' will be output:
%p => ?
%pa => ?a
%pap => ?ap
2) If SPL_USE_TINY_PRINTF_POINTER_SUPPORT is enabled or DEBUG is defined tiny printf supports formatting %p and %pa / %pap.
3) If SPL_NET or NET_LWIP is enabled the support of pointers is extended for %pm, %pM and %pI4.
---
Cc: Tom Rini <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Michael Walle <[email protected]>
Cc: Quentin Schulz <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Benedikt Spranger <[email protected]>
Cc: Jerome Forissier <[email protected]>
Cc: John Ogness <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
---
V2: - Rebase on current master
- Extend commit message
- Restrict use to SPL
- Rename Kconfig to SPL_USE_TINY_PRINTF_POINTER_SUPPORT
- Replace _DEBUG with defined(DEBUG)
- Output '?' if %pm, %pM and %pI4 isn't available
- Add break on case '%'
V3: - Add missing output '?' for the default case
--- Kconfig | 1 + common/spl/Kconfig | 1 + lib/Kconfig | 8 +++++++ lib/tiny-printf.c | 52 +++++++++++++++++++++++----------------------- 4 files changed, 36 insertions(+), 26 deletions(-)
Kconfig +1 -0
@@ -774,6 +774,7 @@ config NET config NET_LWIP bool "Use lwIP for networking stack" + select SPL_USE_TINY_PRINTF_POINTER_SUPPORT if SPL_USE_TINY_PRINTF imply NETDEVICES help Include networking support based on the lwIP (lightweight IP)
common/spl/Kconfig +1 -0
@@ -1116,6 +1116,7 @@ config SPL_DM_SPI_FLASH config SPL_NET bool "Support networking" depends on !NET_LWIP + select SPL_USE_TINY_PRINTF_POINTER_SUPPORT if SPL_USE_TINY_PRINTF help Enable support for network devices (such as Ethernet) in SPL. This permits SPL to load U-Boot over a network link rather than
lib/Kconfig +8 -0
@@ -253,6 +253,14 @@ config VPL_USE_TINY_PRINTF The supported format specifiers are %c, %s, %u/%d and %x. +config SPL_USE_TINY_PRINTF_POINTER_SUPPORT + bool "Extend tiny printf with the pointer formatting %p" + depends on SPL_USE_TINY_PRINTF + help + This option enables the formatting of pointers %p. It supports + %p and %pa / %pap. If this option is selected by SPL_NET or NET_LWIP + it also supports the formatting with %pm, %pM and %pI4. + config PANIC_HANG bool "Do not reset the system on fatal error" help
lib/tiny-printf.c +26 -26
110 lines not on this page · raw message
Signature · 1 line
2.30.2
Quoted 57 lines · Christoph Niedermaier
The formatting with %pa / %pap behaves like %x, which results in an incorrect value being output. To improve this, a new fine-tuning
KconfigSPL_USE_TINY_PRINTF_POINTER_SUPPORTfor pointer formatting has been added. If it is enabled, the output of %pa / %pap should be correct, and if it is disabled, the pointer formatting is completely unsupported. In addition to indicate unsupported formatting, '?' will be output. This allows enabling pointer formatting only when needed. ForSPL_NETandNET_LWIPit is selected by default. Then it also supports the formatting with %pm, %pM and %pI4.In summery this level of %p support for tiny printf is possible now:
1) The standard tiny printf won't have support for pointer formatting. So it doesn't print misleading values for %pa, instead '?' will be output:
%p => ? %pa => ?a %pap => ?ap2) If
SPL_USE_TINY_PRINTF_POINTER_SUPPORTis enabled or DEBUG is defined tiny printf supports formatting %p and %pa / %pap.3) If
SPL_NETorNET_LWIPis enabled the support of pointers is extended for %pm, %pM and %pI4.Signed-off-by Christoph Niedermaier <[email protected]>---
Cc: Tom Rini <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Michael Walle <[email protected]>
Cc: Quentin Schulz <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Benedikt Spranger <[email protected]>
Cc: Jerome Forissier <[email protected]>
Cc: John Ogness <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
---
V2: - Rebase on current master
- Extend commit message
- Restrict use to SPL
- RenameKconfigtoSPL_USE_TINY_PRINTF_POINTER_SUPPORT
- Replace_DEBUGwith defined(DEBUG)
- Output '?' if %pm, %pM and %pI4 isn't available
- Add break on case '%'
V3: - Add missing output '?' for the default case--- Kconfig | 1 + common/spl/Kconfig | 1 + lib/Kconfig | 8 +++++++ lib/tiny-printf.c | 52 +++++++++++++++++++++++----------------------- 4 files changed, 36 insertions(+), 26 deletions(-)Kconfig +0
-0
Kconfig config NET · line 780
Quoted 7 lines
Kconfig +1
-0@@ -774,6 +774,7 @@ config NET config NET_LWIP bool "Use lwIP for networking stack" + select SPL_USE_TINY_PRINTF_POINTER_SUPPORT if SPL_USE_TINY_PRINTF imply NETDEVICES help Include networking support based on the lwIP (lightweight IP)
Sorry I missed this bug until now. This (and the subsequent parts of the patch referencing lwIP) aren't right. There's no SPL_NET_LWIP support (and not planned at this point), so what this does is grow platforms like xilinx_zynq_virt which use lwIP in U-Boot and tiny printf in SPL, but shouldn't since there's no SPL_NET_LWIP.
Signature · 1 line
Tom
From: Tom Rini <[email protected]>
Sent: Wednesday, May 7, 2025 7:43 PM
Quoted 60 lines · Christoph Niedermaier
Quoted 59 lines
The formatting with %pa / %pap behaves like %x, which results in an incorrect value being output. To improve this, a new fine-tuning
KconfigSPL_USE_TINY_PRINTF_POINTER_SUPPORTfor pointer formatting has been added. If it is enabled, the output of %pa / %pap should be correct, and if it is disabled, the pointer formatting is completely unsupported. In addition to indicate unsupported formatting, '?' will be output. This allows enabling pointer formatting only when needed. ForSPL_NETandNET_LWIPit is selected by default. Then it also supports the formatting with %pm, %pM and %pI4.In summery this level of %p support for tiny printf is possible now:
1) The standard tiny printf won't have support for pointer formatting. So it doesn't print misleading values for %pa, instead '?' will be output:
%p => ? %pa => ?a %pap => ?ap2) If
SPL_USE_TINY_PRINTF_POINTER_SUPPORTis enabled or DEBUG is defined tiny printf supports formatting %p and %pa / %pap.3) If
SPL_NETorNET_LWIPis enabled the support of pointers is extended for %pm, %pM and %pI4.Signed-off-by Christoph Niedermaier <[email protected]>---
Cc: Tom Rini <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Michael Walle <[email protected]>
Cc: Quentin Schulz <[email protected]>
Cc: Marek Vasut <[email protected]>
Cc: Benedikt Spranger <[email protected]>
Cc: Jerome Forissier <[email protected]>
Cc: John Ogness <[email protected]>
Cc: Ilias Apalodimas <[email protected]>
---
V2: - Rebase on current master
- Extend commit message
- Restrict use to SPL
- RenameKconfigtoSPL_USE_TINY_PRINTF_POINTER_SUPPORT
- Replace_DEBUGwith defined(DEBUG)
- Output '?' if %pm, %pM and %pI4 isn't available
- Add break on case '%'
V3: - Add missing output '?' for the default case--- Kconfig | 1 + common/spl/Kconfig | 1 + lib/Kconfig | 8 +++++++ lib/tiny-printf.c | 52 +++++++++++++++++++++++----------------------- 4 files changed, 36 insertions(+), 26 deletions(-)Kconfig +0
-0@@ -774,6 +774,7 @@ config NET
Quoted 12 lines
Kconfig config NET · line 780
Quoted 6 lines
Kconfig +1
-0config NET_LWIP bool "Use lwIP for networking stack" + select SPL_USE_TINY_PRINTF_POINTER_SUPPORT if SPL_USE_TINY_PRINTF imply NETDEVICES help Include networking support based on the lwIP (lightweight IP)Sorry I missed this bug until now. This (and the subsequent parts of the patch referencing lwIP) aren't right. There's no
SPL_NET_LWIPsupport (and not planned at this point), so what this does is grow platforms likexilinx_zynq_virtwhich use lwIP in U-Boot and tiny printf in SPL, but shouldn't since there's noSPL_NET_LWIP.
I didn't know that, I took it from the tiny printf pointer handling code. I will remove all lwIP references in version 4.
Thanks and regards
Christoph