Skip to content

Convert env export and import to use getopt()

Simon Glass u-boot 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 6 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2cmd: nvedit: Use getopt() in env exportcmd/Kconfig cmd/nvedit.c+38 -520 replies
2/2cmd: nvedit: Use getopt() in env importcmd/Kconfig cmd/nvedit.c env/common.c+46 -520 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/2] Convert env export and import to use getopt()

U-Boot has had a getopt() implementation for over five years but it is not used much; most commands hand-roll their own argv loops to spot -x style flags. The env export and env import sub-commands have the gnarliest of these parsers in nvedit.c

Each one walks every -prefixed argv element by hand, opens an inner loop to split grouped flags and tracks a counter to catch a repeated format flag.

This short series converts both sub-commands to getopt(). The mutex check for the format flags is done after the option loop, since it is a per-command rule rather than an option-parsing rule, and the trailing positional list is read straight out of argv from gs.index onwards.

There is no functional change. getopt() stops at the first non-option, just as the hand-rolled loops did, so options still have to appear before the positional arguments.

Each command gains a 'select GETOPT' so the parser is linked in on boards that do not already enable it.

For firefly-rk3399:

03: cmd: nvedit: Use getopt() in env export

     aarch64: (for 1/1 boards) all -45.0 rodata +27.0 text -72.0
  04: cmd: nvedit: Use getopt() in env import
     aarch64: (for 1/1 boards) all -27.0 rodata -55.0 text +28.0

Simon Glass (2):
cmd: nvedit: Use getopt() in env export
cmd: nvedit: Use getopt() in env import

 cmd/Kconfig  |   2 +
 cmd/nvedit.c | 186 +++++++++++++++++++++++----------------------------
 env/common.c |   2 +-
 3 files changed, 85 insertions(+), 105 deletions(-)

---
base-commit: 87ed7fe45c76dd78094a2c9a4953676b4b7ace6e
branch: clid3

Signature · 1 line
2.43.0