lib/sw_services/xilflash/src/xilflash_amd.c
int XFlashAmd_Read(XFlash *InstancePtr, u32 Offset, u32 Bytes, void *DestPtr)
{
	u8 *Dest8BitPtr;
	u8 *Src8BitPtr;
	u16 *Dest16BitPtr;
	u16 *Src16BitPtr;
	u32  PartMode;
	u32 Index;
	u32 Startoffset;
	u32 EndOffset;
	XFlashGeometry *GeomPtr;
	XFlashVendorData_Amd *DevDataPtr;
	volatile u16 FlashStatus;

	/* Verify inputs are valid. */
	if(InstancePtr == NULL) {
		return (XST_FAILURE);
	}

	if(DestPtr == NULL) {
		return (XST_FAILURE);
	}

	if(Bytes == 0) {
		return (XST_FAILURE);
	}

	GeomPtr = &InstancePtr->Geometry;
	DevDataPtr = GET_PARTDATA(InstancePtr);

	if (InstancePtr->Geometry.MemoryLayout == XFL_LAYOUT_X16_X16_X1) {
		Startoffset = Offset >> 1;
		EndOffset = Offset + Bytes - 1;
		EndOffset = EndOffset >> 1;
	}
	else {
		Startoffset = Offset;
	}
	PartMode = (InstancePtr->Geometry.MemoryLayout &
			XFL_LAYOUT_PART_MODE_MASK);

	/*
	 * Check to make sure start address is within the device.
	 */
	if (!XFL_GEOMETRY_IS_ABSOLUTE_VALID(&InstancePtr->Geometry,
		Startoffset)) {
		return (XFLASH_ADDRESS_ERROR);
	}

	/*
	 * Reset the bank(s) so that it returns to the read mode.
	 */
	if (XFlashAmd_ResetBank(InstancePtr, Startoffset, Bytes)
		!= XST_SUCCESS) {
		return (XST_FAILURE);
	}

	/*
	 * Perform copy to the user buffer from the flash buffer.
	 */
	if (PartMode == XFL_LAYOUT_PART_MODE_8) {
		/*
		 * Perform copy to the user buffer from the buffer.
		 */
		Src8BitPtr = (u8*) (((volatile u8*)InstancePtr->Geometry.
				     BaseAddress) + Offset);
		Dest8BitPtr = (u8*) DestPtr;

		for (Index = 0; Index < Bytes; Index++) {
			Dest8BitPtr[Index] = Src8BitPtr[Index];
		}

	}
	else if (PartMode == XFL_LAYOUT_PART_MODE_16) {

		/* Wait until device is ready. */
		AmdDevice_is_Ready(InstancePtr);

		/* Send Status Register Clear Command. */
		DevDataPtr->SendCmd(GeomPtr->BaseAddress,XFL_AMD_CMD1_ADDR,
						XFL_AMD_CMD_STATUS_REG_CLEAR);
		/* Perform copy to the user buffer from the buffer. */
		Src16BitPtr = (u16*) (((volatile u16*) InstancePtr->Geometry.
				       BaseAddress) + Startoffset);
		Dest16BitPtr = (u16*) DestPtr;
		for (Index = 0; Index < (Bytes/2); Index++) {
			Dest16BitPtr[Index] = Src16BitPtr[Index];
		}
	} else {
		return (XFLASH_PART_NOT_SUPPORTED);
	}

	return (XST_SUCCESS);
}
/*****************************************************************************/
/**
*
* The routine reads the data from the AMD flash device and copies it into
* user buffer.
*
* @param	InstancePtr is the pointer to the XFlash instance.
* @param	Offset is the offset into the device(s) address space from
*		which to read.
* @param	Bytes is the number of bytes to copy.
* @param	DestPtr is the destination address to copy data to.
*
* @return
*		- XST_SUCCESS if successful.
*		- XFLASH_ADDRESS_ERROR if the source address does not start
*		  within the addressable areas of the device(s).
*		- XFLASH_PART_NOT_SUPPORTED if the command set algorithm or
*		  Layout is not supported by any specific flash device family
*		  compiled into the system.
*		- XST_FAILURE if failed.
*
* @note		None.
*
******************************************************************************/
The routine reads the data from the AMD flash device and copies it into
user buffer.
The routine reads the data from the AMD flash device and copies it into user buffer .
int XFlashAmd_Read(XFlash *InstancePtr, u32 Offset, u32 Bytes, void *DestPtr)
{
	u8 *Dest8BitPtr;
	u8 *Src8BitPtr;
	u16 *Dest16BitPtr;
	u16 *Src16BitPtr;
	u32  PartMode;
	u32 Index;
	u32 Startoffset;
	u32 EndOffset;
	XFlashGeometry *GeomPtr;
	XFlashVendorData_Amd *DevDataPtr;
	volatile u16 FlashStatus;
	if(InstancePtr == NULL) {
		return (XST_FAILURE);
	}
	if(DestPtr == NULL) {
		return (XST_FAILURE);
	}
	if(Bytes == 0) {
		return (XST_FAILURE);
	}
	GeomPtr = &InstancePtr->Geometry;
	DevDataPtr = GET_PARTDATA(InstancePtr);
	if (InstancePtr->Geometry.MemoryLayout == XFL_LAYOUT_X16_X16_X1) {
		Startoffset = Offset >> 1;
		EndOffset = Offset + Bytes - 1;
		EndOffset = EndOffset >> 1;
	}
	else {
		Startoffset = Offset;
	}
	PartMode = (InstancePtr->Geometry.MemoryLayout &
			XFL_LAYOUT_PART_MODE_MASK);
	if (!XFL_GEOMETRY_IS_ABSOLUTE_VALID(&InstancePtr->Geometry,
		Startoffset)) {
		return (XFLASH_ADDRESS_ERROR);
	}
	if (XFlashAmd_ResetBank(InstancePtr, Startoffset, Bytes)
		!= XST_SUCCESS) {
		return (XST_FAILURE);
	}
	if (PartMode == XFL_LAYOUT_PART_MODE_8) {
		Src8BitPtr = (u8*) (((volatile u8*)InstancePtr->Geometry.
				     BaseAddress) + Offset);
		Dest8BitPtr = (u8*) DestPtr;
		for (Index = 0; Index < Bytes; Index++) {
			Dest8BitPtr[Index] = Src8BitPtr[Index];
		}
	}
	else if (PartMode == XFL_LAYOUT_PART_MODE_16) {
		AmdDevice_is_Ready(InstancePtr);
		DevDataPtr->SendCmd(GeomPtr->BaseAddress,XFL_AMD_CMD1_ADDR,
						XFL_AMD_CMD_STATUS_REG_CLEAR);
		Src16BitPtr = (u16*) (((volatile u16*) InstancePtr->Geometry.
				       BaseAddress) + Startoffset);
		Dest16BitPtr = (u16*) DestPtr;
		for (Index = 0; Index < (Bytes/2); Index++) {
			Dest16BitPtr[Index] = Src16BitPtr[Index];
		}
	} else {
		return (XFLASH_PART_NOT_SUPPORTED);
	}
	return (XST_SUCCESS);
}
int XFlashAmd_Read ( XFlash * InstancePtr , u32 Offset , u32 Bytes , void * DestPtr ) { u8 * Dest8BitPtr ; u8 * Src8BitPtr ; u16 * Dest16BitPtr ; u16 * Src16BitPtr ; u32 PartMode ; u32 Index ; u32 Startoffset ; u32 EndOffset ; XFlashGeometry * GeomPtr ; XFlashVendorData_Amd * DevDataPtr ; volatile u16 FlashStatus ; if ( InstancePtr == NULL ) { return ( XST_FAILURE ) ; } if ( DestPtr == NULL ) { return ( XST_FAILURE ) ; } if ( Bytes == 0 ) { return ( XST_FAILURE ) ; } GeomPtr = & InstancePtr -> Geometry ; DevDataPtr = GET_PARTDATA ( InstancePtr ) ; if ( InstancePtr -> Geometry . MemoryLayout == XFL_LAYOUT_X16_X16_X1 ) { Startoffset = Offset >> 1 ; EndOffset = Offset + Bytes - 1 ; EndOffset = EndOffset >> 1 ; } else { Startoffset = Offset ; } PartMode = ( InstancePtr -> Geometry . MemoryLayout & XFL_LAYOUT_PART_MODE_MASK ) ; if ( ! XFL_GEOMETRY_IS_ABSOLUTE_VALID ( & InstancePtr -> Geometry , Startoffset ) ) { return ( XFLASH_ADDRESS_ERROR ) ; } if ( XFlashAmd_ResetBank ( InstancePtr , Startoffset , Bytes ) != XST_SUCCESS ) { return ( XST_FAILURE ) ; } if ( PartMode == XFL_LAYOUT_PART_MODE_8 ) { Src8BitPtr = ( u8 * ) ( ( ( volatile u8 * ) InstancePtr -> Geometry . BaseAddress ) + Offset ) ; Dest8BitPtr = ( u8 * ) DestPtr ; for ( Index = 0 ; Index < Bytes ; Index ++ ) { Dest8BitPtr [ Index ] = Src8BitPtr [ Index ] ; } } else if ( PartMode == XFL_LAYOUT_PART_MODE_16 ) { AmdDevice_is_Ready ( InstancePtr ) ; DevDataPtr -> SendCmd ( GeomPtr -> BaseAddress , XFL_AMD_CMD1_ADDR , XFL_AMD_CMD_STATUS_REG_CLEAR ) ; Src16BitPtr = ( u16 * ) ( ( ( volatile u16 * ) InstancePtr -> Geometry . BaseAddress ) + Startoffset ) ; Dest16BitPtr = ( u16 * ) DestPtr ; for ( Index = 0 ; Index < ( Bytes / 2 ) ; Index ++ ) { Dest16BitPtr [ Index ] = Src16BitPtr [ Index ] ; } } else { return ( XFLASH_PART_NOT_SUPPORTED ) ; } return ( XST_SUCCESS ) ; }
The routine reads the data from the AMD flash device and copies it into
user buffer.
The routine reads the data from the AMD flash device and copies it into user buffer .
/* Verify inputs are valid. */ /*
	 * Check to make sure start address is within the device.
	 */ /*
	 * Reset the bank(s) so that it returns to the read mode.
	 */ /*
	 * Perform copy to the user buffer from the flash buffer.
	 */ /*
		 * Perform copy to the user buffer from the buffer.
		 */ /* Wait until device is ready. */ /* Send Status Register Clear Command. */ /* Perform copy to the user buffer from the buffer. */