0%

busybox 任意toolchain 制作动态版本

1
2
3
4
5
mkdir riscv_build
export CROSS_COMPILE=riscv64-mti-linux-gnu- ARCH=riscv
make defconfig O=riscv_build
make -j12
make install O=riscv_build

上述默认为动态编译

如果需要静态编译

1
2
3
4
5
6
make menuconfig O=riscv_build

Location:
-> Busybox Settings
-> Build Options
[*] Build BusyBox as a static binary (no shared libs)

融合动态库

1
2
3
4
5
6
7
8
9
10
11
#riscv_build/_install 为 busybox 等生成的目录
rsync -rl <toolchain_path>/sysroot/riscv/ _install/ #融合系统目录

# 生成 init
cd _install
ln -s bin/busybox init

# 删除 _install 下的所有 *.o *.a 文件, 缩小体积
cd _install
find . -type f -name "*. O" | xargs rm -f
find . -type f -name "*. A" | xargs rm -f

生成 cpiogz 最终文件

1
2
把 install.sh 拷过来放到 riscv_build下
执行 ./install.sh

install.sh 脚本内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
sudo rm -rf rootfs
mkdir rootfs
cd rootfs

cp -r ../_install/* .
mkdir dev usr bin sbin lib etc proc tmp sys var root mnt
cd etc
cat > inittab <<- EOF
::sysinit:/etc/init.d/rcS
::respawn:-/bin/login
::restart:/sbin/init
::ctrlaltdel:/sbin/reboot
::shutdown:/bin/umount -a -r
::shutdown:/sbin/swapoff -a
EOF

cat > profile <<- EOF
# /etc/profile: system-wide .profile file for the Bourne shells
echo
# echo -n "Processing /etc/profile..."
# no-op
# Set search library path
# echo "Set search library path in /etc/profile"
export LD_LIBRARY_PATH=/lib:/usr/lib
# Set user path
# echo "Set user path in /etc/profile"
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
# Set PS1
# Note: In addition to the SHELL variable, ash supports \u, \h, \W, \$, \!, \n, \w, \nnn (octal numbers corresponding to ASCII characters)
# And \e[xx;xxm (color effects), etc.
# Also add an extra '\' in front of it!
# echo "Set PS1 in /etc/profile"
export PS1="\\e[00;32m[$USER@\\w\\a]\\$\\e[00;34m"
# echo "Done"
alias ll='ls -al'
EOF


cat > fstab <<- EOF
proc /proc proc defaults 0 0
none /tmp tmpfs defaults 0 0
mdev /dev tmpfs defaults 0 0
sysfs /sys sysfs defaults 0 0
EOF

cat > passwd <<- EOF
root:x:0:0:root:/root:/bin/sh
EOF

cat > group <<- EOF
root:x:0:root
EOF

cat > shadow <<- EOF
root:4rs6NCNMjYULk:19366:0:99999:7:::
EOF

mkdir init.d
cd init.d

cat > rcS <<- EOF
#! /bin/sh
#echo "----------mount all"
/bin/mount -a
#echo "----------Starting mdev......"
#/bin/echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s
echo "********************************************************"
echo " mini Rootfs"
echo "********************************************************"
EOF

cd ../../dev
sudo mknod -m 666 console c 5 1
sudo mknod -m 666 null c 1 3
cd ../

sudo chmod 777 etc/init.d/rcS

ln -s bin/busybox init
cd ../
sudo chown -R root:root rootfs
cd rootfs
find .| cpio -o -H newc | gzip > ../busybox_rootfs.cpio.gz