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

📄 tffs_api.c

📁 电子盘DEMO板程序
💻 C
📖 第 1 页 / 共 5 页
字号:
			myIoreq.irHandle = FL_GET_SOCKET_FROM_HANDLE(ioreq) + (i << 4);
			rc = flDOCHSetParitionUserAttributes(&myIoreq);
			if( rc!=DOCH_OK )
			{
				return (rc==DOCH_ProtectionFault)? flHWProtection:TFFS_API_RET(rc);
			}
		}
	}

	/*Set numOfBinaryPartitions*/
#ifdef BDK_ACCESS
	numOfBinaryPartitions = numOfBinaryParToLeave;
#else /*BDK_ACCESS*/
	numOfBinaryPartitions = 0;
#endif /*BDK_ACCESS*/

	/*Set programmer name, programmer version and TFFS version*/
	tffsset(intBuf, 0, DOCH_SECTOR_SIZE);
 	pDiskUserAttrWithBinary->bNumOfBinaryPartitions = numOfBinaryPartitions;
    pDiskUserAttrWithBinary->bIplPresent = bIplPresent;
    pDiskUserAttrWithBinary->bOtpPresent = bOtpPresent;
	tffscpy(&pDiskUserAttrWithBinary->bProgrammerName, FL_PROGRAMMER_NAME, 4);
	tffscpy(&pDiskUserAttrWithBinary->bProgrammerVersion, FL_PROGRAMMER_VERSION, 4);
	tffscpy(&pDiskUserAttrWithBinary->bTFFSVersion, DochSDKVersion, 4);
    tffscpy(pDiskUserAttrWithBinary->bMigrationSignature, TFFS_API_MIGRATION_SIGNATURE, 
                        sizeof(pDiskUserAttrWithBinary->bMigrationSignature));
	tffsset(&myIoreq, 0, sizeof(myIoreq));
    myIoreq.irHandle = FL_GET_SOCKET_FROM_HANDLE(ioreq);
	myIoreq.irData = intBuf;
	rc = flDOCHSetDiskUserAttributes(&myIoreq);
	if(rc != DOCH_OK)
	{
		DBG_PRINT_ERR_PRM(FLZONE_API, (FLTXT("TFFSflashFormat(): flDOCHSetDiskUserAttributes failed with status: 0x%x "), rc));
		return (rc==DOCH_ProtectionFault)? flHWProtection:TFFS_API_RET(rc);
	}
    dochVol.numOfBinaryPartitions = numOfBinaryPartitions;

    if (bOtpPresent == 0)
        total_num_of_partitions++;
    if (bIplPresent == 0)
        total_num_of_partitions++;

	if( (wNumOfOriginalPartitions > 2) ||/* more, than IPL and OTP present */
		(bIplPresent==0 && bOtpPresent == 0 && numOfBinaryPartitions == 0) )/* or not 7.1.x format */
	{
		/*Delete partitions not marked to "leave" (if such exists)*/
		tffsAPISetIoreq( &myIoreq, FL_GET_SOCKET_FROM_HANDLE(ioreq), 0,0,0,0xFF,
			numOfParToLeave + bIplPresent + bOtpPresent);
		rc = flDOCHDeletePartitions(&myIoreq);
		if(rc != DOCH_OK)
		{
			DBG_PRINT_ERR_PRM(FLZONE_API, (FLTXT("TFFSflashFormat(): flDOCHDeletePartitions failed with status: 0x%x "), rc));
			return (rc==DOCH_ProtectionFault)? flHWProtection:TFFS_API_RET(rc);
		}
	}

	/*Set IPL partition*/
	if(bIplPresent == 0)
	{
		/* add IPL partition, update it's attributes and disk attributes */
		checkStatus( tffsApiAddOtpIPL(TRUE, &myIoreq, ioreq) );
		memset (intBuf, 0xff, DOCH_SECTOR_SIZE);
		for (i = 0; i < TFFS_API_8K_NORMAL_IPL_SIZE ; i++)
		{
			tffsAPISetIoreq( &myIoreq, FL_GET_SOCKET_FROM_HANDLE(ioreq), 
				(DOCH_IPL_MODE_8KB_WINDOW|DOCH_IPL_MODE_ADDRESS_SHIFT_IN_AFFECT),
				0, dochVol.intermediateBuf, 1, TFFS_API_8K_NORMAL_IPL_SIZE);
			if (i == 0)
				myIoreq.irFlags |= DOCH_IPL_WRITE_FIRST_CHUNK;
			rc = flDOCHWriteIPL(&myIoreq);
			if (rc != DOCH_OK)
			{
				DBG_PRINT_ERR(FLZONE_API, "TFFSflashFormat(): Failed writing default IPL. status: ");
				DBG_PRINT_ERR_PRM(FLZONE_API, (FLTXT("0x%x \n"), rc));
				TFFS_API_RET_PART_FLSTATUS(rc,flWriteFault);
			}
		}
		dochVol.iplExists = 1;
		bIplPresent = 1;
	}/* IPL should be added */

	/*Set OTP partition*/
	if(bOtpPresent == 0)
	{
		checkStatus( tffsApiAddOtpIPL(FALSE, &myIoreq, ioreq) );
		dochVol.otpExists = 1; 
		bOtpPresent = 1;
	}/*OTP partition should be added */

    binUserParams = FP3->binaryPartitionInfo;
    partNum = bOtpPresent + bIplPresent + numOfParToLeave;

