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

📄 oren_lgc.c

📁 M-System DOC(Disk on a Chip) Flash芯片的诊断工具, 可以从Flash芯片中获取特定的数据信息, 用于判断芯片当前的状态.
💻 C
📖 第 1 页 / 共 5 页
字号:
 * LogicalLowUnit    - The lowest   Logical unit protected
 * LogicalHighUnit   - The highest  Logical unit protected
 * Key                 - Pointer to an 8 bytes array containing the key 
 *                     to be sent. If this field in set to NULL, 
 *                     the routine will automatically use the previous key.
 * Modes:
 *   DO_NOT_COMMIT_PROTECTION  Do not force a download of the controller
 *                             state-machine at the end of the operation.
 *     COMMIT_PROTECTION         Force a download of the controller 
 *                             state-machine and let the new protection
 *                             parameters get into affect.
 *     MTD_ON_DPS_ONLY         Ignores the boundary parameters and protect 
 *                             the DPS itself.
 * LogicalHighUnit - The highest Logical unit protected 
 * MTD specific Flash get protection type routine                       
 *                                                                      
 * No default routine is implemented for this routine.                  
 *                                                                      
 * Parameters:                                                          
 *                                                                      
 ***********************************************************************/
FLStatus OREN_protectionSet (FLFlash *flashPtr,FLByte bAreaNo,FLWord wAreaType,
                             FLWord wLogicalLowUnit,FLWord wLogicalHighUnit,
                             FLByte FAR1* Key,FLByte bModes,FLByte bFloor)
{
  FLStatus status ;
  DPS_Struct DPS,READ_DPS ;
  FLWord wLowUnitOffset,wHighUnitOffset ;
  FLByte bLowBank,bHighBank ;
  PhyUnitType wPhyUnitArray [OREN_MAX_NUMBER_OF_PLANES] ;
  PhyUnitType wHighestPhyUnit,wLowestPhyUnit ;
  FLWord i,wHighUnit,wLowUnit ; 
#ifndef FL_SKIP_ARGS_CHECK
  FLByte bLowFloor,bHighFloor;
#endif /* !FL_SKIP_ARGS_CHECK */

  DBG_PRINT_FLOW(FLZONE_MTD,"Flow: protectionBoundries entered.\r\n");
  checkStatus (OREN_asicSetInNormalMode (flashPtr)) ; 
  OREN_completeOperation (flashPtr) ;

  /*** Step 1 - Before writing the DPS send default key            ***/
#ifndef ERASED_FLASH 
  status = OREN_protectionKeyInsert(flashPtr,bAreaNo,(FLByte FAR1 *)("00000000")) ;
  if (status) 
  {
    DBG_PRINT_ERR_PRM(FLZONE_MTD,(FLTXT("protectionSet:protectionKeyInsert returned status %d \r\n"),status)) ;
    return flHWProtection ;
  }
#endif

  /*** Step 2 - Initialize DPS and set protection type             ***/
  tffsset (&DPS,0x0,sizeof(DPS)) ;
  DPS.protectionType     = 0x10; /* DPS Revision 1          */
  if (wAreaType & READ_PROTECTED)
     DPS.protectionType |= 0x2 ; /* Enable read  protection */
  if (wAreaType & WRITE_PROTECTED)
     DPS.protectionType |= 0x4 ; /* Enable write protection */
  if (wAreaType & LOCK_ENABLED)
     DPS.protectionType |= 0x8 ; /* Enable lock  protection */

  /*** Step 3 - Set Protection Key                                 ***/
  if (Key)
  {
    tffscpy (DPS.protectionKey,Key,OREN_KEY_LENGTH) ;
  }
  else /* Use the previous key */
  {
   /* In this case key=NULL Read key from DPS */
   status = OREN_DPS_Read(flashPtr,&READ_DPS,(FL_DPS_IndexE)bAreaNo,OREN_FIRST_GOOD_COPY,bFloor) ;
   if (status)
   {
     DBG_PRINT_ERR_PRM(FLZONE_MTD,(FLTXT("protectionSet: OREN_DPS_Read returned status %d \r\n"),status)) ;
     return flHWProtection ;
   }
   else
   {
     tffscpy (DPS.protectionKey,READ_DPS.protectionKey,OREN_KEY_LENGTH) ;
   }
  } /* End if - which key to use */

  /*** Step 4 - Set protection boundries                           ***/
  if (bModes & MTD_ON_DPS_ONLY)
  {
    OREN_AsicSetFloor (flashPtr,bFloor) ; 
    /* In this case we ignore the boundries and protects the DPS itself */
    /*** Find the physical low Unit & Physical high units  ***/
    if (bAreaNo==0)
      wHighUnit  = OREN_DPS0_HighProtectedUnit (flashPtr) ;
    else
      wHighUnit  = OREN_DPS1_HighProtectedUnit (flashPtr) ;
    if (bAreaNo==0)
      wLowUnit   = OREN_DPS0_LowProtectedUnit  (flashPtr) ;
    else
      wLowUnit   = OREN_DPS1_LowProtectedUnit  (flashPtr) ;

    DPS.banks = 0;
    if (bAreaNo==0)
    { /* DPS_0 */
      if ((wLowUnit==(wHighUnit-1)) && (wLowUnit==OREN_DPS0_UnitLocation(flashPtr)))
	  { /* In that case we don't need to protect the DPS since it is already protected ***/
        return flOK ;
	  }
      toLE2(DPS.lowUnit ,OREN_DPS0_UnitLocation(flashPtr));   /* Start from MainUnit    */
      toLE2(DPS.highUnit,(FLWord)(OREN_DPS0_UnitLocation(flashPtr)+1)); /* End in Redundancy Unit */
    }
    else
    { /* DPS_1 */
      if ((wLowUnit==(wHighUnit-1)) && (wLowUnit==OREN_DPS1_UnitLocation(flashPtr)))
	  { /* In that case we don't need to protect the DPS since it is already protected ***/
        return flOK ;
	  }
      toLE2(DPS.lowUnit, OREN_DPS1_UnitLocation(flashPtr));   /* Start from MainUnit    */
      toLE2(DPS.highUnit,(FLWord)(OREN_DPS1_UnitLocation(flashPtr)+1)); /* End in Redundancy Unit */
    }
  }
  else /* Use the given protection boundries */
  {
#ifndef FL_SKIP_ARGS_CHECK
    bLowFloor      = (FLByte)(wLogicalLowUnit / MTD_VARS->dwLogicalUnitsInFloor) ;
    if (bFloor!=bLowFloor)
    {
      DBG_PRINT_ERR(FLZONE_MTD,"OREN_DPS_Write:Floor given as input does not.\r\n") ;
      DBG_PRINT_ERR(FLZONE_MTD,"OREN_DPS_Write:equal to floor derived from low unit.\r\n") ;
    }
#endif /* !FL_SKIP_ARGS_CHECK */

    /*** Translate the Logical unit to a set of Physical Units                  ***/	
    /*** The assumption is that there is one Good unit between Low & High units ***/
    /*** and in that case LowUnit would not exceed above HighUnit               ***/
	while (wLogicalLowUnit<=wLogicalHighUnit)
	{
      if (MTD_VARS->MATCH_unitLogicalToPhysical (flashPtr,wLogicalLowUnit,wPhyUnitArray)!=flOK) 
        wLogicalLowUnit++ ;
	  else 
		break ; /*** A matching for the low unit was found ***/
	}

	/*** Check that not all the units that DPS needs to protect are BB          ***/
    if (wLogicalLowUnit>wLogicalHighUnit)
	  return flUnitIsBad ;	

	/*** Calculate the low bank (needed for the DPS struct)                     ***/
    wLowUnitOffset = (FLWord)(wLogicalLowUnit % MTD_VARS->dwLogicalUnitsInFloor) ;
    bLowBank       = (FLByte)(wLowUnitOffset  / MTD_VARS->dwLogicalUnitsInBank) ;


    /* Find the lowest unit in the array */
    wLowestPhyUnit = wPhyUnitArray[0] ;
    for (i=0;i<flashPtr->noOfPlanes;i++)
    {
      if (wPhyUnitArray[i]<wLowestPhyUnit)
        wLowestPhyUnit = wPhyUnitArray[i] ;
    }

    toLE2(DPS.lowUnit,wLowestPhyUnit); /* DPS.lowUnit  = wLowestPhyUnit ; */

#ifndef FL_SKIP_ARGS_CHECK
    bHighFloor      = (FLByte)(wLogicalHighUnit / MTD_VARS->dwLogicalUnitsInFloor) ;
    if (bFloor!=bHighFloor)
    {
      DBG_PRINT_ERR(FLZONE_MTD,"OREN_DPS_Write:Floor given as input does not \r\n") ;
      DBG_PRINT_ERR(FLZONE_MTD,"OREN_DPS_Write:equal to floor derived from high unit \r\n") ;
    }
#endif /* FL_SKIP_ARGS_CHECK */
 
    /*** Translate the Logical unit to a set of Physical Units                  ***/	
    /*** The assumption is that there is one Good unit between Low & High units ***/
    /*** and in that case HighUnit would not exceed below LowUnit               ***/
    while (MTD_VARS->MATCH_unitLogicalToPhysical (flashPtr,wLogicalHighUnit,wPhyUnitArray)!=flOK) 
      wLogicalHighUnit-- ;
	
	/*** Calculate the high bank (needed for the DPS struct)                    ***/
    wHighUnitOffset = (FLWord)(wLogicalHighUnit % MTD_VARS->dwLogicalUnitsInFloor) ;
    bHighBank       = (FLByte)(wHighUnitOffset  / MTD_VARS->dwLogicalUnitsInBank) ;

    /* Find the highest unit in the array */
    wHighestPhyUnit = wPhyUnitArray[0] ;
    for (i=0;i<flashPtr->noOfPlanes;i++)
    {
      if (wPhyUnitArray[i]>wHighestPhyUnit)
        wHighestPhyUnit = wPhyUnitArray[i] ;
    }
    toLE2(DPS.highUnit,wHighestPhyUnit); /* DPS.highUnit = wHighestPhyUnit ; */
    DPS.banks = bLowBank + (bHighBank<<2);
  } /* End if - which boundries to use */

  /*** Step 5 - Actual write of the DPS and optionaly perform download ***/
  status = OREN_DPS_Write (flashPtr,&DPS,(FL_DPS_IndexE)bAreaNo,bFloor) ;
  if (status)
  {
    DBG_PRINT_ERR_PRM(FLZONE_MTD,(FLTXT("protectionSet:OREN_DPS_Write returned status %d \r\n"),status)) ;
    return flHWProtection ;
  }
  if (bModes & COMMIT_PROTECTION)
  {
    status = flashPtr->download(flashPtr);
  }
  DBG_PRINT_FLOW(FLZONE_MTD,"Flow: protectionBoundries exited.\r\n");
  return status ;
}
#endif /* FL_READ_ONLY */

