linux内存管理 (三) 1 内核镜像

要分析的文件
=============
  vmlinux
  arch/arm/boot/Image
  --------------------------上面的为无压缩,下面的为压缩版
  arch/arm/boot/compressed/piggy.gzip
  arch/arm/boot/compressed/vmlinux
  arch/arm/boot/zImage
  arch/arm/boot/uImage

  vmlinuz // 不对应实体文件,是一个概念集合,其实现包括zImage
  arch/xxx/boot/vmlinux.bin // 和 Image 一样,纯二进制文件

生成过程
=============
  LD      vmlinux
  OBJCOPY arch/arm/boot/Image
  GZIP    arch/arm/boot/compressed/piggy.gzip
  LD      arch/arm/boot/compressed/vmlinux
  OBJCOPY arch/arm/boot/zImage
  UIMAGE  arch/arm/boot/uImage

文件格式和生成过程
=============
  vmlinux: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, BuildID[sha1]=3a0278f4e626cd58ef56496dd843b5b17d78aca6, not stripped
  cmd_vmlinux := arm-linux-ld -EL  -p --no-undefined -X --build-id -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-s3c64xx/built-in.o  arch/arm/plat-samsung/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  firmware/built-in.o  net/built-in.o --end-group .tmp_kallsyms2.o
  =================
  arch/arm/boot/Image: data
  cmd_arch/arm/boot/Image := arm-linux-objcopy -O binary -R .comment -S  vmlinux arch/arm/boot/Image
  =================
  arch/arm/boot/compressed/piggy.gzip: gzip compressed data, from Unix, max compression
  cmd_arch/arm/boot/compressed/piggy.gzip := (cat arch/arm/boot/compressed/../Image | gzip -n -f -9 > arch/arm/boot/compressed/piggy.gzip) || (rm -f arch/arm/boot/compressed/piggy.gzip ; false)
  =================
  arch/arm/boot/compressed/vmlinux: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, not stripped
  cmd_arch/arm/boot/compressed/vmlinux := arm-linux-ld -EL    --defsym zreladdr=0x50008000 -p --no-undefined -X -T arch/arm/boot/compressed/vmlinux.lds arch/arm/boot/compressed/head.o arch/arm/boot/compressed/piggy.gzip.o arch/arm/boot/compressed/misc.o arch/arm/boot/compressed/decompress.o arch/arm/boot/compressed/lib1funcs.o -o arch/arm/boot/compressed/vmlinux 
  =================
  arch/arm/boot/zImage: Linux kernel ARM boot executable zImage (little-endian)
  cmd_arch/arm/boot/zImage := arm-linux-objcopy -O binary -R .comment -S  arch/arm/boot/compressed/vmlinux arch/arm/boot/zImage
  =================
  linux-Polaris_release/arch/gpt/boot/vmlinux.bin: data
  cmd_arch/gpt/boot/vmlinux.bin := /opt/gp8300/buildroot_envir/host/bin/gpt-objcopy -O binary -R .note -R .note.gnu.build-id -R .comment -S  vmlinux arch/gpt/boot/vmlinux.bin

