bbtinfo.c

来自「M-System DOC(Disk on a Chip) Flash芯片的诊断工」· C语言 代码 · 共 154 行

C
154
字号
#include "bbtinfo.h"

EXDWORD*    pPhyBadBlockTable ;


#ifndef FL_MALLOC
	byte		bbt_table[0x200];
	byte		phy_bbt_table[0x200];
#endif

byte        bbt_was_printed=FALSE;

FLStatus DINFO_BBT( EXBYTE handle )
{
	FLStatus  Status;
	EXWORD    i;

    DinfoPrint( EX_TEXT("\n BAD BLOCK TABLE INFO.\n") );
	ExPrintLine( 23 );

  /* LOGICAL BBT */
	Status = GetBBT(handle);
	if( Status != flOK )
	{
        /* DinfoPrint( EX_TEXT("   CAN'T FIND THE BAD BLOCK TABLE.\n") ); */
		Status = flOK;
	}

	/* PHYSICAL BBT */
	if( Option.Extraflag )
	{
    DinfoPrint( EX_TEXT("\n PHYSICAL BAD BLOCK TABLE INFO.\n") );
		ExPrintLine( 32 );

		for( i = 0 ; pPhyBadBlockTable[i] != 0xffffffff ; i++ )
		{
          DinfoPrint( EX_TEXT("   Block Number         :  %ld is a bad block.\n"), pPhyBadBlockTable[i] );
		}
	}

	/* if( pPhyBadBlockTable )
		ExMemFree( pPhyBadBlockTable ); */

	return Status;

}

FLStatus GetBBT( EXBYTE handle )
{
	IOreq         ioreq;
	FLStatus      Status;
	EXDWORD       i = 0;
	PhysicalInfo  pInfo;
	EXDWORD*      pBadBlockTable ;
	EXWORD        bbtSize;

	ioreq.irHandle	= handle;
	ioreq.irData	= &pInfo;

	Status =	DINFO_flGetPhysicalInfo(&ioreq);
	if(STATUS_ERROR)
	{
		return Status;
	}

	/* for mdoc512 bbt table size is 0x100 */
	bbtSize = 0x200;

#ifdef FL_MALLOC
	pBadBlockTable = ( EXDWORD* )ExMemAlloc( bbtSize );
	if( pBadBlockTable == NULL )
	{
		Status = flNotEnoughMemory;
		return Status;
	} 
#else
	pBadBlockTable = (EXDWORD *)&bbt_table[0];
#endif

  if( Option.Extraflag )
  {
#ifdef FL_MALLOC
		pPhyBadBlockTable = ( EXDWORD* )ExMemAlloc( bbtSize );
		if( pPhyBadBlockTable == NULL )
		{
			Status = flNotEnoughMemory;
			return Status;
		}
#else
	  pPhyBadBlockTable = (EXDWORD *)&phy_bbt_table[0];
#endif
  }

  ExMemSet( pBadBlockTable, 0x00, bbtSize );
  if( Option.Extraflag )
  {
    ExMemSet( pPhyBadBlockTable, 0xff, bbtSize );
  }

  bbt_was_printed = FALSE;
  ioreq.irData = pBadBlockTable;
  Status = DINFO_flReadBBT( &ioreq ,PRINT_MSG);
  /* if we got error status, we print bbt table inside DINFO_flReadBBT, and here we check */
  /* for error so it won't be  printed twice */
  if (bbt_was_printed)
	return Status;
  if(STATUS_ERROR)
  {
		return Status;
  }
  if (ioreq.irFlags != 0)
  {
	  DinfoPrint( EX_TEXT("   Number of Bad Units  :  %d\n"), ioreq.irFlags );
	  DinfoPrint( EX_TEXT("   Bad Units Percentage :  %.4f\n"), (float)ioreq.irFlags / ( pInfo.mediaSize / pInfo.unitSize) * 100 );

	  for( i = 0 ; i < ioreq.irFlags ; i++ )
	  {
		  DinfoPrint( EX_TEXT("   Unit Number          :  %ld (address 0x%lX)\n"), pBadBlockTable[i]/pInfo.unitSize,pBadBlockTable[i]  );
	  }
  }
  return Status;
}




/* Whenever OREN_isGoodBlock is called , this proc is called and the bad block info */
/* is inserted into this local table.																*/
FLStatus plantedIsGoodBlock(FLFlash * flashPtr, FLWord wBlockNo,FLBoolean * bCurBlockStatus)
{
  
  static int i = 0;


  if( pPhyBadBlockTable )
  {
	if( *bCurBlockStatus == FALSE )
	{
	  pPhyBadBlockTable[i] = wBlockNo;
	  i++;
	}
  }

  return flOK;

}



FLStatus informOfOperation(FLFlash * flash, dword start, dword length , byte bType)
{
  return flOK;
}

⌨️ 快捷键说明

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