搭建Busybox-1.32.0(system.img)

1.解压busybox-1.32.0

(1)将busybox-1.32.0.tar.bz2文件拷贝到ubuntu下的/home/minilinux下,并试用命令tar -xvf busybox-1.32.0.tar.bz2 解压完后如图所示。

在这里插入图片描述
(2)然后进入busybox-1.32.0目录下,使用命令:cd busybox-1.32.0 如图所示。

在这里插入图片描述

2.配置Busybox的编译

(1)使用命令:make menuconfig ,然后在进入Settings–>
在这里插入图片描述
(2)然后修改 ( )Cross compiler prefix的参数。
在这里插入图片描述
(3)选中 Build Options 配置界面的 Cross Compiler prefix 如上图,然后按回车,进入 Cross Compiler prefix 配置界面,如下图。
在这里插入图片描述
(4)输入使用的交叉编译工具 arm-none-linux-gnueabi-,如下图。
在这里插入图片描述
(5)然后按回车返回到 Build Options 配置界面,这时可以看到刚才设置的交叉编译工具,如下图
在这里插入图片描述
(6)接着选中 Destination path for ‘make install’ ,然后按回车进入 Destination path for ‘make install’ 配置界面(这个界面是设置编译完 Busybox,把最终生成的二进制文件安装到哪个目录下面),如下图。
在这里插入图片描述
(7)然后按回车,进入 Destination path for ‘make install’ 配置界面,如下图。
在这里插入图片描述
(8)删除里面的./_install,然后输入“…/system”(最终生成的二进制文件会安装到当前 目录的上一级目录下的 system 目录里面,注意有两个点),如下图。

在这里插入图片描述

(9)然后按回车保存配置,退出配置界面,即可。

3.编译和安装 Busybox

(1)现在 Busybox 的配置已经完成了,接下来开始编译 Busybox,在 Ubuntu 的终端输入“make”命令开始编译 Busybox,如下图。
在这里插入图片描述
(2)等待变异即可,这里要说明一下,编译的过程中可能会遇到编译不同的问题,具体问题需要百度一下即可解决。可参考 “4.编译报错的问题”。

(3)现在编译完成了,接下来需要把编译生成的二进制文件安装到刚才指定的…/system 目录里面,使用命令“make install”安装二进制文件到“…/system”目录,如下图。
在这里插入图片描述
(4)然后返回上一级目录,进行查看,可得到system。如图所示

在这里插入图片描述

4.编译报错的问题

(1)问题一

报错:

networking/libiproute/ipaddress.c: In function ‘print_addrinfo’:
networking/libiproute/ipaddress.c:333: error:IFA_F_DADFAILEDundeclared (first use in this function)
networking/libiproute/ipaddress.c:333: error: (Each undeclared identifier is reported only once
networking/libiproute/ipaddress.c:333: error: for each function it appears in.)
make[1]: *** [networking/libiproute/ipaddress.o] Error 1
make: *** [networking/libiproute] Error 2

查找:

在busybox下查找ipaddress.c进行修改

命令:

locate ipaddress.c
/home/minilinux/busybox-1.32.0/networking/libiproute/ipaddress.c
/opt/poky/3.0.4/sysroots/x86_64-pokysdk-linux/usr/lib/python3.7/__pycache__/ipaddress.cpython-37.opt-1.pyc
/opt/poky/3.0.4/sysroots/x86_64-pokysdk-linux/usr/lib/python3.7/__pycache__/ipaddress.cpython-37.opt-2.pyc
/opt/poky/3.0.4/sysroots/x86_64-pokysdk-linux/usr/lib/python3.7/__pycache__/ipaddress.cpython-37.pyc
/usr/lib/python3.5/__pycache__/ipaddress.cpython-35.pyc
root@ubuntu:/home/minilinux# 

解决办法

networking/libiproute/ipaddress.c:333:
添加条件编译
#ifdef IFA_F_DADFAILED 	//添加
		if (ifa->ifa_flags & IFA_F_DADFAILED) {
				ifa->ifa_flags &= ~IFA_F_DADFAILED;
				printf("dadfailed ");
		}
#endif			//添加

