All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Rini <trini@konsulko.com>
To: Sean Anderson <seanga2@gmail.com>
Cc: "Simon Glass" <sjg@chromium.org>,
	u-boot@lists.denx.de,
	"Andrew Goodbody" <andrew.goodbody@linaro.org>,
	"Benoît Thébaudeau" <benoit.thebaudeau@advansee.com>,
	"Casey Connolly" <casey.connolly@linaro.org>,
	"Daniel Palmer" <daniel@thingy.jp>,
	"Heiko Schocher" <hs@nabladev.com>,
	"Heinrich Schuchardt" <xypron.glpk@gmx.de>,
	"Hugo Villeneuve" <hvilleneuve@dimonoff.com>,
	"Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
	"Jerome Forissier" <jerome.forissier@arm.com>,
	"Joe Hershberger" <joe.hershberger@ni.com>,
	"Kory Maincent (TI.com)" <kory.maincent@bootlin.com>,
	"Marek Vasut" <marek.vasut+renesas@mailbox.org>,
	"Mattijs Korpershoek" <mkorpershoek@kernel.org>,
	"Michal Simek" <michal.simek@amd.com>,
	"Mikhail Kshevetskiy" <mikhail.kshevetskiy@iopsys.eu>,
	"Patrice Chotard" <patrice.chotard@foss.st.com>,
	"Peng Fan" <peng.fan@nxp.com>,
	"Peter Robinson" <pbrobinson@gmail.com>,
	"Quentin Schulz" <quentin.schulz@cherry.de>,
	"Varadarajan Narayanan" <varadarajan.narayanan@oss.qualcomm.com>,
	"Yao Zi" <me@ziyao.cc>
Subject: Re: [RFC PATCH 00/11] Tidy command option parsing and use it a bit
Date: Fri, 15 May 2026 16:21:07 -0600	[thread overview]
Message-ID: <20260515222107.GN1858239@bill-the-cat> (raw)
In-Reply-To: <aa023095-2b32-070f-ff43-1f6922918b51@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4763 bytes --]

On Fri, May 15, 2026 at 06:06:38PM -0400, Sean Anderson wrote:
> 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.

We don't even see a reduction on "qcom" which is a platform that already
enabled GETOPT. nvedit is growth too:
01: Prepare v2026.07-rc2
02: lib: string: Add strlower()
   aarch64: (for 1/1 boards) data -40.0 rodata +40.0
            qcom           : data -40 rodata +40
03: cmd: ini: Use strlower() to normalise case
04: fs: fat: Use strlower() to normalise case
05: boot: pxe_utils: Use strlower() in get_string()
06: lib: getopt: Permute by default with inline reorder
   aarch64: (for 1/1 boards) all -6.0 data -24.0 rodata +18.0
            qcom           : all -6 data -24 rodata +18
               u-boot: add: 0/0, grow: 5/-1 bytes: 272/-8 (264)
                 function                                   old     new   delta
                 __getopt                                   576     756    +180
                 getopt_init_state                           12      88     +76
                 do_log_filter_remove                       364     372      +8
                 do_log_filter_list                         444     448      +4
                 do_log_filter_add                          580     584      +4
                 do_bdinfo                                  160     152      -8
07: lib: getopt: Add getopt_pop() helper
08: cmd: echo: Use getopt() with '+' prefix for option parsing
   aarch64: (for 1/1 boards) all +3.0 rodata +3.0
            qcom           : all +3 rodata +3
               u-boot: add: 0/0, grow: 1/0 bytes: 68/0 (68)
                 function                                   old     new   delta
                 do_echo                                    156     224     +68
09: cmd: hash: Use getopt() for option parsing
10: cmd: nvedit: Use getopt() in env grep
11: cmd: nvedit: Use getopt() in env export and env import
   aarch64: (for 1/1 boards) all -4.0 data -16.0 rodata +12.0
            qcom           : all -4 data -16 rodata +12
               u-boot: add: 0/0, grow: 2/0 bytes: 164/0 (164)
                 function                                   old     new   delta
                 do_env_import                              692     832    +140
                 do_env_export                              608     632     +24
12: doc: commands: Recommend getopt() for option parsing

> 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.

Yes, it would be good to move in that direction. But we need to figure
out how to do it in such a way that's not such a big size loss. If we
have to do a big conversion to start with, fine. If we have to
restructure a few other things, fine. But "convert echo so everyone
links it now and it's sunk-cost" isn't the right path.

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2026-05-15 22:21 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-15 20:32 [RFC PATCH 00/11] Tidy command option parsing and use it a bit Simon Glass
2026-05-15 20:32 ` [RFC PATCH 01/11] lib: string: Add strlower() Simon Glass
2026-05-15 20:32 ` [RFC PATCH 02/11] cmd: ini: Use strlower() to normalise case Simon Glass
2026-05-15 20:32 ` [RFC PATCH 03/11] fs: fat: " Simon Glass
2026-05-15 20:32 ` [RFC PATCH 04/11] boot: pxe_utils: Use strlower() in get_string() Simon Glass
2026-05-15 20:32 ` [RFC PATCH 05/11] lib: getopt: Permute by default with inline reorder Simon Glass
2026-05-15 21:37   ` Sean Anderson
2026-05-15 20:32 ` [RFC PATCH 06/11] lib: getopt: Add getopt_pop() helper Simon Glass
2026-05-15 21:40   ` Sean Anderson
2026-05-15 20:32 ` [RFC PATCH 07/11] cmd: echo: Use getopt() with '+' prefix for option parsing Simon Glass
2026-05-15 21:58   ` Sean Anderson
2026-05-15 20:32 ` [RFC PATCH 08/11] cmd: hash: Use getopt() " Simon Glass
2026-05-15 20:33 ` [RFC PATCH 09/11] cmd: nvedit: Use getopt() in env grep Simon Glass
2026-05-15 20:33 ` [RFC PATCH 10/11] cmd: nvedit: Use getopt() in env export and env import Simon Glass
2026-05-15 20:33 ` [RFC PATCH 11/11] doc: commands: Recommend getopt() for option parsing Simon Glass
2026-05-15 21:43 ` [RFC PATCH 00/11] Tidy command option parsing and use it a bit Tom Rini
2026-05-15 21:59   ` Sean Anderson
2026-05-15 22:06     ` Sean Anderson
2026-05-15 22:21       ` Tom Rini [this message]
2026-05-15 22:27         ` Sean Anderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260515222107.GN1858239@bill-the-cat \
    --to=trini@konsulko.com \
    --cc=andrew.goodbody@linaro.org \
    --cc=benoit.thebaudeau@advansee.com \
    --cc=casey.connolly@linaro.org \
    --cc=daniel@thingy.jp \
    --cc=hs@nabladev.com \
    --cc=hvilleneuve@dimonoff.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jerome.forissier@arm.com \
    --cc=joe.hershberger@ni.com \
    --cc=kory.maincent@bootlin.com \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=me@ziyao.cc \
    --cc=michal.simek@amd.com \
    --cc=mikhail.kshevetskiy@iopsys.eu \
    --cc=mkorpershoek@kernel.org \
    --cc=patrice.chotard@foss.st.com \
    --cc=pbrobinson@gmail.com \
    --cc=peng.fan@nxp.com \
    --cc=quentin.schulz@cherry.de \
    --cc=seanga2@gmail.com \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    --cc=varadarajan.narayanan@oss.qualcomm.com \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.