Ethernut Home Hardware Firmware Tools Download Community
Ethernuts  /  Ethernut 5  /  U-Boot Environment
Search | Legals | Deutsch

Ethernut 5 U-Boot Environment


Before changing environment variables for saving in serial Flash, reboot the board first to make sure to start with a clean environment.

The command saveenv will store the current environment. This may result in unexpected problems, when other commands had been executed before. For example, the variable ipaddr may be set to dhcp, which instructs U-Boot to query an IP configuration from the local DHCP server prior to executing any network command. Once done, the variable ipaddr will then contain the local IP address, and, when saving this modified environment, the dhcp setting is gone. As a result, the board will always use the fixed IP address.

U-Boot is customizable by environment variables, which may contain scripts that are executed by the run command.

On the U-Boot command line enter


to display the current environment.

To create new environment variables or to modify existing ones, use

setenv name value

Note, that no equal sign is used here.

The command


saves the current environment in serial Flash memory (DataFlash) at address offset 0x3DE000, from where it is reloaded during the next system start.

Factory Environment

In addition to the environment variables saved by saveenv, the serial Flash contains a factory default environment at address offset 0x021000. You can activate this environment by entering the command

run setfactory

U-Boot will load the environment image into SDRAM and apply it:

## Executing script at 20000000
## Resetting to default environment
Enter MAC address and then execute 'saveenv' to store the new environment.
Please enter 'ethaddr':

You should now enter the MAC address of your board in the format


where 00:06:98 is the organizational unique identifier (OUI) assigned to Ethernuts manufactured by egnite GmbH and XX:YY:ZZ is the unique part of the individual board. Each board manufactured by egnite do contain a label with this number. Other manufactures will use different OUIs and labeling. Alternatively you can use a locally assigned MAC address.

Note, that your previous environment will return, when rebooting the board now. To permanently store the new environment, use


On virgin boards, the command setfactory will not be available. In this case enter the following commands to apply the factory default:

cp.b 0xC0021000 ${loadaddr} 0x21000
source ${loadaddr}

However, this requires, that an environment image is available in the serial Flash. If not, refer to this page, which explains how to program your board with the Ethernut 5 flasher application.

You can also load the environment over TFTP:

tftpboot ${loadaddr}
source ${loadaddr}

Replace the TFTP-Server providing the environment.

Alternatively, you can set the environment by copying the following contents on the U-Boot command line:

env default -f -a
setenv bootcmd run flashbootlinux

setenv hostname ethernut
setenv ipaddr dhcp
setenv netdev eth0
setenv ntpserver
setenv timeoffset 3600

setenv env_image_name env-ethernut5.bin
setenv uboot_image_name u-boot-ethernut5.bin
setenv linux_image_name uImage-ethernut5.itb
setenv nut_image_name nutapp.bin
setenv rootfs_image_name ethernut5-image-ethernut5.jffs2

setenv nfsrootpath /srv/nut/

setenv env_flash_start 0xC0021000
setenv env_maxsize 0x21000
setenv uboot_flash_start 0xC0042000
setenv uboot_maxsize 0x84000
setenv linux_flash_start 0xC00C6000
setenv linux_maxsize 0x294000
setenv nut_flash_start 0xC035A000
setenv nut_maxsize 0x84000

setexpr env_flash_end ${env_flash_start} + ${env_maxsize} ; setexpr env_flash_end ${env_flash_end} - 1
setexpr uboot_flash_end ${uboot_flash_start} + ${uboot_maxsize} ; setexpr uboot_flash_end ${uboot_flash_end} - 1
setexpr linux_flash_end ${linux_flash_start} + ${linux_maxsize} ; setexpr linux_flash_end ${linux_flash_end} - 1
setexpr nut_flash_end ${nut_flash_start} + ${nut_maxsize} ; setexpr nut_flash_end ${nut_flash_end} - 1

setenv installenv run tftpinstallenv
setenv installuboot run tftpinstalluboot
setenv installlinux run tftpinstalllinux
setenv installnut run tftpinstallnut
setenv installrootfs run tftpinstallrootfs

setenv nfsbootlinux 'run powerup4linux select_linux load_nfs_image addip && bootm'
setenv tftpbootlinux 'run powerup4linux select_linux load_tftp_image addip && bootm'
setenv flashbootlinux 'run powerup4linux select_linux load_flash_image addip && bootm'

