Buildroot学习文章记录收集

buildroot学习记录

buildroot 源码可以在 buildroot 官网下载,链接: buildroot官网地址

1、buildroot目录结构

.
├── arch: 存放CPU架构相关的配置脚本,如arm/mips/x86,这些CPU相关的配置,在制作工具链时,编译uboot和kernel时很关键.
├── board:在构建系统时,board默认的boot和Linux kernel配置文件,以及一些板级相关脚本
├── boot:uboot的配置脚本目录,有各种boot软件的自动构建脚本,不只是u-boot,还有grub等,也可以通过Buildroot来构建。
├── CHANGES
├── Config.in:包含一些package相关的选项,并用于在配置工具中显示
├── Config.in.legacy
├── configs: 板级配置文件,该目录下的配置文件记录这该机器平台或者方案使用的工具链,boot,kernel,各种应用软件包配置 
├── COPYING
├── DEVELOPERS
├── dl: download的简写,存放下载的源代码及应用软件的压缩包. 
├── docs: 存放相关的参考文档. 
├── fs: 放各种文件系统的源代码. 
├── linux: 存放着Linux kernel的自动构建脚本. 
├── Makefile
├── Makefile.legacy
├── output: 是编译出来的输出文件夹. 
│   ├── build: 存放解压后的各种软件包编译完成后的现场.
│   ├── host: 存放着制作好的编译工具链,如gcc、arm-linux-gcc等工具.
│   ├── images: 存放着编译好的uboot.bin, zImage, rootfs等镜像文件,可烧写到板子里, 让linux系统跑起来.
│   ├── staging
│   └── target: 用来制作rootfs文件系统,里面放着Linux系统基本的目录结构,以及编译好的应用库和bin可执行文件. (buildroot根据用户配置把.ko .so .bin文件安装到对应的目录下去,根据用户的配置安装指定位置)
│
├── package:目录包含所有用户空间工具和库(Buildroot 可以将它们编译并添加到目标根文件系统)的 Makefile 和相关文件。
│   └── APP_Demo
│   	├── Config.in:包含一些package相关的选项,并用于在配置工具中显示
│   	└── app_demo.mk: (命名必须小写)用来制作rootfs文件系统,里面放着Linux系统基本的目录结构,以及编译好的应用库
│
├── README
├── support:存放着一些固定的流程脚本,以备构建时调用执行。
├── system:存放着文件系统目录的和设备节点的模板,这些模板会被拷贝到 output/ 目录下,用于制作根文件系统rootfs。
└── toolchain:存放着各种制作工具链的脚本,buildroot可以选择从0开始,用gcc和linux 内核,glibc、uclibc库等原材料制作一个自己工具链,也可以下载第三方制作好的开源工具。

2、buildroot配置

原文链接: 手把手教你用 buildroot 构建根文件系统
原文链接: Buildroot 构建根文件系统(Jz2440)
如有侵权,私信或留言联系删除

0.buildroot文件使用

解压build文件,在buildroot文件目录下输入以下命令打开图形化配置界面:

cd buildroot-2022.02/
make menuconfig

输入make menuconfig 命令配置,如果出现如下错误:

mkdir -p /home/yhz/buildroot/buildroot-2024.02/output/build/buildroot-config/lxdialog
PKG_CONFIG_PATH="" make CC="/usr/bin/gcc" HOSTCC="/usr/bin/gcc" \
    obj=/home/yhz/buildroot/buildroot-2024.02/output/build/buildroot-config -C support/kconfig -f Makefile.br mconf
/usr/bin/gcc -DCURSES_LOC="<curses.h>" -DLOCALE  -I/home/yhz/buildroot/buildroot-2024.02/output/build/buildroot-config -DCONFIG_=\"\"  -MM *.c > /home/yhz/buildroot/buildroot-2024.02/output/build/buildroot-config/.depend 2>/dev/null || :
/usr/bin/gcc -DCURSES_LOC="<curses.h>" -DLOCALE  -I/home/yhz/buildroot/buildroot-2024.02/output/build/buildroot-config -DCONFIG_=\"\"   -c conf.c -o /home/yhz/buildroot/buildroot-2024.02/output/build/buildroot-config/conf.o
 *** Unable to find the ncurses libraries or the
 *** required header files.
 *** 'make menuconfig' requires the ncurses libraries.
 *** 
 *** Install ncurses (ncurses-devel or libncurses-dev 
 *** depending on your distribution) and try again.
 *** 
Makefile:253: recipe for target '/home/yhz/buildroot/buildroot-2024.02/output/build/buildroot-config/dochecklxdialog' failed
make[2]: *** [/home/yhz/buildroot/buildroot-2024.02/output/build/buildroot-config/dochecklxdialog] Error 1
Makefile:955: recipe for target '/home/yhz/buildroot/buildroot-2024.02/output/build/buildroot-config/mconf' failed
make[1]: *** [/home/yhz/buildroot/buildroot-2024.02/output/build/buildroot-config/mconf] Error 2
Makefile:82: recipe for target '_all' failed
make: *** [_all] Error 2


错误的原因:由于我的是新安装的ubuntu虚拟机,没有安装配置界面相关的库。
解决方法安装图像配置界面相关的库:

