Linux 内核的编译系统
Linux 的编译使用 GNU make 工具来检查整个系统的文件和调用 gcc 工具以及脚本完毕编译源码生成 image 等操作。要了解整个编译系统,我们首先要了解 Linux 内核的 Makefile 文件。
Linux 的 编译系统包含 5 个部分
Makefile
顶层的 Makefile 文件
.config
内核配置文件
arch/$(ARCH)/Makefile
平台 Makefile 文件
scripts/Makefile.*
脚本规则
kbuild Makefiles
大概 500 多个其它的 Makefile 文件
Makefile
查看版本号
在内核源码的根文件夹有一个 Makefile 文件,这是编译内核的入口,无论运行配置还是编译,make 命令首先读取这个文件。这个文件首先指明了内核的版本号:
我们这里是 3.10
VERSION = 3
PATCHLEVEL = 10
SUBLEVEL = 0
EXTRAVERSION =
NAME = Unicycling Gorilla
处理參数
然后处理 command line ,一共同拥有 5 个 command line
V : 设定编译时,输出信息的等级,比如你能够用 make V=1, 查看编译时运行的全部命令,包含 gcc 參数都会打印出来
C : 代码检查,使用 sparse,检查源文件。
M : 指定不在当前文件夹(外部模块)的编译,也能够指定当前文件夹的子文件夹,那么将仅仅会编译子文件夹的内容
O :指定编译生成的目标文件位置,当设置了 O 參数,内核生成的 obj 和 builtin 文件都会依照文件夹结构组织到 O 參数指定的文件夹里面
W: 使能外部 gcc 检查
这几个命令參数,在特定的情况下,将会很实用,比方我们想编译一个单独的模块就常常使用 M 參数,用 M 指定模块的路径,make 的时候将会不编译整个内核,而编译我们须要的模块:(M 參数会覆盖 KBUILD_EXTMOD 变量)
make M=drivers/misc/
LD drivers/misc/eeprom/built-in.o
CC [M] drivers/misc/eeprom/eeprom_93cx6.o
LD drivers/misc/built-in.o
Building modules, stage 2.
MODPOST 1 modules
CC drivers/misc/eeprom/eeprom_93cx6.mod.o
LD [M] drivers/misc/eeprom/eeprom_93cx6.ko
O 參数的指定,会改变整个编译出来的文件的结构,比如哦我们有多个平台要编译,你就须要为每一个平台 clone 一份内核代码了,仅仅须要设置不同的输出路径就可以:
make O=atmel, make O=asus (O 參数会覆盖 KBUILD_OUTPUT 变量),对应的文件也会生成在目标路径下,比如 uImage 就在 atmel/arch/arm/boot/uImage
获取信息
接下来系统就会获取交叉编译环境和选择不同的 gcc 和 bin 工具集
ARCH ?= $(SUBARCH)
CROSS_COMPILE ?= $(CONFIG_CROSS_COMPILE:"%"=%)
arch 变量设置目标平台, cross compile 设置交叉编译链。
伪目标
当系统信息获取成功,就能够运行编译命令了,每个伪目标都能够作为一个编译命令:(大概有 40 个左右的伪目标),可是我们会使用到的并没有这么多,能够用 make help 查看我们使用的编译命令:
make help
Cleaning targets:
clean - Remove most generated files but keep the config and
enough build support to build external modules
mrproper - Remove all generated files + config + various backup files
distclean - mrproper + remove editor backup and patch files
Configuration targets:
config - Update current config utilising a line-oriented program
nconfig - Update current config utilising a ncurses menu based program
menuconfig - Update current config utilising a menu based program
xconfig - Update current config utilising a QT based front-end
gconfig - Update current config utilising a GTK based front-end
oldconfig - Update current config utilising a provided .config as base
localmodconfig - Update current config disabling modules not loaded
localyesconfig - Update current config converting local mods to core
silentoldconfig - Same as oldconfig, but quietly, additionally update deps
defconfig - New config with default from ARCH supplied defconfig
savedefconfig - Save current config as ./defconfig (minimal config)
allnoconfig - New config where all options are answered with no
allyesconfig - New config where all options are accepted with yes
allmodconfig - New config selecting modules when possible
alldefconfig - New config with all symbols set to default
randconfig - New config with random answer to all options
listnewconfig - List new options
olddefconfig - Same as silentoldconfig but sets new symbols to their default value
Other generic targets:
all - Build all targets marked with [*]
* vmlinux - Build the bare kernel
* modules - Build all modules
modules_install - Install all modules to INSTALL_MOD_PATH (default: /)
firmware_install- Install all firmware to INSTALL_FW_PATH
(default: $(INSTALL_MOD_PATH)/lib/firmware)
dir/ - Build all files in dir and below
dir/file.[oisS] - Build specified target only
dir/file.lst - Build specified mixed source/assembly target only
(requires a recent binutils and recent build (System.map))
dir/file.ko - Build module including final link
modules_prepare - Set up for building external modules
tags/TAGS - Generate tags file for editors
cscope - Generate cscope index
gtags - Generate GNU GLOBAL index
kernelrelease - Output the release version string
kernelversion - Output the version stored in Makefile
headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH
(default: /media/android/jiangxd/workspace/Miura/kernel/usr)
Static analysers
checkstack - Generate a list of stack hogs
namespacecheck - Name space analysis on compiled kernel
versioncheck - Sanity check on version.h usage
includecheck - Check for duplicate included header files
export_report - List the usages of all exported symbols
headers_check - Sanity check on exported headers
headerdep - Detect inclusion cycles in headers
coccicheck - Check with Coccinelle.
Kernel packaging:
rpm-pkg - Build both source and binary RPM kernel packages
binrpm-pkg - Build only the binary kernel package
deb-pkg - Build the kernel as a deb package
tar-pkg - Build the kernel as an uncompressed tarball
targz-pkg - Build the kernel as a gzip compressed tarball
tarbz2-pkg - Build the kernel as a bzip2 compressed tarball
tarxz-pkg - Build the kernel as a xz compressed tarball
perf-tar-src-pkg - Build perf-3.10.0.tar source tarball
perf-targz-src-pkg - Build perf-3.10.0.tar.gz source tarball
perf-tarbz2-src-pkg - Build perf-3.10.0.tar.bz2 source tarball
perf-tarxz-src-pkg - Build perf-3.10.0.tar.xz source tarball
Documentation targets:
Linux kernel internal documentation in different formats:
htmldocs - HTML
pdfdocs - PDF
psdocs - Postscript
xmldocs - XML DocBook
mandocs - man pages
installmandocs - install man pages generated by mandocs
cleandocs - clean all generated DocBook files
Architecture specific targets (arm):
* zImage - Compressed kernel image (arch/arm/boot/zImage)
Image - Uncompressed kernel image (arch/arm/boot/Image)
* xipImage - XIP kernel image, if configured (arch/arm/boot/xipImage)
uImage - U-Boot wrapped zImage
bootpImage - Combined zImage and initial RAM disk
(supply initrd image via make variable INITRD=<path>)
* dtbs - Build device tree blobs for enabled boards
install - Install uncompressed kernel
zinstall - Install compressed kernel
uinstall - Install U-Boot wrapped compressed kernel
Install using (your) ~/bin/installkernel or
(distribution) /sbin/installkernel or
install to $(INSTALL_PATH) and run lilo
内容很之多。这里仅仅介绍几个经常使用的:
make menuconfig 图形化配置 config
make uImage 编译生成 uImage
make clean 删除大部分生成的文件,可是保留配置,以便能够编译模块
make distclean 删除全部生成的文件,补丁和配置,以及一些备份文件
make mrproper 删除全部生成的文件,补丁和配置
总的来说,顶层 Makefile 文件读取 config 文件生成 Linux 的两大目标文件 vmlinux 和 模块文件
Linux 内核的编译系统的更多相关文章
- 《linux内核设计与实现》读书笔记第三章
第3章 进程管理 3.1 进程 1.进程 进程就是处于执行期的程序. 进程包括: 可执行程序代码 打开的文件 挂起的信号 内核内部数据 处理器状态 一个或多个具有内存映射的内存地址空间 一个或多个执行 ...
- Linux内核Makefile文件(翻译自内核手册)
--译自Linux3.9.5 Kernel Makefiles(内核目录documention/kbuild/makefiles.txt) kbuild(kernel build) 内核编译器 Thi ...
- linux内核编译相关
参考:http://www.arm.linux.org.uk/docs/kerncomp.php 一. 内核编译1) linux 2.4make clean/make mrpropermake dep ...
- 重新编译Linux内核必要性及其准备工作
内核简介 内核,是一个操作系统的核心.它负责管理系统的进程.内存.设备驱动程序.文件和网络系统,决定着系统的性能和稳定性. Linux的一个重要的特点就是其源代码的公开性,所有的内核源程序都可以在/u ...
- Linux 内核的 Makefile
Linux内核的配置系统的基本结构 Linux内核的配置系统由三个部分组成,分别是: 1.Makefile:分布在 Linux 内核源代码根目录及各层目录中,定义 Linux 内核的编译规则: 2.配 ...
- Linux内核调试方法总结
Linux内核调试方法总结 一 调试前的准备 二 内核中的bug 三 内核调试配置选项 1 内核配置 2 调试原子操作 四 引发bug并打印信息 1 BUG()和BUG_ON() 2 ...
- Linux内核分析——期中总结
期中总结 一.MOOC课程 (一)计算机是如何工作的 1.冯诺依曼体系结构的核心思想是存储程序计算机. 2.CPU在实际取指令时根据cs:eip来准确定位一个指令. 3.寄存器模式,以%开头的寄存器标 ...
- Linux内核调试方法【转】
转自:http://www.cnblogs.com/shineshqw/articles/2359114.html kdb:只能在汇编代码级进行调试: 优点是不需要两台机器进行调试. gdb:在调试模 ...
- 为什么要编译Linux内核?
新的内核修订了旧内核的bug,并增加了许多新的特性.如果用户想要使用这些新特性,或想根据自己的系统度身定制一个更高效,更稳定的内核,就需要重新编译Linux内核. 通常,更新的内核会支持更多的硬件,具 ...
随机推荐
- BZOJ 4199: [Noi2015]品酒大会( 后缀数组 + 并查集 )
求出后缀数组后, 对height排序, 从大到小来处理(r相似必定是0~r-1相似), 并查集维护. 复杂度O(NlogN + Nalpha(N)) ------------------------- ...
- 解决一个Android Studio gradle的小问题
自从Android Studio有了gradle之后,就经常有问题,最近在Ubuntu上用Android Studio的时候就遇到一个问题,每次项目目录更改了,Import项目,打开项目,还是新建项目 ...
- IOS 特定于设备的开发:检查设备接近度和电池状态
UIDevice类提供了一些API,使你能够跟踪设备的特征,包括电池的状态和接近度传感器.他们二者都以通知的形式提供更新,可以订阅他们,以便在有重要的更新时通知你的应用程序. 1>启动和禁用接近 ...
- The Use of Aliases in ElasticSearch
http://paulsabou.com/blog/2012/04/15/the-use-of-aliases-in-elasticsearch/ https://github.com/taskrab ...
- Google浏览器调试js
1.进入source找到js位置 一般js文件就到js目录下找,tpl中的就到tpl中找. 我这次写在tpl中的,就到list中找,它就把list中的js单独显示出来了. 2.设置断点,进行排错.刷新 ...
- javascript条件运算符
variablename=(condition)?value1:value2 javascript条件运算符
- js调试若干
主要是将 chrome调试工具 firebug的控制台对以下都有支持 consoleAPI https://developers.google.com/chrome-developer-tools ...
- 全面理解js面向对象
前言 当今 JavaScript 大行其道,各种应用对其依赖日深.web 程序员已逐渐习惯使用各种优秀的 JavaScript 框架快速开发 Web 应用,从而忽略了对原生 JavaScript 的学 ...
- UVa340 Master-Mind Hints
#include <stdio.h>#include <string.h> #define MIN(a,b) (((a) < (b)) ? (a) : (b)) int ...
- Problem B The Blocks Problem(vector的使用)
题目链接:Problem B 题意:有n块木块,编号为0~n-1,要求模拟以下4种操作(下面的a和b都是木块编号) 1. move a onto b: 把a和b上方的木块全部归位,然后把a摞在b上面. ...