#ifdef BDK_ACCESS
	/*Perform for every binary partition*/
	/*----------------------------------*/
	for(i=0; i< FP3->noOfBinaryPartitions; i++)
	{  
		/*	Fill DOCH_PartitionFormatInfoAPI structure from FormatParams3 structure */
		/*==========================================================================*/
		tffsset(intBuf, 0, sizeof(DOCH_PartitionFormatInfoAPI));

		/* standard migration format params */
		TFFS_API_SET_MIG_STD_PART_PRMS(pPartitionFormatInfoAPI, binUserParams->protectionType);

		/* protection features */
		checkStatus( tffsFormatSetProtectionAttribs(binUserParams->protectionType, pPartitionFormatInfoAPI, 
			binUserParams->protectionKey, sizeof(binUserParams->protectionKey)) );


		/*Partition size (must be FL_LENGTH_IN_BYTES)*/
		pPartitionFormatInfoAPI->nPartitionSize = (binUserParams->length & 0x1FF) ? 
              ((binUserParams->length)>>DOCH_SECTOR_SIZE_BITS)+1 : ((binUserParams->length)>>DOCH_SECTOR_SIZE_BITS);

		/*Round partition size to Unit Size*/
		pPartitionFormatInfoAPI->nPartitionSize = 
            (pPartitionFormatInfoAPI->nPartitionSize+dochVol.dwVirtualUnitSizeInSectors-1) & (~(dochVol.dwVirtualUnitSizeInSectors-1));

		if( pPartitionFormatInfoAPI->nPartitionSize == 0 )
		{
			DBG_PRINT_ERR(FLZONE_API, "TFFSflashFormat(): cannot add zero length binary partition ");
			return flBadParameter;
		}

		/*Add partition*/
		tffsAPISetIoreq(&myIoreq, FL_GET_SOCKET_FROM_HANDLE(ioreq), 0,0, intBuf,0,0);
		rc = flDOCHAddPartition(&myIoreq);
		if(rc != DOCH_OK)
		{
			DBG_PRINT_ERR_PRM(FLZONE_API, (FLTXT("TFFSflashFormat(): flDOCHAddPartition (Binary) failed with status: 0x%x "), rc));
			return TFFS_API_RET(rc);
		}             		
#ifdef HW_PROTECTION
		/*Authenticate partition*/
		if(((binUserParams->protectionType & PROTECTABLE) == PROTECTABLE) &&
           ((binUserParams->protectionType & (READ_PROTECTED | WRITE_PROTECTED)) != 0))
		{
			checkStatus( tffsApiAuthPartition(&myIoreq, ioreq, partNum, binUserParams->protectionKey,
											sizeof(binUserParams->protectionKey)));
		}
#endif /*HW_PROTECTION*/

		/*Retrieve partition info*/
		tffsAPISetIoreq(&myIoreq, FL_GET_SOCKET_FROM_HANDLE(ioreq) + (partNum << 4), 0,0, intBuf,0,0);
		rc = flDOCHPartitionInfo(&myIoreq);
		if(rc != DOCH_OK)
		{
			DBG_PRINT_ERR_PRM(FLZONE_API, (FLTXT("TFFSflashFormat(): flDOCHPartitionInfo failed with status: 0x%x "), rc));
			return (rc==DOCH_ProtectionFault) ? flHWProtection : TFFS_API_RET(rc);
		}
        dwPartitionTotalSize = ((DOCH_PartitionInfo*)intBuf)->nPartitionSize;

        /*Retrieve current atttributes*/
		rc = flDOCHGetParitionUserAttributes(&myIoreq);
		if(rc != DOCH_OK)
		{
			DBG_PRINT_ERR_PRM(FLZONE_API, (FLTXT("TFFSflashFormat(): flDOCHGetParitionUserAttributes failed with status: 0x%x "), rc));
			return (rc==DOCH_ProtectionFault) ? flHWProtection : TFFS_API_RET(rc);
		}

		/* Update the partition attributes and write them back to device */
		/*-------------*/
		/*Set type to binary*/
		pPartitionUserAttrWithBinary->bType = PARTITION_TYPE_BINARY;
        pPartitionUserAttrWithBinary->binPartHeader.dwPartitionFlags = binUserParams->flags;
		/*Set signature*/
		tffscpy( pPartitionUserAttrWithBinary->binPartHeader.subPartitions[0].bSignature, 
			binUserParams->sign, BDK_SIGNATURE_NAME);  
		/*Set length*/
		pPartitionUserAttrWithBinary->binPartHeader.subPartitions[0].dwSize = dwPartitionTotalSize;
		/*Set # of sub-partitions to 1*/
		pPartitionUserAttrWithBinary->binPartHeader.bNumOfSubPartitions = 1;
		/*Set DPS attribute*/
		pPartitionUserAttrWithBinary->bDPSFwd = 0; /*Not used*/
		pPartitionUserAttrWithBinary->bDPSBwd = 0; /*Not used*/
		/*Set protection attribute*/
		pPartitionUserAttrWithBinary->bChangableProtection = ((binUserParams->protectionType & CHANGEABLE_PROTECTION) == CHANGEABLE_PROTECTION);
		pPartitionUserAttrWithBinary->bProtected = ((binUserParams->protectionType & PROTECTABLE) == PROTECTABLE);
		/*Set attributes back to device*/
		rc = flDOCHSetParitionUserAttributes(&myIoreq);
		if(rc != DOCH_OK)
		{
			DBG_PRINT_ERR_PRM(FLZONE_API, (FLTXT("TFFSflashFormat(): flDOCHSetParitionUserAttributes failed with status: 0x%x "), rc));
			return (rc==DOCH_ProtectionFault) ? flHWProtection : TFFS_API_RET(rc);
		}        

		/* Update the disk attributes and write them back to device */
		/*-------------*/
		tffsAPISetIoreq(&myIoreq, FL_GET_SOCKET_FROM_HANDLE(ioreq), 0,0, intBuf,0,0);
        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);
	    }        
        pDiskUserAttrWithBinary->bNumOfBinaryPartitions = numOfBinaryPartitions + 1;
		tffsAPISetIoreq(&myIoreq, FL_GET_SOCKET_FROM_HANDLE(ioreq), 0,0, intBuf,0,0);
        rc = flDOCHSetDiskUserAttributes(&myIoreq);
        if(rc != DOCH_OK)
        {
		    DBG_PRINT_ERR_PRM(FLZONE_API, (FLTXT("TFFSflashFormat(): flDOCHSetDiskUserAttributes failed with status: 0x%x "), rc));
			return (rc==DOCH_ProtectionFault) ? flHWProtection : TFFS_API_RET(rc);
	    }

