[RFC PATCH 00/11] Tidy command option parsing and use it a bit
Sean Anderson
seanga2 at gmail.com
Sat May 16 00:06:38 CEST 2026
On 5/15/26 17:59, Sean Anderson wrote:
> On 5/15/26 17:43, Tom Rini wrote:
>> On Fri, May 15, 2026 at 02:32:51PM -0600, Simon Glass wrote:
>>
>>> We have had getopt() for over five years but it is not much used. It is
>>> much easier to understand arg-parsing using getopt() and it avoids
>>> common errors. As the named maintainer I decided to look at how to make
>>> more use of it.
>>>
>>> So this series explores the impact of converting a few commands to use
>>> getopt() instead of ad-hoc parsing. It updates getopt() to handle flags
>>> anywhere in the cmdline and provides a few helpers to reduce
>>> boilerplate.
>>>
>>> The chosen commands are:
>>>
>>> - echo: very simple with no flags
>>> - hash: fairly simple with just one flag
>>> - env grep/export/import - fuller examples
>>>
>>> The series also adds a recommendation to use getopt() for new commands.
>>>
>>> To try to reduce the code-size increase, a lower-case function is added
>>> and called from a few places. The difference is fairly marginal.
>>>
>>> Overall, the result is not pretty (see below) with about a 1.1K size
>>> increase on arm64:
>>
>> I think that means this is a no-go, and you need to work out what might
>> lead to a much smaller growth here.
>>
>
> Unfortunately, the only way to get a size reduction is to convert as many
> commands as possible.
>
> --Sean
And to expand on this, you really only get a reduction for any given command
when there are several options being parsed already like in the nvedit stuff.
Since most U-Boot commands don't use options it will be difficult to get a
reduction even when converting most commands on a board.
That's why I used it for new commands where no one could complain that
I grew their board.
I think it would be nice for all u-boot commands to have proper option support
like in barebox, but it's a lot of effort.
--Sean
More information about the U-Boot
mailing list