public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] setting u-boot params based on serial number
@ 2009-10-23 16:52 David Collier
  2009-10-23 16:58 ` Ben Warren
  2009-10-23 18:03 ` Wolfgang Denk
  0 siblings, 2 replies; 11+ messages in thread
From: David Collier @ 2009-10-23 16:52 UTC (permalink / raw)
  To: u-boot

This may be bloody obvious to most of you, but I'm still learning.

I have a batch of boards in production.

say serial numbers 1 to 50

I want to set the 2 mac address, and the ip address so that the last few
digits match the serial number.

can I do this easily with some sort of u-boot script? Or can I run an app
I write myself in C or whatever, and get it to do setenv commands?

AVR32, if it matters

TVM

David Collier

www.dexdyne.com

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

* [U-Boot] setting u-boot params based on serial number
  2009-10-23 16:52 [U-Boot] setting u-boot params based on serial number David Collier
@ 2009-10-23 16:58 ` Ben Warren
  2009-10-23 18:03 ` Wolfgang Denk
  1 sibling, 0 replies; 11+ messages in thread
From: Ben Warren @ 2009-10-23 16:58 UTC (permalink / raw)
  To: u-boot

David Collier wrote:
> This may be bloody obvious to most of you, but I'm still learning.
>
> I have a batch of boards in production.
>
> say serial numbers 1 to 50
>
> I want to set the 2 mac address, and the ip address so that the last few
> digits match the serial number.
>
> can I do this easily with some sort of u-boot script? Or can I run an app
> I write myself in C or whatever, and get it to do setenv commands?
>
>   
Yes
> AVR32, if it matters
>
>   
It shouldn't.  You can do this any number of ways, but if it was me I'd 
script it off-target.  I'm a big fan of Python, so tend to use pexpect 
for this sort of thing.
> TVM
>
> David Collier
>   
regards,
Ben

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

* [U-Boot] setting u-boot params based on serial number
  2009-10-23 16:52 [U-Boot] setting u-boot params based on serial number David Collier
  2009-10-23 16:58 ` Ben Warren
@ 2009-10-23 18:03 ` Wolfgang Denk
  2009-10-23 20:13   ` David Collier
  1 sibling, 1 reply; 11+ messages in thread
From: Wolfgang Denk @ 2009-10-23 18:03 UTC (permalink / raw)
  To: u-boot

Dear "David Collier",

In message <memo.20091023175206.2092W@postmaster+dexdyne.com.cix.co.uk> you wrote:
> 
> I have a batch of boards in production.
> 
> say serial numbers 1 to 50
> 
> I want to set the 2 mac address, and the ip address so that the last few
> digits match the serial number.
> 
> can I do this easily with some sort of u-boot script? Or can I run an app
> I write myself in C or whatever, and get it to do setenv commands?

You can do this using the "setexpr" command, with the restriction that
you cannot easily get leading zeros in the strings to fill tem up for
the requested length, but for the usage you mention it does not
matter. Also, you cannot easily convert to hex number, if that would
be needed.

Example:

	=> print serial#
	serial#=12851192

Extract last 2 digits into vatiable "tmp" (note: serial# must consist
of digits only):

	=> setex tmp ${serial#} % 100
	=> print tmp 
	tmp=92

Set MAC and IP address as requested:

	=> setenv ip_base 192.168.3.
	=> setenv mac_base ce:94:6b:3a:db:

	=> setenv ipaddr ${ip_base}${tmp}
	=> print ipaddr
	ipxxx=192.168.3.92
	=> setenv ethaddr ${mac_base}${tmp}
	=> print ethaddr
	ethaddr=ce:94:6b:3a:db:92

> AVR32, if it matters

It does not matter. This works on all boards / architectures. You just
have to enable CONFIG_CMD_SETEXPR in your board configuration.


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
"The good Christian should beware of mathematicians and all those who
make empty prophecies. The danger already exists that  mathematicians
have  made a covenant with the devil to darken the spirit and confine
man in the bonds of Hell."                          - Saint Augustine

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

* [U-Boot] setting u-boot params based on serial number
  2009-10-23 18:03 ` Wolfgang Denk
