作者:付汉杰 hankf@amd.com,文章来源:博客园
Xilinx MPSoC的FSBL中使用了看门狗,避免单板进入异常后一直挂死。下面是FSBL关于看门狗的用法总结。
Vivado配置
Vivado中的PS配置中,如果使能了wdt,FSBL会自动使能看门狗。
/** * Definition for WDT to be included */ #if (!defined(FSBL_WDT_EXCLUDE) && defined(XPAR_PSU_WDT_0_DEVICE_ID)) #define XFSBL_WDT_PRESENT #define XFSBL_WDT_DEVICE_ID XPAR_PSU_WDT_0_DEVICE_ID #define XFSBL_WDT_MASK PMU_GLOBAL_ERROR_SRST_EN_1_LPD_SWDT_MASK #elif (!defined(FSBL_WDT_EXCLUDE) && defined(XPAR_PSU_WDT_1_DEVICE_ID)) #define XFSBL_WDT_PRESENT #define XFSBL_WDT_DEVICE_ID XPAR_PSU_WDT_1_DEVICE_ID #define XFSBL_WDT_MASK PMU_GLOBAL_ERROR_SRST_EN_1_FPD_SWDT_MASK #endif
初始化和使能流程
WDT的初始化代码的实现在xfsbl_misc_drivers.c中的函数XFsbl_InitWdt( )中,它在xfsbl_initialization.c中的函数 XFsbl_PrimaryBootDeviceInit( )中被调用。
关闭流程
在FSBL正常退出前, 在文件xfsbl_handoff.c中的函数XFsbl_Handoff ( )中, FSBL调用了XFsbl_StopWdt(),关闭看门狗。
#ifdef XFSBL_WDT_PRESENT if (XFSBL_MASTER_ONLY_RESET != FsblInstancePtr->ResetReason) { /* Stop WDT as we are exiting FSBL */ XFsbl_StopWdt(); } #endif
超时时间
WDT的默认超时时间,XFSBL_WDT_EXPIRE_TIME,是100秒。
#ifdef XFSBL_WDT_PRESENT #define XFSBL_WDT_EXPIRE_TIME (100U) #define XFSBL_WDT_CRV_SHIFT (12U) #endif
重启处理
如果看门狗导致复位,FSBL会返回错误状态值XFSBL_ERROR_SYSTEM_WDT_RESET,从而进入XFSBL_STAGE_ERR,执行XFsbl_ErrorLockDown()和XFsbl_FallBack( )。XFsbl_FallBack( )会增加MULTI_BOOT值,并再次重启动。FallBack操作要求启动设备中有多个Boot.bin。
如果不希望Fallback和再次复位,可以修改代码XFsbl_ResetValidation( ),请参考下面的代码注释“goto END”即可。
#ifdef XFSBL_WDT_PRESENT ResetReasonValue = XFsbl_In32(CRL_APB_RESET_REASON); XFsbl_Printf(DEBUG_GENERAL," ResetReason register: %08x.\n\r", ResetReasonValue); XFsbl_Out32(CRL_APB_RESET_REASON, ResetReasonValue); /** * Check if the reset is due to system WDT during * previous FSBL execution */ if ((ResetReasonValue & CRL_APB_RESET_REASON_PMU_SYS_RESET_MASK) == CRL_APB_RESET_REASON_PMU_SYS_RESET_MASK) { ErrStatusRegValue = XFsbl_In32(PMU_GLOBAL_ERROR_STATUS_1); XFsbl_Printf(DEBUG_GENERAL," ERROR_STATUS_1: %08x.\n\r", ErrStatusRegValue); if(((ErrStatusRegValue & XFSBL_WDT_MASK) == XFSBL_WDT_MASK) && (FsblErrorStatus == XFSBL_RUNNING)) { /* Clear the SWDT0/1 reset error */ XFsbl_Out32(PMU_GLOBAL_ERROR_STATUS_1, XFSBL_WDT_MASK); /** * reset is due to System WDT. * Do a fallback */ Status = XFSBL_ERROR_SYSTEM_WDT_RESET; XFsbl_Printf(DEBUG_GENERAL,"XFSBL_ERROR_SYSTEM_WDT_RESET, fallback\n\r"); goto END; } } #endif
Fallback
请参考UG1085 的章节“Golden Image Search”。
对于QSPI Flash,依次增加32 KB偏移地址来搜索后续的启动映像。对于SD,按boot0001.bin, boot0002.bin, boot0003.bin, ......, boot4095.bin的顺序来搜索后续的启动映像。建议偏移或者文件序号不要太大,否则搜索过程可能花费比较长的时间。比如第一次上电,MultiBoot为0,从SD卡启动搜索到boot0001.bin几乎不需要时间,从SD卡启动搜索到boot2048.bin大约需要8秒钟。
boot4095.bin的启动记录如下:
Xilinx Zynq MP First Stage Boot Loader Release 2021.2 Dec 9 2022 - 10:09:44 MultiBootOffset: 0xFFF Reset Mode : System Reset Platform: Silicon (4.0), Cluster ID 0x80000000 Running on A53-0 (64-bit) Processor, Device Name: XCZU7EV FMC VADJ Configuration Successful Board Configuration successful ResetReason register: 00000001. Processor Initialization Done RESET_REASON: 00000000. RESET_REASON register: 00000001. ================= In Stage 2 ============ FsblInstance.ResetReason: 0. WDT initialization successed SD1 with level shifter Boot Mode SD: rc= 0 File name is BOOT4095.BIN Multiboot Reg : 0xFFF Image Header Table Offset 0x8C0 *****Image Header Table Details******** Boot Gen Ver: 0x1020000 No of Partitions: 0x3 Partition Header Address: 0x440 Partition Present Device: 0x0 Initialization Success ======= In Stage 3, Partition No:1 ======= UnEncrypted data Length: 0x2430DE Data word offset: 0x2430DE Total Data word length: 0x2430DE Destination Load Address: 0xFFFFFFFF Execution Address: 0x0 Data word offset: 0x8EA0 Partition Attributes: 0x26 Destination Device is PL, changing LoadAddress Non authenticated Bitstream download to start now DMA transfer done PL Configuration done successfully Partition 1 Load Success ======= In Stage 3, Partition No:2 ======= UnEncrypted data Length: 0x2C12 Data word offset: 0x2C12 Total Data word length: 0x2C12 Destination Load Address: 0x0 Execution Address: 0x0 Data word offset: 0x24BF80 Partition Attributes: 0x116 Partition 2 Load Success All Partitions Loaded ================= In Stage 4 ============ PMU-FW is not running, certain applications may not be supported. Protection configuration applied Running Cpu Handoff address: 0x0, Exec State: 0 Exit from FSBL WDT Polled Mode Example Test WdtPsPolledExample: 000240, timer: 094655D3 = 155604435 at the beginning. WdtPsPolledExample: 000295, Zero Mode Register(00): 000001C2 WdtPsPolledExample: 000299, Counter Control Register(04): 000003FD WdtPsPolledExample: 000309, Status Register(08): 00000000 WdtPsPolledExample: 000320, ERROR_SRST_EN_1 Register(08): 00000000 WdtPsPolledExample: 000329, ERROR_EN_1 Register(08): 00001000 WdtPsPolledExample: 000346, timer: 097CD774 = 159176564, after 35721 ms before loop.