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

📄 initvsb.c

📁 intel的一个高效率FLASH文件系统。思路很好
💻 C
📖 第 1 页 / 共 2 页
字号:
   if (setupTest != 0)
      return (ERR_SETUP);

/* Initialize component specific variables */
    RetVal = ERR_NONE;
    ErasedBlock = 0xff;
   SpareBlock[ci] = 0xff;
   WriteBlock[ci] = 0xff;
   VSBFound = FALSE;
   ReclaimThresholdOverride = FALSE;
   
#if SOCKET
   /* initialize and power the socket */
   RetVal = Initialization(0xd000);
   if (RetVal)
   {
      return (ERR_FLASH_INVALID);
   }

   PowerUpSocket(12);
#endif

 /*   Check that flash component is compatible with VSB system */

   /*  modify by wangfei
   if( FlashDevCompatCheck( (MEDIA_INFO *)&Info ) != ERR_NONE )
   {
      return( ERR_FLASH_INVALID);
   }
   */
/*
   Check all blocks in component to see if another block was being erased
   when power was lost. If more than 1 block is found to be in the ERASING
   state, it is assumed that the entire flash component is in an invalid
   state and it must be reformatted.
*/
   bi = 0;
   do
   {
      /* Calculate physical address of block attribute */
      FlashAddr = CalculateFlashAddr( ci, bi, 0);

      if ((RetVal = FlashDevRead(FlashAddr, sizeof(BYTE), &BlockAttr))
           != ERR_NONE)
         return (RetVal);            
/* E2.3.38 */
      /* Count the number of VFB_FB_ERASED blocks*/
      if (BlockAttr == VSB_FB_ERASED)
      { 
      	TotalErasedBlocks++;
      	if(TotalErasedBlocks >= MAX_ERASED_BLOCKS)
      	   return(ERR_FORMAT_INVALID);                      
      }
/* E2.3.38 */
      if ((BlockAttr == VSB_FB_ERASING)
#if MLC_DEVICE
          || (BlockAttr == VSB_FB_PLR_ERASING))
      {
         if (BlockAttr == VSB_FB_PLR_ERASING)
         {
 	         BlockAttr = VSB_FB_ERASING;
#   if PLR_TESTING
            if (PowerLossFlags.breakpoint_number == PLR_BP3)
               PowerLossFlags.current_iteration++;
#   endif
            if ((RetVal = FlashDevWrite (FlashAddr, sizeof(BYTE),&BlockAttr))
                 != ERR_NONE)
               return (ERR_WRITE);
         }
#else
       )
      {
#endif
         /* If there is only one erasing block, save it as recover block,
          * then read the block that was being erased.
          */
         if( ErasedBlock == 0xff )
         {
            RecoverBlock = bi;
            ++FlashAddr;
            if ((RetVal = FlashDevRead(FlashAddr, sizeof( BYTE ), &ErasedBlock))
                 != ERR_NONE)
               return (RetVal);
         }
         else   /* found more than one block */
         {
            return( ERR_FORMAT_INVALID );
         }
      }
   } while( ++bi < BLOCK_COUNT );

   if( ErasedBlock != 0xff )                  /* find any erasing blocks ? */
   {
      FlashAddr = CalculateFlashAddr( ci,     /* calculate physical address */
                                       ErasedBlock, /* of block to erase */
                                       0);
      RetVal = FlashDevEraseBlock( FlashAddr ); /* erase block */
      if( RetVal == ERR_NONE )
      {
         FlashAddr = CalculateFlashAddr( ci,  /* calculate physical address */
                                          RecoverBlock, /* of recover block */
                                          VSB_FB_ATTR );
         BlockAttr = VSB_FB_WRITE;
#if PLR_TESTING
         if (PowerLossFlags.breakpoint_number == PLR_BP4)
            PowerLossFlags.current_iteration++;
#endif
         RetVal = FlashDevWrite( FlashAddr,     /* mark recover block as */
                                 sizeof( BYTE ),/* a write block */
                                 &BlockAttr );

         if( RetVal == ERR_NONE )
         {
            WriteBlock[ci] = RecoverBlock;      /* set current write block */
         }
      }
      else
         RetVal = ERR_ERASE;
   }
   ErasedBlock = 0xff;

/*
   Now check all blocks again for valid block attributes
*/

   bi = 0;
   do
   {
      if( RetVal != ERR_NONE )                /* if any errors occur, leave */
      {                                       /* check loop */
         break;
      }

      /* calculate physical address of current block attribute */
      FlashAddr = CalculateFlashAddr( ci, bi, 0 );
      /* read current block attribute */
      if ((RetVal = FlashDevRead( FlashAddr, sizeof( BYTE ), &BlockAttr ))
          != ERR_NONE)
         return (RetVal);

      if( BlockAttr == VSB_FB_RECOVER )     /* in the midst of a reclaim? */
        {
         RetVal = FlashDevEraseBlock( FlashAddr ); /* erase block */
         if( RetVal == ERR_NONE )
         {
            /* get new block attribute */
            if ((RetVal = FlashDevRead(FlashAddr, sizeof( BYTE ), &BlockAttr ))
                != ERR_NONE)
               return (RetVal);
         }
      }

      if( BlockAttr == VSB_FB_WRITE )        /* latest write block? */
      {
         WriteBlock[ci] = bi;                /* update current write block */
         RetVal = ScanVAT( ci, bi );         /* validate VAT entries */
      }
      else if( BlockAttr == VSB_FB_ERASED )  /* erased block? */
      {
         if( SpareBlock[ci] == 0xff )        /* current spare block setup? */
         {
            SpareBlock[ci] = bi;             /* update currenspare block */
         }
         else
         {
            ErasedBlock = bi;                /* save block number for later */
         }
      }
      else if(( BlockAttr == VSB_FB_FULL )    /* Block full? */
#if MLC_DEVICE
       || (BlockAttr == VSB_FB_MLC_FULL))
      {
         /* Write out actual status */
         BlockAttr = VSB_FB_FULL;
         if ((FlashDevWrite( FlashAddr, sizeof( BYTE ),&BlockAttr )) != ERR_NONE)
            return (ERR_WRITE);
#else
       )
      {
#endif
         RetVal = ScanVAT( ci,               /* validate VAT entries */
                           bi );
      }
      else                                   /* must be invalid block */
      {
         return( ERR_FORMAT_INVALID );       /* bail out */
      }
   } while( ++bi < BLOCK_COUNT );
   if( RetVal == ERR_NONE )                  /* everything good so far? */
   {
        /* CountVSB to update the global media statistics, RetVal isn't used */
        SearchForEntry(ci,(MAXIMUM_VSB+2));

        /* enable/disable automatic reclaim */
        ReclaimEnable[ci] = ReclmEnable;

        /* set current operating block */
        CurrentBlock[ci] = WriteBlock[ci];

        /* set current component number */
        CurrentComponent = ci;

        /* Initialize the variable which tracks the last free logical VSB */
        FreeVSB[ci] = 1;

        for (count = 0; count < MRU_VSB_CACHE_SIZE; count++)
        {
            lastLogicalVSB[ci][count].block = DEFAULT_BYTE;
            lastLogicalVSB[ci][count].vsbIndex = DEFAULT_WORD;
        }


   }
   return( RetVal );                         /* give'em back the results */
}

⌨️ 快捷键说明

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