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

📄 docbdk.c

📁 M-System DOC(Disk on a Chip) Flash芯片的诊断工具, 可以从Flash芯片中获取特定的数据信息, 用于判断芯片当前的状态.
💻 C
📖 第 1 页 / 共 5 页
字号:
  return( flOK );
}


/*--------------------------------------------------------------------------
 *                         b d k P o w e r D o w n M o d e
 *
 *  Manipulate the Deep Power Donw Mode (DPD)
 *
 *  Parameters: 
 *        wState - DEEP_POWER_DOWN      - enter the mode - reduce power consumption
 *                 EXIT_DEEP_POWER_DOWN - exit the mode  - restore power consumption
 *
 *  global variable input :
 *               flBdkVol                        - Current binary partition record.
 *               flBdkVol->flash                 - Pointer to flash structure.
 *
 *  global variable output : See called functions headers 
 *
 *  use functions: 
 *          bdkMount                                - Initialize the BDK partitions 
 *          flBdkVol->flash->enterDeepPowerDownMode - Activate the required mode
 *
 *  Return :
 *      flOK                  - success
 *      flFeatureNotSupported - no protection support for device.
 *      other Non-zero value  - error returned from called functions.
 *
 * Routine for BDK stand alone package.
 *------------------------------------------------------------------------*/
FLStatus bdkPowerDownMode            (FLWord wState)
{

  DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkPowerDownMode() Entered.\r\n");

  /* Check that the partition is mounted */
  checkStatus(bdkMount());

  if (flBdkVol->flash->enterDeepPowerDownMode==NULL)
     return flFeatureNotSupported;
  return (flBdkVol->flash->enterDeepPowerDownMode(flBdkVol->flash,wState));
}


/*-------------------------------------------------------------------
 *                   b d k C o p y B o o t A r e a
 *
 * Copy the BDK Image from the DiskOnChip to a RAM area starting at
 * 'startAddress', with a size of 'dwAreaLen' bytes.
 *
 *  Note : Blocks in the DiskOnChip are marked with a 4-byte signature
 *         followed by a 3-digit hexadecimal number.
 *
 *        This routine calls bdkCopyBootAreaInit followed by a series of 
 *        bdkCopyBootAreaBlock calls. It is used for backward compatability since
 *        bdkCopyBootAreaBlock could not handle more than a unit at the past.
 *
 * Parameters: 'startAddress'  - pointer to the beginning of the RAM area
 *             'wStartUnit'    - start block in image for reading
 *             'dwAreaLen'     - BDK image size
 *             'checkSum'      - pointer to the checksum modulo 0x100
 *             'signPtr'       - 4-byte signature of storage units
 *
 *  global variable input : See called functions headers
 *
 *  global variable output : See called functions headers 
 *
 *  use functions: 
 *            bdkCopyBootAreaInit   - Init the read process
 *            bdkCopyBootAreaBlock  - Read data to RAM
 *
 *  Return :
 *      flOK                  - success
 *      other Non-zero value  - error returned from called functions.
 *
 * Routine for BDK stand alone package only.
 *-------------------------------------------------------------------*/

FLStatus bdkCopyBootArea( FLByte FAR1 *bStartAddressPtr,FLWord wStartUnit,FLDword  dwAreaLen,
                          FLByte FAR2 *bCheckSumPtr, FLByte FAR2 *signPtr )
{
  DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkCopyBootArea() Entered.\r\n");
  checkStatus(bdkCopyBootAreaInit( wStartUnit, dwAreaLen, signPtr ));

#ifdef BDK_CHECK_SUM
  if (bCheckSumPtr!=NULL)
    *bCheckSumPtr=0;
#endif /* BDK_CHECK_SUM */

  checkStatus(bdkCopyBootAreaBlock( bStartAddressPtr, dwAreaLen, bCheckSumPtr ));
  DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkCopyBootArea() Exit.\r\n");
  return flOK;
}

#endif /* MTD_STANDALONE */

/*-------------------------------------------------------------------
 *             b d k G e t B o o t P a r t i t i o n I n f o
 *
 *  Get DiskOnChip binary sub partition Information.
 *
 *  Parameters: 'wStartUnit'        - start Unit for Actual sub Partition Size
 *              'partitionSize'     - pointer to return sub Partition Size parameter
 *              'realPartitionSize' - pointer to return Actual sub Partition Size
 *              'unitSize'          - pointer to return Unit Size parameter
 *              'signPtr'           - 4-byteacter signature of storage units
 *
 *  global variable input :          See called functions headers 
 *
 *  global variable output :         See called functions headers 
 *
 *  use functions: 
 *            getBootAreaInfo          - Get information of current partition.
 *
 *  Return :
 *      flOK                  - success
 *      other Non-zero value  - error returned from called functions.
 *
 * Routine for BDK stand alone package only.*
 *-------------------------------------------------------------------*/

FLStatus bdkGetBootPartitionInfo( FLWord wStartUnit, 
                                 FLDword  FAR2 *dwPartitionSizePtr,
                                 FLDword  FAR2 *dwRealPartitionSizePtr,
                                 FLDword  FAR2 *dwUnitSizePtr, 
                                 FLByte FAR2 *signPtr)
{
  FLStatus status = flOK;
  DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkGetBootPartitionInfo() Entered.\r\n");

  status = getBootAreaInfo( wStartUnit , signPtr );

  *dwPartitionSizePtr      = flBdkVol->bootImageSize;
  *dwRealPartitionSizePtr  = flBdkVol->realBootImageSize;
  *dwUnitSizePtr           = 1L<<flBdkVol->erasableBlockBits ;

  DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkGetBootPartitionInfo() Exit.\r\n");
  return( status );
}

/*-------------------------------------------------------------------
 *                   f i n d N e x t G o o d B l o c k
 *
 * Find the next block that belongs to this sub-partition.
 *
 * Parameters: 'wIBlock'    - start block from which to search
 *
 *  global variable input :
 *               flBdkVol                    - current binary partition record
 *               flBdkVol->flash             - Pointer to flash descriptor
 *               flBdkVol->signBuffer        - Sub partition signature
 *
 *               flBdkVol->firstUsableBlock  - Array of first usable block of each floor 
 *               flBdkVol->endPartitionBlock - Last block of the partition
 *               flBdkVol->sectorsInUnitBits - multiplier for number of sectors in unit.
 *               flBdkVol->blockPerFloor     - Number of blocks per floor 
 *
 *  global variable output :
 *     flBdkVol->flash->args.startSector - Sector address of the sub-paritions block
 *
 *  use functions: 
 *               flash->flashRead          - Read data from flash
 *
 *  Return :
 *      flOK                - success
 *      flNoSpaceInVolume   - No more sub partition blocks
 *
 * Routine for both SDK and the BDK stand alone package.
 *-------------------------------------------------------------------*/

static FLStatus findNextGoodBlock (FLWord wIBlock)
{
   FLStatus status;
   FLByte signRead[SIGNATURE_LEN];
   FLFlash * flashPtr = flBdkVol->flash;

   flashPtr->args.extraBuf    = signRead;
   flashPtr->args.noOfSectors = 1;
   flashPtr->args.startSector = (FLDword)wIBlock << flBdkVol->sectorsInUnitBits;
   flashPtr->args.opFlags     = MTD_EXTRA | flBdkVol->MTDFlags ;

   for(;; wIBlock++)
   {
      if (wIBlock < flBdkVol->firstUsableBlock[wIBlock / flBdkVol->blockPerFloor])
        wIBlock = flBdkVol->firstUsableBlock[wIBlock / flBdkVol->blockPerFloor];

      if(wIBlock > flBdkVol->endPartitionBlock)
        break;

      flashPtr->args.startSector = (FLDword)wIBlock << flBdkVol->sectorsInUnitBits;
      status = flashPtr->flashRead(flashPtr);
      switch(status)
      {
         case flOK:
            if( tffscmp( (void FAR1 *)signRead, 
                (void FAR1 *)(flBdkVol->signBuffer),
                BDK_SIGNATURE_NAME ) == 0 )
               return flOK;
            continue;

         case flUnitIsBad:
            DBG_PRINT_FLOW(FLZONE_BDK,"Flow: findNextGoodBlock: Bad Block encountered.\r\n");
            continue;
         case flDataError:
            DBG_PRINT_FLOW(FLZONE_BDK,"Flow: findNextGoodBlock: Data Error encountered.\r\n");
            continue;

         default:
            DBG_PRINT_ERR(FLZONE_BDK,"ERROR: findNextGoodBlock: Failed\r\n");
            DBG_PRINT_ERR_PRM(FLZONE_BDK,(FLTXT("With status %d\r\n"),status));
            return status;
      } /* End read status switch */
   } /* End loop looking for next good signatured unit */

   DBG_PRINT_ERR(FLZONE_BDK,"ERROR: findNextGoodBlock: Required length is too big.\r\n");
   return( flNoSpaceInVolume );             /* Finish (last block) */
}