生成过程详解
======================
  1. vmlinux

  cmd_vmlinux := arm-linux-ld -EL  -p --no-undefined -X --build-id -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-s3c64xx/built-in.o  arch/arm/plat-samsung/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  firmware/built-in.o  net/built-in.o --end-group .tmp_kallsyms2.o


  2. arch/arm/boot/Image

  cmd_arch/arm/boot/Image := arm-linux-objcopy -O binary -R .comment -S  vmlinux arch/arm/boot/Image

  3. arch/arm/boot/compressed/piggy.gzip
  cmd_arch/arm/boot/compressed/piggy.gzip := (cat arch/arm/boot/compressed/../Image | gzip -n -f -9 > arch/arm/boot/compressed/piggy.gzip) || (rm -f arch/arm/boot/compressed/piggy.gzip ; false)

  4. arch/arm/boot/compressed/piggy.gzip.o
  cmd_arch/arm/boot/compressed/piggy.gzip.o := arm-linux-gcc -Wp,-MD,arch/arm/boot/compressed/.piggy.gzip.o.d  -nostdinc -isystem /home/suweishuai/bin/tools/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/include -I/home/suweishuai/learn/linux/linux-3.0.1/ok6410/linux-3.0.1/arch/arm/include -Iarch/arm/include/generated -Iinclude  -include include/generated/autoconf.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-s3c64xx/include -Iarch/arm/plat-samsung/include -D__ASSEMBLY__ -mabi=aapcs-linux -mno-thumb-interwork -funwind-tables  -D__LINUX_ARM_ARCH__=6 -march=armv6 -mtune=arm1136j-s -include asm/unified.h -msoft-float -gdwarf-2    -Wa,-march=all     -c -o arch/arm/boot/compressed/piggy.gzip.o arch/arm/boot/compressed/piggy.gzip.S

  5. arch/arm/boot/compressed/vmlinux
  cmd_arch/arm/boot/compressed/vmlinux := arm-linux-ld -EL    --defsym zreladdr=0x50008000 -p --no-undefined -X -T arch/arm/boot/compressed/vmlinux.lds arch/arm/boot/compressed/head.o arch/arm/boot/compressed/piggy.gzip.o arch/arm/boot/compressed/misc.o arch/arm/boot/compressed/decompress.o arch/arm/boot/compressed/lib1funcs.o -o arch/arm/boot/compressed/vmlinux 

  6. arch/arm/boot/zImage: Linux kernel ARM boot executable zImage (little-endian)
  cmd_arch/arm/boot/zImage := arm-linux-objcopy -O binary -R .comment -S  arch/arm/boot/compressed/vmlinux arch/arm/boot/zImage


  不详细过程解析
    整个过程只有 3->4 的时候不是很明了
    $ cat arch/arm/boot/compressed/piggy.gzip.S 
            .section .piggydata,#alloc
            .globl  input_data
    input_data:
            .incbin "arch/arm/boot/compressed/piggy.gzip"
            .globl  input_data_end
    input_data_end:


  7. vmlinuz
    不对应任何文件,是一个统称
      对应 zImage 和 bzImage

    vmlinuz[1] 的建立有两种方式。
    一
      是编译内核时通过“make zImage”创建,然后通过:
      “cp /usr/src/linux-2.4/arch/i386/linux/boot/zImage /boot/vmlinuz”产生。zImage适用于小内核的情况,它的存在是为了向后的兼容性。
    二
      是内核编译时通过命令make bzImage创建,然后通过:“cp /usr/src/linux-2.4/arch/i386/linux/boot/bzImage /boot/vmlinuz”产生。bzImage是压缩的内核映像,需要注意,bzImage不是用bzip2压缩的,bzImage中的bz容易引起误解,bz表示“big zImage”。 bzImage中的b是“big”意思。

   
    内核文件中包含一个微型的gzip用于解压缩内核并引导它。
    两者的不同之处在于,老的zImage解压缩内核到低端内存(第一个640K), bzImage解压缩内核到高端内存(1M以上)。
    如果内核比较小,那么可以采用zImage 或bzImage之一,两种方式引导的系统运行时是相同的。
    大的内核采用bzImage,不能采用zImage。
    vmlinux是未压缩的内核,vmlinuz是vmlinux的压缩文件。
    vmlinux-2.4.20-8是未压缩内核,vmlinuz-2.4.20-8是vmlinux-2.4.20-8的压缩文件。


    可以通过 
    $ rpm -qf /boot/vmlinuz-3.10.0-327.el7.x86_64 
    kernel-3.10.0-327.el7.x86_64

    验证
  8. vmlinux.bin
    cmd_arch/gpt/boot/vmlinux.bin := /opt/gp8300/buildroot_envir/host/bin/gpt-objcopy -O binary -R .note -R .note.gnu.build-id -R .comment -S  vmlinux arch/gpt/boot/vmlinux.bin



图解过程
  xxx -LD-> vmlinux  -OBJCOPY->   Image  -GZIP->    piggy.gzip     -AS-> piggy.gzip.o -LD> vmlinux -> zImage -> uImage
  												   piggy.gzip.S _| 

参考
	https://blog.csdn.net/manchestermi/article/details/48025913

文件大小比较
-rwxr-xr-x 1 suweishuai ic 85M Jul 30 13:55 vmlinux
-rwxr-xr-x 1 suweishuai ic 8.3M Jul 30 13:55 arch/arm/boot/Image
-rw-r--r-- 1 suweishuai ic 4.0M Jul 30 13:56 arch/arm/boot/compressed/piggy.gzip
-rwxr-xr-x 1 suweishuai ic 4.0M Jul 30 13:56 arch/arm/boot/compressed/vmlinux
-rwxr-xr-x 1 suweishuai ic 4.0M Jul 30 13:56 arch/arm/boot/zImage
应用场景:
	需要解压
		嵌入式中一般用的是 uImage ,zImage , 直接写到 非易失性存储器上,不包括文件系统
		桌面一般用的是 zImage ,bzImage , 名字为 vmlinuz ,/boot 目录
	不需要解压
		还有 用 Image , 直接放到 /boot 目录
	解压与不解压的区别
		uboot打印的最后一句是Starting kernel ... 
		解压的话内核会打印 Uncompressing Linux..... done, booting the kernel,然后打印Booting Linux on physical CPU
		不解压的话内核不会打印这句话,直接打印Booting Linux on physical CPU
  • 需要关注的知识点
解压过程
	Uncompressing Linux..... done, booting the kernel 卡死问题
	arch/arm/boot/compressed 下的 decompress.c  head.S  lib1funcs.S  misc.c  piggy.gzip.S
解压后入口问题
	arch/arm/kernel 下的 head.S
	搬运
		解压后会搬运
		不解压有可能搬运
	不搬运

你可能感兴趣的:(Linux内存管理)