lib/sw_services/xilloader/src/xloader.c
static int XLoader_LoadAndStartSecPdi(XilPdi* PdiPtr)
{
	int Status = XST_FAILURE;
	u32 PdiSrc;
	u32 PdiAddr = PdiPtr->MetaHdr.ImgHdrTbl.SBDAddr;
	u32 SecBootMode = XilPdi_GetSBD(&(PdiPtr->MetaHdr.ImgHdrTbl)) >>
		XIH_IHT_ATTR_SBD_SHIFT;

	if ((SecBootMode == XIH_IHT_ATTR_SBD_SAME) ||
		((PdiPtr->SlrType != XLOADER_SSIT_MASTER_SLR) &&
		(PdiPtr->SlrType != XLOADER_SSIT_MONOLITIC))) {
		/* Do nothing */
		Status = XST_SUCCESS;
	} else {
		XPlmi_Printf(DEBUG_INFO, "+++Configuring Secondary Boot "
				"Device\n\r");
		if (SecBootMode == XIH_IHT_ATTR_SBD_PCIE) {
			Status = XLoader_SbiInit((u32)XLOADER_PDI_SRC_PCIE);
		} else {
			switch(SecBootMode)
			{
				case XIH_IHT_ATTR_SBD_QSPI32:
					PdiSrc = XLOADER_PDI_SRC_QSPI32;
					break;
				case XIH_IHT_ATTR_SBD_QSPI24:
					PdiSrc = XLOADER_PDI_SRC_QSPI24;
					break;
				case XIH_IHT_ATTR_SBD_SD_0:
				#ifdef XLOADER_SD_0
					PdiSrc = XLOADER_PDI_SRC_SD0 |
						XLOADER_SD_RAWBOOT_MASK |
						(PdiPtr->MetaHdr.ImgHdrTbl.SBDAddr
						<< XLOADER_SD_ADDR_SHIFT);
				#else
					PdiSrc = XLOADER_PDI_SRC_SD0;
				#endif
					PdiAddr = 0U;
					break;
				case XIH_IHT_ATTR_SBD_SD_1:
				#ifdef XLOADER_SD_1
					PdiSrc = XLOADER_PDI_SRC_SD1 |
						XLOADER_SD_RAWBOOT_MASK |
						(PdiPtr->MetaHdr.ImgHdrTbl.SBDAddr
						<< XLOADER_SD_ADDR_SHIFT);
				#else
					PdiSrc = XLOADER_PDI_SRC_SD1;
				#endif
					PdiAddr = 0U;
					break;
				case XIH_IHT_ATTR_SBD_SD_LS:
				#ifdef XLOADER_SD_1
					PdiSrc = XLOADER_PDI_SRC_SD1_LS |
						XLOADER_SD_RAWBOOT_MASK |
						(PdiPtr->MetaHdr.ImgHdrTbl.SBDAddr
						<< XLOADER_SD_ADDR_SHIFT);
				#else
					PdiSrc = XLOADER_PDI_SRC_SD1_LS;
				#endif
					PdiAddr = 0U;
					break;
				case XIH_IHT_ATTR_SBD_EMMC:
				#ifdef XLOADER_SD_1
					PdiSrc = XLOADER_PDI_SRC_EMMC1 |
						XLOADER_SD_RAWBOOT_MASK |
						(PdiPtr->MetaHdr.ImgHdrTbl.SBDAddr
						<< XLOADER_SD_ADDR_SHIFT);
				#else
					PdiSrc = XLOADER_PDI_SRC_EMMC1;
				#endif
					PdiAddr = 0U;
					break;
				case XIH_IHT_ATTR_SBD_OSPI:
					PdiSrc = XLOADER_PDI_SRC_OSPI;
					break;
				case XIH_IHT_ATTR_SBD_USB:
					PdiSrc = XLOADER_PDI_SRC_USB;
					PdiAddr = 0U;
					break;
				case XIH_IHT_ATTR_SBD_SMAP:
					PdiSrc = XLOADER_PDI_SRC_SMAP;
					break;
				case XIH_IHT_ATTR_SBD_SD_0_RAW:
					PdiSrc = XLOADER_SD_RAWBOOT_VAL | XLOADER_PDI_SRC_SD0;
					break;
				case XIH_IHT_ATTR_SBD_SD_1_RAW:
					PdiSrc = XLOADER_SD_RAWBOOT_VAL | XLOADER_PDI_SRC_SD1;
					break;
				case XIH_IHT_ATTR_SBD_EMMC_RAW:
					PdiSrc = XLOADER_SD_RAWBOOT_VAL | XLOADER_PDI_SRC_EMMC1;
					break;
				case XIH_IHT_ATTR_SBD_SD_LS_RAW:
					PdiSrc = XLOADER_SD_RAWBOOT_VAL | XLOADER_PDI_SRC_SD1_LS;
					break;
				case XIH_IHT_ATTR_SBD_EMMC_0:
				#ifdef XLOADER_SD_0
					PdiSrc = XLOADER_PDI_SRC_EMMC0 |
						XLOADER_SD_RAWBOOT_MASK |
						(PdiPtr->MetaHdr.ImgHdrTbl.SBDAddr
						 << XLOADER_SD_ADDR_SHIFT);
				#else
					PdiSrc = XLOADER_PDI_SRC_EMMC0;
				#endif
					PdiAddr = 0U;
					break;
				case XIH_IHT_ATTR_SBD_EMMC_0_RAW:
					PdiSrc = XLOADER_SD_RAWBOOT_VAL | XLOADER_PDI_SRC_EMMC0;
					break;
				default:
					Status = (int)XLOADER_ERR_UNSUPPORTED_SEC_BOOT_MODE;
					break;
			}

			if (Status == (int)XLOADER_ERR_UNSUPPORTED_SEC_BOOT_MODE) {
				Status = XPlmi_UpdateStatus(Status, 0);
				goto END;
			}

			Status = XPlmi_MemSetBytes(PdiPtr, sizeof(XilPdi), 0U, sizeof(XilPdi));
			if (Status != XST_SUCCESS) {
				Status = XPlmi_UpdateStatus(XLOADER_ERR_MEMSET, (int)XLOADER_ERR_MEMSET_PDIPTR);
				goto END;
			}
			PdiPtr->PdiType = XLOADER_PDI_TYPE_PARTIAL;
			Status = XLoader_PdiInit(PdiPtr, PdiSrc, PdiAddr);
			if (Status != XST_SUCCESS) {
				goto END;
			}

			Status = XLoader_LoadAndStartSubSystemImages(PdiPtr);
		}
	}

END:
	return Status;
}
/*****************************************************************************/
/**
 * @brief	This function is used to load the primary and secondary PDIs.
 *
 * @param	PdiPtr is Pdi instance pointer
 *
 * @return	XST_SUCCESS on success and error code on failure
 *
 *****************************************************************************/
