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

📄 oren_lgc.c

📁 M-System DOC(Disk on a Chip) Flash芯片的诊断工具, 可以从Flash芯片中获取特定的数据信息, 用于判断芯片当前的状态.
💻 C
📖 第 1 页 / 共 5 页
字号:
              ((!OREN_IsDPS1_WP(flashPtr)) && (!OREN_IsDPS1_RP(flashPtr))) )			  
             continue ;
          break;
      }
      default: /* No such protection area */
        return flGeneralFailure;
    }

    /* Try the Key */       
    tempStatus = OREN_tryKey (flashPtr,bDPS_No,Key,bFloor);
    if (tempStatus == flOK)
	{
      /*** Save the key so that after s/w download you'd still remember the key ***/
      if (bDPS_No==DPS_0)	  
        tffscpy (MTD_VARS->SavedDOC_State_Ptr->DPS_0_Key,Key,PROTECTION_KEY_LENGTH) ;	  
	  else	 
        tffscpy (MTD_VARS->SavedDOC_State_Ptr->DPS_1_Key,Key,PROTECTION_KEY_LENGTH) ;	  		   	   

      continue;
	}

	/* In case the DPS is neither read, nor write protect return */

    /* Try default key */
    tempStatus = OREN_tryKey (flashPtr,bDPS_No,(FLByte *)DEFAULT_KEY,bFloor);
    if (tempStatus != flOK)
    {
       argsPackPtr->maxBitError |= bMask ; /* Mark that the key did not fit */
       status = tempStatus;
    }
  }
  DBG_PRINT_FLOW(FLZONE_MTD,"Flow: protectionKeyInsert exited.\r\n");
#ifdef _FL_IGNORE_KEY_STATUS
  return flOK;
#endif /* _FL_IGNORE_KEY_STATUS */
  return(status);
}
#endif /* ((defined(HW_PROTECTION)) || (!defined(NO_IPL_CODE))) */

#ifdef HW_PROTECTION
/***********************************************************************
 * Name: OREN_protectionKeyRemove
 *   Remove the protection key, while restoring the protection.
 *
 * Parameters:
 *  flashPtr   - FLFlash struct
 *  area    : indicated which protection area to work on. 0 or 1.
 *  Key     : An 8 FLByte long array containing the protection password.          
 *  Notes
 *   1.    The key should be sent to all of the device's floors even if 
 *      one of the floors indicated that the key did not fit.
 *      The key should not be sent to a floor that indicates that 
 *      it's key was already inserted. 
 *      This way allows us to open partition that might have different
 *      keys for different floors as a result of a bug or a power failure.
 *   2.    Before sending the given key the MTD will try and send "00000000" 
 *      (Ascii) key.
 ***********************************************************************/
FLStatus OREN_protectionKeyRemove(FLFlash *flashPtr,FLByte bDps_No)
{
  FLByte bTempKeyArr[OREN_KEY_LENGTH];
  FLByte bFloor;
  FLStatus status;

  checkStatus (OREN_asicSetInNormalMode (flashPtr)) ;
  /* Initialized to remove warnings */
  tffsset(bTempKeyArr,'r',OREN_KEY_LENGTH);

  OREN_completeOperation (flashPtr) ;
  DBG_PRINT_FLOW(FLZONE_MTD,"Flow: protectionKeyRemove entered.\r\n");
  for (bFloor=0;bFloor<flashPtr->noOfFloors;bFloor++)
  {    
    OREN_AsicSetFloor (flashPtr,bFloor) ; 

    status   = OREN_tryKey (flashPtr,bDps_No,bTempKeyArr,bFloor);
    if (status == flOK) /* Unfortunatly the key was fine */
    {
      bTempKeyArr[0]++;
      status = OREN_tryKey(flashPtr,bDps_No,bTempKeyArr,bFloor);
    }
  }
  DBG_PRINT_FLOW(FLZONE_MTD,"Flow: protectionKeyRemove exited.\r\n");
  return flOK;
}

