软硬件环境:
- 主控: Zynq® UltraScale+™ RFSoC zu67dr
- Flash:GD25Q128E,GD55B02GE
- 系统: petalinux 2021.2
- Kernel: 5.10.0
概述:
- 对于FPGA外设国产化的需求。
- 想让xilinx官方支持新的flash,那得等到天荒地老。ps: xilinx的FAE还找我要新FLASH的支持代码呢。
- 大家都知道要想ZYNQ支持新的flash,不只是uboot支持就行了,因为ZYNQ的bootrom加载的第一个程序是FSBL,uboot是靠FSBL从flash拷贝到内存中运行,所以想要支持新的flash启动,则需要在FSBL中增加新FLASH的支持。
- 本文以GD25Q128E和GD55B02GE为例讲解,如何让FSBL支持国产flash,进而能够通过国产FLASH启动整个系统。
- 本文能够起到抛砖引玉的目的,让你看完之后,能够适配其他厂家不同型号的flash,使其能够启动zynq。
调试:
- 适配之前将fsbl烧录到flash,可见出错日志如下,能够正常读取flash id,但是报XFSBL_ERROR_UNSUPPORTED_QSPI
Xilinx Zynq MP First Stage Boot Loader
Release 2022.2 Jan 11 2023 - 09:00:43
MultiBootOffset: 0x0
Reset Mode : System Reset
Platform: Silicon (4.0), Cluster ID 0x80000000
Running on A53-0 (64-bit) Processor, Device Name: XCZU15EG
Processor Initialization Done
================= In Stage 2 ============
PrimaryBootDevice:1
QSPI 24bit Boot Mode
QSPI is in single flash connection
QSPI is using 4 bit bus
FlashID=0xC8 0x40 0x18
XFSBL_ERROR_UNSUPPORTED_QSPI
Boot Device Initialization failed 0xB
================= In Stage Err ============
Fsbl Error Status: 0x0
代码修改
- 在 FlashReadID函数中增加GIGADEVICE_ID信息,对于GD55B02GE等大容量,BGA24封装的flash,查看手册可知,上电默认就支持Quad SPI模式(the default state of the device is Standard/Quad SPI mode.),所以不需要额外的设置模式切换。
@@ -128,6 +131,7 @@ static u32 FlashReadID(XQspiPsu *QspiPsuPtr)
* Deduce flash make
*/
MacronixFlash = 0U;
+ GigadeviceFlash = 0U;
if (ReadBuffer[0] == MICRON_ID) {
QspiFlashMake = MICRON_ID;
XFsbl_Printf(DEBUG_INFO, "MICRON ");
@@ -144,6 +148,10 @@ static u32 FlashReadID(XQspiPsu *QspiPsuPtr)
} else if(ReadBuffer[0] == ISSI_ID) {
QspiFlashMake = ISSI_ID;
XFsbl_Printf(DEBUG_INFO, "ISSI ");
+ } else if(ReadBuffer[0] == GIGADEVICE_ID) {
+ QspiFlashMake = GIGADEVICE_ID;
+ XFsbl_Printf(DEBUG_INFO, "GIGADEVICE ");
+ GigadeviceFlash = 1U;
} else {
UStatus = XFSBL_ERROR_UNSUPPORTED_QSPI;
XFsbl_Printf(DEBUG_GENERAL,"XFSBL_ERROR_UNSUPPORTED_QSPI\r\n");
@@ -187,7 +195,8 @@ static u32 FlashReadID(XQspiPsu *QspiPsuPtr)
|| (ReadBuffer[2] == MACRONIX_FLASH_1_8_V_SIZE_ID_2G)) {
QspiFlashSize = FLASH_SIZE_2G;
if ((QspiFlashMake == WINBOND_ID) ||
- (QspiFlashMake == MICRON_ID)) {
+ (QspiFlashMake == MICRON_ID) ||
+ (QspiFlashMake == GIGADEVICE_ID)) {
MultiDie = (u8)TRUE;
}
XFsbl_Printf(DEBUG_INFO, "2G Bits\r\n");
-
但是对于GD25Q128E等小容量flash,因为默认不是使用的qspi模式,因此需要设置相应寄存器(参考:GD25Q128E-Rev1.2 page 14),设置状态寄存器(Status Register-SR No.2)第S9为1即可。
-
对于容量小于16M的FLASH(例如:GD25Q128E),默认只支持3-byte address (A23-A0) 模式,因为3-byte(0xffffff=16,777,215)最大可寻址16M,没必要采用4-byte地址模式,所以只须针对XFsbl_Qspi24Init做设置即可,也可以做得更智能一点,判断flash id型号,对指定型号做相应设置,目前作者的方法只是起一个抛砖引玉的过程。
@@ -345,6 +354,13 @@ u32 XFsbl_Qspi24Init(u32 DeviceFlags)
(QspiPsuInstance.Config.BusWidth == XFSBL_QSPI_BUSWIDTH_FOUR)) {
ReadCommand = QUAD_READ_CMD_24BIT2;
}
+
+ if ((GigadeviceFlash == 1U) &&
+ (QspiPsuInstance.Config.BusWidth == XFSBL_QSPI_BUSWIDTH_FOUR)) {
+ XFsbl_Printf(DEBUG_GENERAL, "GigadeviceEnableQPIMode...\n\r");
+ GigadeviceEnableQPIMode(&QspiPsuInstance, ENABLE_QPI);
+ }
+
/**
* add code: For a Stacked connection, read second Flash ID
*/
修改petalinux:
● 修改petalinux,建立fsbl-firmware_%.bbappend,将fsbl的修改制作成相应patch。
● 编译petalinux,生成BOOT.bin,通过vivado 烧录到FLASH即可(至于vivado 如何增加新的flash支持,请听下回分解)。
启动LOG:
- 因为博主打开了fsbl的调试开关,所以fsbl的日志比默认要多。
Zynq MP First Stage Boot Loader
Release 2021.2 Oct 13 2021 - 07:15:53
MultiBootOffset: 0x0
Reset Mode : System Reset
Platform: Silicon (4.0), Cluster ID 0x80000000
Running on A53-0 (64-bit) Processor, Device Name: XCZU15EG
Processor Initialization Done
================= In Stage 2 ============
QSPI 24bit Boot Mode
QSPI is in single flash connection
QSPI is using 4 bit bus
FlashID=0xC8 0x40 0x18
GIGADEVICE 128M Bits
GigadeviceEnableQPIMode...
Old status register no.2:0x02
new status register no.2:0x02
Multiboot Reg : 0x0
QSPI Reading Src 0x0, Dest FFFF0040, Length EC0
.QSPI Read Src 0x0, Dest FFFF0040, Length EC0
Image Header Table Offset 0x8C0
QSPI Reading Src 0x8C0, Dest FFFDA0A8, Length 40
.QSPI Read Src 0x8C0, Dest FFFDA0A8, Length 40
*****Image Header Table Details********
Boot Gen Ver: 0x1020000
No of Partitions: 0x5
Partition Header Address: 0x440
Partition Present Device: 0x0
QSPI Reading Src 0x1100, Dest FFFDA0E8, Length 40
.QSPI Read Src 0x1100, Dest FFFDA0E8, Length 40
QSPI Reading Src 0x1140, Dest FFFDA128, Length 40
.QSPI Read Src 0x1140, Dest FFFDA128, Length 40
QSPI Reading Src 0x1180, Dest FFFDA168, Length 40
.QSPI Read Src 0x1180, Dest FFFDA168, Length 40
QSPI Reading Src 0x11C0, Dest FFFDA1A8, Length 40
.QSPI Read Src 0x11C0, Dest FFFDA1A8, Length 40
QSPI Reading Src 0x1200, Dest FFFDA1E8, Length 40
.QSPI Read Src 0x1200, Dest FFFDA1E8, Length 40
Initialization Success
======= In Stage 3, Partition No:1 =======
UnEncrypted data Length: 0x31E8
Data word offset: 0x31E8
Total Data word length: 0x31E8
Destination Load Address: 0xFFFEA000
Execution Address: 0xFFFEA000
Data word offset: 0xF540
Partition Attributes: 0x117
QSPI Reading Src 0x3D500, Dest FFFEA000, Length C7A0
.QSPI Read Src 0x3D500, Dest FFFEA000, Length C7A0
Partition 1 Load Success
======= In Stage 3, Partition No:2 =======
UnEncrypted data Length: 0x38041
Data word offset: 0x38041
Total Data word length: 0x38041
Destination Load Address: 0x8000000
Execution Address: 0x8000000
Data word offset: 0x12730
Partition Attributes: 0x114
QSPI Reading Src 0x49CC0, Dest 8000000, Length E0104
.QSPI Read Src 0x49CC0, Dest 8000000, Length E0104
Partition 2 Load Success
======= In Stage 3, Partition No:3 =======
UnEncrypted data Length: 0x8000
Data word offset: 0x8000
Total Data word length: 0x8000
Destination Load Address: 0x0
Execution Address: 0x0
Data word offset: 0x80000
Partition Attributes: 0x116
QSPI Reading Src 0x200000, Dest 0, Length 20000
.QSPI Read Src 0x200000, Dest 0, Length 20000
Partition 3 Load Success
======= In Stage 3, Partition No:4 =======
UnEncrypted data Length: 0x118
Data word offset: 0x118
Total Data word length: 0x118
Destination Load Address: 0x0
Execution Address: 0x0
Data word offset: 0x88000
Partition Attributes: 0x116
QSPI Reading Src 0x220000, Dest 0, Length 460
.QSPI Read Src 0x220000, Dest 0, Length 460
Partition 4 Load Success
All Partitions Loaded
================= In Stage 4 ============
PM Init Success
Protection configuration applied
Running ÿNOTICE: BL31: v2.4(release):xlnx_rebase_v2.4_2021.2
NOTICE: BL31: Built : 07:41:24, Oct 13 2021
U-Boot 2021.01 (Jun 20 2022 - 11:02:21 +0000)
CPU: ZynqMP
Silicon: v3
Board: Xilinx ZynqMP
DRAM: 1023 MiB
PMUFW: v1.1
EL Level: EL2
Chip ID: zu67dr
WDT: Started with servicing (60s timeout)
MMC: mmc@ff160000: 0
Loading Environment from SPIFlash... SF: Detected gd25q128 with page size 256 Bytes, erase size 64 KiB, total 16 MiB
OK
In: serial
Out: serial
Err: serial
Bootmode: QSPI_MODE
RSA STATUS: OFF
Reset reason: EXTERNAL
Net:
ZYNQ GEM: ff0b0000, mdio bus ff0b0000, phyaddr 1, interface sgmii
mii bus: eth0 phy_mask: 2 devad: -1 get_phy_id:0x4f51e91a
Get yt8521S mode: 2, poll or utp
find phy drv name: YT8531S Ethernet
hw_strap_mode: 0x3
Warning: ethernet@ff0b0000 MAC addresses don't match:
Address in DT is 00:0a:35:00:57:ae
Address in environment is 00:0a:35:00:1a:8b
eth0: ethernet@ff0b0000AXI EMAC: a1020000, phyaddr 0, interface mii
, eth1: ethernet@a1020000AXI EMAC: a1030000, phyaddr 0, interface mii
, eth2: ethernet@a1030000
get clu reset gpio: 31
CLU: reset successfully
Hit any key to stop autoboot: 0
zboot>