U-Boot上電啟動后,敲任意鍵能夠退出自動啟動狀態(tài),進入命令行。
U-Boot 1.1.2 (Apr 26 2005 - 12:27:13)
U-Boot code: 11080000 -> 1109614C BSS: -> 1109A91C
RAM Configuration:
Bank #0: 10000000 32 MB
Micron StrataFlash MT28F128J3 device initialized
Flash: 32 MB
In: serial
Out: serial
Err: serial
Hit any key to stop autoboot: 0
U-Boot>
在命令行提示符下,能夠輸入U-Boot的命令并執(zhí)行。U-Boot能夠支持幾十個常用命令,通過這些命令,能夠對研發(fā)板進行調試,能夠引導Linux內核,還能夠擦寫Flash完成系統(tǒng)部署等功能。掌控這些命令的使用,才能夠順利地進行嵌入式系統(tǒng)的研發(fā)。
輸入help命令,能夠得到當前U-Boot的任何命令列表。每一條命令后面是簡單的命令說明。
=> help
? - alias for 'help'
autoscr - run 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
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
flinfo - print FLASH memory information
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
loop - infinite loop on address range
md - memory display
mm - memory modify (auto-incrementing)
mtest - simple RAM test
mw - memory write (fill)
nfs - boot image via network using NFS protocol
nm - memory modify (constant address)
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
tftpboot - boot image via network using TFTP protocol
version - print monitor version
=>
U-Boot還提供了更加周詳?shù)拿顜椭ㄟ^help命令還能夠查看每個命令的參數(shù)說明。由于研發(fā)過程的需要,有必要先把U-Boot命令的用法弄清楚。接下來,根據(jù)每一條命令的幫助信息,解釋一下這些命令的功能和參數(shù)。
=> help bootm
bootm [addr [arg ...]]
- boot application image stored in memory
passing arguments 'arg ...'; when booting a Linux kernel,
'arg' can be the address of an initrd image
bootm命令能夠引導啟動存儲在內存中的程式映像。這些內存包括RAM和能夠永久保存的Flash。
第1個參數(shù)addr是程式映像的地址,這個程式映像必須轉換成U-Boot的格式。
第2個參數(shù)對于引導Linux內核有用,通常作為U-Boot格式的RAMDISK映像存儲地址;也能夠是傳遞給Linux內核的參數(shù)(缺省情況下傳遞bootargs環(huán)境變量給內核)。
=> help bootp
bootp [loadAddress] [bootfilename]
bootp命令通過bootp請求,需要DHCP服務器分配IP地址,然后通過TFTP協(xié)議下載指定的文檔到內存。
第1個參數(shù)是下載文檔存放的內存地址。
第2個參數(shù)是要下載的文檔名稱,這個文檔應該在研發(fā)主機上準備好。
=> help cmp
cmp [.b, .w, .l] addr1 addr2 count
- compare memory
cmp命令能夠比較2塊內存中的內容。.b以字節(jié)為單位;.w以字為單位;.l以長字為單位。注意:cmp.b中間不能保留空格,需要連續(xù)敲入命令。
第1個參數(shù)addr1是第一塊內存的起始地址。
第2個參數(shù)addr2是第二塊內存的起始地址。
第3個參數(shù)count是要比較的數(shù)目,單位按照字節(jié)、字或長字。
=> help cp
cp [.b, .w, .l] source target count
- copy memory
cp命令能夠在內存中復制數(shù)據(jù)塊,包括對Flash的讀寫操作。
第1個參數(shù)source是要復制的數(shù)據(jù)塊起始地址。
第2個參數(shù)target是數(shù)據(jù)塊要復制到的地址。這個地址假如在Flash中,那么會直接調用寫Flash的函數(shù)操作。所以U-Boot寫Flash就使用這個命令,當然需要先把對應Flash區(qū)域擦干凈。
第3個參數(shù)count是要復制的數(shù)目,根據(jù)cp.b cp.w cp.l分別以字節(jié)、字、長字為單位。
=> help crc32
crc32 address count [addr]
- compute CRC32 checksum [save at addr]
crc32命令能夠計算存儲數(shù)據(jù)的校驗和。
第1個參數(shù)address是需要校驗的數(shù)據(jù)起始地址。
第2個參數(shù)count是要校驗的數(shù)據(jù)字節(jié)數(shù)。
第3個參數(shù)addr用來指定保存結果的地址。
=> help echo
echo [args..]
- echo args to console; \c suppresses newline
echo命令回顯參數(shù)。
=> help erase
erase start end
- erase FLASH from addr 'start' to addr 'end'
erase N:SF[-SL]
- erase sectors SF-SL in FLASH bank # N
erase bank N
- erase FLASH bank # N
erase all
- erase all FLASH banks
erase命令能夠擦Flash。
參數(shù)必須指定Flash擦除的范圍。
按照起始地址和結束地址,start必須是擦除塊的起始地址;end必須是擦除末尾塊的結束地址。這種方式最常用。舉例說明:擦除0x20000 – 0x3ffff區(qū)域命令為erase 20000 3ffff。
按照組和扇區(qū),N表示Flash的組號,SF表示擦除起始扇區(qū)號,SL表示擦除結束扇區(qū)號。另外,還能夠擦除整個組,擦除組號為N的整個Flash組。擦除全部Flash只要給出一個all的參數(shù)即可。
=> help flinfo
flinfo
- print information for all FLASH memory banks
flinfo N
- print information for FLASH memory bank # N
flinfo命令打印全部Flash組的信息,也能夠只打印其中某個組。一般嵌入式系統(tǒng)的Flash只有一個組。
=> help go
go addr [arg ...]
- start application at address 'addr'
passing 'arg' as arguments
go命令能夠執(zhí)行應用程式。
第1個參數(shù)是要執(zhí)行程式的入口地址。
第2個可選參數(shù)是傳遞給程式的參數(shù),能夠不用。
=> help iminfo
iminfo addr [addr ...]
- print header information for application image starting at
address 'addr' in memory; this includes verification of the
image contents (magic number, header and payload checksums)
iminfo能夠打印程式映像的開頭信息,包含了映像內容的校驗(序列號、頭和校驗和)。
第1個參數(shù)指定映像的起始地址。
可選的參數(shù)是指定更多的映像地址。
=> help loadb
loadb [ off ] [ baud ]
- load binary file over serial line with offset 'off' and baudrate 'baud'
loadb命令能夠通過串口線下載二進制格式文檔。
=> help loads
loads [ off ]
- load S-Record file over serial line with offset 'off'
loads命令能夠通過串口線下載S-Record格式文檔。
=> help mw
mw [.b, .w, .l] address value [count]
- write memory
mw命令能夠按照字節(jié)、字、長字寫內存,.b .w .l的用法和cp命令相同。
第1個參數(shù)address是要寫的內存地址。
第2個參數(shù)value是要寫的值。
第3個可選參數(shù)count是要寫單位值的數(shù)目。
=> help nfs
nfs [loadAddress] [host ip addr:bootfilename]
nfs命令能夠使用NFS網(wǎng)絡協(xié)議通過網(wǎng)絡啟動映像。
=> help nm
nm [.b, .w, .l] address
- memory modify, read and keep address
nm命令能夠修改內存,能夠按照字節(jié)、字、長字操作。
參數(shù)address是要讀出并且修改的內存地址。
=> help printenv
printenv
- print values of all environment variables
printenv name ...
- print value of environment variable 'name'
printenv命令打印環(huán)境變量。
能夠打印全部環(huán)境變量,也能夠只打印參數(shù)中列出的環(huán)境變量。
=> help protect
protect on start end
- protect Flash from addr 'start' to addr 'end'
protect on N:SF[-SL]
- protect sectors SF-SL in Flash bank # N
protect on bank N
- protect Flash bank # N
protect on all
- protect all Flash banks
protect off start end
- make Flash from addr 'start' to addr 'end' writable
protect off N:SF[-SL]
- make sectors SF-SL writable in Flash bank # N
protect off bank N
- make Flash bank # N writable
protect off all
- make all Flash banks writable
protect命令是對Flash寫保護的操作,能夠使能和解除寫保護。
第1個參數(shù)on代表使能寫保護;off代表解除寫保護。
第2、3參數(shù)是指定Flash寫保護操作范圍,跟擦除的方式相同。
=> help rarpboot
rarpboot [loadAddress] [bootfilename]
rarboot命令能夠使用TFTP協(xié)議通過網(wǎng)絡啟動映像。也就是把指定的文檔下載到指定地址,然后執(zhí)行。
第1個參數(shù)是映像文檔下載到的內存地址。
第2個參數(shù)是要下載執(zhí)行的映像文檔。
=> help run
run var [...]
- run the commands in the environment variable(s) 'var'
run命令能夠執(zhí)行環(huán)境變量中的命令,后面參數(shù)能夠跟幾個環(huán)境變量名。
=> help setenv
setenv name value ...
- set environment variable 'name' to 'value ...'
setenv name
- delete environment variable 'name'
setenv命令能夠配置環(huán)境變量。
第1個參數(shù)是環(huán)境變量的名稱。
第2個參數(shù)是要配置的值,假如沒有第2個參數(shù),表示刪除這個環(huán)境變量。
=> help sleep
sleep N
- delay execution for N seconds (N is _decimal_ !!!)
sleep命令能夠延遲N秒鐘執(zhí)行,N為十進制數(shù)。
=> help tftpboot
tftpboot [loadAddress] [bootfilename]
tftpboot命令能夠使用TFTP協(xié)議通過網(wǎng)絡下載文檔。按照二進制文檔格式下載。另外使用這個命令,必須配置好相關的環(huán)境變量。例如serverip和ipaddr。
第1個參數(shù)loadAddress是下載到的內存地址。
第2個參數(shù)是要下載的文檔名稱,必須放在TFTP服務器相應的目錄下。
這 些U-Boot命令為嵌入式系統(tǒng)提供了豐富的研發(fā)和調試功能。在Linux內核啟動和調試過程中,都能夠用到U-Boot的命令。但是一般情況下,無需使 用全部命令。比如已支持以太網(wǎng)接口,能夠通過tftpboot命令來下載文檔,那么更有必要使用串口下載的loadb嗎?反過來,假如研發(fā)板需要特別的調 試功能,也能夠添加新的命令。
在建立交叉研發(fā)環(huán)境和調試Linux內核等章節(jié)時,在ARM平臺上移植了U-Boot,并且提供了具體U-Boot的操作步驟。