setenv nfsbootnut 'run netconf && nfs ${loadaddr} ${serverip}:${nfsrootpath}${nut_image_name} && go ${loadaddr}'
setenv tftpbootnut 'run select_nut load_tftp_image && go ${loadaddr}'
setenv flashbootnut 'cp.b ${nut_flash_start} ${loadaddr} ${nut_maxsize} && go ${loadaddr}'

setenv setfactory 'run select_env load_flash_image && source ${loadaddr}'
setenv powerup4linux 'pwrman on; sleep 2'
setenv powerup 'pwrman vbout mmc ethclk ethrst on ; sleep 1 ; pwrman ethrst off'
setenv powerdown 'pwrman off'
setenv poweroff 'pwrman board off'
setenv nettime 'run netconf && if test -z \\"${ntpserverip}\\"; then dns ${ntpserver} ntpserverip; else true; fi && sntp'

setenv settftpserver 'if test -z \\"${tftpserver}\\"; then setenv tftpserver ${serverip}; else true; fi'
setenv setnfsserver 'if test -z \\"${nfsserver}\\"; then setenv nfsserver ${serverip}; else true; fi'
setenv setntpserver 'if test -z \\"${ntpserver}\\"; then setenv ntpserver ${serverip}; else true; fi'
setenv netconf 'if test ${ipaddr} != off; then if test ${ipaddr} = dhcp || test -z \\"${ipaddr}\\"; then dhcp; else true; fi; fi && run settftpserver setnfsserver setntpserver'

setenv load_tftp_image 'run netconf && if test -z \\"${tftpserverip}\\"; then dns ${tftpserver} tftpserverip; else true; fi && tftpboot ${loadaddr} ${tftpserverip}:$image_name'
setenv load_nfs_image 'run netconf && if test -z \\"${nfsserverip}\\"; then dns ${nfsserver} nfsserverip; else true; fi && nfs ${loadaddr} ${nfsserverip}:${nfsrootpath}$image_name'

setenv load_flash_image 'echo Loading... ; cp.b $start ${loadaddr} ${filesize}'
setenv unprotect_flash_image 'protect off $start $end'
setenv protect_flash_image 'protect on $start $end'
setenv save_flash_image 'cp.b ${loadaddr} $start ${filesize}'
setenv save_protected_flash_image run unprotect_flash_image save_flash_image protect_flash_image

setenv select_env 'image_name=${env_image_name} ; start=${env_flash_start} ; end=${env_flash_end} ; setenv filesize ${env_maxsize}'
setenv select_uboot 'image_name=${uboot_image_name} ; start=${uboot_flash_start} ; end=${uboot_flash_end} ; setenv filesize ${uboot_maxsize}'
setenv select_linux 'image_name=${linux_image_name} ; start=${linux_flash_start} ; end=${linux_flash_end} ; setenv filesize ${linux_maxsize}'
setenv select_nut 'image_name=${nut_image_name} ; start=${nut_flash_start} ; end=${nut_flash_end} ; setenv filesize ${nut_maxsize}'

setenv nfsinstallenv 'run select_env load_nfs_image save_protected_flash_image'
setenv nfsinstalluboot 'run select_uboot load_nfs_image save_protected_flash_image'
setenv nfsinstalllinux 'run select_linux load_nfs_image save_protected_flash_image'
setenv nfsinstallnut 'run select_nut load_nfs_image save_protected_flash_image'

setenv tftpinstallenv 'run select_env load_tftp_image save_protected_flash_image'
setenv tftpinstalluboot 'run select_uboot load_tftp_image save_protected_flash_image'
setenv tftpinstalllinux 'run select_linux load_tftp_image save_protected_flash_image'
setenv tftpinstallnut 'run select_nut load_tftp_image save_protected_flash_image'
setenv tftpinstallrootfs 'nand erase.part clean root && image_name=${rootfs_image_name} ; run load_tftp_image && nand write ${loadaddr} ${partition} ${filesize}'

setenv bootargs_ram setenv bootargs root=/dev/ram rw
setenv bootargs_nfs 'setenv bootargs root=/dev/nfs rw nfsroot=${serverip}:${nfsrootpath}'
setenv bootargs_mtd setenv bootargs root=/dev/mtdblock6 rw rootfstype=jffs2

