一、内核目录结构:
linux-2.6.22.6$ ls
arch COPYING drivers ipc MAINTAINERS net(网路协议) security vmlinux block[块设备访问的通用接口] CREDITS fs (nfs, cramfs, jiffs2/ubifs, vfat,procfs, sysfs) Kbuild Makefile README sound vmlinux.dis compile_log.txt crypto include kernel(调度,fork,exit等 ) mm REPORTING-BUGS System.map config Documentation init (初始化相关,LINUX内核的第一个C函数,init/main.c[start_kernel()]) lib Module.symvers scripts usr
黄色:与CPU无关
红色: 与CPU和体系结构相关
|
二、内核重要的配置菜单
三、内核镜像zImage 的生成过程
相关知识:
1、uImage 和 zImage 的组成:uImage = zImage+64B header
uImage 64字节头部 | arch/arm/boot/compressed/head.S misc.c | piggy.gz |
从下面链接脚本可以看出内核的最基本的镜像vmlinux的生产过程,该连接过程最值得关注的就是这一阶段的链接脚本/arch/arm/kernel/vmlinux.lds
arm-linux-gnu-ld -EL -p --no-undefined -X -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 ……
zImage是一个可以直接加载到内存中运行的镜像,或者最终可以固化到Flash上,通常包括了压缩版得基本内核映像,解压缩代码和重定位代码。这里值得关注的也有一个链接脚本。-T arch/arm/boot/compressed/vmlinux.lds.
zImage 生成过程详解:
(1)由arm-linux-gnu-ld -EL -p --no-undefined -X -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 ……
知道内核最基本映像是由一系列.o文件连接而成。此时在更目录下,大小为33MB左右;
(2)将上面的基本linux内核映像vmlinux,执行命令:arm-linux-gnu-objcopy -O binary -R .note -R .comment -S vmlinux arch/arm/boot/Image(去除调试信息、注释、符号表等内容,-R 表示去除)生成arch/arm/boot/Image,大小约为3.6MB左右;
(3)对arch/arm/boot/Image 执行命令:gzip -f -9 < arch/arm/boot/compressed/../Image > arch/arm/boot/compressed/piggy.gz(用gzip -9 压缩生成arch/arm/boot/compressed/piggy.gz ),大小为1.8M左右;
(4)编译arch/arm/boot/compressed/piggy.S 执行命令:arm-linux-gnu-gcc -Wp,-MD,arch/arm/boot/compressed/.piggy.o.d -nostdinc -isystem/crosstool/gcc-3.4.5-glibc-2.3.6/arm-linux-gnu/lib/gcc/arm-linux-gnu/3.4.5/include -D_KERNEL_-Iinclude -mlittle-endian -D_ASSEMBLY_-Wa,_L -gdwarf -2 -mapcs-32 -mno-thumb-interwork -D_LINUX_ARM_ARCH_=4-march=armv4-mtune=arm9tdmi-msoft-float -c -o arch/arm/boot/compressed/piggy.o arch/arm/boot/compressed/piggy.S生成piggy.o文件,arch/arm/boot/compressed/piggy.o大小约1.8MB;
(5)由arch/arm/boot/compressed/vmlinux.lds 将arch/arm/boot/compressed/目录下的文件head.o、piggy.o、misc.o链接生成arch/arm/boot/compressed/vmlinux,此时vmlinux是一个经过压缩且含有自解压代码的内核,大小约为1.8MB;
(6)将arch/arm/boot/compressed/vmlinux 去除调试信息、注释、符号表等内容,生成arch/arm/boot/zImage 大小约为1.8MB;此时zImage已经是一个可用的内核映像文件。
未完,待续……