/***********************************************************************
 *  Name: OREN_protectionType                                             
 *    Get the protection type of a protected area for all of 
 *    the device's floors.                                              
 * Parameters:                                                          
 *   flashPtr   : Pointer to current flash descriptor.
 *   bDpsNo   : The DPS number controlling this protected area 0/1
 *   wAreaType: Pointer to the where the protection type will be 
 *              returned. The protection type may be a combination of
 *              the following flags:
 *              READ_PROTECTED    The area is protected against read operations
 *              WRITE_PROTECTED    The area is protected against write operations
 *              LOCK_ENABLED    The LOCK signal is enabled
 *              LOCK_ASSERTED    The LOCK signal input pin is asserted
 *              KEY_INSERTED    The key has been correctly written
 *              STICKY_LOCK_ASSERTED    The sticky lock was enabled.
 *
 ***********************************************************************/
FLStatus OREN_protectionType (FLFlash *flashPtr,FLByte bDpsNo, FLWord* wAreaType)
{
  FLWord wLowUnit,wHighUnit ; 
  FLByte bFloor ; 

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

  /*** Build the AreaType ***/
  *wAreaType = KEY_INSERTED | CHANGEABLE_PROTECTION ; /* Initialize the AreaType output */

  for (bFloor=0;bFloor<flashPtr->noOfFloors;bFloor++)
  {
    OREN_AsicSetFloor(flashPtr,bFloor) ;
    /*** Find the physical low Unit & Physical high OREN_PROTECTED units  ***/
    if (bDpsNo==0)
	{ /********  DPS_0  ********/
      wLowUnit   = OREN_DPS0_LowProtectedUnit (flashPtr) ;
      wHighUnit  = OREN_DPS0_HighProtectedUnit (flashPtr) ;

      /*** Check if DPS is RP ***/ 
      if (OREN_IsDPS0_RP (flashPtr))
	  {
         if (!OREN_IsDPS0_KeyInserted(flashPtr))
             *wAreaType &= ~KEY_INSERTED ;
         *wAreaType |= READ_PROTECTED ;
	  }

      if (OREN_IsDPS0_WP (flashPtr))
      { /*** If it is WP check that the protection is not on the DPS unit itself ***/
         if (!OREN_IsDPS0_KeyInserted(flashPtr))
            *wAreaType &= ~KEY_INSERTED ;
         if (!((wLowUnit==(wHighUnit-1)) && (wLowUnit==OREN_DPS0_UnitLocation(flashPtr))))
            *wAreaType |= WRITE_PROTECTED ;
      }
      
      /*** Check if DPS is HW_LOCKED ***/           
      if (OREN_IsDPS0_LOCK_Enabled(flashPtr))
        *wAreaType |= LOCK_ENABLED ;
	}
    else
	{ /********  DPS_1  ********/
      wLowUnit   = OREN_DPS1_LowProtectedUnit (flashPtr) ;
      wHighUnit  = OREN_DPS1_HighProtectedUnit (flashPtr) ;

      /*** Check if DPS is RP ***/ 
      if (OREN_IsDPS1_RP (flashPtr)==OREN_PROTECTED)
	  {
         if (!OREN_IsDPS1_KeyInserted(flashPtr))
           *wAreaType &= ~KEY_INSERTED ;

         *wAreaType |= READ_PROTECTED ;
	  }

      /*** Check if DPS is WP ***/           
      if (OREN_IsDPS1_WP (flashPtr))
      { /*** If it is WP check that the protection is not on the DPS unit itself ***/
         if (!OREN_IsDPS1_KeyInserted(flashPtr))
           *wAreaType &= ~KEY_INSERTED ;

         if (!((wLowUnit==(wHighUnit-1)) && (wLowUnit==OREN_DPS1_UnitLocation(flashPtr))))
           *wAreaType |= WRITE_PROTECTED ;
      }
      /*** Check if DPS is HW_LOCKED ***/           
      if (OREN_IsDPS1_LOCK_Enabled(flashPtr))
        *wAreaType |= LOCK_ENABLED ;
	}

    /*** Check if LOCK# H/W signal was asserted in all floors ***/
    if (OREN_Is_LOCK_Asserted(flashPtr))
      *wAreaType |= LOCK_ASSERTED ;

    /*** Check if sticky lock was activated (asserted) ***/
    if (OREN_Is_StickyLOCK_Asserted(flashPtr))
      *wAreaType |= STICKY_LOCK_ASSERTED ;
  }
  DBG_PRINT_FLOW(FLZONE_MTD,"Flow: protectionType exited.\r\n");
  return flOK; 
}

