【Buildroot】构建根文件系统及问题总结

本文详细介绍了如何在Ubuntu和Buildroot环境下搭建嵌入式Linux开发环境,包括下载、安装工具链、配置和编译过程。同时列举了在搭建过程中遇到的常见问题及其解决方案,如权限不足、Python依赖和头文件版本冲突等。

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

0. 前言

对嵌入式linux开发和linux开发环境不熟悉的同志们就不要往下看了
对嵌入式linux开发和linux开发环境不熟悉的同志们就不要往下看了
对嵌入式linux开发和linux开发环境不熟悉的同志们就不要往下看了

10. 环境

软件

ubuntu1804 / ubuntu2204
buildroot-2023.02.3
toolchain:gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf

硬件

alientek - alpha

arm , A7

20. Buildroot 环境搭建

简述

除了内核还需要文件系统,而这个工具就是帮你构建这个系统的,避免了手动添加一些文件夹、三方软件的烦恼。可以直接构建出包含boot、kernel、rootfs和三方软件的镜像。

下载

下载地址:https://buildroot.org/
下载后文件名为“buildroot-2023.02.3.tar.gz”,解压后即可得到工程

环境搭建

toolchain下载、安装

下载地址:(以个人实际编译器为准,这里仅仅是拿这个alpha的开发板来说明)
https://releases.linaro.org/components/toolchain/binaries/4.9-2017.01/arm-linux-gnueabihf/
安装:直接解压 /usr/local/arm (这些乱七八糟的地址都可以自己指定,下面就不赘述了)

  1. GCC完整路径参考:/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin
  2. 环境配置:在系统profile中、个人bashrc中添加toolchain路径,
    2.1 文件:/etc/profile 或者 ~/.bashrc (或者其他shell)
    2.2 修改路径:export PATH=$PATH:/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/bin

构建镜像(仅供参考)

  1. 配置环境
  1. make menuconfig // 配置各项信息

Target options // 目标信息,如平台、指令集等
Toolchain // 交叉编译器,一般使用本地构建好的交叉编译器
Build options // 指定Download路径等配置,默认也可以
System configuration // 配置启动流程等一些,如init0 mdev 密码等
Kernel // 构建kernel,不用它构建
Target packages // 按需添加,事后添加也可以
Filesystem images // 指定文件系统等,如ubifs ,extX ,jffs2等
Bootloaders // 构建uboot等bootloader,不用它构建
Host utilities // 工具包,如dos2linux之类
Legacy config options // 顾名思义

  1. 主要配置项

Target options
Toolchain
System configuration
Kernel
Target packages
Bootloaders

Target options // 配置开发板信息
	Target Architecture (ARM (little endian))  --->                                                                         
	Target Architecture Variant (cortex-A7)  --->                                                                           		
	Target ABI (EABIhf)  --->                                                                                                	
	Floating point strategy (NEON/VFPv4)  --->                                                                              
	ARM instruction set (ARM)  --->                                                                                          	
	Target Binary Format (ELF)  ---> 
Toolchain // 这里要选择外部编译器,即使用已存在的编译器:路径、前缀等
	Toolchain type (External toolchain)  --->
	Toolchain (Custom toolchain)  --->
	Toolchain origin (Pre-installed toolchain)  ---> 
	(/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf) Toolchain path
	($(ARCH)-linux-gnueabihf) Toolchain prefix
	//  配置版本信息,仅供参考
	External toolchain gcc version (4.9.x)  --->
	External toolchain kernel headers series (4.1.x)  ---> 
	External toolchain C library (glibc)  --->
	[*] Toolchain has SSP support?
	[*] Toolchain has SSP strong support?
	[*] Toolchain has RPC support?
	[*] Toolchain has C++ support?	
System configuration // 配置mdev、init-busybox、passwd等
	Init system (BusyBox)  --->
	/dev management (Dynamic using devtmpfs + mdev)  --->
Kernel	// 不要选中,一般不需要它这里生成,单独做uboot-kernel
Target packages	// 按需选择即可
Bootloaders // 不要选中,一般不需要它这里生成,单独做uboot-kernel
  1. 保存退出即可
  1. 编译镜像
  1. sudo make 即可 // 权限是需要的

remarks:

  1. 生成的文件默认存放在./output/
  2. 编译时会下载各类软件的压缩包并存放在./dl文件夹下,国外的服务器下载很慢,但是建议第一次编译时完整下载一遍(酌情使用镜像下载源),后续就可以将这些文件保存下来单独存储,使用时会校验文件,不必担心文件不一致。
// 编译完成后,文件存放在./output/文件夹下:
output/
├── build
├── host
├── images
├── staging -> /xxxxxx/buildroot-2023.02.3/output/host/arm-buildroot-linux-gnueabihf/sysroot
└── target

// 我这里用的是nand flash,ubifs
output/images/
├── rootfs.tar
├── rootfs.ubi
└── rootfs.ubifs

80. 问题点

1. 编译、清除时提示权限不足

sudo make
sudo make clean

2. You must install ‘python’ on your build machine

// 问题
You must install 'python' on your build machine
make: *** [support/dependencies/dependencies.mk:27: dependencies] Error 1
// 解决
sudo apt-get install python3
sudo apt-get install python-is-python3

3. configure: error: you should not run configure as root (set FORCE_UNSAFE_CONFIGURE=1 in environment to bypass this check)

// 问题:
configure: error: you should not run configure as root (set FORCE_UNSAFE_CONFIGURE=1 in environment to bypass this check)
See `config.log' for more details
// 解决:修改顶层Makefile ,添加环境变量
vi Makefile
export FORCE_UNSAFE_CONFIGURE=1

4. error: ‘numeric_limits’ is not a member of ‘std’

版本问题
加头文件,(如果内核版本过低,可以考虑更换降低系统版本,如ubuntu1804)
参考:

 vi cmServerProtocol.cxx
+ #include <stdexcept>
+ #include <limits>

5. c-stack.c:55:26: error: missing binary operator before token “(”

参考:https://stackoverflow.com/questions/69719688/buildroot-error-when-building-with-ubuntu-21-10
版本问题,新版本已经废弃“SIGSTKSZ”
考虑更换host-m4的版本,或者编译系统的版本
更换host-m4的版本:host-m4-1.4.18->host-m4-1.4.19
下载地址:
https://git.busybox.net/buildroot/
替换hash,mk文件即可:

cd /tmp
wget https://buildroot.org/downloads/buildroot-2023.02.4.tar.gz
tar -xf buildroot-2023.02.4.tar.gz
rm -rf xxxxx/package/m4/
cp -rf ./package/m4/ /xxxxx/buildroot-2019.02.6/package/


// 或者直接手动修改文件也行

/* m4.hash */
# Locally calculated after checking pgp signature
sha256  63aede5c6d33b6d9b13511cd0be2cac046f2e70fd0a07aa9573a04a82783af96  m4-1.4.19.tar.xz
# License files, locally calculated
sha256  3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986  COPYING

/* m4.mk */
################################################################################
#
# m4
#
################################################################################

M4_VERSION = 1.4.19
M4_SOURCE = m4-$(M4_VERSION).tar.xz
M4_SITE = $(BR2_GNU_MIRROR)/m4
M4_LICENSE = GPL-3.0+
M4_LICENSE_FILES = COPYING

$(eval $(host-autotools-package))

6. Incorrect selection of kernel headers: expected 4.1.x, got 4.0.x

Incorrect selection of kernel headers: expected 4.1.x, got 4.0.x

头文件版本与设定的版本不匹配
要不改配置,要不给修改头文件版本信息


vi /usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/include/linux/version.h
- #define LINUX_VERSION_CODE 262100	// v4.0.0
+ #define LINUX_VERSION_CODE 262400 // v4.1.0

参数:如4.0.0,用整数记录为40000,转为16进制为262100

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

过得精彩

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

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

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

打赏作者

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

抵扣说明:

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

余额充值