[嵌入式] 重温Mini2440(三)使用BusyBox制作根文件系统

一. 获取BusyBox

可以在BusyBox Index of /downloads下载最新版本
也可以使用git clone git://busybox.net/busybox.git直接获取
下载完成后解压得到BusyBox源码:

tar -xvf busybox-1.33.1.tar.bz2

二. 根文件系统目录

此文使用NFS实现网络文件系统挂载,如何搭载NFS服务可以参考之前的文章:
[嵌入式] 快速配置NFS服务实现Linux主机与ARM开发板文件共享
[嵌入式] 重温Mini2440(一)移植U-Boot

在网络文件系统目录rootfs里面创建几个子目录:

mkdir dev etc home lib mnt proc root sys tmp var

三. 配置编译

1. 修改Makefile

164 CROSS_COMPILE ?= arm-linux-
190 ARCH ?= arm

#编译器版本
#Target: arm-none-linux-gnueabi
#gcc version 4.4.3 (ctng-1.6.1)

2. 导入默认配置

make defconfig

3. 修改配置

make menuconfig

3.1 使用静态编译(不需要自己再拷贝库文件)
Settings-Build Options-Build static binary (no shared libs)

在这里插入图片描述

3.2 配置make install安装路径
Settings-Installation Options-Destination path for 'make install'

在这里插入图片描述

3.3 取消Coreutils-sync

在这里插入图片描述

3.4 取消Linux System Utilities-nsenter

在这里插入图片描述

4. 编译与安装

依次执行makemake install指令

#编译BusyBox
make -j4
#安装BusyBox
make install

此时查看rootfs目录里面的内容,其中uImage是内核镜像,不是BusyBox生成
在这里插入图片描述

五. 创建必要文件

进入rootfs目录,创建几个必要的文件

1. etc/inittab

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

2. etc/init.d/rcS

mkdir etc/init.d
vim etc/init.d/rcS

#!/bin/sh
#This is the first script called by init process
/bin/mount -a
echo /sbin/mdev>/proc/sys/kernel/hotplug
mdev -s

3. etc/fstab

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

4. etc/profile

vim etc/profile

#!/bin/sh
export HOSTNAME=Mini2440
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

六. U-Boot参数设置

通过NFS加载内核以及挂载根文件系统,需要设置正确的参数:

#NFS 启动系统
setenv bootcmd 'nfs 0x30008000 192.168.15.230:/home/lps/rootfs/uImage;bootm'
setenv bootargs noinitrd root=/dev/nfs rw nfsroot=192.168.15.230:/home/lps/rootfs,nolock ip=192.168.15.233:192.168.15.230:192.168.15.1:255.255.255.0:mini2440:eth0:off console=ttySAC0,115200 init=/linuxrc

如果内核和根文件系统都没问题的话,最终在终端会出现这句:
Please press Enter to activate this console.

在这里插入图片描述

七. 其他问题

1.can’t run ‘/etc/init.d/rcS’: Permission denied
没有执行权限,通过chmod赋予权限

chmod a+x /etc/init.d/rcS

2.Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
使用arm-linux-gnueabihf-gcc version 9.3.0编译后出现这个问题,
换回arm-none-linux-gnueabi gcc version 4.4.3 (ctng-1.6.1)问题解决

3.使用动态编译时,怎么复制动态库

cd rootfs/

#查找所用编译器的目录
which arm-linux-gcc

#查看依赖的库
arm-linux-readelf -d bin/ls

#复制动态库到文件系统
cp /opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi/sys-root/lib/*so* lib/ -ra
cp /opt/FriendlyARM/toolschain/4.4.3/arm-none-linux-gnueabi/sys-root/usr/lib/*so* usr/lib/ -ra

#修改库文件属性
chmod 777 lib/*
chmod 777 usr/lib/*

#剥离动态库的调试信息
arm-linux-strip lib/*
arm-linux-strip usr/lib/*
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值