準備工作
在搭建系統(tǒng)之前,需要詳細閱讀訊為公司提供的一些資料(雖然他們家資料一直都做的不完善),搭建好用于開發(fā)的Ubuntu虛擬機環(huán)境,熟練使用一些常用工具如燒錄系統(tǒng)的工具RKDevTool、傳輸文件的工具FileZilla、遠程連接工具MobaXterm等等。當然,本章只針對根文件系統(tǒng),uboot、kernel的鏡像文件和驅(qū)動文件需要提前準備好,編譯訊為提供的Rockchip的SDK即可得到這些文件。
最小Ubuntu根文件系統(tǒng)
Ubuntu在鏡像網(wǎng)站Index of / (ubuntu.com)提供了各種版本的鏡像文件,我們從下面的連接下載最小系統(tǒng),之后繼續(xù)安裝桌面軟件包,進行一系列的配置就可以獲得我們需要的系統(tǒng)。
ubuntu-base-20.04.1-base-arm64.tar.gz |
先尋找一個空白的文件夾放置ubuntu-base-20.04.1-base-arm64.tar.gz,然后以root權(quán)限建立一個文件夾,將根文件系統(tǒng)解壓到這個文件夾中。
sudo mkdir ubuntu-rootfs
sudo tar -xvpf ubuntu-base-20.04.5-base-arm64.tar.gz -C ubuntu-rootfs
接下來在Ubuntu虛擬機上模擬運行arm64架構(gòu)的最小文件系統(tǒng),為此需要安裝qemu-user-static。
sudo apt-get install qemu-user-static
# 適用于arm 32位架構(gòu)
sudo cp /usr/bin/qemu-arm-static ubuntu-rootfs/usr/bin/
# 適用于aarch64即arm64架構(gòu)
sudo cp /usr/bin/qemu-aarch64-static ubuntu-rootfs/usr/bin/
為了連接網(wǎng)絡,需要拷貝resolv.conf文件以及配置國內(nèi)的鏡像源。
# 拷貝文件
sudo cp -b /etc/resolv.conf ubuntu-rootfs/etc/resolv.conf
# 修改鏡像源
sudo gedit ubuntu-rootfs/etc/apt/sources.list
下面是阿里云鏡像源,可以直接復制內(nèi)容覆蓋源鏡像列表文件。
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.aliyun.com/ubuntu-ports/ focal main restricted
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ focal main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirrors.aliyun.com/ubuntu-ports/ focal-updates main restricted
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ focal-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://mirrors.aliyun.com/ubuntu-ports/ focal universe
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ focal universe
deb http://mirrors.aliyun.com/ubuntu-ports/ focal-updates universe
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ focal-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://mirrors.aliyun.com/ubuntu-ports/ focal multiverse
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ focal multiverse
deb http://mirrors.aliyun.com/ubuntu-ports/ focal-updates multiverse
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ focal-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://mirrors.aliyun.com/ubuntu-ports/ focal-backports main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ focal-backports main restricted universe multiverse
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu focal partner
# deb-src http://archive.canonical.com/ubuntu focal partner
deb http://mirrors.aliyun.com/ubuntu-ports/ focal-security main restricted
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ focal-security main restricted
deb http://mirrors.aliyun.com/ubuntu-ports/ focal-security universe
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ focal-security universe
deb http://mirrors.aliyun.com/ubuntu-ports/ focal-security multiverse
# deb-src http://mirrors.aliyun.com/ubuntu-ports/ focal-security multiverse
編寫一個掛載腳本mount.sh,方便進入和退出arm64的文件系統(tǒng)
#!/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 -t devpts -o gid=5,mode=620 devpts ${2}dev/pts
sudo mount -o bind /dev/pts ${2}dev/pts
sudo chroot ${2}
}
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(with trailing ‘/’)"
echo ""
echo "For example: ch-mount -m /media/sdcard/"
echo ""
echo 1st parameter : ${1}
echo 2nd parameter : ${2}
fi
更新與安裝
進入arm64的根文件系統(tǒng)后,終端將只能操作arm64的根文件系統(tǒng),通過exit命令退出并返回Ubuntu虛擬機的終端。
# 進入arm64的根文件系統(tǒng)
./mount.sh -m ubuntu-rootfs/
更新并升級根文件系統(tǒng)。
apt update
apt upgrade
安裝一些必要的軟件,如vim、sudo、網(wǎng)絡管理、藍牙管理等等。
apt install apt-utils dialog
apt install vim sudo
apt install bash-completion
apt install net-tools iputils-ping ifupdown ethtool
apt install wireless-tools network-manager
apt install ssh rsync udev htop rsyslog
apt install bluetooth* bluez* blueman*
# 可裝可不裝
apt install curl
apt install openssh-server
apt install git
apt install ffmpeg
配置系統(tǒng)的時區(qū)、文字編碼。
apt install locales tzdata
# 時區(qū)選擇
# Asia/Shanghai
dpkg-reconfigure locales
# 勾選英文和中文環(huán)境
# en_US.UTF-8 UTF-8
# zh_CN.UTF-8 UTF-8
安裝圖形環(huán)境,依賴非常多,占用空間3G多。
apt install ubuntu-desktop
開機默認切換到圖形界面。
systemctl set-default graphical.target
Network-Manager服務會自動配置網(wǎng)卡,但是其默認配置文件將Ethernet加入了黑名單,以至于Ubuntu提示unmanned。
vi /usr/lib/NetworkManager/conf.d/10-globally-managed-devices.conf
# 文件內(nèi)容改為如下內(nèi)容
[keyfile]
unmanaged-devices=*,except:type:ethernet,except:type:wifi,except:type:gsm,except:type:cdma
設置主機名,增加用戶,修改賬戶密碼。
# 主機名
echo "RK3588" > /etc/hostname
# 主機IP地址
echo "127.0.0.1 localhost RK3588" > /etc/hosts
# 添加用戶
useradd -s '/bin/bash' -m -G adm,sudo user
# 設置密碼
passwd user
passwd root
安裝中英文語言包和中文輸入法。
# 英文環(huán)境
apt install language-pack-en-base
apt install language-pack-gnome-en-base
# 中文環(huán)境
apt install language-pack-zh-hans-base
apt install language-pack-gnome-zh-hans-base
# 中文輸入法
apt install ibus-table-wubi ibus-pinyin ibus-sunpinyin
服務配置
桌面環(huán)境需要的包已經(jīng)基本安裝完成,接下來需要一些別的配置。
Ubuntu根文件系統(tǒng)打包成鏡像并燒錄到emmc后,所占分區(qū)大小和鏡像的大小一樣,為了充分利用emmc的空間,需要在第一次運行時擴充分區(qū)大小。根據(jù)parameter.txt中rootfs分區(qū)對應的名稱配置, 默認是對/dev/mmcblk0p6分區(qū)進行擴充。創(chuàng)建一個腳本和服務來擴充分區(qū)。
vi etc/init.d/firstboot.sh
# 以下是firstboot.sh的內(nèi)容
#!/bin/bash -e
# first boot configure
# resize filesystem mmcblk0p6
if [ ! -e "/usr/local/first_boot_flag" ] ;
then
echo "Resizing /dev/mmcblk0p6..."
resize2fs /dev/mmcblk0p6
touch /usr/local/first_boot_flag
fi
添加運行權(quán)限。
chmod +x etc/init.d/firstboot.sh
vi lib/systemd/system/firstboot.service
# 以下是firstboot.service的內(nèi)容
#start
[Unit]
Description=Setup rockchip platform environment
Before=lightdm.service
After=resize-helper.service
[Service]
Type=simple
ExecStart=/etc/init.d/firstboot.sh
[Install]
WantedBy=multi-user.target
#end
啟動firstboot.service服務。
systemctl enable firstboot.service
啟用ssh的root帳號登錄。
vi /etc/ssh/sshd_config
# 將下面這項設置成yes
PermitRootLogin yes
Ubuntu默認不能用root登錄界面,可以配置啟用以root登錄界面。
vi /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf
# 添加下面的內(nèi)容
greeter-show-manual-login=true
all-guest=false
vi /etc/pam.d/gdm-autologin
# 注釋掉下面這行
#auth required pam_succeed_if.so user != root quiet_success
vi /etc/pam.d/gdm-password
# 注釋掉下面這行
#auth required pam_succeed_if.so user != root quiet_success
vi /root/.profile
# 添加下面的內(nèi)容,替換掉 mesg n || true 這一行
tty -s && mesg n || true
可以設置界面的自動登錄。
vi /etc/gdm3/custom.conf
# 添加下面的內(nèi)容,user即賬戶名
[daemon]
AutomaticLoginEnable=true
AutomaticLogin=user
TimedLoginEnable=true
TimedLogin=user
TimedLoginDelay=10
為方便在沒有網(wǎng)絡的時候調(diào)試,設置通過串口登錄root。
vi /lib/systemd/system/serial-getty\@.service
# 替換ExecStart這行
ExecStart=-/sbin/agetty --autologin root --noclear %I $TERM
打包鏡像
退出arm64文件系統(tǒng)環(huán)境,回到宿主機環(huán)境,卸載掛載的目錄
# 退出arm64的根文件系統(tǒng)
exit
# 卸載掛載的目錄
./mount.sh -u ubuntu-rootfs/
訊為RK3588平臺采用RTL8723du這款wifi和Bluetooth二合一基于USB總線的無線設備,其驅(qū)動被編譯成了模塊,需要安裝這些模塊才能啟用無線和藍牙,其中藍牙還需要RTL官方的固件。這些文件可以在編譯Debian后的輸出目錄的中(/lib/firmware)找到,需要將這些文件拷貝到我們的根文件系統(tǒng)中。8723du.ko是wifi的驅(qū)動,rtk_btusb.ko是藍牙的驅(qū)動。
# copy 8723du.ko to ubuntu-rootfs/lib/modules/5.10.66
# copy rtk_btusb.ko to ubuntu-rootfs/lib/modules/5.10.66
# copy rtl8723du_config rtl8723du_fw to /lib/firmware
# Linux會自動安裝modprobe安裝過的驅(qū)動
# depmod也許會提示缺少modules.order modules.builtin文件,這些文件是編譯內(nèi)核后生成的,同樣復制到ubuntu-rootfs/lib/modules/5.10.66即可
depmod
modprobe 8723du.ko
modprobe rtk_btusb.ko
制作鏡像腳本,空間分配6G
vi mkimage.sh
# mkimage.sh內(nèi)容如下
#!/bin/bash
rootfs_dir=$1
rootfs_file=$2
rootfs_mnt="mnt"
if [ ! $rootfs_dir ] || [ ! $rootfs_file ];
then
echo "Folder or target is empty."
exit 0
fi
if [ -f "$rootfs_file" ]; then
echo "-- Delete exist $rootfs_file ..."
rm -f "$rootfs_file"
fi
echo "-- Create $rootfs_file ..."
dd if=/dev/zero of="$rootfs_file" bs=1M count=6144
sudo mkfs.ext4 -F -L linuxroot "$rootfs_file"
if [ ! -d "$rootfs_mnt" ]; then
mkdir $rootfs_mnt
fi
echo "-- Copy data to $rootfs_file ..."
sudo mount $rootfs_file $rootfs_mnt
sudo cp -rfp $rootfs_dir/* $rootfs_mnt
sudo sync
sudo umount $rootfs_mnt
rm -r $rootfs_mnt
echo "-- Resize $rootfs_file ..."
/sbin/e2fsck -p -f "$rootfs_file"
/sbin/resize2fs -M "$rootfs_file"
echo "-- Done."
制作鏡像,制作完成后即可進行燒錄。
./mkimage.sh ubuntu-rootfs rootfs.img
待解決的問題
1)Ubuntu選擇語言的界面為空,選擇輸入法的界面為空,原因未知。文章來源:http://www.zghlxwxcb.cn/news/detail-781730.html


2)firefly的Ubuntu鏡像優(yōu)化的很不錯,用wayland替代了XServer,界面非常流暢,但是運行在非firefly的設備上,會在開機顯示logo時提示 This's not a firefly's product。文章來源地址http://www.zghlxwxcb.cn/news/detail-781730.html
到了這里,關于基于訊為RK3588平臺搭建Ubuntu20.04.5根文件系統(tǒng)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!