[PATCH v3 2/6] cmd: printf: import busybox-1.33.1 printf.c

Simon Glass sjg at chromium.org
Mon Jul 26 16:06:22 CEST 2021


Hi Roland,

On Mon, 26 Jul 2021 at 02:11, Roland Gaudig (OSS)
<roland.gaudig-oss at weidmueller.com> wrote:
>
> Hi Simon,
>
> On 23.07.21 21:41, Simon Glass wrote:
> > On Fri, 23 Jul 2021 at 06:30, Roland Gaudig
> > <roland.gaudig-oss at weidmueller.com> wrote:
> >>
> >> From: Roland Gaudig <roland.gaudig at weidmueller.com>
> >>
> >> Import printf.c from the Busybox project, which provides Bash like
> >> format string handling.
> >>
> >>   src-url: https://git.busybox.net/busybox/
> >>   commit bcc5b0e6caca6c7602a6a41f "Bump version to 1.33.1"
> >>   version: 1.33.1
> >>
> >> Signed-off-by: Roland Gaudig <roland.gaudig at weidmueller.com>
> >> ---
> >>
> >> (no changes since v1)
> >>
> >>  cmd/printf.c | 455 +++++++++++++++++++++++++++++++++++++++++++++++++++
> >>  1 file changed, 455 insertions(+)
> >>  create mode 100644 cmd/printf.c
> >
> > I think I missed the discussion on this.
>
> Short summary: We wanted to pass a U-Boot environment variable which
> contained a hexadecimal value to the kernel bootargs which required a
> decimal value. Therefore I created a dec operator to the setexpr command
> for converting a value to decimal. Then came the proposal to use a
> format string instead of a dec operator. To keep codesize low I
> implemented a very limited version, allowing only one argument. Then
> came the request to make it more flexible like its Bash counterpart and
> allowing multiple arguments. This is what this version tries to do.
>
> > Why can we not use U-Boot's existing printf()?
>
> The existing printf in the lib directroy implements the C library
> function, whereas my cmd printf implements a Bash like printf.
> Both are on the first glance similar but behave differently in detail.
> The C printf requires, that the requested format matches the type of
> the argument. If I for example request a %s format and pass an int
> type bad things will happen.
>
> In contrast the shell does not have such a strict concept of types,
> when requesting a %d format the argument might contain a string
> representing a Number. Therefore the shell printf implementation
> has to convert this string first into an integer variable, which
> then can be passed to the C lib printf function.
>
> > If we can't, dot we need to remove the existing U-Boot printf()?
> > Again, sorry if I missed some discussion.
>
> No, we can't. The cmd printf is only a front-end performing the
> necessary conversion. It is relying on the lib printf, which does the
> actual work.

OK. I think you should add some comments to the top of both impls
explaining their purpose and why they are separate from the other one.

Regards,
Simon


More information about the U-Boot mailing list