第一部分:busybox移植
1 下载BusyBox 下载链接:Index of /downloads
https://busybox.net/downloads/
源代码解压缩,并进入到源码目录
cd busybox-1.32.0/
make defconfig
make menuconfig
make
make install

执行完上面操作后,源代码同级目录下会生成_install目录,通过cd命令进入_install目录下,添加需要的其他目录。
busybox-1.32.0/_install# mkdir dev etc etc/dropbear etc/init.d etc/rc.d etc/profile.d mnt opt proc root sys tmp var var/log var/www
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
if [ "`id -u`" -eq 0 ]; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin"
fi
export PATH
if [ "${PS1-}" ]; then
if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
# The file bash.bashrc already sets the default PS1.
# PS1='\h:\w\$ '
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
else
if [ "`id -u`" -eq 0 ]; then
PS1='[\u@\h \W]\# '
else
PS1='[\u@\h \W]\$ '
fi
fi
fi
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
busybox-1.32.0/_install# cat etc/profile.d/bash_completion.sh
# Check for interactive bash and that we haven't already been sourced.
if [ -n "$BASH_VERSION" -a -n "$PS1" -a -z "$BASH_COMPLETION_COMPAT_DIR" ]; then
# Check for recent enough version of bash.
bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.}
if [ $bmajor -gt 4 ] || [ $bmajor -eq 4 -a $bminor -ge 1 ]; then
[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion" ] && \
. "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
if shopt -q progcomp && [ -r /usr/share/bash-completion/bash_completion ]; then
# Source completion code.
. /usr/share/bash-completion/bash_completion
fi
fi
unset bash bmajor bminor
fi
2 创建etc/fstab文件,添加以下内容
LABEL=//tmpfs defaults 0 0
none /dev/pts devpts gid=5,mode=620 0 0
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0
none /tmp tmpfs defaults 0 0
3 创建etc/inittab文件
::sysinit:/etc/init.d/rcS
# /bin/ash
#
# Start an askfirst shell on the serial ports
ttyPS0::respawn:-/bin/ash
# What to do when restarting the init
process
::restart:/sbin/init
# What to do before rebooting
::shutdown:/bin/umount -a -r
4 创建etc/passwd文件
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
test:x:1000:1000::/home/test:/bin/sh
5 创建etc/init.d/rcS文件
#!/bin/sh
echo "Starting rcS..."
echo "++ Mounting filesystem"
mount -t sysfs none /sys
mount -t tmpfs none /tmp
echo "++ Setting up mdev"
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s
mkdir -p /dev/pts
mkdir -p /dev/i2c
mount -t devpts devpts /dev/pts
mount -t proc none /proc
/bin/hostname -F /etc/hostname
echo "++ Starting telnet daemon"
telnetd
echo "++ Starting http daemon"
httpd -h /var/www
echo "++ Starting ftp daemon"
tcpsvd 0:21 ftpd ftpd -w /&
echo "++ Starting dropbear (ssh)daemon"
dropbear
/etc/init.d/inotify start
echo "rcS Complete"
for initscript in /etc/rc.d/S[0-9][0-9]*
do
if [ -x $initscript ] ;
then
$initscript start
fi
done
至此,rootfs文件系统算是创建完成了,把整个_install目录下的文件拷贝到嵌入式板卡上Qflash或EMMC对应的文件系统分区,上电即可正常启动。
其它需要的命令和动态库根据项目需要移植,这里介绍一下dropbear-2024.86的移植(ssh scp)。
第二部分:dropbear的移植
dropbear下载链接:Index of /dropbear (ucc.asn.au)
1 解压源代码后,进入源码目录,创建_install目录
cd dropbear-2024.86/
mkdir _install
2 在执行configure
./configure --prefix=/home/zkgx/library/dropbear-2024.86/_install CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ --with-zlib=/home/zkgx/library/zlib-1.2.11/_install --host=arm-linux
3 修改Makefile

4 执行make和make install
make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp"
make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" install
cd _install
5 拷贝到板卡的根文件系统
cp bin/* sbin/* ../../../xilinx/filesys/busybox-1.32.0/_install/usr/sbin/
6 板卡上生产key
cd /etc
mkdir dropbear
cd dropbear
dropbearkey -t rsa -f dropbear_rsa_host_key
dropbearkey -t dss -f dropbear_dss_host_key
然后把生成的key拷贝到原始的根文件系统,其它板卡也可以使用。
登录配置参考:根文件系统添加用户登入功能 - 哔哩哔哩 (bilibili.com)
第三部分:inotifywait移植
该软件用于检测文件变化,可以配合sync同步到emmc或qflash。
1 下载编译
git clone https://github.com/inotify-tools/inotify-tools.git
cd inotify-tools
apt-get install autoconf automake libtool
./autogen.sh
mkdir _install
./configure --prefix=/home/zkgx/library/inotify-tools/_install CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ --host=arm-linux --target=arm-linux --enable-static
make
make install
cd _install/
cp -rf lib/* /home/zkgx/xilinx/filesys/busybox-1.32.0/_install/usr/lib
cp -rf bin/inotifywait /home/zkgx/xilinx/filesys/busybox-1.32.0/_install/usr/bin/
2使用脚本编写
可放在/usr/bin/inotify,作为一个命令使用。
#!/bin/sh
INOTIFYDIR="/root /home /etc/rc.d"
EVENTS=open,create,move,delete,modify,attrib,close_write,moved_to,moved_from
inotifywait -mrq $INOTIFYDIR -e $EVENTS |
while read path action file; do
sync;sync;
done
3启动脚本编写
#! /bin/sh
inotify=/usr/bin/inotify
test -x "$inotify" || exit 0
case "$1" in
start)
echo -n "++ Starting inotify"
start-stop-daemon --start --b --exec $inotify
echo " "
;;
stop)
echo -n "Stopping inotify"
start-stop-daemon --stop --quiet --name inotify
echo " "
;;
*)
echo "Usage: /usr/bin/inotify {start|stop}"
exit 1
esac
exit 0
全部结束!
235



被折叠的 条评论
为什么被折叠?



