前言
雖可使用Petalinux
進行移植,簡單方便,但為了更清楚明白的瞭解整個流程,還是嘗試了一波手動移植。
參考資料
ZYNQ Linux 移植:包含petalinux移植和手動移植debian9
ZYNQ #5 - 從vivado工程開始,從emmc啟動Linux_裡先森-CSDN部落格
流程
對於手動移植,所需的檔案為:
BOOT.bin(FSBL+fpga_bit檔案+u_boot.elf)、uImage、devicetree.dtb、uEnv.txt、檔案系統
檔案放置位置說明:
FLASH:BOOT.bin(FSBL+fpga_bit檔案+u_boot.elf)
EMMC:
第一個分割槽放置:uImage、devicetree.dtb、uEnv.txt
第二個分割槽放置:檔案系統
啟動流程為:板子設定為QSPI啟動模式,FSBL執行調u-boot執行,u-boot根據uEnv.txt調EMMC分割槽1中的核心執行,核心最後跳到分割槽二中的檔案系統。
FSBL、bit檔案、uImage、檔案系統都可複用SD卡移植模式下的內容:參考參考資料第一個連結。
本文章主要講述的重點在於:u-boot、裝置樹、uEnv.txt的更改部分
板子主要資訊說明:板子晶片:ZYNQ7035,板子的除錯列印串列埠為PS0,板子上有SD卡(SD0)、EMMC(SD1),板子上有FLASH。其他外設不贅述。
u-boot移植說明:
1.下載u-boot原始碼:git clone [https://github.com/Xilinx/u-boot-xlnx.git](https://github.com/Xilinx/u-boot-xlnx.git)
NOTE:u-boot xilinx-v2018.3版本的zynq-common.h
跟xilinx-v2018.1版本的不一樣,這裡檢出v2018.1版本使用。
主要是CONFIG_EXTRA_ENV_SETTINGS
環境變數不一致。
預設的如下所示:
/* Default environment */
#ifndef CONFIG_EXTRA_ENV_SETTINGS
#define CONFIG_EXTRA_ENV_SETTINGS \
"ethaddr=00:0a:35:00:01:22\0" \
"kernel_image=uImage\0" \
"kernel_load_address=0x2080000\0" \
"ramdisk_image=uramdisk.image.gz\0" \
"ramdisk_load_address=0x4000000\0" \
"devicetree_image=devicetree.dtb\0" \
"devicetree_load_address=0x2000000\0" \
"bitstream_image=system.bit.bin\0" \
"boot_image=BOOT.bin\0" \
"loadbit_addr=0x100000\0" \
"loadbootenv_addr=0x2000000\0" \
"kernel_size=0x500000\0" \
"devicetree_size=0x20000\0" \
"ramdisk_size=0x5E0000\0" \
"boot_size=0xF00000\0" \
"fdt_high=0x20000000\0" \
"initrd_high=0x20000000\0" \
"bootenv=uEnv.txt\0" \
"loadbootenv=load mmc 0 ${loadbootenv_addr} ${bootenv}\0" \
"importbootenv=echo Importing environment from SD ...; " \
"env import -t ${loadbootenv_addr} $filesize\0" \
"sd_uEnvtxt_existence_test=test -e mmc 0 /uEnv.txt\0" \
"preboot=if test $modeboot = sdboot && env run sd_uEnvtxt_existence_test; " \
"then if env run loadbootenv; " \
"then env run importbootenv; " \
"fi; " \
"fi; \0" \
"mmc_loadbit=echo Loading bitstream from SD/MMC/eMMC to RAM.. && " \
"mmcinfo && " \
"load mmc 0 ${loadbit_addr} ${bitstream_image} && " \
"fpga load 0 ${loadbit_addr} ${filesize}\0" \
"norboot=echo Copying Linux from NOR flash to RAM... && " \
"cp.b 0xE2100000 ${kernel_load_address} ${kernel_size} && " \
"cp.b 0xE2600000 ${devicetree_load_address} ${devicetree_size} && " \
"echo Copying ramdisk... && " \
"cp.b 0xE2620000 ${ramdisk_load_address} ${ramdisk_size} && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}\0" \
"qspiboot=echo Copying Linux from QSPI flash to RAM... && " \
"sf probe 0 0 0 && " \
"sf read ${kernel_load_address} 0x100000 ${kernel_size} && " \
"sf read ${devicetree_load_address} 0x600000 ${devicetree_size} && " \
"echo Copying ramdisk... && " \
"sf read ${ramdisk_load_address} 0x620000 ${ramdisk_size} && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}\0" \
"uenvboot=" \
"if run loadbootenv; then " \
"echo Loaded environment from ${bootenv}; " \
"run importbootenv; " \
"fi; " \
"if test -n $uenvcmd; then " \
"echo Running uenvcmd ...; " \
"run uenvcmd; " \
"fi\0" \
"sdboot=if mmcinfo; then " \
"run uenvboot; " \
"echo Copying Linux from SD to RAM... && " \
"load mmc 0 ${kernel_load_address} ${kernel_image} && " \
"load mmc 0 ${devicetree_load_address} ${devicetree_image} && " \
"load mmc 0 ${ramdisk_load_address} ${ramdisk_image} && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}; " \
"fi\0" \
"usbboot=if usb start; then " \
"run uenvboot; " \
"echo Copying Linux from USB to RAM... && " \
"load usb 0 ${kernel_load_address} ${kernel_image} && " \
"load usb 0 ${devicetree_load_address} ${devicetree_image} && " \
"load usb 0 ${ramdisk_load_address} ${ramdisk_image} && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}; " \
"fi\0" \
"nandboot=echo Copying Linux from NAND flash to RAM... && " \
"nand read ${kernel_load_address} 0x100000 ${kernel_size} && " \
"nand read ${devicetree_load_address} 0x600000 ${devicetree_size} && " \
"echo Copying ramdisk... && " \
"nand read ${ramdisk_load_address} 0x620000 ${ramdisk_size} && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}\0" \
"jtagboot=echo TFTPing Linux to RAM... && " \
"tftpboot ${kernel_load_address} ${kernel_image} && " \
"tftpboot ${devicetree_load_address} ${devicetree_image} && " \
"tftpboot ${ramdisk_load_address} ${ramdisk_image} && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}\0" \
"rsa_norboot=echo Copying Image from NOR flash to RAM... && " \
"cp.b 0xE2100000 0x100000 ${boot_size} && " \
"zynqrsa 0x100000 && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}\0" \
"rsa_nandboot=echo Copying Image from NAND flash to RAM... && " \
"nand read 0x100000 0x0 ${boot_size} && " \
"zynqrsa 0x100000 && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}\0" \
"rsa_qspiboot=echo Copying Image from QSPI flash to RAM... && " \
"sf probe 0 0 0 && " \
"sf read 0x100000 0x0 ${boot_size} && " \
"zynqrsa 0x100000 && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}\0" \
"rsa_sdboot=echo Copying Image from SD to RAM... && " \
"load mmc 0 0x100000 ${boot_image} && " \
"zynqrsa 0x100000 && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}\0" \
"rsa_jtagboot=echo TFTPing Image to RAM... && " \
"tftpboot 0x100000 ${boot_image} && " \
"zynqrsa 0x100000 && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}\0" \
DFU_ALT_INFO \
BOOTENV
#endif
可以看到其上定義了一堆的東西及不同的啟動指令。
不同的啟動指令由#define CONFIG_BOOTCOMMAND指定。
這裡想FLASH+EMMC啟動,則可以選擇sdboot,同時因為EMMC是SD1,所以上述的檔案需要進行更改:更改uEnv.txt的儲存位置為mmc 1;去掉sdboot中的ramdisk,及儲存kernel、裝置樹位置為mmc 1;修改bootm引數。
"loadbootenv=load mmc 1 ${loadbootenv_addr} ${bootenv}\0" \
"importbootenv=echo Importing environment from SD ...; " \
"env import -t ${loadbootenv_addr} $filesize\0" \
"sd_uEnvtxt_existence_test=test -e mmc 1 /uEnv.txt\0" \
"sdboot=if mmcinfo; then " \
"run uenvboot; " \
"echo Copying Linux from hahahah SD to RAM... && " \
"load mmc 1 ${kernel_load_address} ${kernel_image} && " \
"load mmc 1 ${devicetree_load_address} ${devicetree_image} && " \
"bootm ${kernel_load_address} - ${devicetree_load_address}; " \
"fi\0" \
上述命令的執行邏輯為:u-boot啟動後,執行sdboot指令:
(1)裝載uEnv.txt檔案並執行;
(2)裝載核心、裝置樹;
(3)執行;
2.由於是自己做的板子,則可以基於類似的板子defconfig進行修改適配u-boot:這裡使用zynq_zed_defconfig檔案:
(1)增加傳統映象檔案支援:CONFIG_IMAGE_FORMAT_LEGACY=y
(2)因為已經知道是從EMMC啟動相關檔案,則可直接指定:CONFIG_BOOTCOMMAND="mmc dev 1;run sdboot"
mmc dev 1是為了避免u-boot死鎖bug(移植petalinux中u-boot存在,為官方bug,這裡加上,不知道有沒有用);sdboot會直接呼叫執行zynq-common.h中的對應選項。
(3)因為板子上串列埠使用的是PS0,修改:CONFIG_DEBUG_UART_BASE=0xe0000000(地址可在裝置樹中檢視)
檔案參考:
CONFIG_ARM=y
CONFIG_ARCH_ZYNQ=y
CONFIG_SYS_TEXT_BASE=0x4000000
CONFIG_SPL_STACK_R_ADDR=0x200000
CONFIG_DEFAULT_DEVICE_TREE="zynq-zed"
CONFIG_DEBUG_UART=y
CONFIG_DISTRO_DEFAULTS=y
CONFIG_IMAGE_FORMAT_LEGACY=y
CONFIG_FIT=y
CONFIG_FIT_SIGNATURE=y
CONFIG_FIT_VERBOSE=y
CONFIG_BOOTCOMMAND="mmc dev 1;run sdboot"
# CONFIG_DISPLAY_CPUINFO is not set
CONFIG_SPL=y
CONFIG_SPL_STACK_R=y
CONFIG_SPL_OS_BOOT=y
CONFIG_SYS_PROMPT="Zynq> "
CONFIG_CMD_THOR_DOWNLOAD=y
CONFIG_CMD_DFU=y
# CONFIG_CMD_FLASH is not set
CONFIG_CMD_FPGA_LOADBP=y
CONFIG_CMD_FPGA_LOADFS=y
CONFIG_CMD_FPGA_LOADMK=y
CONFIG_CMD_FPGA_LOADP=y
CONFIG_CMD_GPIO=y
CONFIG_CMD_MMC=y
CONFIG_CMD_SF=y
CONFIG_CMD_USB=y
# CONFIG_CMD_SETEXPR is not set
CONFIG_CMD_TFTPPUT=y
CONFIG_CMD_CACHE=y
CONFIG_CMD_EXT4_WRITE=y
CONFIG_OF_EMBED=y
CONFIG_ENV_IS_IN_SPI_FLASH=y
CONFIG_NET_RANDOM_ETHADDR=y
CONFIG_SPL_DM_SEQ_ALIAS=y
CONFIG_DFU_MMC=y
CONFIG_DFU_RAM=y
CONFIG_FPGA_XILINX=y
CONFIG_DM_GPIO=y
CONFIG_MMC_SDHCI=y
CONFIG_MMC_SDHCI_ZYNQ=y
CONFIG_SPI_FLASH=y
CONFIG_SPI_FLASH_BAR=y
CONFIG_SF_DUAL_FLASH=y
CONFIG_SPI_FLASH_SPANSION=y
CONFIG_SPI_FLASH_STMICRO=y
CONFIG_SPI_FLASH_WINBOND=y
CONFIG_PHY_MARVELL=y
CONFIG_PHY_REALTEK=y
CONFIG_PHY_XILINX=y
CONFIG_ZYNQ_GEM=y
CONFIG_DEBUG_UART_ZYNQ=y
CONFIG_DEBUG_UART_BASE=0xe0000000
CONFIG_DEBUG_UART_CLOCK=50000000
CONFIG_ZYNQ_SERIAL=y
CONFIG_ZYNQ_QSPI=y
CONFIG_USB=y
CONFIG_USB_EHCI_HCD=y
CONFIG_USB_ULPI_VIEWPORT=y
CONFIG_USB_ULPI=y
CONFIG_USB_STORAGE=y
CONFIG_USB_GADGET=y
CONFIG_USB_GADGET_MANUFACTURER="Xilinx"
CONFIG_USB_GADGET_VENDOR_NUM=0x03fd
CONFIG_USB_GADGET_PRODUCT_NUM=0x0300
CONFIG_CI_UDC=y
CONFIG_USB_GADGET_DOWNLOAD=y
3.修改u-boot的裝置樹:實際上u-boot也帶了裝置樹,這裡需要進行修改:
(1)修改uart為uart0;
(2)修改SD為mmc1;
(3)去除QSPI中的分割槽表;
檔案參考:
/*
* Xilinx ZED board DTS
*
* Copyright (C) 2011 - 2015 Xilinx
* Copyright (C) 2012 National Instruments Corp.
*
* SPDX-License-Identifier: GPL-2.0+
*/
/dts-v1/;
#include "zynq-7000.dtsi"
/ {
model = "Zynq Zed Development Board";
compatible = "xlnx,zynq-zed", "xlnx,zynq-7000";
aliases {
ethernet0 = &gem0;
serial0 = &uart0;
spi0 = &qspi;
mmc1 = &sdhci1;
};
memory@0 {
device_type = "memory";
reg = <0x0 0x20000000>;
};
chosen {
bootargs = "";
stdout-path = "serial0:115200n8";
};
usb_phy0: phy0@e0002000 {
compatible = "ulpi-phy";
#phy-cells = <0>;
reg = <0xe0002000 0x1000>;
view-port = <0x0170>;
drv-vbus;
};
};
&clkc {
ps-clk-frequency = <33333333>;
};
&gem0 {
status = "okay";
phy-mode = "rgmii-id";
phy-handle = <ðernet_phy>;
ethernet_phy: ethernet-phy@0 {
reg = <0>;
device_type = "ethernet-phy";
};
};
&qspi {
u-boot,dm-pre-reloc;
status = "okay";
is-dual = <0>;
num-cs = <1>;
flash@0 {
compatible = "n25q128a11";
reg = <0x0>;
spi-tx-bus-width = <1>;
spi-rx-bus-width = <4>;
spi-max-frequency = <50000000>;
#address-cells = <1>;
#size-cells = <1>;
};
};
&sdhci1 {
u-boot,dm-pre-reloc;
status = "okay";
};
&uart0 {
u-boot,dm-pre-reloc;
status = "okay";
};
&usb0 {
status = "okay";
dr_mode = "host";
usb-phy = <&usb_phy0>;
};
- 編譯u-boot:
清除中間編譯:
make distclean
使用配置檔案:
make CROSS_COMPILE=arm-linux-gnueabihf- zynq_zed_defconfig
通過下述指令可在介面中uboot進行進一步修改配置:改defconfig檔案也可以,暫時預設即可
make CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
工具編譯:
make CROSS_COMPILE=arm-linux-gnueabihf- tools
編譯u-boot:
make CROSS_COMPILE=arm-linux-gnueabihf-
-
修改總裝置樹的boottags:console=ttyPS0,115200n8 root=/dev/mmcblk1p2 rw noinitrd rootfstype=ext4 rootwait
-
修改uEnv.txt為:mmc 0修改為mmc 1;root=/dev/mmcblk1p2
bootargs=console=ttyPS0,115200 root=/dev/mmcblk1p2 rw earlyprintk rootfstype=ext4 rootwait
load_image=fatload mmc 1 ${kernel_load_address} ${kernel_image} && fatload mmc 1 ${devicetree_load_address} ${devicetree_image}
uenvcmd=echo Copying Linux from SD to RAM... && mmcinfo && run load_image && bootm ${kernel_load_address} - ${devicetree_load_address}
- 組裝BOOT.bin,不贅述。
- 燒錄BOOT.bin到FLASH,對EMMC進行分割槽,EMMC分割槽一中放置uImage、devicetree.dtb、uEnv.txt,EMMC分割槽二中放置檔案系統即可。
- 啟動。
U-Boot 2018.01-dirty (Jul 26 2021 - 20:05:00 +0800)
Model: Zynq Zed Development Board
Board: Xilinx Zynq
Silicon: v3.1
DRAM: ECC disabled 512 MiB
MMC: sdhci_transfer_data: Error detected in status(0x208000)!
sdhci@e0101000: 1 (eMMC)
SF: Detected s25fl128s_64k with page size 256 Bytes, erase size 64 KiB, total 16 MiB
*** Warning - bad CRC, using default environment
In: serial@e0000000
Out: serial@e0000000
Err: serial@e0000000
Net: ZYNQ GEM: e000b000, phyaddr 0, interface rgmii-id
eth0: ethernet@e000b000
Hit any key to stop autoboot: 0
sdhci_transfer_data: Error detected in status(0x208000)!
switch to partitions #0, OK
mmc1(part 0) is current device
Device: sdhci@e0101000
Manufacturer ID: 13
OEM: 14e
Name: Q2J55
Tran Speed: 25000000
Rd Block Len: 512
MMC version 5.0
High Capacity: Yes
Capacity: 7.1 GiB
Bus Width: 4-bit
Erase Group Size: 512 KiB
HC WP Group Size: 8 MiB
User Capacity: 7.1 GiB WRREL
Boot Capacity: 16 MiB ENH
RPMB Capacity: 4 MiB ENH
reading uEnv.txt
356 bytes read in 11 ms (31.3 KiB/s)
Loaded environment from uEnv.txt
Importing environment from SD ...
Running uenvcmd ...
Copying Linux from SD to RAM...
Device: sdhci@e0101000
Manufacturer ID: 13
OEM: 14e
Name: Q2J55
Tran Speed: 25000000
Rd Block Len: 512
MMC version 5.0
High Capacity: Yes
Capacity: 7.1 GiB
Bus Width: 4-bit
Erase Group Size: 512 KiB
HC WP Group Size: 8 MiB
User Capacity: 7.1 GiB WRREL
Boot Capacity: 16 MiB ENH
RPMB Capacity: 4 MiB ENH
reading uImage
4001616 bytes read in 377 ms (10.1 MiB/s)
reading devicetree.dtb
17052 bytes read in 18 ms (924.8 KiB/s)
## Booting kernel from Legacy Image at 02080000 ...
Image Name: Linux-4.14.0-xilinx
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 4001552 Bytes = 3.8 MiB
Load Address: 00008000
Entry Point: 00008000
Verifying Checksum ... OK
## Flattened Device Tree blob at 02000000
Booting using the fdt blob at 0x2000000
Loading Kernel Image ... OK
Loading Device Tree to 1eb12000, end 1eb1929b ... OK
以上。