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

📄 tffs_api.c

📁 H3 M-system NAND flash driver in Linux OS, M-DOC driver
💻 C
📖 第 1 页 / 共 5 页
字号:
	{
		DBG_PRINT_ERR_PRM(FLZONE_API, (FLTXT("TFFSAbsMountVolume(): flDOCHGetDiskUserAttributes failed with status: 0x%x "), rc));
		return (rc==DOCH_ProtectionFault)? flHWProtection:TFFS_API_RET(rc);
	}
	/*Get some data from disk attributes sector*/
    if (tffscmp(((DOCH_DiskUserAttrWithBinary*)dochVol.intermediateBuf)->bMigrationSignature, 
                    TFFS_API_MIGRATION_SIGNATURE, 
                    sizeof(((DOCH_DiskUserAttrWithBinary*)dochVol.intermediateBuf)->bMigrationSignature)) != 0)
    { 
        DBG_PRINT_ERR(FLZONE_API, "TFFSAbsMountVolume(): Device is not formated with TrueFFS. Either reformat the device or run upgrade utility.\n");
        return flBadFormat;
    }

    partition = FL_GET_FLASH_PARTITION_FROM_HANDLE(ioreq);
	flStatus = dochMountTL(partition, FL_GET_SOCKET_FROM_HANDLE(ioreq));
    if (flStatus == flOK)
    {
        if(dochVol.mountCount[partition] < 0x64)
            dochVol.mountCount[partition]++;
    }
	return flStatus;
}/*TFFSAbsMountVolume*/

static FLStatus TFFSAbsDismountVolume(IOreq* ioreq) 
{
    FLByte partition;
	FLStatus rc;
    partition = FL_GET_FLASH_PARTITION_FROM_HANDLE(ioreq);
    if(dochVol.mountCount[partition] == 0)
    {
		return flNotMounted;
    }
	
	if(dochVol.mountCount[partition] > 0)
    {        
        rc = dochDismountTL(partition);
        if (rc == flOK)
        {
		    dochVol.mountCount[partition]--;
        }
    }
    else
        rc = flNotMounted;
	return rc;
}/*TFFSAbsDismountVolume*/


/*----------------------------------------------------------------------*/
/* Function name   : TFFSCheckVolume*/
/* Description     : */
/* Return type     : static FLStatus */
/* Argument        : IOreq* ioreq*/
/*----------------------------------------------------------------------*/
static FLStatus TFFSCheckVolume(IOreq* ioreq) 
{
    FLStatus flStatus;
    if(dochVol.mountCount[FL_GET_FLASH_PARTITION_FROM_HANDLE(ioreq)] > 0)
        flStatus = flOK;
    else
        flStatus = flNotMounted;
    return flStatus;
}/*TFFSCheckVolume*/

#ifndef FL_READ_ONLY
/*----------------------------------------------------------------------*/
/*			  T F F S D e f r a g m e n t V o l u m e		    		*/
/*                                                                      */
/* Performs a general defragmentation and recycling of non-writable     */
/* Flash areas, to achieve optimal write speed.                         */
/*                                                                      */
/* NOTE: The required number of sectors (in irLength) may be changed    */
/* (from another execution thread) while defragmentation is active. In  */
/* particular, the defragmentation may be cut short after it began by   */
/* modifying the irLength field to 0.                                   */
/*                                                                      */
/* Parameters:                                                          */
/*        irHandle  : Drive number (0, 1, ...)                          */
/*                        bits 7-4 - Partition # (zero based)           */
/*                        bits 3-0 - Socket # (zero based)              */ 
/*        irLength  : Minimum number of sectors to make available for   */
/*                    writes.                                           */
/*                                                                      */
/* Returns:                                                             */
/*        irLength  : Actual number of sectors available for writes     */
/*        FLStatus  : 0 on success, otherwise failed                    */
/*----------------------------------------------------------------------*/
static FLStatus TFFSDefragmentVolume(IOreq* ioreq)
{
	DOCH_Error rc;
	IOreq myIoreq;
	FLSDword request = ioreq->irLength;

	TFFS_API_GET_UNIT_SIZE(myIoreq, ioreq, rc, flStatus);
	/*Return values*/
	/*=============*/
	switch(request)
	{
	case FL_MINIMAL_DEFRAGMENTATION:
	case FL_MAXIMUM_DEFRAGMENTATION:
		ioreq->irLength = dochVol.dwVirtualUnitSizeInSectors;
		return flNotEnoughMemory;

	case FL_STATIC_WEAR_LEVELING_DELAYED:
	case FL_STATIC_WEAR_LEVELING_NOW:
	case FL_STATIC_WEAR_LEVELING_ON:
	case FL_STATIC_WEAR_LEVELING_OFF:
		ioreq->irLength = dochVol.dwVirtualUnitSizeInSectors;
		break;

	default:
		if(request > 0)
			ioreq->irLength = dochVol.dwVirtualUnitSizeInSectors;
		else 
		{
			if(request == 0)
				ioreq->irLength = 0;
			else
				return flBadParameter;
		}
		return flNotEnoughMemory;
	}
	return flOK;
}/*TFFSDefragmentVolume()*/