以上是出现的报错问题,通过修改对应的地方即可

(2)问题二

报错:

networking/lib.a(nslookup.o): In function `print_host':
nslookup.c:(.text.print_host+0x44): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
debianutils/lib.a(mktemp.o): In function `mktemp_main':
mktemp.c:(.text.mktemp_main+0x98): warning: the use of `mktemp' is dangerous, better use `mkstemp'
networking/lib.a(ipcalc.o): In function `ipcalc_main':
ipcalc.c:(.text.ipcalc_main+0x25c): warning: Using 'gethostbyaddr' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
libbb/lib.a(inet_common.o): In function `INET_resolve':
inet_common.c:(.text.INET_resolve+0x60): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
networking/lib.a(inetd.o): In function `reread_config_file':
inetd.c:(.text.reread_config_file+0x230): warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
networking/lib.a(netstat.o): In function `ip_port_str':
netstat.c:(.text.ip_port_str+0x50): warning: Using 'getservbyport' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
util-linux/lib.a(nsenter.o): In function `nsenter_main':
nsenter.c:(.text.nsenter_main+0x1b0): undefined reference to `setns'
collect2: ld returned 1 exit status
Note: if build needs additional libraries, put them in CONFIG_EXTRA_LDLIBS.
Example: CONFIG_EXTRA_LDLIBS="pthread dl tirpc audit pam"
Makefile:717: recipe for target 'busybox_unstripped' failed
make: *** [busybox_unstripped] Error 1 

解决办法:

使用命令进入配置界面,make menuconfig

Linux System Utilities—>nsenter,去掉该选项,重新编译make,

(3)问题三

报错:

networking/lib.a(nslookup.o): In function `print_host':
nslookup.c:(.text.print_host+0x44): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
debianutils/lib.a(mktemp.o): In function `mktemp_main':
mktemp.c:(.text.mktemp_main+0x98): warning: the use of `mktemp' is dangerous, better use `mkstemp'
networking/lib.a(ipcalc.o): In function `ipcalc_main':
ipcalc.c:(.text.ipcalc_main+0x25c): warning: Using 'gethostbyaddr' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
libbb/lib.a(inet_common.o): In function `INET_resolve':
inet_common.c:(.text.INET_resolve+0x60): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
networking/lib.a(inetd.o): In function `reread_config_file':
inetd.c:(.text.reread_config_file+0x230): warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
networking/lib.a(netstat.o): In function `ip_port_str':
netstat.c:(.text.ip_port_str+0x50): warning: Using 'getservbyport' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
coreutils/lib.a(sync.o): In function `sync_main':
sync.c:(.text.sync_main+0x7c): undefined reference to `syncfs'
collect2: ld returned 1 exit status
Note: if build needs additional libraries, put them in CONFIG_EXTRA_LDLIBS.
Example: CONFIG_EXTRA_LDLIBS="pthread dl tirpc audit pam"
Makefile:717: recipe for target 'busybox_unstripped' failed
make: *** [busybox_unstripped] Error 1

解决办法:

使用命令进入配置界面,make menuconfig

Coreutils—>sync去掉该选项,重新make编译通过,生成了busybox可执行文件。

5.完善最小 Linux 系统的文件

(1)进入制作好的system文件,进入改目录,使用命令:cd system ,制作的文件系统还需要 dev,etc,lib,mnt,proc,sys,tmp,var 文件夹,使用命令“mkdir dev etc lib mnt proc sys tmp var”创建文件夹,如下图所示。

在这里插入图片描述
(2)使用命令“cd etc”进入到刚才创建的 etc 文件夹,在 etc 目录下使用命令 vi 或者 vim 建立 eth0-setting 文件,并在 eth0-setting 文件里输 入下面的内容。

在这里插入图片描述

(3)然后保存并退出 eth0-setting,使用“chmod 755 eth0-setting”命令修改 eth0-setting 的权限。

(4)在 etc 目录下用“mkdir init.d”命令建立 init.d 文件夹,然后使用“cd init.d”命令进入到 init.d 文件夹中。在 init.d 文件夹下面使用命令进行创建文件“vim ifconfig-eth0”命令建立 ifconfig-eth0 文件,然后在该文件 ifconfig-eth0 文件输入下面的内容。

