7057|12

70

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

为什么NAND Flash要以block为单位erase?FAT表没有block概念如何erase? [复制链接]

对于NAND FLASH,比如SD卡,资料上都读写是以扇区为单位,但擦除却要以块/簇为单位,为什么呢?
还有,在数据区之前是没有cluster/block概念的,但数据区前面的FAT表、DBR也有要修改某个值的时候,修改就要先擦除,那么如何对它们进行擦除操作呢?

最新回复

簇与扇区与针对硬盘的,而sector与block是针对NAND FLASH的,上层的FAT文件系统使用簇与扇区,底层使用sector与block.下面是转换的函数: static Addr LBAtoCHS(FlashInfo *pFlashInfo, Addr lba) {     if(lba.type == CHS)         return lba;     Addr chs;     DWORD tmp = pFlashInfo->dwNumBlocks * pFlashInfo->wSectorsPerBlock;     chs.type = CHS;     chs.chs.cylinder = (WORD)(lba.lba / tmp);     tmp = lba.lba % tmp;     chs.chs.head = (WORD)(tmp / pFlashInfo->wSectorsPerBlock);     chs.chs.sector = (WORD)((tmp % pFlashInfo->wSectorsPerBlock) + 1);     return chs; } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ static Addr CHStoLBA(FlashInfo *pFlashInfo, Addr chs) {     Addr lba;     if(chs.type == LBA)         return chs;     lba.type = LBA;     lba.lba = ((chs.chs.cylinder * pFlashInfo->dwNumBlocks + chs.chs.head)         * pFlashInfo->wSectorsPerBlock)+ chs.chs.sector - 1;     return lba; } FAT表、DBR要修改的时候,会在新的free sector写新的FAT表、DBR数据,然后把以前用的sector标为dirty sector。如果没有free sector的时候,文件系统会擦除dirty sector占用的block,从而得到新的free sector。  详情 回复 发表于 2009-11-16 14:29
点赞 关注

回复
举报

68

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
NAND擦除的时候以block为单位是这种芯片的特性,擦除的时候有专门的命令,可以找相应NAND的DATASHEET看一下。
 
 

回复

88

帖子

0

TA的资源

一粒金砂(初级)

板凳
 
看一下存储器的原理吧
 
 
 

回复

70

帖子

0

TA的资源

一粒金砂(初级)

4
 
《SanDisk Secure Digital Card》里介绍:
If a design needs to support a file system, such as SanDisk’s Host Developers Tool Kit (HDTK), additional considerations are necessary.

Reading and writing to an SD Card and MultiMediaCard is generally done in 512 byte blocks, however, erasing often occurs in much larger blocks. The NAND architecture used by SanDisk and other card vendors currently has Erase Block sizes of (32) or (64) 512 byte blocks, depending on card capacity. In order to re-write a single 512 byte block, all other blocks belonging to the same Erase Block will be imultaneously erased and need to be rewritten.

For example—writing a file to a design using a FAT file system takes three writes/updates of the system area of FAT and one write/update of the data area to complete the file write. First, the directory has to be updated with the
new file name. Second, the actual file is written to the data area. Third, the FAT table is updated with the file data location. Finally, the directory is updated with the start location, length, date and time the file was modified. Therefore, when selecting the file size to write into a design, the size should be as large as possible and a multiple of the Erase Block size. This takes advantage of the architecture.

Some designs update the FAT table for every cluster of the data file written. This can slow the write performance, because the FAT table is constantly being erased and re-written. The best approach is to write all the file clusters then update the FAT table once to avoid the performance hit of erasing and re-writing all the blocks within the Erase Block multiple times.

只是我看不太明白……
 
 
 

回复

55

帖子

0

TA的资源

一粒金砂(初级)

5
 
学习~~~~~
 
 
 

回复

79

帖子

0

TA的资源

一粒金砂(初级)

6
 
以块为单位擦除,是由NAND的原理决定的, 也就是说NAND写入数据前必须先加高电压擦除, 理论上也是可以设计成为按字节擦除, 但是NAND容量一般很大, 按字节擦除效率低,主要还是速度慢, 所以就设计为按Block 或者整个芯片擦除了. 如果你只是修改了Block A中的一个字节, 处理方法是找一个空闲的Block B, 擦除B, 将A中的数据拷贝到B, 如果遇到那个修改的字节, 在内存里修改完毕再拷贝进去. 为了提高拷贝效率, NAND还提供了copy back 的硬件拷贝命令.
 
 
 

回复

67

帖子

0

TA的资源

一粒金砂(初级)

7
 
楼上说的是。不过对于FAT文件系统而言,在保留区没有block的概念,只有sector,那么修改时该怎么办呢?
 
 
 

回复

66

帖子

0

TA的资源

一粒金砂(初级)

8
 
先把保留区内容拷出备份,然后擦除保留区的block,重新写保留区的sector。
 
 
 

回复

73

帖子

0

TA的资源

一粒金砂(初级)

9
 
保留区没有block概念。
典型的,如:某2G的SD卡,FAT16文件系统,保留区占1 个sector,然后是2个FAT表,每个占236 sectors,然后是数据区。每个block包含64个setctors,每个sector是512字节。

