慢慢欣赏linux make uImage流程

本文深入探讨了Linux内核的编译流程,包括makefile的解析,auto.conf与autoconf.h的生成过程,以及vmlinux.o的构建细节。通过对内核编译系统的探秘,读者将了解到从配置到编译的各个环节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

# The all: target is the default when no target is given on the
# command line.
# This allow a user to issue only 'make' to build a kernel including modules
# Defaults vmlinux but it is usually overridden in the arch makefile
all: vmlinux

include $(srctree)/arch/$(SRCARCH)/Makefile
=>include arch/x86/Makefile
里面有重新定义的目标,会产生覆盖
# Default kernel to build
all: bzImage

# KBUILD_IMAGE specify target image being built
KBUILD_IMAGE := $(boot)/bzImage

bzImage: vmlinux
	$(Q)$(MAKE) $(build)=$(boot) $(KBUILD_IMAGE)
	$(Q)mkdir -p $(objtree)/arch/$(UTS_MACHINE)/boot
	$(Q)ln -fsn ../../x86/boot/bzImage $(objtree)/arch/$(UTS_MACHINE)/boot/$@
	
	依赖1
	# vmlinux image - including updated kernel symbols
	vmlinux: $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) vmlinux.o $(kallsyms.o) FORCE
		$(call vmlinux-modpost)
		$(call if_changed_rule,vmlinux__)

		依赖1.4 
		modpost-init := $(filter-out init/built-in.o, $(vmlinux-init))
		vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
			$(call if_changed_rule,vmlinux-modpost)
		
		依赖1.1
		vmlinux-lds  := arch/$(SRCARCH)/kernel/vmlinux.lds
		
			依赖1.x.1,  $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) 都依赖 $(vmlinux-dirs)
			# The actual objects are generated when descending, 
			# make sure no implicit rule kicks in
			$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
				
			vmlinux-dirs	:= $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
				 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
				 $(net-y) $(net-m) $(libs-y) $(libs-m)))
				 
			$(vmlinux-dirs): prepare scripts
				$(Q)$(MAKE) $(build)=$@

prepare的东西不少

prepare 的依赖 prepare0 => prepare1 => prepare2 => prepare3
include/config/kernel.release: include/config/auto.conf FORCE
	$(Q)rm -f $@
	$(Q)echo $(kernelrelease) > $@
	
	依赖2.1
	include/config/%.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
		$(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
		
	注:$(KCONFIG_CONFIG) include/config/auto.conf.cmd: ;
	的作用如下:防止 include/config/%.conf 找不到定义
		依赖2.1.1
		silentoldconfig: $(obj)/conf
			$(Q)mkdir -p include/generated
			$< -s $(Kconfig)
			# $(obj)/conf -s 
			# KCONFIG_CONFIG 指代的就是配置文件 .config
			#生成auto.conf、auto.conf.cmd以及autoconf.h
			main //conf.c
			{
				conf_write_autoconf();
				=>int conf_write_autoconf(void)
				{
					file_write_dep("include/config/auto.conf.cmd");
					name = getenv("KCONFIG_AUTOHEADER");
					if (!name)
						name = "include/generated/autoconf.h"; // autoconf.h
					if (rename(".tmpconfig.h", name))
						return 1;
					name = getenv("KCONFIG_TRISTATE");
					if (!name)
						name = "include/config/tristate.conf";
					if (rename(".tmpconfig_tristate", name))
						return 1;
					name = conf_get_autoconfig_name();
					=>char *conf_get_autoconfig_name(void)
					{
						char *name = getenv("KCONFIG_AUTOCONFIG");

						return name ? name : "include/config/auto.conf"; // auto.conf
					}
					/*
					 * This must be the last step, kbuild has a dependency on auto.conf
					 * and this marks the successful completion of the previous steps.
					 */
					if (rename(".tmpconfig", name))
						return 1;
				}
			}

对linux内核makefile的一点点研究
http://blog.chinaunix.net/uid-20564848-id-225177.html

9.关于内核编译及配置总结:①auto.conf与②autoconf.h的‘自动’生成 
http://blog.sina.com.cn/s/blog_87c063060101klau.html

配置Linux Kernel时make menuconfig执行流程分析
https://www.cnblogs.com/LoTGu/p/5968042.html

Linux移植之make uImage编译过程分析
https://www.cnblogs.com/andyfly/p/9396423.html

Linux移植之auto.conf、autoconf.h、Mach-types.h的生成过程简析
https://www.cnblogs.com/andyfly/p/9399926.html

$(srctree) is not clean, please run 'make mrproper'
https://www.cnblogs.com/senior-engineer/p/4932559.html

makefile中的patsubst
https://blog.youkuaiyun.com/srw11/article/details/7516712

Makefile中patsubst函数使用方法
https://blog.youkuaiyun.com/yanlaifan/article/details/71402787

linux源码Makefile的详细分析
https://www.cnblogs.com/amanlikethis/p/3675486.html

arm-linux内核编译过程小结
https://www.cnblogs.com/liang123/p/6325170.html

linux内核vmlinux的编译过程之 --- vmlinux.o详解(八)
https://blog.youkuaiyun.com/m0_47799526/article/details/106202822?utm_source=blogxgwz7

3.2.5 setup.bin的构建过程
http://book.2cto.com/201309/33427.html

《Linux内核Makefile分析》之 if_changed_rule/cc_o_c/any-prereq/arg-check
http://blog.sina.com.cn/s/blog_87c063060101l25q.html

内核编译系统探秘之一 if_changed_rule
http://blog.sina.com.cn/s/blog_61c81f910100phiq.html


linux 2.6内核makefile分析
https://blog.51cto.com/19880512/453691

Linux内核makefile解析
https://blog.51cto.com/19880512/303544

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值