uboot常用命令详解
来源:互联网 发布:mac maven 仓库地址 编辑:程序博客网 时间:2024/06/14 23:53
U-boot发展到现在,他的命令行模式已经非常接近Linux下的shell了,在我编译的U-boot-2009.11中的命令行模式模式下支持“Tab”键的命令补全和命令的历史记录功能。而且如果你输入的命令的前几个字符和别的命令不重复,那么你就只需要打这几个字符即可,比如我想看这个U-boot的版本号,命令就是“ version”,但是在所有的命令中没有其他任何一个的命令是由“v”开头的,所以只需要输入“v”即可。
[u-boot@MINI2440]# version
U-Boot 2009.11 ( 4月 04 2010 - 12:09:25)
[u-boot@MINI2440]# v
U-Boot 2009.11 ( 4月 04 2010 - 12:09:25)
[u-boot@MINI2440]# base
Base Address: 0x00000000
[u-boot@MINI2440]# ba
Base Address: 0x00000000
由于U-boot支持的命令实在太多,一个一个细讲不现实,也没有必要。所以下面我挑一些烧写和引导常用命令介绍一下,其他的命令大家就举一反三,或者“help”吧!
(1)获取帮助
命令:help 或 ?
功能:查看当前U-boot版本中支持的所有命令。
[u-boot@MINI2440]# help
? - alias for 'help'
askenv - get environment variables from stdin
base - print or set address offset
bdinfo - print Board Info structure
bmp - manipulate BMP image data
boot - boot default, i.e., run 'bootcmd'
bootd - boot default, i.e., run 'bootcmd'
bootelf - Boot from an ELF image in memory
bootm - boot application image from memory
bootp - boot image via network using BOOTP/TFTP protocol
bootvx - Boot vxWorks from an ELF image
cmp - memory compare
coninfo - print console devices and information
cp - memory copy
crc32 - checksum calculation
date - get/set/reset date & time
dcache - enable or disable data cache
dhcp - boot image via network using DHCP/TFTP protocol
echo - echo args to console
editenv - edit environment variable
eeprom - EEPROM sub-system
erase - erase FLASH memory
exit - exit script
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
i2c - I2C sub-system
icache - enable or disable instruction cache
iminfo - print header information for application image
imls - list all images found in flash
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
loadx - load binary file over serial line (xmodem mode)
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
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
protect - enable or disable FLASH write protection
rarpboot- boot image via network using RARP/TFTP protocol
reginfo - print register information
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
unzip - unzip a memory region
usb - USB sub-system
usbboot - boot from USB device
version - print monitor version
如果你想获取某条命令的更详细的帮助,可以使用:
help <你想要查的指令>
或者 ? <你想要查的指令> ,
甚至 h <你想要查的指令缩写>。
以bmp指令为例:
[u-boot@MINI2440]# help bmp
bmp - manipulate BMP image data
Usage:
bmp info <imageAddr> - display image info
bmp display <imageAddr> [x y] - display image at x,y
[u-boot@MINI2440]# ? bmp
bmp - manipulate BMP image data
Usage:
bmp info <imageAddr> - display image info
bmp display <imageAddr> [x y] - display image at x,y
[u-boot@MINI2440]# h bm
bmp - manipulate BMP image data
Usage:
bmp info <imageAddr> - display image info
bmp display <imageAddr> [x y] - display image at x,y
(2)环境变量(environment variables,简称ENV)与相关指令
和shell类似,U-Boot也有环境变量。一些U-boot默认的环境变量如下:
环 境 变 量
解 释 说 明
bootdelay
执行自动启动(bootcmd中的命令)的等候秒数
baudrate
串口控制台的波特率
netmask
以太网的网络掩码
ethaddr
以太网的MAC地址
bootfile
默认的下载文件名
bootargs
传递给Linux内核的启动参数
bootcmd
自动启动时执行命令
serverip
TFTP服务器端的IP地址
ipaddr
本地的IP地址
stdin
标准输入设备,一般是串口
stdout
标准输出,一般是串口,也可是LCD(VGA)
stderr
标准出错,一般是串口,也可是LCD(VGA)
要看到你的板上的ENV值可使用printenv命令,例如我的板子:
[u-boot@MINI2440]# printenv
bootargs=noinitrd root=/dev/nfs rw nfsroot=192.168.0.1:/home/tekkaman/working/nfs/rootfs ip=192.168.0.2:192.168.0.1::255.255.255.0 console=ttySAC0,115200 init=/linuxrc mem=64M
bootcmd=nfs 0x30008000 192.168.0.1:/home/tekkaman/working/nfs/zImage.img;bootm
bootdelay=1
baudrate=115200
ethaddr=08:08:11:18:12:27
ipaddr=192.168.0.2
serverip=192.168.0.1
gatewayip=192.168.0.1
netmask=255.255.255.0
tekkaman=bmp d 70000
stdin=serial
stdout=serial
stderr=serial
ethact=dm9000
Environment size: 470/131068 bytes
你会发现有些有的ENV我没有,还有一个“tekkaman”的ENV。原因是如果你没有设置这个环境变量就不会打印出,你也可以自己定义ENV,并在命令中使用${ENV}来调用它。同时你也可以删除这个ENV。设置ENV的命令是setenv,格式为:
setenv name value
第1个参数是环境变量的名称。
第2个参数是要设置的值,如果没有第2个参数,表示删除这个环境变量。
例如:我先将”tekkaman”参数删除,再设置,最后在一个命令串中调用。
[u-boot@MINI2440]# printenv tekkaman
tekkaman=bmp d 70000
[u-boot@MINI2440]# setenv tekkaman
[u-boot@MINI2440]# printenv tekkaman
## Error: "tekkaman" not defined
[u-boot@MINI2440]# setenv tekkaman echo "I am Tekkaman Ninja!"
[u-boot@MINI2440]# printenv tekkaman
tekkaman=echo I am Tekkaman
[u-boot@MINI2440]# echo I Love Linux ;${tekkaman}
I Love Linux
I am Tekkaman
当你设置了ENV,它只保存在内存中,如果你要它保存在存放ENV的固态存储器中,请使用:saveenv。
[u-boot@MINI2440]# saveenv
Saving Environment to NAND...
Erasing Nand...
Erasing at 0x6000000000002 -- 0% complete.
Writing to Nand... done
如果在启动的时候会看到U-boot打印出:“Warning - bad CRC, using default environment”,说明U-boot没有在存放ENV的固态存储器中找到有效的ENV,只好使用你在编译的时候定义的默认ENV。如果U-boot存放ENV的固态存储器的驱动是OK的,那么只要运行 saveenv就可以把默认ENV写入固态存储器,下次启动就不会有这个警告了。
ENV可以放在许多固体存储器中,对于mini2440来说Nor Flash、Nand Flash或EEPROM都可以,就看你如何配置了(include/configs下的配置文件)。例如:
Nor Flash:
#define CONFIG_ENV_IS_IN_FLASH 1
#define CONFIG_ENV_OFFSET 0X40000
#define CONFIG_ENV_SIZE 0x20000 /* Total Size of Environment Sector */
Nand Flash:
#define CONFIG_ENV_IS_IN_NAND 1
#define CONFIG_ENV_OFFSET 0X40000
#define CONFIG_ENV_SIZE 0x20000 /* Total Size of Environment Sector */
EEPROM:
#define CONFIG_ENV_IS_IN_EEPROM 1 /* use EEPROM for environment vars */
#define CONFIG_ENV_OFFSET 0x000 /* environment starts at offset 0 */
#define CONFIG_ENV_SIZE 0x400 /* 1KB */
CONFIG_ENV_OFFSET是在整个存储器中的偏移地址;
CONFIG_ENV_SIZE是指其使用的大小。
注意 CONFIG_ENV_OFFSET和 CONFIG_ENV_SIZE 的设置,不要覆盖了其他分区。
四、U-boot的使用(二)
命令:
loadb - load binary file over serial line (kermit mode)
loadx - load binary file over serial line (xmodem mode)
loady - load binary file over serial line (ymodem mode)
功能:以不同的协议从串口获取文件.。
格式基本都为:
load? [ off ] [ baud ]
第1个参数是下载到SDRAM的地址,如果不填,就是用默认配置:CONFIG_SYS_LOAD_ADDR
第2个参数是波特率,一般不填,用默认的115200.
在windows下的超级终端可以用这些协议发送文件,但是在ubuntu下基本只能用kermit协议。一下使用C-kermit来发送一个文件到mini2440。
[u-boot@MINI2440]# loadb
## Ready for binary (kermit) download to 0x30008000 at 115200 bps...
上面已经启动了U-boot的kermit传输协议,这时按下 Ctrl + \ , 再按 c, 切换到C-kermit的命令行模式,输入命令:send <文件路径>,回车。
[u-boot@MINI2440]# loadb
## Ready for binary (kermit) download to 0x30008000 at 115200 bps...
(Back at MAGI-Linux)
----------------------------------------------------
C-Kermit 8.0.211, 10 Apr 2004, for Linux
Copyright (C) 1985, 2004,
Trustees of Columbia University in the City of New York.
Type ? or HELP for help.
(/home/tekkaman/桌面/) C-Kermit>send /home/tekkaman/development/share/zImage.img
C-kermit就开始传送,并且显示一个传送界面,并动态显示传送进度。
C-Kermit 8.0.211, 10 Apr 2004, MAGI-Linux
Current Directory: /home/tekkaman/��~L�~]�
Communication Device: /dev/ttyUSB0
[u-boot@MINI2440]# version
U-Boot 2009.11 ( 4月 04 2010 - 12:09:25)
[u-boot@MINI2440]# v
U-Boot 2009.11 ( 4月 04 2010 - 12:09:25)
[u-boot@MINI2440]# base
Base Address: 0x00000000
[u-boot@MINI2440]# ba
Base Address: 0x00000000
由于U-boot支持的命令实在太多,一个一个细讲不现实,也没有必要。所以下面我挑一些烧写和引导常用命令介绍一下,其他的命令大家就举一反三,或者“help”吧!
(1)获取帮助
命令:help 或 ?
功能:查看当前U-boot版本中支持的所有命令。
[u-boot@MINI2440]# help
? - alias for 'help'
askenv - get environment variables from stdin
base - print or set address offset
bdinfo - print Board Info structure
bmp - manipulate BMP image data
boot - boot default, i.e., run 'bootcmd'
bootd - boot default, i.e., run 'bootcmd'
bootelf - Boot from an ELF image in memory
bootm - boot application image from memory
bootp - boot image via network using BOOTP/TFTP protocol
bootvx - Boot vxWorks from an ELF image
cmp - memory compare
coninfo - print console devices and information
cp - memory copy
crc32 - checksum calculation
date - get/set/reset date & time
dcache - enable or disable data cache
dhcp - boot image via network using DHCP/TFTP protocol
echo - echo args to console
editenv - edit environment variable
eeprom - EEPROM sub-system
erase - erase FLASH memory
exit - exit script
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
i2c - I2C sub-system
icache - enable or disable instruction cache
iminfo - print header information for application image
imls - list all images found in flash
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
loadx - load binary file over serial line (xmodem mode)
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
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
protect - enable or disable FLASH write protection
rarpboot- boot image via network using RARP/TFTP protocol
reginfo - print register information
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
unzip - unzip a memory region
usb - USB sub-system
usbboot - boot from USB device
version - print monitor version
如果你想获取某条命令的更详细的帮助,可以使用:
help <你想要查的指令>
或者 ? <你想要查的指令> ,
甚至 h <你想要查的指令缩写>。
以bmp指令为例:
[u-boot@MINI2440]# help bmp
bmp - manipulate BMP image data
Usage:
bmp info <imageAddr> - display image info
bmp display <imageAddr> [x y] - display image at x,y
[u-boot@MINI2440]# ? bmp
bmp - manipulate BMP image data
Usage:
bmp info <imageAddr> - display image info
bmp display <imageAddr> [x y] - display image at x,y
[u-boot@MINI2440]# h bm
bmp - manipulate BMP image data
Usage:
bmp info <imageAddr> - display image info
bmp display <imageAddr> [x y] - display image at x,y
(2)环境变量(environment variables,简称ENV)与相关指令
和shell类似,U-Boot也有环境变量。一些U-boot默认的环境变量如下:
环 境 变 量
解 释 说 明
bootdelay
执行自动启动(bootcmd中的命令)的等候秒数
baudrate
串口控制台的波特率
netmask
以太网的网络掩码
ethaddr
以太网的MAC地址
bootfile
默认的下载文件名
bootargs
传递给Linux内核的启动参数
bootcmd
自动启动时执行命令
serverip
TFTP服务器端的IP地址
ipaddr
本地的IP地址
stdin
标准输入设备,一般是串口
stdout
标准输出,一般是串口,也可是LCD(VGA)
stderr
标准出错,一般是串口,也可是LCD(VGA)
要看到你的板上的ENV值可使用printenv命令,例如我的板子:
[u-boot@MINI2440]# printenv
bootargs=noinitrd root=/dev/nfs rw nfsroot=192.168.0.1:/home/tekkaman/working/nfs/rootfs ip=192.168.0.2:192.168.0.1::255.255.255.0 console=ttySAC0,115200 init=/linuxrc mem=64M
bootcmd=nfs 0x30008000 192.168.0.1:/home/tekkaman/working/nfs/zImage.img;bootm
bootdelay=1
baudrate=115200
ethaddr=08:08:11:18:12:27
ipaddr=192.168.0.2
serverip=192.168.0.1
gatewayip=192.168.0.1
netmask=255.255.255.0
tekkaman=bmp d 70000
stdin=serial
stdout=serial
stderr=serial
ethact=dm9000
Environment size: 470/131068 bytes
你会发现有些有的ENV我没有,还有一个“tekkaman”的ENV。原因是如果你没有设置这个环境变量就不会打印出,你也可以自己定义ENV,并在命令中使用${ENV}来调用它。同时你也可以删除这个ENV。设置ENV的命令是setenv,格式为:
setenv name value
第1个参数是环境变量的名称。
第2个参数是要设置的值,如果没有第2个参数,表示删除这个环境变量。
例如:我先将”tekkaman”参数删除,再设置,最后在一个命令串中调用。
[u-boot@MINI2440]# printenv tekkaman
tekkaman=bmp d 70000
[u-boot@MINI2440]# setenv tekkaman
[u-boot@MINI2440]# printenv tekkaman
## Error: "tekkaman" not defined
[u-boot@MINI2440]# setenv tekkaman echo "I am Tekkaman Ninja!"
[u-boot@MINI2440]# printenv tekkaman
tekkaman=echo I am Tekkaman
[u-boot@MINI2440]# echo I Love Linux ;${tekkaman}
I Love Linux
I am Tekkaman
当你设置了ENV,它只保存在内存中,如果你要它保存在存放ENV的固态存储器中,请使用:saveenv。
[u-boot@MINI2440]# saveenv
Saving Environment to NAND...
Erasing Nand...
Erasing at 0x6000000000002 -- 0% complete.
Writing to Nand... done
如果在启动的时候会看到U-boot打印出:“Warning - bad CRC, using default environment”,说明U-boot没有在存放ENV的固态存储器中找到有效的ENV,只好使用你在编译的时候定义的默认ENV。如果U-boot存放ENV的固态存储器的驱动是OK的,那么只要运行 saveenv就可以把默认ENV写入固态存储器,下次启动就不会有这个警告了。
ENV可以放在许多固体存储器中,对于mini2440来说Nor Flash、Nand Flash或EEPROM都可以,就看你如何配置了(include/configs下的配置文件)。例如:
Nor Flash:
#define CONFIG_ENV_IS_IN_FLASH 1
#define CONFIG_ENV_OFFSET 0X40000
#define CONFIG_ENV_SIZE 0x20000 /* Total Size of Environment Sector */
Nand Flash:
#define CONFIG_ENV_IS_IN_NAND 1
#define CONFIG_ENV_OFFSET 0X40000
#define CONFIG_ENV_SIZE 0x20000 /* Total Size of Environment Sector */
EEPROM:
#define CONFIG_ENV_IS_IN_EEPROM 1 /* use EEPROM for environment vars */
#define CONFIG_ENV_OFFSET 0x000 /* environment starts at offset 0 */
#define CONFIG_ENV_SIZE 0x400 /* 1KB */
CONFIG_ENV_OFFSET是在整个存储器中的偏移地址;
CONFIG_ENV_SIZE是指其使用的大小。
注意 CONFIG_ENV_OFFSET和 CONFIG_ENV_SIZE 的设置,不要覆盖了其他分区。
四、U-boot的使用(二)
命令:
loadb - load binary file over serial line (kermit mode)
loadx - load binary file over serial line (xmodem mode)
loady - load binary file over serial line (ymodem mode)
功能:以不同的协议从串口获取文件.。
格式基本都为:
load? [ off ] [ baud ]
第1个参数是下载到SDRAM的地址,如果不填,就是用默认配置:CONFIG_SYS_LOAD_ADDR
第2个参数是波特率,一般不填,用默认的115200.
在windows下的超级终端可以用这些协议发送文件,但是在ubuntu下基本只能用kermit协议。一下使用C-kermit来发送一个文件到mini2440。
[u-boot@MINI2440]# loadb
## Ready for binary (kermit) download to 0x30008000 at 115200 bps...
上面已经启动了U-boot的kermit传输协议,这时按下 Ctrl + \ , 再按 c, 切换到C-kermit的命令行模式,输入命令:send <文件路径>,回车。
[u-boot@MINI2440]# loadb
## Ready for binary (kermit) download to 0x30008000 at 115200 bps...
(Back at MAGI-Linux)
----------------------------------------------------
C-Kermit 8.0.211, 10 Apr 2004, for Linux
Copyright (C) 1985, 2004,
Trustees of Columbia University in the City of New York.
Type ? or HELP for help.
(/home/tekkaman/桌面/) C-Kermit>send /home/tekkaman/development/share/zImage.img
C-kermit就开始传送,并且显示一个传送界面,并动态显示传送进度。
C-Kermit 8.0.211, 10 Apr 2004, MAGI-Linux
Current Directory: /home/tekkaman/��~L�~]�
Communication Device: /dev/ttyUSB0