[U-Boot] How can I save U-Boot env vars to HUSH shell vars.

Wolfgang Denk
2014-04-10T06:52:20Z

Dear James,

In message <5345D493.4080803@gmail.com> you wrote:
>
> > Heh. As soon as you have to change _any_ code, you can as well
> > upgrade.
>
> I was hoping (in vain perhaps) to do my work modifying only the environment.

Yes, I understand this. But I have to admit that I don't see an easy
way.

Hm... thinking about it, you _can_ do this, but it's a bit ugly...

POC code:

=> print ethaddr ipaddr serverip
ethaddr=00:10:ec:01:08:84
ipaddr=192.168.100.6
serverip=192.168.1.1

=> echo E=$foo_ethaddr I=$foo_ipaddr S=$foo_serverip
E= I= S=

=> setenv setvar 'setenv tmp "foo_$arg=$$arg"'

=> for arg in ethaddr ipaddr serverip ; do
> run setvar
> run tmp
> echo E=$foo_ethaddr I=$foo_ipaddr S=$foo_serverip
> done
E=00:10:ec:01:08:84 I= S=
E=00:10:ec:01:08:84 I=192.168.100.6 S=
E=00:10:ec:01:08:84 I=192.168.100.6 S=192.168.1.1

As you can see, I'm useing a two-step approach to first constuct a
command and then to run it. This "consumes" 2 environment variables
("tmp" and "arg"), but this should be an acceptable price...

> This is a definite drawback to having an old U-Boot; I'm sure I would
> benefit from the bug fixes and other enhancements.

Yes.

> Exporting a list of values sounds like a nice addition that would be
> helpful to me.

The new env command allows for a lot of interesting features, like
maintaining a set of "user profiles", i. e. independent sets of
environment settings which can be loaded and restored as you lik,
including things like perfoming a "reset to factory defaults" (which
still can be changed, i. e. you can update the factory default
settings and are not limited to the fixed compiled in default env
values.

> I suppose, with my 2010.12, I could export everything to memory and then
> parse through it to find the values I need then import them. Sounds
> vaguely possible but it's probably more complex than doing the U-Boot
> upgrade.

You don't have enough tools in the shell to do this parsing by any
scripts, so you would need code. And if you add new code, you change
the binary anyway, so you could upgrade as well.

Best regards,

Wolfgang Denk

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"I knew then (in 1970) that a 4-kbyte minicomputer would cost as much
as a house. So I reasoned that after college, I'd have to live
cheaply in an apartment and put all my money into owning a computer."
- Apple co-founder Steve Wozniak, EE Times, June 6, 1988, pg 45