2011年12月13日 星期二

[mkimage] mkimage - description


mkimage使用詳解 (-a    c參數指定的位址異同的差別)



uboot源代碼的tools/目錄下有mkimage工具,這個工具可以用來製作不壓縮或者壓縮的多種可啟動映像檔案。



mkimage在製作映像檔案的時候,是在原來的可執行映像檔案的前面加上一個0x40位元組的頭,記錄參數所指定的訊息,這樣uboot才能識別這個映像是針對哪個CPU體系架構的,哪個OS的,哪種類型,加載內存中的哪個位置,入口點在內存的那個位置以及映像名是什麼



root@Glym:/tftpboot# ./mkimage

Usage: ./mkimage -l image

-l ==> list image header information

./mkimage -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image

-A ==> set architecture to 'arch'

-O ==> set operating system to 'os'

-T ==> set image type to 'type'

-C ==> set compression type 'comp'

-a ==> set load address to 'addr' (hex)

-e ==> set entry point to 'ep' (hex)

-n ==> set image name to 'name'

-d ==> use image data from 'datafile'

-x ==> set XIP (execute in place)

參數說明︰



-A 指定CPU的體系架構︰



取值 表示的體系架構

alpha Alpha

arm A RM

x86 Intel x86

ia64 IA64

mips MIPS

mips64 MIPS 64 Bit

ppc PowerPC

s390 IBM S390

sh SuperH

sparc SPARC

sparc64 SPARC 64 Bit

m68k MC68000



-O
指定作業系統類型,可以取以下值︰

openbsdnetbsdfreebsd4_4bsdlinuxsvr4esixsolarisirixscodellncrlynxosvxworkspsosqnxu-bootrtemsartos



-T
指定映像類型,可以取以下值︰


standalonekernelramdiskmultifirmwarescriptfilesystem



-C
指定映像壓縮模式,可以取以下值︰


none 不壓縮

gzip gzip的壓縮模式

bzip2 bzip2的壓縮模式



-a 指定映像在內存中的加載位址,映像下載到內存中時,要按照用mkimage製作映像時,這個參數所指定的位址值來下載



-e 指定映像營運的入口點位址,這個位址就是-a參數指定的值加上0x40(因為前面有個mkimage添加的0x40個位元組的頭)



-n 指定映像名



-d 指定製作映像的源檔案





U-BOOT下使用bootm引導內核方法







一、在開始之前先說明一下bootm相關的東西。



1、 首先說明一下,S 3C 2410架構下的bootm只對sdram中的內核鏡像檔案進行操作(好像AT91架構提供了一段從flash複製內核鏡像的代碼,不過針對s 3c 2410架構就沒有這段代碼,雖然可以在u-boot下添加這段代碼,不過好像這個用處不大),所以請確保你的內核鏡像下載到sdram 中,或者在bootcmd下把flash中的內核鏡像複製到sdram中。



2-a參數後是內核的營運位址,-e參數後是入口位址。



3

1)如果我們沒用mkimage對內核進行處理的話,那直接把內核下載到0x30008000再營運就行,內核會自解壓營運(不過內核營運需要一個tag來傳遞參數,而這個tag建議是由bootloader提供的,在u-boot下預設是由bootm命令建立的)。

2)如果使用mkimage生成內核鏡像檔案的話,會在內核的前頭加上了64byte的訊息,供建立tag之用。bootm命令會首先判斷bootm xxxx 這個指定的位址xxxx是否與-a指定的加載位址相同。

(1)如果不同的話會從這個位址開始提取出這個64byte的頭部,對其進行分析,然後把去掉頭部的內核複製到-a指定的load位址中去營運之

(2)如果相同的話那就讓其原封不同的放在那,但-e指定的入口位址會推後64byte,以跳過這64byte的頭部。





二、好,接著介紹使用mkimage生成鏡像檔案並下載營運的方法。



方法一、

1、首先,用u-boot/tools/mkimage這個工具為你的內核加上u-boot引導所需要的檔案頭,具體做法如下︰

[root@localhost tftpboot]#mkimage -n 'linux- 2.6.14 ' -A arm -O linux -T kernel -C none -a 0x30008000 -e 0x30008000 -d zImage zImage.img

Image Name: linux-2.6.14

Created: Fri Jan 12 17:14:50 2007

Image Type: ARM Linux Kernel Image (uncompressed)

Data Size: 1262504 Bytes = 1232.91 kB = 1.20 MB

Load Address: 0x30008000

Entry Point: 0x30008000



