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.
managed | Pointer to a nand_flash_management instance. |
block | Block to allocate, in managed area. |
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.
managed | Pointer to a nand_flash_management instance. |
source_block | Source block number. |
dest_block | Destination block number. |
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.
managed | Pointer to a nand_flash_management instance. |
source_block | Source block number based on managed area. |
source_page | Number of source page inside the source block. |
dest_block | Destination block number based on managed area. |
dest_page | Number of destination page inside the dest block. |
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.
managed | Pointer to a nand_flash_management instance. |
status | Desired block status. |
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.
managed | Pointer to a nand_flash_management instance. |
level | Erase level. |
uint32_t nand_flash_management_erase_block | ( | struct nand_flash_management * | managed, |
uint16_t | block | ||
) |
Erase a DIRTY block of a managed NAND Flash.
managed | Pointer to a nand_flash_management instance. |
block | Block to erase, in managed area. |
uint32_t nand_flash_management_erase_dirty_blocks | ( | struct nand_flash_management * | managed | ) |
Erases all the blocks which are currently marked as DIRTY.
managed | Pointer to a nand_flash_management instance. |
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).
managed | Pointer to a nand_flash_management instance. |
block | Pointer to the block number variable, based on managed area. |
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.
managed | Pointer to a nand_flash_management instance. |
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.
managed | Pointer to a nand_flash_management instance. |
model | Pointer to the underlying NAND Flash chip model. Can be 0. |
command_address | Address at which commands are sent. |
address_address | Address at which addresses are sent. |
data_address | Address at which data is sent. |
base_block | Base physical block address of managed area, managed 0. |
size_in_block | Number of blocks that is managed. |
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.
managed | Pointer to a nand_flash_management instance. |
block | Number of block to read from. |
page | Number of page to read inside given block. |
data | Data area buffer, can be 0. |
spare | Spare area buffer, can be 0. |
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.
managed | Pointer to a nand_flash_management instance. |
block | Block to release, based on managed area. |
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.
managed | Pointer to a nand_flash_management instance. |
block | Number of block to read from. |
page | Number of page to read inside given block. |
data | Data area buffer. |
spare | Spare area buffer. |