Microchip® Advanced Software Framework

nand_flash_management.h File Reference

NAND Flash Management.

This file contains definitions and functions for NAND Flash block management.

Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.

#include "nand_flash_ecc.h"

Data Structures

struct  block_status
 
struct  nand_flash_management
 

Macros

#define BLOCK_STATUS_BAD   0x00
 
#define BLOCK_STATUS_DEFAULT   0xFF
 The lower layer of NAND Flash block management, it is called by NAND Flash translation layer, and it will call NAND Flash ECC layer. More...
 
#define BLOCK_STATUS_DIRTY   0x08
 
#define BLOCK_STATUS_FREE   0x0E
 
#define BLOCK_STATUS_LIVE   0x0C
 
#define ERASE_DATA   1
 
#define ERASE_DIRTY   0
 
#define ERASE_FULL   2
 

Functions

uint32_t nand_flash_management_allocate_block (struct nand_flash_management *managed, uint16_t block)
 Allocate a FREE block of a managed NAND Flash and mark it as LIVE. More...
 
uint32_t nand_flash_management_copy_block (const struct nand_flash_management *managed, uint16_t source_block, uint16_t dest_block)
 Copy the data from a whole block to another block in NAND Flash. More...
 
uint32_t nand_flash_management_copy_page (const struct nand_flash_management *managed, uint16_t source_block, uint16_t source_page, uint16_t dest_block, uint16_t dest_page)
 Copy the data & spare area of one page to another page. More...
 
uint16_t nand_flash_management_count_blocks (const struct nand_flash_management *managed, uint8_t status)
 Count and return the number of blocks having the given status in a managed NAND Flash. More...
 
uint32_t nand_flash_management_erase_all (struct nand_flash_management *managed, uint8_t level)
 Erase all blocks in the managed area of NAND Flash. More...
 
uint32_t nand_flash_management_erase_block (struct nand_flash_management *managed, uint16_t block)
 Erase a DIRTY block of a managed NAND Flash. More...
 
uint32_t nand_flash_management_erase_dirty_blocks (struct nand_flash_management *managed)
 Erases all the blocks which are currently marked as DIRTY. More...
 
uint32_t nand_flash_management_find_youngest_block (const struct nand_flash_management *managed, uint8_t status, uint16_t *block)
 Look for the youngest block having the desired status among the blocks of a managed NAND Flash. More...
 
uint16_t nand_flash_management_get_managed_blocks (const struct nand_flash_management *managed)
 Return the number of available blocks in a managed NAND Flash. More...
 
uint32_t nand_flash_management_initialize (struct nand_flash_management *managed, const struct nand_flash_model *model, uint32_t command_address, uint32_t address_address, uint32_t data_address, uint16_t base_block, uint16_t size_in_block)
 Initialize a nand_flash_management instance. More...
 
uint32_t nand_flash_management_read_page (const struct nand_flash_management *managed, uint16_t block, uint16_t page, void *data, void *spare)
 Read the data and/or the spare area of a page on a managed NAND Flash. More...
 
uint32_t nand_flash_management_release_block (struct nand_flash_management *managed, uint16_t block)
 Release a LIVE block of a NAND Flash and marks it as DIRTY. More...
 
uint32_t nand_flash_management_write_page (const struct nand_flash_management *managed, uint16_t block, uint16_t page, void *data, void *spare)
 Writes the data and/or spare area of a LIVE page on a managed NAND Flash. More...
 

#define BLOCK_STATUS_BAD   0x00
#define BLOCK_STATUS_DEFAULT   0xFF

The lower layer of NAND Flash block management, it is called by NAND Flash translation layer, and it will call NAND Flash ECC layer.

#define BLOCK_STATUS_DIRTY   0x08
#define BLOCK_STATUS_FREE   0x0E
#define BLOCK_STATUS_LIVE   0x0C
#define ERASE_DATA   1
#define ERASE_DIRTY   0
#define ERASE_FULL   2

uint32_t nand_flash_management_allocate_block ( struct nand_flash_management managed,
uint16_t  block 
)

Allocate a FREE block of a managed NAND Flash and mark it as LIVE.

Parameters
managedPointer to a nand_flash_management instance.
blockBlock to allocate, in managed area.
Returns
0 if successful; otherwise returns NAND_COMMON_ERROR_WRONGSTATUS if the block is not FREE, or another error code..
uint32_t nand_flash_management_copy_block ( const struct nand_flash_management managed,
uint16_t  source_block,
uint16_t  dest_block 
)

Copy the data from a whole block to another block in NAND Flash.

Both blocks must be LIVE.

Parameters
managedPointer to a nand_flash_management instance.
source_blockSource block number.
dest_blockDestination block number.
Returns
0 if successful; NAND_COMMON_ERROR_WRONGSTATUS if one or more page is not live; otherwise return another error code.
uint32_t nand_flash_management_copy_page ( const struct nand_flash_management managed,
uint16_t  source_block,
uint16_t  source_page,
uint16_t  dest_block,
uint16_t  dest_page 
)

