MTD bad Block issue

2024-05-28 06:58
文章标签 block bad issue mtd

本文主要是介绍MTD bad Block issue,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

轉載自http://www.stlinux.com/howto/NAND/BadBlocks

Sometimes, an attempt to erase a bad block may appear to work. However, this does not mean that the block is usable. Even if subsequent write operations may appear to work, the reliability of the data cannot be guaranteed. In addition, attempting to erase a bad block risks erasing the MBBM and in some circumstances it may be impossible to recover this information, if further erase operations appear to work. This is obviously a dangerous state of affairs and should be avoided at all costs.

 

全文如下

Bad Blocks

It is in the nature of NAND Flash that a small proportion of the blocks in the device are defective and therefore unusable from the day of manufacture (typically up to 1% is deemed acceptable by the manufacturer). Manufacturers perform thorough testing to identify any potentially bad blocks. When they have been identified, bad blocks are marked with a special marker in the OOB area of the block. This is the Manufacturer's Bad Block Marker (MBBM).

In addition, blocks become "worn" with use and stop being usable after a certain number of write and erase cycles. This condition presents itself by an error flag being set in the NAND device following an Erase operation. The software that manages the NAND device must implement a "wear-leveling" algorithm to ensure that no blocks suffer from excessive use in comparison to the others. If wear leveling is not implemented, this will dramatically reduce the lifetime of the device. The NAND-aware filesystems supported by STMicroelectronics all implement some form of wear-levelling strategy.

Sometimes, an attempt to erase a bad block may appear to work. However, this does not mean that the block is usable. Even if subsequent write operations may appear to work, the reliability of the data cannot be guaranteed. In addition, attempting to erase a bad block risks erasing theMBBM and in some circumstances it may be impossible to recover this information, if further erase operations appear to work. This is obviously a dangerous state of affairs and should be avoided at all costs.

The important point to note is that once a block has been identified as bad, either by the manufacturer or later becasue of an erase failure, that block must be excluded from further use.

Bad Block Management

To cope with the presence of bad blocks, the software must employ some form of bad block management. Typically, it uses a Bad Block Table (BBT) to record all known bad blocks that are present on a device. Before reading from or writing to the NAND device, the software consults theBBT to determine the locations that are safe to use. It must also monitor the status of Erase operations, with all failures being recorded in the BBT.

There are two types of BBT: NAND resident (that is, permanently stored in the NAND device itself) and RAM resident (stored only in volatile SDRAM and therefore regenerated on each boot).

RAM resident BBT

RAM-resident BBTs are volatile and must be recreated every time the system is booted. The process involves scanning each block in the NAND device to check for bad block markers.

The main advantage of this approach is simplicity. This is particularly true for manufacturability, where is is possible for a generic NAND programmer to program pre-prepared images without the need to understand the underlying ECC scheme or any BBT formats.

There are, however, a number of disadavantages. In some cases these disadvantages preclude the use of RAM-resident BBTs.

  • Performance: Typically, scanning the device for bad block markers takes considerably more time than retrieving the BBT from the NAND device.
  • Marking worn blocks: Blocks that go bad through use must be marked in such a way that they can be detected on subsequent scans. Typically, this involves writing a marker in the OOB area, similar to the manufacturer's marker. However, since the block has gone bad, there is no guarantee that writing a bad block marker will succeed. The block will then fail to be detected as bad on subsequent scans which may lead to data corruption if used later.
  • ECC layout clashes with the MBBM location: Certain ECC layouts store the ECC data in the same location in the OOB area as that used by the MBBM. This means that after a page has been programmed, the ECC data may be incorrectly interpreted as an MBBM leading to false-positive bad blocks. In some cases, this issue can be avoided by adding tags to the ECC data. In other cases, there is no viable solution, other than to use NAND-resident BBTs.

NAND resident BBT

The use of NAND-Resident BBTs overcomes many of the issues associated with RAM-resident BBTs. For most cases this is the recommended method for recording and tracking bad blocks.

As a NAND-resident BBT is non-volatile, it is preserved across system boots. There should never be any reason to recreate the BBT by scanning the NAND device for bad block markers.

Typically, the BBT requires two bits of storage for each block. The table is stored in the last good block with a backup in the penultimate good block. By default, the last four physical blocks are reserved for BBTs. If there are fewer than two good blocks available in the last four, then the NAND device should be discarded.

In a ideal situation, the BBT should be built and written to Flash before any other data. This is mandatory in cases where it is not possible to use the ECC tags to distinguish between valid programmed ECC data and an MBBM. However, this has implications for manufacturability, as the NAND programmer needs to be taught how to write the BBT, including the relevant ECC scheme.

In some cases, it may be appropriate for the NAND Programmer to skip writing BBTs, and to defer BBT creation to the software drivers when the system is first booted. This avoids the complexities of customising the NAND Programmer, whilst retaining the benefits of using NAND-residentBBTs. This approach is only viable if there is no clash between the ECC layout and the MBBM location, or where ECC tags can be used to avoid ECC data being misinterpreted as a MBBM.


===================實際案例===============================

1.

If there are fewer than two good blocks available in the last four, then the NAND device should be discarded.

Bad eraseblock 2044 at 0x0000ff800000
Bad eraseblock 2045 at 0x0000ffa00000
Bad eraseblock 2046 at 0x0000ffc00000
Bad eraseblock 2047 at 0x0000ffe00000
No space left to write bad block table

4G flash的最後4block都壞掉了,所以這顆nand flash開不了機

 

2.

使用我自己寫的flash read and write 程式

