本文介绍几种常用的Linux内核映像的区别。
一、vmlinux
vmlinux:Linux内核编译出来的原始的内核文件,elf格式,未做压缩处理。
该映像可用于定位内核问题,但不能直接引导Linux系统启动。
使用readelf命令查看RockPI 4A单板Linux内核编译的vmlinux,内容如下:
- root@ubuntu:/home/run/code/rockchip-bsp/kernel# readelf -h vmlinux
- ELF Header:
- Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
- Class: ELF64
- Data: 2's complement, little endian
- Version: 1 (current)
- OS/ABI: UNIX - System V
- ABI Version: 0
- Type: EXEC (Executable file)
- Machine: AArch64 ## 64位系统
- Version: 0x1
- Entry point address: 0xffffff8008080000
- Start of program headers: 64 (bytes into file)
- Start of section headers: 264512168 (bytes into file)
- Flags: 0x0
- Size of this header: 64 (bytes)
- Size of program headers: 56 (bytes)
- Number of program headers: 4
- Size of section headers: 64 (bytes)
- Number of section headers: 36
- Section header string table index: 35
二、Image
Image:Linux内核编译时,使用objcopy处理vmlinux后生成的二进制内核映像。
该映像未压缩,可直接引导Linux系统启动。
RockPI 4A单板Linux内核编译vmlinux和Image过程如下:
- root@ubuntu:/home/run/code/rockchip-bsp# ./build/mk-kernel.sh rockpi4a
- Building kernel for rockpi4a board!
- 4.4.154 ## 4.4.154内核
- ...
- LINK vmlinux
- LD vmlinux.o
- MODPOST vmlinux.o
- GEN .version
- CHK include/generated/compile.h
- UPD include/generated/compile.h
- CC init/version.o
- LD init/built-in.o
- KSYM .tmp_kallsyms1.o
- KSYM .tmp_kallsyms2.o
- LD vmlinux
- SORTEX vmlinux
- SYSMAP System.map
- OBJCOPY arch/arm64/boot/Image ## 使用objcopy命令将vmlinux变为Image映像
objcopy命令的用法后续介绍。
三、zImage
zImage:使用gzip压缩Image后,使用objcopy命令生成的Linux内核映像。
该映像一般作为uboot的引导映像文件。uboot引导命令后续介绍。
四、uImage
uImage:在zImage前面增加一个64字节的头,描述映像文件类型,加载位置,大小等信息。
该映像是老版本uboot专用的引导映像。
下图是基于imx6 处理器Linux内核编译出的zImage和uImage的差异,区别如下:
zImage和uImage的差异
imx6单板Linux内核编译zImage和uImage过程如下:
- root@ubuntu:/home/run/code/imx6/linux-3.0.35# ./mk_kernel.sh
- arch/arm/configs/imx6_defconfig:1629:warning: override: reassigning to symbol SND_SOC_IMX_WM8962
- ...
- LD vmlinux ## 1.制作vmlinux
- SYSMAP System.map
- SYSMAP .tmp_System.map
- OBJCOPY arch/arm/boot/Image ## 2.使用objcopy命令生成Image
- Kernel: arch/arm/boot/Image is ready
- GZIP arch/arm/boot/compressed/piggy.gzip ## 3.压缩
- AS arch/arm/boot/compressed/piggy.gzip.o
- SHIPPED arch/arm/boot/compressed/lib1funcs.S
- AS arch/arm/boot/compressed/lib1funcs.o
- LD arch/arm/boot/compressed/vmlinux
- OBJCOPY arch/arm/boot/zImage ## 4.使用objcopy命令生成zImage
- Kernel: arch/arm/boot/zImage is ready
- UIMAGE arch/arm/boot/uImage ## 5.使用mkimage命令生成uImage
- Image Name: Linux-3.0.35-2666-gbdde708-g5083
- Created: Sun May 2 08:38:41 2021
- Image Type: ARM Linux Kernel Image (uncompressed)
- Data Size: 3250684 Bytes = 3174.50 kB = 3.10 MB
- Load Address: 0x10008000
- Entry Point: 0x10008000
- Image arch/arm/boot/uImage is ready
下图展示了不同类型的Linux映像生成过程。
Linux映像生成过程
注:zImage和uImage用于32位内核。