使用lwip-tcp远程对QSPI进行更新、QSPI FLASH启动
W25Q128资料:
W25Q128JV datasheet(1/78 Pages) WINBOND | 3V 128M-bit serial flash memory with dual/quad spi (alldatasheet.com)
UG585资料:
Zynq 7000 SoC Technical Reference Manual-UG585
翻译水平有限。
2024.05.27:
- 最近再研究远程升级的问题,都做完了,确实是欠考虑了,如果程序升级过程中死掉了或者因为其他原因导致重启之后跑不了的话,程序无法回滚。。。
- 再有就是我使用FSBL生成的引导程序,BOOT.bin文件=FSBL.elf+程序.elf+FPGA.bit。
- 考虑到之前学过BootLoader,那么就需要把BOOT.bin拆成Bootloader和APP程序(FPGA.bit+程序.elf)。也就是说要自己写引导程序。
- FLASH型号:W25Q128,128Mb=16MB,分析了之前的BOOT.bin存在的地址是从0x0000_0000开始的。
分析一下zynq启动过程:
Device Boot Flowchart
PS部分
重新上电复位:复位所有寄存器硬件采样mode引脚;JTAG/IOP/DDR等控制器失能;根据使用标头加密参数的BootROM确定安全Boot模式;PLL通过。
非重新上电复位:保持之前的Boot模式,使用devcfg.CTRL[SEC_EN]寄存器位供BootROM访问;复位除了保持的寄存器之外的寄存器;安全、非安全模式。
阶段0:BootROM 执行
阶段1:FSBL(引导加载程序)或用户代码
阶段2:操作系统
PL部分
PL硬件包含一个用来准备初始化的自启动序列。后续就是进行初始化,配置,使能。
Boot Modes
BootROM Code
2024.05.28:
参考我自己写的思路:
规划分区:
//Every 32KB find BOOTROM valid header
xil_printf("---------- Enter BootLoader----------\n");
xil_printf(" BOOTLOADER VERSION: %s.%s\n",MAJOR_BOOT_VERSION,MINOR_BOOT_VERSION);
xil_printf("======== flash pration table ========\n");
xil_printf("| name | offset | size |\n");
xil_printf("-------------------------------------\n");
xil_printf("| boot | 0x00000000 | 0x00100000|\n");//32KB*32=1024KB=1MB
xil_printf("| app | 0x00100000 | 0x00600000|\n");//32KB*32*6=6MB
xil_printf("| download | 0x00700000 | 0x00600000|\n");//32KB*32*6=6MB
xil_printf("| setting | 0x00D00000 | 0x00300000|\n");//32KB*32*3=3MB
xil_printf("=====================================\n");
调试的时候,可以在FSBL工程/src/fsbl_debug.h添加宏定义,可以看到启动过程中的调试信息。
#define FSBL_DEBUG_INFO
控制程序重启:
#define PSS_RST_CTRL_REG 0xF8000200 //PSS_RST_CTRL寄存器,绝对地址,
#define SLCR_UNLOCK_ADDR 0xF8000008 //SLCR_UNLOCK寄存器,绝对地址,
#define UNLOCK_KEY 0xDF0D //使能码
#define PSS_RST_MASK 0x01 //复位码
void PsSoftwareReset(void)
{
Xil_Out32(SLCR_UNLOCK_ADDR, UNLOCK_KEY); //写使能
Xil_Out32(PSS_RST_CTRL_REG, PSS_RST_MASK); //复位
}
2024.05.29:
ZYNQ软件复位重启、程序跳转的实现方法(Multiboot)_zynq multiboot-CSDN博客
控制程序跳转:
#define XDCFG_MULTIBOOT_ADDR_OFFSET_REG 0xF800702C //MULTIBOOT寄存器,绝对地址,
#define XDCFG_UNLOCK_OFFSET_ADDR 0xF8007034 //XDCFG_UNLOCK_寄存器,绝对地址,
#define UNLOCK_XDCFG_KEY 0x757BDF0D //使能码
#define APP1_LOCATION 0x00 //APP1位置
#define APP2_LOCATION 0x08 //APP2位置,以32KB为单位,8*0x8000=0x400000
void ModifyMultiBoot(void)
{
Xil_Out32(XDCFG_UNLOCK_OFFSET_ADDR , UNLOCK_XDCFG_KEY ); //写使能
Xil_Out32(XDCFG_MULTIBOOT_ADDR_OFFSET_REG , APP2_LOCATION ); //更改MULTIBOOT
}
MultiBoot
zynq是按照每32KB搜索有效启动头。
2024.05.30:
学到了一个东西,这个地方可以调整,可以把文件烧到不同的地方。
程序框架搭完了,网络连接不上,还没找到原因,原来的程序就行,新建的程序不行,使用的还是同一个bsp。
后来通过一点一点注释代码,发现不能在while(1)里面加usleep,会导致网络连不上。
2024.05.31:
早上测试烧录正常,但是不能从BootLoader切换到download区。找到问题原因,修改程序:
Xil_Out32(XDCFG_MULTIBOOT_ADDR_OFFSET_REG , DOWNLOAD_LOCATION ); //更改MULTIBOOT
#define DOWNLOAD_LOCATION 0x12
这个DOWNLOAD_LOCATION 以32KB为单位,0x12*0x8000=0x00100000
升级完成,成功切换了!!!
Xilinx First Stage Boot Loader
Release 2018.3 May 31 2024-08:13:52
Devcfg driver initialized
Silicon Version 3.1
Boot mode is QSPI
Single Flash Information
FlashID=0xEF 0x40 0x18
WINBOND 128M Bits
QSPI is in single flash connection
QSPI is in 4-bit mode
QSPI Init Done
Flash Base Address: 0xFC000000
Reboot status register: 0x60400000
Multiboot Register: 0x0000C000
Image Start Address: 0x00000000
Partition Header Offset:0x00000C80
Partition Count: 2
Partition Number: 1
Header Dump
Image Word Len: 0x0000C004
Data Word Len: 0x0000C004
Partition Word Len:0x0000C004
Load Addr: 0x00100000
Exec Addr: 0x00100000
Partition Start: 0x000075D0
Partition Attr: 0x00000010
Partition Checksum Offset: 0x00000000
Section Count: 0x00000001
Checksum: 0xFFDD47C2
Application
PCAP:StatusReg = 0x40000A30
PCAP:device ready
PCAP:Clear done
PCAP register dump:
PCAP CTRL 0xF8007000: 0x4C00E07F
PCAP LOCK 0xF8007004: 0x0000001A
PCAP CONFIG 0xF8007008: 0x00000508
PCAP ISR 0xF800700C: 0x00030000
PCAP IMR 0xF8007010: 0xFFFFFFFF
PCAP STATUS 0xF8007014: 0x00000A30
PCAP DMA SRC ADDR 0xF8007018: 0xFC01D741
PCAP DMA DEST ADDR 0xF800701C: 0x00100001
PCAP DMA SRC LEN 0xF8007020: 0x0000C004
PCAP DMA DEST LEN 0xF8007024: 0x0000C004
PCAP ROM SHADOW CTRL 0xF8007028: 0xFFFFFFFF
PCAP MBOOT 0xF800702C: 0x0000C000
PCAP SW ID 0xF8007030: 0x00000000
PCAP UNLOCK 0xF8007034: 0x757BDF0D
PCAP MCTRL 0xF8007080: 0x30800110
DMA Done !
Handoff Address: 0x00100000
In FsblHookBeforeHandoff function
SUCCESSFUL_HANDOFF
FSBL Status = 0x1
FlashID=0xef 0x40 0x18
Successfully init QSPI
Blink,Blink,Blink
link speed for phy address 1: 100
Board IP: 192.168.2.250
Netmask : 255.255.255.0
Gateway : 192.168.2.1
Blink,Blink,Blink
Blink,Blink,Blink
txperf: Connected to iperf server
Start QSPI Update!
file size of BOOT.bin is 3827984 Bytes
Performing Erase Operation...
0%..10%..20%..30%..40%..50%..60%..70%..80%..90%..100%
Erase Operation Successful.
INFO:Elapsed time = 11.910 sec.
Performing Program Operation...
0%..10%..20%..30%..40%..50%..60%..70%..80%..90%..100%
Program Operation Successful.
INFO:Elapsed time = 7.478 sec.
Performing Verify Operation...
0%..10%..20%..30%..40%..50%..60%..70%..80%..90%..100%
Verify Operation Successful.
INFO:Elapsed time = 3.132 sec.
Update Q
Xilinx First Stage Boot Loader
Release 2018.3 May 31 2024-08:15:57
Devcfg driver initialized
Silicon Version 3.1
Boot mode is QSPI
Single Flash Information
FlashID=0xEF 0x40 0x18
WINBOND 128M Bits
QSPI is in single flash connection
QSPI is in 4-bit mode
QSPI Init Done
Flash Base Address: 0xFC000000
Reboot status register: 0x60480000
Multiboot Register: 0x0000C0E0
Image Start Address: 0x00700000
Partition Header Offset:0x00700C80
Partition Count: 3
Partition Number: 1
Header Dump
Image Word Len: 0x000D6468
Data Word Len: 0x000D6468
Partition Word Len:0x000D6468
Load Addr: 0x00000000
Exec Addr: 0x00000000
Partition Start: 0x000075D0
Partition Attr: 0x00000020
Partition Checksum Offset: 0x00000000
Section Count: 0x00000001
Checksum: 0xFFD75A86
Bitstream
In FsblHookBeforeBitstreamDload function
PCAP:StatusReg = 0x40000A30
PCAP:device ready
PCAP:Clear done
Level Shifter Value = 0xA
Devcfg Status register = 0x40000A30
PCAP:Fabric is Initialized done
PCAP register dump:
PCAP CTRL 0xF8007000: 0x4C00E07F
PCAP LOCK 0xF8007004: 0x0000001A
PCAP CONFIG 0xF8007008: 0x00000508
PCAP ISR 0xF800700C: 0x0802000B
PCAP IMR 0xF8007010: 0xFFFFFFFF
PCAP STATUS 0xF8007014: 0x00000A30
PCAP DMA SRC ADDR 0xF8007018: 0xFC71D741
PCAP DMA DEST ADDR 0xF800701C: 0xFFFFFFFF
PCAP DMA SRC LEN 0xF8007020: 0x000D6468
PCAP DMA DEST LEN 0xF8007024: 0x000D6468
PCAP ROM SHADOW CTRL 0xF8007028: 0xFFFFFFFF
PCAP MBOOT 0xF800702C: 0x0000C0E0
PCAP SW ID 0xF8007030: 0x00000000
PCAP UNLOCK 0xF8007034: 0x757BDF0D
PCAP MCTRL 0xF8007080: 0x30800100
...................................................................................................
DMA Done !
FPGA Done !
In FsblHookAfterBitstreamDload function
Partition Number: 2
Header Dump
Image Word Len: 0x0000C004
Data Word Len: 0x0000C004
Partition Word Len:0x0000C004
Load Addr: 0x00100000
Exec Addr: 0x00100000
Partition Start: 0x000DDA40
Partition Attr: 0x00000010
Partition Checksum Offset: 0x00000000
Section Count: 0x00000001
Checksum: 0xFFCFE342
Application
PCAP:StatusReg = 0x40000F30
PCAP:device ready
PCAP:Clear done
PCAP register dump:
PCAP CTRL 0xF8007000: 0x4C00E07F
PCAP LOCK 0xF8007004: 0x0000001A
PCAP CONFIG 0xF8007008: 0x00000508
PCAP ISR 0xF800700C: 0x00030004
PCAP IMR 0xF8007010: 0xFFFFFFFF
PCAP STATUS 0xF8007014: 0x00000F30
PCAP DMA SRC ADDR 0xF8007018: 0xFCA76901
PCAP DMA DEST ADDR 0xF800701C: 0x00100001
PCAP DMA SRC LEN 0xF8007020: 0x0000C004
PCAP DMA DEST LEN 0xF8007024: 0x0000C004
PCAP ROM SHADOW CTRL 0xF8007028: 0xFFFFFFFF
PCAP MBOOT 0xF800702C: 0x0000C0E0
PCAP SW ID 0xF8007030: 0x00000000
PCAP UNLOCK 0xF8007034: 0x757BDF0D
PCAP MCTRL 0xF8007080: 0x30800110
DMA Done !
Handoff Address: 0x00100000
In FsblHookBeforeHandoff function
SUCCESSFUL_HANDOFF
FSBL Status = 0x1
=====================================
------------- Enter APP -------------
PROGRAM VERSION: 000.003
=====================================
FlashID=0xef 0x40 0x18
Successfully init QSPI
Blink,Blink,Blink
link speed for phy address 1: 100
Board IP: 192.168.2.239
Netmask : 255.255.255.0
Gateway : 192.168.2.1
Blink,Blink,Blink
Blink,Blink,Blink
Blink,Blink,Blink
txperf: Connected to iperf server
start adc
然后就是要考虑在Setting区域,给boot_state、download_state、app_state、ip等信息置位。尝试了直接写,读出来值不对,查了好多资料,也没说到底怎做。
后来对比了正点原子和其他例程,开始怀疑是不是W25Q128有什么说法。
2024.06.03:
搜索了一下W25Q128说是要先擦除,再写入。
每次你要先从FLASH读出来,存在数组里,修改某个字节之后,先擦除,再写到FLASH里。还有FLASH没写过的时候全是1,只能从1变成0,不能让0变成1。如果想让0变成1,就要全部刷掉然后再写。
测试写入IP地址,确实没问题。
考虑到感觉没有必要写回滚。规划分区APP那一分区暂时不用。
从BootLoader下载APP(download区),到APP(download区)运行;从APP(download区)回到BootLoader下载新的APP(download区),再到新APP(download区)运行。运行了一圈没问题。