[U-Boot] How to use multiple env variables.

Ladislav Michl Ladislav.Michl at seznam.cz
Thu Jan 28 10:43:08 CET 2010


On Thu, Jan 28, 2010 at 12:30:54PM +0530, Shashi Kumar M.S wrote:
> Is there any option for multiple env variables so that when i upgrade the
> kernel and rootfile system if not working properly so that i can fall back to
> the previous kernel and ramdisk considering i have a sufficiently big nand
> with required number of partition.

Something like this works for me:
Two env variables controls from where to boot: 'ospart' indicating partition
number and 'swapos' saying that there is new firmware pending.
Consider NAND partitions kernel0, rootfs0, kernel1 and rootfs1. System is
running from kernel1 and rootfs1 (ospart=1). Now write new system to kernel0
and rootfs0 and set variable 'swapos', then reboot system. U-Boot then
executes
if test -n $swapos; then
	setenv swapos; saveenv;
	if test $ospart -eq 0; then
		setenv ospart 1;
	else
		setenv ospart 0;
	fi;
fi
and constructs kernel cmdline "root=mtd:rootfs$ospart"
and then loads kernel with "nboot kernel$ospart"

Inside some OS boot script it is then discovered that system is running
from diferent partition than saved in environment (we cleared 'swapos'
env variable, but new 'ospart' was to saved to permanent storage) and
after finding itself in sane state (based on self check or user's
interaction) it sets 'ospart' in environment accordingly. Otherwise
reboot is performed (based on watchdog, user's interaction...) and
original OS version is loaded (as 'ospart' remains intact).

Best regards,
	ladis


More information about the U-Boot mailing list