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

📄 docbdk.c

📁 M-System DOC(Disk on a Chip) Flash芯片的诊断工具, 可以从Flash芯片中获取特定的数据信息, 用于判断芯片当前的状态.
💻 C
📖 第 1 页 / 共 5 页
字号:
		    flBdkVol->startImageBlock = wIBlock;
                 wNumBlock++;
		 flBdkVol->endImageBlock = wIBlock;
                 if((flBdkVol->realBootImageSize == 0L) && 
                    (wNumBlock>wStartUnit             ) &&
                    (tffscmp((void FAR1 *)&bTmpSignPtr[BDK_SIGNATURE_NAME],
                    (void FAR1 *)"FFFF", BDK_SIGNATURE_NAME-1) == 0 ))
                 {   /* Last block of image is marked as block number FFF */
                    flBdkVol->realBootImageSize =
                     ((FLDword)(wNumBlock - wStartUnit) << flBdkVol->erasableBlockBits);
                 }        
              } /* End if - this block belongs to the sub partition */
              else
              {
                 DBG_PRINT_FLOW(FLZONE_BDK,"Flow: Found a block that does not belong to this sub-partition.\r\n"); 
              }
              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");
            return status;
        }
     } /* End loop over the partition looking for sub partitions blocks */

     /*********************************************/
     /* Update global variables with the findings */
     /*********************************************/

     if (wNumBlock == 0) /* Partition is empty*/
     {     
         DBG_PRINT_ERR(FLZONE_BDK,"Error: getBootAreaInfo() - No such sub-partition blocks.\r\n");
         return( flNoSpaceInVolume );
     }
     flBdkVol->bootImageSize = (FLDword)wNumBlock << flBdkVol->erasableBlockBits;
     if( flBdkVol->realBootImageSize == 0L ) /* In case the image without FFF */
         flBdkVol->realBootImageSize = flBdkVol->bootImageSize;
     flBdkVol->bdkGlobalStatus |= BDK_S_INFO_FOUND;
  }
  DBG_PRINT_FLOW(FLZONE_BDK,"Flow: getBootAreaInfo() Exit.\r\n");
  return( flOK );
}

/*----------------------------------------------------------------------
 *                   b d k R e t r i e v e H e a d e r                  
 *                                                                      
 * Retreave media header from all the media floors             
 *                                                                      
 * Note:  The header of each floor is read to the first half of the     
 * buffer and then ORed to the second half therfore constructing the    
 * real header in the upper half. The data is copied to the first half  
 * while cast back from little endian                                   
 *                                                                      
 *  Parameters :
 *       headerBuffer               : Pointer to retrieved media header.
 *
 *  global variable input :
 *      flBdkVol                      : current binary partition record
 *      flBdkVol->blockPerFloor       : no of units in each floor (except fo last floor)
 *      flBdkVol->flash               : pointer to flash structure
 *      flBdkVol->sectorsInUnitBits   : Multiplier for no of sectors in one unit.
 *
 *  global variable output :
 *      flBdkVol->firstUsableBlock    : Array of the first usable block of each floor.
 *
 *  use functions:
 *      flash->flashRead            : Read data from flash.
 *
 *  Return :
 *      flOK                - success
 *      flBadFormat         - Could not read media header.
 *      other Non-zero value- error returned from called functions.
 *----------------------------------------------------------------------*/

static FLStatus bdkRetrieveHeader (FLByte * headerBufferPtr)
{
  FLWord    wIUnit, wJ;
  FLDword   dwEndUnit; /* Might be larger then FLWord */
  FLByte    readBuf[FL_SECTOR_SIZE];  
  FLByte    bFloorNo;
  FLBoolean fFlag;
  FLByte    bIndex;
  FLStatus  status;
  VolumeRecord * volumeHeaderPtr1;
  VolumeRecord * volumeHeaderPtr2;
  FLFlash      * flashPtr=flBdkVol->flash;

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

  DBG_PRINT_ERR(FLZONE_MTD,"\nNote: Searching for the media header. \r\n");
  DBG_PRINT_ERR(FLZONE_MTD,"      As a result a few H/W protection error messages might be reported.\r\n\n");

  /* Empty header buffer*/
  tffsset(headerBufferPtr,0,FL_MAX_TL_PARTITIONS*
          sizeof(VolumeRecord)+ sizeof(BootRecord));

  flashPtr->args.noOfSectors = 1;
  flashPtr->args.readMainBuf = readBuf;
  flashPtr->args.opFlags     = MTD_DATA;

  /* Loop over floors looking for the media header */

  for (bFloorNo = 0 ; bFloorNo < flashPtr->noOfFloors ; bFloorNo++)
  {
     /*****************************************/
     /* Search for media header on this floor */
     /*****************************************/

     wIUnit    = bFloorNo * flBdkVol->blockPerFloor;
     dwEndUnit = wIUnit + flBdkVol->blockPerFloor;

     for (fFlag = FALSE;(wIUnit<dwEndUnit)&&(fFlag==FALSE);wIUnit++)
     {
         for (bIndex=0;bIndex<BDK_NO_OF_MEDIA_HEADERS;bIndex++) /* All copies */
         {            
             flashPtr->args.startSector = (FLDword)(bIndex * BDK_HEADERS_SPACING) 
                              + ((FLDword)wIUnit << flBdkVol->sectorsInUnitBits);
                                                    ;
             status = flashPtr->flashRead(flashPtr);
	         if(status == flHWProtection)
		        break;
	         if(status == flOK)
             {
                if (tffscmp(readBuf, "CNAND", sizeof("CNAND")) == 0)
                {
                   fFlag=TRUE;
                   flBdkVol->firstUsableBlock[bFloorNo] = wIUnit + 1;
                   break;
                }
		        continue;
	         }
	         if(status == flDataError)
		        continue;

	         DBG_PRINT_ERR(FLZONE_BDK,"Error: bdkRetrieveHeader() ERROR reading original unit header.\r\n");
	         return flBadFormat;
	     }
     }
     if (fFlag == FALSE) /* Header not found in all header copies */
     {
        DBG_PRINT_ERR(FLZONE_BDK,"Error: bdkRetrieveHeader() binary partition data could not be found.\r\n");
        return flBadFormat;
     }

     /*******************************/
     /* Merge with previous headers */
     /*******************************/

     volumeHeaderPtr1 = (VolumeRecord *)(headerBufferPtr + 
                                         sizeof(BootRecord));
     volumeHeaderPtr2 = (VolumeRecord *)(readBuf + 
                                         sizeof(BootRecord));
     tffscpy(headerBufferPtr,readBuf,sizeof(BootRecord));

     for(wJ = 0 ; wJ < FL_MAX_TL_PARTITIONS ; wJ++,volumeHeaderPtr1++,volumeHeaderPtr2++)
     {           
        toLE4(volumeHeaderPtr1->quickMountUnits,LE4(volumeHeaderPtr1->quickMountUnits) + LE4(volumeHeaderPtr2->quickMountUnits));
        toLE4(volumeHeaderPtr1->spareUnits     ,LE4(volumeHeaderPtr1->spareUnits)      + LE4(volumeHeaderPtr2->spareUnits));
        toLE4(volumeHeaderPtr1->totalGoodUnits ,LE4(volumeHeaderPtr1->totalGoodUnits)  + LE4(volumeHeaderPtr2->totalGoodUnits));
        toLE4(volumeHeaderPtr1->virtualUnits   ,LE4(volumeHeaderPtr1->virtualUnits)   + LE4(volumeHeaderPtr2->virtualUnits));
        toLE4(volumeHeaderPtr1->transferUnits  ,LE4(volumeHeaderPtr1->transferUnits)  + LE4(volumeHeaderPtr2->transferUnits));
        toLE4(volumeHeaderPtr1->firstQuickMountUnit ,LE4(volumeHeaderPtr1->firstQuickMountUnit) | LE4(volumeHeaderPtr2->firstQuickMountUnit));
        toLE4(volumeHeaderPtr1->firstUnit           ,LE4(volumeHeaderPtr1->firstUnit)           | LE4(volumeHeaderPtr2->firstUnit));
        toLE4(volumeHeaderPtr1->flags               ,LE4(volumeHeaderPtr1->flags)               | LE4(volumeHeaderPtr2->flags));
        toLE4(volumeHeaderPtr1->lastUnit            ,LE4(volumeHeaderPtr1->lastUnit)            | LE4(volumeHeaderPtr2->lastUnit));
        toLE4(volumeHeaderPtr1->protectionArea      ,LE4(volumeHeaderPtr1->protectionArea)      | LE4(volumeHeaderPtr2->protectionArea));
     }       
  } /* End loop over the floors */

  DBG_PRINT_ERR(FLZONE_MTD,"\nNote: header was found - end of media header search.\r\n\n");

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

#ifdef MTD_READ_BBT

/*----------------------------------------------------------------------
 *                      b d k D e f i n e P a r t i t i o n                 
 *                                                 
 *  Informs the MTD of the way the media is partitioned and peforms the
 *  matching algorithms.
 *
 *  Parameters :
 *       headerBuffer  - Pointer to retrieved media header buffer.
 *
 *  global variable input :
 *       flBdkVol->flash    - pointer to flash structure
 *
 *  global variable output :
 *       None
 *
 *  use functions:
 *       flash->definePartitions(flash) - Set MTD partition.
 *
 *  Return :
 *      flOK                - success
 *      flBadFormat         - Media header data is corrupted.
 *      other Non-zero value- error returned from called functions.
 *----------------------------------------------------------------------*/

FLStatus bdkDefinePartition (FLByte * headerBufferPtr)
{
    BootRecord      *bootRecordPtr = (BootRecord*) headerBufferPtr;
    VolumeRecord    *volumePtr     = (VolumeRecord *) (headerBufferPtr + sizeof(BootRecord)) ;
    FLFlash         *flashPtr = flBdkVol->flash;
    FLByte          bIdx;
    FLStatus        status;

    DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkDefinePartition() Entered.\r\n");
    flashPtr->args.noOfPartitions   = (FLByte)(LE4(bootRecordPtr->noOfBinaryPartitions) + 
                                               LE4(bootRecordPtr->noOfBDTLPartitions));
    flashPtr->args.noOfSkippedUnits = (FLByte)LE4(bootRecordPtr->headerUnits) ;
    for(bIdx = 0 ; bIdx < flashPtr->args.noOfPartitions ; bIdx++ , volumePtr++)
    {
        flashPtr->args.noOfUnitsArray[bIdx]  = (FLWord)LE4(volumePtr->totalGoodUnits);
        flashPtr->args.partitionsFlags[bIdx] = ((LE4(volumePtr->flags) & 
            BDK_SAFTL_ADVANCED_MATCHING) ? MTD_AM : MTD_SM);
    }
    
    /* Define the partitions of the media for the MTD */
    status = flashPtr->definePartitions(flashPtr);
    if(status != flOK)
    {
        DBG_PRINT_ERR(FLZONE_BDK,"Error: bdkDefinePartition() Define partition failed.\r\n");
        return status;
    }
    DBG_PRINT_FLOW(FLZONE_BDK,"Flow: bdkDefinePartition() Exit.\r\n");
    return flOK;
}
#endif /* MTD_READ_BBT */

/*--------------------------------------------------------------------------*
 *                         b d k M o u n t
 *
 *  Routine that finds the media header unit and initializes it. The header
 *  supplies the number of binary partition in the DiskOnChip and their
 *  boundries. If the header is valid the curent partition pointer is set to
 *  the required partition and the MTD perform the matching algorithms 
 *  according to header data.
 *
 *  Note : 1) Drive argument is assumed to be O.K and DiskOnChip already found
 *         2) If there are no binary partitions O.K will be returned but the
 *            flBdkVol pointer will not be changed.
 *
 *  Parameters : None
 *
 *  global variable input :
 *           flBdkVol                     : current binary partition record
 *           flBdkVol->bdkGlobalStatus    : was this partition accessed before
 *           flBdkVol->flash              : flash record enabling media I\O
 *           flSocketNo             : DiskOnChip drive number (always 0 for BDK)
 *           flPartitionNo          : Binary partition number in the DiskOnChip
 *           flNoOfPartitions           : the current amount of partitions
 *           flBdkVols                  : array of the binary partitions records
 *
 *  global variable output :
 *           flBdkVol                     : new current binary partition record
 *           flhandleTable                : partition to record converion table
 *           flBdkVol->erasableBlockBits  : number of bits representing a unit
 *           flBdkVol->blockPerFloor
 *           flBdkVol->sectorsInUnitBits  : number of bits representing number of pages in unit.
 *           flBdkVol->sectorsInUnitMask  : Mask for the number of sectors in a unit.
 *           flBdkVol->firstUsableBlock
 *           flBdkVol->startPartitionBlock: physical unit number of first unit
 *           flBdkVol->endPartitionBlock  : and last units of the partition
 *           flBdkVol->protectionArea     : protection area (DPS number) of current partition
 *           flBdkVol->protectionType     : protection type of current partition.
 *           flBdkVol->bdkGlobalStatus    : set to BDK_S_HEADER_FOUND
 *           flNoOfPartitions           : increment with the new found partitions
 *             
 *  use functions:
 *             flash->flashRead           : Read data from flash.
 *             bdkRetrieveHeader            : Read the media  
 *             bdkDefinePartition            : Set the MTD matching table according to header partitions.
 *             
 *
 *  Return:
 *             flOK                  - success
 *             flBadFormat           - TL format does not exists
 *             flFeatureNotSupported - Not a DiskOnChip device.
 *             flNoSpaceInVolume     - No binary partition at all
 *             flBadDriveHandle      - No such binary partition on the media or number
 *                                    binary partitions exceeds the cusomized limit.
 *             other Non-zero value  - error returned from called functions.
 *
 * Routine for both SDK and the BDK stand alone package.
 *--------------------------------------------------------------------------*/

static FLStatus bdkMount(void)
{
#ifndef MTD_STANDALONE
  FLFlash      *   flashPtr        = flBdkVol->flash;
#else
  FLDword   dwTemp;
#endif /* MTD_STANDALONE */
  FLDword          dwNoOfBlocks,dwVolumeFlags;
  FLWord           wUnitsPerChip;
  FLByte           bMaxPartition;
  FLByte           headerBuffer[FL_MAX_TL_PARTITIONS*
                                sizeof(VolumeRecord)+

⌨️ 快捷键说明

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