[Author: Bo Shen <[email protected]>]
前面讲了uImage的生成过程(http://blog.csdn.net/voice_shen/article/details/6559752)。uImage会依赖zImage。那么下面就具体分析zImage生成过程。
其实zImage的生成过程更简单,源代码 <arm/arm/boot/Makefile>,如下:
$(obj)/zImage: $(obj)/compressed/vmlinux FORCE $(call if_changed,objcopy) @$(kecho) ' Kernel: $@ is ready'从源码可知,zImage是由<arm/arm/boot/compressed/vmlinux>通过objcopy生成。
if_changed命令从那里来呢?查看源码,发现其在<scripts/Kbuild.include>里面定义。
--->8---
# if_changed - execute command if any prerequisite is newer than target, or command line has changed.
---8<---
当执行$(call if_changed, objcopy)命令,其中objcopy <scripts/Makefile.lib>命令定义如下:
cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
所以会使用参数:OBJCOPYFLAGS,OBJCOPYFLAGS_zImage ($(@F): 自动化变量,是不带路径的$@)
OBJCOPY在根目录下的Makefile中定义:OBJCOPY = $(CROSS_COMPILE)objcopy
OBJCOPYFLAGS的定义在:<arch/arm/Makefile>
OBJCOPYFLAGS :=-O binary -R .comment -S
整下Makefile系统中没有对OBJCOPYFLAGS进行定义。
所以,最终对<arm/arm/boot/compressed/vmlinux>执行objcopy命令如下:
arm-none-linux-gnueabi-objcopy -O binary -R .comment -S arch/arm/boot/compressed/vmlinux zImage