快轉到主要內容

告別網路限制!Yocto 本地程式碼編譯大作戰,打造你的專屬嵌入式系統!

· loading
作者
Advantech ESS
目錄

你是否曾經因為網路不穩定,或是想更彈性地客製化嵌入式系統,而苦惱於 Yocto 的編譯過程?別擔心!身為嵌入式系統專家的研華,這次要帶領大家擺脫網路的束縛,直接從本地程式碼編譯 Yocto,打造出最符合需求的嵌入式解決方案!

什麼是 Yocto?為什麼它很重要?
#

Yocto Project 就像是嵌入式 Linux 界的樂高積木,它提供了一個彈性且強大的框架,讓開發者可以根據自身需求,客製化 Linux 發行版本。無論你是要開發工業控制系統、車載娛樂系統,還是智慧家庭裝置,Yocto 都能讓你精準地打造出最精簡、高效的系統。

然而,Yocto 的編譯過程往往需要從網路下載大量的原始碼,這對於網路環境不佳,或是需要高度客製化的專案來說,無疑是一大挑戰。因此,研華的工程師們決定挑戰極限,探索從本地程式碼編譯 Yocto 的可能性!

實驗室直擊:Yocto 本地編譯大揭秘
#

這次的實驗目標很明確:讓 Yocto 可以直接從本地的程式碼倉庫編譯,擺脫對網路的依賴,同時提升開發效率與客製化程度。

