You are here

Using U-Boot

U-boot provides a powerful command line interface which may be accessed through a terminal emulator connected to the target board's serial port. For example type "help" at the command prompt will print a list of all the available commands:

MB680> help
?       - alias for 'help'
askenv  - get environment variables from stdin
autoscr - run script from memory
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
chpart  - change active partition
cmp     - memory compare
coninfo - print console devices and information
cp      - memory copy
crc32   - checksum calculation
dhcp    - invoke DHCP client to obtain IP/boot params
echo    - echo args to console
erase   - erase FLASH memory
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 /)
flinfo  - print FLASH memory information
fsinfo  - print information about filesystems
fsload  - load binary file from a filesystem image
go      - start application at address 'addr'
help    - print online help
iminfo  - print header information for application image
imls    - list all images found in flash
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
mii     - MII utility commands
mm      - memory modify (auto-incrementing)
mtdparts- define flash/nand partitions
mtest   - simple RAM test
mw      - memory write (fill)
nand    - NAND sub-system
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
pmb     - displays the contents of the PMB
printenv- print environment variables
protect - enable or disable FLASH write protection
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
sleep   - delay execution for some time
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

For help on an individual command type "help command". For example:

MB680> help setenv
setenv name value ...
    - set environment variable 'name' to 'value ...'
setenv name
    - delete environment variable 'name'

Note you only need to provide enough of a commands name to distinguish it from all other commands. For example you may type "save" instead of "saveenv".

Command Line Editing

Simple command line editing and history is also provided:

Key Function
Control-A move to start of line
Control-E move to end of line
Control-B or Left-Arrow move character left
Control-F or Right-Arrow move character right
Control-K erase to end of line
Control-X erase entire line
Back-Space or Delete erase character to the left of the cursor
Control-D erase character under the cursor
Control-P or Up-Arrow previous command history
Control-N or Down-Arrow next command history
Control-O toggle overwrite/insert mode
Control-C break

U-Boot Environment

U-Boot provides user configuration using Environment Variables which can be saved to Flash memory.

Environment Variables are set using "setenv", printed using "printenv", and saved to Flash using "saveenv".

The value of environment variables can be used in commands (or scripts) by prefixing their name by a dollar ("$"). To stop the evaluation of variables either prepend the dollar with a back-slash ("\") or quote the string with quotes ("'"). Here are some examples of using environment variables:

MB680> setenv targetname fred
MB680> print targetname
targetname=fred
MB680> echo $targetname
fred
MB680> echo ${targetname}
fred
MB680> echo \${targetname}
${targetname}
MB680> echo '${targetname}'
${targetname}

Using "setenv" without a value can be used to delete a variable from the environment. As long as the environment variables are not saved to flash, then you will be working with an in-memory copy. If there is no valid environment in the Flash, a default environment is provided.

Command Scripts

Command scripts can also be saved in environment variables and executed using the "run" command. The syntax for the scripts is similar to the "sh" shell. Commands return 0 if they ran successfully and 1 if they failed. The result of executing a command can be tested with condition commands:

if <list>; then <command list>; [ elif <list>; then <list>; ] ... [ else <list>; ] fi
while <list> ; do <list> ; done
until <list> ; do <list> ; done
for <name> in <word list> ; do <list> ; done

The following is an example script that boots a known good default kernel, if the standard kernel is not available/good in flash - note the script is quoted with quotes ("'") to defer the expansion of the environment variables until the script is eventually executed:

MB680> setenv vm_default_base A0060000
MB680> setenv vm_base A0660000
MB680> set doboot 'if iminfo ${vm_base}; then bootm ${vm_base}; else bootm ${vm_default_base}; fi'
MB680> run doboot
 
## Checking Image at a0660000 ...
   Bad Magic Number
## Booting image at a0060000 ...
   Image Name:   2.6.23.17_0116 #1 (mb680)
   Image Type:   SuperH Linux Kernel Image (uncompressed)
   Data Size:    3895568 Bytes =   3.7 MiB
   Load Address: 8c001000
   Entry Point:  8c002000
   Verifying Checksum ... OK
OK
 
Starting kernel console=ttyAS0,115200 ...

Note: commands need to be typed on a single line. In some of the examples long commands will wrap over on to the following line - these must always be entered on a single line.

Tests And Comparisons

There are two commands provided for comparing values "test" and "itest".

To compare the values of environment variables use "test". The syntax is the same as the shell command:

Expression Evaluated to TRUE if ...
! EXPRESSION EXPRESSION is false
EXPRESSION1 -a EXPRESSION2 both EXPRESSION1 and EXPRESSION2 are true
EXPRESSION1 -o EXPRESSION2 either EXPRESSION1 or EXPRESSION2 is true
-n STRING the length of STRING is non-zero
-z STRING the length of STRING is zero
STRING1 = STRING2 the strings are equal
STRING1 != STRING2 the strings are not equal
INTEGER1 -eq INTEGER2 INTEGER1 is equal to INTEGER2
INTEGER1 -ge INTEGER2 INTEGER1 is greater than or equal to INTEGER2
INTEGER1 -gt INTEGER2 INTEGER1 is greater than INTEGER2
INTEGER1 -le INTEGER2 INTEGER1 is less than or equal to INTEGER2
INTEGER1 -lt INTEGER2 INTEGER1 is less than INTEGER2
INTEGER1 -ne INTEGER2 INTEGER1 is not equal to INTEGER2

The command "itest" allows values in memory to be tested. The syntax for"itest" is:

itest[.b,.w,.l,.s] [*]value1 <op> [*]value2
 
Where the optional suffix means:
        .b byte
        .w short
        .l long (default)
        .s string
 
value1 and value2 can be a constant or and address if preceded by a *.
 
<op> can be one of:
	-lt	<		Less than
	-gt	>		Greater than
	-eq	==		Equal to
	-ne	!=	<>	not Equal to
	-ge	>=		Greater than or Equal to
	-le	<=		Less than or Equal to