Modifying U-boot

From Texas Instruments Wiki
Jump to: navigation, search


Introduction

The default u-boot in the TI SDK is designed to boot the Linux system entirely from the SD card.  This is done with a combination of the default u-boot environment variables and the bootscript boot.scr

To boot from something other than the SD card, it is necessary to modify the u-boot environment variables.

Working with U-boot

To print all environment variables type "printenv" or just "pri" at the u-boot prompt.

OMAP3_EVM # pri
bootcmd=if mmc init; then if run loadbootscript; then run bootscript; else if run loaduimage; then run mmcboot; else run nandboot; f
i; fi; else run nandboot; fi
baudrate=115200
bootfile=uImage
loadaddr=0x82000000
usbtty=cdc_acm
console=ttyS0,115200n8
mmcargs=setenv bootargs console=${console} root=/dev/mmcblk0p2 rw rootfstype=ext3 rootwait
nandargs=setenv bootargs console=${console} root=/dev/mtdblock4 rw rootfstype=jffs2
loadbootscript=fatload mmc 0 ${loadaddr} boot.scr
bootscript=echo Running bootscript from mmc ...; source ${loadaddr}
loaduimage=fatload mmc 0 ${loadaddr} uImage
mmcboot=echo Booting from mmc ...; run mmcargs; bootm ${loadaddr}
nandboot=echo Booting from nand ...; run nandargs; onenand read ${loadaddr} 280000 400000; bootm ${loadaddr}
dieid#=731c0000000000000156087c0a023021
ethact=smc911x-0
filesize=197
bootdelay=3
stdin=serial
stdout=serial
stderr=serial

Environment size: 886/131068 bytes
OMAP3_EVM #

To print all available commands type "help" at the u-boot prompt.

OMAP3_EVM # help
? - alias for 'help'
base - print or set address offset
bdinfo - print Board Info structure
boot - boot default, i.e., run 'bootcmd'
bootd - boot default, i.e., run 'bootcmd'
bootm - boot application image from memory
bootp - boot image via network using BOOTP/TFTP protocol
cmp - memory compare
coninfo - print console devices and information
cp - memory copy
crc32 - checksum calculation
dhcp - boot image via network using DHCP/TFTP protocol
echo - echo args to console
editenv - edit environment variable
exit - exit script
ext2load- load binary file from a Ext2 filesystem
ext2ls - list files in a directory (default /)
fatinfo - print information about filesystem
fatload - load binary file from a dos filesystem
fatls - list files in a directory (default /)
fsinfo - print information about filesystems
fsload - load binary file from a filesystem image
go - start application at address 'addr'
help - print online help
i2c - I2C sub-system
imxtract- extract a part of a multi-image
itest - return true/false on integer compare
loadb - load binary file over serial line (kermit mode)
loads - load S-Record file over serial line
loady - load binary file over serial line (ymodem mode)
loop - infinite loop on address range
ls - list files in a directory (default /)
md - memory display
mm - memory modify (auto-incrementing address)
mmc - MMC sub-system
mtest - simple RAM read/write test
mw - memory write (fill)
nand - NAND sub-system
nandecc - switch OMAP3 NAND ECC calculation algorithm
nboot - boot from NAND device
nfs - boot image via network using NFS protocol
nm - memory modify (constant address)
ping - send ICMP ECHO_REQUEST to network host
printenv- print environment variables
rarpboot- boot image via network using RARP/TFTP protocol
reset - Perform RESET of the CPU
run - run commands in an environment variable
saveenv - save environment variables to persistent storage
setenv - set environment variables
showvar - print local hushshell variables
sleep - delay execution for some time
source - run script from memory
test - minimal test like /bin/sh
tftpboot- boot image via network using TFTP protocol
usb - USB sub-system
usbboot - boot from USB device
version - print monitor version
OMAP3_EVM #


To print help for a particular command type "help <command>" at the u-boot prompt.

OMAP3_EVM # help nand
nand - NAND sub-system

Usage:
nand info - show available NAND devices
nand device [dev] - show or set current device
nand read - addr off|partition size
nand write - addr off|partition size
read/write 'size' bytes starting at offset 'off'
to/from memory address 'addr', skipping bad blocks.
nand erase [clean] [off size] - erase 'size' bytes from
offset 'off' (entire device if not specified)
nand bad - show bad blocks
nand dump[.oob] off - dump page
nand scrub - really clean NAND erasing bad blocks (UNSAFE)
nand markbad off [...] - mark bad block(s) at offset (UNSAFE)
nand biterr off - make a bit error at offset (UNSAFE)
OMAP3_EVM #

 

Modifying Environment Variables

To create a new environment variable use the command "setenv".  This command can also be used to save a copy of an existing environment variable.  Here is an example where "bootcmd" is saved off to another name and a new "bootcmd" is generated. 

OMAP3_EVM # setenv bootcmd_original ${bootcmd}
OMAP3_EVM # pri
bootcmd=if mmc init; then if run loadbootscript; then run bootscript; else if run loaduimage; then run mmcboot; else run nandboot; f
i; fi; else run nandboot; fi
baudrate=115200
bootfile=uImage
loadaddr=0x82000000
usbtty=cdc_acm
console=ttyS0,115200n8
mmcargs=setenv bootargs console=${console} root=/dev/mmcblk0p2 rw rootfstype=ext3 rootwait
nandargs=setenv bootargs console=${console} root=/dev/mtdblock4 rw rootfstype=jffs2
loadbootscript=fatload mmc 0 ${loadaddr} boot.scr
bootscript=echo Running bootscript from mmc ...; source ${loadaddr}
loaduimage=fatload mmc 0 ${loadaddr} uImage
mmcboot=echo Booting from mmc ...; run mmcargs; bootm ${loadaddr}
nandboot=echo Booting from nand ...; run nandargs; onenand read ${loadaddr} 280000 400000; bootm ${loadaddr}
dieid#=731c0000000000000156087c0a023021
ethact=smc911x-0
filesize=197
bootdelay=3
stdin=serial
stdout=serial
stderr=serial
bootcmd_original=if mmc init; then if run loadbootscript; then run bootscript; else if run loaduimage; then run mmcboot; else run na
ndboot; fi; fi; else run nandboot; fi

Environment size: 1056/131068 bytes

OMAP3_EVM # setenv bootcmd_new 'mmc init;run loaduimage;run mmcboot'
OMAP3_EVM # setenv bootcmd 'run bootcmd_new'
OMAP3_EVM # pri
baudrate=115200
bootfile=uImage
loadaddr=0x82000000
usbtty=cdc_acm
console=ttyS0,115200n8
mmcargs=setenv bootargs console=${console} root=/dev/mmcblk0p2 rw rootfstype=ext3 rootwait
nandargs=setenv bootargs console=${console} root=/dev/mtdblock4 rw rootfstype=jffs2
loadbootscript=fatload mmc 0 ${loadaddr} boot.scr
bootscript=echo Running bootscript from mmc ...; source ${loadaddr}
loaduimage=fatload mmc 0 ${loadaddr} uImage
mmcboot=echo Booting from mmc ...; run mmcargs; bootm ${loadaddr}
nandboot=echo Booting from nand ...; run nandargs; onenand read ${loadaddr} 280000 400000; bootm ${loadaddr}
dieid#=731c0000000000000156087c0a023021
ethact=smc911x-0
filesize=197
bootdelay=3
stdin=serial
stdout=serial
stderr=serial
bootcmd_original=if mmc init; then if run loadbootscript; then run bootscript; else if run loaduimage; then run mmcboot; else run na
ndboot; fi; fi; else run nandboot; fi
bootcmd_new=mmc init;run loaduimage;run mmcboot
bootcmd=run bootcmd_new

Environment size: 958/131068 bytes
OMAP3_EVM #

 Notice here that the original bootcmd still exists in bootcmd_original.  The new bootcmd does not contain the conditional statement any longer and does not try to run the boot script.  It simply accesses the SD/MMC card and loads the Linux kernel from the SD card and boots into root filesystem on the SD card.  So the only real difference here is that the boot script is bypassed.

It is now possible to create define environment variables for performing different types of kernel loading and different types of file system mounting.  These can be mixed and matched to perform various types of booting.


Any time that variables are created or modified they must be saved to NAND with the "saveenv" command.  The "setenv" command sets the variable but the variable is only in SRAM until it is saved to NAND with the "saveenv" command.

OMAP3_EVM # saveenv
Saving Environment to NAND...
Erasing Nand...
Erasing at 0x260000 -- 100% complete.
Writing to Nand... done
OMAP3_EVM #

Boot Kernel via TFTP into NFS

In order to TFTP a kernel from the host Linux system, there are several u-boot parameters which must be defined.  These are not in the default environment, but they can be easily added.  The following example shows the various steps.

First, an attempt to TFTP the kernel fails because the variable serverip is not set.  The value of serverip must be the IP address of the host machine (obtainable via /sbin/ifconfig) that is set up as the TFTP server.

OMAP3_EVM # tftp uImage
smc911x: detected LAN9220 controller
smc911x: phy initialized
smc911x: MAC 00:50:c2:7e:8f:90
*** ERROR: `serverip' not set

So, the variable "serverip" must be added.

OMAP3_EVM # setenv serverip 128.247.107.81
OMAP3_EVM # tftp uImage
smc911x: detected LAN9220 controller
smc911x: phy initialized
smc911x: MAC 00:50:c2:7e:8f:90
*** ERROR: `ipaddr' not set

Now the value of ipaddr must be set.  This is the IP address that the EVM will use as its network IP address.  It can be automattically obtained from a DHCP server on the network.  The dhcp command (see below) will also also automatically run the tftp command to get uImage.

OMAP3_EVM # dhcp
smc911x: detected LAN9220 controller
smc911x: phy initialized
smc911x: MAC 00:50:c2:7e:8f:90
BOOTP broadcast 1
*** Unhandled DHCP Option in OFFER/ACK: 43
*** Unhandled DHCP Option in OFFER/ACK: 44
*** Unhandled DHCP Option in OFFER/ACK: 46
*** Unhandled DHCP Option in OFFER/ACK: 43
*** Unhandled DHCP Option in OFFER/ACK: 44
*** Unhandled DHCP Option in OFFER/ACK: 46
DHCP client bound to address 128.247.107.37
Using smc911x-0 device
TFTP from server 128.247.107.81; our IP address is 128.247.107.37
Filename 'uImage'.
Load address: 0x82000000
Loading: #################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#############
done
Bytes transferred = 2396128 (248fe0 hex)
OMAP3_EVM #

And the dhcp command will also write all the variables to the environment.

OMAP3_EVM # pri
baudrate=115200
loadaddr=0x82000000
usbtty=cdc_acm
console=ttyS0,115200n8
mmcargs=setenv bootargs console=${console} root=/dev/mmcblk0p2 rw rootfstype=ext3 rootwait
nandargs=setenv bootargs console=${console} root=/dev/mtdblock4 rw rootfstype=jffs2
loadbootscript=fatload mmc 0 ${loadaddr} boot.scr
bootscript=echo Running bootscript from mmc ...; source ${loadaddr}
loaduimage=fatload mmc 0 ${loadaddr} uImage
mmcboot=echo Booting from mmc ...; run mmcargs; bootm ${loadaddr}
nandboot=echo Booting from nand ...; run nandargs; onenand read ${loadaddr} 280000 400000; bootm ${loadaddr}
dieid#=731c0000000000000156087c0a023021
ethact=smc911x-0
bootdelay=3
bootcmd_original=if mmc init; then if run loadbootscript; then run bootscript; else if run loaduimage; 
then run mmcboot; else run nandboot; fi; fi; else run nandboot; fi
bootcmd_new=mmc init;run loaduimage;run mmcboot
bootcmd=run bootcmd_new
stdin=serial
stdout=serial
stderr=serial
bootfile=uImage
filesize=248FE0
fileaddr=82000000
gatewayip=128.247.106.2
netmask=255.255.254.0
ipaddr=128.247.107.37
serverip=128.247.107.81
dnsip=128.247.5.10

