📄 docbdk.c
字号:
/***********************************************************************************/
/* 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/misc/docbdk.c-arc $
*
* Rev 1.19 Jan 27 2004 08:14:04 oris
* Changed comments
*
* Rev 1.18 Jan 15 2004 01:45:06 oris
* Removed bad debug print
*
* Rev 1.17 Jan 14 2004 22:29:06 oris
* Replaced old (5.x) Trueffs variable types
*
* Rev 1.16 Dec 09 2003 18:46:40 oris
* Fixed Arm compiler error
*
* Rev 1.15 Dec 04 2003 12:31:40 oris
* Bug fix - Binary partition update of partial sectors might not flush the last partial sector to the flash.
*
* Rev 1.14 Sep 30 2003 17:56:34 oris
* Added FL prefix to SECTOR_SIZE and SECTOR_SIZE_BITS
*
* Rev 1.13 Sep 21 2003 09:30:46 OriS
* Bug fix - OREN devices SPL partition did not work, because it used a halved unit size.
*
* Rev 1.12 Sep 01 2003 19:09:34 oris
* - Removed warnings
* - Removed tffsRAMXXX calls.
* - Replaced BLOCK macro with definition with BDK_PAGE_SIZE so that buffer size will be aligned with flash page size.
* - Changed debug print with _PRM (parameters) to use FLTXT(text) macro for easier customization of print macro's with parameters
*
* Rev 1.11 Jun 01 2003 17:03:14 oris
* Bug fix in BDK mode - caused exception if bdkFindDiskOnChip was not called before any other API call.
*
* Rev 1.10 May 22 2003 06:52:06 oris
* Bug fix - real used size was incorrect for BDK package
*
* Rev 1.9 May 19 2003 13:08:32 OriS
* Bug fix - SPL partition caused the unit size of other partition to become smaller.
*
* Rev 1.8 May 18 2003 15:32:20 OriS
* Fixed spaces
*
* Rev 1.7 May 18 2003 13:28:46 OriS
* Bug fix - Wrong status returned when trying to change an unchangeable protected area.
* Added some static prefixes.
*
* Rev 1.6 May 16 2003 00:56:38 OriS
* Bug fix - prevent writing across unit boundary
*
* Rev 1.5 May 12 2003 23:45:24 oris
* Fixed debug print for BDK mode
*
* Rev 1.4 May 11 2003 11:10:04 OriS
* Removed call to doc2exb.h
* Changed REMOVE_XXX to BDK_REMOVE_XXX
*
* Rev 1.3 May 06 2003 11:52:48 OriS
* Changed TFFSCPY to tffsRAMcpy
* Changed TFFSCMP to tffsRAMcmp
* Changed TFFSSET to tffsRAMset
* Changed NO_BDK_PARTIAL_PAGE_ACCESS to FL_NO_BDK_PARTIAL_PAGE_ACCESS
* Bug fixes for BDK mode
*
* Rev 1.2 Apr 27 2003 14:13:38 Oris
* Added support for tffsxxx routines.
*
* Rev 1.1 Apr 27 2003 09:01:10 Oris
* Changed debug messages to inform of media header search.
* Prevented mounting of a binary partition with advanced matching while NO_READ_ BBT_CODE is defined.
* Compilation errors for BDK module.
*
* Rev 1.0 Apr 09 2003 12:15:56 OriS
* Initial revision.
*
*/
/************************************************/
/* B i n a r y D e v e l o p m e n t K i t */
/* ------------------------------------------- */
/************************************************/
/*****************************************************************************
* File Header *
* ----------- *
* Name : docbdk.c *
* *
* Description : This file contains the binary partition handling routines. *
* *
* Note : The file has 2 interfaces each under its own compilation flag: *
* *
* BDK package - Standalone package that exports routines for binary *
* partitions handling(MTD_STANDALONE compilation flag). *
* SDK module - Separated module of the SDK package that exports a *
* common entry point to the same routines. (BDK_ACCESS *
* compilation flag). *
* *
* Warning : Do not use this file with the BDK_ACCESS compilation flag unless *
* you own the full SDK package. *
*****************************************************************************/
#include "docbdk.h"
#ifndef MTD_STANDALONE
#include "blockdev.h"
#endif /* MTD_STANDALONE */
#ifdef BDK_ACCESS
/*********************** Global Variables Start******************************/
/* Conversion table from SDK handles to binary partition handles */
static FLByte flHandleTable[SOCKETS][MAX_BINARY_PARTITIONS_PER_DRIVE];
static FLByte flNoOfPartitions = 0; /* number of mounted binary partition */
static FLByte flPartitionNo = 0; /* The current partition number */
static FLByte flSocketNo = 0; /* The current socket number */
BDKVol flBdkVols[BINARY_PARTITIONS]; /* Binary partitions records */
BDKVol* flBdkVol; /* Pointer to current binary partition */
#ifdef MTD_STANDALONE
FLBoolean flInitStatus = FALSE; /* Global initialization indicator */
#endif /* MTD_STANDALONE */
/*********************** Internal Function Protoype *************************/
static FLStatus bdkMount (void);
static FLStatus getBootAreaInfo (FLWord startUnit , FLByte FAR2* signPtr);
/****************************** Actual Code *********************************/
/*--------------------------------------------------------------------------*
* b d k I n i t
*
* Initialize all binary partition global variables
*
* Note : This function is called automaticly by bdkFindDiskOnChip.
*
* Parameters: None
*
* global variable output:
* flBdkVols - initialized array of binary partitions records
* flBdkVol - current binary partition record set to the first
*
* Return: Nothing
*
* Routine for both SDK and the BDK stand alone package.
*--------------------------------------------------------------------------*/
void bdkInit(void)
{
FLByte bIndex;
DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkInit() Entered.\r\n");
/* initialize binary partitions records with defaultive values */
tffsset(flBdkVols,0,sizeof(flBdkVols));
tffsset(flBdkVols->signBuffer,0xff,sizeof(flBdkVols->signBuffer));
tffsset(flHandleTable,BDK_INVALID_VOLUME_HANDLE,sizeof(flHandleTable));
for (flBdkVol=flBdkVols,bIndex=0;bIndex<BINARY_PARTITIONS;flBdkVol++,bIndex++)
{
flBdkVol->bdkGlobalStatus = BDK_S_INIT;
#ifndef FL_READ_ONLY
flBdkVol->updateImageFlag = BDK_COMPLETE_IMAGE_UPDATE;
#endif /* FL_READ_ONLY */
}
/* Initialize binary handles conversion table with invalid values */
flNoOfPartitions = 0;
#ifdef MTD_STANDALONE
noOfMTDs = 0;
noOfSockets = 0;
flPartitionNo = 0;
flSocketNo = 0;
flInitStatus = TRUE;
flBdkVol = flBdkVols;
tffsset(flFlashOf(0),0,sizeof(FLFlash));
#endif /* MTD_STANDALONE */
DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkInit() Exit.\r\n");
}
/*--------------------------------------------------------------------------*
* g e t B o o t A r e a I n f o
*
* Mount the binary sub partitions by reading the signature area of each
* unit of the entire partition.
*
* Note : Assume that the DiskOnChip was already found (bdkFoundDiskOnChip).
*
* Parameters :
* wStartUnit : unit number in the binary sub partition.
* signPtr : signature of the binary sub partition.
*
* global variable input :
* flBdkVol - current binary partition record
* bdkGlobalStatus - partition predsent status.
* flBdkVol->flash - pointer to FLFlash structure.
* flBdkVol->bdkGlobalStatus - status of the current partition
* (already initialize ot not)
* flBdkVol->signBuffer - Previously used signatur buffer.
* flBdkVol->bdkSavedStartUnit - Previously used start unit input.
*
*
* global variable output :
* flBdkVol->bdkGlobalStatus - Set BDK_S_INFO_FOUND flag.
* flBdkVol->bdkSavedStartUnit - Given start unit input.
* flBdkVol->signBuffer - Update signatur buffer.
* flBdkVol->bootImageSize - Update the partition size
* flBdkVol->realBootImageSize - Update the used partition size.
* flBdkVol->startImageBlock - Update the first image block of the sub-partition.
* flBdkVol->endImageBlock - Update the last image block in the sub-partition.
*
* Use functions:
* bdkMount : Mount the binary sub-partition (if needed).
* flash->flashRead : Read data from flash.
*
* Return :
* flOK - success
* flNoSpaceInVolume - there are 0 units marked with this signature
* other Non-zero value- error returned from called functions.
*
* Routine for both SDK and the BDK stand alone package.
*-------------------------------------------------------------------*/
static FLStatus getBootAreaInfo( FLWord wStartUnit , FLByte FAR2* signPtr )
{
FLByte bTmpSignPtr[SIGNATURE_LEN];
FLFlash * flashPtr;
FLWord wIBlock;
FLWord wNumBlock;
FLByte bFloorNo;
FLStatus status;
DBG_PRINT_FLOW(FLZONE_BDK,"Flow: getBootAreaInfo() Entered.\r\n");
/* set flBdkVol pointer to the proper binary partition */
checkStatus(bdkMount());
DBG_PRINT_FLOW(FLZONE_BDK,"Flow: getBootAreaInfo() - BDK mount succeed.\r\n");
/* Check if this sub-partition was already analized */
if ((!(flBdkVol->bdkGlobalStatus & BDK_S_INFO_FOUND)) ||
(tffscmp((void FAR1 *)(flBdkVol->signBuffer),
(void FAR1 *)signPtr,BDK_SIGNATURE_NAME) != 0) ||
(wStartUnit != flBdkVol->bdkSavedStartUnit))
{
/************************************************************************/
/* Find the boundries and number of the units marked with the signature */
/************************************************************************/
DBG_PRINT_FLOW(FLZONE_BDK,"Flow: searching for signtured blocks.\r\n");
/* The partition needs to be rescaned - save signature and start unit */
tffscpy((void FAR1 *)(flBdkVol->signBuffer),(void FAR1 *)signPtr,
BDK_SIGNATURE_NAME);
/* Prepare for scanning the partition */
flBdkVol->bdkSavedStartUnit = wStartUnit;
flBdkVol->bootImageSize = 0L;
flBdkVol->realBootImageSize = 0L;
flBdkVol->startImageBlock = 0L;
flashPtr = flBdkVol->flash;
/* Find the boundries and number of the units marked with the signature */
for (wNumBlock = 0 , wIBlock = flBdkVol->startPartitionBlock;;wIBlock++)
{
bFloorNo = (FLByte)(wIBlock / flBdkVol->blockPerFloor);
if (wIBlock < flBdkVol->firstUsableBlock[bFloorNo])
wIBlock = flBdkVol->firstUsableBlock[bFloorNo];
if (wIBlock > flBdkVol->endPartitionBlock)
break;
/* check for unit signature */
DBG_PRINT_FLOW(FLZONE_BDK,"Flow: getBootAreaInfo() - Reading unit signature...\r\n");
/* check for unit signatured blocks */
flashPtr->args.noOfSectors = 1;
flashPtr->args.startSector = (FLDword)wIBlock << flBdkVol->sectorsInUnitBits;
flashPtr->args.extraBuf = (FLByte *)bTmpSignPtr;
flashPtr->args.opFlags = MTD_EXTRA | flBdkVol->MTDFlags ;
status = flashPtr->flashRead(flashPtr);
switch(status)
{
case flOK:
if(tffscmp( (void FAR1 *)signPtr ,
(void FAR1 *)bTmpSignPtr,
BDK_SIGNATURE_NAME ) == 0 )
{
/* Current block belongs to current sub-partition - update globals */
if( wNumBlock == wStartUnit )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -