All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] How can I save U-Boot env vars to HUSH shell vars.
@ 2014-04-09 21:09 James Chargin
  2014-04-09 21:50 ` Wolfgang Denk
  0 siblings, 1 reply; 6+ messages in thread
From: James Chargin @ 2014-04-09 21:09 UTC (permalink / raw)
  To: u-boot

I'd like to store the values of environment variables in HUSH shell 
variables and then restore them later. My ultimate goal is to preserve a 
few environment variables through a "env default -f".

I'm working with U-Boot 2010.12. Changing to a newer version is not 
possible at this time.

I realize this is a very old U-Boot. I'm hoping that the relevant parts 
of U-Boot have not changed between that old version and versions you 
might provide help for.

I tried a few things and haven't found the right combination. I think 
the following commands demonstrate my problem.

Given the U-Boot commands

=> setenv e "e ethaddr ipaddr rootpath"
=>
=> printenv e ethaddr ipaddr rootpath
e=e ethaddr ipaddr rootpath
ethaddr=00:00:17:88:09:36
ipaddr=10.3.134.80
rootpath=/home/anyuser/a/device/tr/rootfs
=>
=> for i in $e; do v_$i=$i; done
=>

What I get:

=> showvar
HUSH_VERSION=0.01
v_e=e
v_ethaddr=ethaddr
v_ipaddr=ipaddr
v_rootpath=rootpath
=>

What I want:

=> showvar
HUSH_VERSION=0.01
v_e=e ethaddr ipaddr rootpath
v_ethaddr=00:00:17:88:09:36
v_ipaddr=10.3.134.80
v_rootpath=/home/anyuser/a/device/tr/rootfs
=>

So, how do I re-write the for loop to get the desired results

Thanks for any help,
Jim

-- 
Jim Chargin
AJA Video Systems                       jimc at aja.com
(530) 271-3334                          http://www.aja.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] How can I save U-Boot env vars to HUSH shell vars.
  2014-04-09 21:09 [U-Boot] How can I save U-Boot env vars to HUSH shell vars James Chargin
@ 2014-04-09 21:50 ` Wolfgang Denk
  2014-04-09 23:15   ` James Chargin
  0 siblings, 1 reply; 6+ messages in thread
From: Wolfgang Denk @ 2014-04-09 21:50 UTC (permalink / raw)
  To: u-boot

Dear James,

In message <5345B6EC.6050109@gmail.com> you wrote:
> I'd like to store the values of environment variables in HUSH shell 
> variables and then restore them later. My ultimate goal is to preserve a 
> few environment variables through a "env default -f".

It is probably easier to use "env export" to store this set of
variables to some area in memory.  You could even make this permanent
by writing it to flash or some storage device.

> I'm working with U-Boot 2010.12. Changing to a newer version is not 
> possible at this time.

Heh.  As soon as you have to change _any_ code, you can as well
upgrade.

> I realize this is a very old U-Boot. I'm hoping that the relevant parts 
> of U-Boot have not changed between that old version and versions you 
> might provide help for.

Well, a ton of bug fixes and improvements have been added since.  One
of the extensions you want and which has been added only after
v2010.12 is the capability to export only a sub-set of the environment
(i. e. a list of variables passed on the command line).

> => for i in $e; do v_$i=$i; done
...
> What I get:

...is exactly what you coded.  You would get the same in any other
shell, too.

> => showvar
> HUSH_VERSION=0.01
> v_e=e ethaddr ipaddr rootpath
> v_ethaddr=00:00:17:88:09:36
> v_ipaddr=10.3.134.80
> v_rootpath=/home/anyuser/a/device/tr/rootfs
> =>
> 
> So, how do I re-write the for loop to get the desired results

This would require an "eval" or command substitution, which we do not
have in our implementation of the hush shell.

To me it seems the easiest way to get what you want is to use
"env export ... ethaddr ipaddr rootpath" or similar.

Um... yes, this requires an update to more recent code.

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
Of course there's no reason for it, it's just our policy.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] How can I save U-Boot env vars to HUSH shell vars.
  2014-04-09 21:50 ` Wolfgang Denk
@ 2014-04-09 23:15   ` James Chargin
  2014-04-10  6:52     ` Wolfgang Denk
  0 siblings, 1 reply; 6+ messages in thread
From: James Chargin @ 2014-04-09 23:15 UTC (permalink / raw)
  To: u-boot

Dear Wolfgang,

Thank you for your reply.

On 04/09/2014 02:50 PM, Wolfgang Denk wrote:
> Dear James,
>
> In message <5345B6EC.6050109@gmail.com> you wrote:
>> I'd like to store the values of environment variables in HUSH shell
>> variables and then restore them later. My ultimate goal is to preserve a
>> few environment variables through a "env default -f".
>
> It is probably easier to use "env export" to store this set of
> variables to some area in memory.  You could even make this permanent
> by writing it to flash or some storage device.

I hadn't thought of exporting the environment to memory, excellent idea.

>
>> I'm working with U-Boot 2010.12. Changing to a newer version is not
>> possible at this time.
>
> 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.

>
>> I realize this is a very old U-Boot. I'm hoping that the relevant parts
>> of U-Boot have not changed between that old version and versions you
>> might provide help for.
>
> Well, a ton of bug fixes and improvements have been added since.  One
> of the extensions you want and which has been added only after
> v2010.12 is the capability to export only a sub-set of the environment
> (i. e. a list of variables passed on the command line).
>

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

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