#!/bin/sh

echo -n Try to bring eth0 interface up......>/dev/ttySAC2

if [ -f /etc/eth0-setting ] ; then
        source /etc/eth0-setting

        if grep -q "^/dev/root / nfs " /etc/mtab ; then
                echo -n NFS root ... > /dev/ttySAC2
        else
                ifconfig eth0 down
                ifconfig eth0 hw ether $MAC
                ifconfig eth0 $IP netmask $Mask up
                route add default gw $Gateway
        fi

        echo nameserver $DNS > /etc/resolv.conf
else

        if grep -q "^/dev/root / nfs " /etc/mtab ; then
                echo -n NFS root ... > /dev/ttySAC2
        else
        /sbin/ifconfig eth0 192.168.253.12 netmask 255.255.255.0 up
        fi
fi

echo Done > /dev/ttySAC2

(5)然后保存并退出 ifconfig-eth0,使用命令“chmod 755 ifconfig-eth0”修改 ifconfig-eth0 的权限,

(6)在 init.d 文件夹下面使用“vim rcS”命令建立 rcS 文件,然后在 rcS 文件输入下面的内容。

#! /bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:
runlevel=S
prevlevel=N
umask 022
export PATH runlevel prevlevel

#
#       Trap CTRL-C &c only in this shell so we can interrupt subprocesses.
#
trap ":" INT QUIT TSTP
/bin/hostname iTOP-4412

#/bin/mount -n -t proc none /proc
#/bin/mount -n -t sysfs none /sys
#/bin/mount -n -t usbfs none /proc/bus/usb
#/bin/mount -t ramfs none /dev
[ -e /proc/1 ]    || /bin/mount -n -t proc  none /proc
[ -e /sys/class ] || /bin/mount -n -t sysfs none /sys
[ -e /dev/tty ]   || /bin/mount    -t ramfs none /dev

echo /sbin/mdev > /proc/sys/kernel/hotplug
/sbin/mdev -s
#/bin/hotplug
# mounting file system specified in /etc/fstab
mkdir -p /dev/pts
mkdir -p /dev/shm
/bin/mount -n -t devpts none /dev/pts -o mode=0622
/bin/mount -n -t tmpfs tmpfs /dev/shm
#/bin/mount -n -t ramfs none /tmp
#/bin/mount -n -t ramfs none /var
mkdir -p /var/empty
mkdir -p /var/log
mkdir -p /var/log/boa
mkdir -p /var/lock
mkdir -p /var/run
mkdir -p /var/tmp

ln -sf /dev/ttyS2 /dev/tty2
ln -sf /dev/ttyS2 /dev/tty3
ln -sf /dev/ttyS2 /dev/tty4

syslogd
/etc/rc.d/init.d/netd start
echo "                        " > /dev/tty1
echo "Starting networking..." > /dev/tty1
#sleep 1
#/etc/rc.d/init.d/httpd start
#echo "                        " > /dev/tty1
#echo "Starting web server..." > /dev/tty1
#sleep 1
#/etc/rc.d/init.d/leds start
#echo "                        " > /dev/tty1
#echo "Starting leds service..." > /dev/tty1
#echo "                        "
#sleep 1

#echo "*************************************" > /dev/ttySAC2
#echo "     http://www.topeet.com.cn        " > /dev/ttySAC2
#echo "*************************************" > /dev/ttySAC2
#echo "*************************************" 
#echo "     http://www.topeet.com.cn        " 
#echo "*************************************" 


mkdir /mnt/disk

sleep 1
/sbin/ifconfig lo 127.0.0.1
/etc/init.d/ifconfig-eth0

(7)然后保存并退出 rcS,使用命令“chmod 755 rcS ”修改 rcS 的权限。接下来使用“cd …/”命令返回到 init.d 的上一级目录 /etc下,接下来在 /etc 目录下使用命令“vim passwd”建立文件 passwd,如下图。

在这里插入图片描述
(8)在新建立的 passwd 文件输入下面的内容。

root::0:0:root:/:/bin/sh
bin:*:1:1:bin:/bin:
daemon:*:2:2:daemon:/sbin:
nobody:*:99:99:Nobody:/:

