What's Nand Flash and Bad block?

Oct 25, 2022

1 NAND FLASH

1.1 Introduction of NAND FLASH Memory

NAND FLASH Memory, Chinese name flash memory. It gets its name because of its fast erasing speed.

NAND FLASH was invented by Mr. Fujio Masuoka of Japan's Toshiba Group. Different from other storage devices, NAND FLASH data lines and address lines are multiplexed, and address lines cannot be used for random addressing. Therefore, NAND FLASH uses page pages as the reading unit (generally a single page is 2K Bytes), and blocks as the erasing unit. (Generally a single block is 128KB or 256KB). After sending an erase command, NAND FLASH erases all blocks to 1 at a time, and all the contents inside become 0xFF. Because the erasing time is very short, it is as fast as lightning. So we call this memory FLASH Memory.


1.2 Hardware Implementation Mechanism of NAND FLASH

The basic unit of NAND FLASH is a MOSFET with a floating gate.

Data is stored in the form of electrical charge in Flash memory cells. The amount of stored charge depends on the voltage applied to the external gate. The representation of the data is represented by whether the voltage of the stored charge exceeds a specific threshold Vth, and if the stored charge is enough and exceeds the threshold Vth, it represents 1. For writing 0, it is to discharge it, and the charge is reduced to less than Vth, which means 0.


2 Bad Block

2.1 Definition of Bad block

Since the process of NAND Flash cannot guarantee the reliability of the performance of the NAND Memory Array during its life cycle, bad blocks will occur during the production and use of NAND. The characteristics of bad blocks are: when programming/erasing this block, some bits cannot be pulled high, which will cause errors in Page Program and Block Erase operations.


2.2 Classification of bad blocks: factory bad block FBB & used bad block GBB

(1) FBB: Factory Bad Block, the factory bad block, the bad block that has just left the factory, is called Masked bad block or initial bad/invalid block. When NAND Flash leaves the factory, there will be a certain amount of bad blocks due to the manufacturing process. At the same time, the original factory will test the NAND FLASH before leaving the factory, and the blocks used for the test may also be marked as bad blocks by the original factory.

Before leaving the factory, the original factory will mark the bad blocks. The specific mark is that for the common NAND Flash with a page size of 2K, for NAND flash, the bad block mark is generally located on the first page of each block. The first byte of the page spare area. Specifically, you can query the datasheet of different products. If it is not 0xFF, it means that it is a bad block. Correspondingly, all normal blocks, good blocks, and all data in them are 0xFF.

(2) GBB: Grown Bad Block, using bad blocks. During the use of NAND Flash, because the erasing and writing life of NAND Flash is limited (generally no more than 100,000 times), bad blocks will also occur after a certain period of use. If a Block Erase or Page Program error is found, the block can be marked as a bad block. In order to be consistent with the inherent bad block information, the first byte (byte) of the spare area will also be marked with other values other than 0xFF.


2.3 Bad block table:

The first block of a flash must be good when it leaves the factory, otherwise it means that the entire flash cannot be used. Because generally the first block will be used to save the bad block table (BBT, Bad Block Table). Due to the working mechanism of bad block management (Bad Block Management) in the NAND Flash driver under the Linux kernel MTD architecture and the NAND Flash driver of UBOOT, after loading the driver, if you do not add parameters, you actively ask to skip the bad block scan. If so, it will actively scan for bad blocks and establish the necessary BBT for later bad block management.


2.4 Number and location of bad blocks

The original NAND FLASH factory will have a standard for the number and location of bad blocks. The original factory generally promises that the number of bad blocks does not exceed 2%, but the location of the bad blocks is not guaranteed (but the first block must be good when it leaves the factory. , because the first one will be used to store BTT). For example, a NAND chip has 2048 blocks, 2048*0.02=40.96, so the number of bad blocks will not exceed 40. But where the bad blocks appear, whether they are continuous or random, there is no guarantee.


2.5 The impact of bad blocks on good blocks

A bad block does not affect the performance of good blocks because it is isolated from the bit lines by select gates)


2.6 Detection of bad blocks

An "erase" operation is performed on these blocks marked as "bad blocks". If the Block Erase error occurs, it proves that the block is a real bad block.


2.7 Notes on Erase Operation

In fact, we can also erase marked bad blocks. After forcibly erased in this way, the bad block information no longer exists. For factory bad blocks, it is generally not recommended to erase the marked information.

There is a command in UBOOT called "nand scrub", which erases all the content in the block, including the bad block mark, whether it is the factory or the new mark that appears in the later use process. It is generally not recommended to use this. When the NAND FLASH factory is produced, NAND bad blocks are tested and marked in a relatively wide temperature and voltage range. These bad blocks can still work under a certain temperature or voltage, but may be changed at another time when the conditions change. failure, becoming a potential ticking time bomb. If the bad blocks marked by the original factory are erased, it is easy to encounter the problem of data loss when writing and saving data.

It is better to use "nand erase" to erase only good blocks, for blocks already marked bad blocks, do not erase.


3 Bad block management

The controller of Device or FLASH will manage bad blocks, which is BBM (Bad Block Management). We will add this later.


Remark

1 Why is a good block marked with 0xff: because the erasing of Nand Flash is to change all the bits of the corresponding block to 1, during the write operation, each bit of the chip can only be changed from 1 to 0, but not. Change from 0 to 1. 0XFF means that all can be erased to 11111111. It indicates that it can be erased successfully, and it is a good block.

———————————————

Copyright statement: This article is an original article by CSDN blogger "Alexander_Lai" and follows the CC 4.0 BY-SA copyright agreement. Please attach the original source link and this statement for reprinting.