[U-Boot] [PATCH] cmd_bootm: Add command line arguments to Plan 9

Steven Stallion sstallion at gmail.com
Fri Jun 7 18:13:20 CEST 2013


On Fri, Jun 7, 2013 at 1:16 AM, Wolfgang Denk <wd at denx.de> wrote:

> In message <CAGGHmKHmLAd_85SgHyC=
> cEUmHu8u4ENQyj3Wt3rqyVdzAtWoSw at mail.gmail.com> you wrote:
> >
> > > Please make this code configurable, so that people who never intend to
> > > use Plan 9 do not suffer from the increased code size.
> >
> > This is already done, if you look at the do_bootm_plan9 function, you'll
> > see it is guarded by CONFIG_BOOTM_PLAN9. These changes only affect users
> > that are booting Plan 9.
>
> I see.  Hm... I wonder which version of U-Boot your patch is against?
> The line numbers in your patch are off by at least 126 lines, and
> common/cmd_bootm.c has not been touched for many months ?
>

That's odd. I just double checked and my repository seems to be in sync.
I'll do some poking around to make sure I didn't miss something.

> > ERROR: do not use assignment in if condition
> >
> > I noticed the errors, however the style and format of my changes are the
> > same as those in other functions in cmd_bootm; do_bootm_netbsd probably
> > being the closest example. I did not watch to introduce style drift.
>
> But we should not add more bad style code either.  Feel free to send a
> cleanup patch for the existing code parts.  In any case, do not add
> more such stuff.
>

Will do.

> It's as unlimited as you have memory :-) That said, adjacent pages to
> > CONFADDR are zeroed out at boot, so there is no possibility of overflow
> > once you branch to the kernel.
>
> Adjacent pages being zeroed - that means that you _are_ actually
> limited to one page size?
>
> > > Why do you make this (completely undocumented!!!) distinction between
> > > "bootm" being used with one or more arguments?  Why can you not
> > > simply _always_ use bootargs ?
> >
> > This is to support passing arguments via bootm. This behavior is
> consistent
> > with NetBSD.
>
> ...which I consider a really weird desiign that IMO should not be
> followed without need.
>
> If you decide to do so nevertheless, then please
>
> 1) document the behaviour
> 2) factor out the common code instead of copying it
>

Hmm. Are you arguing against supporting command line arguments to bootm, or
that bootm should copy these arguments to bootargs prior to boot? This has
actually been very useful to test changes without having to update my
bootargs environment variable.

Where is the best place to document the behavior, README? The code looks as
though it's common, but unfortunately it's not. plan9.ini(8) requires that
arguments be terminated with a newline, the NetBSD loader uses spaces.

> > What if the user did not set the "confaddr" environment variable?
> > > Then the memory reagion there is left uninitialized?  Does this not
> > > cause undefined behaviour when booting Plan 9?
> >
> > There are checks which account for uninitialized memory at boot. It's
> ugly,
> > but it's how the OS deals with configuration. I don't like it either.
>
> How does it detect if there are valid arguments (versus random crap)
> in the memory range starting at "confaddr"?  I can see no checksum or
> similar?
>

Some ports (such as OMAP) will stop once it encounters the first non-ASCII
character. In general, the parsing for the configuration is fairly strict
and is only a small risk if a user configures the system incorrectly.

There is also something subtle in not specifying confaddr (or bootargs for
that matter). Many ports support loading configuration from a FAT file
system. U-Boot would be no different.

I realize this probably seems very foreign. Plan 9 is somewhat unique in
that it relies on a variety of loaders. Some are more intelligent than
others, but in the end, configuration has to be dropped in a known location
for the kernel to parse. There is no second-stage loader, so passing a
pointer has limited utility since the code to parse the config happens
after the MMU has been initialized.

> And how does Plan 9 learn where to find this date? I cannot see how
> > > you pass this address on to Plan 9?
> >
> > Like most things in Plan 9, it is a compiled offset (defined in mem.h).
> > CONFADDR is fixed, so as long as the configuration is dumped to the right
> > location (which can change between kernels), it will work.
>
> But then makes no sense to use a "confaddr" environment variable for
> this - the user has no real choice of setting this variable: either it
> matches the fixed CONFADDR value, in which case it works, or it is
> different, in which case it will silently fail.  This is bad.
> I think you should use a CONFIG_SYS_CONFADDR constant instead.
>

Ah, this is another subtlety. CONFADDR can change depending on the kernel
you are booting. Some ports use as much as 64K to store configuration.
Having to recompile U-Boot and reflash based on a kernel change would add a
lot of complication and frustration. Having confaddr also makes it somewhat
simpler to write a generic boot command which will do a fatload rather than
use bootargs.

> Even worse - this code is actually pretty dangerous: "confaddr" is
> > > neither a reserved name, nor is it in any way exotic enough to be sure
> > > nobody else would use this in his environment.  But if somebody does,
> > > he will suddenly find that some (for him random) data is copied unex-
> > > pectedly to that memory range.  This may cause nasty crashes or other
> > > undefined behaviour which is very difficult to debug.
> >
> > True, but it's no different than loadaddr. This only affects Plan 9
> users,
> > and this behavior will be documented for the kernels which support
> U-Boot.
> > I don't think there is too much danger here, though documentation will be
> > important.
>
> It is not documented in U-Boot.  But actually I think this is void -
> using an envrionment variable here makes no sense in the first place.
>

Is there a better method to allow confaddr to change without forcing a
re-compile, or duplication if a user decides to do a fatload rather than
define bootargs?

Cheers,

Steve


More information about the U-Boot mailing list