lib/sw_services/xilflash/src/xilflash_amd.c
int XFlashAmd_Erase(XFlash * InstancePtr, u32 Offset, u32 Bytes)
{
	u16 StartRegion;
	u16 EndRegion;
	u16 StartBlock;
	u16 EndBlock;
	u16 BlocksLeft;
	u16 BlocksQueued;
	u32 Dummy;
	u32 StartOffset;
	u32 EndOffset;
	int Status = (int)XST_FAILURE;
	XFlashGeometry *GeomPtr;
	XFlashVendorData_Amd *DevDataPtr;

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

	GeomPtr = &InstancePtr->Geometry;

	/* Handle case when zero bytes is provided. */
	if (Bytes == 0) {
		return (XST_SUCCESS);
	}

	if (InstancePtr->Geometry.MemoryLayout == XFL_LAYOUT_X16_X16_X1) {
		StartOffset = Offset >> 1;
		EndOffset = Offset + Bytes - 1;
		EndOffset = EndOffset >> 1;
	}
	else {
		StartOffset = Offset;
		EndOffset = Offset + Bytes - 1;
	}
	/*
	 * Convert the starting address to block coordinates. This also verifies
	 * the starting address is within the instance's address space.
	 */
	Status = XFlashGeometry_ToBlock(GeomPtr, StartOffset, &StartRegion,
							&StartBlock, &Dummy);
	if (Status != XST_SUCCESS) {
		return (XFLASH_ADDRESS_ERROR);
	}

	/*
	 * Convert the ending address to block coordinates. This also verifies
	 * the ending address is within the instance's address space.
	 */
	Status = XFlashGeometry_ToBlock(GeomPtr, EndOffset,
					&EndRegion, &EndBlock, &Dummy);
	if (Status != XST_SUCCESS) {
		return (XFLASH_ADDRESS_ERROR);
	}

	/*
	 * Erase loop. Queue up as many blocks at a time until all are erased.
	 */
	DevDataPtr = GET_PARTDATA(InstancePtr);
	BlocksLeft = XFL_GEOMETRY_BLOCK_DIFF(GeomPtr, StartRegion, StartBlock,
					     EndRegion, EndBlock);

	while (BlocksLeft > 0) {
		BlocksQueued = EnqueueEraseBlocks(InstancePtr, &StartRegion,
						  &StartBlock, BlocksLeft);
		BlocksLeft -= BlocksQueued;
		Status = DevDataPtr->PollSR(GeomPtr->BaseAddress, StartOffset);
		if (Status != XFLASH_READY) {
			(void) XFlashAmd_ResetBank(InstancePtr, StartOffset,
				Bytes);
			return (Status);
		}
	}

	/* Reset the bank(s) so that it returns to the read mode. */
	(void) XFlashAmd_ResetBank(InstancePtr, StartOffset, Bytes);

	return (XST_SUCCESS);
}
/*****************************************************************************/
/**
*
* Erases the specified address range in the AMD Flash device.
*
* @param	InstancePtr is the pointer to the XFlash instance.
* @param	Offset is the offset into the device(s) address space from which
*		to begin erasure.
* @param	Bytes is the number of bytes to erase.
*
* @return
*		- XST_SUCCESS if successful.
*		- XFLASH_ADDRESS_ERROR if the destination address range is
*		  not completely within the addressable areas of the device(s).
*		- XST_FAILURE if failed.
*
* @note		Application has to check block protection status of all the
*		which needs to be erased before calling this API. If any block
* 		is protected then this API will return error.
*
******************************************************************************/
Erases the specified address range in the AMD Flash device.
Erases the specified address range in the AMD Flash device .
int XFlashAmd_Erase(XFlash * InstancePtr, u32 Offset, u32 Bytes)
{
	u16 StartRegion;
	u16 EndRegion;
	u16 StartBlock;
	u16 EndBlock;
	u16 BlocksLeft;
	u16 BlocksQueued;
	u32 Dummy;
	u32 StartOffset;
	u32 EndOffset;
	int Status = (int)XST_FAILURE;
	XFlashGeometry *GeomPtr;
	XFlashVendorData_Amd *DevDataPtr;
	if (InstancePtr == NULL) {
		return (XST_FAILURE);
	}
	GeomPtr = &InstancePtr->Geometry;
	if (Bytes == 0) {
		return (XST_SUCCESS);
	}
	if (InstancePtr->Geometry.MemoryLayout == XFL_LAYOUT_X16_X16_X1) {
		StartOffset = Offset >> 1;
		EndOffset = Offset + Bytes - 1;
		EndOffset = EndOffset >> 1;
	}
	else {
		StartOffset = Offset;
		EndOffset = Offset + Bytes - 1;
	}
	Status = XFlashGeometry_ToBlock(GeomPtr, StartOffset, &StartRegion,
							&StartBlock, &Dummy);
	if (Status != XST_SUCCESS) {
		return (XFLASH_ADDRESS_ERROR);
	}
	Status = XFlashGeometry_ToBlock(GeomPtr, EndOffset,
					&EndRegion, &EndBlock, &Dummy);
	if (Status != XST_SUCCESS) {
		return (XFLASH_ADDRESS_ERROR);
	}
	DevDataPtr = GET_PARTDATA(InstancePtr);
	BlocksLeft = XFL_GEOMETRY_BLOCK_DIFF(GeomPtr, StartRegion, StartBlock,
					     EndRegion, EndBlock);
	while (BlocksLeft > 0) {
		BlocksQueued = EnqueueEraseBlocks(InstancePtr, &StartRegion,
						  &StartBlock, BlocksLeft);
		BlocksLeft -= BlocksQueued;
		Status = DevDataPtr->PollSR(GeomPtr->BaseAddress, StartOffset);
		if (Status != XFLASH_READY) {
			(void) XFlashAmd_ResetBank(InstancePtr, StartOffset,
				Bytes);
			return (Status);
		}
	}
	(void) XFlashAmd_ResetBank(InstancePtr, StartOffset, Bytes);
	return (XST_SUCCESS);
}
int XFlashAmd_Erase ( XFlash * InstancePtr , u32 Offset , u32 Bytes ) { u16 StartRegion ; u16 EndRegion ; u16 StartBlock ; u16 EndBlock ; u16 BlocksLeft ; u16 BlocksQueued ; u32 Dummy ; u32 StartOffset ; u32 EndOffset ; int Status = ( int ) XST_FAILURE ; XFlashGeometry * GeomPtr ; XFlashVendorData_Amd * DevDataPtr ; if ( InstancePtr == NULL ) { return ( XST_FAILURE ) ; } GeomPtr = & InstancePtr -> Geometry ; if ( Bytes == 0 ) { return ( XST_SUCCESS ) ; } if ( InstancePtr -> Geometry . MemoryLayout == XFL_LAYOUT_X16_X16_X1 ) { StartOffset = Offset >> 1 ; EndOffset = Offset + Bytes - 1 ; EndOffset = EndOffset >> 1 ; } else { StartOffset = Offset ; EndOffset = Offset + Bytes - 1 ; } Status = XFlashGeometry_ToBlock ( GeomPtr , StartOffset , & StartRegion , & StartBlock , & Dummy ) ; if ( Status != XST_SUCCESS ) { return ( XFLASH_ADDRESS_ERROR ) ; } Status = XFlashGeometry_ToBlock ( GeomPtr , EndOffset , & EndRegion , & EndBlock , & Dummy ) ; if ( Status != XST_SUCCESS ) { return ( XFLASH_ADDRESS_ERROR ) ; } DevDataPtr = GET_PARTDATA ( InstancePtr ) ; BlocksLeft = XFL_GEOMETRY_BLOCK_DIFF ( GeomPtr , StartRegion , StartBlock , EndRegion , EndBlock ) ; while ( BlocksLeft > 0 ) { BlocksQueued = EnqueueEraseBlocks ( InstancePtr , & StartRegion , & StartBlock , BlocksLeft ) ; BlocksLeft -= BlocksQueued ; Status = DevDataPtr -> PollSR ( GeomPtr -> BaseAddress , StartOffset ) ; if ( Status != XFLASH_READY ) { ( void ) XFlashAmd_ResetBank ( InstancePtr , StartOffset , Bytes ) ; return ( Status ) ; } } ( void ) XFlashAmd_ResetBank ( InstancePtr , StartOffset , Bytes ) ; return ( XST_SUCCESS ) ; }
Erases the specified address range in the AMD Flash device.
Erases the specified address range in the AMD Flash device .
/* Verify inputs are valid. */ /* Handle case when zero bytes is provided. */ /*
	 * Convert the starting address to block coordinates. This also verifies
	 * the starting address is within the instance's address space.
	 */ /*
	 * Convert the ending address to block coordinates. This also verifies
	 * the ending address is within the instance's address space.
	 */ /*
	 * Erase loop. Queue up as many blocks at a time until all are erased.
	 */ /* Reset the bank(s) so that it returns to the read mode. */