Linux kernel make 常用选项介绍

本文提供了一份详尽的Linux Kernel编译教程,包括了自动make脚本的编写、不同编译选项的说明以及如何选择合适的defconfig配置文件等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Linux kernel 编译方法大全记录

一、这是一个我自己写的自动make脚本:

#!/bin/sh

export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabihf-   
    export CHEN_DTB="chenfl.dtb"
        
if [ 1 -eq $# ]; then
    if [ $1 = "dtb" ]; then
        make -j2  $CHEN_DTB  O=out
        cp ~/am335x/kernel4.4.12/out/arch/arm/boot/dts/am335x-chenfl.dtb  $CHEN_PATH -rf
        # cp ~/am335x/kernel4.4.12/out/arch/arm/boot/dts/am335x-sbc7109.dtb  $CHEN_PATH -rf
        sync
        echo "Copy  dts over ...\n"
    elif [ $1 = "defconfig" ]; then
        make -j2 aplex_sbc7109_defconfig O=out
        echo "Use aplex_sbc7109_defconfig over ...\n"
    elif [ $1 = "menuconfig" ]; then
        make -j2 $1  O=out
    elif [ $1 = "zImage" ]; then
        make -j2 $1  O=out
        cp ~/am335x/kernel4.4.12/out/arch/arm/boot/zImage   $CHEN_PATH -rf
        sync
        echo "Copy kernel  zImage to myself file over ... \n"
    elif [ $1 = "all" ]; then
        make -j2 $1  O=out
        cp ~/am335x/kernel4.4.12/out/arch/arm/boot/zImage   $CHEN_PATH -rf
        cp ~/am335x/kernel4.4.12/out/arch/arm/boot/dts/am335x-sbc7109.dtb  $CHEN_PATH -rf
        sync
        echo "Copy kernel  image and dts over ... \n"
    elif [ $1 = "savedefconfig" ]; then
        make $1 O=out
        echo "Save .config to defconfig over ... \n"
    elif [ $1 = "clean" ]; then
        make $1 O=out
        echo "Clean out over ...\n"
    elif [ $1 = "distclean" ]; then
        make $1 O=out
        echo "Distclean over ...\n"
    elif [ $1 = "help" ]; then
        make $1
    else
        echo " "
        echo "You can following command to do the thing you want to do..."
        echo "./remake dtb              -- Only cross-complie your device tree table"
        echo "./remake defconfig        -- Only configure your defconfig"
        echo "./remake menuconfig       -- Only configure your configuration"
        echo "./remake zImage           -- Only cross-complie your Linux kernel zImage "
        echo "./remake all              -- Cross-complie kernel and dts"
        echo "./remake savedefconfig    -- Save your .config as defconfig "
        echo "./remake clean            -- Clean your output file"
        echo "./remake distclean        -- Deep clean your output file"
        echo "./remake help             -- Check help infomation "
    fi
else
    echo " "
    echo "You can following command to do the thing you want to do..."
 echo "./remake dtb              -- Only cross-complie your device tree table"
    echo "./remake defconfig        -- Only configure your defconfig"
    echo "./remake menuconfig       -- Only configure your configuration"
    echo "./remake zImage           -- Only cross-complie your Linux kernel zImage "
    echo "./remake all              -- Cross-complie kernel and dts"
    echo "./remake savedefconfig    -- Save your .config as defconfig "
    echo "./remake clean            -- Clean your output file"
    echo "./remake distclean        -- Deep clean your output file"
    echo "./remake help             -- Check help infomation "
fi

二、当你指定ARCH=arm 之后,如下命令运行,则会出现arm相关kernel的help信息。

make ARCH=arm help
这里面完全介绍了有关arm kernel make的帮助信息。

三、挑几个重点的讲解一下。

编译的时候,首先, 指定芯片的架构以及交叉编译器前缀。
export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabihf-   

make clean
除了保存config文件以及构建外围模块必要的文件其他的全部清除。
make mrproper
清理全部生成的文件+config文件+不同的备份文件
make distclean
clean + mrproper , 彻底的清理


执行完上面的步骤之后。
选择一个自己的产品参考的defconfig
文件在arch/arm/configs/ 里面,这里面全部都是你可以选择的defconfig
例如:
make omap2plus_defconfig O=out
O 的指定是指output file 的意思,此时会在out文件夹下生成.config 文件。

当然,你应该还有一些想要添加的,我这里直接使用menuconfig进行配置
make menuconfig O=out

配置好了,你想要保存.config文件为自己的配置的一个备份。
make savedefconfig O=out
这时在out文件夹下就会有一个defconfig文件

当所有的都配置好了,现在,你想编译自己的设备树chenfl.dts
make -j2 chenfl.dtb O=out

你想编译自己的镜像zImage
make -j2 zImage O=out

你想编译自己的模块
make -j2 modules O=out

你想编译所有的东西
make -j2 all O=out


好了,所有常用的make功能介绍完毕。
zImage 在out/arch/arm/boot/zImage
chenfl.dtb 在out/arch/arm/boot/dts/chenfl.dtb
defconfig 你可以复制到arm/arch/configs/ 里面,后缀必须是defconfig

不正望指出谢谢。

转载于:https://www.cnblogs.com/chenfulin5/p/6179554.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值