/*********************************************************/
/* Function name	: tffsFormatSetProtectionAttribs*/
/* Description	    : */
/* Return type		: FLStatus */
/* Argument         : FLByte bProtType*/
/* Argument         : DOCH_PartitionFormatInfoAPI* pPartitionFormatInfoAPI*/
/* Argument         : FLByte * bKey*/
/* Argument         : FLWord wKeyLen*/
/*********************************************************/
static FLStatus tffsFormatSetProtectionAttribs( FLByte bProtType, DOCH_PartitionFormatInfoAPI* pPartitionFormatInfoAPI, 
											    FLByte * pKey, FLWord wKeyLen)
{
	FLBoolean read_protect, write_protect, change_protect, locked;

	read_protect = write_protect = change_protect = locked =FALSE;
	/*Enabled Protections*/
	if( (bProtType & READ_PROTECTED) == READ_PROTECTED)
		read_protect = TRUE;
	if( (bProtType & WRITE_PROTECTED) == WRITE_PROTECTED)
		write_protect = TRUE;
	if( (bProtType & CHANGEABLE_PROTECTION) == CHANGEABLE_PROTECTION)
		change_protect = TRUE;
	if( (bProtType & LOCK_ENABLED) == LOCK_ENABLED)
		locked = TRUE;

	/*Protection requested*/
	if(read_protect || write_protect)
	{
		pPartitionFormatInfoAPI->dwProtectionType = DOCH_PARTITION_PWD_PROTECTED;

		/*Specific protection*/
		if(read_protect)
		{ 
			pPartitionFormatInfoAPI->dwGuestAccessMode = DOCH_PART_ACCESS_MODE_NONE;
		}
		else /*write_protect*/
		{
			pPartitionFormatInfoAPI->dwGuestAccessMode = DOCH_PART_ACCESS_MODE_RO;
		}
	}
	else
	{/*No protection requested or changeable protection only requested */
		pPartitionFormatInfoAPI->dwProtectionType = (change_protect!=FALSE)?DOCH_PARTITION_PWD_PROTECTED:DOCH_PARTITION_NOT_PROTECTED;
		pPartitionFormatInfoAPI->dwUserAccessMode = DOCH_PART_ACCESS_MODE_FULL;
		pPartitionFormatInfoAPI->dwGuestAccessMode = DOCH_PART_ACCESS_MODE_FULL;
	}
	
	/* lock notification */
	pPartitionFormatInfoAPI->dwLockControl = (locked==TRUE) ? DOCH_LOCK_ACTIVE : DOCH_LOCK_NOT_ACTIVE;

	/*Passkey*/
	if(read_protect || write_protect || change_protect)
	{
		tffscpy(pPartitionFormatInfoAPI->bPasskey, pKey, wKeyLen);
	}

	return flOK;
}/*tffsFormatSetProtectionAttribs*/

#ifdef FL_FORMAT_VOLUME
/*----------------------------------------------------------------------*/
/*            T F F S F l a s h  F o r m a t							*/
/*                                                                      */
/* Performs formatting of the DiskOnChip.                               */
/* All existing data is destroyed.                                      */
/*                                                                      */
/* Note : This routine is the format routine for OSAK 5.0 and up.       */
/*                                                                      */
/* Parameters:                                                          */
/*        irHandle : Socket number (0, 1, ...)                          */
/*                   Partition number must be 0                         */
/*        irFlags  :                                                    */
/*           TL_NORMAL_FORMAT          : Normal format                  */
/*           TL_LEAVE_SOME_PARTITIONS  : Leave some of the previously	*/
/*										 existing partitions			*/
/*	         TL_DO_NOT_PERFORM_DOWNLOAD			                		*/
/*        irData   : Address of FormatParams3 structure to use          */
/*                              (defined in format.h)                   */
/*        irLength : If the TL_LEAVE_SOME_PARTITIONS flag is set,		*/
/*                   this field will indicate the number of partitions  */
/*                   to leave.											*/
/*																		*/
/* Returns:                                                             */
/*        FLStatus  : 0 on success, otherwise failed                    */
/*----------------------------------------------------------------------*/
static FLStatus TFFSflashFormat(IOreq* ioreq)
{
	DOCH_Error rc = DOCH_OK;
	FLStatus myStatus;
	IOreq myIoreq;
	FLSNative i=0;
	FLByte partNum=0, numOfBinaryPartitions;
		
#ifdef BDK_ACCESS
	FLByte totalNumOfPartitions;
#endif /*BDK_ACCESS*/

	FormatParams3 FAR1					* FP3 = (FormatParams3 FAR1 *)ioreq->irData;
	BDTLPartitionFormatParams3 FAR2		* bdtlUserParams;

#ifdef BDK_ACCESS
	BinaryPartitionFormatParams3 FAR2	* binUserParams;
	FLSNative	numOfBinaryParToLeave = 0;
#endif /*BDK_ACCESS*/

	FLSNative							  total_num_of_partitions = (FP3->noOfBinaryPartitions + FP3->noOfBDTLPartitions);
	FLSNative	numOfParToLeave = 0;
	FLByte		bOtpPresent, bIplPresent;
	FLWord		lastRemainingPartition, wNumOfOriginalPartitions;

    FLByte* intBuf = dochVol.intermediateBuf;
	DOCH_DiskUserAttrWithBinary* pDiskUserAttrWithBinary = (DOCH_DiskUserAttrWithBinary*)intBuf;
	DOCH_PartitionUserAttrWithBinary* pPartitionUserAttrWithBinary = (DOCH_PartitionUserAttrWithBinary*)intBuf;
	DOCH_PartitionFormatInfoAPI* pPartitionFormatInfoAPI = (DOCH_PartitionFormatInfoAPI*)intBuf;
	DOCH_Socket*  pDev;

#ifdef BDK_ACCESS	
	FLDword dwPartitionTotalSize;
#endif /*BDK_ACCESS*/

	DOCH_get_socket(pDev, FL_GET_SOCKET_FROM_HANDLE(ioreq));
	if( pDev==NULL )
		return flBadParameter;

	/*If binary partitions requested and no BDK support - return error*/
#ifndef BDK_ACCESS
	if(FP3->noOfBinaryPartitions > 0)
	{
		DBG_PRINT_ERR_PRM(FLZONE_API, (FLTXT("TFFSflashFormat(): Binary partitions not supported when BDK_ACCESS Not Defined!\r\n")));
		return flBadParameter;
	}
#endif /*BDK_ACCESS*/

    /*Retrieve disk attributes*/
	tffsset(&myIoreq, 0, sizeof(myIoreq));
    myIoreq.irHandle = FL_GET_SOCKET_FROM_HANDLE(ioreq);
    myIoreq.irData = intBuf;
	rc = flDOCHGetDiskUserAttributes(&myIoreq);
	if(rc != DOCH_OK)
	{
		DBG_PRINT_ERR_PRM(FLZONE_API, (FLTXT("TFFSflashFormat(): flDOCHGetDiskUserAttributes failed with status: 0x%x "), rc));
		return (rc==DOCH_ProtectionFault)? flHWProtection:TFFS_API_RET(rc);
	}

	/* Get some data from disk attributes sector */
	numOfBinaryPartitions = pDiskUserAttrWithBinary->bNumOfBinaryPartitions;
	bIplPresent = pDiskUserAttrWithBinary->bIplPresent;
	bOtpPresent = pDiskUserAttrWithBinary->bOtpPresent;

#ifdef BDK_ACCESS
	totalNumOfPartitions = (FLByte)pDev->wTotalNumOfPartitions;
#endif /*BDK_ACCESS*/

	/* check for corruption during format or wrong format */
		/* wrong signature */
    if( (tffscmp(pDiskUserAttrWithBinary->bMigrationSignature, TFFS_API_MIGRATION_SIGNATURE, 
                   sizeof(pDiskUserAttrWithBinary->bMigrationSignature)) != 0)  
		/* disk attributes not match no. of partitions */		
		|| (pDev->wTotalNumOfPartitions<2 && bIplPresent && bOtpPresent)  
		/* there are enough partitions but IPL or/and OTP indication corrupted */		
		|| (pDev->wTotalNumOfPartitions>2 && (bIplPresent!=1 || bOtpPresent!=1)) )
    { 
        bIplPresent = 0;
        bOtpPresent = 0;
        numOfBinaryPartitions = 0;
    }

#ifdef BDK_ACCESS
	/*Calculate how many binary partition to LEAVE*/
	if(ioreq->irFlags == TL_LEAVE_BINARY_AREA)
	{
		numOfParToLeave = numOfBinaryPartitions;
		numOfBinaryParToLeave = numOfBinaryPartitions;
	}
	else
	{
		if(ioreq->irFlags == TL_LEAVE_SOME_BINARY_AREA)
		{
			numOfParToLeave = ioreq->irLength;
			numOfBinaryParToLeave = TFFSMIN(numOfBinaryPartitions, numOfParToLeave);
		}
		else
		{
			numOfParToLeave = 0;
			numOfBinaryParToLeave = 0;

⌨️ 快捷键说明

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