Copy the data & spare area of one page to another page.

The source block can be either LIVE or DIRTY, and the destination block must be LIVE; they must both have the same parity.

Parameters
managedPointer to a nand_flash_management instance.
source_blockSource block number based on managed area.
source_pageNumber of source page inside the source block.
dest_blockDestination block number based on managed area.
dest_pageNumber of destination page inside the dest block.
Returns
0 if successful; NAND_COMMON_ERROR_WRONGSTATUS if one or more page is not live; otherwise return another error code.
uint16_t nand_flash_management_count_blocks ( const struct nand_flash_management managed,
uint8_t  status 
)

Count and return the number of blocks having the given status in a managed NAND Flash.

Parameters
managedPointer to a nand_flash_management instance.
statusDesired block status.
Returns
the number of blocks.
uint32_t nand_flash_management_erase_all ( struct nand_flash_management managed,
uint8_t  level 
)

Erase all blocks in the managed area of NAND Flash.

Parameters
managedPointer to a nand_flash_management instance.
levelErase level.
Returns
the nand_flash_raw_erase_block code.
uint32_t nand_flash_management_erase_block ( struct nand_flash_management managed,
uint16_t  block 
)

Erase a DIRTY block of a managed NAND Flash.

Parameters
managedPointer to a nand_flash_management instance.
blockBlock to erase, in managed area.
Returns
NAND_COMMON_ERROR_WRONGSTATUS or another error code.
uint32_t nand_flash_management_erase_dirty_blocks ( struct nand_flash_management managed)

Erases all the blocks which are currently marked as DIRTY.

Parameters
managedPointer to a nand_flash_management instance.
Returns
0 if successful; otherwise, return the error code.
uint32_t nand_flash_management_find_youngest_block ( const struct nand_flash_management managed,
uint8_t  status,
uint16_t *  block 
)

Look for the youngest block having the desired status among the blocks of a managed NAND Flash.

If a block is found, its index is stored inside the provided variable (if pointer is not 0).

Parameters
managedPointer to a nand_flash_management instance.
blockPointer to the block number variable, based on managed area.
Returns
0 if a block has been found; otherwise return the error code.
uint16_t nand_flash_management_get_managed_blocks ( const struct nand_flash_management managed)

Return the number of available blocks in a managed NAND Flash.

Parameters
managedPointer to a nand_flash_management instance.
Returns
the number of blocks.
uint32_t nand_flash_management_initialize ( struct nand_flash_management managed,
const struct nand_flash_model model,
uint32_t  command_address,
uint32_t  address_address,
uint32_t  data_address,
uint16_t  base_block,
uint16_t  size_in_block 
)

Initialize a nand_flash_management instance.

Scans the device to retrieve or create block status information.

Parameters
managedPointer to a nand_flash_management instance.
modelPointer to the underlying NAND Flash chip model. Can be 0.
command_addressAddress at which commands are sent.
address_addressAddress at which addresses are sent.
data_addressAddress at which data is sent.
base_blockBase physical block address of managed area, managed 0.
size_in_blockNumber of blocks that is managed.
Returns
0 if the initialization is done; or return the error code.
uint32_t nand_flash_management_read_page ( const struct nand_flash_management managed,
uint16_t  block,
uint16_t  page,
void *  data,
void *  spare 
)

Read the data and/or the spare area of a page on a managed NAND Flash.

If the data pointer is not 0, then the block MUST be LIVE.

Parameters
managedPointer to a nand_flash_management instance.
blockNumber of block to read from.
pageNumber of page to read inside given block.
dataData area buffer, can be 0.
spareSpare area buffer, can be 0.
Returns
NAND_COMMON_ERROR_WRONGSTATUS if the block is not LIVE and the data pointer is not null; Otherwise, return another error code.
uint32_t nand_flash_management_release_block ( struct nand_flash_management managed,
uint16_t  block 
)

Release a LIVE block of a NAND Flash and marks it as DIRTY.

Parameters
managedPointer to a nand_flash_management instance.
blockBlock to release, based on managed area.
Returns
0 if successful; otherwise returns NAND_COMMON_ERROR_WRONGSTATUS if the block is not LIVE, or another error code.
uint32_t nand_flash_management_write_page ( const struct nand_flash_management managed,
uint16_t  block,
uint16_t  page,
void *  data,
void *  spare 
)

Writes the data and/or spare area of a LIVE page on a managed NAND Flash.

ECC for the data area and storing it in the spare. If no data buffer is provided, the ECC is read from the existing page spare. If no spare buffer is provided, the spare area is still written with the ECC information calculated on the data buffer.

Parameters
managedPointer to a nand_flash_management instance.
blockNumber of block to read from.
pageNumber of page to read inside given block.
dataData area buffer.
spareSpare area buffer.
Returns
NAND_COMMON_ERROR_WRONGSTATUS if the page is not LIVE; otherwise, return another error code.