#endif /* HW_PROTECTION */

/********************************************************************************
 *  Name : OREN_doc2Identify 
 *    This routine does the following :
 *    - perform call to the phyDoc2Identify
 *    - perform "hooking" of the Logical MTD API functions
 *    to the FLflash   
 * Status: 
 * Assumptions :   
 *******************************************************************************/
FLStatus OREN_doc2Identify(FLFlash *flashPtr)
{
  checkStatus(OREN_phyDoc2Identify (flashPtr)) ;

#ifndef FL_READ_ONLY
  flashPtr->flashWrite                    = OREN_logicalWrite ;
  flashPtr->flashErase                    = OREN_logicalErase ;
#else
  flashPtr->flashWrite                    = NULL;
  flashPtr->flashErase                    = NULL;
#endif
  flashPtr->flashRead                     = OREN_logicalRead ;

  flashPtr->getEraseCount                 = OREN_getEraseCount ;
  flashPtr->getEraseMark                  = OREN_getEraseMark ;
  flashPtr->setCallBack                   = OREN_setCallBack ;

#ifdef HW_PROTECTION
  flashPtr->protectionBoundries    = OREN_protectionBoundries ;
  flashPtr->protectionKeyInsert    = OREN_protectionKeyInsert ;
  flashPtr->protectionKeyRemove    = OREN_protectionKeyRemove ;
  flashPtr->protectionType         = OREN_protectionType ;
#ifndef FL_READ_ONLY
  flashPtr->protectionSet          = OREN_protectionSet ;
#endif /* FL_READ_ONLY  */
#endif /* HW_PROTECTION */

  return flOK ;
}

/************************************************************************
 *   flRegisterDOCOREN                                                    *
 *                                                                      *
 * Registers this MTD for use                                           *
 *                                                                      *
 * Parameters:                                                          *
 *      None                                                            *
 *                                                                      *
 * Returns:                                                             *
 *      FLStatus        : 0 on success, otherwise failure               *
 ************************************************************************/

FLStatus flRegisterDOCOREN(void)
{
  DBG_PRINT_FLOW(FLZONE_MTD,"Flow: flRegisterDOCOREN Entered.\r\n");

  if (noOfMTDs>=FL_MTDS)
    return( flTooManyComponents );

  /*** The mtdTable is a array of pointers to docPlusIdentify routines          ***/
  /*** Update the mtdTable[noOfMTDs++] with a pointer to my IdentifyDoc routine ***/
  /*** & update the noOfMTDs global variable                                    ***/
  mtdTable[noOfMTDs++]  =  OREN_doc2Identify ;
  DBG_PRINT_FLOW(FLZONE_MTD,"Flow: flRegisterDOCOREN Entered.\r\n");

  return( flOK );
}

⌨️ 快捷键说明

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