文章目录
buildroot官网链接 http://buildroot.uclibc.org/
相对于其他文件系统制作工具 buildroot 避免繁杂的移植工作,通过menuconfig配置我们需要的功能,不需要的功能去掉,再执行make指令编译,buildroot就会自动从指定的服务器上下载源码包,自动编译,自动搭建成我们所需要的嵌入式根文件系统。
从0开始使用QEMU模拟ARM开发环境系列一览表
特别注意:
0、Kernel:内核配置、Bootloaders:硬件启动程序为可选
Kernel:内核配置、Bootloaders:硬件启动程序为可选 如果自己在其他地方编译,不要勾选
1、下载速度慢解决
如果下载较慢可以手动下载后,放到buildroot/dl/对应目录下,比如 手动下载 linux-5.4.93.tar.xz 放到 buildroot/dl/linux 下 再重新 make
2、Bootloaders -> U-boot -> Board defconfig 填写
Board defconfig:根据情况填写,比如填写的是 qemu_arm ,它会在 buildroot根目录的 configs 文件夹中 查找 文件 ,所以需要查看configs 文件夹支持的板子 ,如果 板子没有现成的需要拷贝一份修改
3、Kernel -> Linux Kernel -> Defconfig name 填写
Defconfig name: 会在 内核源码/arch/arm/configs中查找,所以填写需要configs 文件夹中文件支持,如果 没有现成的需要拷贝一份修改(有能力的话),比如填写的 vexpress,查找时会自动补全为vexpress_defconfig
下载并安装buildroot
下载地址https://buildroot.org/download.html,获取buildroot源码包,我下载的是buildroot-2020.11.2.tar.gz
将源码包复制到/opt目录下,并解压
什么是buildroot
Buildroot是Linux平台上一个构建嵌入式Linux系统的框架。整个Buildroot是由Makefile脚本和Kconfig配置文件构成的。你可以和编译Linux内核一样,通过buildroot配置,menuconfig修改,编译出一个完整的可以直接烧写到机器上运行的Linux系统软件(包含boot、kernel、rootfs以及rootfs中的各种库和应用程序)。
buildroot 的目录结构:
buildroot 根目录:
output子目录
buildroot 配置
查看支持的开发板
查看当前buildroot中支持的开发板
make list-defconfigs
进入解压后的buildroot目录,并执行
make menuconfig
配置说明
这里不是实际操作配置,只是列举各个选项并说明(不同版本buildroot,会有差异)。实际操作见 实际配置
要构建自己的开发板,首先要创建一个基本的 buildroot配置作为开发板的基本编译系统。这里包括toolchain,kernel,bootloader,filesystem 和一个简单的 busy-box 用户空间。
执行 make menuconfig:
make menuconfig
Target options:目标板的配置
- Target Architecture:目标架构,根据需要选择, 比如选择 ARM(little endian),ARM小端模式
- Target Binary Format:二进制格式,根据需要选择, 比如为 ELF
- Target Architecture Variant:根据需要选择, 比如架构变体为 Cortex-A9,内核类型 (vexpress-ca9)
- Target ABI:应用程序二进制接口,根据需要选择, 比如为EABI
- Floating point strategy:浮点数的策略,根据需要选择, 比如选择为 Soft float
- ARM instruction set:arm 汇编指令集,根据需要选择, 比如选择 ARM
其他可默认或根据需要选择
Build options:
主要是一些buildroot编译时用到的选项,比如dl的路径,下载代码包使用的路径,同时运行多个编译的上限,是否使能编译器缓冲区等等,这里按照默认就行了。
Toolchain:工具链选项
- Toolchain type:Buildroot提供两种方式使用toolchain
- external toolthain:非Buildroot提供的交叉编译器,根据需要选择
- Buildroot toolchain:Buildroot本身编译生成的Buildroot toolchain,根据需要选择, 比如直接选择此项
- custom toolchain vendor name:可以改变,可以默认
- C library:C库选择,根据需要选择, 比如选择 glibc
- Kernel Headers:内核头文件,根据需要选择, 比如Linux 5.4.x kernel headers 根据内核版本选择
- Glibc Options:根据需要选择, 比如勾选 Install glibc utilities (注不同buildroot版本,可能不一样)
- Binutils Version:binutils版本:根据需要选择, 比如2.34
- Additional binutils options:附加的 binutils 选择,根据需要选择, 比如默认不填即可
- GCC compiler Version:GCC版本选择,gcc 9.x 根据需要选择
- Additional gcc options:附件的GCC选项,根据需要选择, 比如默认不填即可
- Enable C++ support:使能C++支持,根据需要选择, 比如勾选
- Enable Fortran support:使能Fortran语言支持,不选 或 根据需要选择
- Enable D language support: 使能Fortran语言支持,不选 或 根据需要选择
- Enable compiler link-time-optimization support:是否支持LTO,不选,LTO是什么:http://blog.csdn.net/fickyou/article/details/52381776
- Enable compiler OpenMP support:根据需要选择, 比如不选
- Enable graphite support :是否支持graphite。Graphite是应用WEB应用的一套开源的编程接口。不选。具体看百度百科:https://baike.baidu.com/item/Graphite/9810474?fr=aladdin
- Build cross gdb for the host:主机上运行gdb进行调试,根据需要选择, 比如不选
- Copy gconv libraries:拷贝 gconv库,gconv库用于在不同字符集之间进行转换。根据需要选择, 比如默认不选
- Enable MMU support:使能 MMU,**勾选 **或 根据需要选择
- Target Optimizations:根据需要选择, 比如不选
- Target linker options:根据需要选择, 比如不选
- Register toolchain within Eclipse Buildroot plug-in:eclipse插件支持,不选
System configuration:系统配置
- Root FS skeleton: 根文件系统骨架, 根据需要选择, 比如默认
- System hostname:系统主机名根据需要自己填写
- System banner: 系统横幅,根据需要自己填写
- Passwords encoding:密码编码, 默认或 根据需要选择
- Init system:系统初始化,根据需要选择, 比如选择 BusyBox
- /dev management:设备文件管理,根据需要选择, 比如选择Dynamic using devtmpfs + mdev,即使用mdev动态加载设备节点的方式
- Path to the permission tables:设备节点的配置表设置,根据需要选择
- support extended attributes in device tables: 支持设备表中的扩展属性,不选 或 根据需要选择
- Use symlinks to /usr for /bin, /sbin and /lib: 不选 或 根据需要选择
- Enable root login with password:使用密码启用root 登录, 默认选择 或 根据需要选择
- Root password:进入linux控制台终端后的密码,为空则登录时不需要密码,默认登录用户名为root。为空。根据需要设置
- /bin/sh (busybox’ default shell): 默认 或 根据需要选择
- Run a getty (login prompt) after boot:默认选择 或 根据需要选择
- TTY port:根据需要配置,比如配置为 ttyAMA0,但是注意 可能和uboot中需要的不一样,可以该这里或者uboot
- Baudrate :波特率,根据需要配置,比如配置为 115200
- TERM environment variable:默认 或 根据需要选择
- other options to pass to getty:默认 或 根据需要选择
- remount root filesystem read-write during boot:在引导期间以读写方式重新挂载根文件系统,默认选择 或 根据需要选择
- Network interface to configure through DHCP:要通过DHCP配置的网络接口,默认不选 或 根据需要选择
- Purge unwanted locales:清除不需要的区域设置,默认选择 或 根据需要选择
- Locales to keep:要保留的区域设置,默认 或 根据需要选择
- Generate locale data:生成本地日期,默认不选 或 根据需要选择
- Enable Native Language Support (NLS) :启用本地语言支持(NLS),默认不选 或 根据需要选择
- Install timezone info:安装时区信息,默认不选 或 根据需要选择
- Path to the users tables:users tables路径,默认 或 根据需要选择
- Root filesystem overlay directories:根文件系统覆盖目录,默认 或 根据需要选择
- Custom scripts to run before creating filesystem images:创建文件系统映像之前要运行的自定义脚本。默认 或 根据需要选择
- Custom scripts to run inside the fakeroot environment:在fakeroot环境中运行的自定义脚本。默认 或 根据需要选择
- Custom scripts to run after creating filesystem images:创建文件系统映像后要运行的自定义脚本。默认 或 根据需要选择
Kernel:内核配置
Linux Kernel 不选不编译 (如果不让 buildroot 编译 勿勾选)
- Kernel version:内核版本,选择用户自定义,Custom version
- Kernel version:填上自己所需要的版本,根据需要选择, 比如5.4.93
- Custom kernel patches:自定义的内核补丁,默认不选 或 根据需要选择
- Kernel configuration:内核配置,根据需要选择, 比如选择 Using an in-tree defconfig file
- Defconfig name:默认配置名称,根据需要填写,会在 内核源码/arch/arm/configs中查找,所以填写需要configs 文件夹中文件支持,如果 没有现成的需要拷贝一份修改(有能力的话),比如填写的 vexpress,查找时会自动补全为vexpress_defconfig
- Additional configuration fragment files:其他配置片段文件,根据需要选择, 比如暂且不填写
- Custom boot logo file path:自定义boot logo文件路径,根据需要选择, 比如暂且不填写
- Kernel binary format:内核二进制文件格式,根据需要选择, 比如zImage
- Kernel compression format:内核压缩格式,根据需要选择, 比如选择gzip
- Build a Device Tree Blob:设备树,根据需要选择, 比如默认不选 或 根据需要选择
- Install kernel image to /boot in target:将内核映像安装到目标中的/boot,根据需要选择, 比如默认不选
- Needs host OpenSSL:需要主机OpenSSL,默认不选 或 根据需要选择
- Needs host libelf:需要主机libelf,默认不选 或 根据需要选择
- Linux Kernel Extensions:内核扩展,默认不选 或 根据需要选择
- Linux Kernel Tools:内核工具,默认不选 或 根据需要选择
Target packages
目标应用软件,根据需要选择
Filesystem images:文件系统映像
选择 ext2/3/4 root filesystem 或 根据需要选择
Bootloaders:硬件启动程序
U-boot 不选不编译(如果不让 buildroot 编译 勿勾选)
选择为 U-boot
-
Build system:u-boot系统选择为Kconfig
- legacy:若是选择2015.04之前的u-boot 选择此项
- Kconfig:2015.04之后的 u-boot 选择此项,勾选此项
-
U-boot Version:U-boot版本,默认为 2020.10,根据需要选择, 比如选择为Custom version
-
U-Boot version:填写为2021.01, 注意 填之前 查看 https://ftp.denx.de/pub/u-boot/ 中是否有对应版本,并且为 01而不是1
-
Custom U-boot patches:U-boot补丁,默认不选 或 根据需要选择
-
U-Boot configuration:U-boot配置,根据需要选择, 比如选择为:Using an in-tree board defconfig file
-
Board defconfig:根据情况填写,比如填写的是 qemu_arm ,它会在 configs 文件夹中 查找 文件 ,所以如果 板子没有现成的需要拷贝一份修改
-
Additional configuration fragment files:其他配置片段文件,默认不选 或 根据需要选择
-
U-boot needs dtc:是否需要设备树,默认不选 或 根据需要选择
-
U-Boot needs host Python:是否需要Python,默认不选 或 根据需要选择
-
U-Boot needs pylibfdt :是否需要pylibfdt ,默认不选 或 根据需要选择
-
U-Boot needs pyelftools:是否需要pyelftools,默认不选 或 根据需要选择
-
U-boot needs OpenSSL:是否需要 OpenSSL,默认不选 或 根据需要选择
-
U-Boot needs lzop:是否需要 lzop,默认不选 或 根据需要选择
-
U-boot binary format:二进制文件,选择 .bin
-
produce a .ift signed image:默认不选 或 根据需要选择
-
Install U-boot SPL binary image:默认不选 或 根据需要选择
-
Device Tree Source file paths:默认不选 或 根据需要选择
-
Custom make options:默认不选 或 根据需要选择
Host utilities:主机应用程序
默认 或 根据需要选择
Legacy config options:传统配置选项
默认 或 根据需要选择
实际配置
configs 里面有各种厂商的开发板的配置文件,找到需要的
其他相关文章:
从0开始使用QEMU模拟ARM开发环境之编译 uboot、Linux 内核和 busybox 制作 rootfs 并仿真
从0开始使用QEMU模拟ARM开发环境之uboot通过sd卡加载uImage
从0开始使用QEMU模拟ARM开发环境之uboot通过tftp加载uImage并指定nfs挂载根文件系统
之前文章见上已经选择的是 vexpress_defconfig 所以 buildroot 同样选择 qemu_arm_vexpress_defconfig
在 buildroot 根目录下执行 sudo make qemu_arm_vexpress_defconfig
,将配置文件写入 并生成了一个 .config
的配置文件
再执行sudo make menuconfig
在已有.config
的基础上继续配置
设置root密码
system configuration 中,我设置的 root
根文件系统的格式选择
Filesystem images 中 我选择的 ext4
根文件系统打包格式
制作好根文件后,进行压缩生成一个根文件的压缩文件
其他不用改变,注意保存后退出
buildroot 编译
配置完所有内容后,配置工具将生成.config包含整个配置的 文件。该文件将由顶级Makefile读取。
要开始构建过程,只需运行:sudo make -j6
编译过程中要联网,因为可能需要下载一些packages。编译后生成的文件夹格式的rootfs在buildroot/output/images/rootfs.tar。Buildroot输出存储在目录output/中。
根文件系统测试
从0开始使用QEMU模拟ARM开发环境之uboot通过tftp加载uImage并指定nfs挂载根文件系统
参考上面链接修改uboot,然后启动模拟器
sudo qemu-system-arm -M vexpress-a9 -m 256 -kernel u-boot -nographic -net nic,macaddr=00:16:3e:00:00:01 -net tap
如果按照上面链接操作会报如下错误
在制作的根文件/dev中 创建
sudo mknod ttyAMA0 c 204 64
重新启动模拟器测试
如果还是不行
参见 从0开始使用QEMU模拟ARM开发环境之uboot通过tftp加载uImage并指定nfs挂载根文件系统 的解决方法
希望我的文章对于大家有帮助,由于个人能力的局限性,文中可能存在一些问题,欢迎指正、补充!