以下是我們的實驗步驟,雖然看起來有點技術性,但我們會盡量用簡單的方式說明:

  1. 進入 Docker 容器: 首先,我們使用 Docker 建立一個獨立的開發環境,確保實驗過程不會影響到主系統。

    $ sudo docker run --privileged -it --name sa91 -v ${LOCAL_PATH}:/home/adv/adv-release-bsp advrisc/u20.04-imx8lbv1 /bin/bash
    
  2. 安裝 Toolchain BSP: 接著,我們安裝了 Toolchain BSP (Board Support Package),它包含了編譯、連結和除錯嵌入式系統所需的工具和函式庫。

    $ cd adv-release-bsp/
    
    $ sudo chown adv:adv -R .
    
    $ git clone https://token_example@dev.azure.com/ACGKA41/DMS-SA91/_git/rzg2_bsp_scripts
    
    $ sudo chown adv:adv -R .
    
    $ cd rzg2_bsp_scripts/build_scripts/
    
    $ ./setup_repository.sh
    

    完成後,你會看到 rzg_trusted-firmware-arenesas-u-boot-ciprz_linux-cip 三個資料夾。

    image_1741764831870.png

  3. 設定 Yocto 編譯環境: 我們使用 Git 從研華的程式碼倉庫中複製 Yocto 的 BSP。

    $ cd ~/adv-release-bsp/
    
    $ git clone https://token_example@dev.azure.com/ACGKA41/DMS-SA91/_git/bsp_yocto_3.0.5
    
  4. 修改 Yocto 設定,指向本地程式碼: 這是最關鍵的一步!我們需要修改 Yocto 的設定檔,告訴它去哪裡尋找本地的程式碼。具體來說,我們要修改 SRC_URI 這個變數,將原本指向遠端倉庫的 URL,改成指向本地程式碼的路徑。

    舉例來說,對於 U-Boot 的原始碼,我們需要修改 meta-renesas/meta-rz-common/recipes-bsp/u-boot/u-boot_2021.10.bb 這個檔案,將 SRC_URI 修改如下:

    diff --git a/meta-renesas/meta-rz-common/recipes-bsp/u-boot/u-boot_2021.10.bb b/meta-renesas/meta-rz-common/recipes-bsp/u-boot/u-boot_2021.10.bb
    index 46c8a7eb..895ee5b4 100644
    --- a/meta-renesas/meta-rz-common/recipes-bsp/u-boot/u-boot_2021.10.bb
    +++ b/meta-renesas/meta-rz-common/recipes-bsp/u-boot/u-boot_2021.10.bb
    @@ -2,8 +2,7 @@
     require u-boot-common_${PV}.inc
     require u-boot.inc
    
     DEPENDS += "bc-native dtc-native"
    -
    -UBOOT_URL = "git://token_example@dev.azure.com/ACGKA41/DMS-SA91/_git/renesas-u-boot-cip;protocol=https"
    +#UBOOT_URL = "git://token_example@dev.azure.com/ACGKA41/DMS-SA91/_git/renesas-u-boot-cip;protocol=https"
    +UBOOT_URL = "git:///home/adv/adv-release-bsp/rzg2_bsp_scripts/build_scripts/renesas-u-boot-cip;protocol=file"
     BRANCH = "v2021.10/rz"
    
     SRC_URI = "${UBOOT_URL};branch=${BRANCH}"
    

    同樣的,我們也需要修改 Kernel 和 Trusted Firmware 的設定檔,將 SRC_URI 指向對應的本地路徑。

    Kernel source:

    diff --git a/meta-renesas/meta-rz-common/recipes-kernel/linux/linux-renesas_5.10.bb b/meta-renesas/meta-rz-common/recipes-kernel/linux/linux-renesas_5.10.bb
    index 40486061..1d48069d 100644
    --- a/meta-renesas/meta-rz-common/recipes-kernel/linux/linux-renesas_5.10.bb
    +++ b/meta-renesas/meta-rz-common/recipes-kernel/linux/linux-renesas_5.10.bb
    @@ -12,7 +12,8 @@
     COMPATIBLE_MACHINE_rzg1 = "(iwg20m-g1m|iwg20m-g1n|iwg21m|iwg22m|iwg23s)"
    
     BRANCH = "rz-5.10-cip36"
     SRCREV = "${AUTOREV}"
    -SRC_URI = "git://token_example@dev.azure.com/ACGKA41/DMS-SA91/_git/rz_linux-cip;protocol=https;nocheckout=1;branch=${BRANCH}"
    +#SRC_URI = "git://token_example@dev.azure.com/ACGKA41/DMS-SA91/_git/rz_linux-cip;protocol=https;nocheckout=1;branch=${BRANCH}"
    +SRC_URI = "git:///home/adv/adv-release-bsp/rzg2_bsp_scripts/build_scripts/rz_linux-cip;protocol=file;branch=${BRANCH}"
     LIC_FILES_CHKSUM = "file://COPYING;md5=6bc538ed5bd9a7fc9398086aedcd7e46"
     LINUX_VERSION ?= "${@oe.utils.conditional("IS_RT_BSP", "1", "5.10.184-cip36-rt14", "5.10.184-cip36",d)}"
    

    Trusted firmware:

    diff --git a/meta-renesas/meta-rz-common/recipes-bsp/trusted-firmware-a/trusted-firmware-a.bb b/meta-renesas/meta-rz-common/recipes-bsp/trusted-firmware-a/trusted-firmware-a.bb
    index d843a74f..69177bcb 100644
    --- a/meta-renesas/meta-rz-common/recipes-bsp/trusted-firmware-a/trusted-firmware-a.bb
    +++ b/meta-renesas/meta-rz-common/recipes-bsp/trusted-firmware-a/trusted-firmware-a.bb
    @@ -16,7 +16,7 @@
     BRANCH = "v2.9/rz"
     BRANCH_mbedtls = "mbedtls-2.28"
    
     SRC_URI = " \
    -       git://token_example@dev.azure.com/ACGKA41/DMS-SA91/_git/rzg_trusted-firmware-a;protocol=https;branch=v2.9/rz \
    +       git:///home/adv/adv-release-bsp/rzg2_bsp_scripts/build_scripts/rzg_trusted-firmware-a;protocol=file;branch=v2.9/rz \
          git://github.com/ARMmbed/mbedtls.git;branch=${BRANCH_mbedtls};name=mbedtls;destsuffix=mbedtls \
     "
    

    為了方便大家操作,我們將所有修改集中在一個 Patch 檔案中 (source_from_remote_to_local.patch)。

    diff --git a/meta-renesas/meta-rz-common/recipes-bsp/trusted-firmware-a/trusted-firmware-a.bb b/meta-renesas/meta-rz-common/recipes-bsp/trusted-firmware-a/trusted-firmware-a.bb
    index d843a74f..69177bcb 100644
    --- a/meta-renesas/meta-rz-common/recipes-bsp/trusted-firmware-a/trusted-firmware-a.bb
    +++ b/meta-renesas/meta-rz-common/recipes-bsp/trusted-firmware-a/trusted-firmware-a.bb
    @@ -16,7 +16,7 @@
     BRANCH = "v2.9/rz"
     BRANCH_mbedtls = "mbedtls-2.28"
    
     SRC_URI = " \
    -       git://token_example@dev.azure.com/ACGKA41/DMS-SA91/_git/rzg_trusted-firmware-a;protocol=https;branch=v2.9/rz \
    +       git:///home/adv/adv-release-bsp/rzg2_bsp_scripts/build_scripts/rzg_trusted-firmware-a;protocol=file;branch=v2.9/rz \
          git://github.com/ARMmbed/mbedtls.git;branch=${BRANCH_mbedtls};name=mbedtls;destsuffix=mbedtls \
     "
    
    diff --git a/meta-renesas/meta-rz-common/recipes-bsp/u-boot/u-boot_2021.10.bb b/meta-renesas/meta-rz-common/recipes-bsp/u-boot/u-boot_2021.10.bb
    index 46c8a7eb..895ee5b4 100644
    --- a/meta-renesas/meta-rz-common/recipes-bsp/u-boot/u-boot_2021.10.bb
    +++ b/meta-renesas/meta-rz-common/recipes-bsp/u-boot/u-boot_2021.10.bb
    @@ -2,8 +2,7 @@
     require u-boot-common_${PV}.inc
     require u-boot.inc
    
     DEPENDS += "bc-native dtc-native"
    -
    -UBOOT_URL = "git://token_example@dev.azure.com/ACGKA41/DMS-SA91/_git/renesas-u-boot-cip;protocol=https"
    +UBOOT_URL = "git:///home/adv/adv-release-bsp/rzg2_bsp_scripts/build_scripts/renesas-u-boot-cip;protocol=file"
     BRANCH = "v2021.10/rz"
    
     SRC_URI = "${UBOOT_URL};branch=${BRANCH}"
    diff --git a/meta-renesas/meta-rz-common/recipes-kernel/linux/linux-renesas_5.10.bb b/meta-renesas/meta-rz-common/recipes-kernel/linux/linux-renesas_5.10.bb
    index 40486061..1d48069d 100644
    --- a/meta-renesas/meta-rz-common/recipes-kernel/linux/linux-renesas_5.10.bb
    +++ b/meta-renesas/meta-rz-common/recipes-kernel/linux/linux-renesas_5.10.bb
    @@ -12,7 +12,8 @@
     COMPATIBLE_MACHINE_rzg1 = "(iwg20m-g1m|iwg20m-g1n|iwg21m|iwg22m|iwg23s)"
    
     BRANCH = "rz-5.10-cip36"
     SRCREV = "${AUTOREV}"
    -SRC_URI = "git://token_example@dev.azure.com/ACGKA41/DMS-SA91/_git/rz_linux-cip;protocol=https;nocheckout=1;branch=${BRANCH}"
    +#SRC_URI = "git://token_example@dev.azure.com/ACGKA41/DMS-SA91/_git/rz_linux-cip;protocol=https;nocheckout=1;branch=${BRANCH}"
    +SRC_URI = "git:///home/adv/adv-release-bsp/rzg2_bsp_scripts/build_scripts/rz_linux-cip;protocol=file;branch=${BRANCH}"
     LIC_FILES_CHKSUM = "file://COPYING;md5=6bc538ed5bd9a7fc9398086aedcd7e46"
     LINUX_VERSION ?= "${@oe.utils.conditional("IS_RT_BSP", "1", "5.10.184-cip36-rt14", "5.10.184-cip36",d)}"
    
  5. 編譯 Kernel 模組並驗證: 接下來,我們編譯 Kernel 模組,並驗證是否成功從本地程式碼編譯。

    • 解壓縮 Kernel 原始碼:

      $ MACHINE=dms-sa91 bitbake -c do_unpack linux-renesas
      
      $ pushd tmp/work/dms_sa91-poky-linux/linux-renesas/5.10.184-cip36+gitAUTOINC+ce7ed0e25c-r1/git
      
      $ git checkout
      
    • 修改 defconfig: 根據需求修改 Kernel 的預設設定。

      $ vi arch/arm64/configs/defconfig
      
      $ popd
      
    • 編譯 Kernel:

      $ MACHINE=dms-sa91 bitbake -c do_compile linux-renesas
      
    • 檢查內建模組: 確認編譯後的 Kernel 中包含了我們需要的模組。

      $ pushd tmp/work/dms_sa91-poky-linux/linux-renesas/5.10.184-cip36+gitAUTOINC+ce7ed0e25c-r1/linux-dms_sa91-standard-build
      
      $ vi modules.builtin
      
      $ popd
      
    • 清理編譯環境:

      $ MACHINE=dms-sa91 bitbake -c do_cleanall linux-renesas
      

