Skip to contentSkip to conversation

tiny-printf: Handle formatting of %p with an extra Kconfig

PATCH Superseded Christoph Niedermaier 2 participants 4 messages Apr 29, 2025 – Apr 30, 2025 Library code

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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 '%'

---
 Kconfig            |  1 +
 common/spl/Kconfig |  1 +
 lib/Kconfig        |  8 ++++++++
 lib/tiny-printf.c  | 51 +++++++++++++++++++++++-----------------------
 4 files changed, 35 insertions(+), 26 deletions(-)
Kconfig +1 -0
index 51358633762..b8eec3fc931 100644
@@ -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
index b076f49ac00..b89e0c9b4d4 100644
@@ -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
index b2aecd8a49e..e17396701c2 100644
@@ -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 +25 -26

108 lines not on this page · raw message

Signature · 1 line
2.30.2
#1 lore raw
Quoted 19 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 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
Quoted 5 lines

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.

If you need rich printf formatting support , enable full printf instead?

#2 lore raw

From: Marek Vasut <[email protected]>
Sent: Tuesday, April 29, 2025 5:28 PM

Quoted 20 lines · Christoph Niedermaier
Quoted 19 lines

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
Quoted 6 lines
Quoted 5 lines

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.

If you need rich printf formatting support , enable full printf instead?

It is not about extending tiny printf with more formatting. The current support for pointers leads to the printing of misleading values. This patch removes the support for pointers, but makes the already existing pointer support for %pa / %pap optional. The existing support for %pm, %pM and %pI4 enabled by SPL_NET or NET_LWIP CONF has remained functionally the same.

Regards
Christoph

#3 lore raw

From: Christoph Niedermaier
Sent: Tuesday, April 29, 2025 6:49 PM

Quoted 27 lines

From: Marek Vasut <[email protected]>
Sent: Tuesday, April 29, 2025 5:28 PM

Quoted 25 lines · Christoph Niedermaier
Quoted 24 lines

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.
Quoted 7 lines
Quoted 1 line

If you need rich printf formatting support , enable full printf instead?

It is not about extending tiny printf with more formatting. The current support for pointers leads to the printing of misleading values. This patch removes the support for pointers, but makes the already existing pointer support for %pa / %pap optional. The existing support for %pm, %pM and %pI4 enabled by SPL_NET or NET_LWIP CONF has remained functionally the same.

Sorry, I have noticed that in V2 the output of '?' is missing in the default case. I will fix it in V3.

Regards
Christoph