文章目录
1. Download BusyBox
看起来最新的稳定版是 1.31.1 了,那就下载它。
2. Download Cross Compile
因为根文件系统跑在应用层,不能使用之前下载的编译器,因为应用层需要满足 EABI 的协议。之前的编译器只能编译 u-boot 和 kernel,所以这里需要下载支持 EABI 的编译器。
3. Read INSTALL
首先看看 INSTALL 文档,如何编译安装。
The BusyBox build process is similar to the Linux kernel build:
make menuconfig # This creates a file called ".config"
make # This creates the "busybox" executable
make install # or make CONFIG_PREFIX=/path/from/root install
The full list of configuration and install options is available by typing:
make help
Installation:
install - install busybox into CONFIG_PREFIX
Building out-of-tree:
=====================
By default, the BusyBox build puts its temporary files in the source tree.
Building from a read-only source tree, or building multiple configurations from
the same source directory, requires the ability to put the temporary files
somewhere else.
To build out of tree, cd to an empty directory and configure busybox from there:
make KBUILD_SRC=/path/to/source -f /path/to/source/Makefile defconfig
make
make install
Alternately, use the O=$BUILDPATH option (with an absolute path) during the
configuration step, as in:
make O=/some/empty/directory allyesconfig
cd /some/empty/directory
make
make CONFIG_PREFIX=. install
4. make rootfs
4.1 build
初始化环境变量路径:
export CROSS_COMPILE=arm-none-linux-gnueabihf-
export PATH=$PATH:/home/xhr/iTop4412/crossCompiler/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/bin/
export ARCH=arm
根据文档,编译和安装就写个脚本一步到位吧。
- 编译后临时文件:
out/
- 安装路径:
out/install/
#! /bin/bash
mkdir out
make O=$(pwd)/out defconfig
cd out
make -j$(nproc)
mkdir install
make CONFIG_PREFIX=install install -j$(nproc)
4.2 rootfs
编译完成后,还需要制作一些基本文件。
- mkdir dev etc home lib mnt proc root sys tmp var
- vim etc/inittab
#this is run first except when booting in single-user mode.
::sysinit:/etc/init.d/rcS
# /bin/sh invocations on selected ttys
::respawn:-/bin/sh
# Start an "askfirst" shell on the console (whatever that may be)
::askfirst:-/bin/sh
# Stuff to do when restarting the init process
::restart:/sbin/init
# Stuff to do before rebooting
::ctrlaltdel:/sbin/reboot
::shutdown:/sbin/swapoff -a
- mkdir etc/init.d/
- vim etc/init.d/rcS && chmod 777 …/rcS
#!/bin/sh
#This is the first script called by init process
/bin/mount -a
echo /sbin/mdev>/proc/sys/kernel/hotplug
mdev -s
- vim etc/fstab
#device mount-point type options dump fsck order
proc /proc proc defaults 0 0
tmpfs /tmp tmpfs defaults 0 0
sysfs /sys sysfs defaults 0 0
tmpfs /dev tmpfs defaults 0 0
- vim etc/profile
#!/bin/sh
export HOSTNAME=xhr4412
export USER=root
export HOME=root
export PS1="[$USER@$HOSTNAME \W]\# "
#export PS1="[\[\033[01;32m\]$USER@\[\033[00m\]\[\033[01;34m\]$HOSTNAME\[\033[00m\ \W]\$ "
PATH=/bin:/sbin:/usr/bin:/usr/sbin
LD_LIBRARY_PATH=/lib:/usr/lib:$LD_LIBRARY_PATH
export PATH LD_LIBRARY_PATH
- copy shared lib
cd ~/iTop4412/crossCompiler/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/arm-none-linux-gnueabihf/libc/lib
cp -d * ~/iTop4412/xhr4412/busybox/busybox-1.31.1/out/install/lib/
查看依赖的库文件:
arm-none-linux-gnueabihf-readelf -d out/busybox
剥离动态库的调试信息,符号表等等 du -h 查看文件大小;瘦身_install/lib $ arm-linux-strip * 注意操作的目录;如果没有权限把所有的文件权限修改 chmod 777 *
- make_ext4fs
./make_ext4fs -s -l 314572800 -a root -L linux xhr4412_sys.img busybox-1.31.1/out/install
到这里 rootfs 就制作完成了。
5. test rootfs
根文件系统确实是启动成功了,不过一看就能发现还有很多问题,ls 都不能显示完整,使用 vi 更是满屏 crash。暂时先到这吧。。。
参考
- 第4阶段——制作根文件系统之编译配置安装busybox(3)
- 第4阶段——制作根文件系统 (4)
- ext4文件系统制作 - make_ext4fs 参数介绍
- error while loading shared libraries: libstdc++.so.6
- fdisk -c 0 350 1000 300命令
- can’t open /dev/tty2: No such file or directory问题解决 亲自实验
- 嵌入式系统移植-04Linux内核分析(Linux内核基本概念,Linux内核启动分析,Linux内核调试方法) ##Not tainted##
- 从零开始之文件系统制作、根文件系统制作(一、根文件系统制作)busybox-1.29.2
- 通过busybox制作根文件系统 busybox-1.30.0
- busybox 制作根文件系统中etc 目录下几个文件的作用
- BusyBox制作根文件系统 (/etc/inittab实例)