實驗成果:客製化嵌入式系統,就是這麼簡單!
#

經過一連串的實驗,我們成功地讓 Yocto 從本地程式碼編譯,這代表著:

  • 更快的開發速度: 擺脫網路限制,編譯速度大幅提升。
  • 更高的客製化程度: 可以更自由地修改和調整程式碼,打造出最符合需求的嵌入式系統。
  • 更穩定的開發環境: 不受網路波動影響,確保開發過程的穩定性。

研華的創新之路:永不止步
#

這次的實驗不僅僅是一個技術上的突破,更展現了研華在嵌入式系統領域持續創新、追求卓越的精神。我們深知,唯有不斷地探索和嘗試,才能為客戶提供更優質、更具競爭力的解決方案。

未來,研華將持續投入資源,研究更多關於 Yocto 和嵌入式系統的技術,例如:

  • 更智慧化的編譯流程: 透過自動化工具,簡化編譯過程,降低開發門檻。
  • 更完善的本地程式碼管理: 建立一套完善的本地程式碼管理機制,方便開發者維護和更新程式碼。
  • 更豐富的客製化選項: 提供更多客製化選項,滿足不同客戶的需求。

我們相信,透過不斷的努力,研華將成為您在嵌入式系統領域最值得信賴的合作夥伴!

相關文章

研華AI大解密:用OpenWebUI打造你專屬的RAG問答系統,AIR-310實戰登場!
· loading
解鎖未來醫療!Advantech AI 實驗室揭秘:當 MONAI 遇上 Holoscan
· loading
機器人感官神同步!Advantech Time Sync Viewer 助您揪出時間不同步的搗蛋鬼
· loading