這裡解釋一下參數的意義︰

-A ==> set architecture to 'arch'

-O ==> set operating system to 'os'

-T ==> set image type to 'type'

-C ==> set compression type 'comp'

-a ==> set load address to 'addr' (hex)

-e ==> set entry point to 'ep' (hex)

-n ==> set image name to 'name'

-d ==> use image data from 'datafile'

-x ==> set XIP (execute in place)



2
、下載內核


U-Boot 1.1.3 (Jan 12 2007 - 16:16:36)



U-Boot code: 33F 80000 -> 33F 9BAC0 BSS: -> 33F 9FBAC

RAM Configuration:

Bank #0: 30000000 64 MB

Nor Flash: 512 kB

Nand Flash: 64 MB

In: serial

Out: serial

Err: serial

Hit any key to stop autoboot: 0

sbc2410=>tftp 0x31000000 zImage.img

TFTP from server 192.168.1.115; our IP address is 192.168.1.128

Filename 'zImage.img'.

Load address: 0x31000000

Loading: #################################################################

#################################################################

#################################################################

####################################################

done

Bytes transferred = 1263324 (1346dc hex)



3.
營運



sbc2410=>bootm 0x31000000

## Booting image at 31000000 ...

Image Name: linun-2.6.14

Image Type: ARM Linux Kernel Image (uncompressed)

Data Size: 1263260 Bytes = 1.2 MB

Load Address: 30008000

Entry Point: 30008000

Verifying Checksum ... OK

OK



Starting kernel ...



Uncompressing Linux.............................................................Linux version 2.6.14 (root@luofuchong) (gcc version 3.4.1) #21 Fri Oct 20 17:206CPU: ARM920Tid(wb) [41129200] revision 0 (ARMv4T)

Machine: SMDK2410

Memory policy: ECC disabled, Data cache writeback

CPU S 3C 2410A (id 0x32410002)

S 3C 2410: core 202.800 MHz, memory 101.400 MHz, peripheral 50.700 MHz

S 3C 2410 Clocks, (c) 2004 Simtec Electronics

CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on

USB Control, (c) 2006 sbc2410

CPU0: D VIVT write-back cache

CPU0: I cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets

CPU0: D cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets

Built 1 zonelists

Kernel command line: console=ttySAC0 root=/dev/nfs nfsroot=192.168.1.115:/frien"irq: clearing subpending status 00000002

PID hash table entries: 512 (order: 9, 8192 bytes)

timer tcon=00500000, tcnt a509, tcfg 00000200,00000000, usec 00001e 4c

Console: colour dummy device 80x30

Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)

Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)

Memory: 64MB = 64MB total

Memory: 62208KB available (1924K code, 529K data, 108K init)

Mount-cache hash table entries: 512

CPU: Testing write buffer coherency: ok

softlockup thread 0 started up.

NET: Registered protocol family 16

S 3C 2410: Initialising architecture

SCSI subsystem initialized

usbcore: registered new driver usbfs

usbcore: registered new driver hub

S 3C 2410 DMA Driver, (c) 2003-2004 Simtec Electronics

DMA channel 0 at c4800000, irq 33

DMA channel 1 at c4800040, irq 34

DMA channel 2 at c4800080, irq 35

DMA channel 3 at c 48000c 0, irq 36

NetWinder Floating Point Emulator V0.97 (double precision)

devfs: 2004-01-31 Richard Gooch (rgooch@atnf.csiro.au)

devfs: devfs_debug: 0x0

devfs: boot_options: 0x1

yaffs Oct 18 2006 12:39:51 Installing.

Console: switching to colour frame buffer device 30x40

fb0: s 3c 2410fb frame buffer device

fb1: Virtual frame buffer device, using 1024K of video memory

led driver initialized

s 3c 2410 buttons successfully loaded

s 3c 2410_serial0 at MMIO 0x50000000 (irq = 70) is a S 3C 2410

s 3c 2410_serial1 at MMIO 0x50004000 (irq = 73) is a S 3C 2410

s 3c 2410_serial2 at MMIO 0x50008000 (irq = 76) is a S 3C 2410

io scheduler noop registered

io scheduler anticipatory registered

io scheduler deadline registered

io scheduler cfq registered

RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize

usbcore: registered new driver ub

Cirrus Logic CS 8900A driver for Linux (Modified for SMDK2410)

eth0: CS 8900A rev E at 0xe0000300 irq=53, no eeprom , addr: 08: 0:3E:26: 0A :5B

S 3C 24XX NAND Driver, (c) 2004 Simtec Electronics

