OS - 内核构建系统
参考文档:
* Linux源码树 Documentation/Changes 文档查看
总图
Linux整个构建系统的目的是生成一个可启动的二进制文件, zImage构建过程如下
第一步:内核初始化 make distclean, mrproper
第二步:内核配置 kconfig make menuconfig, gconfig, xconfig
第三步:内核构建 kbuild, make all, zImage, modules
第四步:内核安装 make install, modules_install
一、内核初始化
kernel.org 或 git 获得linux 源码, 内核的初始状态
https://git.kernel.org/
解压内核
xz -cd linux-4.X.tar.xz | tar xvf -
有三种类型的kernel
* distribution kernels
Linux distributions (like Red Hat, Suse, or Ubuntu) will take a particular stable kernel and package it for their distribution. This is a distribution (or distro) kernel. Distributions may backport bug fixes to their kernels for 6 months, or even up to 2-4 years. Distribution kernels often lack new hardware support, so compiling with the latest stable kernel is recommended for newer systems.
* stable kernels
Stable kernels (without a -rcX) are released every 2-3 months when Linus feels all new features have been stablized. A particular stable kernel (like 3.1) will be updated with security and bug fixes, and newer versions will have a X.Y.Z designation, like 3.1.2.
* release candidate kernels
The release candidate kernels (signified with a -rcX numbering system) is the bleeding edge kernel that Linus Torvalds maintains. All new features are merged here during the two-week merge window.
注意:为了构建内核,需要以下工具 摘录于 Changes 文档
====================== =============== ======================================== Program Minimal version Command to check the version ====================== =============== ======================================== GNU C 3.2 gcc --version GNU make 3.81 make --version binutils 2.20 ld -v util-linux 2.10o fdformat --version module-init-tools 0.9.10 depmod -V e2fsprogs 1.41.4 e2fsck -V jfsutils 1.1.3 fsck.jfs -V reiserfsprogs 3.6.3 reiserfsck -V xfsprogs 2.6.0 xfs_db -V squashfs-tools 4.0 mksquashfs -version btrfs-progs 0.18 btrfsck pcmciautils 004 pccardctl -V quota-tools 3.09 quota -V PPP 2.4.0 pppd --version isdn4k-utils 3.1pre1 isdnctrl 2>&1|grep version nfs-utils 1.0.5 showmount --version procps 3.2.0 ps --version oprofile 0.9 oprofiled --version udev 081 udevd --version grub 0.93 grub --version || grub-install --version mcelog 0.6 mcelog --version iptables 1.4.2 iptables -V openssl & libcrypto 1.0.0 openssl version bc 1.06.95 bc --version Sphinx\ [#f1]_ 1.3 sphinx-build --version ====================== =============== ========================================
在各大分发版本中安装
sudo apt-get install libncurses5-dev gcc make git exuberant-ctags bc libssl-dev #Ubuntu sudo yum install gcc make git ctags ncurses-devel openssl-devel # Redhat sudo zypper in git gcc ncurses-devel libopenssl-devel ctags cscope #Suse
选择一个稳定的版本
git tag -l | less
git checkout -b stable v4.9
二、内核配置
有几种方式生成 .config 文件
* 复制当前.config 文件 (cp /boot/config-`uname -r`* .config)
* 使用默认配置config (make defconfig)
* 使用最小化config (ktest.pl make_min_config)
* 自定义config (make menuconfig / make nconfig)
树莓派平台编译
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig # 配置内核
make -jX # X是CPU的核数
make modules # 编译内核
make modules_install install # 安装模块
make install # 安装内核
reboot # 重启
三、内核分析工具
安装ctags + cscope
apt-get install ctags # 安装 apt-get install cscope # 安装
make tags ARCH=arm
make cscope ARCH=arm
vim 插件 www.vim.org scripts 菜单
* Source Explorer
* NERD Tree
* Tag List

浙公网安备 33010602011771号