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

📄 tffs_api.c

📁 电子盘DEMO板程序
💻 C
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************/
/*                                                                            */
/*  Copyright (C), 1995-2006, msystems Ltd. All rights reserved.              */
/*                                                                            */
/*  Redistribution and use in source and binary forms, with or without        */
/*  modification, are permitted provided that the following conditions are    */
/*  met:                                                                      */
/*  1. Redistributions of source code must retain the above copyright notice, */
/*     this list of conditions and the following disclaimer.                  */
/*  2. Redistributions in binary form must reproduce the above copyright      */
/*     notice, this list of conditions and the following disclaimer in the    */
/*     documentation and/or other materials provided with the distribution.   */
/*  3. Neither the name of msystems nor the names of its contributors may be  */
/*     used to endorse or promote products derived from this software without */
/*     specific prior written permission.                                     */
/*                                                                            */
/*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       */
/*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED */
/*  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR             */
/*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT      */
/*  OWNER OR CONTRIBUTORS 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.              */
/*                                                                            */
/******************************************************************************/
/*
 * $Log:   V:/PVCSDB/DiskOnChip/archives/Test for 7.x/src/H3/tffs_api.c-arc  $
 * 
 *    Rev 1.79   Sep 14 2006 09:56:50   yaniv.iarovici
 * Set IPL partition as 'protectable' upon its creation.
 * 
 *    Rev 1.78   Sep 13 2006 10:30:46   yaniv.iarovici
 * Fix compilation warnings
 * 
 *    Rev 1.77   Sep 11 2006 13:45:28   yaniv.iarovici
 * Legal header added
 * 
 *    Rev 1.76   Sep 03 2006 14:45:22   Yaniv.Iarovici
 * 1. Allow calling TFFSGetExtendedDiskInfo() without request for specific partition info.
 * 2. Bug fix: In TFFSChangeProtectionType() - set dwLockControl correctly.
 * 
 *    Rev 1.75   Aug 24 2006 11:40:04   Yaniv.Iarovici
 * Bug fix in TFFSGetExtendedDiskInfo() - wrong return code checked.
 * 
 *    Rev 1.74   Aug 22 2006 13:26:56   Yaniv.Iarovici
 * Fix calculation of 'numOfBinaryParToLeave' when BDK_ACCESS is defined.
 * 
 *    Rev 1.73   Aug 17 2006 15:33:28   Yaniv.Iarovici
 * Remove Joint Protection
 * 
 *    Rev 1.71   Aug 17 2006 15:20:18   Yaniv.Iarovici
 * 1) Encapsulate Joint Protection code under '#ifdef FL_JOINT_PROTECTION' (NOT define by default!)
 * 2) Fix Joint protection support for Read protected partitions.
 * 
 *    Rev 1.69   Aug 16 2006 08:48:26   Yaniv.Iarovici
 * 1) Enable READ+Write protection:
 * 	- tffsFormatSetProtectionAttribs()
 * 	- TFFSChangeProtectionType()
 * 2) TFFSflashFormat():
 * 	- Add /LEAVE support for BDTL partitions as well as BDK
 * 	- Rename 'binParToLeave; to 'numOfParToLeave '
 * 	- Encasulate BDK related code by '#ifdef BDK_ACCESS'
 * 3) Fix description for TFFSChangeProtectionType()
 * 4) Encapsulate BDK related code under '#ifdef BDK_ACCESS'.
 * 5) Change error code returned by 'TFFSChangeProtectionKey()' to flHWProtection.
 * 
 *    Rev 1.67   Aug 09 2006 17:27:40   Polina.Marimont
 * initial for DOC Driver 1.0
 * 
 *    Rev 1.66   Aug 09 2006 17:20:28   Polina.Marimont
 * initial for DOC Driver 1.0, DPD fixes from branch  1.64... applied
 * 
 *    Rev 1.63   Jul 03 2006 22:13:56   polina.marimont
 * 1. bug fix - protection with leave failed to format
 * 2. bug fix - flags returned by identifyProtection on OTW protected partition
 * 
 *    Rev 1.62   Jun 28 2006 11:34:56   Polina.Marimont
 * bug fix - TFFSGetUniqueID() shoudl be enabled / disabled by HW_OTP flag and not by FL_EXTENDED_DISK_INFO
 * 
 *    Rev 1.61   Jun 28 2006 10:36:00   Polina.Marimont
 * bug fix - writeIPL() on non-first data chunk caused to wrong data to be written
 * 
 *    Rev 1.60   Jun 27 2006 15:53:26   Polina.Marimont
 * bug fix flVolumeInfo() API return base address 
 * 
 *    Rev 1.59   Jun 26 2006 11:05:22   Polina.Marimont
 * added include to hib.h file
 * 
 *    Rev 1.58   Jun 22 2006 17:55:38   Polina.Marimont
 * compilation warnings fixes
 * 
 *    Rev 1.57   Jun 22 2006 13:18:40   Polina.Marimont
 * updated comments
 * 
 *    Rev 1.56   Jun 22 2006 09:36:46   Polina.Marimont
 * error codes compatibility for extendedDiskInfo()
 * 
 *    Rev 1.55   Jun 22 2006 09:06:06   Polina.Marimont
 * TFFSRemoveProtectionKey() error code compatibily fix
 * 
 *    Rev 1.54   Jun 21 2006 18:25:42   Polina.Marimont
 * 1. enter/exit DPD function fix
 * 2. change protection to OTW updated
 * 3. identify prrotection updated
 * 
 *    Rev 1.53   Jun 20 2006 12:40:28   Polina.Marimont
 * error codes for insert key and authenticate partition fixed to be compatible to non mDOC h3 devices
 * 
 *    Rev 1.52   Jun 18 2006 13:09:00   Polina.Marimont
 * 1. error codes changed to be compatible to non mDOC H3 devices
 * 2. macros definition usage update
 * 3. AutoDPD and DPD parameters set changed, storage moved to SA SDK
 * 
 *    Rev 1.51   Jun 14 2006 17:59:48   Polina.Marimont
 * 1. structure definitions moved to header file
 * 2. special function added for set IOreq structure parameters
 * 3. printing fixes
 * 4. bug fix - flash lifetime indication fix
 * 5. bug fix - number of volume on unformatted device (returns 1)
 * 6. check BDTL size should not be equal to 0, while formatting
 * 7. unformat - remove all, including OTP and IPL partitions from the device
 * 8. wipe sectors usage restored
 * 9. bdkWriteInit() added check for requested size exceeded subpartition size
 * 10. bug fix - used unit on BDK subparition rounded to the low boundary
 * 11. When EDGE interrupt configured - print warning and configure to LEVEL interrupt.
 * 
 *    Rev 1.50   May 31 2006 15:41:44   polina.marimont
 * TrueFFS 7.1.0 EQA16
 * 
 *    Rev 1.49   May 28 2006 14:50:30   polina.marimont
 * fix for IDENTIFY DEVICE
 * 
 *    Rev 1.48   May 28 2006 13:03:10   polina.marimont
 * update for IDENTIFY DEVICE change
 * 
 *    Rev 1.47   May 24 2006 14:57:26   polina.marimont
 * bugfix - erase BDK subpartition always erases first unit of subpartition 0
 * 
 *    Rev 1.46   May 24 2006 08:17:06   polina.marimont
 * dochVol.intermediateBuf - free added to tffsApiExit() function
 * 
 *    Rev 1.45   May 24 2006 08:13:30   polina.marimont
 * TFFSbdkPartitionInfo() - wrong handle received from ioreq.
 * 
 *    Rev 1.44   May 21 2006 18:06:44   polina.marimont
 * compilation errors fix, when CHECK_BEFORE_EVERY_COMMAND defined
 * 
 *    Rev 1.43   May 18 2006 14:29:56   polina.marimont
 * TFFSBdkPartitionInfo() fixed to return flBadDriveHandle, when wrong number of partition specified, using migration variable
 * 
 *    Rev 1.42   May 18 2006 09:47:06   polina.marimont
 * 1. IOCTL fixed
 * 2. used size set back to 0
 * 
 *    Rev 1.41   May 17 2006 15:42:28   polina.marimont
 * 1. Error codes are fixed up to Legacy + SA package
 * 2. LOCK and CHANGABLE protection support 
 * 3. Format fixed - common functions used to add IPL and OTP partitions, also to set partition protection attributes
 * 4. PassThrough implemented
 * 5. bug fixes
 * 
 *    Rev 1.40   Apr 11 2006 13:21:34   tal.heller
 * enable EraseBD API.
 * Bug Fix - Last Partition size wasn't initialized.
 * Fix CC compilation 
 * adapt SecureDelete ioreq implementation to DOCH
 * Bug Fix - StickLock API
 * Comments syntax errors.
 * 
 *    Rev 1.39   Mar 29 2006 16:39:50   DoronC
 * Bug fix - compilation warnings ove various compilers.
 * 
 *    Rev 1.38   Mar 27 2006 16:21:58   DoronC
 * Add DMA support.
 * 
 *    Rev 1.37   Mar 22 2006 17:35:46   DoronC
 * Bug fix - add signature to disk attributes in order to use only 
 * format made by TrueFFS 7.1 and not by host SDK.
 * Other format will force reformatting of the media.
 * 
 *    Rev 1.36   Mar 20 2006 17:21:58   DoronC
 * Bug fix - read IPL using buffers failed.
 * 
 *    Rev 1.35   Mar 20 2006 10:41:16   DoronC
 * Bug fix - protection change was not working.
 * 
 *    Rev 1.34   Mar 15 2006 16:17:54   DoronC
 * Bug fix - wrong flag was checked when reading IPL.
 * 
 *    Rev 1.33   Mar 15 2006 15:58:04   DoronC
 * Bug fix - change protection key caused an exception.
 * 
 *    Rev 1.32   Mar 15 2006 14:14:46   DoronC
 * Bug fix - formating protected partition with no active protection failed.
 * Bug fix - IPL flags were not checked.
 * 
 *    Rev 1.31   Mar 15 2006 11:28:16   DoronC
 * Bug fix - IPL write was not working properly.
 * Bug fix - BDK used size was faulty.
 * 
 *    Rev 1.30   Mar 14 2006 09:53:52   DoronC
 * Bug fix - DOCFlash win field was not initialized by the init routine
 *  causing exception on some conditions.
 * 
 *    Rev 1.29   Mar 06 2006 08:40:52   DoronC
 * Bug fix - protection identify was reported wrong.
 * 
 *    Rev 1.28   Mar 05 2006 15:52:24   DoronC
 * Protection structure of H3 changed to contain dwords instead
 *  of words.
 * 
 *    Rev 1.27   Mar 02 2006 12:02:30   DoronC
 * Bug fix - mount was checked for wrong number of partitions.
 * 
 *    Rev 1.26   Mar 02 2006 08:30:26   DoronC
 * Host SDK API changed from IOreq2 to IOreq.
 * 
 *    Rev 1.25   Feb 16 2006 11:32:38   DoronC
 * Store binary partition flags in the attributes and return then 
 * when requested by extendedInfo for computability with legacy 
 * devices.
 * 
 *    Rev 1.24   Feb 16 2006 10:02:40   DoronC
 * Bug fix - Compilation warnings removed.
 * Bug fix - Combining DPS between BDK and BDTL was not 
 * working properly during format.
 * Bug fix - change protection key&type of combined DPS was not 
 * working.
 * 
 *    Rev 1.23   Feb 14 2006 10:50:02   DoronC
 * Remove large variables from stack. use one global buffer for 
 * all large buffers needs.
 */