#ifdef HW_PROTECTION
		/*Authenticate partition*/
		if((((binUserParams->protectionType & PROTECTABLE) == PROTECTABLE) &&
			(binUserParams->protectionType & (READ_PROTECTED | WRITE_PROTECTED)) != 0) &&
            (ioreq->irFlags & TL_DO_NOT_PERFORM_DOWNLOAD) == 0)
		{
			tffsset(&myIoreq, 0, sizeof(myIoreq));
            myIoreq.irHandle = FL_GET_SOCKET_FROM_HANDLE(ioreq);
			DOCH_SET_PARTITION_TO_IOREQ_HANDLE(&myIoreq, partNum); 
            myIoreq.irFlags = DOCH_ACCESS_USER_PASSWORD;
			rc = flDOCHDisablePartAccess(&myIoreq);
		    if(rc != DOCH_OK)
		    {
			    DBG_PRINT_ERR_PRM(FLZONE_API, (FLTXT("TFFSflashFormat(): flDOCHDisablePartAccess failed with status: 0x%x "), rc));
			    return TFFS_API_RET(rc);
		    }
		}
#endif /*HW_PROTECTION*/

        numOfBinaryPartitions++;
        partNum++;
        dochVol.numOfBinaryPartitions = numOfBinaryPartitions;
        binUserParams++;                                      
	}
