热门关键字:  ubuntu  分区  Fedora  linux系统进程  函数

当前位置 :| 主页>Linux教程>内核研究>

Kernel Compilation

来源: 作者: 时间:2008-02-21 Tag: 点击:

 

  • Downloading the main line kernel source

    A patch file on its own usually does not contain any compilable code. It is a machine-readable description of changes to make to a set of text files (in this case, the kernel source.) You need to obtain the main kernel source tree.

    The kernel source can be found on one of the kernel.org FTP sites. There are many sites scattered around the world, and are named according to a unified naming scheme. All sites start with 'ftp.' and end in '.kernel.org'. In the middle is placed a country identifier. For example:

    • ftp.uk.kernel.org
    • ftp.us.kernel.org
    • ftp.de.kernel.org

    and so forth. You can find out more information on these sites by looking at the main www.kernel.org site.

    Once you have selected a site, you need to find the kernel sources. They will be stored in the subdirectories of /pub/linux/kernel. Each kernel release is accompanied by several files:

    • linux-x.y.z.tar.gz
    • linux-x.y.z.tar.bz2
    • patch-x.y.z.gz
    • patch-x.y.z.bz2

    You will want to download the linux-x.y.z.tar.gz file, again into your $HOME directory. Again, you should look for a version which matches the version of the patch you obtained above. These files are large (about 14MB or more), so if you are on a slow connection, be prepared for it to take some time.

     

  • Unpacking the ARM kernel source

    Unpack the tar archive you downloaded above using:
    	bash$ cd $HOME
    bash$ tar zxvf linux-x.y.z.tar.gz
    This will create a directory called linux or linux-x.y.z in your home directory. Change into the newly created directory and apply the patch files, eg:
    	bash$ cd linux-2.4.26
    bash$ zcat ../patch-2.4.26-vrs1.gz | patch -p1
    The patches are heirarchial, so you need to apply them in the correct order. The patch files with more extensions depend on the ones with less extensions, so you need to apply, for example, the -rmk patch before the -rmk-np patch.

    The kernel source tree is now ready to be configured.

     

  • Configuration of the kernel build environment

    Normally, the kernel build system will build the kernel for the native machine architecture. This is not appropriate when cross compiling, so you will need to change two lines in the top level kernel Makefile. Examine the top level Makefile in an editor and find the definitions for ARCH and CROSS_COMPILE. On 2.4.x kernels, they will look like this:
    ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)
    [...]
    CROSS_COMPILE   =
    and on 2.6.x kernels:
    ARCH            ?= $(SUBARCH)
    CROSS_COMPILE ?=

    Edit these two lines to read:

    ARCH		?= arm
    CROSS_COMPILE ?= /usr/local/bin/arm-linux-

    replacing /usr/local/bin/arm-linux- with the path to your ARM Linux toolchain.

    This completes the configuration of the top level kernel makefile. The next step is to configure the kernel build to select the drivers that your platform requires.

    You may like to read linux/README and linux/Documentation/arm/README before proceeding. Both these files provide further useful information which may be specific to your kernel version.

     

  • Configuration of the kernel sources

    There are a range of 'make' targets which allow a set of defaults to be selected for the particular machine you are compiling the source for. The process is much simpler for 2.6 kernels.

     

    Configuration of 2.4 kernels

    For 2.4 kernels use <machinename>_config format, for example:
    • a5k_config
    • ebsa110_config
    • netwinder_config
    • rpc_config
    • assabet_config

    You should select one of these as the "basic" configuration as follows, and run make oldconfig immediately afterwards:

    	bash$ make netwinder_config
    bash$ make oldconfig
    The oldconfig step will prompt you for any new configuration options which may have been added since the default machine configuration file was submitted. It is normally safe to say 'N' to these new options.

    Note: If you want to change the configuration via make xxx_config, please remove the file linux/.config immediately prior to executing this command.

     

    Configuration of 2.6 kernels

    For 2.6 kernels, the process is similar. Use <machinename>_defconfig to select the machine, eg:
    	bash$ make netwinder_defconfig
    In this case, there is no need to run a separate oldconfig step.
  • Compiling the kernel source

    If you are only installing the kernel source tree for other programs, then you have finished. If you want to compile up a new kernel, type the following commands:
    	bash$ make clean
    bash$ make dep
    bash$ make zImage
    bash$ make modules
    The final two commands will actually compile the kernel and the kernel modules.

    Note: With 2.6 kernels, the make dep stage is not necessary.

  • Installing the kernel

    After the kernel has successfully compiled, you should have the kernel image, arch/arm/boot/zImage. What you do next depends if you are cross compiling or not.

    If you are cross compiling, goto the section "Installing a cross compiled kernel".

    If you are building natively (ie, for the target on the target), continue.



  • 相关文章:
    精通initramfs构建step by step
    Linux利用kexec迅速切换内核
    进程上下文VS中断上下文
    内核通知链 学习笔记
    linux spi子系统驱动分析
    menuconfig 配置选项
    《Linux操作系统内核实习》之练习一
    udev详解
    什么叫微内核,宏内核?
    Linux 信号signal处理机制
    开发简单的 Linux2.6 内核模块
    删除内核的perl脚本
    Linux2.6内核usb gadget驱动移植
    GCC hacks in the Linux kernel
    iomem
    kernel学习的想法
    让自己的驱动支持udev
    linux内核编译步骤
    内核的等待队列
    Linux内核wait_queue深入分析
    升级和删除内核
    SD卡驱动分析2
    Linux Kernel VDSO本地权限提升漏洞
    内核中的TCP的追踪分析-15-TCP(IPV4)的客户端与
    linux 2.6内核可加载模块的编译
    内核模块HelloWorld
    在环回接口上发送一个数据报
    ARP初始化
    1分钟编译FreeBSD内核
    linux设备模型之uart驱动架构分析