norflash 燒寫
(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 ................
(8) USB 操作指令
指令
功能
usb reset 初始化USB控制器
usb stop [f] 關閉USB控制器
usb tree 已連接的USB設備樹
usb info [dev] 顯示USB設備[dev]的信息
usb storage 顯示已連接的USB存儲設備
usb dev [dev] 顯示和設置當前USB存儲設備
usb part [dev] 顯示USB存儲設備[dev]的分區信息
usb read addr blk# cnt 讀取USB存儲設備數據
在所有的命令使用前,必須先插入USB設備,然后使用:usb reset,以初始化USB控制器,獲取設備信息。
我將一個4G的kingstonU盤(可引導盤)插入 mini2440,然后讀取他的頭512 字節(MBR):
[u-boot@MINI2440]# usb reset
(Re)start USB...
USB: scanning bus for devices... 2 USB Device(s) found
scanning bus for storage devices... 1 Storage Device(s) found
[u-boot@MINI2440]# usb tree
Device Tree:
1 Hub (12 Mb/s, 0mA)
| OHCI Root Hub
|
+-2 Mass Storage (12 Mb/s, 100mA)
Kingston DT 101 II 0019E02CB6EB5B8B1B120051
[u-boot@MINI2440]# usb info
1: Hub, USB Revision 1.10
- OHCI Root Hub
- Class: Hub
- PacketSize: 8 Configurations: 1
- Vendor: 0x0000 Product 0x0000 Version 0.0
Configuration: 1
- Interfaces: 1 Self Powered 0mA
Interface: 0
- Alternate Setting 0, Endpoints: 1
- Class Hub
- Endpoint 1 In Interrupt MaxPacket 2 Interval 255ms
2: Mass Storage, USB Revision 2.0
- Kingston DT 101 II 0019E02CB6EB5B8B1B120051
- Class: (from Interface) Mass Storage
- PacketSize: 64 Configurations: 1
- Vendor: 0x0951 Product 0x1613 Version 1.0
Configuration: 1
- Interfaces: 1 Bus Powered 100mA
Interface: 0
- Alternate Setting 0, Endpoints: 2
- Class Mass Storage, Transp. SCSI, Bulk only
- Endpoint 1 In Bulk MaxPacket 64
- Endpoint 2 Out Bulk MaxPacket 64
[u-boot@MINI2440]# usb storage
Device 0: Vendor: Kingston Rev: PMAP Prod: DT 101 II
Type: Removable Hard Disk
Capacity: 3875.0 MB = 3.7 GB (7936000 x 512)
[u-boot@MINI2440]# usb dev 0
USB device 0:
Device 0: Vendor: Kingston Rev: PMAP Prod: DT 101 II
Type: Removable Hard Disk
Capacity: 3875.0 MB = 3.7 GB (7936000 x 512)
... is now current device
[u-boot@MINI2440]# usb part 0
print_part of 0
Partition Map for USB device 0 -- Partition Type: DOS
Partition Start Sector Num Sectors Type
4 63 7935937 c
[u-boot@MINI2440]# usb read 0x30008000 0 200
USB read: device 0 block # 0, count 512 ... .........................
512 blocks read: OK
[u-boot@MINI2440]# md.b 0x30008000 200
30008000: fa 31 c0 8e d8 8e c0 8e d0 bc 00 7c fb fc 89 e6
.1.........|....
30008010: bf 00 06 b9 00 01 f3 a5 ea dc 06 00 00 10 00 01
................
30008020: 00 00 7c 00 00 00 00 00 00 00 00 00 00 80 3f 00
..|...........?.
30008030: ff 00 ed 01 1e 0e 1f 3a 16 10 00 74 06 1f ea 36
.......:...t...6
30008040: e7 00 f0 3d fb 54 75 05 8c d8 fb eb 1d 80 fc 08
...=.Tu.........
30008050: 75 1b e8 81 00 8a 36 13 00 fe ce 8b 0e 15 00 86
u.....6.........
30008060: cd c0 e1 06 0a 0e 11 00 31 c0 f8 eb 65 80 fc 02
........1...e...
30008070: 72 cb 80 fc 04 77 c6 60 80 cc 40 50 be 00 00 c7
r....w.`..@P....
30008080: 04 10 00 30 e4 89 44 02 89 5c 04 8c 44 06 66 31
...0..D..\..D.f1
30008090: c0 66 89 44 0c 88 f0 f6 26 11 00 88 cf 88 eb c0
.f.D....&.......
300080a0: ef 06 81 e1 3f 00 01 c8 48 89 c7 a1 13 00 f7 26
....?...H......&
300080b0: 11 00 f7 e3 01 f8 81 d2 00 00 89 44 08 89 54 0a
...........D..T.
300080c0: 58 30 c0 8a 16 10 00 e8 0c 00 88 26 03 00 61 a1
X0.........&..a.
300080d0: 02 00 1f ca 02 00 9c ff 1e 22 00 c3 80 fa 8f 7f
........."......
300080e0: 04 88 16 2d 06 be 87 07 e8 8d 00 be be 07 31 c0
...-..........1.
300080f0: b9 04 00 f6 04 80 74 03 40 89 f5 81 c6 10 00 e2
......t.@.......
30008100: f2 48 74 02 cd 18 bf 05 00 be 1d 06 c7 44 02 01
.Ht..........D..
30008110: 00 66 8b 46 08 66 89 44 08 b8 00 42 8a 16 2d 06
.f.F.f.D...B..-.
30008120: cd 13 73 0d 4f 74 49 30 e4 8a 16 2d 06 cd 13 eb
..s.OtI0...-....
30008130: d8 a1 fe 7d 3d 55 aa 75 37 fa 66 a1 4c 00 66 a3
...}=U.u7.f.L.f.
30008140: 3f 06 be 13 04 8b 04 48 89 04 c1 e0 06 8e c0 31
?......H.......1
30008150: ff be 1d 06 b9 60 00 fc f3 a5 c7 06 4c 00 17 00
.....`......L...
30008160: a3 4e 00 fb 8a 16 2d 06 89 ee fa ea 00 7c 00 00
.N....-......|..
30008170: be aa 07 e8 02 00 eb fe ac 20 c0 74 09 b4 0e bb
......... .t....
30008180: 07 00 cd 10 eb f2 c3 53 74 61 72 74 20 62 6f 6f
.......Start boo
30008190: 74 69 6e 67 20 66 72 6f 6d 20 55 53 42 20 64 65
ting from USB de
300081a0: 76 69 63 65 2e 2e 2e 0d 0a 00 42 6f 6f 74 20 66
vice......Boot f
300081b0: 61 69 6c 65 64 00 00 00 ea eb d4 ca 00 00 00 00
ailed...........
300081c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
................
300081d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
................
300081e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 01
................
300081f0: 01 00 0c fe 7f ec 3f 00 00 00 c1 17 79 00 55 aa
......?.....y.U.
(9) SD卡(MMC)指令
SD卡的使用命令比較簡單,只有初始化和設備信息的顯示,讀寫是通過文件系統命令實現的。
mmc init [dev] - 初始化MMC子系統
mmc device [dev] - 查看和設置當前設備
使用和USB類似,在所有的命令使用前,必須先插入SD卡,然后使用:mmc init,以初始化MMC 控制器,獲取設備信息。
我在mini2440中插入1GB SD卡:
[u-boot@MINI2440]# mmc init
mmc: Probing for SDHC ...
mmc: SD 2.0 or later card found
trying to detect SD Card...
Manufacturer: 0x00, OEM "roduct name: "
", revision 0.0
Serial number:
7864775
Manufacturing date: 11/2006
CRC:
0x4f, b0 = 1
READ_BL_LEN=6, C_SIZE_MULT=7, C_SIZE=4095
size = 0
SD Card detected RCA: 0x2 type: SD
mmc1 is available
[u-boot@MINI2440]# mmc device
mmc1 is current device
(10) FAT文件系統指令
fatinfo:顯示文件系統的相關信息
格式:fatinfo <interface> <dev[:part]>
Interface:代表接口,如usb、mmc;
dev:代表設備編號,如0、1……;
part:代表存儲設備中的分區,如1、2……。
fatload:從FAT32文件系統中讀取二進制文件到SDRAM。
格式:fatload <interface> <dev[:part]> <addr> <filename> [bytes]
Interface、dev和part同上;
addr:代表寫入SDRAM的地址;
filename:代表存儲設備中的文件名;
bytes:代表從存儲設備中讀取的文件大小,可不填;如果填的數據比文件小,就只讀取bytes字節,如果填的數據比文件大,也只讀取文件的大小。
fatls:列出FAT32文件系統中目錄里的文件。
格式:fatls <interface> <dev[:part]> [directory]
Interface、dev和part同上;
directoryr:代表所要查看的目錄,可不填,默認為/。
這些指令基本上要和U盤或者SD卡同時使用,主要用於讀取這些移動存儲器上的FAT32分區。
使用范例:
[u-boot@MINI2440]# usb part 0
print_part of 0
Partition Map for USB device 0 -- Partition Type: DOS
Partition Start Sector Num Sectors Type
4 63 7935937 c
[u-boot@MINI2440]# fatinfo usb 0:4
Interface: USB
Device 0: Vendor: Kingston Rev: PMAP Prod: DT 101 II
Type: Removable Hard Disk
Capacity: 3875.0 MB = 3.7 GB (7936000 x 512)
Partition 4: Filesystem: FAT32 "7600_16385_"
[u-boot@MINI2440]# fatls usb 0:4
boot/
efi/
sources/
support/
upgrade/
43 autorun.inf
383562 bootmgr
111880 setup.exe
256220 u-boot.bin
4 file(s), 5 dir(s)
[u-boot@MINI2440]# fatls usb 0:4 /boot/
./
../
fonts/
zh-cn/
262144 bcd
3170304 boot.sdi
1024 bootfix.bin
97280 bootsect.exe
4096 etfsboot.com
485440 memtest.exe
6 file(s), 4 dir(s)
[u-boot@MINI2440]# fatload usb 0:4 0x30008000 u-boot.bin
reading u-boot.bin
........................
256220 bytes read
[u-boot@MINI2440]# fatload usb 0:4 0x30008000 u-boot.bin 200
reading u-boot.bin
512 bytes read
(11) 系統引導指令
boot 和bootd 都是運行ENV”bootcmd”中指定的指令。
bootm 指令是專門用於啟動在SDRAM中的用U-boot的mkimage工具處理過的內核映像。
格式:bootm [addr [arg ...]]
addr 是內核映像所在的SDRAM中的地址
當啟動的是Linux內核時,'arg' 可以使 initrd 的地址。
[u-boot@MINI2440]# setenv bootcmd tftp\;bootm
[u-boot@MINI2440]# saveenv
Saving Environment to NAND...
Erasing Nand...
Erasing at 0x6000000000002 -- 0% complete.
Writing to Nand... done
[u-boot@MINI2440]# boot
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)
## 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 2009.11 ( 4月 04 2010 - 12:09:25)
modified by tekkamanninja (tekkamanninja@163.com)
Love Linux
I2C: ready
DRAM: 64 MB
Flash: 2 MB
NAND: 128 MiB
Video: 240x320x16 20kHz 62Hz
In: serial
Out: serial
Err: serial
Net: dm9000
U-Boot 2009.11 ( 4月 04 2010 - 12:09:25)
modified by tekkamanninja
(tekkamanninja@163.com)
Love Linux
Hit any key to stop autoboot: 0
[u-boot@MINI2440]# bootd
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)
## 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 ...
(略)
12)EEPROM 讀寫指令eeprom - I2C 接口的EEPROM 讀寫指令
格式:
eeprom read addr off cnt
eeprom write addr off cnt
第一個參數addr 是要寫入或讀出的數據在SDRAM中的存放地址;
第二個參數off 是在EEPROM中的偏移;
第三個參數cnt 是讀寫的數據字節數。
使用范例:
[u-boot@MINI2440]# md.b 0x30008000 2
30008000: aa aa ..
[u-boot@MINI2440]# eeprom read 0x30008000 10 2
EEPROM @0x50 read: addr 30008000 off 0010 count 2 ... done
[u-boot@MINI2440]# md.b 0x30008000 2
30008000: ff ff ..
[u-boot@MINI2440]# mm.b 0x30008000
30008000: ff ? aa
30008001: ff ? 55
30008002: aa ? q
[u-boot@MINI2440]# md.b 0x30008000 2
30008000: aa 55 .U
[u-boot@MINI2440]# eeprom write 0x30008000 10 2
EEPROM @0x50 write: addr 30008000 off 0010 count 2 ... done
[u-boot@MINI2440]# eeprom read 0x30008010 10 2
EEPROM @0x50 read: addr 30008010 off 0010 count 2 ... done
[u-boot@MINI2440]# md.b 0x30008010 2
30008010: aa 55 .U
(13)設置和讀取RTC指令
date - 設置和讀取RTC
格式:
date [MMDDhhmm[[CC]YY][.ss]]
MM:月份
DD:日期
hh:小時
mm 分鍾
CC:年份的前兩個數字
YY:年份的后兩個數字
ss:秒數
使用范例:
[u-boot@MINI2440]# date
Date: 1980-00-06 (Thursday) Time: 20:30:25
[u-boot@MINI2440]# date 041100582010.20
Date: 2010-04-11 (Sunday) Time: 0:58:20
(14)腳本運行指令
run var [...]
var :ENV中的腳本名
使用范例:
[u-boot@MINI2440]# setenv a_run_test echo $bootfile \; version
[u-boot@MINI2440]# run a_run_test
zImage.img
U-Boot 2009.11 ( 4月 04 2010 - 12:09:25)
(15)系統重啟指令
reset
- 重啟CPU
[u-boot@MINI2440]# reset
resetting ...
U-Boot 2009.11 ( 4月 04 2010 - 12:09:25)
modified by tekkamanninja (tekkamanninja@163.com)
Love Linux
I2C: ready
DRAM: 64 MB
Flash: 2 MB
NAND: 128 MiB
Video: 240x320x16 20kHz 62Hz
In: serial
Out: serial
Err: serial
Net: dm9000
U-Boot 2009.11 ( 4月 04 2010 - 12:09:25)
modified by tekkamanninja
(tekkamanninja@163.com)
Love Linux
Hit any key to stop autoboot: 0
[u-boot@MINI2440]#
四、U-boot的使用(四)
下載與燒寫
使用U-boot將映像文件燒寫到板上的Flash,一般步驟是:
(1)通過網絡、串口、U盤、SD卡等方式將文件傳輸到SDRAM;
(2)使用Nand Flash或Nor Flash相關的讀寫命令將SDRAM中的數據燒入Flash。
下面是燒寫范例:
如果使用 SD卡和U盤形式更新U-boot,那么首先SD卡和U盤中必須有FAT32文件系統,並在里面存放了u-boot.bin 文件。
1) 通過SD卡燒入Nand Flash:
[u-boot@MINI2440]# mmc init
mmc: Probing for SDHC ...
mmc: SD 2.0 or later card found
trying to detect SD Card...
Manufacturer:
0x00, OEM "roduct name:
"
", revision 0.0
Serial number:
7864775
Manufacturing date: 11/2006
CRC:
0x4f, b0 = 1
READ_BL_LEN=6, C_SIZE_MULT=7, C_SIZE=4095
size = 0
SD Card detected RCA: 0x2 type: SD
mmc1 is available
[u-boot@MINI2440]# fatload mmc 1 0x30008000 u-boot.bin
reading u-boot.bin
256220 bytes read
[u-boot@MINI2440]# nand erase 0 0x40000
NAND erase: device 0 offset 0x0, size 0x40000
Erasing at 0x2000000000004 --
0% complete.
OK
[u-boot@MINI2440]# nand write 0x30008000 0 0x40000
NAND write: device 0 offset 0x0, size 0x40000
Writing at 0x2000000020000 -- 100% is complete. 262144 bytes written: OK
2) 通過U盤燒入Nor Flash:
[u-boot@MINI2440]# usb start
(Re)start USB...
USB:
scanning bus for devices... 2 USB Device(s) found
scanning bus for storage devices... 1 Storage Device(s) found
[u-boot@MINI2440]# usb storage
Device 0: Vendor: Kingston Rev: PMAP Prod: DT 101 II
Type: Removable Hard Disk
Capacity: 3875.0 MB = 3.7 GB (7936000 x 512)
[u-boot@MINI2440]# usb part 0
print_part of 0
Partition Map for USB device 0
--
Partition Type: DOS
Partition
Start Sector
Num Sectors
Type
4
63
7935937
c
[u-boot@MINI2440]# fatload usb 0:4 0x30008000 u-boot.bin
reading u-boot.bin
........................
256220 bytes read
[u-boot@MINI2440]# protect off all
Un-Protect Flash Bank # 1
[u-boot@MINI2440]# erase 0x0 0x3ffff
Erasing sector
0 ... ok.
Erasing sector
1 ... ok.
Erasing sector
2 ... ok.
Erasing sector
3 ... ok.
Erased 4 sectors
[u-boot@MINI2440]# cp.b 0x30008000 0x0
0x3ffff
Copy to Flash... done
3) 通過TFTP服務燒入Nand Flash:
[u-boot@MINI2440]# tftpboot 30008000 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
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 erase 0 0x40000
NAND erase: device 0 offset 0x0, size 0x40000
Erasing at 0x2000000000004 --
0% complete.
OK
[u-boot@MINI2440]# nand write 0x30008000 0 0x40000
NAND write: device 0 offset 0x0, size 0x40000
Writing at 0x2000000020000 -- 100% is complete. 262144 bytes written: OK
4) 通過NFS 服務燒入Nand Flash:
[u-boot@MINI2440]# nfs 30008000 192.168.1.100:/home/tekkaman/development/share/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
File transfer via NFS from server 192.168.1.100; our IP address is 192.168.1.101
Filename '/home/tekkaman/development/share/u-boot.bin'.
Load address: 0x30008000
Loading: ###################################################
done
Bytes transferred = 256220 (3e8dc hex)
[u-boot@MINI2440]# nand erase 0 0x40000
NAND erase: device 0 offset 0x0, size 0x40000
Erasing at 0x2000000000004 --
0% complete.
OK
[u-boot@MINI2440]# nand write 0x30008000 0 0x40000
NAND write: device 0 offset 0x0, size 0x40000
Writing at 0x2000000020000 -- 100% is complete. 262144 bytes written: OK
內核引導
內核的引導步驟如下:
(1)用U-boot的mkimage工具處理內核映像zImage。
(2)通過網絡、串口、U盤、SD卡等方式將處理過的內核映像傳輸到SDRAM的一定位置(一般使用0x30008000)
(3)然后使用”bootm"等內核引導命令來啟動內核。
為什么要用U-boot的mkimage工具處理內核映像zImage?
因為在用bootm命令引導內核的時候,bootm需要讀取一個64字節的文件頭,來獲取這個內核映象所針對的CPU體系結構、OS、加載到內存中的位置、在內存中入口點的位置以及映象名等等信息。這樣bootm才能為OS設置好啟動環境,並跳入內核映象的入口點。而mkimage就是添加這個文件頭的專用工具。具體的實現請看U-boot中bootm的源碼和mkimage的源碼。
mkimage工具的使用:
參數說明:
-A 指定CPU的體系結構,可用值有:alpha、arm
、x86、ia64、mips、mips64、ppc 、s390、sh、sparc 、sparc64、m68k等
-O 指定操作系統類型,可用值有:openbsd、netbsd、freebsd、4_4bsd、linux、svr4、esix、solaris、irix、sco、dell、ncr、lynxos、vxworks、psos、qnx、u-boot、rtems、artos
-T 指定映象類型,可用值有:standalone、kernel、ramdisk、multi、firmware、script、filesystem
-C 指定映象壓縮方式,可用值有:
none
不壓縮(一般使用這個,因為zImage是已經被bzip2壓縮過的自解壓內核)
gzip 用gzip的壓縮方式
bzip2 用bzip2的壓縮方式
-a 指定映象在內存中的加載地址,映象下載到內存中時,要按照用mkimage制作映象時,這個參數所指定的地址值來下載
-e
指定映象運行的入口點地址,這個地址就是-a參數指定的值加上0x40(因為前面有個mkimage添加的0x40個字節的頭)
-n
指定映象名
-d 指定制作映象的源文件
以下是制作內核映像的命令示例:
mkimage -n 'tekkaman' -A arm -O linux -T kernel -C none -a 0x30008000 -e 0x30008040 -d zImage zImage.img
以下是使用范例:
1) 通過SD卡引導內核:
首先SD卡中必須有FAT32文件系統,並在里面存放了處理過的內核映像文件。
[u-boot@MINI2440]# mmc init
mmc: Probing for SDHC ...
mmc: SD 2.0 or later card found
trying to detect SD Card...
Manufacturer:
0x00, OEM "roduct name:
"
", revision 0.0
Serial number:
7864775
Manufacturing date: 11/2006
CRC:
0x4f, b0 = 1
READ_BL_LEN=6, C_SIZE_MULT=7, C_SIZE=4095
size = 0
SD Card detected RCA: 0x2 type: SD
mmc1 is available
[u-boot@MINI2440]# fatload mmc 1 30008000 zImage.img
reading zImage.img
2277540 bytes read
[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
(略)
2) 通過TFTP服務引導內核:
[u-boot@MINI2440]# tftpboot 0x30008000 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]# 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
(略)
3) 通過NFS服務引導內核:
[u-boot@MINI2440]# nfs 30008000 192.168.1.100:/home/tekkaman/development/share/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
File transfer via NFS from server 192.168.1.100; our IP address is 192.168.1.101
Filename '/home/tekkaman/development/share/zImage.img'.
Load address: 0x30008000
Loading: #################################################################
done
Bytes transferred = 2277540 (22c0a4 hex)
[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
(略)
4) 通過Nand Flash引導內核:
首先要將處理過的內核映像文件燒入Nand Flash的一定位置(由內核分區表決定)。以后每次啟動時用Nand Flash的讀取命令先將這個內核映像文件讀到內存的一定位置(由制作內核映像時的-a參數決定),再使用bootm命令引導內核。
內核映像文件的燒入:
[u-boot@MINI2440]# nfs 30008000 192.168.1.100:/home/tekkaman/development/share/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
File transfer via NFS from server 192.168.1.100; our IP address is 192.168.1.101
Filename '/home/tekkaman/development/share/zImage.img'.
Load address: 0x30008000
Loading: #################################################################
done
Bytes transferred = 2277540 (22c0a4 hex)
[u-boot@MINI2440]# nand erase 0x80000 0x300000
NAND erase: device 0 offset 0x80000, size 0x300000
Erasing at 0x36000001800000 --
0% complete.
OK
[u-boot@MINI2440]#
nand write 30008000 0x80000 300000
NAND write: device 0 offset 0x80000, size 0x300000
Writing at 0x36000000020000 -- 100% is complete. 3145728 bytes written: OK
內核引導:
[u-boot@MINI2440]#
nand read 30008000 0x80000 300000
NAND read: device 0 offset 0x80000, size 0x300000
3145728 bytes read: OK
[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