(9)然后保存并退出 passwd,使用“chmod 755 passwd”命令修改 passwd 的权限。

(10)接着使用命令“vim profile”在 etc 目录建立 profile 文件,然后在 profile 输入下面的内容

# Ash profile 
# vim: syntax=sh
# No core files by default
ulimit -S -c 0 > /dev/null 2>&1
USER="`id -un`"
LOGNAME=$USER
PS1='[$USER@$HOSTNAME]# '
PATH=$PATH
HOSTNAME=`/bin/hostname`
export USER LOGNAME PS1 PATH

(11)然后保存并退出 profile,使用“chmod 755 profile”命令修改 profile 的权限。

(12)使用“mkdir rc.d”命令在 etc 目录建立文件夹 rc.d,如下图所示。

在这里插入图片描述

(13)然后使用命令“cd rc.d/”进入 rc.d 目录,在 rc.d 目录下使用命令“mkdir init.d”建立 init.d 文件夹。然后使用“cd init.d”命令进入到刚才建立的 init.d 文件夹,接着在 init.d 文件夹,使用“vim netd”命令建立 netd 文件,然后在 netd 文件里面输入下面的内容。

#!/bin/sh
base=inetd
# See how we were called.
case "$1" in
  start)
                /usr/sbin/$base
        ;;
  stop)
        pid=`/bin/pidof $base`
        if [ -n "$pid" ]; then
                kill -9 $pid
        fi
        ;;
esac
exit 0

(14)然后保存并退出 netd,使用“chmod 755 netd”命令修改 netd 的权限。

在这里插入图片描述
(15)然后进入/home/minilinux/system/lib/目录下,因为使用的交叉编译环境和编译内核的相同,所以编译器是/usr/local/arm/arm-2009q3, Busybox 编译生成的二进制文件十一动态链接库的形式运行,所以需要拷贝编译器里面的库文件到 lib 目录,使用下面的命令:
cp /usr/local/arm/arm-2009q3/arm-none-linux-gnueabi/libc/lib/* ./

执行结果如下图所示。

在这里插入图片描述
(16)库文件拷贝完成后,使用“cd …/”命令返回到 system 目录,接下来使用“cd var”命令进入到 var 目录,然后使用“mkdir lib lock log run tmp”命令在 var 目录下建立 lib,lock,log,run, tmp 五个目录。如下图所示。

在这里插入图片描述

(17)至此,文件系统所需要的文件都已经创建好了,使用 cd …/…/命令返回到 system 文件夹的上一级目录,到了这一步,制作好的文件夹“system”,可以在视频教程对应的目录下找到。如果发现 后面的操作命令出现了问题,可以对照着修改文件,看看问题出在什么地方。

在这里插入图片描述

6.安装打包软件和编译

(1)打包工具 make_ext4fs 可以文件系统制作成二进制文件,先来安装一下make_ext4fs 工 具。这个工具是光盘“02_编译器以及烧写工具\tools”目录下的“linux_tools.tgz”压缩文件。
拷贝压缩包“linux_tools.tgz”到 Ubuntu 系统的“/”目录下,注意目录是“/”。如下图所示。

在这里插入图片描述

(2)使用解压命令“tar -vxf linux_tools.tgz”解压即可。
(3)使用命令“cd /home/minilinux/”进入目录“/home/minilinux/”,使用命令 “make_ext4fs -s -l 314572800 -a root -L linux system.img system”生成 system.img 文件系统镜像,如下图所示。
在这里插入图片描述
注意:这里编译的时候,可能会出现编译不通过的情况,请参考7.编译报错的问题(make_ext4fs)

4)接着可以使用 ls 命令查看一下生成的 system.img

在这里插入图片描述

(5)现在已经完成了 linux 文件系统的制作,最终生成的二进制文件system.img。然后烧录到开发板即可。

7.编译报错的问题(make_ext4fs)

报错:
在这里插入图片描述

原因:

原因在于,ubuntu,ia32_libs 被废弃了导致没有32位的lib库。

解决办法:

sudo apt-get install lib32stdc++6
sudo apt-get install lib32z1

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值