⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 saftl.c

📁 M-System DOC(Disk on a Chip) Flash芯片的诊断工具, 可以从Flash芯片中获取特定的数据信息, 用于判断芯片当前的状态.
💻 C
📖 第 1 页 / 共 5 页
字号:
/***********************************************************************************/
/*                        M-Systems Confidential                                   */
/*           Copyright (C) M-Systems Flash Disk Pioneers Ltd. 1995-2003            */
/*                         All Rights Reserved                                     */
/***********************************************************************************/
/*                            NOTICE OF M-SYSTEMS OEM                              */
/*                           SOFTWARE LICENSE AGREEMENT                            */
/*                                                                                 */
/*      THE USE OF THIS SOFTWARE IS GOVERNED BY A SEPARATE LICENSE                 */
/*      AGREEMENT BETWEEN THE OEM AND M-SYSTEMS. REFER TO THAT AGREEMENT           */
/*      FOR THE SPECIFIC TERMS AND CONDITIONS OF USE,                              */
/*      OR CONTACT M-SYSTEMS FOR LICENSE ASSISTANCE:                               */
/*      E-MAIL = info@m-sys.com                                                    */
/***********************************************************************************/

/*
 * $Log:   V:/PVCSDB/DiskOnChip/archives/general storage/TrueFFS/src/tl/saftl.c-arc  $
 * 
 *    Rev 1.33   Jan 27 2004 08:13:58   oris
 * Changed comments
 * 
 *    Rev 1.32   Jan 18 2004 02:34:46   oris
 * Removed warings
 * 
 *    Rev 1.31   Jan 14 2004 22:31:38   oris
 * Bug fix - Corrupted sector caused due to power failure or data retention in the first risk zone of the newest unit of a chain, was not handled properly which might cause data loss.
 * Bug fix - Compilation error when ENVIRONMENT_VARS was not defined.
 * Removed all instances of EXB support
 * Removed warnings
 * 
 *    Rev 1.30   Dec 01 2003 18:24:26   oris
 * Removed warnings.
 * 
 *    Rev 1.29   Dec 01 2003 16:07:38   oris
 * Bug fix - In case a partition's quick mount area is located around one of the media header, the media media header will be erased while discarding the quick mount data.
 * 
 *    Rev 1.28   Oct 30 2003 00:51:46   OriS
 * Bug fix - check quick mount routine always returned not valid.
 * 
 *    Rev 1.27   Oct 26 2003 19:14:54   oris
 * Removed warnings
 * 
 *    Rev 1.26   Oct 23 2003 13:56:04   oris
 * Added undocumented support for static files defragmentation using defragment extended function with -2 as required number of sectors.
 * Added undocumented support for stopping the automatic static files wear leveling flSkipStaticFilesWearLeveling.
 * 
 *    Rev 1.25   Oct 20 2003 08:59:40   oris
 * Added single floor programming support.
 * Bug fix - bad printing message for bad customization of static allocation sizes.
 * 
 *    Rev 1.24   Oct 01 2003 12:11:14   OriS
 * Missing FL_ to format routine.
 * 
 *    Rev 1.23   Sep 30 2003 21:06:50   oris
 * Added FL prefix to SECTOR_SIZE and SECTOR_SIZE_BITS
 * Bug fix - Erase count is not longer cast down to a word before it was stored in the quick mount information.
 * Added Programmer name and version to the extended disk info structure.
 * 
 *    Rev 1.22   Sep 21 2003 10:18:38   OriS
 * Bug fix - leave binary partition flag returned an error code in the format routine (patch #2,#3) and none of the 6.1 versions supported it with an SPL partition. 
 * 
 *    Rev 1.21   Sep 03 2003 11:54:50   OriS
 * Bug fix - Improoved P3 power failure immunity
 * 
 *    Rev 1.20   Sep 01 2003 21:51:24   oris
 * - Bug fix - missing casting in quick mount size calculation in the format routine can cause compilers that use 16bit int to mis-calculate the quick mount area.
 * - Bug fix - In case last used sector is odd and is corrupted, the TL skipped the valid sector on the even sector.
 * - Algorithm change - read operation might cause a folding operation, in case it found a corrupted last used sector.
 * - Algorithm change - when allocating a new unit it is erased only if it was not already erased in this session contrary to previous version that erased the unit just to be sure.
 * - Added check in case of writeFault or corrupted sectors in checkVolume routine
 * - Added validity check of previous media header in format routine.
 * - Removed tffsRAMXXX calls.
 * - Added default FLTXT macro for converting text to printable text strings.
 * - Removed warnings
 * - Added debug printing.
 * - changed TLS definition to FL_TLS 
 * 
 *    Rev 1.19   Jun 17 2003 15:38:02   oris
 * Bug fixes in case of power failures.
 * 
 *    Rev 1.18   Jun 16 2003 01:18:42   oris
 * Added check that SSC is smaller then current logical sector offset and current VSO.
 * Added check in findLastUsedSectorFlash routine for valid SSC and VSO + read valid sectors twice and compare + in case either read operation had more then 2 bit errors, will force finding the last used sector again (or folding in case of a write operation).
 * flReadBBT now returns unavailable blocks as bad blocks.
 * Removed some warnings.
 * 
 *    Rev 1.17   Jun 12 2003 21:44:16   oris
 * Changed CLT[XXX] to GetChainLenght macro.
 * 
 *    Rev 1.16   Jun 09 2003 22:21:24   oris
 * Bug fix - Improved power failure by erasing a unit before linking it to a new chain.
 * 
 *    Rev 1.15   May 28 2003 17:19:46   oris
 * Bug fix - Formating of floors did not erase the last unit of the first floor.
 * 
 *    Rev 1.14   May 28 2003 08:33:34   oris
 * Bug fix - Bad quick mount area size calculation (on unit boundary).
 * Bug fix - First quick mount unit field in media header was wrong in case of AM when the last block of a floor (not the last) is also the last block of a partition and it is bad.
 * Bug fix - Change protection routines did not function correctly in case of floors.
 * Removed unmount in case of a used unit of a chain that does not have any valid sectors on it.
 * Spelling changes
 * 
 *    Rev 1.13   May 19 2003 13:41:44   OriS
 * Extended disk info now returned the size of binary partition unit and not just for Disk parittion.
 * 
 *    Rev 1.12   May 18 2003 13:28:06   OriS
 * Added some static prefixes.
 * Improved the affect of the FL_READ_ONLY compilation flag.
 * Changed handleConversionTable to flHandleConversionTable
 * 
 *    Rev 1.11   May 16 2003 00:58:38   OriS
 * Bug fix - leave binary partition when disk partition is protected might cause media header to become corrupted.
 * Changed ASSUMED_SECTORS_PER_UNIT to  FL_ASSUMED_MAX_SECTORS_PER_UNIT
 * 
 *    Rev 1.10   May 12 2003 23:16:56   oris
 * Added dwUsedUnits field to the extended disk information routine structure.
 * 
 *    Rev 1.9   May 12 2003 22:53:42   oris
 * Bug fix - Wrong file was placed in the PVCS for the partial cache bug fix.
 * Added minimal TrueFFS version field in the media header to support future competability.
 * 
 *    Rev 1.8   May 11 2003 21:53:54   oris
 * Bug fix - none full cache media failed in testdisk.
 * 
 *    Rev 1.7   May 11 2003 18:50:22   OriS
 * Removed warnings
 * 
 *    Rev 1.6   May 11 2003 14:06:16   OriS
 * Changed MAX_VOLUME_MBYTES to FL_ASSUMED_MAX_VOLUME_MBYTES
 * Changed ASSUMED_NFTL_UNIT_SIZE to FL_ASSUMED_MIN_UNIT_SIZE
 * 
 *    Rev 1.5   May 11 2003 08:28:32   OriS
 * Improved quick mount customization options.
 * Added support for runtime foldBestChain algorithm switch.
 * Bug fix in read routine when flDataError occurs.
 * Replaced all flAddLongToFarPointer calls with addToFarPointer.T? 
 * Removed wear leveling heuristic to be deterministic.
 * Added support for write quick mount and get quick mount information.
 * Removed FL_LEAVE_BINARY_AREA and FL_LEAVE_SOME_BINARY_ARE. Now using the TL_xxx version.
 * 
 *    Rev 1.4   May 09 2003 00:06:58   OriS
 * Added support for FL_PUTIMAGE , FL_PUTIMAGE_PARALLEL , FL_DIMAGE compilation flags.
 * Bug fix - readSectors in case of flDataError.
 * Bug fix - getting quick mount information from a bad blocks.
 * Support media header on none first good block.
 * Removed fIsQuickMountVailid field from extended disk information routine.
 * Added support for define partition in pre-mount routines
 * Added getQuickMountInfo routine.
 * Removed verify Write after writing media header.
 * 
 *    Rev 1.3   May 06 2003 11:55:36   OriS
 * Changed SAFTL_K_NUMBER_OF_CACHED_UNITS to FL_NUMBER_OF_CACHED_UNITS
 * Bug fix in quick mount inmplementation - accessing bad blocks
 * Bug fix accessing protected area caused dismount of the media.
 * FL_READ_ONLY compilation flag was not properly supported.
 * Changed foldbestchain algorithm under compilation flag
 * Changed TFFSCPY to tffsRAMcpy
 * Changed TFFSCMP to tffsRAMcmp
 * Changed TFFSSET to tffsRAMset
 * 
 *    Rev 1.2   Apr 27 2003 09:04:10   Oris
 * Removed warnings
 * Added dynamic bad block table support.
 * Added some initialization bug fixes.
 * Improved static files wear leveling heuristics.
 * Simplified FL_NO_QUICK_MOUNT_FEATURE compilation flag
 * 
 *    Rev 1.1   Apr 13 2003 20:30:24   OriS
 * Bug fix - bad partition flags were written to media header
 * Bug fix - spl partition binary signature was written to the wrong place.
 * Changed FL_EXTENEDED_DISK_INFO to FL_EXTENDED_DISK_INFO
 * 
 *    Rev 1.0   Apr 09 2003 12:15:54   OriS
 * Initial revision.
 * 
 */

