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

字体大小: 中小 标准 ->行高大小: 标准
Linux内核编译完成后会生成zImage内核镜像文件。zImage是如何解压的呢?本文将结合关键代码,讲解zImage的解压过程。还是先来看看zImage的组成吧。在内核编译完成后会在arch/arm/boot/下生成zImage。 

在arch/arm/boot/Makefile中,如下代码:

[plain]
  1. #   # arch/arm/boot/Makefile  
  2. #   # This file is included by the global makefile so that you can add your own  
  3. # architecture-specific flags and dependencies.   #  
  4. # This file is subject to the terms and conditions of the GNU General Public   # License.  See the file "COPYING" in the main directory of this archive  
  5. # for more details.   #  
  6. # Copyright (C) 1995-2002 Russell King   #  
  7.    MKIMAGE         := $(srctree)/scripts/mkuboot.sh  
  8.    ifneq ($(MACHINE),)  
  9. include $(srctree)/$(MACHINE)/Makefile.boot   endif  
  10.    # Note: the following conditions must always be true:  
  11. #   ZRELADDR == virt_to_phys(PAGE_OFFSET + TEXT_OFFSET)   #   PARAMS_PHYS must be within 4MB of ZRELADDR  
  12. #   INITRD_PHYS must be in RAM   ZRELADDR    := $(zreladdr-y)  
  13. PARAMS_PHYS := $(params_phys-y)   INITRD_PHYS := $(initrd_phys-y)  
  14.    export ZRELADDR INITRD_PHYS PARAMS_PHYS  
  15.    targets := Image zImage xipImage bootpImage uImage  
  16.    ifeq ($(CONFIG_XIP_KERNEL),y)  
  17.    $(obj)/xipImage: vmlinux FORCE  
  18.     $(call if_changed,objcopy)       @echo '  Kernel: $@ is ready (physical address: $(CONFIG_XIP_PHYS_ADDR))'  
  19.    $(obj)/Image $(obj)/zImage: FORCE  
  20.     @echo 'Kernel configured for XIP (CONFIG_XIP_KERNEL=y)'       @echo 'Only the xipImage target is available in this case'  
  21.     @false     
  22. else     
  23. $(obj)/xipImage: FORCE       @echo 'Kernel not configured for XIP (CONFIG_XIP_KERNEL!=y)'  
  24.     @false     
  25. $(obj)/Image: vmlinux FORCE       $(call if_changed,objcopy)  
  26.     @echo '  Kernel: $@ is ready'     
  27. $(obj)/compressed/vmlinux: $(obj)/Image FORCE       $(Q)$(MAKE) $(build)=$(obj)/compressed $@  
  28.    $(obj)/zImage:  $(obj)/compressed/vmlinux FORCE  
  29.     $(call if_changed,objcopy)       @echo '  Kernel: $@ is ready'  
  30.    endif  
  31.    quiet_cmd_uimage = UIMAGE  $@  
  32.       cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A arm -O linux -T kernel \              -C none -a $(LOADADDR) -e $(STARTADDR) \  
  33.            -n 'Linux-$(KERNELRELEASE)' -d {1}lt; $@     
  34. ifeq ($(CONFIG_ZBOOT_ROM),y)   $(obj)/uImage: LOADADDR=$(CONFIG_ZBOOT_ROM_TEXT)  
  35. else   $(obj)/uImage: LOADADDR=$(ZRELADDR)  
  36. endif     
  37. $(obj)/uImage: STARTADDR=$(LOADADDR)     
  38. $(obj)/uImage:  $(obj)/zImage FORCE       $(call if_changed,uimage)  
  39.     @echo '  Image $@ is ready'     
  40. $(obj)/bootp/bootp: $(obj)/zImage initrd FORCE       $(Q)$(MAKE) $(build)=$(obj)/bootp $@  
  41.     @:     
  42. $(obj)/bootpImage: $(obj)/bootp/bootp FORCE       $(call if_changed,objcopy)  
  43.     @echo '  Kernel: $@ is ready'     
  44. PHONY += initrd FORCE   initrd:  
  45.     @test "$(INITRD_PHYS)" != "" || \       (echo This machine does not support INITRD; exit -1)  
  46.     @test "$(INITRD)" != "" || \       (echo You must specify INITRD; exit -1)  
  47.    install: $(obj)/Image  
  48.     $(CONFIG_SHELL) $(srctree)/$(src)/install.sh $(KERNELRELEASE) \       $(obj)/Image System.map "$(INSTALL_PATH)"  
  49.    zinstall: $(obj)/zImage  
  50.     $(CONFIG_SHELL) $(srctree)/$(src)/install.sh $(KERNELRELEASE) \       $(obj)/zImage System.map "$(INSTALL_PATH)"  
  51.    zi:  
  52.     $(CONFIG_SHELL) $(srctree)/$(src)/install.sh $(KERNELRELEASE) \       $(obj)/zImage System.map "$(INSTALL_PATH)"  
  53.    i:  
  54.     $(CONFIG_SHELL) $(srctree)/$(src)/install.sh $(KERNELRELEASE) \       $(obj)/Image System.map "$(INSTALL_PATH)"  
  55.    subdir-     := bootp compressed  

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/57683.html