[PATCH] tiny-printf: Handle formatting of %p with an extra Kconfig
Michael Walle
mwalle at kernel.org
Wed Apr 9 14:33:08 CEST 2025
Hi,
> >> The formatting with %pa / %pap behaves like %x, which results in an
> >> incorrect value being output. To improve this, a new fine-tuning
> >> Kconfig XPL_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.
> >>
> >> Signed-off-by: Christoph Niedermaier <cniedermaier at dh-electronics.com>
> >> ---
> >> Cc: Tom Rini <trini at konsulko.com>
> >> Cc: Simon Glass <sjg at chromium.org>
> >> Cc: Michael Walle <mwalle at kernel.org>
> >> Cc: Quentin Schulz <quentin.schulz at cherry.de>
> >> Cc: Marek Vasut <marex at denx.de>
> >> Cc: Benedikt Spranger <b.spranger at linutronix.de>
> >> Cc: Jerome Forissier <jerome.forissier at linaro.org>
> >> Cc: John Ogness <john.ogness at linutronix.de>
> >> Cc: Ilias Apalodimas <ilias.apalodimas at linaro.org>
> >> ---
> >> Kconfig | 1 +
> >> common/spl/Kconfig | 1 +
> >> lib/Kconfig | 8 ++++++++
> >> lib/tiny-printf.c | 45 +++++++++++++++++++--------------------------
> >> 4 files changed, 29 insertions(+), 26 deletions(-)
> >>
> >> diff --git a/Kconfig b/Kconfig
> >> index 6379a454166..4d13717294c 100644
> >> --- a/Kconfig
> >> +++ b/Kconfig
> >> @@ -757,6 +757,7 @@ config NET
> >>
> >> config NET_LWIP
> >> bool "Use lwIP for networking stack"
> >> + select XPL_USE_TINY_PRINTF_POINTER_SUPPORT if SPL_USE_TINY_PRINTF || TPL_USE_TINY_PRINTF || VPL_USE_TINY_PRINTF
> >> imply NETDEVICES
> >> help
> >> Include networking support based on the lwIP (lightweight IP)
> >> diff --git a/common/spl/Kconfig b/common/spl/Kconfig
> >> index 94e118f8465..72736dbecf5 100644
> >> --- a/common/spl/Kconfig
> >> +++ b/common/spl/Kconfig
> >> @@ -1096,6 +1096,7 @@ config SPL_DM_SPI_FLASH
> >> config SPL_NET
> >> bool "Support networking"
> >> depends on !NET_LWIP
> >> + select XPL_USE_TINY_PRINTF_POINTER_SUPPORT if SPL_USE_TINY_PRINTF || TPL_USE_TINY_PRINTF || VPL_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
> >> diff --git a/lib/Kconfig b/lib/Kconfig
> >> index 1a683dea670..62e28d4a1f3 100644
> >> --- a/lib/Kconfig
> >> +++ b/lib/Kconfig
> >> @@ -253,6 +253,14 @@ config VPL_USE_TINY_PRINTF
> >>
> >> The supported format specifiers are %c, %s, %u/%d and %x.
> >>
> >> +config XPL_USE_TINY_PRINTF_POINTER_SUPPORT
> >> + bool "Extend tiny printf with the pointer formatting %p"
> >> + depends on SPL_USE_TINY_PRINTF || TPL_USE_TINY_PRINTF || VPL_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.
> >
> > This isn't quite what I'd like to see. I don't want to start using the
> > literal XPL namespace as that will lead to confusion down the line.
>
> OK, in V2 I will only support SPL.
>
> > Since we only have SPL_NET, I think we should name this symbol
> > SPL_USE_TINY_PRINTF_POINTER_SUPPORT, not ask about it (so bool without
> > "prompt text" following), and select from SPL_NET if
> > SPL_USE_TINY_PRINTF.
IIRC, the old one also enabled the pointer support if DEBUG is
enabled. I don't think this will work with Kconfig.
> Now you will get the output '?' when using formatting with %p or %pa.
> If someone wants to use the pointer support e.g. %pa in pinctrl-single.c
> and is restricted to use tiny printf, then it would be good to have
> the option to enable it manually and not be forced to enable SPL_NET or
> NET_LWIP to have the pointer support enabled. In this case, it makes
> sense to allow switching it on in menuconfig.
FWIW, I'm also fine with enabling full printf support as long as the
tiny one doesn't print misleading values.
-michael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 297 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20250409/d4432ce1/attachment.sig>
More information about the U-Boot
mailing list