public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: James Chargin <jimccrown@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] How can I save U-Boot env vars to HUSH shell vars.
Date: Thu, 10 Apr 2014 09:58:42 -0700	[thread overview]
Message-ID: <5346CDC2.40400@gmail.com> (raw)
In-Reply-To: <20140410065220.D43D73803C8@gemini.denx.de>

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

  reply	other threads:[~2014-04-10 16:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2014-04-10 18:46         ` Wolfgang Denk

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=5346CDC2.40400@gmail.com \
    --to=jimccrown@gmail.com \
    --cc=u-boot@lists.denx.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox