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

📄 nand_util.c

📁 <B>SMSC USB2.0 Flash硬盘驱动源码</B>
💻 C
📖 第 1 页 / 共 4 页
字号:
      continue;
    }

    if( _media_is_phyblock_blank() )
    {
      if( _map_is_phy_blk_used( _a_map, g_addr_rd_phy_blk) )
      {
        trace1(0, map, 0, "***  error!  phy_block %d is marked blank on media, but is in use in ram map", g_addr_rd_phy_blk) ;
      }

      for(lb=0; lb < max_lb ; lb++ )
      {
        if( _l2p_map[lb] == g_addr_rd_phy_blk )
        {
          trace2(0, map, 0, "***  error!  phy_block %d is blank on media, but has logical mapping to log_blk:%d", g_addr_rd_phy_blk, lb) ;
        }
      }
      continue;
    }

    // the block SHOULD be marked used in the assignment map
    if ( !_map_is_phy_blk_used( _a_map, g_addr_rd_phy_blk ))
    {
      trace1(0, map, 0, "*** error!  phy_block %d in use, but assign_map shows phy_block is available", g_addr_rd_phy_blk) ;
    }

    check_for_l2p_entry = k_false ;

    // tests to determine whether the block is in-use, but not mapped.
    if( !_media_is_phyblock_ok() )
      check_for_l2p_entry = k_true ;
    if(k_error == _media_phy2log())
      check_for_l2p_entry = k_true ;
    if ( g_addr_log_blk >= max_lb )
      check_for_l2p_entry = k_true ;

    // if block should be in use, but not mapped, make sure there is no mapping
    if(check_for_l2p_entry)
    {
      for(lb=0; lb < max_lb ; lb++ )
      {
        if( _l2p_map[lb] == g_addr_rd_phy_blk )
        {
          trace2(0, map, 0, "***  error!  log_blk %d bound to phy_block %d.  However, phy_block should not have a mapping due to extra-data errors", lb, g_addr_rd_phy_blk) ;
        }
      }
      continue;
    }

    // if the block is in use, and there SHOULD be a mapping, make sure the mapping
    // in the ram tables matches what is on the media
    for(lb=0; lb < max_lb ; lb++)
    {
      if( lb == g_addr_log_blk )
      {
        if(_l2p_map[lb] != g_addr_rd_phy_blk)
        {
          trace3(0, map, 0, "*** error!  log_blk: %d maps to rd_phy_blk %d, should map to rd_phy_blk %d", lb, _l2p_map[lb], g_addr_rd_phy_blk) ;
        }
      }
      else if(_l2p_map[lb] == g_addr_rd_phy_blk)
      {
        trace3(0, map, 0, "*** error!  log_blk: %d incorrectly maps to rd_phy_blk %d!  Should ONLY be mapped log blk %d", lb, g_addr_rd_phy_blk, g_addr_log_blk) ;
      }
    }
  }
}
#endif


//+-----------------------------------------------------------------------------
// Name:
//   map_reclaim_bad_sectors()
//
// Declaration:
//   t_result map_reclaim_bad_sectors(void) reentrant
//
// Purpose:
//  TBD
//
// Arguments:
//  TBD
//
// Return:
//  TBD
//
// Notes:
//  TBD
//
// Since:
//   fmc-1.0
//------------------------------------------------------------------------------
#if 0
t_result map_reclaim_bad_sectors() reentrant
{
  uint8 zone_idx ;
  uint8 page ;
  uint8 rd_blk ;

  trace0(0, map, 0, "map_alloc_wr_blk()") ;
  zone_idx    = g_addr_zone?1:0 ;
  page = g_addr_page ;
  rd_blk = g_addr_rd_phy_blk ;
  _a_map = _assign_map(g_addr_zone) ;

  for( g_addr_rd_phy_blk = 0 ;
       g_addr_rd_phy_blk < _media_data(physica_blocks_per_zone) ;
       g_addr_rd_phy_blk++)
  {
    if ((!g_addr_zone) && (g_addr_rd_phy_blk <= _media_data(boot_block)))
    {
      trace1(0, map, 0, "phy_block %d: not reclaimable", g_addr_rd_phy_blk) ;
      continue;
    }

    if(k_error == _media_read_extra_data() )
    {
      trace0(0, map, 0, "cannot read extra data.  not attempting to reclaim.") ;
      continue;
    }

    // skip bad block
    if( !_media_is_phyblock_ok() )
    {
      trace0(0, map, 0, "phy_block marked bad.  not included in log2phy map") ;
      continue;
    }

    g_addr_wr_phy_blk = g_addr_rd_phy_blk ;

    trace(0, map, 0, "trying to reclaim block %d") ;
    _media_erase_block() ;

    if(k_error == _media_read_extra_data() )
    {
      trace0(0, map, 0, "still cannot read extra data.  not attempting to reclaim.") ;
      continue;
    }

    if( !_media_is_phyblock_ok() )
    {
      trace0(0, map, 0, "phy_block still bad.  not included in log2phy map") ;
      continue;
    }

    if( !_media_is_phyblock_blank() )
    {
      trace0(0, map, 0, "phyblock not blank.  moving on") ;
      continue;
    }



  }
    if ( _map_is_phy_blk_free(_a_map, g_addr_wr_phy_blk) )
    {
      _map_phy_blk_used(_a_map, g_addr_wr_phy_blk) ;
      _media_data(assign_start)[zone_idx] = g_addr_wr_phy_blk + 1;
      trace2(0, map, 0, "zone %d phy_blk %d allocated for writing", g_addr_zone, g_addr_wr_phy_blk) ;
      return k_success ;
    }

  for (g_addr_wr_phy_blk = 0 ;
       g_addr_wr_phy_blk < _media_data(assign_start)[zone_idx] ;
       g_addr_wr_phy_blk++ )
    if( _map_is_phy_blk_free(_a_map, g_addr_wr_phy_blk) )
    {
      _map_phy_blk_used(_a_map, g_addr_wr_phy_blk) ;
      _media_data(assign_start[zone_idx])=g_addr_wr_phy_blk+1;
      trace2(0, map, 0, "zone %d phy_blk %d allocated for writing", g_addr_zone, g_addr_wr_phy_blk) ;
      return k_success ;
    }

  trace0(0, map, 0, "error:  no more available phyblocks in this zone!  try to reclaim some 'bad' blocks") ;
  //  map_reclaim_sectors() ;

  g_addr_wr_phy_blk = k_block_free ;

  trace1(0, map, 0, "error:  k_media_err_write_fault - no more phyblocks available in zone %d", g_addr_zone) ;
  return k_error ;
  page = g_addr_page ;
  rd_blk = g_addr_rd_phy_blk ;

  g_addr_page = 0 ;
  trace0(0, map, 0, "seeking bad blocks") ;
  // populate the assignment map
  for (g_addr_rd_phy_blk=0;
       g_addr_rd_phy_blk < _media_data(physical_blocks_per_zone);
       g_addr_rd_phy_blk++ )
  {



    // set the block used
    _map_phy_blk_used( _a_map, g_addr_rd_phy_blk ) ;

  }
}

#endif


// --------------------------------------------------------------------
// --------------------------------------------------------------------

#if 0
/* log block 0, phy block 2, page 0 */
static code uint8 k_tbl_sm_log_0_pg_0[528] =
{
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01,
  0x10, 0x00, 0x06, 0x0f, 0x60, 0xf3, 0x2f, 0x00,
  0x00, 0x00, 0xd1, 0xe7, 0x03, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa,
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x01,
  0xc0, 0xff, 0x3f, 0x10, 0x01, 0xff, 0xff, 0xff
};


/* log block 1, phy block 3, page 15 */
static code uint8 k_tbl_sm_log_1_pg_15[528] =
{
  0xe9, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20,
  0x20, 0x20, 0x20, 0x00, 0x02, 0x20, 0x01, 0x00,
  0x02, 0x00, 0x01, 0x00, 0x00, 0xf8, 0x20, 0x00,
  0x20, 0x00, 0x10, 0x00, 0x2f, 0x00, 0x00, 0x00,
  0xd1, 0xe7, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x41,
  0x54, 0x31, 0x36, 0x20, 0x20, 0x20, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa,
  
  /* extra data */
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x02,
  0xff, 0xff, 0xff, 0x10, 0x02, 0x99, 0xa9, 0x5b
};

/* log block 1, phy block 3, page 16 */
static code uint8 k_tbl_sm_log_1_pg_16[528] =
{
  0xf8, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

⌨️ 快捷键说明

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