Environment size: 1099/131068 bytes
OMAP3_EVM #

Now the tftp command can be used to acquire the kernel.

OMAP3_EVM # tftp uImage
smc911x: detected LAN9220 controller
smc911x: phy initialized
smc911x: MAC 00:50:c2:7e:8f:90
Using smc911x-0 device
TFTP from server 128.247.107.81; our IP address is 128.247.107.37
Filename 'uImage'.
Load address: 0x82000000
Loading: #################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#############
done
Bytes transferred = 2396128 (248fe0 hex)

And the ping command can be used to check the host machine.

OMAP3_EVM # ping 128.247.107.81
smc911x: detected LAN9220 controller
smc911x: phy initialized
smc911x: MAC 00:50:c2:7e:8f:90
Using smc911x-0 device
host 128.247.107.81 is alive
OMAP3_EVM #


Now, an environment variable is added that will load uImage via TFTP.  This will replace the "loaduimage" command in bootcmd.

OMAP3_EVM # setenv tftpuimage 'tftp uImage'

A new environment variable for the NFS bootargs is also added.  The example below would have to be modified depending on the actual IP address and location of the NFS mount point.


OMAP3_EVM # setenv nfsargs 'mem=128M console=ttyS0,115200n8 noinitrd rw ip=dhcp root=/dev/nfs 
nfsroot=128.247.107.81:/<path to filesystem>/nfs'


Now these two new variables can be combined to create a new bootcmd that will get the kernel from TFTP and use NFS as the filesystem]


OMAP3_EVM # setenv tftp_nfs_boot 'setenv bootargs ${nfsargs}; run tftpuimage; bootm'
OMAP3_EVM # setenv bootcmd 'run tftp_nfs_boot'

So now the new bootcmd will get the kernel from TFTP and mount an NFS filesystem. 

Don't forget to save the environment variables.


OMAP3_EVM # saveenv
Saving Environment to NAND...
Erasing Nand...
Erasing at 0x260000 -- 100% complete.
Writing to Nand... done
OMAP3_EVM #

Boot Kernel via TFTP into NFS (for TI AM37x/EZSDK 4.0)

If you have TI AM/DM37x EVM, remember to run the following EZSDK setup script before do TFTP+NFS booting.

# sudo /home/user/ti-sdk-AM3715-evm-4.0.0.0/ti-sdk-ubuntu-env-setup.sh

It will do apt-get update and install minicom(picocom is alternative and easier), tftp server, nfs server...etc. Prepare your DHCP network environment for your target device and host, then modify the target U-Boot commands:

setenv serverip 192.168.1.1     // TFTP Server
setenv ipaddr 192.168.1.2       // use 'dhcp' to lookup.
setenv loadaddr 0x82000000
setenv console ttyS0,115200n8   // Output from UART1,2

setenv tftp_nfs_img 'tftp ${loadaddr} ${bootfile}'
setenv tftp_nfs_fs '/home/user/ti-sdk-AM3715-evm-4.0.0.0/filesystem,nolock,rsize=1024,wsize=1024'
setenv tftp_nfs_args 'setenv bootargs mem=128M console=${console} noinitrd rw ip=dhcp nfsroot=${serverip}:${tftp_nfs_fs}'
setenv tftp_nfs_boot 'run tftp_nfs_img;run tftp_nfs_args; bootm ${loadaddr}'
setenv bootcmd run tftp_nfs_boot
saveenv

See Also