嵌入式系统构建工具 - BuildRoot

Buildroot是一个用于生成嵌入式Linux系统的Makefiles和补丁集合,支持跨平台构建工具链、根文件系统、内核镜像和引导加载器镜像。通过其简单的配置接口和对数百个用户空间应用程序和库的支持,Buildroot简化了嵌入式系统开发的流程。本文介绍了在Ubuntu系统中设置Buildroot编译环境,下载源码,配置选项,并编译生成根文件系统的步骤。

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

Buildroot is a set of Makefiles and patches that makes it easy to generate a complete embedded Linux system. Buildroot can generate any or all of a cross-compilation toolchain, a root filesystem, a kernel image and a bootloader image. Buildroot is useful mainly for people working with small or embedded systems, using various CPU architectures (x86, ARM, MIPS, PowerPC, etc.) : it automates the building process of your embedded system and eases the cross-compilation process.

The major Buildroot features are:

  • Can handle everything in your embedded system development project: cross-compiling toolchain, root filesystem generation, kernel image compilation and bootloader compilation. Buildroot is also sufficiently flexible that it can also be used for only one or several of these steps.
  • Is very easy to set up, thanks to its menuconfig, gconfig and xconfig configuration interfaces, familiar to all embedded Linux developers. Building a basic embedded Linux system with Buildroot typically takes 15-30 minutes.
  • Supports several hundreds of packages for userspace applications and libraries: X.org stack, Gtk2, Qt, DirectFB, SDL, GStreamer and a large number of network-related and system-related utilities and libraries are supported.
  • Supports multiple filesystem types for the root filesystem image: JFFS2, UBIFS, tarballs, romfs, cramfs, squashfs and more.
  • Can generate an uClibc cross-compilation toolchain, or re-use your existing glibc, eglibc or uClibc cross-compilation toolchain
  • Has a simple structure that makes it easy to understand and extend. It relies only on the well-known Makefile language.

1. ubuntu 系统下准备编译环境,安装编译所需软件包

$ sudo apt-get install build-essential libncurses5-dev bison flex texinfo zlib1g-dev gettext libssl-dev autoconf

buildroot 用 wget 下载软件包源码,因此需要安装 wget 

$ sudo apt-get install wget

Ubuntu 默认的 shell 是 dash,它跟 buildroot 的脚本有些不兼容。用下面的命令切换到 bash 

$ sudo dpkg-reconfigure dash

2. 下载 buildroot-2012.02,放在 HOME 目录

$ cd $ wget http://buildroot.net/downloads/buildroot-2012.02.tar.bz2 
$ tar jxf buildroot-2012.02.tar.bz2

3. 配置 buildroot

buildroot 采用了和 Linux 内核一样的配置工具,使用非常方便。

$ make menuconfig

to save the build time, please use the external toolchain

Toolchain -> Toolchain type (External toolchain) -> Toolchain (Sourcery CodeBench ARM 2011.03)

4. 编译 buildroot。这可能会花几个小时 这可能会花几个小时,取决于你的 Internet 带宽以及 CPU 性能 

$ make

编译好的软件包会放在 output/target 目录下,这个目录拥有根文件系统的目录结构。

5.最后生成的根文件系统在 /output/image 目录下


如果想要制作在目标平台运行的本机编译(Native Compile)工具链,则在 make menuconfig 时打开下面两个选项: 

1. Build options 子菜单下的 development files in target filesystem

2. Package Selection for the target 子菜单下的 native toolchain in the target filesystem


当然,为了能在目标平台上进行本机编译 还需要在配置时选择一些必要的编译工具以及程序库,如:make, autoconf, automake, bison, m4, flex, libz, libiconv 等等。
注:所谓本机编译(Native Compile) (Native Compile),是相对于交叉编译而言的。其实这是最常见的编译方式 其实这是最常见的编译方式,即在本机编译 程序用于在本机或与本机兼容的硬件平台上运行 于在本机或与本机兼容的硬件平台上运行。
补充: 

1. autoconf, automake 等软件包依赖于 microperl 软件包。在编译 microperl 时可能会遇到找不到 m4 的错误,这时只须执行 make host-m4 即可产生 buildroot_dir/output/host/usr/bin/m4, m4 ,然后再执行 make, 中断的编译将继续进行。 

