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

📄 m512_lgc.c

📁 M-System DOC(Disk on a Chip) Flash芯片的诊断工具, 可以从Flash芯片中获取特定的数据信息, 用于判断芯片当前的状态.
💻 C
📖 第 1 页 / 共 5 页
字号:
        /* Check if the DPS is locked:                          */
        /* 1. Check if The DPS is RP/WP                         */
        /* 2. Check if the KEY_OK is on -> means not locked     */  
        /* If these 2 conditions exist do not to try to open    */ 
        /* the protection since it is already open              */
          if ((M512_IsDPS1_KeyInserted(flashPtr)) || /* Key is in */
              ((!M512_IsDPS1_WP(flashPtr)       ) && 
              (!M512_IsDPS1_RP(flashPtr)       )   ))
             continue ;
          break;
      }
      default: /* No such protection area */
        return flGeneralFailure;
    }

    /* Try the Key */       
    tempStatus = M512_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;
	}

    /* Try default key */
    tempStatus = M512_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");
  return(status);
}
#endif /* ((defined(HW_PROTECTION)) || (!defined(NO_IPL_CODE))) */

#ifdef HW_PROTECTION
/***********************************************************************
 * Name: M512_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.          
 ***********************************************************************/
FLStatus M512_protectionKeyRemove(FLFlash *flashPtr,FLByte bDps_No)
{
  FLByte bTempKeyArr[M512_KEY_LENGTH];
  FLByte bFloor;
  FLStatus status;

  MTD_VARS->asicSetInNormalMode (flashPtr) ;  
  flashPtr->completeOperation (flashPtr) ; 

  /* Initialized to remove warnings */
  tffsset(bTempKeyArr,'r',M512_KEY_LENGTH);

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

    M512_AsicSetFloor (flashPtr,bFloor) ; 

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

/***********************************************************************
 *  Name: M512_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
 *              OTW_PROTECTED   The area is OTP protected    
 ***********************************************************************/
FLStatus M512_protectionType (FLFlash *flashPtr,FLByte bDpsNo, FLWord* wAreaType)
{
  FLWord wLowUnit,wHighUnit ; 
  FLByte bFloor ; 
#ifdef DEBUG_MTD
  FLByte bTemp ; 
#endif

  DBG_PRINT_FLOW(FLZONE_MTD,"Flow: protectionType entered.\r\n");
  flashPtr->completeOperation (flashPtr) ; 
  MTD_VARS->asicSetInNormalMode (flashPtr) ;  

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

#ifdef DEBUG_MTD
   bTemp = M512_Read8BitReg (flashPtr,M512_PROTECTION_STATUS_REG) ; 
#endif

  for (bFloor=0;bFloor<flashPtr->noOfFloors;bFloor++)
  {
    M512_AsicSetFloor (flashPtr,bFloor) ;
    /*** Find the physical low Unit & Physical high M512_PROTECTED units  ***/
    if (bDpsNo==0)
	{ /********  DPS_0  ********/
      wLowUnit   = M512_DPS0_LowProtectedUnit (flashPtr) ;
      wHighUnit  = M512_DPS0_HighProtectedUnit (flashPtr) ;

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

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

        if (!((wLowUnit==(wHighUnit-1)) && (wLowUnit==M512_DPS0_UnitLocation(flashPtr))))
          *wAreaType |= WRITE_PROTECTED ;
      }

      /*** Check if DPS is OTP protected ***/ 
      if (M512_IsDPS0_OTP_Protected (flashPtr))
        *wAreaType |= OTW_PROTECTED ;

      /*** Check if the LOCK signal is enabled          ***/           
      if (M512_IsDPS0_LOCK_Enabled(flashPtr))
        *wAreaType |= LOCK_ENABLED ;

	  /*** Check if DPS is locked with a protection key ***/
	  if (*wAreaType & OTW_PROTECTED)
	  { /*** In that case AREA is always protected ***/ 
        *wAreaType &= ~KEY_INSERTED ;
	  }
	}
    else
	{ /********  DPS_1  ********/
      wLowUnit   = M512_DPS1_LowProtectedUnit (flashPtr) ;
	  wHighUnit  = M512_DPS1_HighProtectedUnit (flashPtr) ;

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

      /*** Check if DPS is WP ***/           
      if (M512_IsDPS1_WP (flashPtr))
      {  /*** If it is WP check that the protection is not on the DPS unit itself ***/
        if (!M512_IsDPS1_KeyInserted(flashPtr))
          *wAreaType &= ~KEY_INSERTED ;
        if (!((wLowUnit==(wHighUnit-1)) && (wLowUnit==M512_DPS1_UnitLocation(flashPtr))))
          *wAreaType |= WRITE_PROTECTED ;
      }

      /*** Check if DPS is OTP protected ***/ 
      if (M512_IsDPS1_OTP_Protected (flashPtr))
        *wAreaType |= OTW_PROTECTED ;
	  
      /*** Check if the LOCK signal is enabled          ***/           
      if (M512_IsDPS1_LOCK_Enabled(flashPtr))
        *wAreaType |= LOCK_ENABLED ;

	  /*** Check if DPS is locked with a protection key ***/
	  if (*wAreaType & OTW_PROTECTED)
	  { /*** In that case AREA is always protected ***/ 
        *wAreaType &= ~KEY_INSERTED ;
	  }
	}
 
    /*** Check if sticky lock was activated (asserted) ***/
    if (M512_Is_StickyLOCK_Asserted(flashPtr))
      *wAreaType |= STICKY_LOCK_ASSERTED ;

    /*** Check if LOCK# H/W signal was asserted in all floors ***/
    if (!M512_Is_LOCK_Negated(flashPtr))
      *wAreaType |= LOCK_ASSERTED ;
  }
  DBG_PRINT_FLOW(FLZONE_MTD,"Flow: protectionType exited.\r\n");
  return flOK; 
}

/***********************************************************************
 *  Name: M512_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  -  Pointer to where the protection start address 
 *                     (in bytes from the beginning of the media)
 *                      will be returned.
 *  HighLogicalUnit -  Pointer to where the protection end address 
 *                     (in bytes from the beginning of the media) will 
 *                     be returned.
 *                                                                     
 * Returns: 
 *   flOK else other status                                                                   
 ***********************************************************************/
FLStatus M512_protectionBoundries(FLFlash *flashPtr,FLByte bDPS_No,FLWord *wLowLogicalUnitPtr,
                                  FLWord *wHighLogicalUnitPtr,FLByte bFloor)

{
  PhyUnitType wLowPhyUnit,wHighPhyUnit;
#ifdef MTD_READ_BBT 
  LogicUnitType  wLogicalUnit ;
#endif /* MTD_READ_BBT */

  DBG_PRINT_FLOW(FLZONE_MTD,"Flow: protectionBoundries entered.\r\n");
  MTD_VARS->asicSetInNormalMode (flashPtr) ;  
  flashPtr->completeOperation (flashPtr) ; 

  /*** Set the asic floor ***/    
  M512_AsicSetFloor (flashPtr,bFloor) ;
 
  switch (bDPS_No)
  {
    case DPS_0: 
    {
      wLowPhyUnit  = M512_DPS0_LowProtectedUnit(flashPtr)  <<1 ;
      wHighPhyUnit = M512_DPS0_HighProtectedUnit(flashPtr) <<1 ;
      break ;
	}
    case DPS_1: 
    {
      wLowPhyUnit  = M512_DPS1_LowProtectedUnit(flashPtr)  <<1 ;
      wHighPhyUnit = M512_DPS1_HighProtectedUnit(flashPtr) <<1 ;
      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,0,&wLogicalUnit)==TRUE)
        *wLowLogicalUnitPtr = wLogicalUnit ; /* Advanced matching */
      else 
#endif
        *wLowLogicalUnitPtr  = (FLWord)((wLowPhyUnit >> MTD_VARS->bNoOfPlanesBits)  /* Simple Matching */       
	       					 + ((FLWord)bFloor   * MTD_VARS->dwLogicalUnitsInFloor)) ;

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

⌨️ 快捷键说明

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