nand flash是256MB,切成兩顆mtd0:128MB, mtd1:128MB

nand_erase_nand: attempt to erase a bad block at page 0x0001ff00

nand_erase_nand: attempt to erase a bad block at page 0x0001ff40

nand_erase_nand: attempt to erase a bad block at page 0x0001ff80

nand_erase_nand: attempt to erase a bad block at page 0x0001ffc0

對照用ioctl(fd, MEMGETBADBLOCK, &offset)抓出錯誤的block起始位置

Skipping bad block at 0x07f80000

Skipping bad block at 0x07fa0000

Skipping bad block at 0x07fc0000

Skipping bad block at 0x07fe0000

NOTE: 1block=64pages

此顆nand flash, 1 block=128K,所以1page=2K

因為我是以mtd1作實驗,所以page的數量要先減掉mtd0的page數

mtd0 page數為 128MB=0x8000000, 1page=2K=0x800.所以mtd0 page數為0x10000

0x0001ff00->0xff00, 0xff00*0x800(2K)=0x7f80000

0x0001ff40->0xff40, 0xff40*0x800=0x7fa0000

0x0001ff80->0xff80, 0xff80*0x800=0x7fc0000

0x0001ffc0->0xffc0, 0xffc0*0x800=0x7fe0000


这篇关于MTD bad Block issue的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1009856

相关文章

[Linux Kernel Block Layer第一篇] block layer架构设计

目录 1. single queue架构 2. multi-queue架构(blk-mq)  3. 问题 随着SSD快速存储设备的发展,内核社区越发发现,存储的性能瓶颈从硬件存储设备转移到了内核block layer,主要因为当时的内核block layer是single hw queue的架构,导致cpu锁竞争问题严重,本文先提纲挈领的介绍内核block layer的架构演进,然

block对变量捕获的方式

之前见很多文章对block捕获变量的方法,会进行诸如此类的描述:“block会捕获被引用的变量, 并对其进行copy操作, 因此, 可能会导致其引用计数加1,如果处理不好, 可能因循环引用导致内存泄漏。” 实际上, 这种说法并不严谨。block对变量的捕获, 根据变量类型的不同,会采用不同的捕获方式。 (1)静态或者全局变量, 在block中直接是指针传递的方式传入block中,对其进行的操作

Linux block_device gendisk和hd_struct到底是个啥关系

本文的源码版本是Linux 5.15版本,有图有真相: 1.先从块设备驱动说起 安卓平台有一个非常典型和重要的块设备驱动:zram,我们来看一下zram这个块设备驱动加载初始化和swapon的逻辑,完整梳理完这个逻辑将对Linux块设备驱动模型有深入的理解。 zram驱动加载的时候会调用zram_add函数,源码如下: 1887/*1888 * Allocate and initia

【python requests错误】Caused by SSLError(SSLError(bad handshake: SysCallError(104, 'ECONNRESET')

错误描述: 在发送get请求时错误,执行下面一句时报错了: response = requests.get(image_url) 原因HTTPSConnectionPool(host='test-kkbuluo-resource.cdn.hzmltest.com', port=443): Max retries exceeded with url: /IMCORE/RESOURCE/LOG

Oracle - ORA-01789: Query block has incorrect number of result columns

一、原因     这个错误一般是在执行表之间的相加(union),相减(minus)等SQL语句时,两个个查询块具有不一致的结果列数所导致的。 二、方案     只要将两段SQL语句的列数调整为一致就可以解决。使用union时,要注意数据库字段的格式要一致,如varchar和nvarchar是不一样的。

nacos Spring cloud 报错 URI is not absolute、service not found、502 bad gateway

- 服务没找到,请加入依赖 <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-loadbalancer</artifactId></dependency> - 如果是 "URI is not absolute" , 将URL变成固定的字符串,例如

ARC下的block导致的循环引用问题解析

引言 使用block已经有一段时间了,感觉自己了解的还行,但是几天前看到CocoaChina上一个关于block的小测试主题:【小测试】你真的知道blocks在Objective-C中是怎么工作的吗?,发现竟然做错了几道,才知道自己想当然的理解是错误的,所以抽时间学习了下,并且通过一些测试代码进行测试,产生这篇博客。 Block简介(copy一段) Block作为C语言的扩展,并不是高新

前端面试:对BFC规范(块级格式化上下文:block formatting context)的理解

块级格式化上下文(BFC)是一个独立的渲染区域,具有特定的布局规则。理解BFC对于前端开发非常重要,因为它影响元素的布局和定位。以下是对BFC的一些关键理解: 定义:BFC是一个HTML文档中的部分区域,内部的元素在该区域内独立于外部元素进行布局。BFC的创建可以通过特定的CSS属性,如overflow(非visible)、display: flow-root、position: absolut

git or vscode-电脑电源断或者蓝屏-重启运行项目git报错-git : bad signnature 300000

1.场景         电脑电源断或者蓝屏-重启运行项目git报错-git : bad signnature 300000; 2.解决         2.1.git下的index文件损坏,直接删除;         2.2在.git文件目录运行重新回到上次节点或者指定版本 git reset

猫猫学iOS 之BLOCK的妙用_利用block实现链式编程

猫猫分享,必须精品 原创文章,欢迎转载。转载请注明:翟乃玉的博客 地址:http://blog.csdn.net/u013357243 一:场景 我们有个对象人,他有两个方法,一个是学习study,一个是跑步run, 这个人有个怪癖,跑完步之后必须学习,为了实现这个方法并且能调用方便,我们让跑步和学习都回返回自己这个对象作为下一次调用的快捷方式,代码如下: 调用: int main(