>> => for i in $e; do v_$i=$i; done
> ...
>> What I get:
>
> ...is exactly what you coded.  You would get the same in any other
> shell, too.
>
>> => showvar
>> HUSH_VERSION=0.01
>> v_e=e ethaddr ipaddr rootpath
>> v_ethaddr=00:00:17:88:09:36
>> v_ipaddr=10.3.134.80
>> v_rootpath=/home/anyuser/a/device/tr/rootfs
>> =>
>>
>> So, how do I re-write the for loop to get the desired results
>
> This would require an "eval" or command substitution, which we do not
> have in our implementation of the hush shell.
>

"eval" seemed to me also to be what I wanted. I'm aware it isn't present 
in hush, but I was hoping for some magic from the community. :-)

> To me it seems the easiest way to get what you want is to use
> "env export ... ethaddr ipaddr rootpath" or similar.
>

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.

> Um... yes, this requires an update to more recent code.

Yes, update is on my to-do list, but schedules dictate that the upgrade 
is not my first priority. The conclusion reached here adds to the 
argument for doing it sooner rather than later.

>
> Best regards,
>
> Wolfgang Denk
>

Thank you again for you comments.
Jim

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] How can I save U-Boot env vars to HUSH shell vars.
  2014-04-09 23:15   ` James Chargin
@ 2014-04-10  6:52     ` Wolfgang Denk
  2014-04-10 16:58       ` James Chargin
  0 siblings, 1 reply; 6+ messages in thread
From: Wolfgang Denk @ 2014-04-10  6:52 UTC (permalink / raw)
  To: u-boot

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] How can I save U-Boot env vars to HUSH shell vars.
  2014-04-10  6:52     ` Wolfgang Denk
@ 2014-04-10 16:58       ` James Chargin
  2014-04-10 18:46         ` Wolfgang Denk
  0 siblings, 1 reply; 6+ messages in thread
From: James Chargin @ 2014-04-10 16:58 UTC (permalink / raw)
  To: u-boot

Dear Wolfgang,

With your help, I have satisfied my need.

On 04/09/2014 11:52 PM, Wolfgang Denk wrote:
> 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...

Extending this a bit further to include yet another env var, I have the 
following that allows a list to be saved and restored.

	=> setenv setvar 'setenv tmp "v_$arg=$$arg"'
	=> setenv usevar 'setenv t v_$arg;setenv tmp "setenv $arg $$t"'
	=>
And testing these:
	=> setenv list "ipaddr ethaddr list"
	=> printenv ipaddr ethaddr
	ipaddr=10.3.134.80
	ethaddr=00:00:17:88:09:36
	=>
	=> # to save
	=> for arg in $list; do run setvar; run tmp; done
	=> showvar
	HUSH_VERSION=0.01
	arg=list
	v_ipaddr=10.3.134.80
	v_ethaddr=00:00:17:88:09:36
	v_list=ipaddr ethaddr list
	=>
	=> # simulate "env default -f"
	=> setenv ethaddr; setenv ipaddr; setenv list
	=>
	=> # to restore (note use of v_list rather than list)
	=> for arg in $v_list; do run usevar; run tmp; done
	=> printenv ipaddr ethaddr list
	ipaddr=10.3.134.80
	ethaddr=00:00:17:88:09:36
	list=ipaddr ethaddr list
	=>

Perhaps this isn't as nice looking as it could be. But, it does solve 
the problem at hand, which has value for me. The solution boils down to 
two definitions in the default environment (setvar and usevar) and then 
a single script line to save the values and another single script line 
to restore them. I don't consider this addition burdensome at all.

And to paraphrase a former US Sec Def, "You code with the tools you have 
rather than with the tools you might like to have."

Setting temporaries to commands that are then executed as a means to 
getting evaluations done when needed seems like a great addition to the 
"bag of tricks"

> ...
>
> The new env command allows for a lot of interesting features, ...

I look forward to using these new facilities.

And, I appreciate you help very much.

Best regards,
Jim
-- 
Jim Chargin
AJA Video Systems                       jimc at aja.com
(530) 271-3334                          http://www.aja.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [U-Boot] How can I save U-Boot env vars to HUSH shell vars.
  2014-04-10 16:58       ` James Chargin
@ 2014-04-10 18:46         ` Wolfgang Denk
  0 siblings, 0 replies; 6+ messages in thread
From: Wolfgang Denk @ 2014-04-10 18:46 UTC (permalink / raw)
  To: u-boot

Dear James,

In message <5346CDC2.40400@gmail.com> you wrote:
> 
> With your help, I have satisfied my need.

I'm happy that I was able to help.

Thanks for the summary and your actual code.

> And, I appreciate you help very much.

You are welcome.

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
God made the integers; all else is the work of Man.       - Kronecker

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-04-10 18:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-09 21:09 [U-Boot] How can I save U-Boot env vars to HUSH shell vars James Chargin
2014-04-09 21:50 ` Wolfgang Denk
2014-04-09 23:15   ` James Chargin
2014-04-10  6:52     ` Wolfgang Denk
2014-04-10 16:58       ` James Chargin
2014-04-10 18:46         ` Wolfgang Denk

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.