@brief       This function is used to load the primary and secondary PDIs.
@param       PdiPtr is Pdi instance pointer

@return      XST_SUCCESS on success and error code on failure
@brief This function is used to load the primary and secondary PDIs . @param PdiPtr is Pdi instance pointer @return XST_SUCCESS on success and error code on failure
static int XLoader_LoadAndStartSecPdi(XilPdi* PdiPtr)
{
	int Status = XST_FAILURE;
	u32 PdiSrc;
	u32 PdiAddr = PdiPtr->MetaHdr.ImgHdrTbl.SBDAddr;
	u32 SecBootMode = XilPdi_GetSBD(&(PdiPtr->MetaHdr.ImgHdrTbl)) >>
		XIH_IHT_ATTR_SBD_SHIFT;
	if ((SecBootMode == XIH_IHT_ATTR_SBD_SAME) ||
		((PdiPtr->SlrType != XLOADER_SSIT_MASTER_SLR) &&
		(PdiPtr->SlrType != XLOADER_SSIT_MONOLITIC))) {
		Status = XST_SUCCESS;
	} else {
		XPlmi_Printf(DEBUG_INFO, "+++Configuring Secondary Boot "
				"Device\n\r");
		if (SecBootMode == XIH_IHT_ATTR_SBD_PCIE) {
			Status = XLoader_SbiInit((u32)XLOADER_PDI_SRC_PCIE);
		} else {
			switch(SecBootMode)
			{
				case XIH_IHT_ATTR_SBD_QSPI32:
					PdiSrc = XLOADER_PDI_SRC_QSPI32;
					break;
				case XIH_IHT_ATTR_SBD_QSPI24:
					PdiSrc = XLOADER_PDI_SRC_QSPI24;
					break;
				case XIH_IHT_ATTR_SBD_SD_0:
				#ifdef XLOADER_SD_0
					PdiSrc = XLOADER_PDI_SRC_SD0 |
						XLOADER_SD_RAWBOOT_MASK |
						(PdiPtr->MetaHdr.ImgHdrTbl.SBDAddr
						<< XLOADER_SD_ADDR_SHIFT);
				#else
					PdiSrc = XLOADER_PDI_SRC_SD0;
				#endif
					PdiAddr = 0U;
					break;
				case XIH_IHT_ATTR_SBD_SD_1:
				#ifdef XLOADER_SD_1
					PdiSrc = XLOADER_PDI_SRC_SD1 |
						XLOADER_SD_RAWBOOT_MASK |
						(PdiPtr->MetaHdr.ImgHdrTbl.SBDAddr
						<< XLOADER_SD_ADDR_SHIFT);
				#else
					PdiSrc = XLOADER_PDI_SRC_SD1;
				#endif
					PdiAddr = 0U;
					break;
				case XIH_IHT_ATTR_SBD_SD_LS:
				#ifdef XLOADER_SD_1
					PdiSrc = XLOADER_PDI_SRC_SD1_LS |
						XLOADER_SD_RAWBOOT_MASK |
						(PdiPtr->MetaHdr.ImgHdrTbl.SBDAddr
						<< XLOADER_SD_ADDR_SHIFT);
				#else
					PdiSrc = XLOADER_PDI_SRC_SD1_LS;
				#endif
					PdiAddr = 0U;
					break;
				case XIH_IHT_ATTR_SBD_EMMC:
				#ifdef XLOADER_SD_1
					PdiSrc = XLOADER_PDI_SRC_EMMC1 |
						XLOADER_SD_RAWBOOT_MASK |
						(PdiPtr->MetaHdr.ImgHdrTbl.SBDAddr
						<< XLOADER_SD_ADDR_SHIFT);
				#else
					PdiSrc = XLOADER_PDI_SRC_EMMC1;
				#endif
					PdiAddr = 0U;
					break;
				case XIH_IHT_ATTR_SBD_OSPI:
					PdiSrc = XLOADER_PDI_SRC_OSPI;
					break;
				case XIH_IHT_ATTR_SBD_USB:
					PdiSrc = XLOADER_PDI_SRC_USB;
					PdiAddr = 0U;
					break;
				case XIH_IHT_ATTR_SBD_SMAP:
					PdiSrc = XLOADER_PDI_SRC_SMAP;
					break;
				case XIH_IHT_ATTR_SBD_SD_0_RAW:
					PdiSrc = XLOADER_SD_RAWBOOT_VAL | XLOADER_PDI_SRC_SD0;
					break;
				case XIH_IHT_ATTR_SBD_SD_1_RAW:
					PdiSrc = XLOADER_SD_RAWBOOT_VAL | XLOADER_PDI_SRC_SD1;
					break;
				case XIH_IHT_ATTR_SBD_EMMC_RAW:
					PdiSrc = XLOADER_SD_RAWBOOT_VAL | XLOADER_PDI_SRC_EMMC1;
					break;
				case XIH_IHT_ATTR_SBD_SD_LS_RAW:
					PdiSrc = XLOADER_SD_RAWBOOT_VAL | XLOADER_PDI_SRC_SD1_LS;
					break;
				case XIH_IHT_ATTR_SBD_EMMC_0:
				#ifdef XLOADER_SD_0
					PdiSrc = XLOADER_PDI_SRC_EMMC0 |
						XLOADER_SD_RAWBOOT_MASK |
						(PdiPtr->MetaHdr.ImgHdrTbl.SBDAddr
						 << XLOADER_SD_ADDR_SHIFT);
				#else
					PdiSrc = XLOADER_PDI_SRC_EMMC0;
				#endif
					PdiAddr = 0U;
					break;
				case XIH_IHT_ATTR_SBD_EMMC_0_RAW:
					PdiSrc = XLOADER_SD_RAWBOOT_VAL | XLOADER_PDI_SRC_EMMC0;
					break;
				default:
					Status = (int)XLOADER_ERR_UNSUPPORTED_SEC_BOOT_MODE;
					break;
			}
			if (Status == (int)XLOADER_ERR_UNSUPPORTED_SEC_BOOT_MODE) {
				Status = XPlmi_UpdateStatus(Status, 0);
				goto END;
			}
			Status = XPlmi_MemSetBytes(PdiPtr, sizeof(XilPdi), 0U, sizeof(XilPdi));
			if (Status != XST_SUCCESS) {
				Status = XPlmi_UpdateStatus(XLOADER_ERR_MEMSET, (int)XLOADER_ERR_MEMSET_PDIPTR);
				goto END;
			}
			PdiPtr->PdiType = XLOADER_PDI_TYPE_PARTIAL;
			Status = XLoader_PdiInit(PdiPtr, PdiSrc, PdiAddr);
			if (Status != XST_SUCCESS) {
				goto END;
			}
			Status = XLoader_LoadAndStartSubSystemImages(PdiPtr);
		}
	}
END:
	return Status;
}
static int XLoader_LoadAndStartSecPdi ( XilPdi * PdiPtr ) { int Status = XST_FAILURE ; u32 PdiSrc ; u32 PdiAddr = PdiPtr -> MetaHdr . ImgHdrTbl . SBDAddr ; u32 SecBootMode = XilPdi_GetSBD ( & ( PdiPtr -> MetaHdr . ImgHdrTbl ) ) >> XIH_IHT_ATTR_SBD_SHIFT ; if ( ( SecBootMode == XIH_IHT_ATTR_SBD_SAME ) || ( ( PdiPtr -> SlrType != XLOADER_SSIT_MASTER_SLR ) && ( PdiPtr -> SlrType != XLOADER_SSIT_MONOLITIC ) ) ) { Status = XST_SUCCESS ; } else { XPlmi_Printf ( DEBUG_INFO , " " " \n \r " ) ; if ( SecBootMode == XIH_IHT_ATTR_SBD_PCIE ) { Status = XLoader_SbiInit ( ( u32 ) XLOADER_PDI_SRC_PCIE ) ; } else { switch ( SecBootMode ) { case XIH_IHT_ATTR_SBD_QSPI32 : PdiSrc = XLOADER_PDI_SRC_QSPI32 ; break ; case XIH_IHT_ATTR_SBD_QSPI24 : PdiSrc = XLOADER_PDI_SRC_QSPI24 ; break ; case XIH_IHT_ATTR_SBD_SD_0 : #ifdef XLOADER_SD_0 PdiSrc = XLOADER_PDI_SRC_SD0 | XLOADER_SD_RAWBOOT_MASK | ( PdiPtr -> MetaHdr . ImgHdrTbl . SBDAddr << XLOADER_SD_ADDR_SHIFT ) ; #else PdiSrc = XLOADER_PDI_SRC_SD0 ; #endif PdiAddr = 0U ; break ; case XIH_IHT_ATTR_SBD_SD_1 : #ifdef XLOADER_SD_1 PdiSrc = XLOADER_PDI_SRC_SD1 | XLOADER_SD_RAWBOOT_MASK | ( PdiPtr -> MetaHdr . ImgHdrTbl . SBDAddr << XLOADER_SD_ADDR_SHIFT ) ; #else PdiSrc = XLOADER_PDI_SRC_SD1 ; #endif PdiAddr = 0U ; break ; case XIH_IHT_ATTR_SBD_SD_LS : #ifdef XLOADER_SD_1 PdiSrc = XLOADER_PDI_SRC_SD1_LS | XLOADER_SD_RAWBOOT_MASK | ( PdiPtr -> MetaHdr . ImgHdrTbl . SBDAddr << XLOADER_SD_ADDR_SHIFT ) ; #else PdiSrc = XLOADER_PDI_SRC_SD1_LS ; #endif PdiAddr = 0U ; break ; case XIH_IHT_ATTR_SBD_EMMC : #ifdef XLOADER_SD_1 PdiSrc = XLOADER_PDI_SRC_EMMC1 | XLOADER_SD_RAWBOOT_MASK | ( PdiPtr -> MetaHdr . ImgHdrTbl . SBDAddr << XLOADER_SD_ADDR_SHIFT ) ; #else PdiSrc = XLOADER_PDI_SRC_EMMC1 ; #endif PdiAddr = 0U ; break ; case XIH_IHT_ATTR_SBD_OSPI : PdiSrc = XLOADER_PDI_SRC_OSPI ; break ; case XIH_IHT_ATTR_SBD_USB : PdiSrc = XLOADER_PDI_SRC_USB ; PdiAddr = 0U ; break ; case XIH_IHT_ATTR_SBD_SMAP : PdiSrc = XLOADER_PDI_SRC_SMAP ; break ; case XIH_IHT_ATTR_SBD_SD_0_RAW : PdiSrc = XLOADER_SD_RAWBOOT_VAL | XLOADER_PDI_SRC_SD0 ; break ; case XIH_IHT_ATTR_SBD_SD_1_RAW : PdiSrc = XLOADER_SD_RAWBOOT_VAL | XLOADER_PDI_SRC_SD1 ; break ; case XIH_IHT_ATTR_SBD_EMMC_RAW : PdiSrc = XLOADER_SD_RAWBOOT_VAL | XLOADER_PDI_SRC_EMMC1 ; break ; case XIH_IHT_ATTR_SBD_SD_LS_RAW : PdiSrc = XLOADER_SD_RAWBOOT_VAL | XLOADER_PDI_SRC_SD1_LS ; break ; case XIH_IHT_ATTR_SBD_EMMC_0 : #ifdef XLOADER_SD_0 PdiSrc = XLOADER_PDI_SRC_EMMC0 | XLOADER_SD_RAWBOOT_MASK | ( PdiPtr -> MetaHdr . ImgHdrTbl . SBDAddr << XLOADER_SD_ADDR_SHIFT ) ; #else PdiSrc = XLOADER_PDI_SRC_EMMC0 ; #endif PdiAddr = 0U ; break ; case XIH_IHT_ATTR_SBD_EMMC_0_RAW : PdiSrc = XLOADER_SD_RAWBOOT_VAL | XLOADER_PDI_SRC_EMMC0 ; break ; default : Status = ( int ) XLOADER_ERR_UNSUPPORTED_SEC_BOOT_MODE ; break ; } if ( Status == ( int ) XLOADER_ERR_UNSUPPORTED_SEC_BOOT_MODE ) { Status = XPlmi_UpdateStatus ( Status , 0 ) ; goto END ; } Status = XPlmi_MemSetBytes ( PdiPtr , sizeof ( XilPdi ) , 0U , sizeof ( XilPdi ) ) ; if ( Status != XST_SUCCESS ) { Status = XPlmi_UpdateStatus ( XLOADER_ERR_MEMSET , ( int ) XLOADER_ERR_MEMSET_PDIPTR ) ; goto END ; } PdiPtr -> PdiType = XLOADER_PDI_TYPE_PARTIAL ; Status = XLoader_PdiInit ( PdiPtr , PdiSrc , PdiAddr ) ; if ( Status != XST_SUCCESS ) { goto END ; } Status = XLoader_LoadAndStartSubSystemImages ( PdiPtr ) ; } } END : return Status ; }
@brief       This function is used to load the primary and secondary PDIs.
@brief This function is used to load the primary and secondary PDIs .
/* Do nothing */