# Petalinux system building flow

## 名詞簡述

* Petalinux 是以Yocto建構LINUX系統工具，透過此工具客製化LINUX相關功能
* 基於以上的概念整合軟體工具(bitbake/buildtool......等等)，簡化LINUX建立之指令流程

## 指令流程

參考以下流程概念在建立可於XILINX FPGA PS端運行的LINUX系統：

<figure><img src="https://xilinx.file.force.com/servlet/servlet.ImageServer?id=0152E000003pLqZ&#x26;oid=00D2E000000nHq7" alt=""><figcaption></figcaption></figure>

1. **從vivado導出xxx.xsa**
2. **建立petalinux模板**\
   `petalinux-create --type project --template zynqMP -n <projectname>`
3. **導入硬體描述檔(.xsa)**\
   `petalinux-config --get-hw-description <xxx.dsa目錄>`\
   用來導入XSA，會把你指定路徑的XSA放到這個專案內，他會進去抓裡面第一個XSA檔應該是按照檔案名稱順序，若要比免抓錯不要放其他XSA\
   \
   進到Linux 畫面可參考一下做一些相關調整
   * (Must)根據FPGA型號調整DTG\
     例如：使用zcu104 ，則DTG Settings->MACHINE\_NAME則改 zcu104-revc\
     以下為一些型號參數參考表\
     ZCU102:    zcu102-rev1.0\
     ZCU104:    zcu104-revc\
     ultra96 :    avnet-ultra96-rev1
   * (Opt)Ethernet setting可以使用自動IP或固定IP
   * (Opt)在image packaging config -> Root file system如果要從INITRD改成EXT4，ethernet會被改成auto
   * (Opt)第一次build建議每個選點進去看一下，避免奇怪的錯誤
4. **設定kernel**\
   petalinux-config 根據需求進行linux設定，也可以直接進到petalinux-build，格式如下：\
   `petalinux-config -c 模組參數`； -c表示--componen ，模組參數輸入關鍵字，關鍵字有以下幾種：kernel, rootfs, u-boot, bootloader, device-tree, plm, psmfw．細節可參考[連結](https://docs.amd.com/r/en-US/ug1144-petalinux-tools-reference-guide/petalinux-config)
   * (常用)`petalinux-config -c kernel`
5. **建立系統鏡像**\
   petalinux-build主要用於建構完整的linux架構，內部基於bitbake軟體以及yocto建構系統，可使用`petalinux-build`直接對整體系統編譯，亦可使用`petalinux-build -c 模組`進行個別模組(kernel,u-boot,......等等)編譯減少局部修改時間．
   * (常用) `petalinux-build`&#x20;
   * (Opt) `petalinux-build -c device-tree`
   * (Opt) 如果編譯過程有失敗 可以使用\
     &#x20;`petalinux-build -c kernel -x distclean` 清除做到一半的image
   * (進階) 可參考[連結表格](https://docs.amd.com/r/en-US/ug1144-petalinux-tools-reference-guide/petalinux-build-c-component-options)找到與bitbake等價功能
6. **使用qemu開機模擬**\
   在完成linux建構後，可以先進行模擬，確定系統初步符合需求後再將boot.bin,image.ub，放上sd card進行開機．細節可[參考](/fpga-training/petalinux-system-building-flow.md)
   * (常用) petalinux-boot --qemu --kernel
7. **build\_image**\
   當完成petalinux-build以及相關檢查後，準備燒板子，執行命令，並且把BOOT.bin , image.ub丟到boot區即可．\
   petalinux-build 會更新image.ub，而petalinux-package --boot .....`會更新`BOOT.bin
   * (Must) `petalinux-package --boot --u-boot --fpga ./images/linux/system.bit --force`

***

## MISC

* `petalinux-devtool modify linux-xlnx`\
  有時候會需要下載BSP source code，使用以上命令可以下載，若要下載fsbl-firmware，可以使用`petalinux-devtool modify fsbl-firmware`
* 使用2019年的XSA import到2021.2的petalinux可以build成功\
  &#x20;-> 推論舊的xsa可以於新的petalinux上運作


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://soups-misc.gitbook.io/fpga-training/petalinux-system-building-flow.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