@ 2009-10-23 20:13   ` David Collier
  2009-10-23 20:38     ` David Collier
  2009-10-23 21:04     ` Wolfgang Denk
  0 siblings, 2 replies; 11+ messages in thread
From: David Collier @ 2009-10-23 20:13 UTC (permalink / raw)
  To: u-boot


Well I have got it working - but it seems to do exactly what you say it
doesn't

for instance 

LPNC U-Boot> printenv serialnumber
serialnumber=410
LPNC U-Boot> setexpr sn34 ${serialnumber} / 2
LPNC U-Boot> printenv sn34
sn34=208

so it looks like it works ONLY in hex -

yup

	a = simple_strtoul(argv[2], NULL, 16);
	b = simple_strtoul(argv[4], NULL, 16);

I'd like the decimal version like you described :-)

so I've defined setexprd to do that

David

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

* [U-Boot] setting u-boot params based on serial number
  2009-10-23 20:13   ` David Collier
@ 2009-10-23 20:38     ` David Collier
  2009-10-23 21:05       ` Wolfgang Denk
  2009-10-23 21:04     ` Wolfgang Denk
  1 sibling, 1 reply; 11+ messages in thread
From: David Collier @ 2009-10-23 20:38 UTC (permalink / raw)
  To: u-boot

wow

serialnumber=1234
set_mac_IP=setexprd sn34 ${serialnumber} % 100 ;setexprd sn12
${serialnumber} / 100; setenv ipaddr 10.212.${sn12}.${sn34}; setenv
ethaddr 00:90:46:20:${sn12}:${sn34}; setenv eth1addr
00:90:46:21:${sn12}:${sn34}; setenv sn12 ; setenv sn34

that's seriously useful!

TVM

David Collier

www.dexdyne.com

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

* [U-Boot] setting u-boot params based on serial number
  2009-10-23 20:13   ` David Collier
  2009-10-23 20:38     ` David Collier
@ 2009-10-23 21:04     ` Wolfgang Denk
  2009-10-26 10:36       ` David Collier
  1 sibling, 1 reply; 11+ messages in thread
From: Wolfgang Denk @ 2009-10-23 21:04 UTC (permalink / raw)
  To: u-boot

Dear "David Collier",

In message <memo.20091023211352.2092c@postmaster+dexdyne.com.cix.co.uk> you wrote:
> 
> Well I have got it working - but it seems to do exactly what you say it
> doesn't

Well, I'm not always right :-)

> so it looks like it works ONLY in hex -

Makes sense. That's what semi-all commands do in U-Boot.

> I'd like the decimal version like you described :-)
> 
> so I've defined setexprd to do that

I did not only describe it, I tested it. I just "tricked" a bit.
You asked to extract the last two digits, and I used "% 100" to do
this. Note that this works correctly in any number base - may it be 10
or 16 or whatever :-)

Hey, that was clever, wasn't it? :-)

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
"Love is an ideal thing, marriage a real thing; a  confusion  of  the
real with the ideal never goes unpunished."                  - Goethe

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

* [U-Boot] setting u-boot params based on serial number
  2009-10-23 20:38     ` David Collier
@ 2009-10-23 21:05       ` Wolfgang Denk
  0 siblings, 0 replies; 11+ messages in thread
From: Wolfgang Denk @ 2009-10-23 21:05 UTC (permalink / raw)
  To: u-boot

Dear "David Collier",

In message <memo.20091023213810.2092d@postmaster+dexdyne.com.cix.co.uk> you wrote:
> 
> serialnumber=1234
> set_mac_IP=setexprd sn34 ${serialnumber} % 100 ;setexprd sn12
> ${serialnumber} / 100; setenv ipaddr 10.212.${sn12}.${sn34}; setenv
> ethaddr 00:90:46:20:${sn12}:${sn34}; setenv eth1addr
> 00:90:46:21:${sn12}:${sn34}; setenv sn12 ; setenv sn34
> 
> that's seriously useful!

And it works the same when using "setexpr" ...

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
COBOL is for morons.                                 -- E.W. Dijkstra

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

* [U-Boot] setting u-boot params based on serial number
  2009-10-23 21:04     ` Wolfgang Denk
