world leader in high performance signal processing
Trace: » env

U-Boot Environment

The power of U-Boot can come from it's ability for run time configuration. This flexibility is based on being able to easily change environment variables. These “environment variables” are set up be default in the board's ./include/configs/board_name.h file, and is kept in flash at a predefined location:

#define CONFIG_ENV_OFFSET                 0x4000
#define CONFIG_ENV_SIZE                   0x2000

and copied to RAM when U-Boot starts. The environment is protected by a CRC32 checksum.

Common variables

This lists the most important environment variables, all of which have a special meaning to U-Boot.

autoload
if set to no (or any string beginning with 'n'), the rarpb, bootp or dhcp commands will perform only a configuration lookup from the BOOTP / DHCP server, but not try to load any image using TFTP.
autostart
if set to yes, an image loaded using the rarpb, bootp, dhcp, tftp, disk, or docb commands will be automatically started (by internally calling the bootm command).
baudrate
a decimal number that selects the console baudrate (in bps).
bootargs
The contents of this variable are passed to the Linux kernel as boot arguments (aka “command line”).
bootcmd
This variable defines a command string that is automatically executed when the initial countdown is not interrupted. This command is only executed when the variable bootdelay is also defined!
bootdelay
After reset, U-Boot will wait this number of seconds before it executes the contents of the bootcmd variable. During this time a countdown is printed, which can be interrupted by pressing any key.
Set this variable to 0 boot without delay. Be careful: depending on the contents of your bootcmd variable, this can prevent you from entering interactive commands again forever!
Set this variable to -1 to disable autoboot.
bootfile
name of the default image to load with TFTP
ethaddr
Ethernet MAC address for first/only ethernet interface (eth0 in Linux).
This variable can be set only once (usually during manufacturing of the board). U-Boot refuses to delete or overwrite this variable once it has been set.
ipaddr
IP address; needed for tftp command
loadaddr
Default load address for commands like tftp or loads
serverip
TFTP server IP address; needed for tftp command.
silent
If the configuration option CONFIG_SILENT_CONSOLE has been enabled for your board, setting this variable to any value will suppress all console messages. Please see silent_booting for details.
verify
If set to n or no disables the checksum calculation over the complete image in the bootm command to trade speed for safety in the boot process. Note that the header checksum is still verified.

Modifying variables in U-Boot

Examining env var in U-Boot

bfin> print bootcmd
bootcmd=tftp 0x1000000 uImage548; bootm;
bfin> print bootargs
bootargs=root=/dev/mtdblock0 rw earlyprintk=serial,uart1,57600 console=tty0 console=ttyBF0,57600
bfin> print bootdelay
bootdelay=1
bfin> print serverip
serverip=10.64.204.96
bfin> print ipaddr
ipaddr=10.64.204.128

Setting env var in U-Boot

bfin> set bootcmd 'tftp 0x1000000 uImage548; bootm'
bfin> set ipaddr 10.64.204.192
bfin> print ipaddr
ipaddr=10.64.204.192
bfin> dhcp
start Auto negotiation... (take ~2sec)
Auto negotiation complete, 100BaseTX, full duplex
BOOTP broadcast 1
DHCP client bound to address 10.64.204.128
bfin> print serverip
serverip=10.64.204.42
bfin> set serverip 10.64.204.96

Removing an env var in U-Boot

bfin> set foo 'tftp 0x1000000 uImage548; bootm'
bfin> print foo
tftp 0x1000000 uImage548; bootm
bfin> set foo
bfin> print foo
## Error: "foo" not defined

Modifying variables from Linux

Enable u-boot tools in the uClinux-dist user space configuration:

Blackfin app programs  --->  
   [*] U-Boot Tools

Configuring the system

Before the a Linux userspace application can access U-Boot's environment variables, the flash location of the environment variables must be specified. The first step in doing this is to determine which mtd partition that U-Boot is using.

In this example, we are booting from SPI flash:

root:/> cat /proc/mtd
dev:    size   erasesize  name
mtd0: 00400000 00020000 "linux kernel(nand)"
mtd1: 0fc00000 00020000 "file system(nand)"
mtd2: 00040000 00010000 "bootloader(spi)"
mtd3: 001c0000 00010000 "linux kernel(spi)"

So we will use mtd2.

root:/> cat /etc/fw_env.config
# Configuration file for fw_(printenv/saveenv) utility.
# Up to two entries are valid, in this case the redundand
# environment sector is assumed present.

# MTD device name       Device offset   Env. size       Flash sector size
/dev/mtd2               0x4000          0x2000          0x2000

Examining env var in Linux

root:/> fw_printenv
baudrate=57600
loads_echo=1
autoload=no
rootpath=/romfs
hostname=bf537-stamp
loadaddr=0x1000000
ubootfile=u-boot.ldr
addip=set bootargs $(bootargs) ip=$(ipaddr):$(serverip):$(gatewayip):$(netmask):$(hostname):eth0:off
ramargs=set bootargs root=/dev/mtdblock0 rw earlyprintk=serial,uart0,57600 console=ttyBF0,57600
ramboot=tftp $(loadaddr) uImage;run ramargs;run addip;bootm
nfsargs=set bootargs root=/dev/nfs rw nfsroot=$(serverip):$(rootpath),tcp,nfsvers=3
nfsboot=tftp $(loadaddr) vmImage;run nfsargs;run addip;bootm
flashboot=bootm 0x20100000
ethaddr=00:E0:22:FE:52:3A
ethact=Blackfin EMAC
verify=n
filesize=1cb8c8
fileaddr=1000000
gatewayip=192.168.0.1
netmask=255.255.255.0
ipaddr=10.44.2.45
serverip=10.44.2.88
bootcmd=bootm 0x20040000
bootargs=root=/dev/mtdblock0 rw console=ttyBF0,57600 quiet lpj=2093056
stdin=serial
stdout=serial
stderr=serial
silent=1
bootdelay=0

root:/> fw_printenv bootargs
bootargs=root=/dev/mtdblock0 rw earlyprintk=serial,uart1,57600 console=tty0 console=ttyBF0,57600
root:/> fw_printenv bootdelay
bootdelay=1

Setting env var in Linux

Revert u-boot silent boot and add a bootdelay

root:/> fw_setenv silent
Unlocking flash...
Done
Erasing old environment...
Done
Writing environment to /dev/mtd0...
Done
Locking ...
Done

root:/> fw_setenv bootdelay 1
Unlocking flash...
Done
Erasing old environment...
Done
Writing environment to /dev/mtd0...
Done
Locking ...
Done