#include "flsystem.h"
#include "flcustom.h"
#include "defs.h"
#include "flbase.h"
#include "flstdcmp.h"

#include "flsystyp.h"
#include "flchkdef.h"
#include "blockdev.h"
#include "_docsys.h"

#include "hib.h"
#include "doch_ata.h"
#include "doch_api.h"
#include "bdkemul.h"
#include "tffs_api.h"
#include "doch_func.h"
#include "dochtl.h"


#define MAX_MOUNT_COUNT	100	/*100 Times...*/
#define DOCH_NUM_OF_PLANES		1
#define DOCH_NUM_OF_BANKS		1
#define DOCH_SECTORS_PER_PAGE	4
#define DOCH_SHARED_SECTORS		32

#define DOCH_CAPACITY_128MB		0x40000		/*In Sectors*/
#define DOCH_CAPACITY_256MB		0x80000		/*In Sectors*/
#define DOCH_CAPACITY_512MB		0x100000	/*In Sectors*/
#define DOCH_CAPACITY_1GB		0x200000	/*In Sectors*/
#define DOCH_CAPACITY_2GB		0x400000	/*In Sectors*/
#define DOCH_CAPACITY_4GB		0x800000	/*In Sectors*/
#define DOCH_CAPACITY_8GB		0x1000000	/*In Sectors*/

