public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Wolfgang Denk <wd@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] setting u-boot params based on serial number
Date: Fri, 23 Oct 2009 20:03:49 +0200	[thread overview]
Message-ID: <20091023180349.6C3C1E398E1@gemini.denx.de> (raw)
In-Reply-To: <memo.20091023175206.2092W@postmaster+dexdyne.com.cix.co.uk>

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

  parent reply	other threads:[~2009-10-23 18:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=20091023180349.6C3C1E398E1@gemini.denx.de \
    --to=wd@denx.de \
    --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