1.概述
Linux系統平臺上有許多開源的系統構建框架,這些框架方便了開發者進行嵌入式系統的構建和定制化開發,目前比較常見的有Buildroot, Yocto, OpenEmbedded等等。
同時更多的傳統的桌面系統也加入到嵌入式環境體系中,如Ubuntu,debian等,為嵌入式提供更方便實用的系統。本文主要介紹基于ubuntu22.04 core和米爾核心板定制一個完整的嵌入式ubuntu22.04系統的完整流程,其中包括開發環境的準備,ubuntu22.04系統的獲取與移植, LXDE輕量級桌面管理等。
本文檔并不包含Linux BSP系統相關基礎知識的介紹,將直接使用米爾發布的myir-image-full提供的的BSP。如需了解BSP文件的制作請查看《Remi Pi_Linux軟件開發指南》。
1.1.?軟件資源
Remi Pi使用的Ubuntu系統基于ubuntu-base-22.04-base-arm64.tar.gz版本制作(下載地址如下),在此版本基礎上添加了豐富的系統資源和其他軟件資源。
Ubuntu Base 22.04.2 LTS (Jammy Jellyfish)
表1-1.資源列表
功能項 | 文件名 |
Ubuntu22.04 base | ubuntu-base-22.04-base-arm64.tar.gz |
啟動管理 | Xinit |
網絡管理 | network-manager network-manager-gnome |
?頻管理 | xine |
視頻播放器 | xine |
注意:米爾提供的ubuntu系統的登錄名為:root 密碼為:123456
2.?開發環境準備
基于ubuntu base系統在開發過程中所需的一些軟硬件環境,包括必要的開發主機環境,必備的軟件工具,代碼和資料的獲取等,具體的準備工作下面將進行詳細介紹。
2.1.?開發主機環境
本節將介紹如何搭建適用于瑞薩Remi Pi平臺的開發環境,該平臺使用的RZ/G系列處理器是多核異構的處理器,RZ/G2L擁有兩個2個ARM Cortex A53。通過閱讀本章節,您將了解相關硬件工具,軟件開發調試工具的安裝和使用。并能快速的搭建相關開發環境,為后面的開發和調試做準備。
-
主機硬件
整個SDK包項目的構建對開發主機的要求比較高,要求處理器具有雙核以上CPU,8GB以上 內存,100GB硬盤或更高配置。可以是安裝Linux系統的PC或服務器,也可以是運行Linux系統的虛擬機,Windows系統下的WSL2等。
-
主機操作系統
一般選擇在安裝Fedora, openSUSE, Debian, Ubuntu, RHEL或者 CentOS等Linux發行版的本地主機上進行,這里推薦的是Ubuntu22.04 64bit桌面版系統,后續開發也是以此系統為例進行介紹。
-
安裝必備軟件包
基礎軟件包請查看《Remi Pi_Linux軟件開發指南》進行安裝,這里只需安裝一個軟件包即可。
PC@system1:~$??sudo?apt-get?update PC@system1:~$??sudo?apt-get?install?qemu-user-static
3.?Ubuntu?22.04?文件系統移植
3.1.?簡介
ubuntu-base 是Ubuntu官方構建的ubuntu最小文件系統,包含debain軟件包管理器,基礎包大小通常只有幾十兆,其背后有整個ubuntu軟件源支持,ubuntu軟件一般穩定性比較好,基于ubuntu-base按需安裝Linux軟件,深度可定制等,常用于嵌入式rootfs構建。
嵌入式常見的幾種文件系統構建方法:busybox、yocto、buildroot,但Ubuntu方便,強大的包管系統,有強大的社區支持,可以直接apt-get install來安裝新軟件包。本文介紹了如何基于Ubuntu-base構建完整的ubuntu 系統。ubuntu支持很多架構,arm、X86、powerpc、ppc等,本文主要基于arm為例,構建一個較為完整的ubuntu系統。
3.2.?獲取源碼
我們提供兩種獲取源碼的方式,一種是直接從米爾光盤鏡像04-sources目錄中獲取壓縮包,另外一種是使用wget獲取位官方的上源碼進行構建,請用戶根據實際需要選擇其中一種進行構建。
3.2.1.?通過wget獲取源碼
具體操作方法如下:
PC@system1:~$?sudo?wget?https://cdimage.ubuntu.com/ubuntu-base/releases/22.04/release/ubuntu-base-22.04-base-arm64.tar.gz
創建rootfs目錄,然后將下載的ubuntu-base-22.04-base-arm64.tar.gz壓縮包解壓到rootfs目錄下:(用戶請根據自己實際路徑和目錄操作)
PC@system1:~$?mkdir?rootfs PC@system1:~$?tar?-xf?ubuntu-base-22.04.1-base-arm64.tar.gz?-C?rootfs/
解壓出的目錄內容如下:
PC@system1:~$?tree?-d?-L?1?rootfs ubuntu_rootfs ├──?bin?->?usr/bin ├──?boot ├──?dev ├──?etc ├──?home ├──?lib?->?usr/lib ├──?media ├──?mnt ├──?opt ├──?proc ├──?root ├──?run ├──?sbin?->?usr/sbin ├──?snap ├──?srv ├──?sys ├──?tmp ├──?usr └──?var
3.3.?準備chroot環境
3.3.1.?安裝模擬器
PC@system1:~$?cp?/usr/bin/qemu-aarch64-static?./rootfs/usr/bin/
(如果主機沒有安裝qemu-user-static工具包,可輸入以下命令安裝工具包)
PC@system1:~$?sudo?apt?install?qemu-user-static
拷貝主機?DNS 配置文件到 arm 架構 Ubuntu 文件系統內(必須拷貝,否則可能會導致下面操作無法進行)。
PC@system1:~$?cp?/etc/resolv.conf?./rootfs/etc/resolv.conf
3.3.2.?制作掛載腳本
將下列腳本代碼拷貝到ch-mount.sh文件中,并改變權限(777)為可執行。
PC@system1:~$??vi?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???????? 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?bothparameters?were?missing" echo?"" echo?"1'st?parameter?can?be?one?ofthese:?-m(mount)?OR?-u(umount)" echo?"2'nd?parameter?is?the?full?pathof?rootfs?directory(with?trailing?'/')" echo?"" echo?"For?example:?ch-mount?-m/media/sdcard/" echo?"" echo?1st?parameter?:?${1} echo?2nd?parameter?:?${2} fi
3.4.?安裝包文件
3.4.1.?掛載系統
首先使用ch-mount.sh將ubuntu文件系統掛載。
PC@system1:~$?./ch-mount.sh?-m?./rootfs/ MOUNTING root@system1:/# root@system1:/#?ls bin?dev??home??media??opt???root??sbin??sys??usr boot?etc??lib???mnt????proc??run???srv???tmp??var
掛載成功即可配置ubuntu文件系統與安裝一些必要的軟件。
3.4.2.?基礎包安裝
可根據需要自行安裝下列包文件,推薦全部安裝。(請按照順序安裝,避免安裝時出錯)
root@system1:/#?chmod?777?/tmp?????????(避免update時失敗) root@system1:/#?apt?update root@system1:/#?apt-get?install?language-pack-zh-hant?language-pack-zh-hans root@system1:/#?apt?install?language-pack-en-base root@system1:/#?apt?install?dialog?rsyslog root@system1:/#?apt?install?systemd?avahi-daemon?avahi-utils?udhcpc?ssh(必備安裝) root@system1:/#?apt?install?sudo root@system1:/#?apt?install?vim root@system1:/#?apt?install?net-tools root@system1:/#?apt?install?ethtool root@system1:/#?apt?install?ifupdown root@system1:/#?apt?install?iputils-ping root@system1:/#?apt?install?htop root@system1:/#?apt?install?lrzsz root@system1:/#?apt?install?gpiod root@system1:/#?apt?install?wpasupplicant root@system1:/#?apt?install?kmod root@system1:/#?apt?install?iw root@system1:/#?apt?install?usbutils root@system1:/#?apt?install?memtester root@system1:/#?apt?install?alsa-utils root@system1:/#?apt?install?ufw root@system1:/#?apt?install?psmisc
添加log,用戶調試ubuntu系統的調試
root@system1:/#?touch?/var/log/rsyslog root@system1:/#?chown?syslog:adm?/var/log/rsyslog root@system1:/#?chmod?666?/var/log/rsyslog root@system1:/#?systemctl?unmask?rsyslog root@system1:/#?systemctl?enable?rsyslog
安裝網絡和語言包支持
root@system1:/#?apt-get?install?synaptic root@system1:/#?apt-get?install?rfkill root@system1:/#?apt-get?install?network-manager root@system1:/#?apt?install?-y?--force-yes?--no-install-recommends?fonts-wqy-microhei root@system1:/#?apt?install?-y?--force-yes?--no-install-recommends?ttf-wqy-zenhei
3.4.3.?桌面系統的安裝
LXDE桌面系統安裝
root@system1:/#?apt-get?install?xinit root@system1:/#?apt-get?install?lxde
瀏覽器和音頻安裝
root@system1:/#?sudo?apt?install?epiphany-browser root@system1:/#?sudo?apt?install?xine-ui
3.4.4.?創建用戶
設置root密碼: 123456
root@system1:/#?passwd?root Enter?new?UNIX?password: Retype?new?UNIX?password: passwd:?password?updated?successfully
可刪除root用戶密碼登錄
root@system1:/#?passwd?-d?root
一定要執行下面的指令,不然會sudo報錯sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
root@system1:/#?chown?root:root?/usr/bin/sudo root@system1:/#?chmod?4755?/usr/bin/sudo
創建一個用戶名為:myir 密碼為:123456
root@system1:/#?adduser?myir perl:?warning:?Setting?locale?failed. perl:?warning:?Please?check?that?your?locale?settings: LANGUAGE?=?(unset), LC_ALL?=?(unset), LC_TIME?=?"zh_CN.UTF-8", LC_IDENTIFICATION?=?"zh_CN.UTF-8", LC_TELEPHONE?=?"zh_CN.UTF-8", LC_NUMERIC?=?"zh_CN.UTF-8", LC_ADDRESS?=?"zh_CN.UTF-8", LC_NAME?=?"zh_CN.UTF-8", LC_MONETARY?=?"zh_CN.UTF-8", LC_PAPER?=?"zh_CN.UTF-8", LC_MEASUREMENT?=?"zh_CN.UTF-8", LANG?=?"zh_CN.UTF-8" are?supported?and?installed?on?your?system. perl:?warning:?Falling?back?to?the?standard?locale?("C"). Adding?user?`myir'?... Adding?new?group?`myir'?(1000)?... Adding?new?user?`myir'?(1000)?with?group?`myir'?... Creating?home?directory?`/home/myir'?... Copying?files?from?`/etc/skel'?... Enter?new?UNIX?password: Retype?new?UNIX?password: passwd:?password?updated?successfully Changing?the?user?information?for?myir Enter?the?new?value,?or?press?ENTER?for?the?default Full?Name?[]:?cy?? Room?Number?[]:?604 Work?Phone?[]: Home?Phone?[]: Other?[]: Is?the?information?correct??[Y/n]?y
設置權限
sudo?vi?/etc/sudoers root?ALL=(ALL:ALL)?ALL myir(根據自己添加的用戶來添加)?ALL=(ALL:ALL)?ALL
上面添加用戶的時候,中間出現的警告可使用下列命令:
root@system1:/#?export?LC_ALL=C
3.4.5.?其他配置
設置hosts和主機名稱,添加127.0.0.1 myir
root@system1:/#?vi?/etc/hosts
清空hostname文件內容,添加myir(根據實際添加的用戶名來添加)
root@system1:/#?vi?/etc/hostname
修改passwd文件
root@system1:/#?vi?/etc/passwd 找到這一行:_apt:x:100:65534::/nonexistent:/usr/sbin/nologin 修改為:_apt:x:0:65534::/nonexistent:/usr/sbin/nologin
創建鏈接文件(一定要執行,不然執行二進制可執行程序時會報錯)
root@system1:/#?ln?-s?/lib?/lib64
配置網卡接口,添加如下內容
root@system1:/#?vi?/etc/network/interfaces auto?eth0 iface?eth0?inet?dhcp
3.4.6.?卸載系統
以上步驟操作完成后即可卸載系統。直接在系統中輸入exit退出系統,并使用命令來卸載
root@system1:/#?exit exit PC@system1:~$ PC@system1:~$?./ch-mount.sh?-u?ubuntu-rootfs/ UNMOUNTING
至此ubuntu 文件系統已經配置完成。
3.5.?ubuntu系統打包
3.5.1.?制作ext4格式文件
根據以上步驟已經制作好了ubuntu-rootfs文件系統,此時要將它制作成.ext4格式的文件,用于刷寫到開發板中。
PC@system1:~$?dd?if=/dev/zero?of=ubuntu22.04.ext4??bs=1M??count=3300
請用戶根據實際情況來決定大小,這里以3.3G大小舉例制作。
PC@system1:~$?mkfs.ext4?ubuntu22.04.ext4
創建一個臨時目錄temp,然后將ubuntu22.04.ext4文件掛載
PC@system1:~$?mkdir?temp PC@system1:~$?sudo?mount?ubuntu22.04.ext4?temp
將ubuntu-rootfs目錄中的內容復制到掛載的文件系統中,然后卸載。
PC@system1:~$?sudo?cp?-avrf?ubuntu-rootfs/*?temp PC@system1:~$?sudo?umount?temp
3.5.2.?制作SD啟動鏡像
先將下載資源的03_Tools/myir tools目錄下的RemiPi_SDUpdate.tar.bz2解壓到虛擬機中(用戶請根據自己實際情況解壓)
PC@system1:~$?tar?-xf?RemiPi_SDUpdate.tar.bz2 PC@system1:~$?cd?RemiPi_SDUpdate/renesas-sd PC@system1:~/RemiPi_SDUpdate/renesas-sd$?ls image?README.md???rzg2_bsp_scripts??fat16?????output??rootfs
把打包好的ubuntu22.04文件系統替換到rootfs/home/root/g2l_images目錄
PC@system1:~/RemiPi_SDUpdate/renesas-sd/rootfs/home/root/g2l_images$?tree?-L?1 . ├──?DDR_1G ├──?Image ├──?Manifest ├──?mys-rzg2l-sdcard.dtb ├──?mys-rzg2l-wifi.dtb └──?ubuntu22.04.ext4 1?directory,?5?files
修改Manifest文件
PC@system1:~/RemiPi_SDUpdate/renesas-sd/rootfs/home/root/g2l_images$?cat?Manifest bl2file="bl2_bp-myir-remi-1g_pmic.bin" fipfile="fip-myir-remi-1g_pmic.bin" imagefile="Image" dtbfile="*.dtb" rootfsfile="ubuntu22.04.ext4" ledname="162"
修改自己實際路徑的配置,這個請參考《RemiPi_Linux 軟件開發指南》4.3章節,修改myir_config.ini配置文件,將里面的路徑修改成自己實際的路徑。
最后進入到下面目錄,執行制作鏡像的腳本即可。
PC@system1:~/RemiPi_SDUpdate/renesas-sd$?cd?rzg2_bsp_scripts/image_creator/ PC@system1:?~/RemiPi_SDUpdate/renesas-sd/rzg2_bsp_scripts/image_creator$?./create_image.sh?myir_config.ini
燒錄步驟請參考《RemiPi_Linux 軟件開發指南》中4.2章節。
4.?認識LXDE
4.1.?LXDE介紹
LXDE是一個輕量級和快速的桌面環境。它被設計為用戶友好和占用資源少,同時保持資源使用率低。LXDE使用更少的內存和CPU來盡可能地展現功能豐富的桌面環境。與其它的桌面環境不同,LXDE努力成為模塊化的桌面環境,所以每個組件可以獨立使用。這使得移植LXDE不同分布和平臺更容易。?
LXDE包含多個核心組件,可用于桌面環境下來管理整個系統資源。主要組件如下:
-
LXPanel:這是LXDE的面板系統,類似于GNOME的GNOME Panel或KDE的Kicker。它提供了快速訪問應用程序、系統工具、文件夾和剪貼板的方式。?
-
LXSession:這是LXDE的會話管理器,它負責啟動和終止LXDE桌面環境。
-
LXDE-OpenBox:?這是一個窗口管理器,提供窗口布局和導航。LXDE使用OpenBox作為其默認的窗口管理器。
-
PCManFM:這是一個輕量級的文件管理器,提供文件和目錄的瀏覽、復制、移動、刪除等操作
除了這些核心組件外,LXDE還有其他一些輔助工具,如LXAppearance(用于更改主題和圖標)、LXTask(任務管理器)等。
4.2.?啟動LXDE
開機啟動后,可手動輸入密碼123456登錄,或者在串口終端執行(startx /usr/bin/lxsession -s LXDE &)命令進行登錄,如圖4-1:
圖4-1:lxde登錄界面
登錄成功后,由于默認背景是黑色的,可以點擊鼠標右鍵后選擇Desktop Preferences->Appearance->Wallpaper(/usr/share/lxde/wallpapers/lxde_blue.jpg)來選擇背景圖片,如圖4-2:
圖4-2:lxde背景圖片修改
背景圖片修改成功,如圖4-3:
圖4-3:lxde背景圖片