@ 2009-10-26 10:36       ` David Collier
  2009-10-26 12:01         ` Wolfgang Denk
  0 siblings, 1 reply; 11+ messages in thread
From: David Collier @ 2009-10-26 10:36 UTC (permalink / raw)
  To: u-boot

> I did not only describe it, I tested it. I just "tricked" a bit.
> You asked to extract the last two digits, and I used "% 100" to do
> this. Note that this works correctly in any number base - may it be 
> 10 or 16 or whatever :-)
> 
> Hey, that was clever, wasn't it? :-)

yeah it was - but of course I really wanted the next 2 digits as well....
I'm hoping to make more than 100 units really! pardon me for
over-simplifying my question.

I wonder if it would be useful/helpful to allow the user to optionally
over-ride the number base for reading and separately for writing by
setexpr.

That would extend it's usefulness without requiring an extra command or
breaking any existing code

say 

setenv setexpr_in  10 
setenv setexpr_out 16
 
If I wrote a patch would you look favourably on it?

David







> 
> 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
> "Love is an ideal thing, marriage a real thing; a  confusion  of  
> the
> real with the ideal never goes unpunished."                  - 
> Goethe
> 


David Collier

www.dexdyne.com

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

* [U-Boot] setting u-boot params based on serial number
  2009-10-26 10:36       ` David Collier
@ 2009-10-26 12:01         ` Wolfgang Denk
  2009-10-26 13:29           ` David Collier
  0 siblings, 1 reply; 11+ messages in thread
From: Wolfgang Denk @ 2009-10-26 12:01 UTC (permalink / raw)
  To: u-boot

Dear "David Collier",

In message <memo.20091026103604.2092e@postmaster+dexdyne.com.cix.co.uk> you wrote:
> > I did not only describe it, I tested it. I just "tricked" a bit.
> > You asked to extract the last two digits, and I used "% 100" to do
> > this. Note that this works correctly in any number base - may it be 
> > 10 or 16 or whatever :-)
> > 
> > Hey, that was clever, wasn't it? :-)
> 
> yeah it was - but of course I really wanted the next 2 digits as well....
> I'm hoping to make more than 100 units really! pardon me for
> over-simplifying my question.

Then do the same with "% 10000" and "/ 100" ?

> I wonder if it would be useful/helpful to allow the user to optionally
> over-ride the number base for reading and separately for writing by
> setexpr.

I don't see a need for it; certainly not here.

> That would extend it's usefulness without requiring an extra command or
> breaking any existing code

No extra command is needed here.

> setenv setexpr_in  10 
> setenv setexpr_out 16
>  
> If I wrote a patch would you look favourably on it?

I don't think so. If we did something like that, it should be generic
and not restricted to one command. And it would break a LOT of
existing scripts. And it is not needed at all, at least not for the
use case you have in mind here. [If anything is worth implementing at
all, then maybe the regexp handling present in standard expr
command.]

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
Testing can show the presense of bugs, but not their absence.
                                                   -- Edsger Dijkstra

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

* [U-Boot] setting u-boot params based on serial number
  2009-10-26 12:01         ` Wolfgang Denk
@ 2009-10-26 13:29           ` David Collier
  2009-10-26 14:12             ` Wolfgang Denk
  0 siblings, 1 reply; 11+ messages in thread
From: David Collier @ 2009-10-26 13:29 UTC (permalink / raw)
  To: u-boot


OK,

I concede I can indeed do the one thing I need here by using decimal
values with hex arithmetic, and it will give the right answer.

though it is truly horrible coding :-)

I can see situations where I'd want to do something like "add one to the
last serial number I used" where decimal arithmetic would be needed.

For myself, I don't see any reason why an arithmetic command shouldn't be
a special case ( in having the option to work in various bases ), it's
doing a special job.

Sorry it took me a while to catch onto your clever trick, and thanks for
your help.

David


In article <20091026120130.9538128B9B@gemini.denx.de>, wd at denx.de
(Wolfgang Denk) wrote:

