Nandflash bad block management method
By dividing the storage space of NandFlash into a boot area, a maintenance area and a mapping area, and setting a bad block management area and a backup in the mapping area, the problem of bad blocks generated during NandFlash's use is solved, which ensures the stability and reliability of the data.
Patent Information
- Application Number
- CN202411724990.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-28
- Publication Date
- 2025-03-21
AI Technical Summary
When the prior art generates bad blocks during NandFlash use, data cannot be accessed in the logical area, resulting in operational impact.
The storage space of NandFlash is divided into 3 areas: the boot area, the maintenance area and the mapping area. The first two blocks of the mapping area are used as the bad block management area, and there are two backups (AB backups), which maintain and detect bad blocks through the bad block management area.
By sacrificing some areas as bad block management areas, ensuring that the maintenance area is not affected by bad blocks, solving the problem that NandFlash generates bad blocks during use and cannot access data.
Smart Images

Figure CN119668504A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of memory technology, and in particular to a Nandflash bad block management method. Background Art
[0002] Nandflash memory is a type of flash memory that uses a nonlinear macrocell mode internally, providing a cheap and effective solution for the implementation of solid-state large-capacity memory. Nandflash memory has the advantages of large capacity and fast rewrite speed, and is suitable for storing large amounts of data. Therefore, it has been increasingly widely used in the industry, such as embedded products including digital cameras, MP3 player memory cards, and compact USB flash drives.
[0003] When NandFlash is shipped from the factory, there will be some bad blocks. These bad blocks that exist at the factory are called factory bad blocks. NandFlash is also prone to bad blocks during use. Once a bad block is generated, it will affect the reading and writing operations of NandFlash. Therefore, it is very necessary to manage the bad blocks of NandFlash. However, in the prior art, if a bad block is generated during the use of NandFlash, data cannot be accessed in the logical area. Therefore, further improvements are needed to the prior art. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a Nandflash bad block management method for the above-mentioned prior art, which allows a specific area of the Nandflash to be unaffected by bad blocks.
[0005] The technical solution adopted by the present invention to solve the above technical problems is: a Nandflash bad block management method, characterized in that: the storage space of Nandflash is divided into three areas, namely, a boot area, a maintenance area and a mapping area, and the first two blocks of the mapping area are used as a bad block management area, and at the same time, the bad block management area has two copies for AB backup;
[0006] Nandflash bad block management method includes bad block maintenance method, specifically:
[0007] After the terminal with the above Nandflash is powered on, try to read the contents of the bad block management area in the Nandflash mapping area and store it in RAM for use;
[0008] If both AB backups are damaged, the mapping area is traversed backward to find the bad block management area, and the entire mapping area is rescanned; if new bad blocks are found during the use of Nandflash, the new bad blocks found are written into the AB backups of the bad block management area in sequence;
[0009] During the startup process of the terminal with the above-mentioned Nandflash, the respective check values of the AB backups and the consistency of the AB backup data are verified. If the check values of the AB backups are incorrect, the entire Nandflash is rescanned; if the AB backup data are inconsistent, the backup with the most bad blocks is used, and the content of the bad block management area is re-updated before updating the other backup content.
[0010] Preferably, the content of the bad block management area includes the status of the corresponding block and the mapping sequence number of the corresponding block.
[0011] Preferably, the status of the corresponding block includes a good block, a bad block, a reserved block and a factory bad block.
[0012] Preferably, if the AB backup data are inconsistent, the backup with the most bad blocks is used, and the mapping sequence numbers of the corresponding blocks in the bad block management area are re-updated.
[0013] Preferably, the checksum values of the AB backups are CRC32 values.
[0014] In order to ensure that the data read and written by the application layer are stable and reliable when in use, a bad block detection method is also included, specifically:
[0015] When the Nandflash fails to be erased, the block in the Nandflash that fails to be erased is determined as a bad block;
[0016] When Nandflash is written successfully, the data is read through software or hardware ECC verification. If the read verification fails, the block that failed the read verification is determined as a bad block;
[0017] When Nandflash is written successfully, the data is read through software or hardware ECC verification. If the ECC check value reaches the preset check digit, the current block is determined to be a bad block.
[0018] Compared with the prior art, the advantages of the present invention are: by dividing the storage space of Nandflash into three areas, namely the boot area, the maintenance area and the mapping area, part of the Nandflash area is sacrificed as the mapping area, so that the maintenance area is not affected by bad blocks, thereby solving the problem that bad blocks are generated during the use of Nandflash and data cannot be accessed in the logical area. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] Figure 1 Schematic diagram of the MTD hierarchical structure in an embodiment of the present invention. DETAILED DESCRIPTION
[0020] The present invention is further described in detail below with reference to the accompanying drawings.
[0021] The storage space of Nandflash is divided into three areas, namely the boot area, maintenance area and mapping area, and the first two blocks of the mapping area are used as the bad block management area. At the same time, the bad block management area has two copies for AB backup;
[0022] Take Nandflash with a total size of 256MB and a block size of 128KB as an example:
[0023] The bad block management method of this solution is referred to as BMT (block manager table), which is actually an expansion of nandflash's bbt (bad block table). BMT divides Nandflash into three areas, as shown in the following table:
[0024]
[0025] Because bad blocks may also appear in the mapping area, the mapping area logically defaults to BMT at the beginning. If a bad block appears or BMT cannot be found, it will be searched in the mapping area in sequence.
[0026] The Nandflash bad block management method in this embodiment includes a bad block maintenance method and a bad block detection method, wherein the bad block maintenance method is specifically as follows:
[0027] After the terminal with the above Nandflash is powered on, an attempt is made to read the content of the bad block management area in the mapping area of the Nandflash and store it in the RAM for use; in this embodiment, the content of the bad block management area includes the status of the corresponding block and the mapping sequence number of the corresponding block; the status of the corresponding block includes a good block, a bad block, a reserved block and a factory bad block;
[0028] If both AB backups are damaged, the mapping area is traversed backward to find the bad block management area, and the entire mapping area is rescanned; if new bad blocks are found during the use of Nandflash, the new bad blocks found are written into the AB backups of the bad block management area in sequence;
[0029] During the startup process of the terminal with the above Nandflash, the checksum values of the AB backups and the consistency of the AB backup data are checked. If the checksums of the AB backups are not correct, the entire Nandflash is rescanned; if the AB backup data are inconsistent, the backup with the most bad blocks is used, and the content of the bad block management area is updated again before updating the content of another backup. Specifically, the checksum values of the AB backups are CRC32 values; if the AB backup data are inconsistent, the backup with the most bad blocks is used, and the mapping sequence number of the corresponding block in the bad block management area is updated again.
[0030] The composition of BMT is as follows:
[0031] bbt: Every 2 bytes represent the status of the corresponding block
[0032]
[00] indicates a good block
[01] indicates a bad block
[10] indicates a reserved block
[11] indicates a factory bad block
[0033] map: every 2 bytes corresponds to the block mapping number;
[0034] For example, to access block0, first access map[block0] to obtain the mapped block number, and then obtain the real flash address; map[block0]->blockn->blockn addr; blockn is the mapped block number, and blocknaddr is the real flash address corresponding to blockn;
[0035] The prerequisite in this embodiment is that the Boot firmware will not be modified frequently or the SOC can ensure to the greatest extent that the Boot can be correctly loaded from Nandflash; because this solution is implemented through a software algorithm, it is only effective after the Boot is started normally; therefore, the Boot firmware cannot be modified frequently to cause bad blocks to affect the startup, otherwise the SOC itself needs to support skipping bad blocks or other backup methods to load the Boot program in Nandflash.
[0036] Usually, Nandflash erase failure is judged as a bad block, but this condition is not completely correct. There may also be abnormal data reading after successful writing. Therefore, many file systems that support Nandflash have their own set of logic when using Nandflash. Therefore, this solution adopts a more rigorous bad block judgment scheme to ensure that the data read and written by the application layer is stable and reliable when in use;
[0037] The above bad block detection method is specifically as follows:
[0038] When the Nandflash fails to be erased, the block in the Nandflash that fails to be erased is determined as a bad block;
[0039] When Nandflash is written successfully, the data is read through software or hardware ECC verification. If the read verification fails, the block that failed the read verification is determined as a bad block;
[0040] When Nandflash is written successfully, the data is read through software or hardware ECC check. If the ECC check value reaches the preset check digit, the current block is judged as a bad block;
[0041] Among them, the reliability of the read data can be verified by ECC (error checking and correction). If bit reversal occurs, it can be corrected to a certain extent. Nandflash generates bad blocks because the number of bit reversals increases and reaches an uncontrollable level. However, this change is gradual and will not suddenly change from none to a lot. Therefore, the ECC result can be used to determine what stage the current Nandflash block is in; for example, if ECC=0 indicates normal, ECC=1 indicates that there are individual bit reversals, ECC=2 indicates that there are a small number of bit reversals, ECC=3 indicates that there are more bit reversals and cannot be corrected, and ECC=4 indicates abnormal reading. Based on this solution, the block can be marked as a bad block during the change of ECC from 2 to 3, thereby avoiding the ECC of this block entering the stage where it cannot be corrected, resulting in data abnormalities.
[0042] like Figure 1 As shown, the Nandflash in this embodiment belongs to the MTD block device. The conventional file system supporting Nandflash controls the maintenance of bad blocks in the block device node between the file system and the MTD block device, and its implementation varies according to different file systems. This solution is deployed between the MTD original device and the FLASH hardware driver layer, so that for the MTD device, the maintenance area of the FLASH can be used as an EMMC (i.e., an embedded multimedia card, a standard for flash memory cards), which can adapt to most file systems.
[0043] In this embodiment, uboot is read in Nandflash, and after running uboot, the Nandflash can be used in the usable area, which can be understood as no bad blocks. You can use io to directly read and write the fixed position of Nandflash or use any file system, regardless of whether the file system supports bad block management. That is, if the prerequisites are met, Nandflash can be used as EMMC.
[0044] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A Nandflash bad block management method, characterized in that: The storage space of Nandflash is divided into three areas, namely the boot area, maintenance area and mapping area, and the first two blocks of the mapping area are used as the bad block management area. At the same time, the bad block management area has two copies for AB backup; Nandflash bad block management method includes bad block maintenance method, specifically: After the terminal with the above Nandflash is powered on, try to read the contents of the bad block management area in the Nandflash mapping area and store it in RAM for use; If both AB backups are damaged, the mapping area is traversed backward to find the bad block management area, and the entire mapping area is rescanned; If new bad blocks are found during the use of Nandflash, the new bad blocks found will be written into the AB backup of the bad block management area in sequence; During the booting process of the terminal with the above Nandflash, the checksum values of the AB backups and the consistency of the AB backup data are checked. If the checksums of the AB backups are not correct, the entire Nandflash is rescanned. If the AB backup data are inconsistent, use the backup with the most bad blocks, re-update the content of the bad block management area, and then update the content of the other backup.
2. The Nandflash bad block management method according to claim 1, characterized in that: The content of the bad block management area includes the status of the corresponding block and the mapping sequence number of the corresponding block.
3. The Nandflash bad block management method according to claim 2, characterized in that: The status of the corresponding blocks includes good blocks, bad blocks, reserved blocks and factory bad blocks.
4. The Nandflash bad block management method according to claim 2, characterized in that: If the AB backup data are inconsistent, the backup with the most bad blocks will be used, and the mapping sequence numbers of the corresponding blocks in the bad block management area will be updated again.
5. The Nandflash bad block management method according to claim 1, characterized in that: The checksum values of the AB backups are CRC32 values.
6. The Nandflash bad block management method according to any one of claims 1 to 5, characterized in that: It also includes bad block detection methods, specifically: When the Nandflash fails to be erased, the block in the Nandflash that fails to be erased is determined as a bad block; When Nandflash is written successfully, the data is read through software or hardware ECC verification. If the read verification fails, the block that failed the read verification is determined as a bad block; When Nandflash is written successfully, the data is read through software or hardware ECC verification. If the ECC check value reaches the preset check digit, the current block is determined to be a bad block.