四、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 "Product 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-bootmkimage工具處理內核映像zImage?

因爲在用bootm命令引導內核的時候,bootm需要讀取一個64字節的文件頭,來獲取這個內核映象所針對的CPU體系結構、OS、加載到內存中的位置、在內存中入口點的位置以及映象名等等信息。這樣bootm才能爲OS設置好啓動環境,並跳入內核映象的入口點。而mkimage就是添加這個文件頭的專用工具。具體的實現請看U-bootbootm的源碼和mkimage的源碼。

mkimage工具的使用:

 

參數說明:

-A 指定CPU的體系結構,可用值有:alphaarm x86ia64mipsmips64ppc s390shsparc sparc64m68k

-O 指定操作系統類型,可用值有:openbsdnetbsdfreebsd4_4bsdlinuxsvr4esixsolarisirixscodellncrlynxosvxworkspsosqnxu-bootrtemsartos

-T 指定映象類型,可用值有:standalonekernelramdiskmultifirmwarescriptfilesystem

-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 "Product 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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章