lib/sw_services/xilloader/src/xloader_sd.c
int XLoader_SdCopy(u64 SrcAddr, u64 DestAddr, u32 Length, u32 Flags)
{
	int Status = XST_FAILURE;
	FRESULT Rc; /* Result code */
	UINT Br = 0U;
	u32 TrfLen;
	u64 DestOffset = 0U;
	(void)Flags;

	Rc = f_lseek(&FFil, (FSIZE_t)SrcAddr);
	if (Rc != FR_OK) {
		XLoader_Printf(DEBUG_INFO, "SD: Unable to seek to 0x%0x%08x\n",
				(SrcAddr >> 32U), (u32)SrcAddr);
		Status = XPlmi_UpdateStatus(XLOADER_ERR_SD_F_LSEEK, (int)Rc);
		XLoader_Printf(DEBUG_GENERAL,"XLOADER_ERR_SD_F_LSEEK\n\r");
		goto END;
	}

	if ((DestAddr >> 32U) == 0U) {
		Rc = f_read(&FFil, (void*)(UINTPTR)DestAddr, Length, &Br);
		if (Rc != FR_OK) {
			XLoader_Printf(DEBUG_GENERAL, "SD: f_read returned %d\r\n", Rc);
			Status = XPlmi_UpdateStatus(XLOADER_ERR_SD_F_READ, (int)Rc);
			XLoader_Printf(DEBUG_GENERAL, "XLOADER_ERR_SD_F_READ\n\r");
			goto END;
		}
	}
	else {
		while(Length > 0U) {
			if(Length > XLOADER_CHUNK_SIZE) {
				TrfLen = XLOADER_CHUNK_SIZE;
			}
			else {
				TrfLen = Length;
			}

			Rc = f_read(&FFil, (void*)(UINTPTR)XPLMI_PMCRAM_BASEADDR, TrfLen, &Br);
			if (Rc != FR_OK) {
				XLoader_Printf(DEBUG_GENERAL, "SD: f_read returned %d\r\n", Rc);
				Status = XPlmi_UpdateStatus(XLOADER_ERR_SD_F_READ, (int)Rc);
				XLoader_Printf(DEBUG_GENERAL, "XLOADER_ERR_SD_F_READ\n\r");
				goto END;
			}
			Status = XPlmi_DmaXfr((u64)XPLMI_PMCRAM_BASEADDR,
					(DestAddr + DestOffset), (TrfLen / XPLMI_WORD_LEN),
					XPLMI_PMCDMA_0);
            if (Status != XST_SUCCESS) {
		Status = XPlmi_UpdateStatus(XLOADER_ERR_DMA_XFER, Status);
                 XLoader_Printf(DEBUG_GENERAL, "XLOADER_ERR_SD_F_READ\n\r");
                 goto END;
            }

			Length -= TrfLen;
			DestOffset += TrfLen;
		}
	}
	Status = XST_SUCCESS;

END:
	return Status;
}
/*****************************************************************************/
/**
 * @brief	This function is used to copy the data from SD/eMMC to
 * destination address.
 *
 * @param	SrcAddr is the address of the SD flash where copy should
 * 		start from
 * @param 	DestAddr is the address of the destination where it
 * 		should copy to
 * @param	Length of the bytes to be copied
 * @param	Flags are unused and only passed to maintain compatibility without
 *		the copy functions of other boot modes
 *
 * @return	XST_SUCCESS on success and error code on failure
 *
 *****************************************************************************/
@brief       This function is used to copy the data from SD/eMMC to
destination address.

@param       SrcAddr is the address of the SD flash where copy should
start from
@param       DestAddr is the address of the destination where it
should copy to
@param       Length of the bytes to be copied
@param       Flags are unused and only passed to maintain compatibility without
the copy functions of other boot modes