> *From:* Wolfgang Denk <wd@denx.de>
> *To:* from_denx_uboot at dexdyne.com
> *CC:* u-boot at lists.denx.de
> *Date:* Mon, 26 Oct 2009 13:01:30 +0100
> 
> Dear "David Collier",
> 
> In message 
> <memo.20091026103604.2092e@postmaster+dexdyne.com.cix.co.uk> you 
> wrote:
> > > I did not only describe it, I tested it. I just "tricked" a bit.
> > > You asked to extract the last two digits, and I used "% 100" to 
> > do
> > > this. Note that this works correctly in any number base - may 
> > it be > 10 or 16 or whatever :-)
> > > 
> > > Hey, that was clever, wasn't it? :-)
> > 
> > yeah it was - but of course I really wanted the next 2 digits as 
> > well....
> > I'm hoping to make more than 100 units really! pardon me for
> > over-simplifying my question.
> 
> Then do the same with "% 10000" and "/ 100" ?
> 
> > I wonder if it would be useful/helpful to allow the user to 
> > optionally
> > over-ride the number base for reading and separately for writing 
> > by
> > setexpr.
> 
> I don't see a need for it; certainly not here.
> 
> > That would extend it's usefulness without requiring an extra 
> > command or
> > breaking any existing code
> 
> No extra command is needed here.
> 
> > setenv setexpr_in  10 
> > setenv setexpr_out 16
> >  
> > If I wrote a patch would you look favourably on it?
> 
> I don't think so. If we did something like that, it should be 
> generic
> and not restricted to one command. And it would break a LOT of
> existing scripts. And it is not needed at all, at least not for the
> use case you have in mind here. [If anything is worth implementing 
> at
> all, then maybe the regexp handling present in standard expr
> command.]
> 
> 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
> Testing can show the presense of bugs, but not their absence.
>                                                    -- Edsger 
> Dijkstra
> 


David Collier

www.dexdyne.com

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

* [U-Boot] setting u-boot params based on serial number
  2009-10-26 13:29           ` David Collier
@ 2009-10-26 14:12             ` Wolfgang Denk
  0 siblings, 0 replies; 11+ messages in thread
From: Wolfgang Denk @ 2009-10-26 14:12 UTC (permalink / raw)
  To: u-boot

Dear "David Collier",

In message <memo.20091026132928.2092l@postmaster+dexdyne.com.cix.co.uk> you wrote:
> 
> I concede I can indeed do the one thing I need here by using decimal
> values with hex arithmetic, and it will give the right answer.
> 
> though it is truly horrible coding :-)

You misunderstand. You misunderstand completly.

Exstracting the last N digits from a number using '%' is independent
of the number base.

> I can see situations where I'd want to do something like "add one to the
> last serial number I used" where decimal arithmetic would be needed.

Not for the addition itself :-)

> For myself, I don't see any reason why an arithmetic command shouldn't be
> a special case ( in having the option to work in various bases ), it's
> doing a special job.

What probably would make sense and could be helpful for more advanced
scripting is something like a sprintf command that would allow you to
output (and store the result in a new environment variable) the
content of one or more environment variables in a specific format,
plus regexp support for setexpr.

Volunteers wellcome.

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
Why don't you have a Linux partition installed so you can be  working
in  a  programmer-friendly environment instead of a keep-gates'-bank-
account-happy one? :-)                            -- Tom Christiansen

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

end of thread, other threads:[~2009-10-26 14:12 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-23 16:52 [U-Boot] setting u-boot params based on serial number David Collier
2009-10-23 16:58 ` Ben Warren
2009-10-23 18:03 ` Wolfgang Denk
2009-10-23 20:13   ` David Collier
2009-10-23 20:38     ` David Collier
2009-10-23 21:05       ` Wolfgang Denk
2009-10-23 21:04     ` Wolfgang Denk
2009-10-26 10:36       ` David Collier
2009-10-26 12:01         ` Wolfgang Denk
2009-10-26 13:29           ` David Collier
2009-10-26 14:12             ` Wolfgang Denk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox