## Yocto Project (5):在樹梅派 4 上跑 Openbmc 目標:建立 Openbmc image 跑在 raspberry pi 4 上 虛擬機作業系統:Ubuntu 20.04 安裝套件。 ```bash sudo apt install git python3-distutils gcc g++ make file wget gawk diffstat bzip2 cpio chrpath zstd lz4 bzip2 ``` 下載 Openbmc 原始碼 ```bash git clone https://github.com/openbmc/openbmc.git ``` 切換到 2.8.0 的版本 ```bash cd openbmc git checkout tags/2.8.0 ``` 調整 Flash Memory 的尺寸。 ```bash nano meta-phosphor/classes/image_types_phosphor.bbclass ``` 更改成以下這些數值 ```bash FLASH_SIZE ?= "131072" FLASH_KERNEL_OFFSET ?= "560" FLASH_ROFS_OFFSET ?= "9856" FLASH_RWFS_OFFSET ?= "45600" FLASH_UBI_RWFS_SIZE_flash-131072 ?= "45600" FLASH_UBI_RWFS_TXT_SIZE_flash-131072 ?= "48MiB" ``` 設定環境變數,指定要用 raspberrypi 的設定檔目錄 ```bash export TEMPLATECONF=meta-evb/meta-evb-raspberrypi/conf ``` 確認變數有沒有設定成功 ```bash echo $TEMPLATECONF meta-evb/meta-evb-raspberrypi/conf ``` 載入 OpenBMC 的建構環境,執行完會自動切換到 build 目錄 ```bash source openbmc-env ``` 調整 MACHINE 名稱 ```bash cp conf/local.conf conf/local.conf.bk nano conf/local.conf ``` 修改成以下的內容 ```bash MACHINE ??= "raspberrypi4" ``` 增加以下的內容 ```bash DL_DIR ?= "/home/zhonwei/.cache/bitbake/downloads" SSTATE_DIR ?= "/home/zhonwei/.cache/bitbake/sstate-cache" IMAGE_FSTYPES += " rpi-sdimg" ``` 建立快取目錄 ```bash mkdir -p ~/.cache/bitbake/downloads mkdir -p ~/.cache/bitbake/sstate-cache ``` 調整 linux-firmware-rpidistro 這個 recipe ```bash! sed -i 's|SRC_URI = "git://github.com/RPi-Distro/firmware-nonfree"|SRC_URI = "git://github.com/RPi-Distro/firmware-nonfree;protocol=https;branch=buster"|' ~/openbmc/meta-raspberrypi/recipes-kernel/linux-firmware-rpidistro/linux-firmware-rpidistro_git.bb ``` 查看有沒有更改成功 ```bash! git diff ~/openbmc/meta-raspberrypi/recipes-kernel/linux-firmware-rpidistro/linux-firmware-rpidistro_git.bb ``` 輸出結果會長的跟以下差不多: ```bash -SRC_URI = "git://github.com/RPi-Distro/firmware-nonfree" +SRC_URI = "git://github.com/RPi-Distro/firmware-nonfree;protocol=https;branch=buster" SRCREV = "616fc2dd4df421e3974179d9e46d45e7006aeb28" PV = "20190114-1+rpt6" ``` 開始 bitbake ```bash bitbake obmc-phosphor-image ``` :::danger 可能會出現的問題:找不到指定的 commit hash 常見的 Yocto/OpenBMC 編譯錯誤,指定要下載的 Commit ID 在 master 分支中找不到 ::: ```bash Unable to find revision 13becaddb6... in branch master even from upstream ``` 解法: 開啟範例檔案(哪個檔案出問題就開哪個檔案) ```bash nano /home/zhonwei/openbmc/meta-openembedded/meta-oe/recipes-test/googletest/googletest_git.bb ``` 找到 SRC_URI 這一行,將 branch=master 改為 branch=main(依照各個 commit 在哪個分支中進行調整): ```bash! # 修改前 SRC_URI = "git://github.com/google/googletest.git;branch=master" # 修改後 SRC_URI = "git://github.com/google/googletest.git;branch=main;protocol=https" ``` 存檔退出,就可以重新編譯了 編譯完成之後,image 檔會放在 `~/openbmc/build/tmp/deploy/images/raspberrypi4` 中,名稱叫做 obmc-phosphor-image-raspberrypi4-20260422105513.rootfs.rpi-sdimg --- 接下來就要把這個 image 檔移到主機上 首先,在 VirtualBox 設定共享資料夾 1. 對虛擬機按右鍵 → 設定(Settings) 2. 左側選 共享資料夾(Shared Folders) 3. 右側點 + 新增 ``` 資料夾路徑:選你 Host(Windows)上想要共享的資料夾 資料夾名稱:自訂一個名稱(例如 shared) 自動掛載(Auto-mount):✅ 勾起來 永久(Make Permanent):✅ 勾起來 ``` 確認 Guest Additions 有裝 ```bash! lsmod | grep vboxguest ``` VirtualBox 會自動掛載共享資料夾,確認掛載位置 ```bash mount | grep shared ``` 掛載點會在 /media/sf_共享資料夾名稱/,例如 ```bash /media/sf_shared/ ``` 把使用者加入 vboxsf 群組 ```bash! sudo usermod -aG vboxsf $USER #加完之後要登出再登入才會生效 ``` 這樣就可以在 shared 資料夾上同時看到 Windows 上的檔案和虛擬機上的檔案 現在把 image 檔複製到共享資料夾上 ```bash! cp ~/openbmc/build/tmp/deploy/images/raspberrypi4/obmc-phosphor-image-raspberrypi4.rpi-sdimg /media/sf_shared/ ``` 就可以在主機上透過 Raspberry Pi Imager 把 image 檔灌到 SD 卡中,就可以開電初始化樹梅派 4 了 :::danger 錯誤訊息:start4.elf: is not compatible ::: 參考解法:https://forums.raspberrypi.com/viewtopic.php?t=346302 在 https://github.com/raspberrypi/firmware/tree/master/boot 找到 start4.elf 和 fixup4.dat 這兩個檔案更新在 image 檔裡面,再重新燒錄一次。 最後再登入 openbmc 的帳號密碼 ```bash login: root password: 0penBmc ``` ![image](https://hackmd.io/_uploads/HyiPITvaZe.png) 就成功啦!!!! --- 參考資料 1. [建構樹莓派的OpenBMC映像檔](https://engineer-leo.blogspot.com/2023/03/vmware15-ub2004-openbmc-2-8-0.html) 2. [start4.elf is not compatible problem with raspbx](https://forums.raspberrypi.com/viewtopic.php?t=346302&__cf_chl_tk=7lxJd2JAacjmdEOil9Aac49028nwFBTUo1OLJ_Powgg-1776946798-1.0.1.1-rxSJOTWRsssKiNr.cRALYaGeCQf7Zaxfxr.7fE28Pa8)