sudo apt install libncurses-dev
1.配置 Target options
Target options
	->Target Architecture = ARM (little endian)  // 目标架构,这里选择 ARM(little endian),ARM小端模式
	->Target Binary Format = ELF                 // 二进制格式,为 ELF
	->Target Architecture Variant = arm920t      // s3c2440 的 CPU 核心架构为 arm920t
	->Target ABI = EABI                          // 应用程序二进制接口,为EABI
	->Floating point strategy = Soft float       // 浮点数的策略,s3c2440没有硬件浮点运算,所以选择为 Soft float
	->ARM instruction set = ARM                  // arm 汇编指令集,选择为 ARM 指令集
2.配置Toolchain

此配置项用于配置交叉编译工具链,设置为我们自己所使用的交叉编译器,必须是绝对路径。

目前,在ARM Linux的开发中,人们趋向于使用Linaro( http://www.linaro.org/ )工具链团队维护的ARM工具链,它以每月一次的 形式发布新的版本,编译好的可执行文件可从网址 http://www.linaro.org/downloads/ 下载。Linaro是ARM Linux领域中最著名最具技术成就的开源组织,其会员包括ARM、Broadcom、Samsung、TI、Qualcomm等,国内的海思、中兴、全志和中国台湾的MediaTek 也是它的会员。

一个典型的ARM Linux工具链包含arm-linux-gnueabihf-gcc(后续工具省略前缀)、strip、gcc、objdump、ld、gprof、nm、readelf、 addr2line等。前缀中的“hf”显 示该工具链是完全的硬浮点。

Toolchain
  -> Toolchain type = External toolchain //工具链:外部工具链、内部工具链,想减少构建时间,请考虑使用外部工具链后端。
  -> Toolchain = Custom toolchain 				//用户自己的交叉编译器
  -> Toolchain origin = Pre-installed toolchain //预装的编译器
  -> Toolchain path =   //编译器绝对路径 
  -> Toolchain prefix = $(ARCH)-linux-gnueabihf 	  //前缀
  -> External toolchain gcc version = 4.9.x 		  //工具链的版本
  -> External toolchain kernel headers series = 4.1.x //内核头文件
  -> External toolchain C library = glibc/eglibc 
  -> [*] Toolchain has SSP support? (NEW) //选中
  -> [*] Toolchain has RPC support? (NEW) //选中
  -> [*] Toolchain has C++ support? 	  //选中
  -> [*] Enable MMU support (NEW) 		  //选中
3.配置 System configuration
System configuration
 -> System hostname = world 			//平台名字,自行设置
 -> System banner = Welcome to xxxxx 	//欢迎语
 -> Init system = BusyBox 				//使用 busybox
 -> /dev management = Dynamic using devtmpfs + mdev //使用 mdev
 -> [*] Enable root login with password (NEW) 		//使能登录密码
 -> Root password = 123456 							//登录密码为 123456
 其他选项默认即可

注:当我们配置时需要输入内容时,输错了,可以按 ctrl + backspace 组合键删除输错的信息。
.

4.配置 Filesystem images

此选项配置我们最终制作的根文件系统为什么格式的。

 -> Filesystem images
 -> [*] ext2/3/4 root filesystem //如果是 EMMC 或 SD 卡的话就用 ext3/ext4
 -> ext2/3/4 variant = ext4 //选择 ext4 格式
 -> [*] ubi image containing an ubifs root filesystem //如果使用 NAND 的话就用 ubifs
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 内核的编译。

-> Kernel 
-> [ ] Linux Kernel //不要选择编译 Linux Kernel 选项!

接着禁止编译 Uboot。

-> Bootloaders 
-> [ ] U-Boot //不要选择编译 U-Boot 选项!
6.配置 Target packages

此选项用于配置要选择的第三方库或软件、比如 alsa-utils、ffmpeg、iperf、ftp、ssh等工具,可以按需选择。

配置完成以后就可以编译 buildroot 了,编译完成以后 buildroot 就会生成编译出来的根文件系统压缩包,我们可以直接使用。

sudo make //注意,一定要加 sudo,而且不能通过-jx 来指定多核编译!!!

buildroot 编译过程会很耗时,请耐心等待!编译完成以后就会在 buildroot/output/images 下生成根文件系统,即可使用。

编译过程需要一定的额外内存,注意需要留好内存,否则会报错如下:

g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report
buildroot 下的 busybox 配置

buildroot 在构建根文件系统的时候也是要用到 busybox 的,既然用到了 busybox 那么就涉及到 busybox 的配置。buildroot 会自动下载 busybox 压缩包,buildroot 下载的源码压缩包都存放在/dl 目录下,在 dl 目录下就有一个叫做“busybox”的文件夹,此目录下保存着 busybox 压缩包。

在 buildroot下打开 busybox 的配置界面输入如下命令:

sudo make busybox-menuconfig

输入以后就会打开 buildroot 下的 busybox 配置界面,需要什么功能,使能即可。可以在busybox中修改文件,使其对中文支持,这一点可以百度设置。

编译完毕以后,会生成 rootfs.tar,拷贝出来以后,可以对其进行解压然后使用nfs挂载到板子上,或者直接使用SD卡烧录。编译出来的文件系统即可使用,如果需要什么命令和工具,在 make menuconfig 中使能再次编译即可。

3、buildroot添加package

链接: buildroot-构建自己的第三方packet包
链接: link

  • 22
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值