為樹莓派4B編譯uboot


1.編譯環境

2.安裝交叉編譯工具鏈以及相關庫

sudo apt install gcc-aarch64-linux-gnu make bison flex libssl-dev

3.構建樹莓派4的make配置並編譯

export CROSS_COMPILE=aarch64-linux-gnu-
make distclean
make rpi_4_defconfig
make -j

如果編譯過程沒有報錯,則會在根目錄下生成u-boot.bin文件。如有報錯,搜索錯誤代碼解決。

4.拷貝文件,上機測試

  1. 需要將vFAT格式的SD卡,推薦使用樹莓派官方的鏡像制作工具,執行擦除操作即可,比較方便。
    image
  2. 修改config.txt文件
    如果你給樹莓派安裝過官方系統的話,config.txt文件就在官方鏡像的boot分區下,使用任意編輯器在其中加入這行文字保存即可。
kernel=u-boot.bin

如果需要用串口查看效果的話再加入下面這一行:

enable_uart=1
  1. 將啟動u-boot需要的文件放入SD卡根目錄
    這些文件在官方鏡像的boot分區下都能找到,直接復制即可,唯一需要注意的是別漏了u-boot.bin
bcm2711-rpi-4-b.dtb
bootcode.bin
config.txt
fixup4.dat
start4.elf
u-boot.bin

官方鏡像boot分區內的文件如圖所示。
image
4. 板子插入SD卡,上電測試。
屏幕看到以下圖像即成功啟動uboot
image
啟動成功時串口輸出如下

U-Boot 2022.04-rc3-00046-g0444cbbe77 (Mar 06 2022 - 03:43:01 -0800)

DRAM:  7.1 GiB
RPI 4 Model B (0xd03114)
Core:  202 devices, 13 uclasses, devicetree: board
MMC:   mmcnr@7e300000: 1, mmc@7e340000: 0
Loading Environment from FAT... Unable to read "uboot.env" from mmc0:1...
In:    serial
Out:   vidconsole
Err:   vidconsole
Net:   eth0: ethernet@7d580000
PCIe BRCM: link up, 5.0 Gbps x1 (SSC)
starting USB...
Bus xhci_pci: Register 5000420 NbrPorts 5
Starting the controller
USB XHCI 1.00
scanning bus xhci_pci for devices... 2 USB Device(s) found
       scanning usb for storage devices... 0 Storage Device(s) found
Hit any key to stop autoboot:  0
U-Boot>

至此大功告成。


因筆者能力經驗有限,文中所述可能存在錯誤,歡迎各位讀者指正。


參考:

  1. 在樹莓派4(Raspberry Pi 4 B)上運行u-boot - zhangpf的文章 - 知乎
    https://zhuanlan.zhihu.com/p/92689086
  2. https://www.beyondlogic.org/compiling-u-boot-with-device-tree-support-for-the-raspberry-pi/
  3. 樹莓派4B,uboot啟動Raspberry Pi OS - 嵌入式干飯人的文章 - 知乎
    https://zhuanlan.zhihu.com/p/365748456

– – – – – –
原創不易,轉載請注明出處。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM