U-BOOT的常用命令
我們以JZ2440 V3開發板,採用U-BOOT 1.1.6版本,熟悉常用命令與環境變數
1、help命令
(1)查詢所有的命令
OpenJTAG> help ? - alias for 'help' 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' 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 chpart - change active partition 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 echo - echo args to console erase - erase FLASH memory 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 icache - enable or disable instruction cache 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 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 menu - display a menu, to select the items to do something 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 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 suspend - suspend the board tftpboot- boot image via network using TFTP protocol usbslave - get file from host(PC) version - print monitor version
(2)查詢某一個命令的用法
help+命令的名稱
OpenJTAG> help printenv
printenv
- print values of all environment variables
printenv name ...
- print value of environment variable 'name'
2、環境變數的操作命令
(1)如何理解環境變數:
環境變數就好像程式的全域性變數一樣。程式中任何地方都可以根據需要去呼叫或者更改環境變數(一般都是呼叫),環境變數和全域性變數不同之處在於:全域性變數的生命週期是在程式的一次運行當中,開始執行時誕生程式結束時死亡,下次執行程式時從頭開始;但是環境變數被儲存在Flash的另一塊專門區域(Flash上有一個環境變數分割槽),一旦我們在程式中儲存了該環境變數,那麼下次開機時該環境變數的值將維持上一次更改儲存後的值。
(2)環境變數如何參與程式執行
環境變數有2份,一份在Flash中,另一份在DDR中。uboot開機時一次性從Flash中讀取全部環境變數到DDR中作為環境變數的初始化值,然後使用過程中都是用DDR中這一份,使用者可以用saveenv指令將DDR中的環境變數重新寫入Flash中去更新Flash中環境變數。下次開機時又會從Flash中再讀一次。
(3)printenv/print
print命令不用帶引數,作用是打印出系統中所有的環境變數。
OpenJTAG> print
bootargs=noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0,115200
bootcmd=nand read.jffs2 0x30007FC0 kernel; bootm 0x30007FC0
bootdelay=2
baudrate=115200
ethaddr=08:00:3e:26:0a:5b
ipaddr=192.168.1.17
serverip=192.168.1.11
netmask=255.255.255.0
stdin=serial
stdout=serial
stderr=serial
mtdids=nand0=nandflash0
mtdparts=mtdparts=nandflash0: [email protected](bootloader),128k(params),2m(kernel),-(root)
partition=nand0,0
mtddevnum=0
mtddevname=bootloader
Environment size: 450/131068 bytes
(4)設定(新增/更改)環境變數:setenv/set
setenv name value ...
- set environment variable 'name' to 'value ...'
setenv name
- delete environment variable 'name'
OpenJTAG> set bootdelay 3
OpenJTAG> print
bootargs=noinitrd root=/dev/mtdblock3 init=/linuxrc console=ttySAC0,115200
bootcmd=nand read.jffs2 0x30007FC0 kernel; bootm 0x30007FC0
baudrate=115200
ethaddr=08:00:3e:26:0a:5b
ipaddr=192.168.1.17
serverip=192.168.1.11
netmask=255.255.255.0
stdin=serial
stdout=serial
stderr=serial
mtdids=nand0=nandflash0
mtdparts=mtdparts=nandflash0:[email protected](bootloader),128k(params),2m(kernel),-(root)
partition=nand0,0
mtddevnum=0
mtddevname=bootloader
bootdelay=3
(5)儲存環境變數的更改:saveenv/save
上面操作只是更新了記憶體中的環境變數,但是flash中的環境變數還是原來的,下次開機時,bootdelay還是2。
saveenv/save命令不帶引數,直接執行,作用是將記憶體中的環境變數的值同步儲存到Flash中環境變數的分割槽。注意:環境變數的儲存是整體的覆蓋儲存,也就是說記憶體中所有的環境變數都會整體的將Flash中環境變數分割槽中原來的內容整體覆蓋。
3、記憶體操作指令:mm、mw、md
(1)DDR中是沒有分割槽的(只聽說過對硬碟、Flash進行分割槽,沒聽說過對記憶體進行分割槽····),但是記憶體使用時要注意,千萬不能越界踩到別人了。因為uboot是一個裸機程式,不像作業系統會由系統整體管理所有記憶體,系統負責分配和管理,系統會保證記憶體不會隨便越界。然後裸機程式中uboot並不管理所有記憶體,記憶體是散的隨便用的,所以如果程式設計師(使用uboot的人)自己不注意就可能出現自己把自己的資料給覆蓋了。
(2)md就是memory display,用來顯示記憶體中的內容。
OpenJTAG> help md
md [.b, .w, .l] address [# of objects]
- memory display
其中
.b byte 以位元組為單位進行操作
.w word 以雙字為單位進行操作
.l long 以四位元組為單位進行操作
OpenJTAG> md.b 30000000
30000000: 20 00 00 c0 00 00 00 c0 08 00 00 c0 08 00 00 c0 ...............
30000010: 10 00 00 c0 10 00 00 c0 18 00 00 c4 18 00 00 c0 ................
30000020: 20 40 00 c0 20 00 00 c0 28 00 10 c0 28 00 00 c8 @.. ...(...(...
30000030: 30 00 00 c0 30 00 00 c0 3a 00 20 c0 38 00 00 c0 0...0...:. .8...
30000040: 40 00 00 c0 40 00 00 c0 48 00 00 c0 48 00 00 c0 @[email protected]
30000050: 50 00 01 c4 50 00 00 c0 58 00 00 c0 50 00 00 c0 P...P...X...P...
OpenJTAG> md.w 30000000
30000000: 0020 c000 0000 c000 0008 c000 0008 c000 ...............
30000010: 0010 c000 0010 c000 0018 c400 0018 c000 ................
30000020: 4020 c000 0020 c000 0028 c010 0028 c800 @.. ...(...(...
30000030: 0030 c000 0030 c000 003a c020 0038 c000 0...0...:. .8...
30000040: 0040 c000 0040 c000 0048 c000 0048 c000 @[email protected]
30000050: 0050 c401 0050 c000 0058 c000 0050 c000 P...P...X...P...
30000060: 0060 c000 0060 c000 0068 c000 0068 c000 `...`...h...h...
OpenJTAG> md.l 30000000
30000000: c0000020 c0000000 c0000008 c0000008 ...............
30000010: c0000010 c0000010 c4000018 c0000018 ................
30000020: c0004020 c0000020 c0100028 c8000028 @.. ...(...(...
30000030: c0000030 c0000030 c020003a c0000038 0...0...:. .8...
30000040: c0000040 c0000040 c0000048 c0000048 @[email protected]
(3)mw就是memory write,將內容寫到記憶體中
OpenJTAG> help mw
mw [.b, .w, .l] address value [count]
- write memory
(4)mm就是memory modify,修改記憶體中的某一塊,說白了還是寫記憶體(如果需要批量的逐個單元的修改記憶體,用mm最合適)
OpenJTAG> help mm
mm [.b, .w, .l] address
- memory modify, auto increment address
4、啟動核心指令:bootm、go
(1)uboot的終極目標就是啟動核心,啟動核心在uboot中表現為一個指令,uboot命令列中呼叫這個指令就會啟動核心(不管成功與否,所以這個指令是一條死路)。
(2)差別:bootm啟動核心同時給核心傳參,而go命令啟動核心不傳參。bootm其實才是正宗的啟動核心的命令,一般情況下都用這個;go命令本來不是專為啟動核心設計的,go命令內部其實就是一個函式指標指向一個記憶體地址然後直接呼叫那個函式,go命令的實質就是PC直接跳轉到一個記憶體地址去執行而已。go命令可以用來在uboot中執行任何的裸機程式(有一種除錯裸機程式的方法就是事先啟動uboot,然後在uboot中去下載裸機程式,用go命令去執行裸機程式)
OpenJTAG> 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
在uboot命令裡面,使用中括號括起來的是可選項。 add是我們核心存放的地址,arg是傳給核心的引數
5.nandflash的操作命令
OpenJTAG> help nand
nand info - show available NAND devices
nand device [dev] - show or set current device
nand read[.jffs2] - addr off|partition size
nand write[.jffs2] - addr off|partiton size - read/write `size' bytes starting
at offset `off' to/from memory address `addr'
nand read.yaffs addr off size - read the `size' byte yaffs image starting
at offset `off' to memory address `addr'
nand write.yaffs addr off size - write the `size' byte yaffs image starting
at offset `off' from memory address `addr'
nand read.raw addr off size - read the `size' bytes starting
at offset `off' to memory address `addr', without oob and ecc
nand write.raw addr off size - write the `size' bytes starting
at offset `off' from memory address `addr', without oob and ecc
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 at offset (UNSAFE)
nand biterr off - make a bit error at offset (UNSAFE)
nand lock [tight] [status] - bring nand to lock state or display locked pages
nand unlock [offset] [size] - unlock section
部分參考朱友鵬老師課件