dnw:在進入系統之前進入指令行,輸入該指令可下載燒錄文件。
re:重新啟動嵌入式系統。
printenv:打印當前系統環境變量。
setenv:設置環境變量,格式:setenv name value ...,表示將name 變量設置成value 值;如果沒有這個參數,表示刪除該變量。
saveenv:保存環境變量到NAND中。
sleep:延遲執行,格式:sleep N,可以延遲N秒鍾執行。
run:執行環境變量中的命令,格式:run var,可以跟幾個環境變量名。
crc32:計算校驗值,格式:crc32 address count [addr],第一個參數是需校驗的起始地址,第二個參數是校驗的數據字節數,第三個參 數是保存校驗值的地址。
cp:在內存中復制數據塊,格式:cp source target count,第一個參數是源地址,第二個參數是目的地址,第三個參數是復制數目。
cmp:比較內存中的數據塊,格式:cmp addr1 addr2 count,第一個參數是內存地址一,第二個參數是內存地址二,第三個是比較長度(單位是字節數除以4,以WORDS為單位)。
bootm:可以引導啟動存儲在內存中的程序映像。格式:bootm addr1 addr2,第一個參數是程序映像的地址,第二個參數一般是RAMDISK地址。
nand scrub:暴力擦除指令,擦除整個NAND,會擦除bad block標記。
nand erase:擦除NAND,格式:nand erase addr1 count,第一個參數是OFFSET,第二個參數是擦除字節數。其中OFFSET是相對於Download地址。
nand write:下載的內存數據寫入NAND,格式:nand write addr offset count,第一個參數是寫入基地址,第二個參數是偏移地址,第三個參數是寫入字節數。
nand read:講NAND數據讀取到內存,格式:nand read addr offset count,第一個參數是讀取的NAND地址,第二個參數是內存位置偏移,第三個參數是讀取字節數。
nand bad:測試NAND FLASH壞塊的命令。如:nand bad,即可顯示壞的區塊地址。
通常我們會回寫數據來測試寫入跟讀取的數據是否一致,如:
假設Download Address: 0xc0000000,Download Filesize:0x1df48c
nand erase 600000 300000 //擦除c0600000為開始的300000個字節
nand write c0000000 600000 300000 //往剛擦除的空間寫入內存起始地址的數據共300000個長度
nand read c0600000 600000 300000 //讀取剛寫入的NAND地址共300000個長度到偏移600000的內存中
cmp c0600000 c0000000 300000 //比較兩段內存的數據是否相同
此通常會用在DDR調試上,比如128MDDR的MEMORY MAP基地址是0X50000000,空間從0X50000000-0X58000000,如果要改軟件支持到256M,假設DOWNLOAD地址是0XC0000000,通過內存拷貝和比較命令來對比0XC0000000和0X59000000的內容是否一致。
*************************************************************************
引用別人之前的解決的一個問題:
當把u-boot下載進去,再把內核下進去后發現,內核跑不起來。反反復復嘗試,還是沒有進展。在一篇文章中看到了u-boot源代碼的配制文件config.mk,打開這個文件,看到內核的啟動地址是0x50008000與用戶手冊上的0xc0008000不一樣。就按照這個搞了一下,果然就可以啟動內核了。但還是不能燒到flash里去,后來用nand bad命令發現:存放內核的nand flash啟始地址是個壞塊。所以將內核存在了擴展區才搞成功
*****************************************************************************SBL*****************
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
Communication Speed: 115200
Parity: none
RTT/Timeout: 01 / 02
SENDING: /home/tekkaman/development/share/zImage.img => zImage.img
File Type: BINARY
File Size: 2277540
Percent Done: 19 /////////-
...10...20...30...40...50...60...70...80...90..100
Estimated Time Left: 00:03:35
Transfer Rate, CPS: 8536
Window Slots: 1 of 1
Packet Type: D
Packet Count: 557
Packet Length: 1000
Error Count: 0
Last Error:
Last Message:
X to cancel file, Z to cancel group, <CR> to resend last packet,
E to send Error packet, ^C to quit immediately, ^L to refresh screen.
傳送完畢后,輸入c ,回到U-boot的串口界面。
[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
(/home/tekkaman/桌面/) C-Kermit>c
Connecting to /dev/ttyUSB0, speed 115200
Escape character: Ctrl-\ (ASCII 28, FS): enabled
Type the escape character followed by C to get back,
or followed by ? to see other options.
----------------------------------------------------
## Total Size = 0x0022c0a4 = 2277540 Bytes
## Start Addr = 0x30008000
(4)網絡命令
只要你的網卡驅動沒問題,那么你就可以通過網絡來傳輸文件到開發板,這可比串口快多了。你可以直接用交叉網線連接開發板和電腦,也可以用普通直連網線連接路由器,再連到電腦,不過記得配置好網絡,關閉防火牆哦。
先測試網絡是否通了,現在開發板使用ping 命令,看看是否可以ping通電腦:
[u-boot@MINI2440]# ping 192.168.1.100
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:08:11:18:12:27
operating at 100M full duplex mode
Using dm9000 device
host 192.168.1.100 is alive
如果出現:
[u-boot@MINI2440]# ping 192.168.1.100
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:08:11:18:12:27
operating at 100M full duplex mode
Using dm9000 device
ping failed; host 192.168.1.100 is not alive
這樣無法ping通的事,可能是:
1、U-boot網卡驅動有問題
2、U-boot網絡協議延時配置有問題
3、網絡參數配置問題,比如IP等,Host和Target都有可能有問題。Host最好關閉IPv6。
實在找不到原因,用Wireshark抓包看看。
如果網絡暢通,下面就可以使用下面的命令從tftp目錄或者nfs目錄下載文件到SDRAM了。
命令:
dhcp - boot image via network using DHCP/TFTP protocol
rarpboot- boot image via network using RARP/TFTP protocol
nfs - boot image via network using NFS protocol
tftpboot- boot image via network using TFTP protocol
bootp - boot image via network using BOOTP/TFTP protocol
這幾個命令的格式都是:<指令> [目的SDRAM地址] [[主機IP:]文件名]
注意:
要使用dhcp、rarpboot或 bootp 等功能要路由器或Host的支持。
如果沒有輸入[目的SDRAM地址],系統就是用編譯時定義的CONFIG_SYS_LOAD_ADDR作為目的SDRAM地址
如果tftpboot和nfs命令沒有定義[主機IP:],則使用ENV中的serverip
其它命令必需定義[主機IP:],否則會使用提供動態IP服務的主機IP作為[主機IP:]。
使用范例:
[u-boot@MINI2440]# nfs 0x30008000 192.168.1.100:/home/tekkaman/development/share/u-boot.bin
Loading: ###################################################
done
Bytes transferred = 256220 (3e8dc hex)
[u-boot@MINI2440]# tftp u-boot.bin
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:08:11:18:12:27
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 192.168.1.100; our IP address is 192.168.1.101
Filename 'u-boot.bin'.
Load address: 0x30008000
Loading: T ##################
done
Bytes transferred = 256220 (3e8dc hex)
[u-boot@MINI2440]# dhcp 192.168.1.100:u-boot.bin
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:08:11:18:12:27
operating at 100M full duplex mode
BOOTP broadcast 1
BOOTP broadcast 2
DHCP client bound to address 192.168.1.101
Using dm9000 device
TFTP from server 192.168.1.100; our IP address is 192.168.1.101
Filename 'u-boot.bin'.
Load address: 0x30008000
Loading: ##################
done
Bytes transferred = 256220 (3e8dc hex)
[u-boot@MINI2440]# bootp 192.168.1.100:u-boot.bin
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:08:11:18:12:27
operating at 100M full duplex mode
BOOTP broadcast 1
BOOTP broadcast 2
DHCP client bound to address 192.168.1.101
Using dm9000 device
TFTP from server 192.168.1.100; our IP address is 192.168.1.101
Filename 'u-boot.bin'.
Load address: 0x30008000
Loading: ##################
done
Bytes transferred = 256220 (3e8dc hex)
[u-boot@MINI2440]# rarpboot 192.168.1.100:u-boot.bin
我的路由器沒有開rarp協議,所以rarpboot 無法使用,要使用dhcp或 bootp 也是要路由或Host支持的。
(5)Nand Flash操作指令
常用的Nand Flash指令如下:
指令
功能
nand info
顯示可使用的Nand Flash
nand device [dev]
顯示或設定當前使用的Nand Flash
nand read
addr off
size
Nand Flash讀取命令,從Nand的 off 偏移地址處讀取size 字節的數據到SDRAM的 addr地址。
nand write
addr off
size
Nand Flash燒寫命令,將SDRAM的 addr地址處的size 字節的數據燒寫到Nand的 off 偏移地址。
nand write[.yaffs[1]]
addr off size
燒寫yaffs 映像專用的命令,.yaffs1 for 512+16 NAND
nand erase [clean] [off size]
Nand Flash檫除命令,擦除Nand Flash的 off 偏移地址處的size 字節的數據
nand bad
顯示Nand Flash的壞塊
nand dump[.oob] off
顯示Nand Flash中的數據(16進制)
nand scrub
徹底擦除整塊Nand Flash中的數據,包括OOB。可以擦除軟件壞塊標志。
nand markbad off
標示 Nand的 off 偏移地址處的塊為壞塊
使用范例:
[u-boot@MINI2440]# nand info
Device 0: NAND 128MiB 3,3V 8-bit, sector size 128 KiB
[u-boot@MINI2440]# nand device 0
Device 0: NAND 128MiB 3,3V 8-bit... is now current device
[u-boot@MINI2440]# nand read 0x30008000 0x60000 200000
NAND read: device 0 offset 0x60000, size 0x200000
2097152 bytes read: OK
[u-boot@MINI2440]# nand bad
Device 0 bad blocks:
030a0000
030c0000
030e0000
07ee0000
[u-boot@MINI2440]# nand markbad 0x500000
block 0x00500000 successfully marked as bad
[u-boot@MINI2440]# nand bad
Device 0 bad blocks:
00500000
030a0000
030c0000
030e0000
07ee0000
[u-boot@MINI2440]# nand scrub
NAND scrub: device 0 whole chip
Warning: scrub option will erase all factory set bad
There is no reliable way to recover them.
Use this command only for testing purposes if you
are sure of what you are
Really scrub this NAND flash? <y/N>
Erasing at 0x2f4000008000000 -- 0% complete.
NAND 128MiB 3,3V 8-bit: MTD Erase failure: -5
NAND 128MiB 3,3V 8-bit: MTD Erase failure: -5
NAND 128MiB 3,3V 8-bit: MTD Erase failure: -5
Erasing at 0x7ea000008000000 -- 0% complete.
NAND 128MiB 3,3V 8-bit: MTD Erase failure: -5
Erasing at 0x7fe000008000000 -- 0% complete.
OK
[u-boot@MINI2440]# nand bad
Device 0 bad blocks:
030a0000
030c0000
030e0000
07ee0000
[u-boot@MINI2440]# nand dump 0x8000
Page 00008000 dump:
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
(略)
OOB:
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
[u-boot@MINI2440]# tftp u-boot.bin
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:08:11:18:12:27
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 192.168.1.100; our IP address is 192.168.1.101
Filename 'u-boot.bin'.
Load address: 0x30008000
Loading: T ##################
done
Bytes transferred = 256220 (3e8dc hex)
[u-boot@MINI2440]# nand write 0x30008000 0 40000
NAND write: device 0 offset 0x0, size 0x40000
Writing at 0x2000000020000 -- 100% is complete. 262144 bytes written: OK
[u-boot@MINI2440]# nand dump 0x8000
Page 00008000 dump:
00 00 53 e1 01 00 00 2a 15 40 e0 e3 19 00 00 ea
(略)
60 30 97 e5 03 00 54 e1 f6 ff ff ba 00 40 a0 e3
OOB:
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff
65 a9 6b f3 ff 33 fc 30
f3 33 cf 33 0f f0 ff 00
cc 0f 59 55 57 96 a5 5b
nboot 指令也是一條Nand Flash 讀取指令,它是將Nand Flash 的 offset 偏移地址的內核映像讀取到SDRAM的loadAddr位置。它會自動讀取到內核映像(使用mkimage處理過的)的結束,所以不用給出讀取大小。
格式:nboot loadAddr dev offset
使用范例:
[u-boot@MINI2440]# tftp 192.168.1.100:zImage.img
dm9000 i/o: 0x20000300, id: 0x90000a46
DM9000: running in 16 bit mode
MAC: 08:08:11:18:12:27
operating at 100M full duplex mode
Using dm9000 device
TFTP from server 192.168.1.100; our IP address is 192.168.1.101
Filename 'zImage.img'.
Load address: 0x30008000
Loading: T #################################################################
#################################################################
##########################
done
Bytes transferred = 2277540 (22c0a4 hex)
[u-boot@MINI2440]# nand erase 0x100000 300000
NAND erase: device 0 offset 0x100000, size 0x300000
Erasing at 0x3e000001800000 -- 0% complete.
OK
[u-boot@MINI2440]# nand write 0x30008000 0x100000 300000
NAND write: device 0 offset 0x100000, size 0x300000
Writing at 0x3e000000020000 -- 100% is complete. 3145728 bytes written: OK
[u-boot@MINI2440]# nand device 0
Device 0: NAND 128MiB 3,3V 8-bit... is now current device
[u-boot@MINI2440]# nboot 30008000 0 0x100000
Loading from NAND 128MiB 3,3V 8-bit, offset 0x100000
Image Name: tekkaman
Created: 2010-03-29 12:59:51 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2277476 Bytes = 2.2 MB
Load Address: 30008000
Entry Point: 30008040
[u-boot@MINI2440]# bootm 30008000
## Booting kernel from Legacy Image at 30008000 ...
Image Name: tekkaman
Created: 2010-03-29 12:59:51 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 2277476 Bytes = 2.2 MB
Load Address: 30008000
Entry Point: 30008040
Verifying Checksum ... OK
XIP Kernel Image ... OK
OK
Starting kernel ...
Uncompressing Linux... done, booting the kernel.
Linux version 2.6.33.1 (tekkaman@MAGI-Linux) (gcc version 4.3.2 (crosstool-NG-1.6.1-tekkaman) ) #5 Mon Mar 29 20:58:50 CST 2010
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: MINI2440
(略)
四、U-boot的使用(三)
(6) 內存/寄存器操作指令
nm 修改內存值 (指定地址)
格式: nm [.b, .w, .l] address
mm 修改內存值(地址自動加一)
格式: mm [.b, .w, .l] address
md 顯示內存值
格式: md [.b, .w, .l] address [# of objects]
mw 用指定的數據填充內存
格式: mw [.b, .w, .l] address value [count]
cp 內存的拷貝(包括內存與Nor Flash間的數據拷貝)
格式:cp [.b, .w, .l] source target count
上面是查看和修改內存值的指令,可以查看和修改SDRAM和寄存器值。
[.b, .w, .l]代表了查看和修改形式:bit、word、long
使用范例:
[u-boot@MINI2440]# md.b 0x30008000 20
30008000: cc 33 fe 33 cc b3 4c 33 ac 33 de 33 5c 13 cc 33 .3.3..L3.3.3\..3
30008010: cc 32 cc 31 dc 33 cf 33 cc 33 4e 33 8f 13 cc 33 .2.1.3.3.3N3...3
[u-boot@MINI2440]# md.w 0x30008000 20
30008000: 33cc 33fe b3cc 334c 33ac 33de 135c 33cc .3.3..L3.3.3\..3
30008010: 32cc 31cc 33dc 33cf 33cc 334e 138f 33cc .2.1.3.3.3N3...3
30008020: 338c 33cd 33cc 7bcc 3bcc 33cc 135e 734c .3.3.3.{.;.3^.Ls
30008030: 7bdc 37cc 31dc 33c4 038c 33e8 77cc 13cc .{.7.1.3...3.w..
[u-boot@MINI2440]# md.l 0x30008000 20
30008000: 33fe33cc 334cb3cc 33de33ac 33cc135c .3.3..L3.3.3\..3
30008010: 31cc32cc 33cf33dc 334e33cc 33cc138f .2.1.3.3.3N3...3
30008020: 33cd338c 7bcc33cc 33cc3bcc 734c135e .3.3.3.{.;.3^.Ls
30008030: 37cc7bdc 33c431dc 33e8038c 13cc77cc .{.7.1.3...3.w..
30008040: 234c77ce 33dc339c 33ec3ece f3cc36ec .wL#.3.3.>.3.6..
30008050: 37dc33cc 73cc3f5c 17dd314c 33cc62e8 .3.7\?.sL1...b.3
30008060: b6cc33dc 33c233cc 33cc32cc 33cc3f68 .3...3.3.2.3h?.3
30008070: 73cc31cc b3cc33cc 33cc37c9 33df13cc .1.s.3...7.3...3
[u-boot@MINI2440]# nm 0x30008000
30008000: 33fe33cc ? 12345678
30008000: 12345678 ? 34567890
30008000: 34567890 ? q
[u-boot@MINI2440]# nm.b 0x30008000
30008000: 90 ? 11
30008000: 11 ? 12
30008000: 12 ? q
[u-boot@MINI2440]# mm 0x30008000
30008000: 34567812 ? 54321123
30008004: 334cb3cc ? 12345678
30008008: 33de33ac ? 21234543
3000800c: 33cc135c ? q
[u-boot@MINI2440]# md.b 0x30008000 20
30008000: 23 11 32 54 78 56 34 12 43 45 23 21 5c 13 cc 33 #.2TxV4.CE#!\..3
30008010: cc 32 cc 31 dc 33 cf 33 cc 33 4e 33 8f 13 cc 33 .2.1.3.3.3N3...3
[u-boot@MINI2440]# mw.b 0x30008000 aa 10
[u-boot@MINI2440]# mw.b 0x30008010 55 10
[u-boot@MINI2440]# md.b 0x30008000 20
30008000: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................
30008010: 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 UUUUUUUUUUUUUUUU
[u-boot@MINI2440]# cp.b 0x30008000 0x30008010 10
[u-boot@MINI2440]# md.b 0x30008000 20
30008000: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................
30008010: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa ................
你可以試着修改LED相連的GPIO寄存器的數據寄存器值,可以控制LED的點亮!
先熄滅后點亮LED1的范例:(這個實驗要結合芯片數據手冊和mini2440的原理圖來理解)
[u-boot@MINI2440]# md 0x56000014 1
56000014: 00000600 ....
[u-boot@MINI2440]# nm.w 0x56000014
56000014: 0600 ? 620 (熄滅)
56000014: 0620 ? 600 (點亮)
(7) Nor Flash指令
Nor Flash 的命令經常用於燒寫數據到Nor Flash 。
flinfo 打印Flash存儲器的信息,並列出所有Sector。
flinfo N 單獨打Flash存儲器N Block的信息。(在有多塊Nor Flash時使用)
使用范例:
[u-boot@MINI2440]# flinfo
Bank # 1: SST: 1x SST39VF1601 (2MB)
Size: 2 MB in 32 Sectors
Sector Start Addresses:
00000000 (RO) 00010000 (RO) 00020000 (RO) 00030000 (RO) 00040000
00050000 00060000 (RO) 00070000 (RO) 00080000 00090000
000A0000 000B0000 000C0000 000D0000 000E0000
000F0000 00100000 00110000 00120000 00130000
00140000 00150000 00160000 00170000 00180000
00190000 001A0000 001B0000 001C0000 001D0000
001E0000 001F0000
[u-boot@MINI2440]# flinfo 1
Bank # 1: SST: 1x SST39VF1601 (2MB)
Size: 2 MB in 32 Sectors
Sector Start Addresses:
00000000 (RO) 00010000 (RO) 00020000 (RO) 00030000 (RO) 00040000
00050000 00060000 (RO) 00070000 (RO) 00080000 00090000
000A0000 000B0000 000C0000 000D0000 000E0000
000F0000 00100000 00110000 00120000 00130000
00140000 00150000 00160000 00170000 00180000
00190000 001A0000 001B0000 001C0000 001D0000
001E0000 001F0000
[u-boot@MINI2440]# flinfo 2
Only FLASH Banks # 1 ... # 1 supported
后面帶有(RO)的說明這個Sector已經寫保護了。
因為Nor Flash的讀取接口和SDRAM是一樣的,所以Nor Flash的讀取也是使用md命令。范例如下:
[u-boot@MINI2440]# md.b 0x0 20
00000000: 12 00 00 ea 14 f0 9f e5 14 f0 9f e5 14 f0 9f e5 ................
00000010: 14 f0 9f e5 14 f0 9f e5 14 f0 9f e5 14 f0 9f e5 ................
[u-boot@MINI2440]# md 0x0 20
00000000: ea000012 e59ff014 e59ff014 e59ff014 ................
00000010: e59ff014 e59ff014 e59ff014 e59ff014 ................
00000020: 33f80260 33f802c0 33f80320 33f80380 `..3...3 ..3...3
00000030: 33f803e0 33f80440 33f804a0 deadbeef ...3@..3...3....
00000040: 33f80000 33f80000 33fbe8dc 3400374c ...3...3...3L7.4
00000050: e10f0000 e3c0001f e38000d3 e129f000 ..............).
00000060: e3a00453 e3a01000 e5801000 e3e01000 S...............
00000070: e59f0488 e5801000 e59f1484 e59f0484 ................
但由於Nor Flash的燒寫時序和SDRAM的寫入不同,燒寫Nor Flash 不能使用mm等命令,只能使用cp命令從內存拷貝到Nor Flash,而且燒寫之前必須解除保護並擦除!命令如下:
protect :對Flash 寫保護的操作,可以使能和解除寫保護。
格式:
protect on/off start end
protect on/off start +end
protect on/off N:SF[-SL]
protect on/off bank N
protect on/off all
第1 個參數on 代表使能寫保護;off 代表解除寫保護。
第2 、3 參數是指定Flash 寫保護操作范圍
start end是照起始地址和結束地址定義范圍,start是擦除塊的起始地址;end 是擦除末尾塊的結束地址。
例如:擦除Sector 2和Sector 3區域命令為erase 20000 3ffff 。
start +end是照起始地址和操作字節數定義范圍,這種方式最常用。start是擦除塊的起始地址;end 是擦除的字節數。
例如:擦除Sector 2和Sector 3區域命令為erase 20000 +20000
N:SF[-SL]是按照組和扇區,N 表示Flash 的Block號,SF 表示擦除起始Sector號,SL 表示擦除結束Sector號。
例如:擦除Block1 的Sector 2和Sector 3區域命令為erase 1:2-3。
bank N是擦除整個Block,擦除Block號為N 的整個Flash。
all是擦除全部Flash。
注意:Nor Flash擦除的最小單位是Sector,也就是0x10000字節,如果你定義的大小不滿1 Sector或超過Sector的邊界,那么被定義到的Sector會被全部擦除。
erase :擦除Flash的命令
格式:
erase start end
erase start +end
erase N:SF[-SL]
erase bank N
erase all
參數是指定Flash 擦除操作范圍,跟寫保護的方式相同。
以下的范例將mini2440的Nor Flash的Sector 16寫保護,再解除保護,擦除數據,最后將起始的20字節拷貝到Sector 16。
[u-boot@MINI2440]# flinfo 1
Bank # 1: SST: 1x SST39VF1601 (2MB)
Size: 2 MB in 32 Sectors
Sector Start Addresses:
00000000 (RO) 00010000 (RO) 00020000 (RO) 00030000 (RO) 00040000
00050000 00060000 (RO) 00070000 (RO) 00080000 00090000
000A0000 000B0000 000C0000 000D0000 000E0000
000F0000 00100000 00110000 00120000 00130000
00140000 00150000 00160000 00170000 00180000
00190000 001A0000 001B0000 001C0000 001D0000
001E0000 001F0000
[u-boot@MINI2440]# protect on 1:16-16
Protect Flash Sectors 16-16 in Bank # 1
[u-boot@MINI2440]# flinfo 1
Bank # 1: SST: 1x SST39VF1601 (2MB)
Size: 2 MB in 32 Sectors
Sector Start Addresses:
00000000 (RO) 00010000 (RO) 00020000 (RO) 00030000 (RO) 00040000
00050000 00060000 (RO) 00070000 (RO) 00080000 00090000
000A0000 000B0000 000C0000 000D0000 000E0000
000F0000 00100000 (RO) 00110000 00120000 00130000
00140000 00150000 00160000 00170000 00180000
00190000 001A0000 001B0000 001C0000 001D0000
001E0000 001F0000
[u-boot@MINI2440]# protect off 0x100000 0x10ffff
Un-Protect Flash Sectors 16-16 in Bank # 1
[u-boot@MINI2440]# flinfo 1
Bank # 1: SST: 1x SST39VF1601 (2MB)
Size: 2 MB in 32 Sectors
Sector Start Addresses:
00000000 (RO) 00010000 (RO) 00020000 (RO) 00030000 (RO) 00040000
00050000 00060000 (RO) 00070000 (RO) 00080000 00090000
000A0000 000B0000 000C0000 000D0000 000E0000
000F0000 00100000 00110000 00120000 00130000
00140000 00150000 00160000 00170000 00180000
00190000 001A0000 001B0000 001C0000 001D0000
001E0000 001F0000
[u-boot@MINI2440]# erase 0x100000 +20
Erasing sector 16 ... ok.
Erased 1 sectors
[u-boot@MINI2440]# cp.b 0x0 0x100000 0x20
Copy to Flash... done
[u-boot@MINI2440]# md.b 100000 20
00100000: 12 00 00 ea 14 f0 9f e5 14 f0 9f e5 14 f0 9f e5 ................
00100010: 14 f0 9f e5 14 f0 9f e5 14 f0 9f e5 14 f0 9f e5 ................
****************************************SBL*************************************