mkimage製作linux內核映像 即uImage是怎麼製作的

轉自http://blog.chinaunix.net/uid-26318500-id-3327170.html

也可參考http://blog.sina.com.cn/s/blog_67a84df50100q72v.html

bootm命令是用來引導經過u-boot的工具mkimage打包後的kernel image的,什麼叫做經過u-boot的工具mkimage打包後的kernel image,這個就要看mkimage的代碼,看看它做了些什麼,雖然我很希望大家不要偷懶,認真地去看看,但是我知道還是有很多人懶得去做這件,那麼我就j將分析mkimage代碼後得到的總結告訴大家,mkimage做了些什麼,怎麼用這個工具。

mkimage的用法
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 ARM
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 指定操作系統類型,可以取以下值:
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 不壓縮
gzip 用gzip的壓縮方式
bzip2 用bzip2的壓縮方式

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

-e 指定映象運行的入口點地址,這個地址就是-a參數指定的值加上0x40(因爲前面有個mkimage添加的0x40個字節的頭)

-n 指定映象名

-d 指定製作映象的源文件

mkimage

   解壓內核源碼包,編輯Makefile
   設置 cross_compile:=[編譯器的絕對路徑]     ;這個絕對路徑既上面2.95.3放到的路徑
   進入內核文件夾,執行下面命令
   [root@hostname]# make clean
   [root@hostname]# make dep
   [root@hostname]# make
   [root@hostname]# [編譯器的絕對路徑]/bin/arm-linux-objcopy -O binary -S vmlinux linux.bin    ;編譯器的絕對路徑也是上面說到的路徑
    [root@hostname]# gzip linux.bin
下面的比較重要了,主要是u-boot的安裝,這個在H9200的手冊上說的很不清楚
    [root@hostname]# tar xzvf u-boot-1.0.0.tar.gz      ;解壓u-boot
    [root@hostname]# cd u-boot-1.0.0
    [root@hostname]# make distclean
    [root@hostname]# make at91rm9200dk_config
    [root@hostname]# make all
    然後在/usr/local下建立uboot文件夾將u-boot-1.0.0下的所有文件都複製到uboot下
    [root@hostname]# [uboot的絕對路徑]/tools/mkimage -A arm -O linux -C gzip -a 0x20008000 -e 0x20008000 -d linux.bin.gz uImage           ;這裏的絕對路徑是/usr/local/uboot

vmlinux linux.bin linux.bin.gz uImage(uboot製作的image)

mkimage -a -e

-a參數後是內核的運行地址,-e參數後是入口地址。

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的頭部。


QUESTIONS

1. I have built a vmlinux image but I can boot it.

2: The mkimage tool, ARMboot's tftp command, and the bootm command require
   certain load and entry addresses. I'm confused which ones to chose.


ANSWERS

1. I have built a vmlinux image but I can boot it.
--------------------------------------------------

ARMboot is designed to boot Images as created by the mkimage tool, that
comes with ARMboot and is automatically built, too. You cannot directly load
the vmlinux image, as it expects a number of prerequisits such as special
register contents etc.

2. The mkimage tool, ARMboot's tftp command, and the bootm command require
   certain load and entry addresses. I'm confused which ones to chose.
--------------------------------------------------------------------------

Well, there are 3 different addresses:

1. Kernel Load Address. This is the address, where the kernel was linked
   to when you built the vmlinux and can be found in arch/arm/Makefile.
   The default for it is:
   
   ifeq ($(CONFIG_CPU_32),y)
   PROCESSOR    = armv
   TEXTADDR     = 0xC0008000
   LDSCRIPT     = arch/arm/vmlinux-armv.lds.in
   endif
   
   Provide this as "-a" parameter to mkimage.

2. Kernel Entry Point. This is the address, where ARMboot jumps to to
   enter the Kernel. It usually is the same as the kernel load address.

   Provide this as "-e" parameter to mkimage.

3. The Network Download Address. This is where you download the mkimage
   File. This address MUST BE different to the Kernel Load Address, and
   should be sufficiently far away to allow ARMboot to relocate the 
   image to the final Kernel Load Address. Loading to the 5th MB
   within the RAM is usually a good idea, eg. if the RAM begins at
   0xc0000000, you can do this:
   
   LART # tftp c0400000 linux.img
   ARP broadcast 1
   eth addr: 00:02:03:04:05:06
   TFTP from server 192.168.1.1; our IP address is 192.168.1.2
   Filename 'image.img'.
   Load address: 0xc0400000
   Loading: 
   ##################################################################done
   Bytes transferred = 567252 (8a7d4 hex)
   LART # bootm c0400000
      Image Name:   Linux 2.4.18
      Created:      Mon Jun 24 12:00:01 2002
      Image Type:   ARM Linux Kernel Image (gzip compressed)
      Data Size:    567188 Bytes = 553 kB = 0 MB
      Load Address: 0xc0008000
      Entry Point: 0xc0008000
      Verifying Checksum ... OK
      Loading Kernel Image ... OK

   Starting kernel ...
   Linux version 2.4.18 (mag@mag) (gcc version 2.95.3 20010315 (release)) #4 Mon Jun 17 20:35:32 CST 2002


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