lib/sw_services/xilloader/src/xloader.c
int XLoader_PdiInit(XilPdi* PdiPtr, PdiSrc_t PdiSrc, u64 PdiAddr)
{
	volatile int Status = XST_FAILURE;
	u32 RegVal = XPlmi_In32(PMC_GLOBAL_PMC_MULTI_BOOT);
	u64 PdiInitTime = XPlmi_GetTimerValue();
	XPlmi_PerfTime PerfTime;
	u8 DeviceFlags = (u8)(PdiSrc & XLOADER_PDISRC_FLAGS_MASK);
	u32 SdRawBootVal = RegVal & XLOADER_SD_RAWBOOT_MASK;
	const char *RawString = "";
	const PdiSrcMap PdiSourceMap[] = {
		{"SBI", XLOADER_SBI_INDEX}, /* SBI JTAG - 0 */
		{"QSPI24", XLOADER_QSPI_INDEX}, /* QSPI24 - 1 */
		{"QSPI32", XLOADER_QSPI_INDEX}, /* QSPI32 - 2 */
		{"SD0", XLOADER_SD_INDEX}, /* SD0 - 3 */
		{"EMMC0", XLOADER_SD_INDEX}, /* EMMC0 - 4 */
		{"SD1", XLOADER_SD_INDEX}, /* SD1 - 5 */
		{"EMMC1", XLOADER_SD_INDEX}, /* EMMC - 6 */
		{"USB", XLOADER_USB_INDEX}, /* USB - 7 */
		{"OSPI", XLOADER_OSPI_INDEX}, /* OSPI - 8 */
		{"SBI", XLOADER_SBI_INDEX}, /* SBI - 9*/
		{"SMAP", XLOADER_SBI_INDEX}, /* SMAP - 0xA */
		{"PCIE", XLOADER_SBI_INDEX}, /* PCIE - 0xB */
		{"", XLOADER_INVALID_INDEX}, /* Unused - 0xC */
		{"", XLOADER_INVALID_INDEX}, /* Unused - 0xD */
		{"SD1_LS", XLOADER_SD_INDEX}, /* SD1_LS - 0xE */
		{"DDR", XLOADER_DDR_INDEX}, /* DDR - 0xF */
	};

	/*
	 * Mark PDI loading is started.
	 */
	XPlmi_Out32(PMC_GLOBAL_DONE, XLOADER_PDI_LOAD_STARTED);

	/*
	 * Store address of the structure in PMC_GLOBAL.GLOBAL_GEN_STORAGE4.
	 */
	XPlmi_Out32(PMC_GLOBAL_GLOBAL_GEN_STORAGE4,
		(u32)((UINTPTR) &ATFHandoffParams));

	if (DeviceFlags >= XPLMI_ARRAY_SIZE(PdiSourceMap)) {
		goto END1;
	}

	PdiPtr->PdiIndex = PdiSourceMap[DeviceFlags].Index;
	if (PdiPtr->PdiIndex == XLOADER_SD_INDEX) {
		if (PdiPtr->PdiType != XLOADER_PDI_TYPE_FULL) {
			SdRawBootVal = PdiSrc & XLOADER_SD_RAWBOOT_MASK;
		}
		else {
			if ((SdRawBootVal == XLOADER_SD_RAWBOOT_MASK) ||
				(SdRawBootVal == 0U)) {
				/* 0 is for QEMU */
				PdiSrc |= (RegVal << XLOADER_PDISRC_FLAGS_SHIFT);
			}
			else {
				PdiSrc |= SdRawBootVal;
			}
		}
		if ((SdRawBootVal != 0U) &&
			(SdRawBootVal != XLOADER_SD_RAWBOOT_MASK)) {
			PdiPtr->PdiIndex = XLOADER_SD_RAW_INDEX;
			if (SdRawBootVal == XLOADER_EMMC_BP1_RAW_VAL) {
				RawString = "_RAW_BP1";
			}
			else if (SdRawBootVal == XLOADER_EMMC_BP2_RAW_VAL) {
				RawString = "_RAW_BP2";
			}
			else {
				RawString = "_RAW";
			}
		}
	}
	if ((PdiPtr->PdiIndex >= XLOADER_INVALID_INDEX) ||
		(DeviceOps[PdiPtr->PdiIndex].Init == NULL)) {
		goto END1;
	}
	XPlmi_Printf(DEBUG_GENERAL, "Loading PDI from %s%s\n\r",
		PdiSourceMap[DeviceFlags].Name, RawString);
	/*
	 * Update PDI Ptr with source and address
	 */
	PdiPtr->PdiSrc = PdiSrc;
	PdiPtr->PdiAddr = PdiAddr;
	PdiPtr->SlrType = (u8)(XPlmi_In32(PMC_TAP_SLR_TYPE) &
		PMC_TAP_SLR_TYPE_VAL_MASK);
	if ((PdiPtr->SlrType == XLOADER_SSIT_MASTER_SLR) ||
		(PdiPtr->SlrType == XLOADER_SSIT_MONOLITIC)) {
		XPlmi_Printf(DEBUG_GENERAL, "Monolithic/Master Device\n\r");

		Status = DeviceOps[PdiPtr->PdiIndex].Init(PdiPtr->PdiSrc);
		if (Status != XST_SUCCESS) {
			goto END;
		}
		if (PdiPtr->PdiSrc == XLOADER_PDI_SRC_USB) {
			PdiPtr->PdiType = XLOADER_PDI_TYPE_PARTIAL;
		}
	}

	PdiPtr->MetaHdr.DeviceCopy = DeviceOps[PdiPtr->PdiIndex].Copy;

	Status = XST_FAILURE;
	Status = XLoader_ReadAndValidateHdrs(PdiPtr, RegVal);
	if (Status != XST_SUCCESS) {
		goto END;
	}

	if (PdiPtr->PdiType == XLOADER_PDI_TYPE_FULL) {
		BootPdiPtr = PdiPtr;
	}
	goto END;

END1:
	XPlmi_Printf(DEBUG_GENERAL, "Unsupported Boot Mode: Source:0x%x\n\r",
		PdiPtr->PdiSrc);
	Status = XPlmi_UpdateStatus(XLOADER_UNSUPPORTED_BOOT_MODE, 0);
END:
	XPlmi_MeasurePerfTime(PdiInitTime, &PerfTime);
	XPlmi_Printf(DEBUG_PRINT_PERF,
		"%u.%03u ms: PDI initialization time\n\r",
		(u32)PerfTime.TPerfMs, (u32)PerfTime.TPerfMsFrac);
	return Status;
}
/*****************************************************************************/
/**
 * @brief	This function initializes the PDI instance with required details
 * and read the meta header.
 *
 * @param	PdiPtr is instance pointer pointing to PDI details
 * @param	PdiSrc is source of PDI. It can be any boot Device or DDR
 * @param	PdiAddr is the address at which PDI is located in the PDI source
 *
 * @return	XST_SUCCESS on success and error code on failure
 *
 *****************************************************************************/
