nandps
Vitis Drivers API Documentation
xnandps_skip_example.c File Reference

Overview

This file contains a design example using the NAND driver (XNandPs).

This example tests the skip block method of erase/read/write operations. The skip block method is useful while reading/writing images on to the flash. The flash is erased and programming by considering the bad blocks. The data is read back and compared with the data written for correctness.

Note

None.

 MODIFICATION HISTORY:
 Ver   Who  Date         Changes


1.00 nm 12/10/2010 First release 1.01a nm 28/02/2012 Modified the test offsets. ms 04/10/17 Modified Comment lines to follow doxygen rules 2.8 akm 07/06/23 Add support for system device-tree flow.

Macros

#define NAND_TEST_OFFSET   0x01000000
 Flash Test Offset. More...
 
#define NAND_TEST_LENGTH   0x00080000
 Test Length. More...
 

Functions

int NandSkipBlockExample (u32 NandDeviceId)
 This function runs a test on the NAND flash device using the basic driver functions. More...
 
int XNandPs_SkipRead (XNandPs *InstancePtr, u64 Offset, u32 Length, void *DestPtr)
 This function reads the data from the Flash device and copies it into the specified user buffer. More...
 
int XNandPs_SkipWrite (XNandPs *InstancePtr, u64 Offset, u32 Length, void *SrcPtr)
 This function programs the flash device(s) with data specified in the user buffer. More...
 
int XNandPs_SkipErase (XNandPs *InstancePtr, u64 Offset, u32 Length)
 This function erases length bytes in the flash device from a given offset. More...
 
int main (void)
 Main function to execute the Skip Block based Nand read/write example. More...
 
u32 XNandPs_CalculateLength (XNandPs *InstancePtr, u64 Offset, u32 Length)
 This function returns the length including bad blocks from a given offset and length. More...
 

Macro Definition Documentation

#define NAND_TEST_LENGTH   0x00080000

Test Length.

Referenced by NandSkipBlockExample().

#define NAND_TEST_OFFSET   0x01000000

Flash Test Offset.

Referenced by NandSkipBlockExample().

Function Documentation

int main ( void  )

Main function to execute the Skip Block based Nand read/write example.

Returns
  • XST_SUCCESS if the example has completed successfully.
  • XST_FAILURE if the example has failed.
Note
None.

References NandSkipBlockExample().

int NandSkipBlockExample ( u32  NandDeviceId)

This function runs a test on the NAND flash device using the basic driver functions.

The function does the following tasks:

  • Initialize the driver.
  • Erase the required length of bytes by taking bad blocks into account.
  • Write the number of bytes from given offset by taking bad blocks into account.
  • Read the number of bytes from given offset by taking bad blocks into account.
  • Compare the data read against the data Written.
Parameters
NandDeviceIdis the XPAR_<NAND_instance>_DEVICE_ID value from xparameters.h.
Returns
  • XST_SUCCESS if successful.
  • XST_FAILURE if failed.
Note
None.

References XNandPs_Config::FlashBase, NAND_TEST_LENGTH, NAND_TEST_OFFSET, ReadBuffer, XNandPs_Config::SmcBase, WriteBuffer, XNandPs_CfgInitialize(), XNandPs_LookupConfig(), XNandPs_SkipErase(), XNandPs_SkipRead(), and XNandPs_SkipWrite().

Referenced by main().

u32 XNandPs_CalculateLength ( XNandPs InstancePtr,
u64  Offset,
u32  Length 
)

This function returns the length including bad blocks from a given offset and length.

Parameters
InstancePtris the pointer to the XNandPs instance.
Offsetis the flash data address to read from.
Lengthis number of bytes to read.
Returns
  • Return actual length including bad blocks.
Note
None.

References XNandPs_Geometry::BlockSize, XNandPs_Geometry::DeviceSize, XNandPsTag::Geometry, and XNandPs_IsBlockBad().

Referenced by XNandPs_SkipRead(), and XNandPs_SkipWrite().

int XNandPs_SkipErase ( XNandPs InstancePtr,
u64  Offset,
u32  Length 
)

This function erases length bytes in the flash device from a given offset.

The Offset and Length must be block aligned. This functions skips bad blocks.

Parameters
InstancePtris the pointer to the XNand instance.
Offsetis the flash address to start erasing from.
Lengthis number of bytes to erase.
Returns
  • XST_SUCCESS if successful.
  • XST_FAILURE if error in erase.
Note
None.

References XNandPs_Geometry::BlockSize, XNandPsTag::Geometry, XNandPs_Geometry::NumBlocks, XNandPs_EraseBlock(), and XNandPs_IsBlockBad().

Referenced by NandSkipBlockExample().

int XNandPs_SkipRead ( XNandPs InstancePtr,
u64  Offset,
u32  Length,
void *  DestPtr 
)

This function reads the data from the Flash device and copies it into the specified user buffer.

This function considers bad blocks and skips them to read next blocks.

Parameters
InstancePtris the pointer to the XNandPs instance.
Offsetis the flash data address to read from.
Lengthis number of bytes to read.
DestPtris the destination address to copy data to.
Returns
  • XST_SUCCESS if successful.
  • XST_FAILURE if fail.
Note
None.

References XNandPs_Geometry::BlockSize, XNandPs_Geometry::DeviceSize, XNandPsTag::Geometry, XNandPs_CalculateLength(), XNandPs_IsBlockBad(), and XNandPs_Read().

Referenced by NandSkipBlockExample().

int XNandPs_SkipWrite ( XNandPs InstancePtr,
u64  Offset,
u32  Length,
void *  SrcPtr 
)

This function programs the flash device(s) with data specified in the user buffer.

This function considers bad blocks and skips them.

Parameters
InstancePtris the pointer to the XNandPs instance.
Offsetis the flash data address to write to.
Lengthis number of bytes to write.
SrcPtris the source address to write the data from.
Returns
  • XST_SUCCESS if successful.
  • XST_FAILURE if fail.
Note
None.

References XNandPs_Geometry::BlockSize, XNandPs_Geometry::DeviceSize, XNandPsTag::Geometry, XNandPs_CalculateLength(), XNandPs_IsBlockBad(), and XNandPs_Write().

Referenced by NandSkipBlockExample().