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

Simon Glass sjg at chromium.org
Wed May 20 22:12:12 CEST 2026


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

-- 
2.43.0



More information about the U-Boot mailing list