一个最小的根文件系统需要的项:
终端:/dev/console,/dev/NULL
如果不设置 inittab 格式中的 id (标准输入、输出和标准错误) 时,就定位到 /dev/NULL 中去。
init 程序,就是 busybox .
配置文件:/etc/inittab
配置文件若指定的某些应用程序或执行脚本。
应用程序需要的库。
配置编译busybox
编译方法
Building:
=========
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 //最后安装默认会安装到 PC 机上。要装到嵌入式文件系统中,则用后面指定目录的安装方法
make menuconfig 遇到的错误以及解决办法:
问题1:
fwhyj@localhost:~/busybox-1.7.0$ make menuconfig
Makefile:405: *** mixed implicit and normal rules: deprecated syntax
Makefile:1242: *** mixed implicit and normal rules: deprecated syntax
make: *** No rule to make target 'menuconfig'. Stop.
分析原因:
新版Makefile不支持这样的组合目标:config %config(一个有通配符,另一个没有通配符)
解决方法:
要么把config %config拆成2个规则,要么把其中一个目标去掉。
所以,
a.修改busybox-1.7.0 顶层Makefile 405行:
config %config: scripts_basic outputmakefile FORCE
改为:
%config:scripts_basic outputmakefile FORCE
b.修改busybox-1.7.0 顶层Makefile 1242行:
/ %/: prepare scripts FORCE
改为:
%/:prepare scripts FORCE
问题2
fwhyj@localhost:~/busybox-1.7.0$ make menuconfig
interrupted(11)
busybox-1.7.0/scripts/kconfig/Makefile:14: recipe for target 'menuconfig' failed
make[1]: *** [menuconfig] Error 1
Makefile:406: recipe for target 'menuconfig' failed
make: *** [menuconfig] Error 2
解决方法:安装2个库
sudo apt-get install libncurses5-dev libncursesw5-dev
Makefile 中指定交叉编译工具
# Cross compiling and selecting different set of gcc/bin-utils
# ---------------------------------------------------------------------------
#
# When performing cross compilation for other architectures ARCH shall be set
# to the target architecture. (See arch/* for the possibilities).
# ARCH can be set during invocation of make:
# make ARCH=ia64
# Another way is to have ARCH set in the environment.
# The default ARCH is the host where make is executed.
# CROSS_COMPILE specify the prefix used for all executables used
# during compilation. Only gcc and related bin-utils executables
# are prefixed with $(CROSS_COMPILE).
# CROSS_COMPILE can be set on the command line
# make CROSS_COMPILE=ia64-linux-
# Alternatively CROSS_COMPILE can be set in the environment.
# Default value for CROSS_COMPILE is not to prefix executables
# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
ARCH ?= $(SUBARCH)
CROSS_COMPILE ?= arm-linux-
配置
016 make menuconfig.png
设置的配置选项为:
命令补全
Busybox Settings --->
Busybox Library Tuning --->
[* ] Tab completion
指定库
Build Options ---->
[] Build BusyBox as a static binary (no shard libs)
这是将 BusyBox 编译成一个静态的程序,那么那些 C 库 就不需要了。这里不选表示用动态的。
压缩命令, 用默认的。
模块加载命令,默认也是选择上的。
支持 mdev 热拔插。
Networking Utilities: ifconfig
编译
fwhyj@localhost:~/busybox-1.7.0$ make
安装
要使用make CONFIG_PREFIX=指定的目录 install
建一个目录作为安装目录
fwhyj@localhost:~/busybox-1.7.0$ mkdir -p /work/nfs_root/first_fs
fwhyj@localhost:~/busybox-1.7.0$ make CONFIG_PREFIX=/work/nfs_root/first_fs install
完成了最小根文件系统的busybox。
创建 /dev/console,/dev/NULL
fwhyj@localhost:/work/nfs_root/first_fs/dev$ sudo mknod console c 5 1
fwhyj@localhost:/work/nfs_root/first_fs/dev$ sudo mknod null c 1 3
fwhyj@localhost:/work/nfs_root/first_fs/dev$ ls -l
total 0
crw-r--r-- 1 root root 5, 1 3月 17 16:24 console
crw-r--r-- 1 root root 1, 3 3月 17 16:24 null
创建 /etc/inittab 配置文件
只写一条 ::askfirst:-/bin/sh
表示它里面只执行一个 askfirst 一个/bin/sh 程序,/bin/sh 这个程序的标准输入、输出和标准错误都定位到“/dev/console”里面去。
安装 glibc 库
将所有 .so 文件拷贝过来即可。
fwhyj@localhost:/work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux/lib$ cp *.so* /work/nfs_root/first_fs/lib -d
fwhyj@localhost:/work/nfs_root/first_fs$ ls
bin dev etc lib linuxrc sbin usr
fwhyj@localhost:/work/nfs_root/first_fs$ ls dev/ lib/ etc/
dev/:
console null
etc/:
inittab
lib/:
ld-2.3.6.so libm.so libnss_nis.so.2
ld-linux.so.2 libm.so.6 libpcprofile.so
libanl-2.3.6.so libnsl-2.3.6.so libpthread-0.10.so
libanl.so libnsl.so libpthread.so
libanl.so.1 libnsl.so.1 libpthread.so.0
libBrokenLocale-2.3.6.so libnss_compat-2.3.6.so libpthread.so_orig
libBrokenLocale.so libnss_compat.so libresolv-2.3.6.so
libBrokenLocale.so.1 libnss_compat.so.2 libresolv.so
libc-2.3.6.so libnss_dns-2.3.6.so libresolv.so.2
libcrypt-2.3.6.so libnss_dns.so librt-2.3.6.so
libcrypt.so libnss_dns.so.2 librt.so
libcrypt.so.1 libnss_files-2.3.6.so librt.so.1
libc.so libnss_files.so libSegFault.so
libc.so.6 libnss_files.so.2 libstdc++.so
libc.so_orig libnss_hesiod-2.3.6.so libstdc++.so.6
libdl-2.3.6.so libnss_hesiod.so libstdc++.so.6.0.3
libdl.so libnss_hesiod.so.2 libthread_db-1.0.so
libdl.so.2 libnss_nis-2.3.6.so libthread_db.so
libgcc_s.so libnss_nisplus-2.3.6.so libthread_db.so.1
libgcc_s.so.1 libnss_nisplus.so libutil-2.3.6.so
libm-2.3.6.so libnss_nisplus.so.2 libutil.so
libmemusage.so libnss_nis.so libutil.so.1
以上便是最小的根文件系统。
将最小根文件系统烧到 FLASH 上
做一个映像文件,这里使用的 NAND FLASH 每一页是2048字节,得用yaff2。
需要使用yaffs源码编译出一个工具。
fwhyj@localhost:~/work/system$ cd Development_util_ok/yaffs2/utils/
fwhyj@localhost:~/Development_util_ok/yaffs2/utils$ make
生成了 mkyaffs2image 这个工具。将这个工具直接拷贝到这台 PC 机的 /usr/local/bin 目录下。
fwhyj@localhost:~/Development_util_ok/yaffs2/utils$ sudo cp mkyaffs2image /usr/local/bin/
fwhyj@localhost:~/Development_util_ok/yaffs2/utils$ ls -l /usr/local/bin/mkyaffs2image
-rwxr-xr-x 1 root root 19120 3月 17 17:15 /usr/local/bin/mkyaffs2image
接着制作这个根文件系统:first_fs.yaffs2
fwhyj@localhost:/work/nfs_root$ mkyaffs2image first_fs first_fs.yaffs2
Object 596, first_fs/bin/cat is a symlink to "busybox"
Object 597, first_fs/bin/deluser is a symlink to "busybox"
Object 598, first_fs/linuxrc is a symlink to "bin/busybox"
Operation complete.
342 objects in 9 directories
4145 NAND pages
fwhyj@localhost:/work/nfs_root$ ls
first_fs first_fs.yaffs2
得到了第一个文件系统的映象文件first_fs.yaffs2 。
烧写完最小根文件系统后,启动系统。可看到停在“Please press Enter to activate this console.”等待enter键输入
VFS: Mounted root (yaffs filesystem).
Freeing init memory: 140K
init started: BusyBox v1.7.0 (2019-03-17 14:59:36 CST)
Please press Enter to activate this console.
输入enter
Please press Enter to activate this console.
starting pid 763, tty '/dev/console': '/bin/sh'
#
#
# cat /etc/inittab
console::askfirst:-/bin/sh
#
启动成功。