@return      XST_SUCCESS on success and error code on failure
@brief This function is used to copy the data from SD / eMMC to destination address . @param SrcAddr is the address of the SD flash where copy should start from @param DestAddr is the address of the destination where it should copy to @param Length of the bytes to be copied @param Flags are unused and only passed to maintain compatibility without the copy functions of other boot modes @return XST_SUCCESS on success and error code on failure
int XLoader_SdCopy(u64 SrcAddr, u64 DestAddr, u32 Length, u32 Flags)
{
	int Status = XST_FAILURE;
	FRESULT Rc; 
	UINT Br = 0U;
	u32 TrfLen;
	u64 DestOffset = 0U;
	(void)Flags;
	Rc = f_lseek(&FFil, (FSIZE_t)SrcAddr);
	if (Rc != FR_OK) {
		XLoader_Printf(DEBUG_INFO, "SD: Unable to seek to 0x%0x%08x\n",
				(SrcAddr >> 32U), (u32)SrcAddr);
		Status = XPlmi_UpdateStatus(XLOADER_ERR_SD_F_LSEEK, (int)Rc);
		XLoader_Printf(DEBUG_GENERAL,"XLOADER_ERR_SD_F_LSEEK\n\r");
		goto END;
	}
	if ((DestAddr >> 32U) == 0U) {
		Rc = f_read(&FFil, (void*)(UINTPTR)DestAddr, Length, &Br);
		if (Rc != FR_OK) {
			XLoader_Printf(DEBUG_GENERAL, "SD: f_read returned %d\r\n", Rc);
			Status = XPlmi_UpdateStatus(XLOADER_ERR_SD_F_READ, (int)Rc);
			XLoader_Printf(DEBUG_GENERAL, "XLOADER_ERR_SD_F_READ\n\r");
			goto END;
		}
	}
	else {
		while(Length > 0U) {
			if(Length > XLOADER_CHUNK_SIZE) {
				TrfLen = XLOADER_CHUNK_SIZE;
			}
			else {
				TrfLen = Length;
			}
			Rc = f_read(&FFil, (void*)(UINTPTR)XPLMI_PMCRAM_BASEADDR, TrfLen, &Br);
			if (Rc != FR_OK) {
				XLoader_Printf(DEBUG_GENERAL, "SD: f_read returned %d\r\n", Rc);
				Status = XPlmi_UpdateStatus(XLOADER_ERR_SD_F_READ, (int)Rc);
				XLoader_Printf(DEBUG_GENERAL, "XLOADER_ERR_SD_F_READ\n\r");
				goto END;
			}
			Status = XPlmi_DmaXfr((u64)XPLMI_PMCRAM_BASEADDR,
					(DestAddr + DestOffset), (TrfLen / XPLMI_WORD_LEN),
					XPLMI_PMCDMA_0);
            if (Status != XST_SUCCESS) {
		Status = XPlmi_UpdateStatus(XLOADER_ERR_DMA_XFER, Status);
                 XLoader_Printf(DEBUG_GENERAL, "XLOADER_ERR_SD_F_READ\n\r");
                 goto END;
            }
			Length -= TrfLen;
			DestOffset += TrfLen;
		}
	}
	Status = XST_SUCCESS;
END:
	return Status;
}
int XLoader_SdCopy ( u64 SrcAddr , u64 DestAddr , u32 Length , u32 Flags ) { int Status = XST_FAILURE ; FRESULT Rc ; UINT Br = 0U ; u32 TrfLen ; u64 DestOffset = 0U ; ( void ) Flags ; Rc = f_lseek ( & FFil , ( FSIZE_t ) SrcAddr ) ; if ( Rc != FR_OK ) { XLoader_Printf ( DEBUG_INFO , " \n " , ( SrcAddr >> 32U ) , ( u32 ) SrcAddr ) ; Status = XPlmi_UpdateStatus ( XLOADER_ERR_SD_F_LSEEK , ( int ) Rc ) ; XLoader_Printf ( DEBUG_GENERAL , " \n \r " ) ; goto END ; } if ( ( DestAddr >> 32U ) == 0U ) { Rc = f_read ( & FFil , ( void * ) ( UINTPTR ) DestAddr , Length , & Br ) ; if ( Rc != FR_OK ) { XLoader_Printf ( DEBUG_GENERAL , " \r \n " , Rc ) ; Status = XPlmi_UpdateStatus ( XLOADER_ERR_SD_F_READ , ( int ) Rc ) ; XLoader_Printf ( DEBUG_GENERAL , " \n \r " ) ; goto END ; } } else { while ( Length > 0U ) { if ( Length > XLOADER_CHUNK_SIZE ) { TrfLen = XLOADER_CHUNK_SIZE ; } else { TrfLen = Length ; } Rc = f_read ( & FFil , ( void * ) ( UINTPTR ) XPLMI_PMCRAM_BASEADDR , TrfLen , & Br ) ; if ( Rc != FR_OK ) { XLoader_Printf ( DEBUG_GENERAL , " \r \n " , Rc ) ; Status = XPlmi_UpdateStatus ( XLOADER_ERR_SD_F_READ , ( int ) Rc ) ; XLoader_Printf ( DEBUG_GENERAL , " \n \r " ) ; goto END ; } Status = XPlmi_DmaXfr ( ( u64 ) XPLMI_PMCRAM_BASEADDR , ( DestAddr + DestOffset ) , ( TrfLen / XPLMI_WORD_LEN ) , XPLMI_PMCDMA_0 ) ; if ( Status != XST_SUCCESS ) { Status = XPlmi_UpdateStatus ( XLOADER_ERR_DMA_XFER , Status ) ; XLoader_Printf ( DEBUG_GENERAL , " \n \r " ) ; goto END ; } Length -= TrfLen ; DestOffset += TrfLen ; } } Status = XST_SUCCESS ; END : return Status ; }
@brief       This function is used to copy the data from SD/eMMC to
 destination address.
@brief This function is used to copy the data from SD / eMMC to destination address .
/* Result code */