一、简介
之前有介绍到 ARM 平台移植 ubuntu 的操作流程,在 RK 系列的平台同样适用,所以这里就不介绍怎么一步步的去对 ubuntu 进行移植,而是怎么将移植的过程编写成脚本,这样便可以在 SDK 中通过一行命令即可生成 rootfs.img 镜像,管理起来也也比较方便,需要裁剪摸个工具时也很便捷。
可能没有进行过系统移植的小伙伴看着比较困难,建议先从前面的笔记看着来,在看这篇笔记就会发现很简单,也可以理解 RK 平台的 SDK 是怎么回事。
二、准备材料
我使用的芯片是RK3588,小伙伴可以根据自己的情况选择开发版。
开发环境:VMware
操作系统:ubuntu
开发版:RK3588
三、Debian 目录
因为 RK 平台的 SDK 中是已经支持 Debian 的,所以我们可以根据 Debian 系统的编译方式来模仿 ubuntu 脚本的编写,这样大大降低了操作的难度,还可以明白系统移植是的流程。
目录 | 作用 |
---|---|
overlay | 适配Rockchip平台共性配置⽂件 |
overlay-debug | 系统常使⽤的调试⼯具 |
overlay-firmware | ⼀些设备firmware的存放,⽐如npu/dp等 |
packages | 包含armhf arm64系统适配硬加速使⽤的预编译的包 |
packages-patches | 预编包,基于官⽅打上的补丁 |
ubuntu-build-service | 从官⽅获取Debian发⾏版,可依赖包和定制安装相关包 |
mk-base-debian.sh | 获取Debian基础包和编译 |
mk-image.sh | 打包⽣成ext4的固件 |
mk-rootfs-buster/bullseye.sh | 适配Rockchip相关硬件加速包 |
mk-rootfs.sh | 指向具体Rootfs版本,⽬前有Buster、Bullseye两个版本 |
readme.md | ⽂档指引 |
注意: 以上这些文件都是与外设相关的,也就是解决安装第三方系统后与硬件环境不兼容问题的关键,这里应该会有小伙伴和一样好奇,这里面的文件是怎么来的,我也没仔细去研究过,但是一定是从官方提供的 external 中编程出来的。
-
配置文件、 .so、.a 文件:可以与 buildroot 进行对比,没猜错的话,一定能在 buildroot 编译输出的目录中能找到。
-
deb 工具包:这里就不用过多的介绍了,看我之前的笔记便可明白
-
ubuntu-build-service/packages 目录下的 deb:这里需要注意一下,这里面的包是编译时宿主机必须具备的环境,并不是厂商提供的,而是从网上下载的,路径如下
live-build_*.deb来源https://mirrors.ustc.edu.cn/debian/pool/main/l/live-build/ debootstrap_*.deb来源https://mirrors.ustc.edu.cn/debian/pool/main/d/debootstrap/
当然也是可以通过 apt 命令进行安装。
了解这些基本信息后,变可以仿照编写一个 ubuntu 编译的脚本。这个工程量还是有点大的,难度虽然不大,但是也是一个比较费时的事,不过好在我在网上找了一下,找到了野火已经编写好了,这里我们就不用重复造轮子了,在这里感谢野火的无私奉献。
四、编译 ubuntu
-
下载地址
shellhttps://github.com/LubanCat/ubuntu/tree/ubuntu22.04
-
编译
shell./mk-base-ubuntu.sh ./mk-ubuntu-rootfs.sh
五、ubuntu 制作过程
-
下载 ubuntu 系统
shellif [ ! -d $TARGET_ROOTFS_DIR ] ; then sudo mkdir -p $TARGET_ROOTFS_DIR if [ ! -e ubuntu-base-20.04.5-base-$ARCH.tar.gz ]; then echo -e "\033[47;36m wget ubuntu-base-20.04-base-x.tar.gz \033[0m" wget -c http://cdimage.ubuntu.com/ubuntu-base/releases/20.04/release/ubuntu-base-20.04.5-base-$ARCH.tar.gz fi sudo tar -xzf ubuntu-base-20.04.5-base-$ARCH.tar.gz -C $TARGET_ROOTFS_DIR/ sudo cp sources.list $TARGET_ROOTFS_DIR/etc/apt/sources.list sudo cp -b /etc/resolv.conf $TARGET_ROOTFS_DIR/etc/resolv.conf 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
不难看出来,这个环节下载 ubuntu 系统,不论选择的版本类型是什么,下载的都是 base 版。
-
构建独立环境
shellfunction mnt() { echo "MOUNTING" sudo mount -t proc /proc ${2}/proc sudo mount -t sysfs /sys ${2}/sys sudo mount -o bind /dev ${2}/dev }
通过挂载 proc、sysfs 和 /dev 是为了构建一个隔离的运行环境,让 chroot 内的程序以为自己运行在一个独立的系统环境中,而不是主机的实际系统环境。
- 挂载 /proc 文件系统: /proc 是一个虚拟文件系统,提供了关于系统内核和进程的信息。
- 挂载 /sys 文件系统: /sys 文件系统包含了关于系统硬件、设备和驱动程序的信息。
- 绑定挂载 /dev 目录: /dev 目录包含了设备文件,用于访问系统的各种硬件设备。
-
进入 chroot 环境
shellcat <<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 ...... ...... ...... EOF
前面已经准备好了独立的 chroot 环境,现在需要的做便是进入 chroot 环境后,安装自己需要的组件即可
-
安装自己所需的工具
shellif [ "$TARGET" == "gnome" ]; then DEBIAN_FRONTEND=noninteractive apt install -y ubuntu-desktop-minimal rsyslog sudo dialog apt-utils ntp evtest onboard mv /var/lib/dpkg/info/ /var/lib/dpkg/info_old/ mkdir /var/lib/dpkg/info/ apt-get update DEBIAN_FRONTEND=noninteractive apt install -y ubuntu-desktop-minimal rsyslog sudo dialog apt-utils ntp evtest onboard mv /var/lib/dpkg/info_old/* /var/lib/dpkg/info/ elif [ "$TARGET" == "xfce" ]; then DEBIAN_FRONTEND=noninteractive apt install -y xubuntu-core onboard rsyslog sudo dialog apt-utils ntp evtest udev mv /var/lib/dpkg/info/ /var/lib/dpkg/info_old/ mkdir /var/lib/dpkg/info/ apt-get update DEBIAN_FRONTEND=noninteractive apt install -y xubuntu-core onboard rsyslog sudo dialog apt-utils ntp evtest udev mv /var/lib/dpkg/info_old/* /var/lib/dpkg/info/ elif [ "$TARGET" == "lite" ]; then DEBIAN_FRONTEND=noninteractive apt install -y rsyslog sudo dialog apt-utils ntp evtest acpid elif [ "$TARGET" == "gnome-full" ]; then DEBIAN_FRONTEND=noninteractive apt install -y ubuntu-desktop-minimal rsyslog sudo dialog apt-utils ntp evtest onboard mv /var/lib/dpkg/info/ /var/lib/dpkg/info_old/ mkdir /var/lib/dpkg/info/ apt-get update DEBIAN_FRONTEND=noninteractive apt install -y ubuntu-desktop-minimal rsyslog sudo dialog apt-utils ntp evtest onboard mv /var/lib/dpkg/info_old/* /var/lib/dpkg/info/ elif [ "$TARGET" == "xfce-full" ]; then DEBIAN_FRONTEND=noninteractive apt install -y xubuntu-desktop onboard rsyslog sudo dialog apt-utils ntp evtest udev mv /var/lib/dpkg/info/ /var/lib/dpkg/info_old/ mkdir /var/lib/dpkg/info/ apt-get update DEBIAN_FRONTEND=noninteractive apt install -y xubuntu-desktop onboard rsyslog sudo dialog apt-utils ntp evtest udev mv /var/lib/dpkg/info_old/* /var/lib/dpkg/info/ fi \${APT_INSTALL} net-tools openssh-server ifupdown alsa-utils ntp network-manager gdb inetutils-ping libssl-dev \ vsftpd tcpdump can-utils i2c-tools strace vim iperf3 ethtool netplan.io toilet htop pciutils usbutils curl \ whiptail gnupg bc xinput gdisk parted gcc sox libsox-fmt-all gpiod libgpiod-dev python3-pip python3-libgpiod \ guvcview \${APT_INSTALL} ttf-wqy-zenhei xfonts-intl-chinese if [[ "$TARGET" == "gnome-full" || "$TARGET" == "xfce-full" ]]; then apt purge ibus firefox -y echo -e "\033[47;36m Install Chinese fonts.................... \033[0m" \${APT_INSTALL} language-pack-zh-hans fonts-noto-cjk-extra gnome-user-docs-zh-hans language-pack-gnome-zh-hans # set default xinput for fcitx \${APT_INSTALL} fcitx fcitx-table fcitx-googlepinyin fcitx-pinyin fcitx-config-gtk sed -i 's/default/fcitx/g' /etc/X11/xinit/xinputrc \${APT_INSTALL} ipython3 jupyter fi if [[ "$TARGET" == "gnome-full" || "$TARGET" == "xfce-full" ]]; then # Uncomment zh_CN.UTF-8 for inclusion in generation sed -i 's/^# *\(zh_CN.UTF-8\)/\1/' /etc/locale.gen echo "LANG=zh_CN.UTF-8" >> /etc/default/locale # Generate locale locale-gen zh_CN.UTF-8 # Export env vars echo "LC_ALL=zh_CN.UTF-8" >> /etc/environment echo "LANG=zh_CN.UTF-8" >> /etc/environment echo "LANGUAGE=zh_CN:zh:en_US:en" >> /etc/environment echo "export LC_ALL=zh_CN.UTF-8" >> /etc/profile.d/zh_CN.sh echo "export LANG=zh_CN.UTF-8" >> /etc/profile.d/zh_CN.sh echo "export LANGUAGE=zh_CN:zh:en_US:en" >> /etc/profile.d/zh_CN.sh \${APT_INSTALL} $(check-language-support) fi if [[ "$TARGET" == "gnome" || "$TARGET" == "gnome-full" ]]; then \${APT_INSTALL} mpv acpid gnome-sound-recorder elif [[ "$TARGET" == "xfce" || "$TARGET" == "xfce-full" ]]; then \${APT_INSTALL} mpv acpid gnome-sound-recorder elif [ "$TARGET" == "lite" ]; then \${APT_INSTALL} fi pip3 install python-periphery Adafruit-Blinka -i https://mirrors.aliyun.com/pypi/simple/
不难看出来,这里的操作都是为了,安装自己所需要的工具,所以需要新增或者裁减时,直接在这里添加即可。
-
创建用户
shellHOST=lubancat # Create User useradd -G sudo -m -s /bin/bash cat passwd cat <<IEOF temppwd temppwd IEOF gpasswd -a cat video gpasswd -a cat audio passwd root <<IEOF root root IEOF
-
允许 root 登录
shellsed -i '/pam_securetty.so/s/^/# /g' /etc/pam.d/login
-
设置主机名
shellecho lubancat > /etc/hostname
-
设置本地时间
shellln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
-
禁用指定服务的等待在线服务单元,以防止启动过程中等待网络服务在线的延迟
shellservices=(NetworkManager systemd-networkd) for service in ${services[@]}; do systemctl mask ${service}-wait-online.service done
-
通过禁用这些单元,系统将不会自动启动相关的 wpa_supplicant 服务
shellsystemctl mask wpa_supplicant-wired@ systemctl mask wpa_supplicant-nl80211@ systemctl mask wpa_supplicant@
-
调整 systemd 日志级别
shell# 将 /etc/systemd/system.conf 文件中的日志级别从 info 改为 warning,减少系统日志的输出。 sed -i 's/#LogLevel=info/LogLevel=warning/' \ /etc/systemd/system.conf # 将日志目标从 journal-or-kmsg 改为 journal,将日志发送到 journal。 sed -i 's/#LogTarget=journal-or-kmsg/LogTarget=journal/' \ /etc/systemd/system.conf
-
检查以确保 sudoers 文件具有 sudo 组的 ref
shellSUDOEXISTS="$(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
-
确保为 %sudo 设置了 NOPASSWD
shellsed -i -e ' /\%sudo/ c \ %sudo ALL=(ALL) NOPASSWD: ALL ' /etc/sudoers
-
清理安装包后退出 chroot 环境
shellapt-get clean rm -rf /var/lib/apt/lists/* sync
-
卸载 proc、sysfs 和 /dev
shell./ch-mount.sh -u $TARGET_ROOTFS_DIR
-
打包系统进行保存
shellDATE=$(date +%Y%m%d) echo -e "\033[47;36m Run tar pack ubuntu-base-$TARGET-$ARCH-$DATE.tar.gz \033[0m" sudo tar zcf ubuntu-base-$TARGET-$ARCH-$DATE.tar.gz $TARGET_ROOTFS_DIR
注意: 看我之前的笔记,你将会发现上面脚本执行的流程和手动操作的环节是一样的。所以这里已经可以将系统打包成镜像后下载测试,建议各位小伙伴都测试一下,加深对系统移植的理解。
测试完成后,便会发现有很多问题,比如硬件环境基本不能使用,界面起不来等各种问题。不要慌,接下来便开始处理这些不兼容的问题,操作方式也很简单,第一篇笔记已经介绍到了,这里就不在赘述了,看操作。
六、平台适配
-
环境准备
shell# 通过选择设置 SOC 和 TARGET 变量的值 if [ ! $SOC ]; then echo "---------------------------------------------------------" echo "please enter soc number:" echo "请输入要构建CPU的序号:" echo "[0] Exit Menu" echo "[1] rk3566/rk3568" echo "[2] rk3588/rk3588s" echo "---------------------------------------------------------" read input case $input in 0) exit;; 1) SOC=rk356x ;; 2) SOC=rk3588 ;; *) echo 'input soc number error, exit !' exit;; esac echo -e "\033[47;36m set SOC=$SOC...... \033[0m" fi if [ ! $TARGET ]; then echo "---------------------------------------------------------" echo "please enter TARGET version number:" echo "请输入要构建的根文件系统版本:" echo "[0] Exit Menu" echo "[1] gnome" echo "[2] xfce" echo "[3] lite" echo "[4] gnome-full" echo "[5] xfce-full" echo "---------------------------------------------------------" read input case $input in 0) exit;; 1) TARGET=gnome ;; 2) TARGET=xfce ;; 3) TARGET=lite ;; 4) TARGET=gnome-full ;; 5) TARGET=xfce-full ;; *) echo -e "\033[47;36m input TARGET version number error, exit ! \033[0m" exit;; esac echo -e "\033[47;36m set TARGET=$TARGET...... \033[0m" fi # 设置 MALI 和 ISP 以及 MIRROR 变量的值 install_packages() { case $SOC in rk3399|rk3399pro) MALI=midgard-t86x-r18p0 ISP=rkisp ;; rk3328|rk3528) MALI=utgard-450 ISP=rkisp ;; rk356x|rk3566|rk3568) MALI=bifrost-g52-g13p0 ISP=rkaiq_rk3568 MIRROR=carp-rk356x ;; rk3588|rk3588s) ISP=rkaiq_rk3588 MALI=valhall-g610-g13p0 MIRROR=carp-rk3588 ;; esac } # 设置 ARCH 变量的值,默认为 arm64 case "${ARCH:-$1}" in arm|arm32|armhf) ARCH=armhf ;; *) ARCH=arm64 ;; esac echo -e "\033[47;36m Building for $ARCH \033[0m" # 设置 VERSION 变量 if [ ! $VERSION ]; then VERSION="release" fi echo -e "\033[47;36m Building for $VERSION \033[0m" # 判断文件是否存在 if [ ! -e ubuntu-base-"$TARGET"-$ARCH-*.tar.gz ]; then echo "\033[41;36m Run mk-base-ubuntu.sh first \033[0m" exit -1 fi # 错误时执行此函数 finish() { sudo umount $TARGET_ROOTFS_DIR/dev exit -1 } trap finish ERR # 将文件 ubuntu-base-$TARGET-$ARCH-*.tar.gz,之前的操作压缩时,文件便是 TARGET_ROOTFS_DIR,所以不用指定目录 echo -e "\033[47;36m Extract image \033[0m" sudo rm -rf $TARGET_ROOTFS_DIR sudo tar -xpf ubuntu-base-$TARGET-$ARCH-*.tar.gz
这里的操作没啥好说的,主要将之前打包的系统再次解压出来,并配置一些变量
-
拷贝相关的 deb 包
shell# 将文件 ubuntu-base-$TARGET-$ARCH-*.tar.gz,之前的操作压缩时,文件便是 TARGET_ROOTFS_DIR,所以不用指定目录 echo -e "\033[47;36m Extract image \033[0m" sudo rm -rf $TARGET_ROOTFS_DIR sudo tar -xpf ubuntu-base-$TARGET-$ARCH-*.tar.gz # 将 所有的 deb 文件拷贝到指定目录 # packages folder sudo mkdir -p $TARGET_ROOTFS_DIR/packages sudo cp -rpf packages/$ARCH/* $TARGET_ROOTFS_DIR/packages # 根据 SOC 拷贝 GPU/CAMERA 对应的 deb 包 #GPU/CAMERA packages folder install_packages sudo mkdir -p $TARGET_ROOTFS_DIR/packages/install_packages sudo cp -rpf packages/$ARCH/libmali/libmali-*$MALI*-x11*.deb $TARGET_ROOTFS_DIR/packages/install_packages sudo cp -rpf packages/$ARCH/${ISP:0:5}/camera_engine_$ISP*.deb $TARGET_ROOTFS_DIR/packages/install_packages #linux kernel deb if [ -e ../linux-headers* ]; then Image_Deb=$(basename ../linux-headers*) sudo mkdir -p $TARGET_ROOTFS_DIR/boot/kerneldeb sudo touch $TARGET_ROOTFS_DIR/boot/build-host sudo cp -vrpf ../${Image_Deb} $TARGET_ROOTFS_DIR/boot/kerneldeb sudo cp -vrpf ../${Image_Deb/headers/image} $TARGET_ROOTFS_DIR/boot/kerneldeb fi # 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 -rpf overlay-debug/* $TARGET_ROOTFS_DIR/ fi ## hack the 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 echo -e "\033[47;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
-
进入 chroot 环境
shellsudo mount -o bind /dev $TARGET_ROOTFS_DIR/dev # 使用 stat 命令获取指定文件或目录的用户 ID,并将其存储在变量 ID 中, 默认情况下是 0 ID=$(stat --format %u $TARGET_ROOTFS_DIR) cat << EOF | sudo chroot $TARGET_ROOTFS_DIR # 修复程序所有者 # Fixup owners if [ "$ID" -ne 0 ]; then find / -user $ID -exec chown -h 0:0 {} \; fi for u in \$(ls /home/); do chown -h -R \$u:\$u /home/\$u done # 根据 $MIRROR 变量的值配置 Embedfire 的软件源 if [ $MIRROR ]; then mkdir -p /etc/apt/keyrings curl -fsSL https://Embedfire.github.io/keyfile | gpg --dearmor -o /etc/apt/keyrings/embedfire.gpg chmod a+r /etc/apt/keyrings/embedfire.gpg echo "deb [arch=arm64 signed-by=/etc/apt/keyrings/embedfire.gpg] https://cloud.embedfire.com/mirrors/ebf-debian carp-lbc main" | tee /etc/apt/sources.list.d/embedfire-lbc.list > /dev/null echo "deb [arch=arm64 signed-by=/etc/apt/keyrings/embedfire.gpg] https://cloud.embedfire.com/mirrors/ebf-debian $MIRROR main" | tee /etc/apt/sources.list.d/embedfire-$MIRROR.list > /dev/null fi export LC_ALL=C.UTF-8 apt-get update apt-get upgrade -y 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"
-
配置桌面
shellecho -e "\033[47;36m ---------- LubanCat -------- \033[0m" \${APT_INSTALL} fire-config u-boot-tools logrotate if [[ "$TARGET" == "gnome" || "$TARGET" == "gnome-full" ]]; then \${APT_INSTALL} gdisk fire-config-gui #Desktop background picture ln -sf /usr/share/xfce4/backdrops/lubancat-wallpaper.png /usr/share/backgrounds/warty-final-ubuntu.png elif [[ "$TARGET" == "xfce" || "$TARGET" == "xfce-full" ]]; then \apt-get remove -y gnome-bluetooth \${APT_INSTALL} bluez bluez-tools fire-config-gui #Desktop background picture ln -sf /usr/share/xfce4/backdrops/lubancat-wallpaper.png /usr/share/xfce4/backdrops/xubuntu-wallpaper.png elif [ "$TARGET" == "lite" ]; then \${APT_INSTALL} bluez bluez-tools fi
-
安装平台工具包
shellapt install -fy --allow-downgrades /packages/install_packages/*.deb apt install -fy --allow-downgrades /boot/kerneldeb/* || true if [[ "$TARGET" == "gnome" || "$TARGET" == "xfce" || "$TARGET" == "gnome-full" || "$TARGET" == "xfce-full" ]]; then echo -e "\033[47;36m ----- power management ----- \033[0m" \${APT_INSTALL} pm-utils triggerhappy bsdmainutils cp /etc/Powermanager/triggerhappy.service /lib/systemd/system/triggerhappy.service fi echo -e "\033[47;36m ----------- RGA ----------- \033[0m" \${APT_INSTALL} /packages/rga2/*.deb if [[ "$TARGET" == "gnome" || "$TARGET" == "xfce" || "$TARGET" == "gnome-full" || "$TARGET" == "xfce-full" ]]; then echo -e "\033[47;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 fi if [[ "$TARGET" == "gnome" || "$TARGET" == "xfce" || "$TARGET" == "gnome-full" || "$TARGET" == "xfce-full" ]]; then echo -e "\033[47;36m ----- Install Camera ----- - \033[0m" \${APT_INSTALL} cheese v4l-utils \${APT_INSTALL} /packages/libv4l/*.deb elif [ "$TARGET" == "lite" ]; then echo -e "\033[47;36m ----- Install Camera ----- - \033[0m" \${APT_INSTALL} v4l-utils \${APT_INSTALL} /packages/mpp/* fi if [[ "$TARGET" == "gnome" || "$TARGET" == "gnome-full" ]]; then echo -e "\033[47;36m ----- Install Xserver------- \033[0m" \${APT_INSTALL} /packages/xserver/xserver-xorg-*.deb apt-mark hold xserver-xorg-core xserver-xorg-legacy elif [[ "$TARGET" == "xfce" || "$TARGET" == "xfce-full" ]]; then echo -e "\033[47;36m ----- Install Xserver------- \033[0m" \${APT_INSTALL} /packages/xserver/*.deb apt-mark hold xserver-common xserver-xorg-core xserver-xorg-legacy fi if [[ "$TARGET" == "gnome" || "$TARGET" == "xfce" || "$TARGET" == "gnome-full" || "$TARGET" == "xfce-full" ]]; then echo -e "\033[47;36m ------ update chromium ----- \033[0m" \${APT_INSTALL} /packages/chromium/*.deb # echo -e "\033[47;36m --------- firefox-esr ------ \033[0m" # \${APT_INSTALL} /packages/firefox/*.deb fi echo -e "\033[47;36m ------- Install libdrm ------ \033[0m" \${APT_INSTALL} /packages/libdrm/*.deb if [[ "$TARGET" == "gnome" || "$TARGET" == "xfce" || "$TARGET" == "gnome-full" || "$TARGET" == "xfce-full" ]]; then echo -e "\033[47;36m ------ 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 fi if [[ "$TARGET" == "gnome" || "$TARGET" == "xfce" || "$TARGET" == "gnome-full" || "$TARGET" == "xfce-full" ]]; then if [ "$VERSION" == "debug" ]; then echo -e "\033[47;36m ------ Install glmark2 ------ \033[0m" \${APT_INSTALL} glmark2-es2 fi fi if [ -e "/usr/lib/aarch64-linux-gnu" ] ; then echo -e "\033[47;36m ------- move rknpu2 --------- \033[0m" mv /packages/rknpu2/*.tar / fi echo -e "\033[47;36m ----- Install rktoolkit ----- \033[0m" \${APT_INSTALL} /packages/rktoolkit/*.deb if [[ "$TARGET" == "gnome" || "$TARGET" == "xfce" || "$TARGET" == "gnome-full" || "$TARGET" == "xfce-full" ]]; then echo -e "\033[47;36m ------ Install ffmpeg ------- \033[0m" \${APT_INSTALL} ffmpeg \${APT_INSTALL} /packages/ffmpeg/*.deb fi if [[ "$TARGET" == "gnome" || "$TARGET" == "xfce" || "$TARGET" == "gnome-full" || "$TARGET" == "xfce-full" ]]; then echo -e "\033[47;36m ------- Install mpv --------- \033[0m" \apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install -y /packages/mpv/*.deb fi if [[ "$TARGET" == "gnome-full" || "$TARGET" == "xfce-full" ]]; then echo -e "\033[47;36m ------ Install scratch ------- \033[0m" \${APT_INSTALL} /packages/embedfire/scratch_*.deb fi
是不是发现这个环节也是挺简单的,需要对平台资源的移植的裁剪时,直接更改这里的操作即可。
-
自定义脚本
shellecho -e "\033[47;36m ------- Custom Script ------- \033[0m" systemctl mask systemd-networkd-wait-online.service systemctl mask NetworkManager-wait-online.service systemctl disable hostapd rm /lib/systemd/system/wpa_supplicant@.service
-
清除后退出 chroot 环境
shellecho -e "\033[47;36m ---------- Clean ----------- \033[0m" if [ -e "/usr/lib/arm-linux-gnueabihf/dri" ] ; then cd /usr/lib/arm-linux-gnueabihf/dri/ cp kms_swrast_dri.so swrast_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 / rm /usr/lib/aarch64-linux-gnu/dri/*.so mv /*.so /usr/lib/aarch64-linux-gnu/dri/ rm /etc/profile.d/qt.sh fi rm -rf /home/$(whoami) rm -rf /var/lib/apt/lists/* rm -rf /var/cache/ rm -rf /packages/ rm -rf /boot/*
注意: 关于上面提到平台相关的 deb 是怎么来的,在文章的开头变介绍了,这里就不过多描述。可以多参看一下 buildroot 的操作过程,熟悉后,基本可以轻松了解整个环节
七、镜像打包
shell
#!/bin/bash -e
TARGET_ROOTFS_DIR=./binary
MOUNTPOINT=./rootfs
ROOTFSIMAGE=ubuntu-$IMAGE_VERSION-rootfs.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=7000
finish() {
sudo umount ${MOUNTPOINT} || true
echo -e "[ MAKE ROOTFS FAILED. ]"
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}
将会发现整个打包的过程也比较简单,前面也有笔记进行介绍。
八、总结
到此我们对于 ARM 环境中安装系统的操作基本结束了,看到这里都没什么问题的小伙伴也彻底掌握了移植的流程和移植过程中的问题处理。剩下的就是时间问题。
给大家的建议也很简单,在学习的时候,一定要多练习,有时候脑子是明白了,一操作感觉又啥都不会,在练习的过程中,可以帮助自己理解。
这里我们再次感谢野火的无私奉献,他们的脚本,帮助我们快速学习 ubuntu 环境的安装,大大省去了自己编写脚本的过程,特别像我们这样对编写 shell 脚本熟练不是很高的小伙伴,话的时间会更久。
最后便可以学习 android 和 鸿蒙系统的安装,由于我也在学习的过程中,还要自己的工作要处理,所以后面的笔记出的会慢一些。也欢迎大家一起加入学习的队伍中来,相互分型,共同加快学习的速度。