s 3c 2410-nand: mapped registers at c4980000

s 3c 2410-nand: timing: Tacls 10ns, Twrph0 30ns, Twrph1 10ns

NAND device: Manufacturer ID: 0xec, Chip ID: 0x76 (Samsung NAND 64MiB 3,3V 8-bi)Scanning device for bad blocks

Bad eraseblock 1884 at 0x01d70000

Creating 4 MTD partitions on "NAND 64MiB 3,3V 8-bit":

0x00000000-0x00020000 : "vivi"

0x00020000-0x00030000 : "param"

0x00030000-0x00200000 : "kernel"

0x00200000-0x04000000 : "root"

usbmon: debugfs is not available

s 3c 2410-ohci s 3c 2410-ohci: S 3C 24XX OHCI

s 3c 2410-ohci s 3c 2410-ohci: new USB bus registered, assigned bus number 1

s 3c 2410-ohci s 3c 2410-ohci: irq 42, io mem 0x49000000

hub 1-0:1.0: USB hub found

hub 1-0:1.0: 2 ports detected

Initializing USB Mass Storage driver...

usbcore: registered new driver usb-storage

USB Mass Storage support registered.

usbcore: registered new driver usbmouse

drivers/usb/input/usbmouse.c: v1.6:USB HID Boot Protocol mouse driver

mice: PS/2 mouse device common for all mice

s 3c 2410 TouchScreen successfully loaded

UDA1341 audio driver initialized

NET: Registered protocol family 2

IP route cache hash table entries: 1024 (order: 0, 4096 bytes)

TCP established hash table entries: 4096 (order: 2, 16384 bytes)

TCP bind hash table entries: 4096 (order: 2, 16384 bytes)

TCP: Hash tables configured (established 4096 bind 4096)

TCP reno registered

TCP bic registered

NET: Registered protocol family 1

IP-Config: Complete:

device=eth0, addr=192.168.1.128, mask=255.255.255.0, gw=192.168.1.1,

host=luofuchong, domain=, nis-domain=(none),

bootserver=192.168.1.1, rootserver=192.168.1.115, rootpath=

Looking up port of RPC 100003/2 on 192.168.1.115

Looking up port of RPC 100005/1 on 192.168.1.115

VFS: Mounted root (nfs filesystem).

Mounted devfs on /dev

Freeing init memory: 108K

init started: BusyBox v1.1.3 (2006.09.20-14:52+0000) multi-call binary

Starting pid 696, console /dev/tts/0: '/etc/init.d/rcS'



Please press Enter to activate this console.







方法二、


1、首先,用u-boot/tools/mkimage這個工具為你的內核加上u-boot引導所需要的檔案頭,具體做法如下︰

[root@localhost tftpboot]#mkimage -n 'linux-2.6.14' -A arm -O linux -T kernel -C none -a 0x30008000 -e 0x30008040 -d zImage zImage.img

Image Name: linux-2.6.14

Created: Fri Jan 12 17:14:50 2007

Image Type: ARM Linux Kernel Image (uncompressed)

Data Size: 1262504 Bytes = 1232.91 kB = 1.20 MB

Load Address: 0x30008000

Entry Point: 0x30008040





2
、下載內核

U-Boot 1.1.3 (Jan 12 2007 - 16:16:36)



U-Boot code: 33F 80000 -> 33F 9BAC0 BSS: -> 33F 9FBAC

RAM Configuration:

Bank #0: 30000000 64 MB

Nor Flash: 512 kB

Nand Flash: 64 MB

In: serial

Out: serial

Err: serial

Hit any key to stop autoboot: 0

sbc2410=>tftp 0x30008000 zImage.img

TFTP from server 192.168.1.115; our IP address is 192.168.1.128

Filename 'zImage.img'.

Load address: 0x30008000

Loading: #################################################################

#################################################################

#################################################################

####################################################

done

Bytes transferred = 1263324 (1346dc hex)



3.
營運




sbc2410=>bootm 0x30008000

## Booting image at 30008000 ...

Image Name: linux-2.6.14

Image Type: ARM Linux Kernel Image (uncompressed)

Data Size: 1261056 Bytes = 1.2 MB

Load Address: 30008000

Entry Point: 30008040

Verifying Checksum ... OK

XIP Kernel Image ... OK





內核啟動訊息省。。。。 



轉自:http://bbs.61job.cn/showtopic-540.aspx

       
http://www.wretch.cc/blog/poemsoul/15441093

0 意見:

張貼留言