歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 基於Linux2.6.38.8內核zImage文件的自解壓詳解

基於Linux2.6.38.8內核zImage文件的自解壓詳解

日期:2017/2/28 15:56:14   编辑:Linux教程
Linux內核編譯完成後會生成zImage內核鏡像文件。zImage是如何解壓的呢?本文將結合關鍵代碼,講解zImage的解壓過程。還是先來看看zImage的組成吧。在內核編譯完成後會在arch/arm/boot/下生成zImage。

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

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