#define DOCH_UNIT_SIZE_256KB	0x40000		/*In Bytes*/
#define DOCH_UNIT_SIZE_512KB	0x80000		/*In Bytes*/
#define DOCH_UNIT_SIZE_1MB		0x100000	/*In Bytes*/
#define DOCH_UNIT_SIZE_2MB		0x200000	/*In Bytes*/
#define DOCH_UNIT_SIZE_4MB		0x400000	/*In Bytes*/

#define createIrHandle(socket, partition) ((socket) + ((partition) << 4));


/********************/
/*	Externs         */
/********************/

#ifdef __cplusplus
extern "C" {
#endif
	
extern FLDword gIsDMAEnabled;				/*DMA is Enabled/Disabled*/
extern DOCH_DpdSettings gDpdSettings;

#ifdef CHECK_POWER_ON_EVERY_COMMAND
extern FLBoolean gDeviceTurnedOff;
#endif /*CHECK_POWER_ON_EVERY_COMMAND*/

#ifdef __cplusplus
}
#endif

/********************/
/*	Global Vars		*/
/********************/

DocHVolume dochVol;
FLBoolean dochBdCallWasCalled = FALSE;
FLBoolean dochDpdInitialized = FALSE;

#ifdef CHECK_POWER_ON_EVERY_COMMAND
#define TFFS_API_RET(rc)((rc==DOCH_DeviceTurnedOff) ? flSuspendModeDetected : flGeneralFailure)
#else /*CHECK_POWER_ON_EVERY_COMMAND*/

⌨️ 快捷键说明

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