uImage生成过程

 

当编译linux的时候,运行make uImage,如果一切正常,最后会生成uImage。

如下具体讲解uImage生成过程:

1. 生成uImag的工具mkimage由arch/arm/boot/Makefile中的MKIMAGE定义

[c-sharp] view plain copy print ?
  1. MKIMAGE         := $(srctree)/scripts/mkuboot.sh 
MKIMAGE := $(srctree)/scripts/mkuboot.sh

mkuboot.sh的作用是去找到是否存在"mkimage",此工具是用来生成最后的uImage。

  mkuboot.sh 首先检查toolchain是否拥有mkimage (使用-z来判空),如果没有,再检查系统中是否拥有mkimage;如果没有则报错。

:其中使用type命令来查找。

        type: Display information about command type  (type [-afptP] name [name ...])

       ==> # type mkimage

      ==> mkimage is /usr/bin/mkimage

2. 从makefile.boot中传入生成uImage的相关参数(e.g: arm/arm/mach-at91/Makefile.boot)

[c-sharp] view plain copy print ?
  1. ifneq ($(MACHINE),) 
  2. include $(srctree)/$(MACHINE)/Makefile.boot 
  3. endif 
ifneq ($(MACHINE),) include $(srctree)/$(MACHINE)/Makefile.boot endif

3.  通过mkimage来生成uImage,其过程是加上0x40 bytes 的kernel头

[c-sharp] view plain copy print ?
  1. quiet_cmd_uimage = UIMAGE  $@ 
  2.       cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A arm -O linux -T kernel / 
  3.            -C none -a $(LOADADDR) -e $(STARTADDR) / 
  4.            -n 'Linux-$(KERNELRELEASE)' -d $< $@ 
quiet_cmd_uimage = UIMAGE $@ cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A arm -O linux -T kernel / -C none -a $(LOADADDR) -e $(STARTADDR) / -n 'Linux-$(KERNELRELEASE)' -d $< $@

mkimage的参数如下:

[c-sharp] view plain copy print ?
  1. Usage: mkimage -l image 
  2.           -l ==> list image header information 
  3.        mkimage [-x] -A arch -O os -T type -C comp -a addr -e ep -n name -d data_file[:data_file...] image 
  4.           -A ==> set architecture to 'arch' 
  5.           -O ==> set operating system to 'os' 
  6.           -T ==> set image type to 'type' 
  7.           -C ==> set compression type 'comp' 
  8.           -a ==> set load address to 'addr' (hex) 
  9.           -e ==> set entry point to 'ep' (hex) 
  10.           -n ==> set image name to 'name' 
  11.           -d ==> use image data from 'datafile' 
  12.           -x ==> set XIP (execute in place) 
Usage: mkimage -l image -l ==> list image header information mkimage [-x] -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)

Load address 由下面代码获得

[c-sharp] view plain copy print ?
  1. ifeq ($(CONFIG_ZBOOT_ROM),y) 
  2. $(obj)/uImage: LOADADDR=$(CONFIG_ZBOOT_ROM_TEXT) 
  3. else 
  4. $(obj)/uImage: LOADADDR=$(ZRELADDR) 
  5. endif 
ifeq ($(CONFIG_ZBOOT_ROM),y) $(obj)/uImage: LOADADDR=$(CONFIG_ZBOOT_ROM_TEXT) else $(obj)/uImage: LOADADDR=$(ZRELADDR) endif

start address 由下面代码获得

[c-sharp] view plain copy print ?
  1. $(obj)/uImage: STARTADDR=$(LOADADDR) 
$(obj)/uImage: STARTADDR=$(LOADADDR)

由zImage生成uImage:

[c-sharp] view plain copy print ?
  1. $(obj)/uImage:  $(obj)/zImage FORCE 
  2.     $(call if_changed,uimage) 
  3.     @echo '  Image $@ is ready' 
$(obj)/uImage: $(obj)/zImage FORCE $(call if_changed,uimage) @echo ' Image $@ is ready'

也可以自行用mkimage来生成uImage,

  mkimage -A arm -O linux -T kernel -C none -a -e -n -d zImage uImage

e.g : mkimage -A arm -O linux -T kernel -C none -a 0x70008000 -e 0x70008000 -n linux-2.6.30 -d zImage uImage

其中:0x8000这32K 空间是Note that the kernel uses 16K of RAM below the image to store page tables.  The recommended placement is 32KiB into RAM. (来自Documentation/arm/booting文件)

 

文章转自:http://blog.csdn.net/voice_shen/article/details/6559752

你可能感兴趣的:(linux内核分析)