@brief       This function initializes the PDI instance with required details
and read the meta header.

@param       PdiPtr is instance pointer pointing to PDI details
@param       PdiSrc is source of PDI. It can be any boot Device or DDR
@param       PdiAddr is the address at which PDI is located in the PDI source

@return      XST_SUCCESS on success and error code on failure
@brief This function initializes the PDI instance with required details and read the meta header . @param PdiPtr is instance pointer pointing to PDI details @param PdiSrc is source of PDI . It can be any boot Device or DDR @param PdiAddr is the address at which PDI is located in the PDI source @return XST_SUCCESS on success and error code on failure
int XLoader_PdiInit(XilPdi* PdiPtr, PdiSrc_t PdiSrc, u64 PdiAddr)
{
	volatile int Status = XST_FAILURE;
	u32 RegVal = XPlmi_In32(PMC_GLOBAL_PMC_MULTI_BOOT);
	u64 PdiInitTime = XPlmi_GetTimerValue();
	XPlmi_PerfTime PerfTime;
	u8 DeviceFlags = (u8)(PdiSrc & XLOADER_PDISRC_FLAGS_MASK);
	u32 SdRawBootVal = RegVal & XLOADER_SD_RAWBOOT_MASK;
	const char *RawString = "";
	const PdiSrcMap PdiSourceMap[] = {
		{"SBI", XLOADER_SBI_INDEX}, 
		{"QSPI24", XLOADER_QSPI_INDEX}, 
		{"QSPI32", XLOADER_QSPI_INDEX}, 
		{"SD0", XLOADER_SD_INDEX}, 
		{"EMMC0", XLOADER_SD_INDEX}, 
		{"SD1", XLOADER_SD_INDEX}, 
		{"EMMC1", XLOADER_SD_INDEX}, 
		{"USB", XLOADER_USB_INDEX}, 
		{"OSPI", XLOADER_OSPI_INDEX}, 
		{"SBI", XLOADER_SBI_INDEX}, 
		{"SMAP", XLOADER_SBI_INDEX}, 
		{"PCIE", XLOADER_SBI_INDEX}, 
		{"", XLOADER_INVALID_INDEX}, 
		{"", XLOADER_INVALID_INDEX}, 
		{"SD1_LS", XLOADER_SD_INDEX}, 
		{"DDR", XLOADER_DDR_INDEX}, 
	};
	XPlmi_Out32(PMC_GLOBAL_DONE, XLOADER_PDI_LOAD_STARTED);
	XPlmi_Out32(PMC_GLOBAL_GLOBAL_GEN_STORAGE4,
		(u32)((UINTPTR) &ATFHandoffParams));
	if (DeviceFlags >= XPLMI_ARRAY_SIZE(PdiSourceMap)) {
		goto END1;
	}
	PdiPtr->PdiIndex = PdiSourceMap[DeviceFlags].Index;
	if (PdiPtr->PdiIndex == XLOADER_SD_INDEX) {
		if (PdiPtr->PdiType != XLOADER_PDI_TYPE_FULL) {
			SdRawBootVal = PdiSrc & XLOADER_SD_RAWBOOT_MASK;
		}
		else {
			if ((SdRawBootVal == XLOADER_SD_RAWBOOT_MASK) ||
				(SdRawBootVal == 0U)) {
				PdiSrc |= (RegVal << XLOADER_PDISRC_FLAGS_SHIFT);
			}
			else {
				PdiSrc |= SdRawBootVal;
			}
		}
		if ((SdRawBootVal != 0U) &&
			(SdRawBootVal != XLOADER_SD_RAWBOOT_MASK)) {
			PdiPtr->PdiIndex = XLOADER_SD_RAW_INDEX;
			if (SdRawBootVal == XLOADER_EMMC_BP1_RAW_VAL) {
				RawString = "_RAW_BP1";
			}
			else if (SdRawBootVal == XLOADER_EMMC_BP2_RAW_VAL) {
				RawString = "_RAW_BP2";
			}
			else {
				RawString = "_RAW";
			}
		}
	}
	if ((PdiPtr->PdiIndex >= XLOADER_INVALID_INDEX) ||
		(DeviceOps[PdiPtr->PdiIndex].Init == NULL)) {
		goto END1;
	}
	XPlmi_Printf(DEBUG_GENERAL, "Loading PDI from %s%s\n\r",
		PdiSourceMap[DeviceFlags].Name, RawString);
	PdiPtr->PdiSrc = PdiSrc;
	PdiPtr->PdiAddr = PdiAddr;
	PdiPtr->SlrType = (u8)(XPlmi_In32(PMC_TAP_SLR_TYPE) &
		PMC_TAP_SLR_TYPE_VAL_MASK);
	if ((PdiPtr->SlrType == XLOADER_SSIT_MASTER_SLR) ||
		(PdiPtr->SlrType == XLOADER_SSIT_MONOLITIC)) {
		XPlmi_Printf(DEBUG_GENERAL, "Monolithic/Master Device\n\r");
		Status = DeviceOps[PdiPtr->PdiIndex].Init(PdiPtr->PdiSrc);
		if (Status != XST_SUCCESS) {
			goto END;
		}
		if (PdiPtr->PdiSrc == XLOADER_PDI_SRC_USB) {
			PdiPtr->PdiType = XLOADER_PDI_TYPE_PARTIAL;
		}
	}
	PdiPtr->MetaHdr.DeviceCopy = DeviceOps[PdiPtr->PdiIndex].Copy;
	Status = XST_FAILURE;
	Status = XLoader_ReadAndValidateHdrs(PdiPtr, RegVal);
	if (Status != XST_SUCCESS) {
		goto END;
	}
	if (PdiPtr->PdiType == XLOADER_PDI_TYPE_FULL) {
		BootPdiPtr = PdiPtr;
	}
	goto END;
END1:
	XPlmi_Printf(DEBUG_GENERAL, "Unsupported Boot Mode: Source:0x%x\n\r",
		PdiPtr->PdiSrc);
	Status = XPlmi_UpdateStatus(XLOADER_UNSUPPORTED_BOOT_MODE, 0);
END:
	XPlmi_MeasurePerfTime(PdiInitTime, &PerfTime);
	XPlmi_Printf(DEBUG_PRINT_PERF,
		"%u.%03u ms: PDI initialization time\n\r",
		(u32)PerfTime.TPerfMs, (u32)PerfTime.TPerfMsFrac);
	return Status;
}
int XLoader_PdiInit ( XilPdi * PdiPtr , PdiSrc_t PdiSrc , u64 PdiAddr ) { volatile int Status = XST_FAILURE ; u32 RegVal = XPlmi_In32 ( PMC_GLOBAL_PMC_MULTI_BOOT ) ; u64 PdiInitTime = XPlmi_GetTimerValue ( ) ; XPlmi_PerfTime PerfTime ; u8 DeviceFlags = ( u8 ) ( PdiSrc & XLOADER_PDISRC_FLAGS_MASK ) ; u32 SdRawBootVal = RegVal & XLOADER_SD_RAWBOOT_MASK ; const char * RawString = " " ; const PdiSrcMap PdiSourceMap [ ] = { { " " , XLOADER_SBI_INDEX } , { " " , XLOADER_QSPI_INDEX } , { " " , XLOADER_QSPI_INDEX } , { " " , XLOADER_SD_INDEX } , { " " , XLOADER_SD_INDEX } , { " " , XLOADER_SD_INDEX } , { " " , XLOADER_SD_INDEX } , { " " , XLOADER_USB_INDEX } , { " " , XLOADER_OSPI_INDEX } , { " " , XLOADER_SBI_INDEX } , { " " , XLOADER_SBI_INDEX } , { " " , XLOADER_SBI_INDEX } , { " " , XLOADER_INVALID_INDEX } , { " " , XLOADER_INVALID_INDEX } , { " " , XLOADER_SD_INDEX } , { " " , XLOADER_DDR_INDEX } , } ; XPlmi_Out32 ( PMC_GLOBAL_DONE , XLOADER_PDI_LOAD_STARTED ) ; XPlmi_Out32 ( PMC_GLOBAL_GLOBAL_GEN_STORAGE4 , ( u32 ) ( ( UINTPTR ) & ATFHandoffParams ) ) ; if ( DeviceFlags >= XPLMI_ARRAY_SIZE ( PdiSourceMap ) ) { goto END1 ; } PdiPtr -> PdiIndex = PdiSourceMap [ DeviceFlags ] . Index ; if ( PdiPtr -> PdiIndex == XLOADER_SD_INDEX ) { if ( PdiPtr -> PdiType != XLOADER_PDI_TYPE_FULL ) { SdRawBootVal = PdiSrc & XLOADER_SD_RAWBOOT_MASK ; } else { if ( ( SdRawBootVal == XLOADER_SD_RAWBOOT_MASK ) || ( SdRawBootVal == 0U ) ) { PdiSrc |= ( RegVal << XLOADER_PDISRC_FLAGS_SHIFT ) ; } else { PdiSrc |= SdRawBootVal ; } } if ( ( SdRawBootVal != 0U ) && ( SdRawBootVal != XLOADER_SD_RAWBOOT_MASK ) ) { PdiPtr -> PdiIndex = XLOADER_SD_RAW_INDEX ; if ( SdRawBootVal == XLOADER_EMMC_BP1_RAW_VAL ) { RawString = " " ; } else if ( SdRawBootVal == XLOADER_EMMC_BP2_RAW_VAL ) { RawString = " " ; } else { RawString = " " ; } } } if ( ( PdiPtr -> PdiIndex >= XLOADER_INVALID_INDEX ) || ( DeviceOps [ PdiPtr -> PdiIndex ] . Init == NULL ) ) { goto END1 ; } XPlmi_Printf ( DEBUG_GENERAL , " \n \r " , PdiSourceMap [ DeviceFlags ] . Name , RawString ) ; PdiPtr -> PdiSrc = PdiSrc ; PdiPtr -> PdiAddr = PdiAddr ; PdiPtr -> SlrType = ( u8 ) ( XPlmi_In32 ( PMC_TAP_SLR_TYPE ) & PMC_TAP_SLR_TYPE_VAL_MASK ) ; if ( ( PdiPtr -> SlrType == XLOADER_SSIT_MASTER_SLR ) || ( PdiPtr -> SlrType == XLOADER_SSIT_MONOLITIC ) ) { XPlmi_Printf ( DEBUG_GENERAL , " \n \r " ) ; Status = DeviceOps [ PdiPtr -> PdiIndex ] . Init ( PdiPtr -> PdiSrc ) ; if ( Status != XST_SUCCESS ) { goto END ; } if ( PdiPtr -> PdiSrc == XLOADER_PDI_SRC_USB ) { PdiPtr -> PdiType = XLOADER_PDI_TYPE_PARTIAL ; } } PdiPtr -> MetaHdr . DeviceCopy = DeviceOps [ PdiPtr -> PdiIndex ] . Copy ; Status = XST_FAILURE ; Status = XLoader_ReadAndValidateHdrs ( PdiPtr , RegVal ) ; if ( Status != XST_SUCCESS ) { goto END ; } if ( PdiPtr -> PdiType == XLOADER_PDI_TYPE_FULL ) { BootPdiPtr = PdiPtr ; } goto END ; END1 : XPlmi_Printf ( DEBUG_GENERAL , " \n \r " , PdiPtr -> PdiSrc ) ; Status = XPlmi_UpdateStatus ( XLOADER_UNSUPPORTED_BOOT_MODE , 0 ) ; END : XPlmi_MeasurePerfTime ( PdiInitTime , & PerfTime ) ; XPlmi_Printf ( DEBUG_PRINT_PERF , " \n \r " , ( u32 ) PerfTime . TPerfMs , ( u32 ) PerfTime . TPerfMsFrac ) ; return Status ; }
@brief       This function initializes the PDI instance with required details
 and read the meta header.
@brief This function initializes the PDI instance with required details and read the meta header .
/* SBI JTAG - 0 */ /* QSPI24 - 1 */ /* QSPI32 - 2 */ /* SD0 - 3 */ /* EMMC0 - 4 */ /* SD1 - 5 */ /* EMMC - 6 */ /* USB - 7 */ /* OSPI - 8 */ /* SBI - 9*/ /* SMAP - 0xA */ /* PCIE - 0xB */ /* Unused - 0xC */ /* Unused - 0xD */ /* SD1_LS - 0xE */ /* DDR - 0xF */ /*
	 * Mark PDI loading is started.
	 */ /*
	 * Store address of the structure in PMC_GLOBAL.GLOBAL_GEN_STORAGE4.
	 */ /* 0 is for QEMU */ /*
	 * Update PDI Ptr with source and address
	 */