setenv addip 'if test -z \\"${ipaddr}\\" ; then setenv ipaddr dhcp ; fi; if test ${ipaddr} = off || test ${ipaddr} = dhcp ; then setenv bootargs ${bootargs} ip=${ipaddr} panic=1; else run addfixedip; fi'
setenv addfixedip 'setenv bootargs ${bootargs} ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}:${netdev}:off panic=1'
setenv enable_nfs 'dhcp && dns ${nfsserver} nfsserverip && setenv bootargs root=/dev/nfs rw nfsroot=${nfsserverip}:/srv/nut ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}:${netdev}:off'

setenv ram_root 'run bootargs_ram addip;bootm ${linux_addr} ${ramdisk_addr} ${fdt_addr}'
setenv nfs_root 'run bootargs_nfs addip;bootm ${linux_addr} - ${fdt_addr}'

mtdparts default

echo Enter MAC address and then execute \'saveenv\' to store the new environment.
askenv ethaddr 17

If copied in one go, this may fail, because the lines are sent too fast for U-Boot. Either use a slower baudrate or add a line delay in your terminal emulator configuration. When using TeraTerm, select Setup -> Serial Port form the main menu and specify a transmit delay of 100 ms per line.

Booting Nut/OS Applications

This chapter assumes, that you are familiar with building Nut/OS applications. If not, please refer to the Nut/OS Software Manual.

Nut/OS applications for Ethernut 5 are typically compiled for running in SDRAM. During the development phase it is most convenient to load them over Ethernet, using TFTP. This requires to install a TFTP server on your PC. While ready-to-run packages are available for Linux, we recommend TFTPD32 for Windows PCs.

For building your Nut/OS application, use

make clean all install

This will copy the final binary to nut/bin/arm9. If you prefer a different location, add the following line to in your sample (application) directory:

BINDIR = path/to/my/tftp/upload/directory

To load and start the application, enter

setenv nut_image_name appname.bin
run tftpbootnut

on the U-Boot command line, replacing appname by the name of the application, e.g. events. To avoid entering these commands over and over again, you can change the default environment. Reboot the board first, to make sure that the environment is unmodified by U-Boot. Then enter

setenv nut_image_name appname.bin
setenv bootcmd run tftpbootnut

Now the application will be automatically loaded and started each time you press the Ethernut 5 reset button. Quite convenient, isn't it?

When your application is stable, you can store it in serial Flash memory, using

run installnut
setenv bootcmd run flashbootnut

Again, these commands should be entered immediately after booting the board.

Updating Images

U-Boot can be used to update all images, which are stored in the serial Flash. The factory default environment provides command to load the images from TFTP or NFS, but you could also load them from a SD-Card or an USB-Stick.

If you want to load them over TFTP, you first need to tell U-Boot the IP-Address of the TFTP-Server:

setenv tftpserverip

Replace with the IP of your TFTP-Server.

All commands prefixed with tftpinstall are used to load the image over TFTP and save them into the serial Flash. To update U-Boot itself you can use the following command:

run tftpinstalluboot

The other images can be installed with the following commands:

run tftpinstallenv
run tftpinstalllinux
run tftpinstallnut
run tftpinstallrootfs

Note, that tftpinstallenv does not activate the installed environment. This can be done with run setfactory as seen above.

Booting Linux

If you have installed all images and the factory default environment is activated, Linux will boot automatically. You can also use the following command to load the Linux Kernel from the Flash and start it:

run flashbootlinux

If the Kernel is located on a TFTP-Server, you can also boot Linux without saving the image to the Flash:

run tftpbootlinux

When started U-Boot will run the bootcmd, which defaults to flashbootlinux. If you always want to load Linux over TFTP you can change bootcmd:

setenv bootcmd run tftpbootlinux

The U-Boot environment variable bootargs is used to tell Linux how to boot. It defaults to

bootargs=console=ttyS0,115200 root=/dev/mtdblock0 mtdparts=atmel_nand:128m(root),896m(data) rw rootfstype=jffs2

The option root=/dev/mtdblock0 tells Linux that the root filesystem is in the NAND Flash. It can be modified to support a root filesystem on a SD-Card, an USB-Stick or a NFS-Share.


Castrop-Rauxel, 5th of July 2011.