linux kernel makefile整体分析
来源:互联网 发布:软件缺陷分析方法 编辑:程序博客网 时间:2024/05/17 20:24
参考资料:http://www.tuicool.com/articles/aYZn6f
关于linux内核的编译,用户首先会输入make menuconfig,对内核进行配置。然后输入make zImage生成zImage.bin。
下面我们对linux内核的makefile进行分析。
首先查找zImage目标。
顶层makefile的第454行可以找到以下包含文件。
include $(srctree)/arch/$(SRCARCH)/Makefile
其中SRCARCH为arm。srctree为源代码路径,当前为空。
在该makefile的第267行可以看到
zImage Image xipImage bootpImage uImage: vmlinux
$(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $(boot)/$@
由此可以得知zImage依赖vmlinux来生成。然后从顶层makefile中的848行可以看到
vmlinux: $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) vmlinux.o $(kallsyms.o) FORCE
ifdef CONFIG_HEADERS_CHECK
$(Q)$(MAKE) -f $(srctree)/Makefile headers_check
endif
ifdef CONFIG_SAMPLES
$(Q)$(MAKE) $(build)=samples
endif
ifdef CONFIG_BUILD_DOCSRC
$(Q)$(MAKE) $(build)=Documentation
endif
$(call vmlinux-modpost)
$(call if_changed_rule,vmlinux__)
$(Q)rm -f .old_version
所以当前我们应该首要分析 $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) vmlinux.o $(kallsyms.o) FORCE这些依赖文件的生成规则。
我们一个一个慢慢来。
<1> $(vmlinux-lds)
$(vmlinux-lds)是借助vmlinux-dirs的生成过程生成的。通过执行顶层makefile的882行中的$(Q)$(MAKE) $(build)=$@来生成的。
参考:
scrip/Makefile.build的第92行:
__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
$(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \
$(subdir-ym) $(always)
@:
\arch\arm\kernel:62行
其中的extra-y := $(head-y) init_task.o vmlinux.lds
Makefile.build:277
$(obj)/%.lds: $(src)/%.lds.S FORCE
$(call if_changed_dep,cpp_lds_S)
<1-1>
顶层makefile的873行
$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
<1-1-1>
顶层makefile的654行
vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
$(core-y) $(core-m) $(drivers-y) $(drivers-m) \
$(net-y) $(net-m) $(libs-y) $(libs-m)))
顶层makefile的882行
$(vmlinux-dirs): prepare scripts
$(Q)$(MAKE) $(build)=$@
<1-1-1-1>
prepare3: include/config/kernel.release
ifneq ($(KBUILD_SRC),)
@$(kecho) ' Using $(srctree) as source for kernel'
$(Q)if [ -f $(srctree)/.config -o -d $(srctree)/include/config ]; then \
echo " $(srctree) is not clean, please run 'make mrproper'";\
echo " in the '$(srctree)' directory.";\
/bin/false; \
fi;
endif
# prepare2 creates a makefile if using a separate output directory
prepare2: prepare3 outputmakefile
prepare1: prepare2 include/linux/version.h include/generated/utsrelease.h \
include/config/auto.conf
$(cmd_crmodverdir)
archprepare: prepare1 scripts_basic
prepare0: archprepare FORCE
$(Q)$(MAKE) $(build)=.
$(Q)$(MAKE) $(build)=. missing-syscalls
# All the preparing..
prepare: prepare0
<1-1-1-2>
scripts: scripts_basic include/config/auto.conf include/config/tristate.conf
$(Q)$(MAKE) $(build)=$(@)
<2>$(vmlinux-init)
顶层makefile698行:
vmlinux-init := $(head-y) $(init-y)
<2-1>
\arch\arm下的makefile第110行:
head-y := arch/arm/kernel/head$(MMUEXT).o arch/arm/kernel/init_task.o
<2-2>
顶层makefile第479行:
init-y := init/
顶层makefile第663行:
init-y := $(patsubst %/, %/built-in.o, $(init-y))
参考<1-1-1>中,init/built-in.o就是在那时候已经创建。
<3>$(vmlinux-main)
顶层makefile 699:
vmlinux-main := $(core-y) $(libs-y) $(drivers-y) $(net-y)
参考<1-1-1>,创建也是在这时候。不过不清楚为什么要在这边写出来。
<4>vmlinux.o
vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
$(call if_changed_rule,vmlinux-modpost)
<4-1>
Kbuild.include第220行:
if_changed_rule = $(if $(strip $(any-prereq) $(arg-check) ), \
@set -e; \
$(rule_$(1)))
ifeq ($(KBUILD_VERBOSE),2)
why = \
$(if $(filter $@, $(PHONY)),- due to target is PHONY, \
$(if $(wildcard $@), \
$(if $(strip $(any-prereq)),- due to: $(any-prereq), \
$(if $(arg-check), \
$(if $(cmd_$@),- due to command line change, \
$(if $(filter $@, $(targets)), \
- due to missing .cmd file, \
- due to $(notdir $@) not in $$(targets) \
) \
) \
) \
), \
- due to target missing \
) \
)
echo-why = $(call escsq, $(strip $(why)))
endif
<4-1-1>
顶层makefile 840行:
define rule_vmlinux-modpost
:
+$(call cmd,vmlinux-modpost)
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost $@
$(Q)echo 'cmd_$@ := $(cmd_vmlinux-modpost)' > $(dot-target).cmd
endef
<4-1-2>
Kbuild.include 168行
echo-cmd = $(if $($(quiet)cmd_$(1)),\
echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';)
# printing commands
cmd = @$(echo-cmd) $(cmd_$(1))
<4-1-3>
顶层makefile 836:
quiet_cmd_vmlinux-modpost = LD $@
cmd_vmlinux-modpost = $(LD) $(LDFLAGS) -r -o $@ \
$(vmlinux-init) --start-group $(vmlinux-main) --end-group \
$(filter-out $(vmlinux-init) $(vmlinux-main) FORCE ,$^)
define rule_vmlinux-modpost
:
+$(call cmd,vmlinux-modpost)
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost $@
$(Q)echo 'cmd_$@ := $(cmd_vmlinux-modpost)' > $(dot-target).cmd
endef
<5>vmlinux.o $(kallsyms.o)
这两个目前先不去看了。先去看看其他了。
- linux kernel makefile整体分析
- linux内核Makefile整体分析
- linux内核Makefile整体分析
- linux kernel Makefile编译流程分析
- OpenWrt Makefile 整体分析
- OpenWrt Makefile 整体分析
- OpenWrt Makefile 整体分析
- OpenWrt Makefile 整体分析
- kernel的Makefile分析
- Linux kernel makefile 文档
- The Linux Kernel Makefile
- Linux Kernel Makefile
- Linux kernel Makefile
- linux kernel makefile analysis
- Kernel顶层Makefile文件分析
- 嵌入式 Linux开发Kernel移植(三)——Kernel工程Makefile分析
- Linux Kernel Makefile默认目标
- Linux Kernel Makefile之一概况
- 欢迎使用CSDN-markdown编辑器
- Spring集成Mybatis
- 使用TextToSpeech实现文本转音频(自动朗读)
- Description Resource Path Location Type Java compiler level does not match the version of the insta
- 实例详解CSS中position的fixed属性使用
- linux kernel makefile整体分析
- 阴影映射(Shadow Map)的研究(二)
- linux的审计功能(audit)
- 黑马程序员——Java之IO流(二)
- GOF23设计模式之享元模式之理解
- java基础8:GUI
- linux 定时任务
- mvc UIViewController 设备旋转
- 【Python与R】Rpy2 - 安装