/*-------------------------------------------------------------------
 *           b d k F i n d B l o c k I n P a r t i t i o n 
 *
 *  Find the logical unit number of a givven block in a partition.
 *
 *  Parameters: 'wUnitNo'             - pointer to return field of logical unit number.
 *              'block number         - Number of the block that is searched
  *
 *  global variable input :             
 *            flBdkVol                       : current binary partition record.
 *            flBdkVol->flash                : pointer to flash structure.
 *            flBdkVol->startPartitionBlock  : start unit of the current partition.
 *            flBdkVol->endPartitionBlock    : end unit of current partition.
 *            flBdkVol->sectorsInUnitBits    : number of sectors in unit shift.
 *            flBdkVol->signBuffer           : 4-byteacter signature of storage units
 *
 *  global variable output :         
 *            None
 *
 *  use functions: 
 *            flash->flashRead            : Read data from flash
 *
 *  Return :
 *      flOK                  - success
 *      other Non-zero value  - error returned from called functions.
 *
 * Routine for BDK stand alone package only.
 *-------------------------------------------------------------------*/

FLStatus bdkFindBlockInPartition(FLWord wBlockNo, FLWord *wUnitNoPtr)
{
    FLWord   wIUnit, wCurBlock;
    FLFlash  *flashPtr = flBdkVol->flash;

    DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkFindBlockInPartition() Entered.\r\n");

    wCurBlock  = 0;
    
    for(wIUnit  = flBdkVol->startPartitionBlock;
        wIUnit <= flBdkVol->endPartitionBlock ; wIUnit++)
    { /*Search tha partition and count blocks with givven signature*/
        checkStatus(findNextGoodBlock(wIUnit));
        wIUnit = (FLWord)(flashPtr->args.startSector >> flBdkVol->sectorsInUnitBits);
        if (wCurBlock == wBlockNo)
        { /* When wanted block is found, return it's number.*/
           *wUnitNoPtr = (FLWord)(wIUnit);
           DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkFindBlockInPartition() Exit.\r\n");
           return flOK;
        }
        wCurBlock++;
    }
    DBG_PRINT_ERR(FLZONE_BDK,"ERROR: There are'nt that many blocks with the required signature.\r\n");
    return flNoSpaceInVolume;
}

/*-------------------------------------------------------------------
 *                   b d k C o p y B o o t A r e a I n i t
 *
 * Initialize read operations on the DiskOnChip starting at 'wStartUnit', with
 * a size of 'dwAreaLen' bytes and 'signature'.
 *
 *  Note : Blocks in the DiskOnChip are marked with a 4-byteacter signature
 *         followed by a 3-digit hexadecimal number.
 *
 * Parameters: 'wStartUnit'    - start block in image for reading
 *             'dwAreaLen'     - BDK image size
 *             'signPtr'       - 4-FLByte signature of storage units
 *
 *  global variable input :
 *               flBdkVol      - current binary partition record
 *
 *  global variable output :
 *               flBdkVol->signBuffer          - initialize with given signature
 *               flBdkVol->curReadImageSector  - Set to the first sector of the image
 *               flBdkVol->curReadOffset       - current offset of the image (set to 0)
 *               flBdkVol->actualReadLen       - length left to read
 *
 *  use functions: 
 *                 bdkMount                     - mount the current sub partition.
 *                 bdkFindBlockInPartition     - Find the given block number.
 *
 *  Return :
 *      flOK                - success
 *
 * Routine for both SDK and the BDK stand alone package.
 *-------------------------------------------------------------------*/

⌨️ 快捷键说明

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