/***********************************************************************
 *  Name: OREN_protectionBoundries          
 *                                                                      
 * MTD specific Flash get protection boundries routine                 
 *  flashPtr - FLFlash struct
 *  bDpsNo - Dps0 / Dps1 (0/1)  
 *  bFloor - The floor in which the DPS resides in 
 * Outputs:
 *  LowLogicalUnit  -  LowLogical unit Boundary 
 *  HighLogicalUnit -  HighLogical unit Boundary 
 *                                                                     
 * Parameters:                                                          
 *                                                                      
 ***********************************************************************/
FLStatus OREN_protectionBoundries(FLFlash *flashPtr,FLByte bDPS_No,FLWord *wLowLogicalUnitPtr,
                             FLWord *wHighLogicalUnitPtr,FLByte bFloor)

{
  PhyUnitType wLowPhyUnit,wHighPhyUnit;  
#ifdef MTD_READ_BBT 
  LogicUnitType  wLogicalUnit ;
#endif
  FLByte bLowBank,bHighBank ;    

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

  /*** Set the asic floor ***/    
  OREN_AsicSetFloor (flashPtr,bFloor) ;
 
  switch (bDPS_No)
  {
    case DPS_0: 
    {
      wLowPhyUnit  = OREN_DPS0_LowProtectedUnit  (flashPtr) ;
      wHighPhyUnit = OREN_DPS0_HighProtectedUnit (flashPtr) ;
      bLowBank     = OREN_DPS0_LowProtectedBank  (flashPtr) ;
      bHighBank    = OREN_DPS0_HighProtectedBank (flashPtr) ;
      break ;
	}
	case DPS_1:
	{
      wLowPhyUnit  = OREN_DPS1_LowProtectedUnit  (flashPtr) ;
      wHighPhyUnit = OREN_DPS1_HighProtectedUnit (flashPtr) ;
      bLowBank     = OREN_DPS1_LowProtectedBank  (flashPtr) ;
      bHighBank    = OREN_DPS1_HighProtectedBank (flashPtr) ;
      break ;
	}
	default :
	{
      DBG_PRINT_ERR(FLZONE_MTD,"Error: protectionBoundries wrong parameters.\r\n");
      return flBadParameter ;      
	}
  }

#ifdef MTD_READ_BBT 
  if (MTD_VARS->MATCH_searchPhyUnitInLOOKUP_Table (flashPtr,wLowPhyUnit,bFloor,bLowBank,&wLogicalUnit)==TRUE)
    *wLowLogicalUnitPtr = wLogicalUnit ; /* Advanced matching */
  else 
#endif
    *wLowLogicalUnitPtr  =  (FLWord)((wLowPhyUnit >> MTD_VARS->bNoOfPlanesBits)  /* Simple Matching */       
	                      + ((FLWord)bLowBank * MTD_VARS->dwLogicalUnitsInBank)
						  + ((FLWord)bFloor   * MTD_VARS->dwLogicalUnitsInFloor)) ;

#ifdef MTD_READ_BBT 
    if (MTD_VARS->MATCH_searchPhyUnitInLOOKUP_Table (flashPtr,wHighPhyUnit,bFloor,bHighBank,&wLogicalUnit)==TRUE)
      *wHighLogicalUnitPtr = wLogicalUnit ; /* Advanced matching */
    else 
#endif
     *wHighLogicalUnitPtr =   (FLWord)((wHighPhyUnit>>MTD_VARS->bNoOfPlanesBits) /* Simple Matching */       
	                        + ((FLWord)bHighBank * MTD_VARS->dwLogicalUnitsInBank)
						    + ((FLWord)bFloor    * MTD_VARS->dwLogicalUnitsInFloor)) ;
    
  DBG_PRINT_FLOW(FLZONE_MTD,"Flow: protectionBoundries exited.\r\n");
  return flOK ;      
}

#ifndef FL_READ_ONLY
/***********************************************************************
 * Name: OREN_protectionSet                                                                                               
 *
 * Parameters:
 *  flashPtr   - FLFlash struct
 *  AreaNo   - Dps0 / Dps1 (0/1)  
 *  AreaType:
 *   READ_PROTECTED  - The area is protected against read  operations. 
 *   WRITE_PROTECTED - The area is protected against write operations.
 *   LOCK_PROTECTED  - The Lock signal is enabled 

⌨️ 快捷键说明

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