GNU/Linux - 如何编译kernel

使用 make 命令构建 Linux 内核涉及多个步骤。下面是整个过程的基本概述:

1. 获取内核源代码

    * 从 kernel.org 或你的发行版软件仓库下载内核源代码。

    * 将源代码解压缩到一个目录中。

2. 配置内核

    * 切换到内核源代码目录。

    * 可选择清理源代码树:make clean。

    * 使用以下方法之一配置内核:

        * 使用默认配置:make defconfig 或 make oldconfig。

        * 自定义配置:make menuconfig(基于文本)、make xconfig(基于 Qt)或 make gconfig(基于 GTK)。

3. 构建内核

    * 运行 make 来构建内核。可选择使用 -j 标志指定并行编译的线程数,后跟线程数(例如,make -j4 表示 4 个线程。)

    * 此步骤可能需要一些时间,具体取决于硬件和所选配置选项。

确保在开始编译前安装了必要的开发工具和依赖项(gcc、make、用于 menuconfig/xconfig/gconfig 的 libncurses-dev 等)。


Building the Linux kernel using the make command involves several steps. Here’s a basic overview of the process:

  1. Get the Kernel Source:

    • Download the kernel source code from kernel.org or your distribution’s repositories.

    • Extract the source code to a directory.

  2. Configure the Kernel:

    • Change to the kernel source directory.

    • Optionally, clean the source tree: make clean.

    • Configure the kernel using one of the following methods:

      • Use the default configuration: make defconfig or make oldconfig.

      • Customize the configuration: make menuconfig (text-based), make xconfig (Qt-based), or make gconfig (GTK-based).

  3. Build the Kernel:

    • Run make to build the kernel. Optionally, you can specify the number of threads for parallel compilation using -j flag followed by the number of threads (e.g., make -j4 for 4 threads. j means job).

    • This step might take some time depending on your hardware and the configuration options chosen.

Ensure you have the necessary development tools and dependencies installed (gcc, make, libncurses-dev for menuconfig/xconfig/gconfig, etc.) before starting the build process.


补充说明:

1,执行make defconfig,会将当前默认的配置写入.config文件,如果没有就创建。

2,make menuconfig,退出时提示是否保存,会保存到.config文件,如果没有就创建。

3,make时使用的就是.config配置文件,如果此文件发生变化,旧内容保存到.config.old,新内容保存到.config

4, make oldconfig会载入.config.old的内容到.config文件。

远程服务器,openwet 下面有这样的配置{ "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/include", "${workspaceFolder}/staging_dir/target-*/usr/include", "${workspaceFolder}/staging_dir/target-*/include", "${workspaceFolder}/staging_dir/toolchain-*/usr/include", "${workspaceFolder}/staging_dir/toolchain-*/include", "${workspaceFolder}/build_dir/target-*/linux-*/backports-*/include", "${workspaceFolder}/build_dir/target-*/linux-*/backports-*/backport-include", "${workspaceFolder}/package/kernel/siflower/openwrt-x2880-driver/**", "${workspaceFolder}/package/kernel/siflower/openwrt-x2880-driver/src/**", "${workspaceFolder}/sf_kernel/linux-5.10/arch/riscv/include/generated", "${workspaceFolder}/sf_kernel/linux-5.10/arch/riscv/include/uapi", "${workspaceFolder}/sf_kernel/linux-5.10/arch/riscv/include/uapi/asm", "${workspaceFolder}/sf_kernel/linux-5.10/include/generated", "${workspaceFolder}/sf_kernel/linux-5.10/include", "${workspaceFolder}/sf_kernel/linux-5.10/include/uapi", "${workspaceFolder}/sf_kernel/linux-5.10/include/net", "${workspaceFolder}/sf_kernel/linux-5.10/include/uapi/asm-generic", "${workspaceFolder}/package/kernel/siflower/easymesh/**" ], "defines": [ "__KERNEL__", "MODULE", "KBUILD_MODNAME=__FILE__", "CONFIG_64BIT=1", "CONFIG_SIWIFI_FULLMAC", "CONFIG_SIWIFI_IGMP", "__linux__", "__OpenWrt__" ], "compilerPath": "${workspaceFolder}/staging_dir/toolchain-*/bin/*-gcc", "cStandard": "gnu11", "cppStandard": "gnu++17", "intelliSenseMode": "linux-gcc-arm64" } ], "version": 4 }为什么代码里面还是有红色波浪线
最新发布
03-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜流冰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值