#include "xil_types.h"
#include "xstatus.h"
#include "xilflash_properties.h"
#include "xparameters.h"
#include <string.h>
Data Structures | |
struct | XFlash_UserInputs |
struct | XFlashGeometry |
struct | XFlashTag |
Defines | |
#define | XFL_CMDSET_INTEL_STANDARD 3 |
#define | XFL_CMDSET_INTEL_EXTENDED 1 |
#define | XFL_CMDSET_AMD_STANDARD 2 |
#define | XFL_CMDSET_AMD_EXTENDED 4 |
#define | XFL_CMDSET_INTEL_G18 0x200 |
#define | XFLASH_BUSY 101 |
#define | XFLASH_READY 102 |
#define | XFLASH_ERROR 103 |
#define | XFLASH_ERASE_SUSPENDED 104 |
#define | XFLASH_WRITE_SUSPENDED 105 |
#define | XFLASH_PART_NOT_SUPPORTED 106 |
#define | XFLASH_NOT_SUPPORTED 107 |
#define | XFLASH_TOO_MANY_REGIONS 108 |
#define | XFLASH_TIMEOUT_ERROR 109 |
#define | XFLASH_ADDRESS_ERROR 110 |
#define | XFLASH_ALIGNMENT_ERROR 111 |
#define | XFLASH_BLOCKING_CALL_ERROR 112 |
#define | XFLASH_CFI_QUERY_ERROR 113 |
#define | XFLASH_BLOCK_PROTECTED 114 |
#define | XFL_LAYOUT_X16_X8_X1 0x02020101 |
#define | XFL_LAYOUT_X16_X16_X1 0x02020201 |
#define | XFL_LAYOUT_X16_X16_X2 0x04020202 |
#define | XFL_LAYOUT_X16_X16_X4 0x08020204 |
#define | XFL_DEVCTL_GET_LAST_ERROR 1 |
#define | XFL_DEVCTL_GET_GEOMETRY 2 |
#define | XFL_DEVCTL_GET_PROPERTIES 3 |
#define | XFL_DEVCTL_SET_RYBY 4 |
#define | XFL_DEVCTL_ERASE_RESUME 5 |
#define | XFL_DEVCTL_ERASE_SUSPEND 6 |
#define | XFL_DEVCTL_ENTER_EXT_MODE 7 |
#define | XFL_DEVCTL_EXIT_EXT_MODE 8 |
#define | XFL_DEVCTL_CHIP_ERASE 9 |
#define | XFL_DEVCTL_PROTECTION_STATUS 10 |
#define | XFL_INTEL_MAX_ERASE_REGIONS 20 |
#define | XFL_GEOMETRY_INCREMENT(GeometryPtr, Region, Block) |
#define | XFL_GEOMETRY_BLOCK_DIFF(GeometryPtr, StartRegion, StartBlock, EndRegion, EndBlock) |
#define | XFL_GEOMETRY_IS_ABSOLUTE_VALID(GeometryPtr, Offset) ((Offset) < (GeometryPtr)->DeviceSize) |
#define | XFL_GEOMETRY_IS_BLOCK_VALID(GeometryPtr, Region, Block, BlockOffset) |
Typedefs | |
typedef XFlashTag | XFlash |
Functions | |
int | XFlash_Initialize (XFlash *InstancePtr, u32 BaseAddress, u8 BusWidth, int IsPlatformFlash) |
int | XFlash_Reset (XFlash *InstancePtr) |
int | XFlash_DeviceControl (XFlash *InstancePtr, u32 Command, DeviceCtrlParam *Parameters) |
int | XFlash_Read (XFlash *InstancePtr, u32 Offset, u32 Bytes, void *DestPtr) |
int | XFlash_Write (XFlash *InstancePtr, u32 Offset, u32 Bytes, void *SrcPtr) |
int | XFlash_Erase (XFlash *InstancePtr, u32 Offset, u32 Bytes) |
int | XFlash_Lock (XFlash *InstancePtr, u32 Offset, u32 Bytes) |
int | XFlash_Unlock (XFlash *InstancePtr, u32 Offset, u32 Bytes) |
int | XFlash_IsReady (XFlash *InstancePtr) |
This is not a library for a specific device, but for a set of command read/write/erase algorithms. CFI allows us to determine which algorithm to utilize at runtime.
Library Initialization
The function call XFlash_Initialize() should be called by the application before any other function in the library. The initialization function checks for the device family and initializes the XFlash instance with the family specific data. The VT table (Contains the function pointers to family specific API's) is setup and family specific initialization routine is called.
Device Geometry
The Device geometry varies for different flash device families. The following list describes geometry of different flash device families:
Intel Flash Device Geometry
Flash memory space is segmented into areas called blocks. The size of each block is based on a power of 2. A region is defined as a contiguous set of blocks of the same size. Some parts have several regions while others have one. The arrangement of blocks and regions is refered to by this module as the part's geometry. Some Intel flash supports multiple banks on the same device. This library supports single and multiple bank flash devices.
AMD Flash Device Geometry
Flash memory space is segmented into areas called banks and further in to regions and blocks. The size of each block is based on a power of 2. A region is defined as a contiguous set of blocks of the same size. Some parts have several regions while others have one. A bank is defined as a contiguous set of blocks. The bank may contain blocks of different size. The arrangement of blocks, regions and banks is referred to by this module as the part's geometry.
The cells within the part can be programmed from a logic 1 to a logic 0 and not the other way around. To change a cell back to a logic 1, the entire block containing that cell must be erased. When a block is erased all bytes contain the value 0xFF. The number of times a block can be erased is finite. Eventually the block will wear out and will no longer be capable of erasure. As of this writing, the typical flash block can be erased 100,000 or more times.
Write Operation
The write call can be used to write a minimum of zero bytes and a maximum entire flash. If the Offset Address specified to write is out of flash or if the number of bytes specified from the Offset address exceed flash boundaries an error is reported back to the user. The write is blocking in nature in that the control is returned back to user only after the write operation is completed successfully or an error is reported.
Read Operation
The read call can be used to read a minimum of zero bytes and maximum of entire flash. If the Offset Address specified to write is out of flash boundary an error is reported back to the user. The read function reads memory locations beyond Flash boundary. Care should be taken by the user to make sure that the Number of Bytes + Offset address is within the Flash address boundaries. The write is blocking in nature in that the control is returned back to user only after the read operation is completed successfully or an error is reported.
Erase Operation
The erase operations are provided to erase a Block in the Flash memory. The erase call is blocking in nature in that the control is returned back to user only after the erase operation is completed successfully or an error is reported.
Sector Protection
The Flash Device is divided into Blocks. Each Block can be protected individually from unwarranted writing/erasing. The Block locking can be achieved using XFlash_Lock() lock. All the memory locations from the Offset address specified will be locked. The block can be unlocked using XFlash_UnLock() call. All the Blocks which are previously locked will be unlocked. The Lock and Unlock calls are blocking in nature in that the control is returned back to user only after the operation is completed successfully or an error is reported. The AMD flash device requires high voltage on Reset pin to perform lock and unlock operation. User must provide this high voltage (As defined in datasheet) to reset pin before calling lock and unlock API for AMD flash devices. Lock and Unlock features are not tested for AMD flash device.
Device Control
Functionalities specific to a Flash Device Family are implemented as Device Control.
The following are the Intel specific device control:
The following are the AMD specific device control:
This library is intended to be RTOS and processor independent. It works with physical addresses only. Any needs for dynamic memory management, threads, mutual exclusion, virtual memory, cache control, or HW write protection management must be satisfied by the layer above this library.
All writes to flash occur in units of bus-width bytes. If more than one part exists on the data bus, then the parts are written in parallel. Reads from flash are performed in any width up to the width of the data bus. It is assumed that the flash bus controller or local bus supports these types of accesses.
MODIFICATION HISTORY:
Ver Who Date Changes ----- ---- -------- ----------------------------------------------- 1.00a rmm 10/25/07 First release 1.00a mta 10/25/07 Updated to flash library 1.01a ksu 04/10/08 Added support for AMD CFI Interface 1.02a ksu 06/16/09 Added support for multiple banks in Intel flash Removed unused defines (XFL_MAX_NUM_BANKS, XFL_BANK1, XFL_BANK2) Added IOCTL to set configuration register of platform flash 1.03a ksu 10/07/09 Added support for large buffer size flash (CR535564) 2.00a ktn 12/04/09 Updated to use the HAL processor APIs/macros 2.01a ktn 03/31/10 Updated the AMD code to support uniform sector WP modes 2.02a sdm 06/30/10 Updated to support AXI EMC with Little Endian Processor 2.02a sdm 07/07/10 Updated XFlashAmd_Initialize() to NOT change the erase region information of a top boot device, when the number of erase regions is not more than 1. 3.00a sdm 03/03/11 Removed static parameters in mld and updated code to determine these parameters from the CFI data. 3.00a sdm 03/23/11 Added two new parameters in mld for flash families. Users can enable support for either of the flash devices or both of them. 3.01a srt 03/02/12 Added support for Micron G18 Flash device to fix CRs 648372, 648282. Modified XFlashIntel_Reset function to reset all the partitions. Added DATA_SYNC to fix the CR 644750. 3.02a srt 05/30/12 Changed Implementation for Micron G18 Flash, which fixes the CR 662317. CR 662317 Description - Xilinx Platform Flash on ML605 fails to work. 3.03a srt 11/04/12 Increased AMD maximum erase regions (CR 668730) Fixed CR 679937 - Description: Non-word aligned data write to flash fails with AXI interface. 3.04a srt 02/18/13 Fixed CR 700553.
|
Includes Fujitsu/STM |
|
Includes Fujitsu/STM |
|
Includes Micron/Sharp |
|
Micron G18 Flash |
|
Vendor command set codes. Refer to industry document "CFI publication 100" for the latest list Includes Micron/Sharp |
|
Erase whole chip |
|
Enter Extended mode |
|
Resume Erase |
|
Suspend Erase |
|
Exit Extended mode |
|
Get Device geometry |
|
Retrieve the last error data |
|
Get Device Properties |
|
Check block protection status |
|
Set RYBY pin mode |
|
Value: (((GeometryPtr)->EraseRegion[EndRegion].AbsoluteBlock + (EndBlock)) - \ ((GeometryPtr)->EraseRegion[StartRegion].AbsoluteBlock + \ (StartBlock)) + 1)
|
|
Value: { \
if ((GeometryPtr)->EraseRegion[Region].Number <= ++(Block)) \
{ \
(Region)++; \
(Block) = 0; \
} \
}
|
|
Tests the given absolute Offset to verify it lies within the bounds of the address space defined by a geometry instance.
|
|
Value: (((Region) < ( GeometryPtr)->NumEraseRegions) && \ ((Block) < (GeometryPtr)->EraseRegion[Region].Number) && \ ((BlockOffset) < (GeometryPtr)->EraseRegion[Region].Size))
|
|
A block region is defined as a set of consecutive erase blocks of the same size. Most flash devices only have a handful of regions. If a part has more regions than defined by this constant, then the constant must be modified to accommodate the part. The minimum value of this constant is 1 and there is no maximum value. Note that increasing this value also increases the amount of memory used by the geometry structure approximately 12 bytes per increment. |
|
One 16-bit part operating in 16-bit mode. Total data bus width is 16-bits. This layout is supported in AMD and Intel flash devices |
|
Two 16-bit parts operating in 16-bit mode. Total data bus width is 32-bits. This layout is only supported in Intel flash devices |
|
Four 16-bit parts operating in 16-bit mode. Total data bus width is 64-bits. This layout is only supported in Intel flash devices |
|
Supported part arrangements. This enumeration defines the supported arrangements of parts on the data-bus. The naming convention for these constants is as follows: XFL_LAYOUT_Xa_Xb_Xc, where Xa is the part's physical data bus width. Xb is the is the part's selected data bus width (this field is required because a x16 part can be placed in x8 mode). Xc is the number of interleaved parts. For example one part can be tied to D0-D15 and a second to data lines D15-D31. Parts arranged in series should be treated as separate instances. An example of this layout: Two X16 parts operating in X16 mode. The first part occupies address space FF000000 - FF0FFFFF and a second from FF100000 - FF1FFFFF. These constants are encoded using bit masks defined in the next section. One 16-bit part operating in 8-bit mode. Total data bus width is 8-bits. This layout is only supported in AMD flash devices |
|
Accessed flash outside its addressable range |
|
Write alignment error |
|
Block is protected |
|
Couldn't return immediately from write/erase function with XFL_NON_BLOCKING_WRITE/ERASE option cleared |
|
Flash is erasing or programming |
|
Failed to query the device |
|
Flash is in suspended erase state |
|
Flash had detected an internal error. Use XFlash_DeviceControl to retrieve device specific codes |
|
Operation not supported |
|
Flash type not supported by library |
|
Flash is ready for commands |
|
Programming or erase operation aborted due to a timeout |
|
Too many erase regions |
|
Flash is in suspended write state |
|
The XFlash library instance data. The user is required to allocate a variable of this type for every flash device in the system. A pointer to a variable of this type is then passed to the library API functions. |
|
This function is used to execute device specific commands. For a list of device specific commands, see the xilflash.h.
|
|
This function erases the specified address range in the flash device. The number of bytes to erase can be any number as long as it is within the bounds of the device(s). The device is polled until an error or the operation completes successfully.
|
|
Initializes a specific XFlash instance. The initialization entails:
|
|
Checks the readiness of the device, which means it has been successfully initialized.
|
|
This function Locks the blocks in the specified range of the flash device(s). The device is polled until an error or the operation completes successfully.
|
|
This function reads the data from the Flash device and copies it into the specified user buffer. The source and destination addresses can be on any alignment supported by the processor. The device is polled until an error or the operation completes successfully.
|
|
This function resets the flash device and places it in read mode.
|
|
This function Unlocks the blocks in the specified range of the flash device(s). The device is polled until an error or the operation completes successfully.
|
|
This function programs the flash device(s) with data specified in the user buffer. The source and destination address must be aligned to the width of the flash's data bus. The device is polled until an error or the operation completes successfully.
|