2. 编译某些软件包需要 pkg-config for host config host(在编译平台上运行而非在目标平台上运行)

$ make host-pkgconfig

可编译产生 buil buildroot_dir/output/host/usr/bin/pkg-config



简介 XMake 是一个跨平台自动构建工具,支持在各种主流平台构建项目,类似 cmake、automake、premake,但是更加的方便易用,工程描述语法更简洁直观,支持平台更多,并且集创建、配置、编译、打包、安装、卸载、运行于一体。 支持特性 支持windows、mac、linux、ios、android等平台,自动检测不同平台上的编译工具链(也可手动配置) 编译windows项目采用原生vs的工具链,不需要使用cygwin、mingw(当然这些也支持) 支持自定义平台编译配置,可以很方便的扩展第三方平台支持 采用lua脚本语法描述项目,描述规则简单高效,逻辑规则可灵活修改,并且不会生成相关平台的工程文件,是工程更加简单明了 支持创建模板工程、配置项目、编译项目、运行、打包、安装和卸载等常用功能(后续还会增加:自动生成文档、调试等模块) 支持编译c/c /objc成静态库、动态库、命令行可执行程序(后续还会增加:mac、ios、android的app的生成规则) 提供丰富的工程描述api,使用简单灵活,例如添加编译文件只需(还支持过滤排除): add_files("src/*.c", "src/asm/**.S", "src/*.m") 支持头文件、接口、链接库依赖、类型的自动检测,并可自动生成配置头文件config.h 支持自定义编译配置开关,例如如果在工程描述文件中增加了enable_xxx的开关,那么配置编译的时候就可以手动进行配置来启用它: xmake config --enable_xxx=true 提供一键打包功能,不管在哪个平台上进行打包,都只需要执行一条相同的命令,非常的方便 支持自定义编译工具和规则,例如想要增加对masm/yasm的编译规则,只需将自己写的masm.lua/yasm.lua规则文件,放到当前项目目录下即可。。 支持全局配置,一些常用的项目配置,例如工具链、规则描述等等,都可以进行全局配置,这样就不需要每次编译不同工程,都去配置一遍 除了可以自动检测依赖模块,也支持手动强制配置模块,还有各种编译flags。 简单例子 创建一个c console项目:xmake create -l c  -t 1 console  or xmake create --language=c  --template=1 console 工程描述文件:xmake.luaadd_target("console")     set_kind("binary")     add_files("src/*.c") 配置工程: 这个是可选的步骤,如果只想编译当前主机平台的项目,是可以不用配置的,默认编译release版本。   当然每次配置都会被缓存,不需要每次全部重新配置。xmake f -p iphoneos -m debug or xmake f --ldflags="-Lxxx -lxxx" or xmake f --plat=macosx --arch=x86_64 or xmake config --plat=iphoneos --mode=debug or xmake config --plat=iphonesimulator or xmake config --plat=android --arch=armv7---ndk=xxxxx or xmake config --cross=i386-mingw32- --toolchains=/xxx/bin or xmake config --cxflags="-Dxxx -Ixxx" or xmake config --help 编译工程:xmake or xmake -r or xmake --rebuild 运行目标:xmake r console or xmake run console 打包所有:xmake p or xmake p --archs="armv7, arm64" or xmake package or xmake package console or xmake package -o /tmp or xmake package --output=/tmp 安装目标:xmake i or xmake install or xmake install console or xmake install -o /tmp or xmake install --output=/tmp 详细使用方式和参数说明,请参考文档 或者运行:xmake -h or xmake --help or xmake config --help or xmake package --help ... 也可以参考使用xmake的实际项目:TBOX 后续工作 完善打包模块,支持对ios、mac、android的app进行一键打包和签名,生成.ipa、.apk、.app的应用程序文件 完善安装功能,支持对ios、android的app进行安装到设备 实现调试功能 实现自动生成doxygen文档功能 增加一些实用的工程描述api,例如:下载api,可以自动下载缺少的依赖库等等。。 解析automake、cmake的工程,并自动生成xmake的描述文件,实现无缝编译(如果这个实现成功的话,以后移植编译一些开源代码就更方便了) 标签:构建工具
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值