目录

1.确定gcc工具版本

2.下载Buildroot源码并编译

[2.1 下载Buildroot源码](#2.1 下载Buildroot源码)

[2.2 配置Buildroot](#2.2 配置Buildroot)

[2.2.1 配置 Target options](#2.2.1 配置 Target options)

[2.2.2 配置交叉编译工具链](#2.2.2 配置交叉编译工具链)

[2.2.3 配置 System configuration](#2.2.3 配置 System configuration)

[2.2.4 配置 Filesystem images](#2.2.4 配置 Filesystem images)

[2.2.5 禁止编译 Linux 内核和 uboot](#2.2.5 禁止编译 Linux 内核和 uboot)

[2.2.6 编译Buildroot源码](#2.2.6 编译Buildroot源码)

[2.2.7 查看编译结果](#2.2.7 查看编译结果)

[3 编译Buildroot中出现的错误](#3 编译Buildroot中出现的错误)

1.确定gcc工具版本

根据Linux源码版本,确定所使用的gcc编译器的版本,gcc编译器所支持的Linux内核版本查看路径为:gcc文件夹→arm-linux-gnueabihf→libc→usr→include→linux→version.h如下图所示:

由上图可知,支持Linux 5.15.71版本的gcc编译为12.2.1,安装12.2.1版本gcc 交叉编译器,如下图所示:

2.下载Buildroot源码并编译

2.1 下载Buildroot源码

登录Buildroot官网下载Buildroot源码,如下图所示:

2.2 配置Buildroot

将下载的Buildroot源码文件buildroot-2024.02.5.tar.gz拷贝到 ~/linux/imx6ull/buildroot,>拷贝完成后进行解压,如下图所示:

输入make menuconfig命令进入图形化配置界面,如下图所示:

2.2.1 配置 Target options

配置Target options 选项,需要配置以下项目,对应的配置项及选择的内容如下所示:

配置项

配置内容

Target Architecture

ARM (little endian)

Target Binary Format

ELF

Target Architecture Variant

cortex-A7

Target ABI

EABIhf

Floating point strategy

NEON/VFPv4

ARM instruction set

ARM

配置过程如下图所示:

2.2.2 配置交叉编译工具链

配置Toolchain选项,需要配置以下项目,对应的配置项及选择的内容如下所示:

配置项

配置内容

Toolchain type

External toolchain

Toolchain

Custom toolchain

Toolchain origin

Pre-installed toolchain

Toolchain path

/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf

Toolchain prefix

$(ARCH)-linux-gnueabihf

External toolchain gcc version

12.2.1

External toolchain kernel headers series

5.15.71

External toolchain C library

glibc/eglibc

配置项及所选内容如下图所示:

2.2.3 配置 System configuration

此选项用于设置一些系统配置,比如开发板名字、欢迎语、用户名、密码等。需要配置的项目和其对应的内容如下所示:

配置项

配置内容

System hostname

External toolchain

System banner

Custom toolchain

Init system

Pre-installed toolchain

/dev management

/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf

[*] Enable root login with password (NEW)

$(ARCH)-linux-gnueabihf

External toolchain gcc version

12.2.1

External toolchain kernel headers series

5.15.71

External toolchain C library

glibc/eglibc

2.2.4 配置 Filesystem images

此选项配置制作的根文件系统的格式,配置如下图所示:

2.2.5 禁止编译 Linux 内核和 uboot

buildroot 不仅仅能构建根文件系统,也可以编译 linux 内核和 uboot。当配置 buildroot,使能 linux 内核和 uboot 以后 buildroot 就会自动下载最新的 linux 内核和 uboot 源码并编译。一般我们都不会使用 buildroot 下载的 linux 内核和 uboot,因为 buildroot 下载的 linux 和 uboot官方源码,里面会缺少很多驱动文件,而且最新的 linux 内核和 uboot 会对编译器版本号有要求,可能导致编译失败。因此我们需要配置 buildroot,关闭 linux 内核和 uboot 的编译,只使用buildroot 来构建根文件系统, 首先是禁止 Linux 内核的编译, 配置如下图所示:

2.2.6 编译Buildroot源码

配置完成以后就可以编译 buildroot 了,编译完成以后 buildroot 就会生成编译出来的根文件系统压缩包,我们可以直接使用。输入sudo make命令开始编译:

2.2.7 查看编译结果

​ 编译完成后进入buildroot-2024.02.4/output/images目录查看编译结果,如下图所示:

3 编译Buildroot中出现的错误

1.编译过程出现Fortran support is not selected but is available in external toolchain 错误如下图所示:

解决办法:进入配置界面在Toolchain交叉编译工具下使能Fortran,如下图所示:

2.编译过程出现OpenMP support is not selected but is available in external toolchain 错误如下图所示:

解决办法:进入配置界面在Toolchain交叉编译工具下使能OpenMP,如下图所示:

3.编译过程出现RPC support not available in C library, please disable BR2_TOOLCHAIN_EXTERNAL_INET_PRC 错误如下图所示:

解决办法:进入配置界面在Toolchain交叉编译工具下使能OpenMP,如下图所示: