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

📄 docbdk.c

📁 DOC文件系统驱动源代码
💻 C
📖 第 1 页 / 共 5 页
字号:

#ifndef NO_NFTL_SUPPORT
     if (flash->flags & NFTL_ENABLED)
     {
    tffscpy(buf1,"ANAND",TL_SIGNATURE);
     }
#endif /* NO_NFTL_SUPPORT */
#ifndef NO_INFTL_SUPPORT
     if (flash->flags & INFTL_ENABLED)
     {
    tffscpy(buf1,"BNAND",TL_SIGNATURE);
     }
#endif /* NO_INFTL_SUPPORT */
     if ((flash->flags & (NFTL_ENABLED | INFTL_ENABLED))==0)
     {
       DEBUG_PRINT(("Debug: Not a DiskOnChip device therfore Binary partitions are not supported.\r\n"));
    return( flFeatureNotSupported );
     }

     /* Find the medium boot record in order to get partition boundries */

     for(iBlock=flash->firstUsableBlock;( iBlock < noOfBlocks );iBlock++)
     {
    checkStatus(flash->read(flash,(CardAddress)iBlock << bdkVol->erasableBlockBits,
                buf2,TL_SIGNATURE,0));

    if(tffscmp((void FAR1 *)buf2,(void FAR1 *)buf1,TL_SIGNATURE) == 0 )
    {
       break;
    }
     }

     if (iBlock==noOfBlocks)
     {
       DEBUG_PRINT(("Debug: TL format does not exists.\r\n"));
       return( flBadFormat );
     }

     /* Analize The media header */

#ifndef NO_NFTL_SUPPORT
     if (flash->flags & NFTL_ENABLED)     /* NFTL - only a single partition */
     {
         DEBUG_PRINT(("NFTL media header encounterd.\r\n"));
         bdkVol->startPartitionBlock = 0;
         bdkVol->endPartitionBlock   = (word)((iBlock) ? iBlock-1 : 0);
         maxPartition                = 1;
     }
#endif /* NO_NFTL_SUPPORT */
#ifndef NO_INFTL_SUPPORT
     if (flash->flags & INFTL_ENABLED)    /* INFTL - parse media header */
     {
         DEBUG_PRINT(("INFTL media header encounterd.\r\n"));
         maxPartition = 0;
         checkStatus(bdkRetrieveHeader((dword *)headerBuffer));
         volume = (VolumeRecord *) (headerBuffer+BDK_FIELDS_BEFORE_HEADER);
         if (((LE4(volume->flags) & BDK_BINARY_FLAG)==0) && (globalPartitionNo == 0))
         {
            DEBUG_PRINT(("Device is not formated with a binary partition.\r\n"));
            return flNoSpaceInVolume;
         }
         blockMultiplierBits = (byte)LE4(headerBuffer[MULTIPLIER_OFFSET]);
         bdkVol = &bdkVols[noOfPartitions];
         for (;(BINARY_PARTITIONS >= maxPartition + noOfPartitions) &&
             (LE4(volume->flags) & BDK_BINARY_FLAG) ; bdkVol++,volume++)
        {
            maxPartition++;
            bdkVol->startPartitionBlock = (word)LE4(volume->firstUnit) << blockMultiplierBits;
            bdkVol->endPartitionBlock   = (word)((LE4(volume->lastUnit)+1) << blockMultiplierBits) - 1;
            bdkVol->flash = bdkVols[noOfPartitions].flash;
#ifdef PROTECT_BDK_IMAGE
            bdkVol->protectionArea = (byte)LE4(volume->protectionArea);
            bdkVol->protectionType = (word)LE4(volume->flags);
#endif /* PROTECT_BDK_IMAGE */
            bdkVol->blockPerFloor     = bdkVols[noOfPartitions].blockPerFloor;
            bdkVol->erasableBlockBits = bdkVols[noOfPartitions].erasableBlockBits;
        }
     }
#endif /* NO_INFTL_SUPPORT */

     /* Initialize the partitions that had been found */

     for (blockMultiplierBits=0;blockMultiplierBits<maxPartition;
          blockMultiplierBits++) /* reused blockMultiplierBits as counter */
     {
        bdkVol                              = &bdkVols[noOfPartitions];
        handleTable[globalSocketNo][blockMultiplierBits] = noOfPartitions++;
        bdkVol->bdkGlobalStatus             = BDK_S_DOC_FOUND |
                                              BDK_S_HEADER_FOUND;
     }
  }

  /* set the current partition by changing the bdkVol global pointer */

  if ((globalPartitionNo>MAX_BINARY_PARTITIONS_PER_DRIVE) ||
      (handleTable[globalSocketNo][globalPartitionNo] == BDK_INVALID_VOLUME_HANDLE))
  {
     DEBUG_PRINT(("Device is not formated the specified binary partition.\r\n"));
     return flBadDriveHandle;
  }
  else
  {
    bdkVol = &bdkVols[handleTable[globalSocketNo][globalPartitionNo]];
  }
  return flOK;
}

#ifdef MTD_STANDALONE

/*-------------------------------------------------------------------
 *                         b d k E x i t
 *
 * Reset BDK variables and Free 'bdkWin' memory.
 *
 * Parameters: None
 *
 * Return:     Nothing
 *-------------------------------------------------------------------*/

void bdkExit( void )
{
  if( bdkVol->bdkGlobalStatus & BDK_S_DOC_FOUND )  /* DiskOnChip was found */
  {
    freePointer(bdkWin,DOC_WIN);
  }
  bdkInit();
}

/*-------------------------------------------------------------------
 *                   b d k S e t D o c W i n d o w
 *
 *  Set DiskOnChip window explicitly
 *
 *  Note : This routine should not be used after a DiskOnChip was already
 *         found since it does not initialize the Global binary variables.
 *         In order to switch between DiskOnChip call bdkexists before
 *         calling this routine.
 *
 *  Parameters : 'docWindow' - DiskOnChip physical address
 *
 *  global variable input :
 *               bdkVol           - current binary partition record
 *
 *  global variable output :
 *           bdkDocWindow     - initialized with the given address
 *
 *  Return:     Nothing
 *
 * Routine for BDK stand alone package.
 *-------------------------------------------------------------------*/

void bdkSetDocWindow( dword docWindow )
{
  if(globalInitStatus==FALSE)
      bdkInit();

   bdkVol->bdkDocWindow = docWindow;
}

/*--------------------------------------------------------------------------
 *                     b d k F i n d D i s k O n C h i p
 *
 *  Find DiskOnChip in the specified memory range and identify the flash
 *  media (initialize flash). Update 'docSize' and 'docAddress' according
 *  to the DiskOnChip size and address respectively.
 *
 *  Note : If the DiskOnChip location is known, specify the same address
 *         for DOC_LOW_ADDRESS and DOC_HIGH_ADDRESS.
 *
 *  Parameters : 'docAddress'      - pointer to the DiskOnChip address
 *               'docSize'         - pointer to the returned size
 *
 *  global variable input :
 *           bdkGlobalStatus  - was this device found before
 *               bdkVol           - current binary partition record
 *               bdkDocWindow     - if > 0 only this address will be checked
 *
 *  global variable output :
 *               flash            - flash record enabling media I\O
 *           bdkGlobalStatus  - set to BDK_S_DOC_FOUND
 *               bdkDocWindow     - save physical window address
 *
 *  Return:
 *      flOK                - success
 *      flDriveNotAvailable - DiskOnChip ASIC was not found
 *      flUnknownMedia      - failed in Flash chips recognition
 *      flBadDownload          - DiskOnChip Millennium Plus reported an uncorrectable
 *                            protection violation. This device is unusable.
 *
 * Routine for BDK stand alone package.
 *------------------------------------------------------------------------*/

FLStatus bdkFindDiskOnChip(dword FAR2 *docAddress, dword FAR2 *docSize )
{
  FLStatus status;
  byte     mtdIndex;
  dword    blockSize;
  FLSocket *socket = flSocketOf(0);
  FLFlash  *flash  = flFlashOf(0);

  if(globalInitStatus==FALSE)
      bdkInit();

  if ((bdkVol->bdkGlobalStatus & BDK_S_DOC_FOUND) == 0) /* initialize MTD */
  {

      bdkVol        = bdkVols;
      bdkVol->flash = flash;

#ifndef NO_DOC2000_FAMILY_SUPPORT
      flRegisterDOC2000();
#endif
#ifndef NO_DOCPLUS_FAMILY_SUPPORT
      flRegisterDOCPLUS();
#endif

      /* Search for ASIC in the given memory boundries */

      for(mtdIndex=0;mtdIndex < doc_noOfMTDs;mtdIndex++)
      {
         if( bdkVol->bdkDocWindow > 0 )       /* Set range explicitely */
         {
            status = socketTable[mtdIndex](socket,
                     bdkVol->bdkDocWindow,bdkVol->bdkDocWindow);
         }
         else
         {
            status = socketTable[mtdIndex](socket,
                     DOC_LOW_ADDRESS,DOC_HIGH_ADDRESS);
         }
         if (status == flOK)
         {
              /* Identify flash connected to the ASIC */

            bdkVol->bdkDocWindow = pointerToPhysical(socket->base);

            flash->socket = socket;
            checkStatus(doc_mtdTable[mtdIndex](flash));
            break;
         }
      }
      if (status != flOK)
         return status;

      bdkVol->bdkGlobalStatus |= BDK_S_DOC_FOUND;

      /* Calculate erasable Block Size Bits */
      for(blockSize = flash->erasableBlockSize>>1,flash->erasableBlockSizeBits = 0;
         blockSize>0; flash->erasableBlockSizeBits++,blockSize = blockSize >> 1);
  }

  *docAddress  = pointerToPhysical(socket->base);
  *docSize     = flash->chipSize * flash->noOfChips;

  return flOK;
}

/*--------------------------------------------------------------------------
 *               b d k S e t B o o t P a r t i t i o n N o
 *
 *  Set current binary partiton pointer to a specific binary partition
 *
 *  Note : This routine is neccesay only for partitions > 0 .
 *         This routine can replace the bdkFindDiskOnChip call.
 *
 *  Parameters : 'partitionNo'     - serial number of binary partition
 *
 *  global variable output :
 *           globalPartitionNo  - changed to the current partition number.
 *
 *  Return:
 *     flOK on success
 *     flBadParameter if BDK is not customized to support that many partitions.
 *
 * Routine for BDK stand alone package only.
 *------------------------------------------------------------------------*/

FLStatus bdkSetBootPartitionNo(byte partitionNo)
{
  if (partitionNo < TFFSMIN(BINARY_PARTITIONS,MAX_BINARY_PARTITIONS_PER_DRIVE))
  {
     globalPartitionNo = partitionNo;
     return flOK;
  }
  else
  {
     DEBUG_PRINT(("BDK is not customized to support the specified partition number.\r\n"));
     return flBadParameter;
  }
}

/*-------------------------------------------------------------------
 *                    b d k C h e c k S i g n O f f s e t
 *
 *  Set BDK signature offset
 *
 *  Note : Offset 0 does not support the use of EDC\ECC mechanizm and
 *         therfore it reconmended not to be used.
 *         The new found offset is stored in the bdkSignOffset field of the
 *         partitions global record.
 *
 *  Parameters : 'signature'       - 4-character signature of storage units
 *
 *  global variable input :
 *           bdkGlobalStatus     - was this partition accessed before
 *               bdkVol              - current binary partition record
 *               bdkDocWindow        - DiskOnChip window physical address
 *                                     (used to narrow search for DiskOnChip)
 *
 *  global variable output :
 *           bdkSignOffset - the offset of the signature (either 0 or 8)
 *

⌨️ 快捷键说明

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