#endif /*BDK_ACCESS*/

	/* fix the partition size to be zero - spend on the reminder of the disk
	   required for last partition */	
	FP3->BDTLPartitionInfo[FP3->noOfBDTLPartitions-1].length = 0;

	/*Perform for every bdtl partition*/
	/*--------------------------------*/
	bdtlUserParams = FP3->BDTLPartitionInfo;
	for(i=0; i< FP3->noOfBDTLPartitions; i++)
	{  
        /*	Fill DOCH_PartitionFormatInfoAPI structure from FormatParams3 structure */
		/*==========================================================================*/
		tffsset(intBuf, 0, sizeof(DOCH_PartitionFormatInfoAPI));

		/* standard migration format params */
		TFFS_API_SET_MIG_STD_PART_PRMS(pPartitionFormatInfoAPI, bdtlUserParams->protectionType);

		/* protection features */
		checkStatus( tffsFormatSetProtectionAttribs(bdtlUserParams->protectionType, pPartitionFormatInfoAPI, 
			bdtlUserParams->protectionKey, sizeof(bdtlUserParams->protectionKey)) );

		/*Partition size*/
		/*--------------*/
		switch(bdtlUserParams->lengthType)
		{
		case FL_LENGTH_IN_BYTES:
			/*Convert to Sectors*/
			pPartitionFormatInfoAPI->nPartitionSize = 
                (bdtlUserParams->length & 0x1FF) ? 
                ((bdtlUserParams->length)>>DOCH_SECTOR_SIZE_BITS)+1 : ((bdtlUserParams->length)>>DOCH_SECTOR_SIZE_BITS);
			break;

		case FL_LENGTH_IN_SECTORS:
			/*Already in sectors*/
			pPartitionFormatInfoAPI->nPartitionSize = bdtlUserParams->length;
			break;

		case FL_LENGTH_IN_UNITS:
			pPartitionFormatInfoAPI->nPartitionSize = (bdtlUserParams->length << DOCH_SECTORS_IN_UNIT_BITS);
			break;

		case FL_LENGTH_IN_PERCENTS:
			/*Not supported*/
			DBG_PRINT_ERR(FLZONE_API, "TFFSflashFormat(): FL_LENGTH_IN_PERCENTS Not supported\r\n ");
			return flBadParameter;

		case FL_LENGTH_IN_CYLINDERS:
			/*Not supported*/
			DBG_PRINT_ERR(FLZONE_API, "TFFSflashFormat(): FL_LENGTH_IN_CYLINDERS Not supported\r\n ");
			return flBadParameter;

		default:
			DBG_PRINT_ERR(FLZONE_API, "TFFSflashFormat(): Unsupported Normal area length type\r\n ");
			return flBadParameter;
		}

		/*Round partition size to Unit Size*/
		/*---------------------------------*/
		pPartitionFormatInfoAPI->nPartitionSize = 
                    ((pPartitionFormatInfoAPI->nPartitionSize + 
                    dochVol.dwVirtualUnitSizeInSectors - 1) & (~(dochVol.dwVirtualUnitSizeInSectors-1)));

		/*Fast area size*/
		/*--------------*/
		switch(bdtlUserParams->fastAreaLengthType)
		{
		case FL_LENGTH_IN_BYTES:
			pPartitionFormatInfoAPI->nFastAreaSize = (bdtlUserParams->fastAreaLength >> DOCH_SECTOR_SIZE_BITS);
			pPartitionFormatInfoAPI->dwFastAreaSizeType = DOCH_FAST_AREA_TYPE_SECTORS;
			break;

		case FL_LENGTH_IN_SECTORS:
			pPartitionFormatInfoAPI->nFastAreaSize = bdtlUserParams->fastAreaLength;
			pPartitionFormatInfoAPI->dwFastAreaSizeType = DOCH_FAST_AREA_TYPE_SECTORS;
			break;

		case FL_LENGTH_IN_UNITS:
			/*Not supported*/
			DBG_PRINT_ERR(FLZONE_API, "TFFSflashFormat(): FL_LENGTH_IN_UNITS Not supported\r\n ");
			return flB

⌨️ 快捷键说明

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