目录:
1.顶层makefile简介
2.压缩内核镜像bzimage构建
2.1 bzimage由来
2.2 setup.bin构建
2.3 vmlinux.bin构建
摘要:
本文假定读者具有的前提:粗略的makefile知识,编译x86平台linux内核,内核版本为2.6.35.13-正在执行如下动作make menuconfig,make bzimage, make modules , make modules_install。
1 顶层makefile简介
怎么配置内核?
先定义config-targets := 0,在这个逻辑中:
$(srctree)/Makefile:
427:ifeq ($(KBUILD_EXTMOD),) // KBUILD_EXTMOD变量用于选定module编译到指定目录,默认目录为代码树的module目录 ifneq ($(filter config %config,$(MAKECMDGOALS)),) // MAKECMDGOALS为执行make时命令行中的make的参数。 config-targets := 1 ifneq ($(filter-out config %config,$(MAKECMDGOALS)),) mixed-targets := 1 endif endif 434:endif |
判断此刻不是编译module,如果有config对象,则config-targets赋值为1;若还有其他对象,则为mixed-targets,mixed-targets指同时包括config对象和镜像对象(注:行号,对应的版本2.6.35.13版本的makefile,若是其他版本可以忽略,由于添加注释缘故,行号会有些出入,所以行号本身并不重要,但余念想彼时大学园中,孤诣coding,凡事必究其原因,大耗精力,若今日有此类读者,故添之,亦不必强迫纠结无行号之痒)。
顶层makefile的主要逻辑:
$(srctree)/Makefile:
436:ifeq ($(mixed-targets),1) //编译混合对象 444:else 445: ifeq ($(config-targets),1) include $(srctree)/arch/$(SRCARCH)/Makefile // $(srctree)变量即为当前代码树的目录 //编译配置对象 464: else include $(srctree)/arch/$(SRCARCH)/Makefile // 编译vmlinux // 编译modules 1376: endif 1377:endif |
怎么得到特定体系结构?
$(srctree)/Makefile:
162: SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/ -e s/s390x/s390/ -e s/parisc64/parisc/ -e s/ppc.*/powerpc/ -e s/mips.*/mips/ -e s/sh[234].*/sh/ ) 189: ARCH ?= $(SUBARCH) |