A method for marking bad blocks in NAND flash memory
Patent Information
- Application Number
- CN202310916900.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-24
- Publication Date
- 2026-11-03
- Estimated Expiration
- 2043-07-24
AI Technical Summary
Existing methods for managing bad blocks in NAND flash memory are insufficient in terms of versatility and hardware cost, and cannot effectively manage bad blocks generated during manufacturing and use.
A software approach is used to create a bad block table, including a master table and a mirror table. Bad block information is marked by scanning the OOB area of the NAND FLASH, and the bad block information sequence is built and updated in memory to ensure the reliability and fast response of the bad block table.
It enables rapid generation of bad block information, ensuring high efficiency of read and write operations and reliability of the bad block table, reducing hardware costs, and adapting to the management needs of different NAND FLASH devices.
Smart Images

Figure CN116909483B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer technology, especially the field of NAND FLASH devices, and relates to a method for marking bad blocks in NAND FLASH, which is applicable to the management of bad blocks in general NAND FLASH devices. Background Technology
[0002] With the rapid development of electronic and network technologies, there is an increasing demand for high-capacity storage devices. NAND flash memory, a mainstream storage device, has emerged to meet this demand. Based on charge storage flash memory technology, it boasts high density, low cost, and high-speed read / write capabilities, satisfying user needs. However, bad blocks caused by unavoidable manufacturing defects during NAND flash production and those generated during use introduce instability into the storage device. Therefore, a software approach is needed to manage all bad blocks in NAND flash memory. Two main bad block management methods exist:
[0003] Patent application number 202111157900.3 discloses a bad block management method based on NAND FLASH. This method employs two strategies to manage bad blocks, dividing all blocks into two parts: one for data storage and the other for reservation. When a bad block occurs during use, a replacement strategy is first used to copy the data to be written to the bad block to the reserved part; if the frequency of bad blocks increases, a skip strategy is adopted, directly skipping the current bad block and writing to the next bad block. Although this method can improve block utilization, due to the continuous improvement of NAND FLASH manufacturing processes, the bad block rate generated during use is not very high, and there is no need to sacrifice a large amount of software copying and computation time for strategy switching.
[0004] Patent No. 201210414610.7 discloses a flash memory and a method for bad block management. This method utilizes the NAND flash memory itself for bad block management. When a user sends read / write commands to the NAND flash, the NAND flash internally maps the data. If the mapped block is a good block, it is read or written; if the mapped block is a bad block, the bad block information is updated and stored in a specific area within the NAND flash. While this method provides bad block management internally, eliminating the need for user intervention, it lacks versatility and cannot meet the current requirements for bad block management in general NAND flash memory. Furthermore, the addition of multiple processing units significantly increases the hardware cost of the NAND flash. Summary of the Invention
[0005] The purpose of this invention is to provide a method for marking bad blocks in NAND FLASH, using software to manage bad blocks generated during the manufacturing and use of NAND FLASH.
[0006] The method steps of this invention are as follows:
[0007] Step (1) Set one or more blocks at the beginning or end of the NAND FLASH as bad block table storage space to store bad block tables; the bad block table is special data used to manage bad block information of NAND FLASH, including a master table and a mirror table; the block is a data storage unit in NAND FLASH, each block contains n pages, n is usually 64; the page is the basic unit of reading and writing;
[0008] Step (2) Scan the storage space of the bad block table to determine whether there is header description information of the bad block table main table or mirror table: if not, it means that there is no bad block table, and proceed to step (3); if there is header description information of the main table or mirror table, it means that there is a bad block table, and proceed to step (4).
[0009] Step (3) Create a bad block table based on the bad block markings of the NAND FLASH at the factory, and then execute step (5); specifically:
[0010] (3-1) Request two memory spaces from memory. The first memory space is used to store the bad block information sequence, and the second memory space is used to store the bad block table information, including the main table and the mirror table.
[0011] (3-2) Scan the OOB area corresponding to the first PAGE in each BLOCK of NAND FLASH. The OOB area is an additional storage area in NAND FLASH other than the main data storage area. The first two bytes are the bad block mark at the factory. If it is not a bad block, it is marked as 0xFF. If it is a bad block, it is marked as non-0xFF.
[0012] (3-3) If the first two bytes of the OOB region are not both 0xFF, it means that the current block is a bad block generated at the factory. The BLOCK corresponding to the OOB region is marked with bad block description information and the bad block description information is stored in the first memory space. If the first two bytes of the OOB region are both 0xFF, it means that the current block is a good block. The BLOCK corresponding to the OOB region is marked with good block description information and the good block description information is stored in the first memory space.
[0013] (3-4) Scan all BLOCKs sequentially, arrange the description information of bad blocks or good blocks in order to form a bad block information sequence, store it in the first memory space, and indicate the offset of each bad block on the NAND FLASH;
[0014] (3-5) Based on the bad block information sequence, determine whether each block in the bad block table storage space is a good block or a bad block;
[0015] If the bad block table storage space contains multiple blocks that are good blocks, then two blocks that are good blocks are selected for erasure, and these two blocks are marked in the bad block information sequence with bad block description information to form a new bad block information sequence.
[0016] If the bad block table storage space contains only one good block, then that block is erased and marked in the bad block information sequence with bad block description information to form a new bad block information sequence.
[0017] If the bad block table storage space does not contain any blocks that are good blocks, the bad block information sequence will not be updated;
[0018] Store the new sequence of bad block information in the first memory space;
[0019] (3-6) Construct the main table of the bad block table and store it in the second memory space. The main table information includes the main table header description information, version number, reserved bytes, number of NAND FLASH blocks, updated bad block information sequence, and CRC value calculated based on the above information. The CRC value is used to detect and verify whether data errors occur during transmission.
[0020] (3-7) Construct a mirror table of the bad block table and store it in the second memory space. The mirror table information includes the mirror table header description information, version number, reserved bytes, number of NAND FLASH BLOCKs, updated bad block information sequence, and CRC value calculated based on the above information. The mirror table header description information is set to be different from the main table header description information. (3-8) If there are multiple good blocks in the bad block table storage space, the main table and mirror table of the bad block table are stored in the first page of the two erased blocks respectively.
[0021] If the bad block table storage space has only one BLOCK that is a good block, then the main table of the bad block table will be stored in the first PAGE of the erased BLOCK;
[0022] If there are no blocks in the bad block table storage space that are good blocks, then neither the main table nor the mirror table of the bad block table will be stored in NAND FLASH.
[0023] Step (4) Update the bad block table of the NAND FLASH, and then execute step (5); specifically:
[0024] (4-1) Read the bad block table of NAND FLASH into memory, compare the version information of the main bad block table and the mirror table, and use the table with the larger version number as the bad block table. If the version numbers are the same, use the main table as the determined bad block table.
[0025] (4-2) Update the main table and mirror table of bad blocks of NAND FLASH using the determined bad block table. The updated main table and mirror table are identical except for the header description information and CRC value.
[0026] Step (5) Perform read, write, and erase operations on the NAND FLASH. First, use the bad block table to retrieve bad block information. If the BLOCK covered by the current read, write, and erase operation is a bad block, skip the current BLOCK and operate on the next BLOCK; otherwise, operate on the current BLOCK. If the write and erase operations fail, mark the current BLOCK with bad block description information to form a new bad block information sequence, update the bad block table used, skip the current BLOCK, and operate on the next BLOCK.
[0027] When a bad block table is needed, the bad block table in the bad block table storage space is used first. If both the main table and the mirror table exist, the main table is used. If the bad block table does not exist in the bad block table storage space, the main table in the second memory space is used.
[0028] This invention scans all blocks only during the initial startup phase. Subsequent startup operations only read bad block information from the bad block table. This means that bad block information is generated by reading all blocks only once, enabling rapid response to user read, write, and erase operations. When creating the bad block table, this invention simultaneously creates a master table and a mirror table to prevent the entire bad block table from becoming unusable due to the failure of one table. Each table is provided with a version number, so normal operation is possible as long as information from one bad block table is available. Furthermore, during bad block table creation, the method allows configuration to select which blocks to use as storage space. Even when all configured blocks are bad, the memory-based bad block table can still be used, ensuring the normal functioning of the bad block table. This invention is simple to use, capable of retrieving current block information from the bad block table based on the block where the current read, write, and erase operation occurs, and quickly updating the bad block information when a bad block is generated. Attached Figure Description
[0029] Figure 1 This is a flowchart illustrating the method of the present invention. Detailed Implementation
[0030] The technical solution of the present invention will be further described below with reference to the embodiments.
[0031] A method for marking bad blocks in NAND flash memory, specifically:
[0032] Step (1) Select the last 4 blocks of NAND FLASH as the bad block table storage space to store the bad block table.
[0033] Step (2) Read the first PAGE of each BLOCK sequentially from the end of the bad block table storage space backwards to check if there is bad block table main table header description information. If not, read it again to check if there is bad block table mirror table header description information. If neither is present, a bad block table needs to be created and step (3) is executed. If there is header description information of the main table or mirror table, it indicates that a bad block table exists and step (4) is executed.
[0034] Step (3) Create a bad block table based on the bad block markings of the NAND FLASH at the factory, and then execute step (5); specifically:
[0035] (3-1) Allocate two memory spaces to memory, where: the first memory space is used to store the bad block information sequence, using 2 bits of data to describe the good or bad status of a BLOCK: where 11 represents that the block is a good block, 00 represents that it is a factory bad block, and 01 and 10 represent bad blocks generated during use; the second memory space is used to store bad block table information, including the main table and the mirror table;
[0036] (3-2) Scan the OOB region corresponding to the first page in each block of the NAND FLASH;
[0037] (3-3) If the first two bytes of the OOB region are not both 0xFF, it means that the current block is a bad block generated at the factory. The BLOCK corresponding to the OOB region is marked with bad block description information, and the bad block description information of the block is stored in the first memory space with 00. If the first two bytes of the OOB region are both 0xFF, it means that the current block is a good block. The BLOCK corresponding to the OOB region is marked with good block description information, and the good block description information of the block is stored in the first memory space with 11.
[0038] (3-4) Scan all BLOCKs sequentially, arrange the bad block and good block description information in order, construct a bad block information sequence, store it in the first memory space, indicating the offset of each bad block on the NAND FLASH;
[0039] (3-5) Based on the bad block information sequence, determine whether each block in the bad block table storage space is a good block or a bad block;
[0040] If the bad block table storage space contains multiple blocks that are good blocks, then two blocks that are good blocks are selected for erasure, and these two blocks are marked in the bad block information sequence with bad block description information to form a new bad block information sequence.
[0041] If the bad block table storage space contains only one good block, then that block is erased and marked in the bad block information sequence with bad block description information to form a new bad block information sequence.
[0042] If the bad block table storage space does not contain any blocks that are good blocks, the bad block information sequence will not be updated;
[0043] Store the new sequence of bad block information in the first memory space;
[0044] (3-6) Construct the main table of bad block table and store it in the second memory space. The main table information includes the main table header description information, version number set to 1, one byte reserved, the number of blocks contained in the entire NAND FLASH converted to hexadecimal, the updated bad block information sequence, and the 4-byte CRC value calculated based on the above information.
[0045] (3-7) Construct a mirror table of the bad block table and store it in the second memory space. The mirror table information includes the mirror table header description information, the version number is set to 1, one byte is reserved, the number of blocks contained in the entire NAND FLASH is converted to hexadecimal, the updated bad block information sequence, and the 4-byte CRC value calculated based on the above information.
[0046] The mirror table and the main table are identical except for the header description information and CRC value.
[0047] (3-8) If the bad block table storage space has multiple blocks that are good blocks, then the main table and the mirror table of the bad block table are stored in the first page of the two blocks after erasure; the subsequent blocks store the main table, and the bad block table uses the information from the main table.
[0048] If the bad block table storage space has only one BLOCK that is a good block, then the main table of the bad block table is stored in the first PAGE of the erased BLOCK, and the bad block table uses the information from the main table;
[0049] If there are no blocks in the bad block table storage space that are good blocks, then neither the main table nor the mirror table of the bad block table is stored in NAND FLASH. Instead, the bad block table information stored in the second memory space is used. This process is repeated every time the driver starts to create a memory-based bad block table.
[0050] Step (4) Update the bad block table of the NAND FLASH, and then execute step (5); specifically:
[0051] (4-1) Read the bad block table of NAND FLASH into memory, compare the version information of the main bad block table and the mirror table, and use the table with the larger version number as the bad block table. If the version numbers are the same, use the main table as the determined bad block table.
[0052] (4-2) Update the main table and mirror table of bad blocks of NAND FLASH using the determined bad block table. The updated main table and mirror table are identical except for the header description information and CRC value.
[0053] Step (5) Perform read, write, and erase operations on the NAND FLASH. First, use the bad block table to retrieve bad block information. If the BLOCK covered by the current read, write, and erase operation is a bad block, skip the current BLOCK and operate on the next BLOCK; otherwise, operate on the current BLOCK. If the write and erase operations fail, mark the current BLOCK with bad block description information to form a new bad block information sequence, update the bad block table used, skip the current BLOCK, and operate on the next BLOCK.
[0054] When a bad block table is needed, the bad block table in the bad block table storage space is used first. If both the main table and the mirror table exist, the main table is used. If the bad block table does not exist in the bad block table storage space, the main table in the second memory space is used.
[0055] The above embodiments are merely preferred embodiments of the present invention. It should be understood that those skilled in the art can design many other modifications and embodiments. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for marking bad blocks in NAND flash memory, characterized in that: Step (1) Set one or more blocks at the beginning or end of the NANDFLASH as bad block table storage space to store the bad block table; Step (2) Scan the storage space of the bad block table to determine whether there is header description information of the bad block table main table or mirror table: if not, it means that there is no bad block table, and proceed to step (3); if there is header description information of the main table or mirror table, it means that there is a bad block table, and proceed to step (4). Step (3) Create a bad block table based on the bad block markings of the NAND FLASH at the factory, and then execute step (5); specifically: (3-1) Request two memory spaces from memory. The first memory space is used to store the bad block information sequence, and the second memory space is used to store the bad block table information, including the main table and the mirror table. (3-2) Scan the OOB region corresponding to the first PAGE in each BLOCK of the NANDFLASH; (3-3) If the first two bytes of the OOB region are not both 0xFF, it means that the current block is a bad block generated at the factory. The BLOCK corresponding to the OOB region is marked with bad block description information and the bad block description information is stored in the first memory space. If the first two bytes of the OOB region are both 0xFF, it means that the current block is a good block. The BLOCK corresponding to the OOB region is marked with good block description information and the good block description information is stored in the first memory space. (3-4) Scan all BLOCKs sequentially, arrange the description information of bad blocks or good blocks in order, form a bad block information sequence, and store it in the first memory space; (3-5) Based on the bad block information sequence, determine whether each block in the bad block table storage space is a good block or a bad block; If the bad block table storage space contains multiple blocks that are good blocks, then two blocks that are good blocks are selected for erasure, and these two blocks are marked in the bad block information sequence with bad block description information to form a new bad block information sequence. If the bad block table storage space contains only one good block, then that block is erased and marked in the bad block information sequence with bad block description information to form a new bad block information sequence. If the bad block table storage space does not contain any blocks that are good blocks, the bad block information sequence will not be updated; Store the new sequence of bad block information in the first memory space; (3-6) Construct the main table of the bad block table and store it in the second memory space. The main table information includes the main table header description information, version number, reserved bytes, number of NAND FLASH blocks, updated bad block information sequence, and CRC value calculated based on the above information. The CRC value is used to detect and verify whether data errors occur during transmission. (3-7) Construct a mirror table of the bad block table and store it in the second memory space. The mirror table information includes the mirror table header description information, version number, reserved bytes, number of NAND FLASH blocks, updated bad block information sequence, and CRC value calculated based on the above information. The mirror table header description information is set to be different from the main table header description information. (3-8) If the bad block table storage space has multiple blocks that are good blocks, then store the main table and the mirror table of the bad block table in the first page of the two blocks after erasure. If the bad block table storage space has only one BLOCK that is a good block, then the main table of the bad block table will be stored in the first PAGE of the erased BLOCK; If there are no blocks in the bad block table storage space that are good blocks, then neither the main table nor the mirror table of the bad block table will be stored in NAND FLASH. Step (4) Update the bad block table of NAND FLASH, and then execute step (5); specifically: (4-1) Read the bad block table of NANDFLASH into memory, compare the version information of the main bad block table and the mirror table, and use the table with the larger version number as the bad block table. If the version numbers are the same, use the main table as the determined bad block table. (4-2) Update the main table and mirror table of bad blocks of NANDFLASH using the determined bad block table. The updated main table and mirror table are identical except for the header description information and CRC value. Step (5) Perform read, write, and erase operations on the NAND FLASH. First, use the bad block table to retrieve bad block information. If the BLOCK covered by the current read, write, and erase operation is a bad block, skip the current BLOCK and operate on the next BLOCK; otherwise, operate on the current BLOCK. If the write and erase operations fail, mark the current BLOCK with bad block description information to form a new bad block information sequence, update the bad block table used, skip the current BLOCK, and operate on the next BLOCK. When a bad block table is needed, the bad block table in the bad block table storage space is used first. If both the main table and the mirror table exist, the main table is used. If the bad block table does not exist in the bad block table storage space, the main table in the second memory space is used.
2. The NAND flash bad block marking method as described in claim 1, characterized in that: The bad block table is a special data used to manage bad block information in NAND FLASH, including a master table and a mirror table; the BLOCK is the data storage unit in NAND FLASH; and the PAGE is the basic unit for reading and writing.
3. The NAND flash bad block marking method as described in claim 1, characterized in that: The OOB area is an additional storage area in NAND FLASH besides the main data storage area. The first two bytes are the bad block marker at the factory. If it is not a bad block, it is marked as 0xFF; if it is a bad block, it is marked as non-0xFF.
Citation Information
Patent Citations
Flash memory and bad block managing method thereof
CN103778065A
A bad block management method based on NAND Flash
CN113921071B
Method and device for writing data by NAND FLASH
CN104778127A
Bad block processing method of NAND FLASH
CN110597458A
