xnandps.c File Reference
#include "xnandps.h"
#include "xnandps_bbm.h"
#include "xnandps_onfi.h"
Functions |
void | XNandPs_SendCommand (XNandPs *InstancePtr, XNandPs_CommandFormat *Command, int Page, int Column) |
void | XNandPs_InitBbtDesc (XNandPs *InstancePtr) |
int | XNandPs_ScanBbt (XNandPs *InstancePtr) |
u8 | Onfi_CmdReadStatus (XNandPs *InstancePtr) |
int | Onfi_NandInit (XNandPs *InstancePtr) |
int | XNandPs_CfgInitialize (XNandPs *InstancePtr, XNandPs_Config *ConfigPtr, u32 SmcBaseAddr, u32 FlashBaseAddr) |
int | XNandPs_Read (XNandPs *InstancePtr, u64 Offset, u32 Length, void *DestPtr, u8 *UserSparePtr) |
int | XNandPs_ReadCache (XNandPs *InstancePtr, u64 Offset, u32 Length, void *DestPtr, u8 *UserSparePtr) |
int | XNandPs_Write (XNandPs *InstancePtr, u64 Offset, u32 Length, void *SrcPtr, u8 *UserSparePtr) |
int | XNandPs_WriteCache (XNandPs *InstancePtr, u64 Offset, u32 Length, void *SrcPtr, u8 *UserSparePtr) |
int | XNandPs_ReadSpareBytes (XNandPs *InstancePtr, u32 Page, u8 *Buf) |
int | XNandPs_WriteSpareBytes (XNandPs *InstancePtr, u32 Page, u8 *Buf) |
int | XNandPs_EraseBlock (XNandPs *InstancePtr, u32 BlockNum) |
Variables |
u32 | NandOob16 [] = {13, 14, 15} |
u32 | NandOob32 [] = {26, 27, 28, 29, 30, 31} |
u32 | NandOob64 [] |
XNandPs_CommandFormat | OnfiCommands [] |
Detailed Description
This file contains the implementation of the interface functions for XNandPs driver. Refer to the header file xnandps.h for more detailed information.
This module supports for NAND flash memory devices that conform to the "Open NAND Flash Interface" (ONFI) Specification. This modules implements basic flash operations like read, write and erase.
- Note:
- None
MODIFICATION HISTORY:
Ver Who Date Changes
----- ---- ---------- -----------------------------------------------
1.00a nm 12/10/2010 First release
1.01a nm 28/02/2012 Fixed 16-bit issue with ONFI commands like
read, write and read status command. The config
structure width is updated after ONFI query
with the parameter page width.
1.02a nm 20/09/2012 Removed setting of set_cycles and set_opmode
register values as it is now done in FSBL using
the PCW generated files. CR#678949.
1.03a nm 10/22/2012 Fixed CR# 673348.
1.04a nm 04/15/2013 Fixed CR# 704401. Removed warnings when compiled
with -Wall and -Wextra option in bsp.
04/25/2013 Implemented PR# 699544. Added page cache read
and program support. Added API's XNandPs_ReadCache
and XNandPs_WriteCache for page cache support.
Added ECC handling functions XNandPs_EccSetCfg,
XNandPs_EccSetMemCmd1...etc, to support better
usage of ECC block for page cache commands.
Modified Read/Write API's so that there is common
code for normal read/write and page cache commands.
Disabling/Re-enabling ECC block in read/write API's
of spare bytes since we don't calculate ECC for
spare bytes.
2.01 kpc 07/24/2014 Fixed CR#808770. Update command register twice only
if flash device requires >= four address cycles.
Function Documentation
u8 Onfi_CmdReadStatus |
( |
XNandPs * |
InstancePtr |
) |
|
This function sends read status command to the flash device.
- Parameters:
-
| InstancePtr | is a pointer to the XNandPs instance. |
- Returns:
- flash status value read
- Note:
- None
int Onfi_NandInit |
( |
XNandPs * |
InstancePtr |
) |
|
This function initializes the NAND flash and gets the geometry information.
- Parameters:
-
| InstancePtr | is a pointer to the XNandPs instance. |
- Returns:
- XST_SUCCESS if successful.
- XST_FAILURE if failed.
- Note:
- None
int XNandPs_CfgInitialize |
( |
XNandPs * |
InstancePtr, |
|
|
XNandPs_Config * |
ConfigPtr, |
|
|
u32 |
SmcBaseAddr, |
|
|
u32 |
FlashBaseAddr | |
|
) |
| | |
This function initializes a specific XNandPs device/instance. This function must be called prior to using the flash device to read or write any data.
- Parameters:
-
| InstancePtr | is a pointer to the XNandPs instance. |
| ConfigPtr | points to the XNandPs device configuration structure. |
| SmcBaseAddr | is the base address of SMC controller. |
| FlashBaseAddr | is the base address of NAND flash. |
- Returns:
- XST_SUCCESS if successful.
- XST_FAILURE if fail.
- Note:
- The user needs to first call the XNandPs_LookupConfig() API which returns the Configuration structure pointer which is passed as a parameter to the XNandPs_CfgInitialize() API.
int XNandPs_EraseBlock |
( |
XNandPs * |
InstancePtr, |
|
|
u32 |
BlockNum | |
|
) |
| | |
This function erases a specific block in the NAND device.
- Parameters:
-
| InstancePtr | is a pointer to the XNandPs instance. |
| BlockNum | is the block number of the device. |
- Returns:
- XST_SUCCESS if successful.
- XST_FAILURE if fail.
- XST_NAND_WRITE_PROTECTED if the flash is write protected.
- Note:
- None
void XNandPs_InitBbtDesc |
( |
XNandPs * |
InstancePtr |
) |
|
This function initializes the Bad Block Table(BBT) descriptors with a predefined pattern for searching Bad Block Table(BBT) in flash.
- Parameters:
-
| InstancePtr | is a pointer to the XNandPs instance. |
- Returns:
-
int XNandPs_Read |
( |
XNandPs * |
InstancePtr, |
|
|
u64 |
Offset, |
|
|
u32 |
Length, |
|
|
void * |
DestPtr, |
|
|
u8 * |
UserSparePtr | |
|
) |
| | |
This function reads the data from the Flash device and copies it into the specified user buffer. It doesn't check for the bad blocks while reading the flash pages that cross block boundary. User must take care of handling bad blocks.
- Parameters:
-
| InstancePtr | is the pointer to the XNandPs instance. |
| Offset | is the flash data address to read from. |
| Length | is number of bytes to read. |
| DestPtr | is the destination address to copy data to. |
| UserSparePtr | is the user buffer to which spare data must be copied. |
- Returns:
- XST_SUCCESS if successful.
- XST_FAILURE if fail.
- Note:
- This function reads sequential pages from the Flash device.
int XNandPs_ReadCache |
( |
XNandPs * |
InstancePtr, |
|
|
u64 |
Offset, |
|
|
u32 |
Length, |
|
|
void * |
DestPtr, |
|
|
u8 * |
UserSparePtr | |
|
) |
| | |
This function reads the data from the Flash device using read page cache command and copies it into the specified user buffer. It doesn't check for the bad blocks while reading the flash pages that cross block boundary. User must take care of handling bad blocks.
- Parameters:
-
| InstancePtr | is the pointer to the XNandPs instance. |
| Offset | is the flash data address to read from. |
| Length | is number of bytes to read. |
| DestPtr | is the destination address to copy data to. |
| UserSparePtr | is the user buffer to which spare data must be copied. |
- Returns:
- XST_SUCCESS if successful.
- XST_FAILURE if fail.
- Note:
- This function reads sequential pages from the Flash device.
int XNandPs_ReadSpareBytes |
( |
XNandPs * |
InstancePtr, |
|
|
u32 |
Page, |
|
|
u8 * |
Buf | |
|
) |
| | |
This function reads the spare area of a page.
- Parameters:
-
| InstancePtr | is the pointer to the XNandPs instance. |
| Page | is the page number from where spare data is read. |
| Buf | is pointer to the buffer where the spare data is filled. |
- Returns:
- XST_SUCCESS if successful.
- XST_FAILURE if fail.
- Note:
- None.
int XNandPs_ScanBbt |
( |
XNandPs * |
InstancePtr |
) |
|
This function reads the Bad Block Table(BBT) if present in flash. If not it scans the flash for detecting factory marked bad blocks and creates a bad block table and write the Bad Block Table(BBT) into the flash.
- Parameters:
-
| InstancePtr | is a pointer to the XNandPs instance. |
- Returns:
- XST_SUCCESS if successful.
- XST_FAILURE if fail.
This function sends a NAND command to the flash device.
- Parameters:
-
| InstancePtr | is the pointer to XNandPs struture |
| Command | is the NAND command to send |
| Page | is the page offset required for specific commands |
| Column | the column offset required for specific commands |
- Returns:
- None
- Note:
- None
int XNandPs_Write |
( |
XNandPs * |
InstancePtr, |
|
|
u64 |
Offset, |
|
|
u32 |
Length, |
|
|
void * |
SrcPtr, |
|
|
u8 * |
UserSparePtr | |
|
) |
| | |
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. It doesn't check for the bad blocks while writing to the flash pages that cross block boundary. User must take care of handling bad blocks.
- Parameters:
-
| InstancePtr | is the pointer to the XNandPs instance. |
| Offset | is the flash data address to write to. |
| Length | is number of bytes to write. |
| SrcPtr | is the source address to write the data from. |
| UserSparePtr | is the user buffer which contains buffer to write into spare data area. |
- Returns:
- XST_SUCCESS if successful.
- XST_FAILURE if fail.
- XST_NAND_WRITE_PROTECTED if the flash is write protected.
- Note:
- This function writes number of sequential pages into the Flash device.
int XNandPs_WriteCache |
( |
XNandPs * |
InstancePtr, |
|
|
u64 |
Offset, |
|
|
u32 |
Length, |
|
|
void * |
SrcPtr, |
|
|
u8 * |
UserSparePtr | |
|
) |
| | |
This function programs the flash device(s) with data specified in the user buffer using program cache command. The source and destination address must be aligned to the width of the flash's data bus. It doesn't check for the bad blocks while writing to the flash pages that cross block boundary. User must take care of handling bad blocks.
- Parameters:
-
| InstancePtr | is the pointer to the XNandPs instance. |
| Offset | is the flash data address to write to. |
| Length | is number of bytes to write. |
| SrcPtr | is the source address to write the data from. |
| UserSparePtr | is the user buffer which contains buffer to write into spare data area. |
- Returns:
- XST_SUCCESS if successful.
- XST_FAILURE if fail.
- XST_NAND_WRITE_PROTECTED if the flash is write protected.
- Note:
- This function writes number of sequential pages into the Flash device.
int XNandPs_WriteSpareBytes |
( |
XNandPs * |
InstancePtr, |
|
|
u32 |
Page, |
|
|
u8 * |
Buf | |
|
) |
| | |
This function write to the spare area of a page.
- Parameters:
-
| InstancePtr | is the pointer to the XNandPs instance. |
| Page | is the page number to write. |
| Buf | is pointer to the buffer which holds the data. |
- Returns:
- XST_SUCCESS if successful.
- XST_FAILURE if fail.
- Note:
- None.
Variable Documentation
Ecc position for 16 bytes spare area
Ecc position for 32 bytes spare area
Initial value: {52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63}
Ecc position for 64 bytes spare area
ONFI commands
This structure defines the onfi command format sent to the flash.
Copyright © 1995-2014 Xilinx, Inc. All rights reserved.