基于Linux2.6.38.8内核zImage文件的自解压详解(2)

我们将上面的部分内容抓取出来,独立来分析,这样就不会被其它的代码干扰到,见下面的代码:

$(obj)/Image: vmlinux FORCE
$(call if_changed,objcopy)
@echo '  Kernel: $@ is ready'

$(obj)/zImage:$(obj)/compressed/vmlinux FORCE
$(call if_changed,objcopy)
@echo '  Kernel: $@ is ready'

由此可见,zImage是由arch/arm/boot/compressed/vmlinux二进制化得到的,与此同时在arch/armboot/compressed/Makefile中:
$(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/$(HEAD) $(obj)/piggy.$(suffix_y).o \
$(addprefix $(obj)/, $(OBJS)) $(lib1funcs) FORCE
$(call if_changed,ld)
@:

$(obj)/piggy.$(suffix_y): $(obj)/../Image FORCE
$(call if_changed,$(suffix_y))

$(obj)/piggy.$(suffix_y).o:  $(obj)/piggy.$(suffix_y) FORCE

其中Image是由内核顶层目录下的vmlinux二进制化后得到的[见上面蓝色加粗部分代码],其中在arch/armboot/compressed/Makefile链接选项中有个 –fpic参数:
EXTRA_CFLAGS  := -fpic -fno-builtin
EXTRA_AFLAGS  := -Wa,-march=all

总结一下zImage的组成,它是由一个压缩后的内核piggy.o,连接上一段初始化及解压功能的代码(head.o misc.o),组成的。见下面的代码:

[plain]

#   # linux/arch/arm/boot/compressed/Makefile   #   # create a compressed vmlinuz image from the original vmlinux   #   ......................   ......................   #   # We now have a PIC decompressor implementation.  Decompressors running   # from RAM should not define ZTEXTADDR.  Decompressors running directly   # from ROM or Flash must define ZTEXTADDR (preferably via the config)   # FIXME: Previous assignment to ztextaddr-y is lost here. See SHARK   ifeq ($(CONFIG_ZBOOT_ROM),y)   ZTEXTADDR   := $(CONFIG_ZBOOT_ROM_TEXT)   ZBSSADDR    := $(CONFIG_ZBOOT_ROM_BSS)   else   ZTEXTADDR   := 0   ZBSSADDR    := ALIGN(8)   endif      SEDFLAGS    = s/TEXT_START/$(ZTEXTADDR)/;s/BSS_START/$(ZBSSADDR)/      suffix_$(CONFIG_KERNEL_GZIP) = gzip   suffix_$(CONFIG_KERNEL_LZO)  = lzo   suffix_$(CONFIG_KERNEL_LZMA) = lzma      targets       := vmlinux vmlinux.lds \            piggy.$(suffix_y) piggy.$(suffix_y).o \            font.o font.c head.o misc.o $(OBJS)      # Make sure files are removed during clean   extra-y       += piggy.gzip piggy.lzo piggy.lzma lib1funcs.S  

targets       := vmlinux vmlinux.lds \
piggy.$(suffix_y) piggy.$(suffix_y).o \
font.o font.c head.o misc.o $(OBJS)

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/22525.html