[PATCH 0/3] cmd: setexpr: add fmt format string operation

Roland Gaudig roland.gaudig-oss at weidmueller.com
Mon Jun 28 17:17:47 CEST 2021


From: Roland Gaudig <roland.gaudig at weidmueller.com>


This patch series is the revised version of the previos proposal
[PATCH v1 0/1] cmd: setexpr: add dec operation for converting variable
to decimal

In contrast to version 1, the "dec" operator has been replaced by
a more flexible "fmt" operator to handle format strings.

U-Boot uses almost everywhere hexadecimal numbers. But some bootargs
passed to Linux are expecting decimal numbers. As long as the values
are in the range 0 to 9 it is sufficient to just strip 0x from the
number. But for greater values a method for converting numbers to
decimal is needed.

This patch adds C like format string capabilities to the setexpr
command. Here are some examples:

  => setexpr foo fmt %d 0x100
  => echo $foo
  256
  =>

  => setexpr foo fmt 0x%08x 63
  => echo $foo
  0x00000063
  =>

  => setexpr foo fmt %%%o 8
  => echo $foo
  %10
  =>

In contrast to the original C format strings the number of parameters
is limited to one. As the get_arg() function returns unsigned long
type, the format string commands are limited to those which are
operating on unsigned long type.

Patman insisted adding a maintainer to for the doc/usage/setexpr.rst,
but I am not sure if chose the correct section and person.



Roland Gaudig (3):
  cmd: setexpr: add fmt format string operation
  doc: usage: add description for setexpr command
  test: cmd: setexpr: add tests for format string operations

 MAINTAINERS           |   6 ++
 cmd/setexpr.c         | 102 ++++++++++++++++++++++++++++++++-
 doc/usage/index.rst   |   1 +
 doc/usage/setexpr.rst | 130 ++++++++++++++++++++++++++++++++++++++++++
 test/cmd/setexpr.c    |  33 +++++++++++
 5 files changed, 271 insertions(+), 1 deletion(-)
 create mode 100644 doc/usage/setexpr.rst

-- 
2.25.1



More information about the U-Boot mailing list