Chinaunix首页 | 论坛 | 博客
  • 博客访问: 451776
  • 博文数量: 72
  • 博客积分: 3186
  • 博客等级: 中校
  • 技术积分: 1039
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-07 16:53
文章分类

全部博文(72)

文章存档

2012年(1)

2011年(5)

2010年(10)

2009年(56)

我的朋友

分类: LINUX

2010-01-15 18:49:38

编译内核后使其直接生成uImage,要观察生成过程,使用了如下命令编译:
make O=/tmp/test V=1 uImage > make.log
编译后在/tmp/test下生成了vmlinux

$ ls -sh vmlinux
2.5M vmlinux         -------生成的vmlinux 为 2.5M
$ ls -sh arch/arm/boot/
总用量 3.6M
4.0K compressed  1.8M Image  908K uImage  908K zImage
                     -------生成的uImage与zImage差不多大小,猜想内核编译时生成的
                            uImage是由zImage生成的。
$ ll arch/arm/boot/
总用量 3656
drwxr-xr-x 2 linux linux    4096 2010-01-15 16:10 compressed
-rwxr-xr-x 1 linux linux 1880568 2010-01-15 16:10 Image
-rw-r--r-- 1 linux linux  926308 2010-01-15 16:10 uImage
-rwxr-xr-x 1 linux linux  926244 2010-01-15 16:10 zImage
                    -------可以看到uImage比zImage正好大64个字节,即头信息大小

[linux@ test]$ ls -sh vmlinux
2.5M vmlinux         ---------顶层下的vmlinux 2.5M
[linux@ test]$ ls -sh arch/arm/boot/compressed/vmlinux
920K arch/arm/boot/compressed/vmlinux
                     ---------arch/arm/boot/compressed下的vmlinux 920K

查看make.log下记录的信息,其中有如下几行

/usr/local/arm/4.3.3/bin/arm-none-linux-gnueabi-ld -EL -p --no-undefined -X -o vmlinux -T arch/arm/kernel/vmlinux.lds arch/arm/kernel/head.o arch/arm/kernel/init_task.o init/built-in.o --start-group usr/built-in.o arch/arm/kernel/built-in.o arch/arm/mm/built-in.o arch/arm/common/built-in.o arch/arm/mach-s3c2410/built-in.o arch/arm/mach-s3c2400/built-in.o arch/arm/mach-s3c2412/built-in.o arch/arm/mach-s3c2440/built-in.o arch/arm/mach-s3c2442/built-in.o arch/arm/mach-s3c2443/built-in.o arch/arm/plat-s3c24xx/built-in.o kernel/built-in.o mm/built-in.o fs/built-in.o ipc/built-in.o security/built-in.o crypto/built-in.o block/built-in.o arch/arm/lib/lib.a lib/lib.a arch/arm/lib/built-in.o lib/built-in.o drivers/built-in.o sound/built-in.o net/built-in.o --end-group


            ============0. 生成顶层下的vmlinux  

/usr/local/arm/4.3.3/bin/arm-none-linux-gnueabi-objcopy -O binary -R .note -R .comment -S  vmlinux arch/arm/boot/Image
            ============1. 生成Image二进制文件,未压缩的

  gzip -f -9 < arch/arm/boot/compressed/../Image > arch/arm/boot/compressed/piggy.gz
            ===========2. arch/arm/boot/compressed/目录下 压缩../Image,得到piggy.gz

/usr/local/arm/4.3.3/bin/arm-none-linux-gnueabi-gcc -Wp,-MD,arch/arm/boot/compressed/.head.o.d -nostdinc -isystem /usr/local/arm/4.3.3/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3/include -D__KERNEL__ -Iinclude -Iinclude2 -I/home/linux/test/kernel/linux-2.6.22.6/include -include include/linux/autoconf.h -mlittle-endian -D__ASSEMBLY__ -mabi=aapcs-linux -mno-thumb-interwork -D__LINUX_ARM_ARCH__=4 -march=armv4t -mtune=arm9tdmi -msoft-float -c -o arch/arm/boot/compressed/head.o /home/linux/test/kernel/linux-2.6.22.6/arch/arm/boot/compressed/head.S


            ===========3.arch/arm/boot/compressed目录下 head.S 编译生成 head.o

/usr/local/arm/4.3.3/bin/arm-none-linux-gnueabi-gcc -Wp,-MD,arch/arm/boot/compressed/.piggy.o.d -nostdinc -isystem /usr/local/arm/4.3.3/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3/include -D__KERNEL__ -Iinclude -Iinclude2 -I/home/linux/test/kernel/linux-2.6.22.6/include -include include/linux/autoconf.h -mlittle-endian -D__ASSEMBLY__ -mabi=aapcs-linux -mno-thumb-interwork -D__LINUX_ARM_ARCH__=4 -march=armv4t -mtune=arm9tdmi -msoft-float -c -o arch/arm/boot/compressed/piggy.o /home/linux/test/kernel/linux-2.6.22.6/arch/arm/boot/compressed/piggy.S


            ==============4. arch/arm/boot/compressed/目录下 piggy.S生成 piggy.o
来看下arch/arm/boot/compressed/piggy.S中的内容

    .section .piggydata,#alloc
    .globl    input_data
input_data:
    .incbin    "arch/arm/boot/compressed/piggy.gz"
    .globl    input_data_end
input_data_end:

可见其中 .incbin  "arch/arm/boot/compressed/piggy.gz" 这一句是有玄机的,as中解释.incbin如下
7.60 .incbin "file "[,skip [,count ]]
The incbin directive includes file verbatim at the current location. You can control the
search paths used with the ‘-I’ command-line option (see Chapter 2 [Command-Line Op-
tions], page 17). Quotation marks are required around file.
   The skip argument skips a number of bytes from the start of the file. The count argument
indicates the maximum number of bytes to read. Note that the data is not aligned in any
way, so it is the user’s responsibility to make sure that proper alignment is provided both
before and after the incbin directive.
 
$ ll piggy.*
-rw-r--r-- 1 linux linux 912587 2010-01-15 16:10 piggy.gz
-rw-r--r-- 1 linux linux 913270 2010-01-15 16:10 piggy.o
piggy.o比piggy.gz大了一点

综上,piggy.gz => piggy.o

/usr/local/arm/4.3.3/bin/arm-none-linux-gnueabi-gcc -Wp,-MD,arch/arm/boot/compressed/.misc.o.d -nostdinc -isystem /usr/local/arm/4.3.3/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3/include -D__KERNEL__ -Iinclude -Iinclude2 -I/home/linux/test/kernel/linux-2.6.22.6/include -include include/linux/autoconf.h -mlittle-endian -I/home/linux/test/kernel/linux-2.6.22.6/arch/arm/boot/compressed -Iarch/arm/boot/compressed -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -O2 -marm -fno-omit-frame-pointer -mapcs -mno-sched-prolog -mabi=aapcs-linux -mno-thumb-interwork -D__LINUX_ARM_ARCH__=4 -march=armv4t -mtune=arm9tdmi -msoft-float -Uarm -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-stack-protector -Wdeclaration-after-statement -Wno-pointer-sign -fpic -Dstatic= -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(misc)" -D"KBUILD_MODNAME=KBUILD_STR(misc)" -c -o arch/arm/boot/compressed/misc.o /home/linux/test/kernel/linux-2.6.22.6/arch/arm/boot/compressed/misc.c

         
             ==============5. arch/arm/boot/compressed/目录下 misc.c 生成 misc.o


/usr/local/arm/4.3.3/bin/arm-none-linux-gnueabi-ld -EL --defsym zreladdr=0x30008000 --defsym params_phys=0x30000100 -p --no-undefined -X /usr/local/arm/4.3.3/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.3/armv4t/libgcc.a -T arch/arm/boot/compressed/vmlinux.lds arch/arm/boot/compressed/head.o arch/arm/boot/compressed/piggy.o arch/arm/boot/compressed/misc.o -o arch/arm/boot/compressed/vmlinux


             ===========6. 生成arch/arm/boot/compressed/vmlinux
                 --no-undefined通常创建一个非符号共享库时,无定义的符号允许出现,
                               并留待运行时连接器去解决,这个选项关闭无定义符号的使用
                 -X 删除所有的临时本地符号
            这里将compressed目录下的head.o链在最前,(还要链接其他如libggc.a中的函数)

                                                    head.o + piggy.o + misc.o => vmlinux  (这一行都在arch/arm/boot/compressed/目录下)
       objcopy                                  gzip            |
vmlinux ---> arch/arm/boot/Image --------> piggy.gz

  /usr/local/arm/4.3.3/bin/arm-none-linux-gnueabi-objcopy -O binary -R .note -R .comment -S  arch/arm/boot/compressed/vmlinux arch/arm/boot/zImage
             ======生成zImage
  Kernel: arch/arm/boot/zImage is ready
  /bin/sh /home/linux/test/kernel/linux-2.6.22.6/scripts/mkuboot.sh -A arm -O linux -T kernel -C none -a 0x30008000 -e 0x30008000 -n 'Linux-2.6.22.6' -d arch/arm/boot/zImage arch/arm/boot/uImage
Image Name:   Linux-2.6.22.6
Created:      Fri Jan 15 16:10:12 2010
Image Type:   ARM Linux Kernel Image (uncompressed)
Data Size:    926244 Bytes = 904.54 kB = 0.88 MB
Load Address: 30008000
Entry Point:  30008000
             ========将zImage用mkimage工具制作成uImage
  Image arch/arm/boot/uImage is ready


总而言之,内核中直接“make uImage”,制作出来的uImage虽然压缩类型为none,但实际上它还是一个已压缩的内核,只不过被压缩的数据不是由uboot来解压的,而是由内核自己解压的(zImage里加入的解压的代码)

最后再制作一张图,理清这中间的关系



阅读(11553) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~