每次擦除只能以block(32 sectors),而保留区只有1个扇区,FAT表也不是block的整数倍。那如何擦除保留区和FAT表?
 
 
 

回复

67

帖子

0

TA的资源

一粒金砂(初级)

10
 
我现在用的是STM32F103VE,编译、调试环境是Keil uVision4,它自带的FAT源码里,我没完全看懂,不知道这个是不是擦除函数,如果是的话,那擦除就成了以sector为单位的了……
static BOOL clear_clus (U32 clus) {
   /* Clear current cluster. */
   U32 i;
   U32 sect = clus_to_sect(clus);

   /* Use cache for faster write. */
   memset(ca.buf, 0, 512);
   for (i = 0; i < mmc.SecPerClus; i++) {
      EX(write_cache(sect + i),__FALSE);
   }
   /* Flush the cache buffer when done. */
   EX(write_cache (0),__FALSE);
   return (__TRUE);
}
擦除整个disk用的是:
static BOOL wipe_disk (U32 dsize) {
   /* Clear the whole disk, write FF to all sectors. */
   U32 i,csize;

   /* Invalidate the cache. */
   ca.nwr = 0;
   ca.nrd = 0;

   /* Use the cache buffer. */
   csize = _MC_CSIZE;   /* 8 */
   if (csize == 0) {
      csize = 1;
   }
   memset (ca.buf, 0xFF, csize * 512);

   for (i = 0; i < dsize; i += csize) {
      EX(mmc_write_sect (i, ca.buf, csize),__FALSE);
   }
  return (__TRUE);
}
好像也是以sector为单位……
 
 
 

回复

67

帖子

0

TA的资源

一粒金砂(初级)

11
 
引用 8 楼 nf0yxpkdtt 的回复:
保留区没有block概念。
典型的,如:某2G的SD卡,FAT16文件系统,保留区占1 个sector,然后是2个FAT表,每个占236 sectors,然后是数据区。每个block包含64个setctors,每个sector是512字节。

每次擦除只能以block(32 sectors),而保留区只有1个扇区,FAT表也不是block的整数倍。那如何擦除保留区和FAT表?


你没有理解驱动分层的概念, Block的概念只有在NAND的驱动层才能够看到, 驱动层给上层提供的接口就是以Sector为单位了, 对于FAT应用层而言, 看到的就是Sector为单位的操作, 根本看不到Block, 不要在逻辑上把这两层混合在一起考虑.


 
 
 

回复

90

帖子

0

TA的资源

一粒金砂(初级)

12
 
楼上正解,两层概念不要弄在一起。
你说的nand的block处理等都属于driver层次的。这个部分都是nand特性的一些处理。这部分有bad block处理等。
而你的FAT是属于文件系统。在driver的上层。对于文件系统层来说,就会把这些flash啊磁盘啊SD卡等介质会做成一个标准特性,就是楼主说的按sector读写,这样用不同存储介质的话,也可以通用这个FAT了。,就可能会有一些sector的操作了。也会考虑到坏块的问题。

再往上层的话,flash对于应用程序来说,就是一个大的磁盘空间,根本不用考虑坏块啊,sector,block之类的概念。

我觉得楼主要做的是在nand driver里面,Fat需要的一些特性写进入就ok。比如统计sector的数目啊。坏的数目等等。
 
 
 

回复

78

帖子

0

TA的资源

一粒金砂(初级)

13
 
簇与扇区与针对硬盘的,而sector与block是针对NAND FLASH的,上层的FAT文件系统使用簇与扇区,底层使用sector与block.下面是转换的函数:
static Addr LBAtoCHS(FlashInfo *pFlashInfo, Addr lba)
{
    if(lba.type == CHS)
        return lba;

    Addr chs;
    DWORD tmp = pFlashInfo->dwNumBlocks * pFlashInfo->wSectorsPerBlock;

    chs.type = CHS;
    chs.chs.cylinder = (WORD)(lba.lba / tmp);
    tmp = lba.lba % tmp;
    chs.chs.head = (WORD)(tmp / pFlashInfo->wSectorsPerBlock);
    chs.chs.sector = (WORD)((tmp % pFlashInfo->wSectorsPerBlock) + 1);

    return chs;
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
static Addr CHStoLBA(FlashInfo *pFlashInfo, Addr chs)
{
    Addr lba;

    if(chs.type == LBA)
        return chs;

    lba.type = LBA;
    lba.lba = ((chs.chs.cylinder * pFlashInfo->dwNumBlocks + chs.chs.head)
        * pFlashInfo->wSectorsPerBlock)+ chs.chs.sector - 1;

    return lba;
}

FAT表、DBR要修改的时候,会在新的free sector写新的FAT表、DBR数据,然后把以前用的sector标为dirty sector。如果没有free sector的时候,文件系统会擦除dirty sector占用的block,从而得到新的free sector。
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条
报名最后一周!2025 英飞凌消费、计算与通讯创新大会-北京站
会议时间:3月18日(周二)09:30签到
参会奖励:电动螺丝刀套装、户外登山包、京东卡

查看 »

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

 
机器人开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表