/*************************************************/
/* T r u e F F S   6.0   S o u r c e   F i l e s */
/* --------------------------------------------- */
/*************************************************/

/*****************************************************************************
* File Header                                                                *
* -----------                                                                *
* Name : saftl.c                                                             *
*                                                                            *
* Description : Implementation of SAFTL flash translation layer.             *
*                                                                            *
*****************************************************************************/

/* M-Systems Internal Compilation Flags */   
/* #define _FL_CREATE_LOG_FILE */ /* Dump all read and write data           */
/* #define _FL_ALWAYS_WAIT_FOR_READY */ /* Remove delayed wait for ready support  */

/**************************/
/* List of included files */
/**************************/

#include "saftl.h"

#ifdef CHAINS_DEBUG
#include "saftldbg.c"
#endif /* CHAINS_DEBUG */

#ifdef _FL_CREATE_LOG_FILE
FILE * _FL_MY_OUTPUT;
#define  _FL_MY_FILE_NAME "output1.txt"
#endif /* _FL_CREATE_LOG_FILE */

/*********************/
/* Private variables */
/*********************/

static FLByte saftlBuffers[VOLUMES][FL_SECTOR_SIZE];
static Cnand vols[VOLUMES];

#ifndef FL_MALLOC
static FLWord flSAFTVUT[SOCKETS][(FL_ASSUMED_MAX_VOLUME_MBYTES<<20)/FL_ASSUMED_MIN_UNIT_SIZE];
static FLWord flSAFTLLUT[SOCKETS][(FL_ASSUMED_MAX_VOLUME_MBYTES<<20)/FL_ASSUMED_MIN_UNIT_SIZE];
static FLWord flSAFTLSectorsTableSAFTL[VOLUMES][FL_NUMBER_OF_CACHED_UNITS*(FL_ASSUMED_MAX_SECTORS_PER_UNIT)];
static CNANDCache flSAFTLUnitCache[VOLUMES][FL_NUMBER_OF_CACHED_UNITS];
static FLByte flSAFTLCLT[SOCKETS][(FL_ASSUMED_MAX_VOLUME_MBYTES<<20)/FL_ASSUMED_MIN_UNIT_SIZE];
static FLByte flSAFTLFoldingBuffer[SOCKETS][ASSUMED_FOLDING_BUFFER_SIZE];
static CNANDSectorHeader flSAFTLHeaders[SOCKETS][FL_ASSUMED_MAX_SECTORS_PER_UNIT];
#ifndef _FL_ALWAYS_WAIT_FOR_READY
static FLByte flSAFTLSavedDataBuffer[SOCKETS][ASSUMED_LAST_WRITE_BUFFER_SIZE];
#endif /* _FL_ALWAYS_WAIT_FOR_READY */
#endif /* FL_MALLOC */

