buildroot

背景

buildroot的基本功能是可以通过简单的配置即可创建出根文件系统。另外,还可以创建交叉编译器,
编译u-boot以及内核。关于buildroot的基础知识不再赘述,网上很多资料,不过,参考官网上的资料就足够了。

交叉编译器

创建

首次使用时,需要buildroot创建交叉编译器。

make beaglebone_defconfig
make menuconfig
Toolchain  ---> 
    Toolchain type (Buildroot toolchain)  ---> 
    C library (glibc)  ---> 
    Kernel Headers (Same as kernel being built)  --->
    Custom kernel headers series (3.14.x)  --->
    glibc version (2.23)  --->
    GCC compiler Version (gcc 4.8.x)  --->
    [*] Enable C++ support 
Kernel  --->
    Kernel version (Custom version)  --->
     (3.14) Kernel version 

保存设置,make。编译完之后,会在output/host/目录下生成usr目录。将usr目录整个拷贝到/opt/arm/目录下,当然这个目录你可以随便指定。

保存
#vi .bash_profile 
PATH=$PATH:$HOME/bin:/opt/arm/usr/bin
#source .bash_profile 

# arm-linux-gcc -v
Using built-in specs.
COLLECT_GCC=/opt/arm/usr/bin/arm-linux-gcc.br_real
COLLECT_LTO_WRAPPER=/opt/arm/usr/bin/../libexec/gcc/arm-buildroot-linux-gnueabihf/4.8.5/lto-wrapper
Target: arm-buildroot-linux-gnueabihf
Configured with: ./configure --prefix=/root/buildroot-2017.02.3/output/host/usr --sysconfdir=/root/buildroot-2017.02.3/output/host/etc --enable-static --target=arm-buildroot-linux-gnueabihf --with-sysroot=/root/buildroot-2017.02.3/output/host/usr/arm-buildroot-linux-gnueabihf/sysroot --disable-__cxa_atexit --with-gnu-ld --disable-libssp --disable-multilib --with-gmp=/root/buildroot-2017.02.3/output/host/usr --with-mpc=/root/buildroot-2017.02.3/output/host/usr --with-mpfr=/root/buildroot-2017.02.3/output/host/usr --with-pkgversion='Buildroot 2017.02.3' --with-bugurl=http://bugs.buildroot.net/ --disable-libquadmath --enable-tls --disable-libmudflap --enable-threads --without-isl --without-cloog --disable-decimal-float --with-abi=aapcs-linux --with-cpu=cortex-a8 --with-fpu=vfpv3-d16 --with-float=hard --with-mode=arm --enable-languages=c,c++ --with-build-time-tools=/root/buildroot-2017.02.3/output/host/usr/arm-buildroot-linux-gnueabihf/bin --enable-shared --disable-libgomp
Thread model: posix
gcc version 4.8.5 (Buildroot 2017.02.3) 

这样通过buildroot就创建好了交叉编译工具。
另外,还需要配置动态库的路径。

cd /etc/ld.so.conf.d
vi arm.conf
写入
/opt/arm/usr/lib
保存
ldconfig
使其生效
配置

接下来需要在buildroot中设置使用外部交叉编译工具,就是刚才copy出来的,从而避免每次都编译交叉编译工具。

Toolchain  ---> 
    Toolchain type (External toolchain)  --->
    Toolchain (Custom toolchain)  --->
    Toolchain origin (Pre-installed toolchain)  --->
    (/opt/arm/usr) Toolchain path
    ($(ARCH)-linux) Toolchain prefix (NEW) 
    External toolchain gcc version (4.8.x)  --->
    External toolchain kernel headers series (3.14.x)  ---> 
    External toolchain C library (glibc/eglibc)  ---> 
    [*] Toolchain has C++ support?

配置u-boot

Bootloaders  ---> 
    U-Boot Version (Custom version)  ---> 
    (2016.09) U-Boot version
    (my_patch) Custom U-Boot patches  
    (am335x_evm) Board defconfig 
    (MLO)   U-Boot SPL binary image name 

其他选项用默认即可。
其中my_patch为你的u-boot补丁文件,绝对路径。

配置内核

Kernel  ---> 
    Kernel version (Custom version)  --->
    (3.14) Kernel version 
    (my_patch) Custom kernel patches
    (omap2plus) Defconfig name
    Kernel binary format (uImage)  --->
    (0x80008000) load address (for 3.7+ multi-platform image) 
    [*]   Build a Device Tree Blob (DTB) 
    (am335x-evm) Device Tree Source file names

其他选项用默认即可。
其中my_patch为你的u-boot补丁文件,绝对路径。

配置文件系统

Filesystem images  --->
    [*] tar the root filesystem 

其他选项用默认即可。

制作根文件系统

编译完成后,会在output/images目录下生成rootfs.tar

mkdir rootfs
tar xvf rootfs.tar -C rootfs
cd rootfs/bin
chmod 755 busybox

现在rootfs就是一个可以使用的根文件系统了。
需要注意的是不要使用output/target目录下的内容作为根文件系统。
该目录下专门有个文件来说明THIS_IS_NOT_YOUR_ROOT_FILESYSTEM。

ubi根文件系统

使制作ubi的工具(ubinize、ubifs.conf、mkfs.ubifs)和rootfs位于同一目录下,执行make.sh。
该脚本的内容:

rm -f ubifs.img
rm -f ubi.img
./mkfs.ubifs -r ./rootfs -F -o ubifs.img -m 2048 -e 126976 -c 1580
./ubinize -o ubi.img -m 2048 -p 128KiB -s 2048 -O 2048 ubifs.conf
rm -f ubifs.img

具体这些参数什么意思,具体设置多少,需要了解ubi文件系统根据的使用以及自己的nand参数。
最终生成的ubi.img就是我们需要的ubi格式的根文件系统。

烧写根文件系统

tftp 0x82000000 ubi.img
nand erase 0x780000 0xf880000
nand write.i 0x82000000 0x780000 ${filesize}

在此需要注意,烧写ubi时,需要把剩余的nand空间都擦除掉,否则,会报下面的错误:

[    1.920406] UBI error: ubi_init: cannot open mtd NAND.file-system, error -2
[    1.994273] davinci_mdio 4a101000.mdio: davinci mdio revision 1.6
[    2.000701] davinci_mdio 4a101000.mdio: detected phy mask fffffffe
[    2.009864] libphy: 4a101000.mdio: probed
[    2.014104] davinci_mdio 4a101000.mdio: phy[0]: device 4a101000.mdio:00, driver SMSC LAN8710/LAN8720
[    2.025761] Detected MACID = 38:d2:69:77:b4:94
[    2.036569] input: volume_keys.7 as /devices/volume_keys.7/input/input0
[    2.047932] omap_rtc 44e3e000.rtc: setting system clock to 2000-01-01 00:00:00 UTC (946684800)
[    2.077501] UBIFS error (pid 1): ubifs_mount: cannot open "ubi0:rootfs", error -19
[    2.085587] VFS: Cannot open root device "ubi0:rootfs" or unknown-block(0,0): error -19
[    2.093999] Please append a correct "root=" boot option; here are the available partitions:
[    2.102928] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值