Commit 9cf116e7 authored by Benoit Rat's avatar Benoit Rat

usb-loader: Adding NAND support

parent 54f05751
......@@ -320,7 +320,7 @@ void BOARD_ConfigureDdram(unsigned char ddrModel, unsigned char busWidth)
*(pDdr) = 0;
// Step 21: Write the refresh rate into the count field in the Refresh Timer register. The DDR2-SDRAM device requires a
// refresh every 15.625 s or 7.81 s. With a 100MHz frequency, the refresh timer count register must to be set with
// refresh every 15.625 ns or 7.81 ns. With a 100MHz frequency, the refresh timer count register must to be set with
// (15.625 /100 MHz) = 1562 i.e. 0x061A or (7.81 /100MHz) = 781 i.e. 0x030d.
// Set Refresh timer
......@@ -548,6 +548,22 @@ void BOARD_ConfigureSdram(unsigned char busWidth)
//------------------------------------------------------------------------------
void BOARD_ConfigureNandFlash(unsigned char busWidth)
{
AT91C_BASE_MATRIX->MATRIX_EBICSA |= AT91C_EBI_CS3A_SM;
// Configure SMC
AT91C_BASE_SMC->SMC_SETUP3 = 0x00020002;
AT91C_BASE_SMC->SMC_PULSE3 = 0x04040404;
AT91C_BASE_SMC->SMC_CYCLE3 = 0x00070007;
AT91C_BASE_SMC->SMC_CTRL3 = 0x00030003;
if (busWidth == 8) {
AT91C_BASE_SMC->SMC_CTRL3 |= AT91C_SMC_DBW_WIDTH_EIGTH_BITS;
}
else if (busWidth == 16) {
AT91C_BASE_SMC->SMC_CTRL3 |= AT91C_SMC_DBW_WIDTH_SIXTEEN_BITS;
}
}
//------------------------------------------------------------------------------
......
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
//------------------------------------------------------------------------------
/// \page "EccNandFlash"
///
/// !!!Purpose
///
/// EccNandFlash layer is called by SkipBlockNandFlash driver, it will call the bl driver (RawNandFlash)
/// to do write/read operations, and do ECC check to the write/read result, it then will feedback the
/// ecc check result to the upper SkipBlockNandFlash layer driver.
///
/// !!!Usage
///
/// -# EccNandFlash_Initialize is used to initializes an EccNandFlash instance.
/// -# EccNandFlash_WritePage is used to write a Nandflash page with ecc result, the function
/// will calculate ecc for the data that is going to be written, and write data and spare(with
/// calculated ecc) to Nandflash device.
/// -# EccNandFlash_ReadPage is uese to read a Nandflash page with ecc check, the function
/// will read out data and spare first, then it calculates ecc with data and then compare with
/// the readout ecc, and feedback the ecc check result to dl driver.
//------------------------------------------------------------------------------
#ifndef ECCNANDFLASH_H
#define ECCNANDFLASH_H
//------------------------------------------------------------------------------
// Headers
//------------------------------------------------------------------------------
#include "RawNandFlash.h"
#include <board.h>
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
struct EccNandFlash {
struct RawNandFlash raw;
};
//------------------------------------------------------------------------------
// Exported functions
//------------------------------------------------------------------------------
extern unsigned char EccNandFlash_Initialize(
struct EccNandFlash *ecc,
const struct NandFlashModel *model,
unsigned int commandAddress,
unsigned int addressAddress,
unsigned int dataAddress,
const Pin pinChipEnable,
const Pin pinReadyBusy);
extern unsigned char EccNandFlash_ReadPage(
const struct EccNandFlash *ecc,
unsigned short block,
unsigned short page,
void *data,
void *spare);
extern unsigned char EccNandFlash_WritePage(
const struct EccNandFlash *ecc,
unsigned short block,
unsigned short page,
void *data,
void *spare);
extern void EccNandlfash_SetNoECC(void);
extern void EccNandlfash_ClearNoECC(void);
extern unsigned char EccNandlfash_GetNoECC(void);
#endif //#ifndef ECCNANDFLASH_H
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
//------------------------------------------------------------------------------
/// \page "ManagedNandFlash"
///
/// !!!Purpose
///
/// The lower layer of nandflash block management, it is called by MappedNandFlash layer, and
/// it will call EccNandFlash layer.
//------------------------------------------------------------------------------
#ifndef MANAGEDNANDFLASH_H
#define MANAGEDNANDFLASH_H
//------------------------------------------------------------------------------
// Headers
//------------------------------------------------------------------------------
#include "NandCommon.h"
#include "EccNandFlash.h"
//------------------------------------------------------------------------------
// Definitions
//------------------------------------------------------------------------------
#define NandBlockStatus_DEFAULT 0xF
#define NandBlockStatus_FREE 0xE
#define NandBlockStatus_LIVE 0xC
#define NandBlockStatus_DIRTY 0x8
#define NandBlockStatus_BAD 0x0
#define NandEraseDIRTY 0 // Erase dirty blocks only
#define NandEraseDATA 1 // Erase all data, calculate count
#define NandEraseFULL 2 // Erase all, reset erase count
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
struct NandBlockStatus {
unsigned int status:4,
eraseCount:28;
};
struct ManagedNandFlash {
struct EccNandFlash ecc;
struct NandBlockStatus blockStatuses[NandCommon_MAXNUMBLOCKS];
unsigned short baseBlock;
unsigned short sizeInBlocks;
};
//------------------------------------------------------------------------------
// Exported functions
//------------------------------------------------------------------------------
extern unsigned char ManagedNandFlash_Initialize(
struct ManagedNandFlash *managed,
const struct NandFlashModel *model,
unsigned int commandAddress,
unsigned int addressAddress,
unsigned int dataAddress,
const Pin pinChipEnable,
const Pin pinReadyBusy,
unsigned short baseBlock,
unsigned short sizeInBlocks);
extern unsigned char ManagedNandFlash_AllocateBlock(
struct ManagedNandFlash *managed,
unsigned short block);
extern unsigned char ManagedNandFlash_ReleaseBlock(
struct ManagedNandFlash *managed,
unsigned short block);
extern unsigned char ManagedNandFlash_EraseBlock(
struct ManagedNandFlash *managed,
unsigned short block);
extern unsigned char ManagedNandFlash_ReadPage(
const struct ManagedNandFlash *managed,
unsigned short block,
unsigned short page,
void *data,
void *spare);
extern unsigned char ManagedNandFlash_WritePage(
const struct ManagedNandFlash *managed,
unsigned short block,
unsigned short page,
void *data,
void *spare);
extern unsigned char ManagedNandFlash_CopyPage(
const struct ManagedNandFlash *managed,
unsigned short sourceBlock,
unsigned short sourcePage,
unsigned short destBlock,
unsigned short destPage);
extern unsigned char ManagedNandFlash_CopyBlock(
const struct ManagedNandFlash *managed,
unsigned short sourceBlock,
unsigned short destBlock);
extern unsigned char ManagedNandFlash_EraseDirtyBlocks(
struct ManagedNandFlash *managed);
extern unsigned char ManagedNandFlash_FindYoungestBlock(
const struct ManagedNandFlash *managed,
unsigned char status,
unsigned short *block);
extern unsigned short ManagedNandFlash_CountBlocks(
const struct ManagedNandFlash *managed,
unsigned char status);
extern unsigned short ManagedNandFlash_GetDeviceSizeInBlocks(
const struct ManagedNandFlash *managed);
extern unsigned char ManagedNandFlash_EraseAll(
struct ManagedNandFlash *managed,
unsigned char level);
#endif //#ifndef MANAGEDNANDFLASH_H
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
//------------------------------------------------------------------------------
/// \page "MappedNandFlash"
///
/// !!!Purpose
///
/// MappedNandFlash layer will do operations on logical blocks of nandflash, it is called by
/// TranslatedNandFlash layer
//------------------------------------------------------------------------------
#ifndef MAPPEDNANDFLASH_H
#define MAPPEDNANDFLASH_H
//------------------------------------------------------------------------------
// Headers
//------------------------------------------------------------------------------
#include "ManagedNandFlash.h"
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
struct MappedNandFlash {
struct ManagedNandFlash managed;
signed short logicalMapping[NandCommon_MAXNUMBLOCKS];
signed short logicalMappingBlock;
unsigned char mappingModified;
unsigned char reserved;
};
//------------------------------------------------------------------------------
// Exported functions
//------------------------------------------------------------------------------
extern unsigned char MappedNandFlash_Initialize(
struct MappedNandFlash *mapped,
const struct NandFlashModel *model,
unsigned int commandAddress,
unsigned int addressAddress,
unsigned int dataAddress,
const Pin pinChipEnable,
const Pin pinReadyBusy,
unsigned short baseBlock,
unsigned short sizeInBlocks);
extern unsigned char MappedNandFlash_ReadPage(
const struct MappedNandFlash *mapped,
unsigned short block,
unsigned short page,
void *data,
void *spare);
extern unsigned char MappedNandFlash_WritePage(
const struct MappedNandFlash *mapped,
unsigned short block,
unsigned short page,
void *data,
void *spare);
extern unsigned char MappedNandFlash_Map(
struct MappedNandFlash *mapped,
unsigned short logicalBlock,
unsigned short physicalBlock);
extern unsigned char MappedNandFlash_Unmap(
struct MappedNandFlash *mapped,
unsigned short logicalBlock);
extern signed short MappedNandFlash_LogicalToPhysical(
const struct MappedNandFlash *mapped,
unsigned short logicalBlock);
extern signed short MappedNandFlash_PhysicalToLogical(
const struct MappedNandFlash *mapped,
unsigned short physicalBlock);
extern unsigned char MappedNandFlash_SaveLogicalMapping(
struct MappedNandFlash *mapped,
unsigned short physicalBlock);
extern unsigned char MappedNandFlash_EraseAll(
struct MappedNandFlash *mapped,
unsigned char level);
#endif //#ifndef MAPPEDNANDFLASH_H
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
#ifndef NANDCOMMON_H
#define NANDCOMMON_H
//------------------------------------------------------------------------------
// Definitions
//------------------------------------------------------------------------------
#if defined(at91sam3u1) || defined(at91sam3u2) || defined(at91sam7se32)
#define NF_MAXPAGESIZE_SUPPORT_2K
#endif
//------------------------------------------------------------------------------
/// \page "NandFlash Maximum Supported Values"
/// Since no memory allocation is available, limits have been set on various
/// characteristics of a NandFlash chip:
///
/// !Maximums
/// - NandCommon_MAXNUMBLOCKS
/// - NandCommon_MAXNUMPAGESPERBLOCK
/// - NandCommon_MAXPAGESIZE
/// Maximum number of blocks in a device
#define NandCommon_MAXNUMBLOCKS 1024 //2048
/// Maximum number of pages in one block
#define NandCommon_MAXNUMPAGESPERBLOCK 256 //64
/// Maximum size of the data area of one page, in bytes.
#if !defined(NF_MAXPAGESIZE_SUPPORT_2K)
#define NandCommon_MAXPAGEDATASIZE 4096 //2048
#else
#define NandCommon_MAXPAGEDATASIZE 2048
#endif
/// Maximum size of the spare area of one page, in bytes.
#define NandCommon_MAXPAGESPARESIZE 128 //64
/// Maximum number of ecc bytes stored in the spare for one single page.
#define NandCommon_MAXSPAREECCBYTES 48 //24
/// Maximum number of extra free bytes inside the spare area of a page.
#define NandCommon_MAXSPAREEXTRABYTES 78 //38
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// \page "NandFlash Error Codes"
/// NandFlash API methods return either 0 (indicating that there was no error),
/// or one of the following error codes:
///
/// !Codes
/// - NandCommon_ERROR_NOMOREBLOCKS
/// - NandCommon_ERROR_BLOCKNOTMAPPED
/// - NandCommon_ERROR_OUTOFBOUNDS
/// - NandCommon_ERROR_MAPPINGNOTFOUND
/// - NandCommon_ERROR_CANNOTREAD
/// No more blocks can be allocated for a write operation.
#define NandCommon_ERROR_NOMOREBLOCKS 1
/// The desired logical block has no current physical mapping.
#define NandCommon_ERROR_BLOCKNOTMAPPED 2
/// Access if out-of-bounds.
#define NandCommon_ERROR_OUTOFBOUNDS 3
/// There are no block having the desired property.
#define NandCommon_ERROR_NOBLOCKFOUND 4
/// The nandflash device has no logical mapping information on it.
#define NandCommon_ERROR_MAPPINGNOTFOUND 5
/// A read operation cannot be carried out.
#define NandCommon_ERROR_CANNOTREAD 6
/// A write operation cannot be carried out.
#define NandCommon_ERROR_CANNOTWRITE 7
/// NandFlash chip model cannot be recognized.
#define NandCommon_ERROR_UNKNOWNMODEL 8
/// Page data is corrupted according to ECC
#define NandCommon_ERROR_CORRUPTEDDATA 9
/// Block is not in the required status.
#define NandCommon_ERROR_WRONGSTATUS 10
/// Device has no logical mapping stored in it
#define NandCommon_ERROR_NOMAPPING 11
/// The block being accessed is bad and must be replaced
#define NandCommon_ERROR_BADBLOCK 12
/// Failed to perform an erase operation
#define NandCommon_ERROR_CANNOTERASE 13
/// A hardware copyback operation failed.
#define NandCommon_ERROR_CANNOTCOPY 14
/// HW Ecc Not compatible with the Nand Model
#define NandCommon_ERROR_ECC_NOT_COMPATIBLE 15
//------------------------------------------------------------------------------
#endif //#ifndef NANDCOMMON_H
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
//------------------------------------------------------------------------------
/// \unit
/// !Purpose
///
/// Type and methods for manipulating NandFlash models.
///
/// !Usage
///
/// -# Find the model of a NandFlash using its device ID with the
/// NandFlashModel_Find function.
///
/// -# Retrieve parameters of a NandFlash model using the following functions:
/// - NandFlashModel_GetDeviceId
/// - NandFlashModel_GetDeviceSizeInBlocks
/// - NandFlashModel_GetDeviceSizeInPages
/// - NandFlashModel_GetDeviceSizeInBytes
/// - NandFlashModel_GetBlockSizeInPages
/// - NandFlashModel_GetBlockSizeInBytes
/// - NandFlashModel_GetPageDataSize
/// - NandFlashModel_GetPageSpareSize
/// - NandFlashModel_GetDataBusWidth
/// - NandFlashModel_UsesSmallBlocksRead
/// - NandFlashModel_UsesSmallBlocksWrite
//------------------------------------------------------------------------------
#ifndef NANDFLASHMODEL_H
#define NANDFLASHMODEL_H
//------------------------------------------------------------------------------
// Forward declarations
//------------------------------------------------------------------------------
struct NandSpareScheme;
//------------------------------------------------------------------------------
// Definitions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// \page "NandFlashModel options"
/// This page lists the possible options for a NandFlash chip.
///
/// !Options
/// - NandFlashModel_DATABUS8
/// - NandFlashModel_DATABUS16
/// - NandFlashModel_COPYBACK
/// Indicates the Nand uses an 8-bit databus.
#define NandFlashModel_DATABUS8 (0 << 0)
/// Indicates the Nand uses a 16-bit databus.
#define NandFlashModel_DATABUS16 (1 << 0)
/// The Nand supports the copy-back function (internal page-to-page copy).
#define NandFlashModel_COPYBACK (1 << 1)
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// Describes a particular model of NandFlash device.
//------------------------------------------------------------------------------
struct NandFlashModel {
/// Identifier for the device.
unsigned char deviceId;
/// Special options for the NandFlash.
unsigned char options;
/// Size of the data area of a page, in bytes.
unsigned short pageSizeInBytes;
/// Size of the device in MB.
unsigned short deviceSizeInMegaBytes;
/// Size of one block in kilobytes.
unsigned short blockSizeInKBytes;
/// Spare area placement scheme
const struct NandSpareScheme *scheme;
};
//------------------------------------------------------------------------------
// Exported functions
//------------------------------------------------------------------------------
extern unsigned char NandFlashModel_Find(
const struct NandFlashModel *modelList,
unsigned int size,
unsigned int id,
struct NandFlashModel *model);
extern unsigned char NandFlashModel_TranslateAccess(
const struct NandFlashModel *model,
unsigned int address,
unsigned int size,
unsigned short *block,
unsigned short *page,
unsigned short *offset);
extern const struct NandSpareScheme * NandFlashModel_GetScheme(
const struct NandFlashModel *model);
extern unsigned char NandFlashModel_GetDeviceId(
const struct NandFlashModel *model);
extern unsigned short NandFlashModel_GetDeviceSizeInBlocks(
const struct NandFlashModel *model);
extern unsigned int NandFlashModel_GetDeviceSizeInPages(
const struct NandFlashModel *model);
extern unsigned long long NandFlashModel_GetDeviceSizeInBytes(
const struct NandFlashModel *model);
extern unsigned int NandFlashModel_GetDeviceSizeInMBytes(
const struct NandFlashModel *model);
extern unsigned short NandFlashModel_GetBlockSizeInPages(
const struct NandFlashModel *model);
extern unsigned int NandFlashModel_GetBlockSizeInBytes(
const struct NandFlashModel *model);
extern unsigned short NandFlashModel_GetPageDataSize(
const struct NandFlashModel *model);
extern unsigned char NandFlashModel_GetPageSpareSize(
const struct NandFlashModel *model);
extern unsigned char NandFlashModel_GetDataBusWidth(
const struct NandFlashModel *model);
extern unsigned char NandFlashModel_HasSmallBlocks(
const struct NandFlashModel *model);
extern unsigned char NandFlashModel_SupportsCopyBack(
const struct NandFlashModel *model);
#endif //#ifndef NANDFLASHMODEL_H
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
//------------------------------------------------------------------------------
// Headers
//------------------------------------------------------------------------------
#include "NandFlashModelList.h"
#include "NandSpareScheme.h"
//------------------------------------------------------------------------------
// Exported variables
//------------------------------------------------------------------------------
/// List of NandFlash models which can be recognized by the software.
const struct NandFlashModel nandFlashModelList[NandFlashModelList_SIZE] = {
// | ID | Options | Page | Mo | Block |BlkPg |DevBlk
{0x6e, NandFlashModel_DATABUS8, 256, 1, 4, &nandSpareScheme256},
{0x64, NandFlashModel_DATABUS8, 256, 2, 4, &nandSpareScheme256},
{0x6b, NandFlashModel_DATABUS8, 512, 4, 8, &nandSpareScheme512},
{0xe8, NandFlashModel_DATABUS8, 256, 1, 4, &nandSpareScheme256},
{0xec, NandFlashModel_DATABUS8, 256, 1, 4, &nandSpareScheme256},
{0xea, NandFlashModel_DATABUS8, 256, 2, 4, &nandSpareScheme256},
{0xd5, NandFlashModel_DATABUS8, 512, 4, 8, &nandSpareScheme512},
{0xe3, NandFlashModel_DATABUS8, 512, 4, 8, &nandSpareScheme512},
{0xe5, NandFlashModel_DATABUS8, 512, 4, 8, &nandSpareScheme512},
{0xd6, NandFlashModel_DATABUS8, 512, 8, 8, &nandSpareScheme512},
{0x39, NandFlashModel_DATABUS8, 512, 8, 8, &nandSpareScheme512},
{0xe6, NandFlashModel_DATABUS8, 512, 8, 8, &nandSpareScheme512},
{0x49, NandFlashModel_DATABUS16, 512, 8, 8, &nandSpareScheme512},
{0x59, NandFlashModel_DATABUS16, 512, 8, 8, &nandSpareScheme512},
{0x33, NandFlashModel_DATABUS8, 512, 16, 16, &nandSpareScheme512},
{0x73, NandFlashModel_DATABUS8, 512, 16, 16, &nandSpareScheme512},
{0x43, NandFlashModel_DATABUS16, 512, 16, 16, &nandSpareScheme512},
{0x53, NandFlashModel_DATABUS16, 512, 16, 16, &nandSpareScheme512},
{0x35, NandFlashModel_DATABUS8, 512, 32, 16, &nandSpareScheme512},
{0x75, NandFlashModel_DATABUS8, 512, 32, 16, &nandSpareScheme512},
{0x45, NandFlashModel_DATABUS16, 512, 32, 16, &nandSpareScheme512},
{0x55, NandFlashModel_DATABUS16, 512, 32, 16, &nandSpareScheme512},
{0x36, NandFlashModel_DATABUS8, 512, 64, 16, &nandSpareScheme512},
{0x76, NandFlashModel_DATABUS8, 512, 64, 16, &nandSpareScheme512},
{0x46, NandFlashModel_DATABUS16, 512, 64, 16, &nandSpareScheme512},
{0x56, NandFlashModel_DATABUS16, 512, 64, 16, &nandSpareScheme512},
{0x78, NandFlashModel_DATABUS8, 512, 128, 16, &nandSpareScheme512},
{0x39, NandFlashModel_DATABUS8, 512, 128, 16, &nandSpareScheme512},
{0x79, NandFlashModel_DATABUS8, 512, 128, 16, &nandSpareScheme512},
{0x72, NandFlashModel_DATABUS16, 512, 128, 16, &nandSpareScheme512},
{0x49, NandFlashModel_DATABUS16, 512, 128, 16, &nandSpareScheme512},
{0x74, NandFlashModel_DATABUS16, 512, 128, 16, &nandSpareScheme512},
{0x59, NandFlashModel_DATABUS16, 512, 128, 16, &nandSpareScheme512},
{0x71, NandFlashModel_DATABUS8, 512, 256, 16, &nandSpareScheme512},
// Large blocks devices. Parameters must be fetched from the extended I
#define OPTIONS NandFlashModel_COPYBACK
{0xA2, NandFlashModel_DATABUS8 | OPTIONS, 0, 64, 0, &nandSpareScheme2048},
{0xF2, NandFlashModel_DATABUS8 | OPTIONS, 0, 64, 0, &nandSpareScheme2048},
{0xB2, NandFlashModel_DATABUS16 | OPTIONS, 0, 64, 0, &nandSpareScheme2048},
{0xC2, NandFlashModel_DATABUS16 | OPTIONS, 0, 64, 0, &nandSpareScheme2048},
{0xA1, NandFlashModel_DATABUS8 | OPTIONS, 0, 128, 0, &nandSpareScheme2048},
{0xF1, NandFlashModel_DATABUS8 | OPTIONS, 0, 128, 0, &nandSpareScheme2048},
{0xB1, NandFlashModel_DATABUS16 | OPTIONS, 0, 128, 0, &nandSpareScheme2048},
{0xC1, NandFlashModel_DATABUS16 | OPTIONS, 0, 128, 0, &nandSpareScheme2048},
{0xAA, NandFlashModel_DATABUS8 | OPTIONS, 0, 256, 0, &nandSpareScheme2048},
{0xDA, NandFlashModel_DATABUS8 | OPTIONS, 0, 256, 0, &nandSpareScheme2048},
{0xBA, NandFlashModel_DATABUS16 | OPTIONS, 0, 256, 0, &nandSpareScheme2048},
{0xCA, NandFlashModel_DATABUS16 | OPTIONS, 0, 256, 0, &nandSpareScheme2048},
{0xAC, NandFlashModel_DATABUS8 | OPTIONS, 0, 512, 0, &nandSpareScheme2048},
{0xDC, NandFlashModel_DATABUS8 | OPTIONS, 0, 512, 0, &nandSpareScheme2048},
{0xBC, NandFlashModel_DATABUS16 | OPTIONS, 0, 512, 0, &nandSpareScheme2048},
{0xCC, NandFlashModel_DATABUS16 | OPTIONS, 0, 512, 0, &nandSpareScheme2048},
{0xA3, NandFlashModel_DATABUS8 | OPTIONS, 0, 1024, 0, &nandSpareScheme2048},
{0xD3, NandFlashModel_DATABUS8 | OPTIONS, 0, 1024, 0, &nandSpareScheme2048},
{0xB3, NandFlashModel_DATABUS16 | OPTIONS, 0, 1024, 0, &nandSpareScheme2048},
{0xC3, NandFlashModel_DATABUS16 | OPTIONS, 0, 1024, 0, &nandSpareScheme2048},
{0xA5, NandFlashModel_DATABUS8 | OPTIONS, 0, 2048, 0, &nandSpareScheme2048},
{0xD5, NandFlashModel_DATABUS8 | OPTIONS, 0, 2048, 0, &nandSpareScheme2048},
{0xB5, NandFlashModel_DATABUS16 | OPTIONS, 0, 2048, 0, &nandSpareScheme2048},
{0xC5, NandFlashModel_DATABUS16 | OPTIONS, 0, 2048, 0, &nandSpareScheme2048},
};
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
//------------------------------------------------------------------------------
/// \unit
/// !Purpose
///
/// Static array of the various NandFlashModels which are supported.
///
/// !Usage
///
/// -# Uses the NandFlashModel_Find function to look for a particular model in
/// the nandFlashModelList array.
//------------------------------------------------------------------------------
#ifndef NANDFLASHMODELLIST_H
#define NANDFLASHMODELLIST_H
//------------------------------------------------------------------------------
// Headers
//------------------------------------------------------------------------------
#include "NandFlashModel.h"
//------------------------------------------------------------------------------
// Definitions
//------------------------------------------------------------------------------
/// Number of NandFlash models inside the list.
#define NandFlashModelList_SIZE 58
//------------------------------------------------------------------------------
// Exported variables
//------------------------------------------------------------------------------
extern const struct NandFlashModel nandFlashModelList[NandFlashModelList_SIZE];
#endif //#ifndef NANDFLASHMODELLIST_H
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
//------------------------------------------------------------------------------
// Headers
//------------------------------------------------------------------------------
#include "NandSpareScheme.h"
#include <utility/assert.h>
//------------------------------------------------------------------------------
// Exported variables
//------------------------------------------------------------------------------
/// Spare area placement scheme for 256 byte pages.
const struct NandSpareScheme nandSpareScheme256 = {
// Bad block marker is at position #5
5,
// 3 ecc bytes
3,
// Ecc bytes positions
{0, 1, 2},
// 4 extra bytes
4,
// Extra bytes positions
{3, 4, 6, 7}
};
/// Spare area placement scheme for 512 byte pages.
const struct NandSpareScheme nandSpareScheme512 = {
// Bad block marker is at position #5
5,
// 6 ecc bytes
6,
// Ecc bytes positions
{0, 1, 2, 3, 6, 7},
// 8 extra bytes
8,
// Extra bytes positions
{8, 9, 10, 11, 12, 13, 14, 15}
};
/// Spare area placement scheme for 2048 byte pages.
const struct NandSpareScheme nandSpareScheme2048 = {
// Bad block marker is at position #0
0,
// 24 ecc bytes
24,
// Ecc bytes positions
{40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63},
// 38 extra bytes
38,
// Extra bytes positions
{ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39}
};
/// Spare area placement scheme for 4096 byte pages.
const struct NandSpareScheme nandSpareScheme4096 = {
// Bad block marker is at position #0
0,
// 48 ecc bytes
48,
// Ecc bytes positions
{ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
125, 126, 127},
// 78 extra bytes
78,
// Extra bytes positions
{ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
78, 79}
};
//------------------------------------------------------------------------------
// Exported functions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// Reads the bad block marker inside a spare area buffer using the provided
/// scheme.
/// \param scheme Pointer to a NandSpareScheme instance.
/// \param spare Spare area buffer.
/// \param marker Pointer to the variable to store the bad block marker.
//------------------------------------------------------------------------------
void NandSpareScheme_ReadBadBlockMarker(
const struct NandSpareScheme *scheme,
const unsigned char *spare,
unsigned char *marker)
{
*marker = spare[scheme->badBlockMarkerPosition];
}
//------------------------------------------------------------------------------
/// Modifies the bad block marker inside a spare area, using the given scheme.
/// \param scheme Pointer to a NandSpareScheme instance.
/// \param spare Spare area buffer.
/// \param marker Bad block marker to write.
//------------------------------------------------------------------------------
void NandSpareScheme_WriteBadBlockMarker(
const struct NandSpareScheme *scheme,
unsigned char *spare,
unsigned char marker)
{
spare[scheme->badBlockMarkerPosition] = marker;
}
//------------------------------------------------------------------------------
/// Reads ECC information from a spare area using the provided scheme.
/// \param scheme Pointer to a NandSpareScheme instance.
/// \param spare Spare area buffer.
/// \param ecc ECC buffer.
//------------------------------------------------------------------------------
void NandSpareScheme_ReadEcc(
const struct NandSpareScheme *scheme,
const unsigned char *spare,
unsigned char *ecc)
{
unsigned int i;
for (i=0; i < scheme->numEccBytes; i++) {
ecc[i] = spare[scheme->eccBytesPositions[i]];
}
}
//------------------------------------------------------------------------------
/// Writes ECC information in a spare area, using a particular scheme.
/// \param scheme Pointer to a NandSpareScheme instance.
/// \param spare Spare area buffer.
/// \param ecc ECC buffer.
//------------------------------------------------------------------------------
void NandSpareScheme_WriteEcc(
const struct NandSpareScheme *scheme,
unsigned char *spare,
const unsigned char *ecc)
{
unsigned int i;
for (i=0; i < scheme->numEccBytes; i++) {
spare[scheme->eccBytesPositions[i]] = ecc[i];
}
}
//------------------------------------------------------------------------------
/// Reads extra bytes of information from a spare area, using the provided
/// scheme.
/// \param scheme Pointer to a NandSpareScheme instance.
/// \param spare Spare area buffer.
/// \param extra Extra bytes buffer.
/// \param size Number of extra bytes to read.
/// \param offset Index where to read the first extra byte.
//------------------------------------------------------------------------------
void NandSpareScheme_ReadExtra(
const struct NandSpareScheme *scheme,
const unsigned char *spare,
void *extra,
unsigned char size,
unsigned char offset)
{
ASSERT((size + offset) < scheme->numExtraBytes,
"NandSpareScheme_ReadExtra: Too many bytes\n\r");
unsigned int i;
for (i=0; i < size; i++) {
((unsigned char *) extra)[i] = spare[scheme->extraBytesPositions[i+offset]];
}
}
//------------------------------------------------------------------------------
/// Write extra bytes of information inside a spare area, using the provided
/// scheme.
/// \param scheme Pointer to a NandSpareScheme instance.
/// \param spare Spare area buffer.
/// \param extra Extra bytes to write.
/// \param size Number of extra bytes to write.
/// \param offset Index where to write the first extra byte.
//------------------------------------------------------------------------------
void NandSpareScheme_WriteExtra(
const struct NandSpareScheme *scheme,
unsigned char *spare,
const void *extra,
unsigned char size,
unsigned char offset)
{
ASSERT((size + offset) < scheme->numExtraBytes,
"NandSpareScheme_WriteExtra: Too many bytes\n\r");
unsigned int i;
for (i=0; i < size; i++) {
spare[scheme->extraBytesPositions[i+offset]] = ((unsigned char *) extra)[i];
}
}
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
//------------------------------------------------------------------------------
/// \page "NandSpareScheme"
///
/// !!!Purpose
///
/// NandSpareScheme layer is used to do Nandflash device's spare area operations. It is called by
/// upper layer drivers, such as SkipBlockNandFlash layer.
///
/// !!!Usage
///
/// -# NandSpareScheme_WriteBadBlockMarker is used to mark a badblock marker inside a spare
/// area.
/// -# NandSpareScheme_ReadBadBlockMarker is used to readout the marker.
/// -# NandSpareScheme_ReadEcc is used to read out ecc from spare area using the provided
/// spare scheme.
/// -# NandSpareScheme_WriteEcc is used to write ecc to spare area using the provided
/// spare scheme.
/// -# NandSpareScheme_ReadExtra is used to read extra bytes from spare area using the provided
/// spare scheme.
/// -# NandSpareScheme_WriteExtra is used to write extra bytes to spare area using the provided
/// spare scheme.
//------------------------------------------------------------------------------
#ifndef NANDSPARESCHEME_H
#define NANDSPARESCHEME_H
//------------------------------------------------------------------------------
// Headers
//------------------------------------------------------------------------------
#include "NandCommon.h"
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
struct NandSpareScheme {
unsigned char badBlockMarkerPosition;
unsigned char numEccBytes;
unsigned char eccBytesPositions[NandCommon_MAXSPAREECCBYTES];
unsigned char numExtraBytes;
unsigned char extraBytesPositions[NandCommon_MAXSPAREEXTRABYTES];
};
//------------------------------------------------------------------------------
// Exported variables
//------------------------------------------------------------------------------
extern const struct NandSpareScheme nandSpareScheme256;
extern const struct NandSpareScheme nandSpareScheme512;
extern const struct NandSpareScheme nandSpareScheme2048;
extern const struct NandSpareScheme nandSpareScheme4096;
//------------------------------------------------------------------------------
// Exported functions
//------------------------------------------------------------------------------
extern void NandSpareScheme_ReadBadBlockMarker(
const struct NandSpareScheme *scheme,
const unsigned char *spare,
unsigned char *marker);
extern void NandSpareScheme_WriteBadBlockMarker(
const struct NandSpareScheme *scheme,
unsigned char *spare,
unsigned char marker);
extern void NandSpareScheme_ReadEcc(
const struct NandSpareScheme *scheme,
const unsigned char *spare,
unsigned char *ecc);
extern void NandSpareScheme_WriteEcc(
const struct NandSpareScheme *scheme,
unsigned char *spare,
const unsigned char *ecc);
extern void NandSpareScheme_ReadExtra(
const struct NandSpareScheme *scheme,
const unsigned char *spare,
void *extra,
unsigned char size,
unsigned char offset);
extern void NandSpareScheme_WriteExtra(
const struct NandSpareScheme *scheme,
unsigned char *spare,
const void *extra,
unsigned char size,
unsigned char offset);
#endif //#ifndef NANDSPARESCHEME_H
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
//------------------------------------------------------------------------------
/// \page "RawNandflash"
///
/// !!!Purpose
///
/// RawNandflash is a bl Nandflash driver, it directly interacts with hardware's register to
/// operate Nandflash interface, and it is called by upper layer drivers, such as EccNandFlash
///
/// !!!Usage
///
/// -# RawNandFlash_Initialize is used to initializes a RawNandFlash instance based on the given
/// model and physical interface. If no model is provided, then the function tries to autodetect
/// it.
/// -# RawNandFlash_Reset is used to reset a Nandflash device.
/// -# RawNandFlash_ReadId is used to read a Nandflash's id.
/// -# RawNandFlash_EraseBlock is used to erase a certain Nandflash device's block.
/// -# RawNandFlash_ReadPage and RawNandFlash_WritePage is used to do read/write operation.
/// -# RawNandFlash_CopyPage is used to issue copypage command to Nandflash device.
/// -# RawNandFlash_CopyBlock calls RawNandFlash_CopyPage to do a Nandflash block copy.
//------------------------------------------------------------------------------
#ifndef RAWNANDFLASH_H
#define RAWNANDFLASH_H
//------------------------------------------------------------------------------
// Headers
//------------------------------------------------------------------------------
#include "NandFlashModel.h"
#include <pio/pio.h>
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// Describes a physical NandFlash chip connected to the SAM microcontroller.
//------------------------------------------------------------------------------
struct RawNandFlash {
/// Model describing this NandFlash characteristics.
struct NandFlashModel model;
/// Address for sending commands to the NandFlash.
unsigned int commandAddress;
/// Address for sending addresses to the NandFlash
unsigned int addressAddress;
/// Address for sending data to the NandFlash.
unsigned int dataAddress;
/// Pin used to enable the NandFlash chip.
Pin pinChipEnable;
/// Pin used to monitor the ready/busy signal from the NandFlash.
Pin pinReadyBusy;
};
//------------------------------------------------------------------------------
// Exported functions
//------------------------------------------------------------------------------
extern unsigned char RawNandFlash_Initialize(
struct RawNandFlash *raw,
const struct NandFlashModel *model,
unsigned int commandAddress,
unsigned int addressAddress,
unsigned int dataAddress,
const Pin pinChipEnable,
const Pin pinReadyBusy);
extern void RawNandFlash_Reset(const struct RawNandFlash *raw);
extern unsigned int RawNandFlash_ReadId(const struct RawNandFlash *raw);
extern unsigned char RawNandFlash_EraseBlock(
const struct RawNandFlash *raw,
unsigned short block);
extern unsigned char RawNandFlash_ReadPage(
const struct RawNandFlash *raw,
unsigned short block,
unsigned short page,
void *data,
void *spare);
extern unsigned char RawNandFlash_WritePage(
const struct RawNandFlash *raw,
unsigned short block,
unsigned short page,
void *data,
void *spare);
extern unsigned char RawNandFlash_CopyPage(
const struct RawNandFlash *raw,
unsigned short sourceBlock,
unsigned short sourcePage,
unsigned short destBlock,
unsigned short destPage);
extern unsigned char RawNandFlash_CopyBlock(
const struct RawNandFlash *raw,
unsigned short sourceBlock,
unsigned short destBlock);
#if defined(CHIP_NAND_CTRL)
extern void RawNandlfash_SetDma(void);
extern void RawNandlfash_ClearDma(void);
extern unsigned char RawNandlfash_GetDma(void);
#endif
#endif //#ifndef RAWNANDFLASH_H
/* ----------------------------------------------------------------------------
* ATMEL Microcontroller Software Support
* ----------------------------------------------------------------------------
* Copyright (c) 2008, Atmel Corporation
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ----------------------------------------------------------------------------
*/
//------------------------------------------------------------------------------
/// \dir
///
/// !!!Purpose
///
/// This directory contains nandflash drivers
///
/// !!!Description
/// - Nandflash drivers: SkipBlockNandFlash layer, EccNandFlash and NandSpareScheme layer,
/// RawNandflash layer.
/// - Nandflash parameter interface : NandFlashModel.
/// - Supported Nandflash device list : NandFlashModelList.
/// - Nandflash block management drivers : TranslatedNandFlash layer, MappedNandFlash layer,
/// ManagedNandFlash layer.
//------------------------------------------------------------------------------
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment