5. 内核初始化
5.1 合成内核镜像过程:
$ make ARCH=arm CROSS_COMPILE=arm-linux- V=1 zImage
编译的最后打印:
.....
OBJCOPY arch/arm/boot/Image
Kernel: arch/arm/boot/Image is ready
GZIP arch/arm/boot/compressed/piggy.gz
AS arch/arm/boot/compressed/piggy.o
LD arch/arm/boot/compressed/vmlinux
OBJCOPY arch/arm/boot/zImage
Kernel: arch/arm/boot/zImage is ready
1. 将ELF格式的内核文件vmlinux转换成二进制内核文件Image:OBJCOPY arch/arm/boot/Image
arm-linux-objcopy -O binary -R .note -R .comment -S vmlinux arch/arm/boot/Image
2. 汇编arch/arm/boot/compressed/head.S生成:head.o
arm-linux-gcc -Wp,-MD,arch/arm/boot/compressed/.head.o.d -nostdinc -isystem
/work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5/include
-D__KERNEL__ -Iinclude -include include/linux/autoconf.h
-mlittle-endian -D__ASSEMBLY__ -mapcs-32 -mno-thumb-interwork -D__LINUX_ARM_ARCH__=4 -march=armv4t -mtune=arm9tdmi -msoft-float
-c -o arch/arm/boot/compressed/head.o // 目标文件
arch/arm/boot/compressed/head.S // 源文件
3. 将二进制内核文件Image经过gzip压缩成:piggy.gz
gzip -f -9 < arch/arm/boot/compressed/../Image > arch/arm/boot/compressed/piggy.gz
4. piggy.gz包含在piggy.S文件中,汇编器通过汇编piggy.S来生成piggy.o
arm-linux-gcc -Wp,-MD,arch/arm/boot/compressed/.piggy.o.d -nostdinc -isystem
/work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5/include
-D__KERNEL__ -Iinclude -include include/linux/autoconf.h
-mlittle-endian -D__ASSEMBLY__ -mapcs-32 -mno-thumb-interwork -D__LINUX_ARM_ARCH__=4 -march=armv4t -mtune=arm9tdmi -msoft-float
-c -o arch/arm/boot/compressed/piggy.o // 目标文件
arch/arm/boot/compressed/piggy.S // 源文件
5. misc.c编译成misc.o,里面带有解压缩内核镜像的函数
arm-linux-gcc -Wp,-MD,
.......
-c -o arch/arm/boot/compressed/misc.o // 目标文件
arch/arm/boot/compressed/misc.c // 源文件
6. 将二进制目标文件:head.o, misc.o, misc.o,根据链接文件vmlinux.lds生成二进制内核镜像vmlinux
arm-linux-ld -EL --defsym zreladdr=0x30008000 --defsym params_phys=0x30000100 -p --no-undefined -X
/work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5/libgcc.a
-T arch/arm/boot/compressed/vmlinux.lds
arch/arm/boot/compressed/head.o
arch/arm/boot/compressed/piggy.o
arch/arm/boot/compressed/misc.o
-o arch/arm/boot/compressed/vmlinux
7. 将二进制内核镜像vmlinux最终合成内核镜像zImage,可以用引导加载程序进行加载。
arm-linux-objcopy -O binary -R .note -R .comment
-S arch/arm/boot/compressed/vmlinux
arch/arm/boot/zImage
总结编译过程:
1. 生成一个ELF格式的内核镜像vmlinux
2. 压缩ELF格式的镜像vmlinux,并加入可以解压缩的文件,合成为一个自带解压缩功能的压缩的二进制镜像vmlinux
3. 将该二进制镜像vmlinux转换成可以被引导程序加载的内核镜像。
5.1.1 Image对象
Image是将内核主体(vmlinux)从ELF格式转换为二进制格式,并除去了调试信息等等。
5.1.2 与具体架构相关的对象
阅读(1006) | 评论(0) | 转发(0) |