/*******************************/
/* Private routine declaration */
/*******************************/

static void dismountSAFTL(Cnand *volPrmPtr);
static FLStatus loadUnitIntoCache(Cnand * volPrmPtr,
                                  CNANDCache FAR1 * cachePtr);
#ifndef FL_READ_ONLY
static FLStatus foldFromNewestUnit(Cnand * volPrmPtr,
                                   CNANDCache FAR1 * cachePtr);
static void setFoldingHeuristic(Cnand * volPrmPtr,
                                CNANDCache FAR1 * cachePtr);
static FLStatus formatUnit(Cnand * volPrmPtr,FLWord wLogicalUnit);
static FLStatus foldBestChain(Cnand * volPrmPtr, FLWord *wUnitNoPtr);
static FLStatus findFreeUnitNoMatterWhat(Cnand * volPrmPtr);
static FLStatus writeMultiSector(Cnand *volPrmPtr,
                                 SectorNo sectorNo,
                                 void FAR1 *fromAddressPtr,
                                 SectorNo sectorCount);
#endif /* FL_READ_ONLY */
static FLBoolean getLastUsedSectorRAM(Cnand  * volPrmPtr, 
                                      FLWord   wVirtualUnit,
                                      FLWord   wLogicalUnit,
                                      FLWord * wOldestUnitPtr);
static FLStatus findLastUsedSectorFlash(Cnand * volPrmPtr,
                                        FLWord wVirtualUnit,
                                        FLWord wLogicalUnit,
                                        FLWord wOldestUnit);
#if ((!defined(_FL_ALWAYS_WAIT_FOR_READY)) && (!defined (FL_READ_ONLY)))
static FLStatus completeLastOperation(Cnand *volPrmPtr);
#endif /* _FL_ALWAYS_WAIT_FOR_READY and FL_READ_ONLY */


/************************************************************************/
/************************************************************************/
/***                                                                  ***/
/***    M i s c e l l a n e o u s   I n t e r n a l   R o u i n te    ***/
/***                                                                  ***/
/************************************************************************/
/************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -