[Author: Bo Shen <[email protected]>]
[Linux kernel: 3.13-rc6, ]
前面文章讲解了zImage的生成过程(http://blog.csdn.net/voice_shen/article/details/17713441),其要依赖于<arch/arm/boot/compressed/vmlinux>。下面详细讲解<arch/arm/boot/compressed/vmlinux>生成过程。
51 $(obj)/compressed/vmlinux: $(obj)/Image FORCE 52 $(Q)$(MAKE) $(build)=$(obj)/compressed $@由51行可知,<arch/arm/compressed/vmlinux>的生成需要依赖于Image。后面给出分析。
其52行的$(Q)表示什么意思呢?查看Linux根目录下面的Makefile可知:
300 # If KBUILD_VERBOSE equals 0 then the above command will be hidden. 301 # If KBUILD_VERBOSE equals 1 then the above command is displayed. 302 303 ifeq ($(KBUILD_VERBOSE),1) 304 quiet = 305 Q = 306 else 307 quiet=quiet_ 308 Q = @ 309 endif由303~309行可知,Q的取值由KBUILD_VERBOSE是否为1决定。那么KBUILD_VERBOSE在什么情况下等于1呢?
44 # To put more focus on warnings, be less verbose as default 45 # Use 'make V=1' to see the full commands 46 47 ifeq ("$(origin V)", "command line") 48 KBUILD_VERBOSE = $(V) 49 endif 50 ifndef KBUILD_VERBOSE 51 KBUILD_VERBOSE = 0 52 endif由上面代码可知,KBUILD_VERBOSE在执行命令"make V=1"的时候取值为1。
分析完Q的值后,就可以知道编译生成<arch/arm/boot/compressed/vmlinux>的过程了。其就是进入<arch/arm/boot/compressed>目录后执行: make vmlinux。 下面进入到<arch/arm/boot/compressed>目录下查看Makefile文件。
179 $(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/$(HEAD) $(obj)/piggy.$(suffix_y).o \ 180 $(addprefix $(obj)/, $(OBJS)) $(lib1funcs) $(ashldi3) FORCE 181 @$(check_for_multiple_zreladdr) 182 $(call if_changed,ld) 183 @$(check_for_bad_syms)根据vmlinux.lds,将这些文件链接在一起生成最后的vmlinux文件。
vmlinux.lds文件的生成:
195 $(obj)/vmlinux.lds: $(obj)/vmlinux.lds.in arch/arm/boot/Makefile $(KCONFIG_CONFIG) 196 @sed "$(SEDFLAGS)" < $< > $@
84 SEDFLAGS = s/TEXT_START/$(ZTEXTADDR)/;s/BSS_START/$(ZBSSADDR)/从上面的代码可知,vmlinux.lds文件是把vmlinux.lds.in文件中的TEXT_START换成$(ZTEXTADDR), BSS_START换成$(ZBSSADDR)后得到。对于ARM来说,ZTEXTADDR=0, ZBSSADDR=ALIGN(8)。
185 $(obj)/piggy.$(suffix_y): $(obj)/../Image FORCE 186 $(call if_changed,$(suffix_y)) 187 188 $(obj)/piggy.$(suffix_y).o: $(obj)/piggy.$(suffix_y) FORCE
因为编译Linux kernel选择了gzip,所以suffix_y=gzip。在185~186,对上一层目录的Image文件进行gzip压缩。
86 suffix_$(CONFIG_KERNEL_GZIP) = gzip 87 suffix_$(CONFIG_KERNEL_LZO) = lzo 88 suffix_$(CONFIG_KERNEL_LZMA) = lzma 89 suffix_$(CONFIG_KERNEL_XZ) = xzkern 90 suffix_$(CONFIG_KERNEL_LZ4) = lz4
OBJS如下:
25 HEAD = head.o 26 OBJS += misc.o decompress.o 27 ifeq ($(CONFIG_DEBUG_UNCOMPRESS),y) 28 OBJS += debug.o 29 endif 33 OBJS += string.o