Convert env export and import to use getopt()
cover 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.0Simon 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
PATCH 1/2 cmd: nvedit: Use getopt() in env export
This is one of the gnarliest hand-rolled parsers in nvedit.c
The code walks each -prefixed argv element by hand, opens an inner while (*++arg) to split grouped flags, and tracks a fmt counter to catch a second -b / -c / -t
It also adds a 'goto NXTARG' that jumps over the inner loop after consuming the argument to -s SIZE, since the rest of the current argv element no longer makes sense once -s has eaten the next slot.
getopt() collapses all of that. The mutex check for the format flags is done after the option loop (it is a per-command rule, not an option-parsing rule), the -s argument arrives in gs.arg, and the trailing positional list is read from argv + gs.index.
Adjust CMD_EXPORTENV to select GETOPT so the parser is linked in on boards that did not already enable it.
Also redo the sep_err logic, use env_set_hex() and shorten error messages to reduce code size.
---
cmd/Kconfig | 1 + cmd/nvedit.c | 89 ++++++++++++++++++++++------------------------------ 2 files changed, 38 insertions(+), 52 deletions(-)
cmd/Kconfig +1 -0
@@ -704,6 +704,7 @@ config CMD_ASKENV config CMD_EXPORTENV bool "env export" default y + select GETOPT help Export environments.
cmd/nvedit.c +37 -52
137 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 2/2 cmd: nvedit: Use getopt() in env import
In reply to Simon GlassThis is the other gnarly hand-rolled parser in nvedit.c
The code walks each -prefixed argv element by hand, opens an inner while (*++arg) to split grouped flags, and tracks a fmt counter to catch a second -b / -c / -t
getopt() collapses all of that. The mutex check for the format flags is done after the option loop (it is a per-command rule, not an option-parsing rule) and the trailing positional list is read from argv + gs.index.
Adjust CMD_IMPORTENV to select GETOPT so the parser is linked in on boards that did not already enable it.
Also redo the sep_err logic and error message, along with a fmt tweak to reduce code size.
---
cmd/Kconfig | 1 + cmd/nvedit.c | 95 ++++++++++++++++++++++++---------------------------- env/common.c | 2 +- 3 files changed, 46 insertions(+), 52 deletions(-)
cmd/Kconfig +1 -0
@@ -711,6 +711,7 @@ config CMD_EXPORTENV config CMD_IMPORTENV bool "env import" default y + select GETOPT help Import environments.
cmd/nvedit.c +44 -51
150 lines not on this page · raw message
env/common.c +1 -1
@@ -402,7 +402,7 @@ void env_set_default(const char *s, int flags)if (himport_r (&env_htab, default_environment,sizeof (default_environment),'\0' , flags,0 ,0 ,NULL ) ==0 ) { -pr_err ("## Error: Environment import failed: errno = %d\n" , +pr_err ("## Error: Environment import failed (err %dE)\n" , errno);return ; }
Signature · 1 line
2.43.0
Quoted 29 lines · Simon Glass
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 innvedit.cEach 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 exportaarch64: (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
Quoted 8 lines
Simon Glass (2):
cmd: nvedit: Usegetopt()in env export
cmd: nvedit: Usegetopt()in env importcmd/Kconfig | 2 + cmd/nvedit.c | 186 +++++++++++++++++++++++---------------------------- env/common.c | 2 +- 3 files changed, 85 insertions(+), 105 deletions(-)
For the record, here's a link to v2:
https://lore.kernel.org/u-boot/[email protected]/
And here's the full size change for firefly-rk3399:
Summary of 3 commits for 1 boards (1 thread, 12 jobs per thread)
01: arm: Fix typo in linker script
aarch64: w+ firefly-rk3399
+(firefly-rk3399) Image 'simple-bin' is missing external blobs and is non-functional: atf-bl31 +(firefly-rk3399)
+(firefly-rk3399) /binman/simple-bin/fit/images/@atf-SEQ/atf-bl31 (atf-bl31):
+(firefly-rk3399) See the documentation for your board. You may need to build ARM Trusted
+(firefly-rk3399) Firmware and build with BL31=/path/to/bl31.bin
+(firefly-rk3399) Image 'simple-bin' is missing optional external blobs but is still functional: tee-os +(firefly-rk3399) /binman/simple-bin/fit/images/@tee-SEQ/tee-os (tee-os):
+(firefly-rk3399) See the documentation for your board. You may need to build Open Portable
+(firefly-rk3399) Trusted Execution Environment (OP-TEE) and build with TEE=/path/to/tee.bin
+(firefly-rk3399) Some images are invalid
02: cmd: nvedit: Use getopt() in env export
aarch64: (for 1/1 boards) all +883.0 rodata +199.0 text +684.0
firefly-rk3399 : all +883 rodata +199 text +684
u-boot: add: 5/0, grow: 0/-2 bytes: 1184/-500 (684)
function old new delta
__getopt - 520 +520
static.bdinfo_print_all - 324 +324
print_eth - 236 +236
print_bi_dram - 92 +92
getopt_init_state - 12 +12
do_env_export 548 476 -72
do_bdinfo 588 160 -428
03: cmd: nvedit: Use getopt() in env import
aarch64: (for 1/1 boards) all -27.0 rodata -55.0 text +28.0
firefly-rk3399 : all -27 rodata -55 text +28
u-boot: add: 0/0, grow: 1/0 bytes: 28/0 (28)
function old new delta
do_env_import 668 696 +28
And so this is why I'm just deferring this until someone has the time to pick up and address the underlying problems with this potential migration that have been raised in the previous iterations.
Signature · 1 line
Tom
Hi Tom,
Quoted 76 lines · Tom Rini
Quoted 29 lines · Simon Glass
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 innvedit.cEach 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 exportaarch64: (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.0Quoted 8 lines
Simon Glass (2):
cmd: nvedit: Usegetopt()in env export
cmd: nvedit: Usegetopt()in env importcmd/Kconfig | 2 + cmd/nvedit.c | 186 +++++++++++++++++++++++---------------------------- env/common.c | 2 +- 3 files changed, 85 insertions(+), 105 deletions(-)For the record, here's a link to v2:
https://lore.kernel.org/u-boot/[email protected]/
And here's the full size change for firefly-rk3399:
Summary of 3 commits for 1 boards (1 thread, 12 jobs per thread) 01: arm: Fix typo in linker script
aarch64: w+ firefly-rk3399(quoted diff) +10
-0+(firefly-rk3399) Image 'simple-bin' is missing external blobs and is non-functional: atf-bl31 +(firefly-rk3399) +(firefly-rk3399) /binman/simple-bin/fit/images/@atf-SEQ/atf-bl31 (atf-bl31): +(firefly-rk3399) See the documentation for your board. You may need to build ARM Trusted +(firefly-rk3399) Firmware and build with BL31=/path/to/bl31.bin +(firefly-rk3399) Image 'simple-bin' is missing optional external blobs but is still functional: tee-os +(firefly-rk3399) /binman/simple-bin/fit/images/@tee-SEQ/tee-os (tee-os): +(firefly-rk3399) See the documentation for your board. You may need to build Open Portable +(firefly-rk3399) Trusted Execution Environment (OP-TEE) and build with TEE=/path/to/tee.bin +(firefly-rk3399) Some images are invalid02: cmd: nvedit: Use
getopt()in env export
aarch64: (for 1/1 boards) all +883.0 rodata +199.0 text +684.0
firefly-rk3399 : all +883 rodata +199 text +684
u-boot: add: 5/0, grow: 0/-2 bytes: 1184/-500 (684)
function old new delta
__getopt- 520 +520
static.bdinfo_print_all - 324 +324
print_eth- 236 +236
print_bi_dram- 92 +92
getopt_init_state- 12 +12
do_env_export548 476 -72
do_bdinfo588 160 -428
03: cmd: nvedit: Usegetopt()in env import
aarch64: (for 1/1 boards) all -27.0 rodata -55.0 text +28.0
firefly-rk3399 : all -27 rodata -55 text +28
u-boot: add: 0/0, grow: 1/0 bytes: 28/0 (28)
function old new delta
do_env_import668 696 +28
Quoted 3 lines
And so this is why I'm just deferring this until someone has the time to pick up and address the underlying problems with this potential migration that have been raised in the previous iterations.
That is actually what I am trying to do.
Just to restate, the main question to resolve is whether we are OK with ~1K of growth in order to have any sort of getopt(). I did find a way to shave ~200 bytes off it (v2 series), but it is still growth. We could migrate the less common commands first, to avoid that growth for most boards, which that seems a little sneaky. Better to decide whether to use getopt() or not.
If you are asking whether someone can write a getopt() which fits in 500 bytes or less, I don't believe so, but you never know.
This v3 series is mostly about showing that we can likely avoid (additional) growth for each command which converts.
I won't send it for now, but I did try passing the getopt struct to each command (instead of argc/argv). That does reduce code size for each command by about 10-20 bytes, so if we converted all the commands we would likely break even in the end.
Regards,
Simon
Quoted 75 lines · Tom Rini
Quoted 29 lines · Simon Glass
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 innvedit.cEach 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 exportaarch64: (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.0Quoted 8 lines
Simon Glass (2):
cmd: nvedit: Usegetopt()in env export
cmd: nvedit: Usegetopt()in env importcmd/Kconfig | 2 + cmd/nvedit.c | 186 +++++++++++++++++++++++---------------------------- env/common.c | 2 +- 3 files changed, 85 insertions(+), 105 deletions(-)For the record, here's a link to v2:
https://lore.kernel.org/u-boot/[email protected]/
And here's the full size change for firefly-rk3399:
Summary of 3 commits for 1 boards (1 thread, 12 jobs per thread) 01: arm: Fix typo in linker scriptaarch64: w+ firefly-rk3399(quoted diff) +10
-0+(firefly-rk3399) Image 'simple-bin' is missing external blobs and is non-functional: atf-bl31 +(firefly-rk3399) +(firefly-rk3399) /binman/simple-bin/fit/images/@atf-SEQ/atf-bl31 (atf-bl31): +(firefly-rk3399) See the documentation for your board. You may need to build ARM Trusted +(firefly-rk3399) Firmware and build with BL31=/path/to/bl31.bin +(firefly-rk3399) Image 'simple-bin' is missing optional external blobs but is still functional: tee-os +(firefly-rk3399) /binman/simple-bin/fit/images/@tee-SEQ/tee-os (tee-os): +(firefly-rk3399) See the documentation for your board. You may need to build Open Portable +(firefly-rk3399) Trusted Execution Environment (OP-TEE) and build with TEE=/path/to/tee.bin +(firefly-rk3399) Some images are invalid02: cmd: nvedit: Use
getopt()in env export
aarch64: (for 1/1 boards) all +883.0 rodata +199.0 text +684.0
firefly-rk3399 : all +883 rodata +199 text +684
u-boot: add: 5/0, grow: 0/-2 bytes: 1184/-500 (684)
function old new delta
__getopt- 520 +520
static.bdinfo_print_all - 324 +324
print_eth- 236 +236
print_bi_dram- 92 +92
getopt_init_state- 12 +12
do_env_export548 476 -72
do_bdinfo588 160 -428
03: cmd: nvedit: Usegetopt()in env importaarch64: (for 1/1 boards) all -27.0 rodata -55.0 text +28.0 firefly-rk3399 : all -27 rodata -55 text +28 u-boot: add: 0/0, grow: 1/0 bytes: 28/0 (28) function old new delta do_env_import 668 696 +28
Quoted 4 lines
And so this is why I'm just deferring this until someone has the time to pick up and address the underlying problems with this potential migration that have been raised in the previous iterations.
Chiming in because I was put in Cc...
Do I understand correctly that this only impacts U-Boot proper? If so, is a size increase in proper that much of a blocker? As opposed to xPL which usually resides in SRAM, I'm assuming U-Boot proper would run in RAM where I hope an additional ~700B shouldn't be too much to ask for? The issue however could be on the storage medium where U-Boot proper is located, maybe this gets the binary above the max space allowed for U-Boot proper to be stored (e.g. on some of my boards I'm (self-imposed) limited to 2000KiB) though I'm assuming it could be less than 700B if U-Boot proper is compressed for example. But I'm also lucky enough to have storage space and (D)RAM to spare on my boards.
Out of the RFC, I see the strlower() part as being separate from the rest, maybe that's something we could revisit separately? Reading the cover letter, we should even spare 60B with that alone, with the added benefit of easier maintainability?
Cheers,
Quentin
Quoted 94 lines · Quentin Schulz
Quoted 75 lines · Tom Rini
Quoted 29 lines · Simon Glass
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 innvedit.cEach 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 exportaarch64: (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.0Quoted 8 lines
Simon Glass (2):
cmd: nvedit: Usegetopt()in env export
cmd: nvedit: Usegetopt()in env importcmd/Kconfig | 2 + cmd/nvedit.c | 186 +++++++++++++++++++++++---------------------------- env/common.c | 2 +- 3 files changed, 85 insertions(+), 105 deletions(-)For the record, here's a link to v2:
https://lore.kernel.org/u-boot/[email protected]/
And here's the full size change for firefly-rk3399:
Summary of 3 commits for 1 boards (1 thread, 12 jobs per thread) 01: arm: Fix typo in linker scriptaarch64: w+ firefly-rk3399(quoted diff) +10
-0+(firefly-rk3399) Image 'simple-bin' is missing external blobs and is non-functional: atf-bl31 +(firefly-rk3399) +(firefly-rk3399) /binman/simple-bin/fit/images/@atf-SEQ/atf-bl31 (atf-bl31): +(firefly-rk3399) See the documentation for your board. You may need to build ARM Trusted +(firefly-rk3399) Firmware and build with BL31=/path/to/bl31.bin +(firefly-rk3399) Image 'simple-bin' is missing optional external blobs but is still functional: tee-os +(firefly-rk3399) /binman/simple-bin/fit/images/@tee-SEQ/tee-os (tee-os): +(firefly-rk3399) See the documentation for your board. You may need to build Open Portable +(firefly-rk3399) Trusted Execution Environment (OP-TEE) and build with TEE=/path/to/tee.bin +(firefly-rk3399) Some images are invalid02: cmd: nvedit: Use
getopt()in env export
aarch64: (for 1/1 boards) all +883.0 rodata +199.0 text +684.0
firefly-rk3399 : all +883 rodata +199 text +684
u-boot: add: 5/0, grow: 0/-2 bytes: 1184/-500 (684)
function old new delta
__getopt- 520 +520
static.bdinfo_print_all - 324 +324
print_eth- 236 +236
print_bi_dram- 92 +92
getopt_init_state- 12 +12
do_env_export548 476 -72
do_bdinfo588 160 -428
03: cmd: nvedit: Usegetopt()in env importaarch64: (for 1/1 boards) all -27.0 rodata -55.0 text +28.0 firefly-rk3399 : all -27 rodata -55 text +28 u-boot: add: 0/0, grow: 1/0 bytes: 28/0 (28) function old new delta do_env_import 668 696 +28Quoted 4 lines
And so this is why I'm just deferring this until someone has the time to pick up and address the underlying problems with this potential migration that have been raised in the previous iterations.
Chiming in because I was put in Cc...
Do I understand correctly that this only impacts U-Boot proper? If so, is a size increase in proper that much of a blocker? As opposed to xPL which usually resides in SRAM, I'm assuming U-Boot proper would run in RAM where I hope an additional ~700B shouldn't be too much to ask for? The issue however could be on the storage medium where U-Boot proper is located, maybe this gets the binary above the max space allowed for U-Boot proper to be stored (e.g. on some of my boards I'm (self-imposed) limited to 2000KiB) though I'm assuming it could be less than 700B if U-Boot proper is compressed for example. But I'm also lucky enough to have storage space and (D)RAM to spare on my boards.
Quoted 4 lines
Out of the RFC, I see the
strlower()part as being separate from the rest, maybe that's something we could revisit separately? Reading the cover letter, we should even spare 60B with that alone, with the added benefit of easier maintainability?
This was just impacting U-Boot proper. However, it showed I think two sets of problems. The first of which is that there was an expectation that switching the code should result in some sort of savings, somewhere. And it didn't. And we do have boards where the space between the end of U-Boot and the start of the environment is small and so global changes that aren't just bug fixes need careful consideration (and they've already turned off things that aren't needed for them such as EFI loader). The second thing was that the code wasn't really easier to read / follow. So I don't object to the concept but I think the outcome of this series was that our getopt needs to be looked at in a bit more detail, and figure out if it's really designed the way we need it.
Signature · 1 line
Tom
Quoted 100 lines · Tom Rini
Quoted 94 lines · Quentin Schulz
Quoted 75 lines · Tom Rini
Quoted 29 lines · Simon Glass
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 innvedit.cEach 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: Usegetopt()in env import
aarch64: (for 1/1 boards) all -27.0 rodata -55.0 text +28.0Quoted 8 lines
Simon Glass (2):
cmd: nvedit: Usegetopt()in env export
cmd: nvedit: Usegetopt()in env importcmd/Kconfig | 2 + cmd/nvedit.c | 186 +++++++++++++++++++++++---------------------------- env/common.c | 2 +- 3 files changed, 85 insertions(+), 105 deletions(-)For the record, here's a link to v2:
https://lore.kernel.org/u-boot/[email protected]/
And here's the full size change for firefly-rk3399:
Summary of 3 commits for 1 boards (1 thread, 12 jobs per thread) 01: arm: Fix typo in linker scriptaarch64: w+ firefly-rk3399(quoted diff) +10
-0+(firefly-rk3399) Image 'simple-bin' is missing external blobs and is non-functional: atf-bl31 +(firefly-rk3399) +(firefly-rk3399) /binman/simple-bin/fit/images/@atf-SEQ/atf-bl31 (atf-bl31): +(firefly-rk3399) See the documentation for your board. You may need to build ARM Trusted +(firefly-rk3399) Firmware and build with BL31=/path/to/bl31.bin +(firefly-rk3399) Image 'simple-bin' is missing optional external blobs but is still functional: tee-os +(firefly-rk3399) /binman/simple-bin/fit/images/@tee-SEQ/tee-os (tee-os): +(firefly-rk3399) See the documentation for your board. You may need to build Open Portable +(firefly-rk3399) Trusted Execution Environment (OP-TEE) and build with TEE=/path/to/tee.bin +(firefly-rk3399) Some images are invalid02: cmd: nvedit: Use
getopt()in env export
aarch64: (for 1/1 boards) all +883.0 rodata +199.0 text +684.0
firefly-rk3399 : all +883 rodata +199 text +684
u-boot: add: 5/0, grow: 0/-2 bytes: 1184/-500 (684)
function old new delta
__getopt- 520 +520
static.bdinfo_print_all - 324 +324
print_eth- 236 +236
print_bi_dram- 92 +92
getopt_init_state- 12 +12
do_env_export548 476 -72
do_bdinfo588 160 -428
03: cmd: nvedit: Usegetopt()in env importaarch64: (for 1/1 boards) all -27.0 rodata -55.0 text +28.0 firefly-rk3399 : all -27 rodata -55 text +28 u-boot: add: 0/0, grow: 1/0 bytes: 28/0 (28) function old new delta do_env_import 668 696 +28Quoted 4 lines
And so this is why I'm just deferring this until someone has the time to pick up and address the underlying problems with this potential migration that have been raised in the previous iterations.
Chiming in because I was put in Cc...
Do I understand correctly that this only impacts U-Boot proper? If so, is a size increase in proper that much of a blocker? As opposed to xPL which usually resides in SRAM, I'm assuming U-Boot proper would run in RAM where I hope an additional ~700B shouldn't be too much to ask for? The issue however could be on the storage medium where U-Boot proper is located, maybe this gets the binary above the max space allowed for U-Boot proper to be stored (e.g. on some of my boards I'm (self-imposed) limited to 2000KiB) though I'm assuming it could be less than 700B if U-Boot proper is compressed for example. But I'm also lucky enough to have storage space and (D)RAM to spare on my boards.
Quoted 4 lines
Out of the RFC, I see the
strlower()part as being separate from the rest, maybe that's something we could revisit separately? Reading the cover letter, we should even spare 60B with that alone, with the added benefit of easier maintainability?
Quoted 13 lines
This was just impacting U-Boot proper. However, it showed I think two sets of problems. The first of which is that there was an expectation that switching the code should result in some sort of savings, somewhere. And it didn't. And we do have boards where the space between the end of U-Boot and the start of the environment is small and so global changes that aren't just bug fixes need careful consideration (and they've already turned off things that aren't needed for them such as EFI loader). The second thing was that the code wasn't really easier to read / follow. So I don't object to the concept but I think the outcome of this series was that our getopt needs to be looked at in a bit more detail, and figure out if it's really designed the way we need it.
Understood, thanks for the additional info.
Cheers,
Quentin
Hi Quentin,
Quoted 116 lines · Quentin Schulz
Quoted 100 lines · Tom Rini
Quoted 94 lines · Quentin Schulz
Quoted 75 lines · Tom Rini
Quoted 29 lines · Simon Glass
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 innvedit.cEach 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: Usegetopt()in env import
aarch64: (for 1/1 boards) all -27.0 rodata -55.0 text +28.0Quoted 8 lines
Simon Glass (2):
cmd: nvedit: Usegetopt()in env export
cmd: nvedit: Usegetopt()in env importcmd/Kconfig | 2 + cmd/nvedit.c | 186 +++++++++++++++++++++++---------------------------- env/common.c | 2 +- 3 files changed, 85 insertions(+), 105 deletions(-)For the record, here's a link to v2:
https://lore.kernel.org/u-boot/[email protected]/
And here's the full size change for firefly-rk3399:
Summary of 3 commits for 1 boards (1 thread, 12 jobs per thread) 01: arm: Fix typo in linker scriptaarch64: w+ firefly-rk3399(quoted diff) +10
-0+(firefly-rk3399) Image 'simple-bin' is missing external blobs and is non-functional: atf-bl31 +(firefly-rk3399) +(firefly-rk3399) /binman/simple-bin/fit/images/@atf-SEQ/atf-bl31 (atf-bl31): +(firefly-rk3399) See the documentation for your board. You may need to build ARM Trusted +(firefly-rk3399) Firmware and build with BL31=/path/to/bl31.bin +(firefly-rk3399) Image 'simple-bin' is missing optional external blobs but is still functional: tee-os +(firefly-rk3399) /binman/simple-bin/fit/images/@tee-SEQ/tee-os (tee-os): +(firefly-rk3399) See the documentation for your board. You may need to build Open Portable +(firefly-rk3399) Trusted Execution Environment (OP-TEE) and build with TEE=/path/to/tee.bin +(firefly-rk3399) Some images are invalid02: cmd: nvedit: Use
getopt()in env export
aarch64: (for 1/1 boards) all +883.0 rodata +199.0 text +684.0
firefly-rk3399 : all +883 rodata +199 text +684
u-boot: add: 5/0, grow: 0/-2 bytes: 1184/-500 (684)
function old new delta
__getopt- 520 +520
static.bdinfo_print_all - 324 +324
print_eth- 236 +236
print_bi_dram- 92 +92
getopt_init_state- 12 +12
do_env_export548 476 -72
do_bdinfo588 160 -428
03: cmd: nvedit: Usegetopt()in env importaarch64: (for 1/1 boards) all -27.0 rodata -55.0 text +28.0 firefly-rk3399 : all -27 rodata -55 text +28 u-boot: add: 0/0, grow: 1/0 bytes: 28/0 (28) function old new delta do_env_import 668 696 +28Quoted 4 lines
And so this is why I'm just deferring this until someone has the time to pick up and address the underlying problems with this potential migration that have been raised in the previous iterations.
Chiming in because I was put in Cc...
Do I understand correctly that this only impacts U-Boot proper? If so, is a size increase in proper that much of a blocker? As opposed to xPL which usually resides in SRAM, I'm assuming U-Boot proper would run in RAM where I hope an additional ~700B shouldn't be too much to ask for? The issue however could be on the storage medium where U-Boot proper is located, maybe this gets the binary above the max space allowed for U-Boot proper to be stored (e.g. on some of my boards I'm (self-imposed) limited to 2000KiB) though I'm assuming it could be less than 700B if U-Boot proper is compressed for example. But I'm also lucky enough to have storage space and (D)RAM to spare on my boards.
Quoted 4 lines
Out of the RFC, I see the
strlower()part as being separate from the rest, maybe that's something we could revisit separately? Reading the cover letter, we should even spare 60B with that alone, with the added benefit of easier maintainability?Quoted 13 lines
This was just impacting U-Boot proper. However, it showed I think two sets of problems. The first of which is that there was an expectation that switching the code should result in some sort of savings, somewhere. And it didn't. And we do have boards where the space between the end of U-Boot and the start of the environment is small and so global changes that aren't just bug fixes need careful consideration (and they've already turned off things that aren't needed for them such as EFI loader). The second thing was that the code wasn't really easier to read / follow. So I don't object to the concept but I think the outcome of this series was that our getopt needs to be looked at in a bit more detail, and figure out if it's really designed the way we need it.
Quoted 1 line
Understood, thanks for the additional info.
For the first point, it is true - I honestly don't see much in the way of savings. In fact I had to work (very) hard just to keep things the same after a conversion. Granted, this work can be used for other commands too. As I may have mentioned elsewhere, I could imagine changing the 'cmd' function-signature to a version which is just passed the getopt struct. I later did some experimentation and it did help, saving about 30 bytes (from memory) for each command.
For the second point, getopt() is easy enough to follow for regular commands, but U-Boot does have a lot of hand-parsed pieces that translate less well to getopt(). When I chose what to convert I deliberately chose the odd things so that we wouldn't go ahead with the conversion and then discover lots of pain later. Better to go in with eyes open.
For your third point, when I see size increasing I tend to look around randomly for things to chop. So I think it is better to keep the strlower() win in the bag, ready for use when we need it to maintain code size.
My vote (as I may have mentioned :-) is to bite the bullet and enable getopt() for most boards...improving the architecture as we go. I doubt anyone would take on converting ~1000 U-Boot commands in one go, so we have to start somewhere.
Regards,
Simon