1、阅读Linux源代码根目录下的Makefile #Build vmlinux vmlinux is built from the objects selected by S(vmlinux-init)and #$(vmlinux-main).Most are built-in.o files from top-level directories in the kernel tree,others are specified in arch/S(ARCH)/Makefile. #Ordering when linking is important,and $(vmlinux-init)must be first. #vmlinux / 并 +-S(vmlinux-init) +-init/version.o more 并 +-<$(vmlinux-main) 并 +-driver/built-in.o mm/built-in.o more 并 +-kallsyms.o (see description in CONFIG KALLSYMS section) 4口4四1是4P刀00 陈香兰(x1 anchenoustc,edu.en)(升计异丸应 长人式样饰系蛇 ovenber27.201410/48
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1、阅读Linux源代码根目录下的Makefile . . . # Build vmlinux # ————————————————————————— # vmlinux is built from the objects selected by $(vmlinux-init) and # $(vmlinux-main). Most are built-in.o files from top-level directories # in the kernel tree, others are specified in arch/$(ARCH)/Makefile. # Ordering when linking is important, and $(vmlinux-init) must be first. # # vmlinux # ^ # | # +-< $(vmlinux-init) # | +–< init/version.o + more # | # +–< $(vmlinux-main) # | +–< driver/built-in.o mm/built-in.o + more # | # +-< kallsyms.o (see description in CONFIG_KALLSYMS section) 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室@计算机学院嵌入式系统实验室 嵌入式操作系统 @苏州研究院中国科学技术大学Fall 2014) November 27, 2014 10 / 48
●参见“Documentation/kbuild/makefiles.txt” -6.7 Custom kbuild commands When kbuild is executing with KBUILD_VERBOSE=0,then only a shorthand of a command is normally displayed. To enable this behaviour for custom commands kbuild requires two variables to be set: quiet_cmd_<command>-what shall be echoed cmd_<command>-the command to execute Example: quiet_cmd_image BUILD So cmd_image S(objj)/tools/build S(BUILDFLAGS)\ S(ob.j)/vmlinux.bin $o targets +bzImage S(obj)/bzImage:$(ob.j)/vmlinux.bin $(ob.j)/tools/build FORCE S(call if_changed,image) eecho'Kernel:So is ready' When updating the S(objj)/bzImage target,the line BUILD arch/i386/boot/bzImage will be displayed with make KBUILD_VERBOSE=0" 月aC 陈香兰(xlanchenoustc,ed加.cn)(计年丸应 收人式择作系蛇 Novenber 27.2014 11/48
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 参见“Documentation/kbuild/makefiles.txt” . . — 6.7 Custom kbuild commands When kbuild is executing with KBUILD_VERBOSE=0, then only a shorthand of a command is normally displayed. To enable this behaviour for custom commands kbuild requires two variables to be set: quiet_cmd_<command> - what shall be echoed cmd_<command> - the command to execute Example: # quiet_cmd_image = BUILD $@ cmd_image = $(obj)/tools/build $(BUILDFLAGS) \ $(obj)/vmlinux.bin > $@ targets += bzImage $(obj)/bzImage: $(obj)/vmlinux.bin $(obj)/tools/build FORCE $(call if_changed,image) @echo ’Kernel: $@ is ready’ When updating the $(obj)/bzImage target, the line BUILD arch/i386/boot/bzImage will be displayed with ”make KBUILD_VERBOSE=0”. 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室@计算机学院嵌入式系统实验室 嵌入式操作系统 @苏州研究院中国科学技术大学Fall 2014) November 27, 2014 11 / 48
●注意: vmlinux-init vmlinux-main vmlinux-init :$(head-y)S(init-y) vmlinux-main :$(core-y)S(libs-y)$(drivers-y)$(net-y) vmlinux-all :$(vmlinux-init)$(vmlinux-main) vmlinux-1ds :arch/$(SRCARCH)/kernel/vmlinux.1ds vmlinux-dirs vmlinux-dirs S(patsubst %/,%,S(filter/,$(init-y)$(init-m)\ $(core-y)$(core-m)S(drivers-y)S(drivers-m)\ $(net-y)S(net-m)$(libs-y)S(libs-m))) 4口4四1是4P刀00 陈香兰(xlanchenoustc,ed加.cn)(计年丸应 长人式样饰泰统 ovenber27,201412/48
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 注意: ▶ vmlinux-init ▶ vmlinux-main . . vmlinux-init := $(head-y) $(init-y) vmlinux-main := $(core-y) $(libs-y) $(drivers-y) $(net-y) vmlinux-all := $(vmlinux-init) $(vmlinux-main) vmlinux-lds := arch/$(SRCARCH)/kernel/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))) 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室@计算机学院嵌入式系统实验室 嵌入式操作系统 @苏州研究院中国科学技术大学Fall 2014) November 27, 2014 12 / 48
Outline Linx的源代码组织 2 ARM1inux的编译过程和产生的映像 o阅读Makefile ●源代码根目录下的vmlinux的生成 。zImage的生成 o bootpImage的生成 ③ARM1inux的启动分析 小结和作业 4口4四是4P在刀0C 陈香兰(xlanchenoustc,edu,cn)(计算机应 长人式择作系统 ovenber27,201413/48
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Outline . 1. Linux的源代码组织 .2 ARMlinux的编译过程和产生的映像 阅读Makefile 源代码根目录下的vmlinux的生成 zImage的生成 bootpImage的生成 .3 ARMlinux的启动分析 4. 小结和作业 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室@计算机学院嵌入式系统实验室 嵌入式操作系统 @苏州研究院中国科学技术大学Fall 2014) November 27, 2014 13 / 48
主要目标文件vmlinux的编译 o vmlinux ↓ The actual objects are generated when descending. #make sure no implicit rule kicks in $(sort $(vmlinux-init)$(vmlinux-main))$(vmlinux-lds):$(vmlinux-dirs); ↓ Handle descending into subdirectories listed in S(vmlinux-dirs) Preset locale variables to speed up the build process.Limit locale tweaks to this spot to avoid wrong language settings when running 并make menuconfig etc. #Error messages still appears in the original language PHONY +S(vmlinux-dirs) S(vmlinux-dirs):prepare scripts S(Q)S(MAKE)S(build)=0 ↓ valinux-dirs :$(patsubst /.,$(filter /$(init-y)$(init-m)\ S(core-y)S(core-n)$(drivers-y)S(drivers-m)\ S(net-y)S(net-m)$(libs-y)$(libs-m))) o不妨以core-y为例, 观察体系相关和体系无关部分的代码是如何被包含选来的 口40¥是42卡月00 东香兰(x1 anchenoustc,ed加.cn)(升并款应 收人式择作系蛇 ovenber27,201414/48
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 主要目标文件vmlinux的编译 . vmlinux ↓ . . # The actual objects are generated when descending, # make sure no implicit rule kicks in $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ; ↓ . . # Handle descending into subdirectories listed in $(vmlinux-dirs) # Preset locale variables to speed up the build process. Limit locale # tweaks to this spot to avoid wrong language settings when running # make menuconfig etc. # Error messages still appears in the original language PHONY += $(vmlinux-dirs) $(vmlinux-dirs): prepare scripts $(Q)$(MAKE) $(build)=$@ ↓ . . vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \ $(core-y) $(core-m) $(drivers-y) $(drivers-m) \ $(net-y) $(net-m) $(libs-y) $(libs-m))) 不妨以core-y为例, 观察体系相关和体系无关部分的代码是如何被包含进来的 陈香兰(xlanchen@ustc.edu.cn) (计算机应用教研室@计算机学院嵌入式系统实验室 嵌入式操作系统 @苏州研究院中国科学技术大学Fall 2014) November 27, 2014 14 / 48