参考链接:https://www.bilibili.com/read/cv33377580/?spm_id_from=333.999.0.0
感谢作者,按照参考链接,首先制作四个shell文件
shell文件
1.ch-mount.sh
#!/bin/bash
function mnt() {
echo "MOUNTING"
sudo mount -t proc /proc ${2}/proc
sudo mount -t sysfs /sys ${2}/sys
sudo mount -o bind /dev ${2}/dev
sudo mount -o bind /dev/pts ${2}/dev/pts
}
function umnt() {
echo "UNMOUNTING"
sudo umount ${2}/proc
sudo umount ${2}/sys
sudo umount ${2}/dev/pts
sudo umount ${2}/dev
}
if [ "$1" == "-m" ] && [ -n "$2" ] ;
then
mnt $1 $2
elif [ "$1" == "-u" ] && [ -n "$2" ];
then
umnt $1 $2
else
echo ""
echo "Either 1'st, 2'nd or both parameters were missing"
echo ""
echo "1'st parameter can be one of these: -m(mount) OR -u(umount)"
echo "2'nd parameter is the full path of rootfs directory"
echo ""
echo "For example: ch-mount.sh -m /media/sdcard"
echo ""
echo 1st parameter : ${1}
echo 2nd parameter : ${2}
fi
2.mk-base-ubuntu-tspi.sh
#!/bin/bash -e
if [ "$ARCH" == "armhf" ]; then
ARCH='armhf'
elif [ "$ARCH" == "arm64" ]; then
ARCH='arm64'
else
echo -e "\033[36m please input the os type,armhf or arm64...... \033[0m"
fi
VERSION="debug"
TARGET_ROOTFS_DIR="binary"
user_install_list=(
"rsyslog" #系统日志
"dialog" #交互对话框
"sudo" #超级用户(root)的权限执行命令
"vim" #装个vim方便修改文件
"apt-utils" #包管理工具
"net-tools" #网络工具的软件包,包含ifconfig、arp、netstat 等
"inetutils-ping" #ping 我习惯用了但是好像被遗废掉了
"onboard" #虚拟键盘
"evtest" #事件工具
"udev" #设备管理的子系统
"language-pack-zh-hans" #中文语言支持,包括界面、帮助文件等。
)
if [ -e ubuntu22.04-whole.tar.gz ]; then
sudo rm -rf ubuntu22.04-whole.tar.gz
fi
if [ -d $TARGET_ROOTFS_DIR ] ; then
sudo rm -rf $TARGET_ROOTFS_DIR
fi
if [ ! -d $TARGET_ROOTFS_DIR ] ; then
sudo mkdir -p $TARGET_ROOTFS_DIR
if [ ! -e ubuntu-base-22.04.4-base-$ARCH.tar.gz ]; then
echo "\033[36m wget ubuntu-base-22.04-base-x.tar.gz \033[0m"
wget -c http://cdimage.ubuntu.com/ubuntu-base/releases/22.04.4/release/ubuntu-base-22.04.4-base-$ARCH.tar.gz
fi
sudo tar -xzvf ubuntu-base-22.04.4-base-$ARCH.tar.gz -C $TARGET_ROOTFS_DIR/
sudo cp -b /etc/resolv.conf $TARGET_ROOTFS_DIR/etc/resolv.conf
sudo cp -b sources.list $TARGET_ROOTFS_DIR/etc/apt/
if [ "$ARCH" == "armhf" ]; then
sudo cp -b /usr/bin/qemu-arm-static $TARGET_ROOTFS_DIR/usr/bin/
elif [ "$ARCH" == "arm64" ]; then
sudo cp -b /usr/bin/qemu-aarch64-static $TARGET_ROOTFS_DIR/usr/bin/
fi
fi
finish() {
./ch-mount.sh -u $TARGET_ROOTFS_DIR
echo -e "error exit"
exit -1
}
trap finish ERR
echo "\033[36m Change root.....................\033[0m"
./ch-mount.sh -m $TARGET_ROOTFS_DIR
cat <<EOF | sudo chroot $TARGET_ROOTFS_DIR/
export APT_INSTALL="apt-get install -fy --allow-downgrades"
export LC_ALL=C.UTF-8
apt-get -y update
apt-get -f -y upgrade
#--------- Xfce -----
DEBIAN_FRONTEND=noninteractive apt install -y xubuntu-core
#------------------user isntall------------
\${APT_INSTALL} ${user_install_list[@]}
HOST=lckfb
# Create User
useradd -G sudo -m -s /bin/bash lckfb
passwd lckfb <<IEOF
lckfb
lckfb
IEOF
gpasswd -a lckfb video
gpasswd -a lckfb audio
passwd root <<IEOF
root
root
IEOF
# Enable lightdm autologin for linaro user
if [ -e /etc/gdm3/custom.conf ]; then
sed -i "s|^# AutomaticLogin=.*|AutomaticLogin=lckfb|" /etc/gdm3/custom.conf
sed -i "s|^# AutomaticLoginEnable=.*|AutomaticLoginEnable=true|" /etc/gdm3/custom.conf
fi
# workaround 90s delay
services=(NetworkManager systemd-networkd)
for service in \${services[@]}; do
systemctl mask \${service}-wait-online.service
done
# disbale the wire/nl80211
systemctl mask wpa_supplicant-wired@
systemctl mask wpa_supplicant-nl80211@
systemctl mask wpa_supplicant@
# Make systemd less spammy
sed -i 's/#LogLevel=info/LogLevel=warning/' \
/etc/systemd/system.conf
sed -i 's/#LogTarget=journal-or-kmsg/LogTarget=journal/' \
/etc/systemd/system.conf
# check to make sure sudoers file has ref for the sudo group
SUDOEXISTS="\$(awk '\$1 == "%sudo" { print \$1 }' /etc/sudoers)"
if [ -z "\$SUDOEXISTS" ]; then
# append sudo entry to sudoers
echo "# Members of the sudo group may gain root privileges" >> /etc/sudoers
echo "%sudo ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
fi
# make sure that NOPASSWD is set for %sudo
# expecially in the case that we didn't add it to /etc/sudoers
# just blow the %sudo line away and force it to be NOPASSWD
sed -i -e '
/\%sudo/ c \
%sudo ALL=(ALL) NOPASSWD: ALL
' /etc/sudoers
sync
EOF
./ch-mount.sh -u $TARGET_ROOTFS_DIR
sudo tar zcvf ubuntu22.04-whole.tar.gz $TARGET_ROOTFS_DIR
sudo rm $TARGET_ROOTFS_DIR -r
echo -e "normal exit"
3.post-build.sh
#!/bin/bash -e
TARGET_DIR=$1
shift
RK_LEGACY_PARTITIONS=" \
${RK_OEM_FS_TYPE:+oem:/oem:${RK_OEM_FS_TYPE}}
${RK_USERDATA_FS_TYPE:+userdata:/userdata:${RK_USERDATA_FS_TYPE}}
"
# <dev>:<mount point>:<fs type>:<source dir>, for example:
# RK_EXTRA_PARTITIONS="oem:/oem:ext2:oem_normal userdata:/userdata:vfat:userdata_empty"
RK_EXTRA_PARTITIONS=${RK_EXTRA_PARTITIONS:-${RK_LEGACY_PARTITIONS}}
function fixup_root()
{
echo "Fixing up rootfs type: $1"
FS_TYPE=$1
sed -i "s#\([[:space:]]/[[:space:]]\+\)\w\+#\1${FS_TYPE}#" \
${TARGET_DIR}/etc/fstab
}
function fixup_part()
{
echo "Fixing up partition: $@"
if echo $1 | grep -qE "^/"; then
DEV=$1
else
DEV="PARTLABEL=$1"
fi
MOUNT=${2:-/$1}
FS_TYPE=${3:-auto}
OPT=${4:-defaults}
sed -i "#[[:space:]]${MOUNT}[[:space:]]#d" ${TARGET_DIR}/etc/fstab
echo -e "${DEV}\t${MOUNT}\t${FS_TYPE}\t${OPT}\t0 2" >> \
${TARGET_DIR}/etc/fstab
mkdir -p ${TARGET_DIR}/${MOUNT}
}
function fixup_fstab()
{
echo "Fixing up /etc/fstab..."
case "${RK_ROOTFS_TYPE}" in
ext[234])
fixup_root ${RK_ROOTFS_TYPE}
;;
*)
fixup_root auto
;;
esac
for part in ${RK_EXTRA_PARTITIONS}; do
fixup_part $(echo "${part}" | xargs -d':')
done
}
function add_build_info()
{
[ -f ${TARGET_DIR}/etc/os-release ] && \
sed -i "/^BUILD_ID=/d" ${TARGET_DIR}/etc/os-release
echo "Adding build-info to /etc/os-release..."
echo "BUILD_INFO=\"$(whoami)@$(hostname) $(date)${@:+ - $@}\"" >> \
${TARGET_DIR}/etc/os-release
}
function add_dirs_and_links()
{
echo "Adding dirs and links..."
cd ${TARGET_DIR}
mkdir -p mnt/sdcard mnt/usb0
ln -sf media/usb0 udisk
ln -sf mnt/sdcard sdcard
ln -sf userdata data
}
echo "Executing $(basename $0)..."
add_build_info $@
[ -f ${TARGET_DIR}/etc/fstab ] && fixup_fstab
add_dirs_and_links
exit 0
4.mk-rootfs-tspi.sh
#!/bin/bash -e
TARGET_ROOTFS_DIR="binary"
case "${ARCH:-$1}" in
arm|arm32|armhf)
ARCH=armhf
;;
*)
ARCH=arm64
;;
esac
echo -e "\033[36m Building for $ARCH \033[0m"
if [ ! $VERSION ]; then
VERSION="release"
fi
if [ -e $TARGET_ROOTFS_DIR ]; then
sudo rm -rf $TARGET_ROOTFS_DIR
fi
if [ ! -e ubuntu22.04-whole.tar.gz ]; then
echo "\033[36m Run mk-base-ubuntu.sh first \033[0m"
exit -1
fi
finish() {
sudo umount $TARGET_ROOTFS_DIR/dev
exit -1
}
trap finish ERR
echo -e "\033[36m Extract image \033[0m"
sudo tar -xpf ubuntu22.04-whole.tar.gz
# packages folder
sudo mkdir -p $TARGET_ROOTFS_DIR/packages
sudo cp -rpf packages/$ARCH/* $TARGET_ROOTFS_DIR/packages
# overlay folder
sudo cp -rpf overlay/* $TARGET_ROOTFS_DIR/
# overlay-firmware folder
sudo cp -rpf overlay-firmware/* $TARGET_ROOTFS_DIR/
# overlay-debug folder
# adb, video, camera test file
if [ "$VERSION" == "debug" ]; then
sudo cp -rf overlay-debug/* $TARGET_ROOTFS_DIR/
fi
## serial
sudo cp -f overlay/usr/lib/systemd/system/serial-getty@.service $TARGET_ROOTFS_DIR/lib/systemd/system/serial-getty@.service
# adb
if [[ "$ARCH" == "armhf" && "$VERSION" == "debug" ]]; then
sudo cp -f overlay-debug/usr/local/share/adb/adbd-32 $TARGET_ROOTFS_DIR/usr/bin/adbd
elif [[ "$ARCH" == "arm64" && "$VERSION" == "debug" ]]; then
sudo cp -f overlay-debug/usr/local/share/adb/adbd-64 $TARGET_ROOTFS_DIR/usr/bin/adbd
fi
# bt/wifi firmware
sudo mkdir -p $TARGET_ROOTFS_DIR/system/lib/modules/
sudo mkdir -p $TARGET_ROOTFS_DIR/vendor/etc
sudo find ./kernel/drivers/net/wireless/rockchip_wlan/* -name "*.ko" | \
xargs -n1 -i sudo cp {} $TARGET_ROOTFS_DIR/system/lib/modules/
echo -e "\033[36m Change root.....................\033[0m"
if [ "$ARCH" == "armhf" ]; then
sudo cp /usr/bin/qemu-arm-static $TARGET_ROOTFS_DIR/usr/bin/
elif [ "$ARCH" == "arm64" ]; then
sudo cp /usr/bin/qemu-aarch64-static $TARGET_ROOTFS_DIR/usr/bin/
fi
sudo cp -f /etc/resolv.conf $TARGET_ROOTFS_DIR/etc/
sudo cp -f sources.list $TARGET_ROOTFS_DIR/etc/apt/
sudo mount -o bind /dev $TARGET_ROOTFS_DIR/dev
sudo mount -o bind /dev/pts $TARGET_ROOTFS_DIR/dev/pts
cat << EOF | sudo chroot $TARGET_ROOTFS_DIR
export LC_ALL=C.UTF-8
apt-get update
apt-get upgrade -y
apt-get install -fy
chmod o+x /usr/lib/dbus-1.0/dbus-daemon-launch-helper
chmod +x /etc/rc.local
export APT_INSTALL="apt-get install -fy --allow-downgrades"
#---------------Pre-packages --------------
\${APT_INSTALL} bsdmainutils parole
apt remove -fy firefox totem
#---------------Rga--------------
\${APT_INSTALL} /packages/rga/*.deb
echo -e "\033[36m Setup Video.................... \033[0m"
\${APT_INSTALL} gstreamer1.0-plugins-bad gstreamer1.0-plugins-base gstreamer1.0-tools gstreamer1.0-alsa \
gstreamer1.0-plugins-base-apps qtmultimedia5-examples
\${APT_INSTALL} /packages/mpp/*
\${APT_INSTALL} /packages/gst-rkmpp/*.deb
#\${APT_INSTALL} /packages/gstreamer/*.deb
#\${APT_INSTALL} /packages/gst-plugins-base1.0/*.deb
#\${APT_INSTALL} /packages/gst-plugins-bad1.0/*.deb
#\${APT_INSTALL} /packages/gst-plugins-good1.0/*.deb
#---------Camera---------
echo -e "\033[36m Install camera.................... \033[0m"
\${APT_INSTALL} cheese v4l-utils
#\${APT_INSTALL} /packages/rkisp/*.deb
\${APT_INSTALL} /packages/rkaiq/*.deb
\${APT_INSTALL} /packages/libv4l/*.deb
#---------Xserver---------
echo -e "\033[36m Install Xserver.................... \033[0m"
#\${APT_INSTALL} /packages/xserver/*.deb
dpkg -i /packages/xserver/*.deb
apt install -f -y
apt-mark hold xserver-xorg-core
#---------update chromium-----
\${APT_INSTALL} libjsoncpp-dev libminizip1
\${APT_INSTALL} /packages/chromium/*.deb
#------------------libdrm------------
echo -e "\033[36m Install libdrm.................... \033[0m"
\${APT_INSTALL} /packages/libdrm/*.deb
#------------------libdrm-cursor------------
echo -e "\033[36m Install libdrm-cursor.................... \033[0m"
\${APT_INSTALL} /packages/libdrm-cursor/*.deb
# Only preload libdrm-cursor for X
sed -i "/libdrm-cursor.so/d" /etc/ld.so.preload
sed -i "1aexport LD_PRELOAD=libdrm-cursor.so.1" /usr/bin/X
#------------------blueman------------
echo -e "\033[36m Install blueman.................... \033[0m"
\${APT_INSTALL} /packages/blueman/*.deb
#------------------rkwifibt------------
echo -e "\033[36m Install rkwifibt.................... \033[0m"
\${APT_INSTALL} /packages/rkwifibt/*.deb
ln -s /system/etc/firmware /vendor/etc/
if [ "$VERSION" == "debug" ]; then
#------------------glmark2------------
echo -e "\033[36m Install glmark2.................... \033[0m"
\${APT_INSTALL} glmark2-es2
fi
#------------------rknpu2------------
echo -e "\033[36m Install rknpu2.................... \033[0m"
tar xvf /packages/rknpu2/*.tar -C /
#------------------rktoolkit------------
echo -e "\033[36m Install rktoolkit.................... \033[0m"
\${APT_INSTALL} /packages/rktoolkit/*.deb
#------------------apt-utils------------
apt-get install -y apt-utils
apt-get install -y dialog
#------------------ffmpeg------------
\${APT_INSTALL} /packages/ffmpeg/*.deb
#------------------mpv------------
\${APT_INSTALL} smplayer
\${APT_INSTALL} /packages/mpv/*.deb
mv /etc/mpv/mpv-rk.conf /etc/mpv/mpv.conf
cp /packages/libmali/libmali-*-x11*.deb /
cp -rf /packages/rkaiq/*.deb /
# reduce 500M size for rootfs
rm -rf /usr/lib/firmware
sed -i "/exit 0/i \ echo 3 > /sys/class/graphics/fb0/blank" /etc/rc.local
#------remove unused packages------------
apt remove --purge -fy linux-firmware*
#---------------Clean--------------
if [ -e "/usr/lib/arm-linux-gnueabihf/dri" ]; then
cd /usr/lib/arm-linux-gnueabihf/dri/
cp kms_swrast_dri.so swrast_dri.so rockchip_dri.so /
rm /usr/lib/arm-linux-gnueabihf/dri/*.so
mv /*.so /usr/lib/arm-linux-gnueabihf/dri/
elif [ -e "/usr/lib/aarch64-linux-gnu/dri" ]; then
cd /usr/lib/aarch64-linux-gnu/dri/
cp kms_swrast_dri.so swrast_dri.so rockchip_dri.so /
rm /usr/lib/aarch64-linux-gnu/dri/*.so
mv /*.so /usr/lib/aarch64-linux-gnu/dri/
rm /etc/profile.d/qt.sh
fi
cd -
# mark package to hold
apt list --installed | grep -v oldstable | cut -d/ -f1 | xargs apt-mark hold
#---------------Custom Script--------------
systemctl mask systemd-networkd-wait-online.service
systemctl mask NetworkManager-wait-online.service
rm /lib/systemd/system/wpa_supplicant@.service
EOF
sudo umount $TARGET_ROOTFS_DIR/dev
5.mk-image.sh
#!/bin/bash -e
TARGET_ROOTFS_DIR=./binary
MOUNTPOINT=./rootfs
ROOTFSIMAGE=ubuntu-jammy.img
echo Making rootfs!
if [ -e ${ROOTFSIMAGE} ]; then
rm ${ROOTFSIMAGE}
fi
if [ -e ${MOUNTPOINT} ]; then
rm -r ${MOUNTPOINT}
fi
sudo ./post-build.sh $TARGET_ROOTFS_DIR
# Create directories
mkdir ${MOUNTPOINT}
dd if=/dev/zero of=${ROOTFSIMAGE} bs=1M count=0 seek=8000
finish() {
sudo umount ${MOUNTPOINT} || true
echo -e "\e[31m MAKE ROOTFS FAILED.\e[0m"
exit -1
}
echo Format rootfs to ext4
mkfs.ext4 ${ROOTFSIMAGE}
echo Mount rootfs to ${MOUNTPOINT}
sudo mount ${ROOTFSIMAGE} ${MOUNTPOINT}
trap finish ERR
echo Copy rootfs to ${MOUNTPOINT}
sudo cp -rfp ${TARGET_ROOTFS_DIR}/* ${MOUNTPOINT}
echo Umount rootfs
sudo umount ${MOUNTPOINT}
echo Rootfs Image: ${ROOTFSIMAGE}
e2fsck -p -f ${ROOTFSIMAGE}
resize2fs -M ${ROOTFSIMAGE}
6.假添加sources.list镜像源
sudo vim sources.list
#复制以下内容->sources.list
deb http://mirrors.bfsu.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse
deb-src http://mirrors.bfsu.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse
deb http://mirrors.bfsu.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.bfsu.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb http://mirrors.bfsu.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.bfsu.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse
deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse
Ubuntu22.04/18.04根目录文件编译(亲测可行)
1.文件转移
将立创官方给的编译好的kernel文件和未编译的debian文件目录下的文件夹放在上述shell文件放入同一文件下:
![](https://img-blog.csdnimg.cn/direct/4cdab780de954c5b93b47f37636fb04f.jpeg)
![](https://img-blog.csdnimg.cn/direct/06e3b89170004ee7a2aa7dfc618f615d.jpeg)
2.按顺序依次执行shell文件
export ARCH=arm64 RELEASE=jammy
sudo ./mk-base-ubuntu-tspi.sh
export VERSION=debug ARCH=arm64
sudo ./mk-rootfs-tspi.sh
sudo ./mk-image.sh
编译结果
其中ubuntu22.04-whole.tar.gz和ubuntu-base-22.04.4-base-arm64.tar.gz两个压缩包是运行shell自动下载,ubuntu-jammy.img是rootfs根目录镜像。binary是编译完成后的开发板中的根目录系统文件,这个镜像中包含了adb调试工具和wifi驱动以及可视化界面。
![](https://img-blog.csdnimg.cn/direct/6f9b93c7f7974e5a9f1a52f7afa47035.jpeg)