[PATCH v3 4/6] cmd: setexpr: add format string handling

Simon Glass sjg at chromium.org
Fri Jul 23 23:41:09 CEST 2021


Hi Roland,

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>
>
> Add format string handling operator to the setexpr command.
> It allows to use C or Bash like format string expressions to be
> evaluated with the result being stored inside the environment variable
> name.
>
>   setexpr <name> fmt <format> [value]...
>
> The following example
>
>   setexpr foo fmt "%d, 0x%x" 0x100 ff
>
> will result in $foo being set to "256, 0xff".
>
> Signed-off-by: Roland Gaudig <roland.gaudig at weidmueller.com>
> ---
>
> (no changes since v1)
>
>  MAINTAINERS   |   5 +
>  cmd/Kconfig   |   8 +
>  cmd/Makefile  |   1 +
>  cmd/printf.c  | 419 +++++++++++++++++++++++++++++---------------------
>  cmd/printf.h  |   8 +
>  cmd/setexpr.c |  37 ++++-
>  6 files changed, 300 insertions(+), 178 deletions(-)
>  create mode 100644 cmd/printf.h

Reviewed-by: Simon Glass <sjg at chromium.org>

nit below

>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index a6b49b54b9..fe53698878 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -1049,6 +1049,11 @@ F:       arch/sandbox/
>  F:     doc/arch/sandbox.rst
>  F:     include/dt-bindings/*/sandbox*.h
>
> +SETEXPR
> +M:     Roland Gaudig <roland.gaudig at weidmueller.com>
> +S:     Maintained
> +F:     cmd/printf.c
> +
>  SH
>  M:     Marek Vasut <marek.vasut+renesas at gmail.com>
>  M:     Nobuhiro Iwamatsu <iwamatsu at nigauri.org>
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index e40d390f88..f1bcf9ebde 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -1414,6 +1414,14 @@ config CMD_SETEXPR
>           Also supports loading the value at a memory location into a variable.
>           If CONFIG_REGEX is enabled, setexpr also supports a gsub function.
>
> +config CMD_SETEXPR_FMT
> +       bool "setexpr_fmt"
> +       default n
> +       depends on CMD_SETEXPR
> +       help
> +         Evaluate format string expression and store result in an environment
> +           variable.
> +
>  endmenu
>
>  menu "Android support commands"
> diff --git a/cmd/Makefile b/cmd/Makefile
> index 9d10e07f0e..ed3669411e 100644
> --- a/cmd/Makefile
> +++ b/cmd/Makefile
> @@ -141,6 +141,7 @@ obj-$(CONFIG_CMD_SF) += sf.o
>  obj-$(CONFIG_CMD_SCSI) += scsi.o disk.o
>  obj-$(CONFIG_CMD_SHA1SUM) += sha1sum.o
>  obj-$(CONFIG_CMD_SETEXPR) += setexpr.o
> +obj-$(CONFIG_CMD_SETEXPR_FMT) += printf.o
>  obj-$(CONFIG_CMD_SPI) += spi.o
>  obj-$(CONFIG_CMD_STRINGS) += strings.o
>  obj-$(CONFIG_CMD_SMC) += smccc.o
> diff --git a/cmd/printf.c b/cmd/printf.c
> index 337ab8ce5d..e024676743 100644
> --- a/cmd/printf.c
> +++ b/cmd/printf.c
> @@ -1,12 +1,21 @@
> -/* vi: set sw=4 ts=4: */
> +// SPDX-License-Identifier: GPL-2.0+
>  /*
> - * printf - format and print data
> + * Copyright (C) 2021 Weidmüller Interface GmbH & Co. KG
> + * Roland Gaudig <roland.gaudig at weidmueller.com>
>   *
>   * Copyright 1999 Dave Cinege
>   * Portions copyright (C) 1990-1996 Free Software Foundation, Inc.
>   *
>   * Licensed under GPLv2 or later, see file LICENSE in this source tree.
>   */
> +/*
> + * This file provides a shell printf like format string expansion as required

This is a bit confusing with all the words run together.

Does it mean a printf-like, format-string expansion feature ?


More information about the U-Boot mailing list