Ethernut 5 U-Boot Environment
| Note |
|---|
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
printenv
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
saveenv
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:
Loading... ## 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
hh:hh:hh:hh:hh:hh
Note, that your previous environment will return, when rebooting the board now. To permanently store the new environment, use
saveenv
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}
saveenv
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.
Alternatively, you can set the environment by copying the following contents on the U-Boot command line:
env default -f
setenv bootcmd run flashbootlinux
setenv hostname ethernut
setenv ipaddr dhcp
setenv netdev eth0
setenv ntpserver de.pool.ntp.org
setenv timeoffset 3600
setenv env_image_name env-ethernut5.bin
setenv uboot_image_name u-boot-ethernut5.bin
setenv linux_image_name uImage-ethernut5.bin
setenv nut_image_name nutapp.bin
setenv rootfs_image_name console-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 ramargs addip;bootm ${linux_addr} ${ramdisk_addr} ${fdt_addr}'
setenv nfs_root 'run nfsargs 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 UserConf.mk 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 saveenv
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 saveenv
Again, these commands should be entered immediately after booting the board.
Enjoy!
Castrop-Rauxel, 5th of July 2011.
