Flash bad block management method and device, electronic equipment and storage medium

By pre-storing index identifiers of unused physical blocks in flash memory and dynamically adjusting the data storage location upon write request, the problem of wasted flash memory resources is solved, achieving more efficient resource utilization and a longer lifespan.

CN121900694APending Publication Date: 2026-04-21HANGZHOU EZVIZ SOFTWARE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HANGZHOU EZVIZ SOFTWARE CO LTD
Filing Date
2025-12-23
Publication Date
2026-04-21

AI Technical Summary

Technical Problem

Existing bad block management methods lead to wasted flash memory resources and low flash memory resource utilization efficiency.

Method used

The index identifiers of unused physical blocks are pre-stored in the flash memory. When a data write request is made, it is determined whether the target physical block is a bad block. If it is a bad block, a spare physical block is determined from the pre-stored index identifiers for data writing, and the unused physical block is used as a spare physical block.

Benefits of technology

It improves the resource utilization of flash memory, reduces resource waste, and extends the lifespan of flash memory.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121900694A_ABST
    Figure CN121900694A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a flash memory bad block management method and device, electronic equipment and a storage medium. The method comprises the following steps: in response to a first data writing request, acquiring a logic block index identifier corresponding to a writing address requested to be written by the first data writing request as a second index identifier, and acquiring first target data requested to be written by the first data writing request; judging whether the physical block corresponding to the second index identifier is a bad block or not; and if the physical block corresponding to the second index identifier is a bad block, determining a third index identifier in the pre-stored first index identifier, and writing the first target data into the physical block corresponding to the third index identifier. By applying the embodiment of the invention, the resource utilization rate of the flash memory can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of embedded device technology, and in particular to a flash memory bad block management method, apparatus, electronic device and storage medium. Background Technology

[0002] Existing bad block management methods primarily rely on bad block replacement strategies. The principle behind this strategy is to reserve a certain number of spare physical blocks in the flash memory. When a physical block is found to be bad, its valid data is copied to a spare physical block. This bad physical block is then marked as bad, and the correspondence between it and the spare physical block containing the copied valid data is recorded. Subsequently, when accessing the address of this physical block, the system will directly access the spare physical block containing the copied valid data based on this correspondence.

[0003] In practical applications, typically 5% of the total number of physical blocks in a flash memory is reserved as spare physical blocks. For example, in a flash memory with 128MB of space and 128KB physical blocks, the reserved spare physical blocks would total approximately 6MB, meaning the flash memory can only use a maximum of 122MB of space, resulting in a waste of 6MB. In other words, this bad block management method leads to a waste of flash memory resources, resulting in low resource utilization efficiency. Therefore, improving flash memory resource utilization has become an urgent problem to be solved. Summary of the Invention

[0004] The purpose of this application is to provide a flash memory bad block management method, apparatus, electronic device, and storage medium to improve the resource utilization of flash memory. The specific technical solution is as follows:

[0005] This application provides a flash memory bad block management method, applied to flash memory in an electronic device. The flash memory includes multiple partitions, each partition including at least one physical block storing the original data of the partition and at least one unused physical block. The flash memory pre-stores a first index identifier, which is the index identifier of each of the unused physical blocks.

[0006] The method includes:

[0007] In response to the first data write request, obtain the logical block index identifier corresponding to the write address requested by the first data write request, use it as the second index identifier, and obtain the first target data requested by the first data write request.

[0008] Determine whether the physical block corresponding to the second index identifier is a bad block;

[0009] If the physical block corresponding to the second index identifier is a bad block, then a third index identifier is determined from the pre-stored first index identifier, and the first target data is written into the physical block corresponding to the third index identifier.

[0010] In one possible embodiment, the index identifiers of each of the unused physical blocks are pre-stored in the flash memory in the following manner:

[0011] In response to completing the operation of burning the offline programming package to the flash memory, the original data of each partition in the offline programming package and the first index identifier are stored;

[0012] The offline burning package is generated in the following way:

[0013] Obtain the partition address of each partition and the original data to be stored;

[0014] For each partition, based on the partition address and the size of the original data, determine the index address of at least one unused physical block in the partition as a first index identifier;

[0015] An offline burning package is generated based on the first index identifier and the original data of each partition.

[0016] In one possible embodiment, the flash memory further includes a management block for storing the first index identifier and an identifier of the original bad block in the flash memory; the method further includes:

[0017] In response to the start signal, it is determined whether the i-th physical block in the flash memory is a bad block; initially, i is 1, and the first physical block is the first physical block when the physical blocks in the flash memory are sorted from smallest to largest according to their index addresses;

[0018] If the i-th physical block in the flash memory is a bad block, then the i-th physical block is recorded as the original bad block;

[0019] If the i-th physical block in the flash memory is not a bad block, then determine whether the i-th physical block is the management block;

[0020] If the i-th physical block is the management block, then the index address of the i-th management block is recorded as the address of the management block;

[0021] If the i-th physical block is not the management block, then determine whether the i-th physical block stores the first index identifier;

[0022] If the i-th physical block stores the first index identifier, then record the first index identifier, set the initial startup identifier, and increment i by 1;

[0023] If the i-th physical block does not store the first index identifier, then increment i by 1;

[0024] Determine whether i is greater than the total number of physical blocks in the flash memory; if yes, then in response to the initial boot identifier, store the recorded original bad block identifier and the first index identifier in the management block; if no, return to the step of determining whether the i-th physical block in the flash memory is a bad block.

[0025] In one possible embodiment, the flash memory also stores the correspondence between the index identifiers of the unused physical blocks and the logical block index identifiers;

[0026] The method further includes:

[0027] In response to the second data write request, obtain the logical block index identifier corresponding to the write address requested by the second data write request, use it as the fourth index identifier, and obtain the second target data requested by the second data write request.

[0028] Determine whether the fourth index identifier is found in the correspondence;

[0029] If the fourth index identifier is found in the correspondence, the second target data is written into the unused physical block corresponding to the fourth index identifier;

[0030] If the fourth index identifier is not found in the correspondence, then it is determined whether the physical block corresponding to the fourth index identifier is a bad block;

[0031] If the physical block corresponding to the fourth index identifier is a bad block, then the fifth index identifier is determined from the pre-stored first index identifier, the second target data is written into the physical block corresponding to the fifth index identifier, and the fifth index identifier and the fourth index identifier are stored accordingly.

[0032] In one possible embodiment, the method further includes:

[0033] If the physical block corresponding to the fourth index identifier is not a bad block and the physical block corresponding to the fourth index identifier is not used, then the second target data is written into the physical block corresponding to the fourth index identifier.

[0034] In one possible embodiment, the method further includes:

[0035] In response to a data read request, obtain the logical block index identifier corresponding to the read address requested by the data read request, and use it as the sixth index identifier;

[0036] Determine whether the sixth index identifier is found in the correspondence;

[0037] If the sixth index identifier is found in the correspondence, then the data in the unused physical block corresponding to the sixth index identifier in the correspondence is read;

[0038] If the sixth index identifier is not found in the correspondence, then the data in the physical block corresponding to the sixth index identifier is read.

[0039] This application embodiment also provides a flash memory bad block management device, applied to flash memory in an electronic device, the flash memory including multiple partitions, each partition including: at least one physical block storing the original data of the partition and at least one unused physical block, the flash memory pre-stores a first index identifier, the first index identifier being the index identifier of each of the unused physical blocks;

[0040] The device includes:

[0041] The first acquisition module is used to, in response to the first data write request, acquire the logical block index identifier corresponding to the write address requested by the first data write request, use it as the second index identifier, and acquire the first target data requested by the first data write request.

[0042] The first judgment module is used to determine whether the physical block corresponding to the second index identifier is a bad block;

[0043] The first write module is configured to determine a third index identifier from the pre-stored first index identifier if the physical block corresponding to the second index identifier is a bad block, and write the first target data into the physical block corresponding to the third index identifier.

[0044] In one possible embodiment, the index identifiers of each of the unused physical blocks are pre-stored in the flash memory in the following manner:

[0045] In response to completing the operation of burning the offline programming package to the flash memory, the original data of each partition in the offline programming package and the first index identifier are stored;

[0046] The offline burning package is generated in the following way:

[0047] Obtain the partition address of each partition and the original data to be stored;

[0048] For each partition, based on the partition address and the size of the original data, determine the index address of at least one unused physical block in the partition as a first index identifier;

[0049] An offline burning package is generated based on the first index identifier and the original data of each partition.

[0050] In one possible embodiment, the flash memory further includes a management block for storing the first index identifier and identifiers of original bad blocks in the flash memory; the apparatus further includes:

[0051] The second judgment module is used to determine whether the i-th physical block in the flash memory is a bad block in response to the start signal; initially, i is 1, and the first physical block is the first physical block when the physical blocks in the flash memory are sorted from smallest to largest according to the index address;

[0052] The first recording module is used to record the i-th physical block as an original bad block if the i-th physical block in the flash memory is a bad block;

[0053] The third judgment module is used to determine whether the i-th physical block is the management block if the i-th physical block in the flash memory is not a bad block;

[0054] The second recording module is used to record the index address of the i-th management block as the address of the management block if the i-th physical block is the management block;

[0055] The fourth judgment module is used to determine whether the i-th physical block stores the first index identifier if the i-th physical block is not the management block.

[0056] The third recording module is used to record the first index identifier, set the initial startup identifier, and increment i by 1 if the i-th physical block stores the first index identifier;

[0057] The add-a-block module is used to increment i by 1 if the i-th physical block does not store the first index identifier;

[0058] The fifth judgment module is used to determine whether i is greater than the total number of physical blocks in the flash memory; if yes, in response to the initial boot identifier, the recorded original bad block identifier and the first index identifier are stored in the management block; if no, the process returns to the step of determining whether the i-th physical block in the flash memory is a bad block.

[0059] In one possible embodiment, the flash memory also stores the correspondence between the index identifiers of the unused physical blocks and the logical block index identifiers;

[0060] The device further includes:

[0061] The second acquisition module is used to, in response to the second data write request, acquire the logical block index identifier corresponding to the write address requested by the second data write request, use it as the fourth index identifier, and acquire the second target data requested by the second data write request.

[0062] The sixth judgment module is used to determine whether the fourth index identifier is found in the correspondence;

[0063] The second writing module is used to write the second target data into the unused physical block corresponding to the fourth index identifier if the fourth index identifier is found in the correspondence.

[0064] The seventh judgment module is used to determine whether the physical block corresponding to the fourth index identifier is a bad block if the fourth index identifier is not found in the correspondence.

[0065] The third write module is used to determine a fifth index identifier from the pre-stored first index identifier if the physical block corresponding to the fourth index identifier is a bad block, write the second target data into the physical block corresponding to the fifth index identifier, and store the fifth index identifier and the fourth index identifier accordingly.

[0066] In one possible embodiment, the device further includes:

[0067] The fourth write module is used to write the second target data into the physical block corresponding to the fourth index identifier if the physical block corresponding to the fourth index identifier is not a bad block and the physical block corresponding to the fourth index identifier is not used.

[0068] In one possible embodiment, the device further includes:

[0069] The third acquisition module is used to respond to a data read request by acquiring the logical block index identifier corresponding to the read address requested by the data read request, and using it as the sixth index identifier;

[0070] The eighth judgment module is used to determine whether the sixth index identifier is found in the correspondence;

[0071] The first reading module is used to read the data in the unused physical block corresponding to the sixth index identifier in the correspondence if the sixth index identifier is found in the correspondence.

[0072] The second reading module is used to read the data in the physical block corresponding to the sixth index identifier if the sixth index identifier is not found in the correspondence.

[0073] This application also provides an electronic device, including:

[0074] Memory, used to store computer programs;

[0075] The processor, when executing a program stored in memory, implements any of the flash memory bad block management methods described above.

[0076] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements any of the flash memory bad block management methods described above.

[0077] This application also provides a computer program product containing instructions that, when run on a computer, cause the computer to execute any of the flash memory bad block management methods described above.

[0078] Beneficial effects of the embodiments in this application:

[0079] This application provides a flash memory bad block management method, apparatus, electronic device, and storage medium. It is understood that flash memory is typically divided into multiple partitions, and considering the scalability of the flash memory, the size of a partition is usually larger than the size of the original data to be stored in that partition. That is, each partition of the flash memory includes at least one physical block storing the original data of that partition and at least one unused physical block. This application pre-stores index identifiers (i.e., first index identifiers) of each unused physical block in the flash memory. In response to a first data write request, it can obtain the logical block index identifier corresponding to the write address requested by the first data write request as a second index identifier, and obtain the first target data requested by the first data write request. If the physical block corresponding to the first index identifier is a bad block, a third index identifier is determined from the pre-stored first index identifiers, and the first target data is written into the physical block corresponding to the third index identifier. By employing the above method, unused physical blocks within each partition of the flash memory can be treated as spare physical blocks. In the event that a physical block is faulty, data that would otherwise be stored in that physical block can be transferred to a spare physical block. This allows unused physical blocks reserved for flash memory expansion in each partition to be reused as spare physical blocks when needed, thus achieving full utilization of the unused physical blocks within each partition. Furthermore, by treating unused physical blocks within each partition of the flash memory as spare physical blocks, this embodiment of the application eliminates the need to reserve spare physical blocks in the flash memory, reducing the waste of flash memory resources caused by reserving spare physical blocks, thereby improving the resource utilization efficiency of the flash memory, extending its lifespan, and ultimately increasing the lifespan of the electronic device to which it belongs.

[0080] Of course, implementing any product or method of this application does not necessarily require achieving all of the advantages described above at the same time. Attached Figure Description

[0081] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other embodiments can be obtained based on these drawings.

[0082] Figure 1a A schematic diagram of a flash memory structure provided in an embodiment of this application;

[0083] Figure 1b This is a schematic diagram of a first flowchart of a flash memory bad block management method provided in an embodiment of this application;

[0084] Figure 2 This is a second flowchart illustrating the flash memory bad block management method provided in an embodiment of this application.

[0085] Figure 3 This is a schematic diagram of a third type of flash memory bad block management method provided in an embodiment of this application;

[0086] Figure 4 This is a schematic diagram of the fourth process of the flash memory bad block management method provided in the embodiments of this application;

[0087] Figure 5 A fifth flowchart illustrating the flash memory bad block management method provided in this application embodiment;

[0088] Figure 6 A sixth flowchart illustrating the flash memory bad block management method provided in this application embodiment;

[0089] Figure 7 A seventh flowchart illustrating the flash memory bad block management method provided in this application embodiment;

[0090] Figure 8 This is an eighth flowchart illustrating the flash memory bad block management method provided in this application embodiment;

[0091] Figure 9 A ninth flowchart illustrating the flash memory bad block management method provided in this application embodiment;

[0092] Figure 10 A schematic diagram of a flash memory bad block management device provided in an embodiment of this application;

[0093] Figure 11 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0094] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art based on this application are within the scope of protection of this application.

[0095] To improve the resource utilization efficiency of flash memory, this application provides a flash memory bad block management method. To facilitate understanding of the flash memory bad block management method provided in this application, the execution subject used to perform the flash memory bad block management method provided in this application will be described first, that is, the flash memory in an electronic device will be described first.

[0096] The flash memory includes multiple partitions, each partition including: at least one physical block of raw data for storing the partition and at least one unused physical block. The flash memory pre-stores a first index identifier, which is the index identifier of each unused physical block.

[0097] Flash memory is typically divided into multiple partitions during use. For example, it might be divided into a bootloader partition, a factory configuration partition, a firmware partition, a firmware backup partition, a data partition, and so on. Furthermore, considering future scalability, the size of each partition is larger than the amount of original data it needs to store. For instance, assuming the firmware partition needs to store 27MB of original data at the factory, 30MB of space would typically be allocated in the flash memory as the firmware partition. This approach ensures that each partition includes at least one physical block containing the partition's original data, as well as at least one unused physical block.

[0098] A schematic diagram of the structure of flash memory can be shown as follows Figure 1a As shown. See also Figure 1a The flash memory includes N partitions: partition 1, partition 2, ..., partition N. Each partition includes used space and unused space. The used space of a partition is the space composed of all physical blocks in that partition that store the original data of that partition, and the unused space of a partition is the space composed of all unused physical blocks in that partition.

[0099] The first index identifier can be any identifier capable of distinguishing different unused physical blocks. For example, the first index identifier can be the address of the unused physical block, or it can be the number of the unused physical block in the flash memory, etc. Each unused physical block in the flash memory can be located based on the first index identifier pre-stored in the flash memory.

[0100] The flash memory in electronic devices has been described above by way of example. The flash memory bad block management method provided in this application embodiment will be described below by way of example, in conjunction with the above-described flash memory. See also Figure 1b Flash memory bad block management methods include:

[0101] S101, in response to the first data write request, obtain the logical block index identifier corresponding to the write address requested by the first data write request, use it as the second index identifier, and obtain the first target data requested by the first data write request.

[0102] S102, determine whether the physical block corresponding to the second index identifier is a bad block.

[0103] S103, if the physical block corresponding to the second index identifier is a bad block, then determine the third index identifier from the pre-stored first index identifier, and write the first target data into the physical block corresponding to the third index identifier.

[0104] S104, if the physical block corresponding to the second index identifier is not a bad block, then write the first target data into the physical block corresponding to the second index identifier.

[0105] By applying the embodiments of this application, it can be understood that flash memory is typically divided into multiple partitions, and considering the scalability of flash memory, the size of a partition is usually larger than the size of the original data to be stored in that partition. That is, each partition of flash memory includes at least one physical block storing the original data of the partition and at least one unused physical block. The embodiments of this application pre-store index identifiers (i.e., first index identifiers) of each unused physical block in the flash memory, and in response to a first data write request, obtain the logical block index identifier corresponding to the write address requested by the first data write request as a second index identifier, and obtain the first target data requested by the first data write request; if the physical block corresponding to the first index identifier is a bad block, determine a third index identifier from the pre-stored first index identifiers, and write the first target data into the physical block corresponding to the third index identifier. By employing the above method, unused physical blocks within each partition of the flash memory can be treated as spare physical blocks. In the event that a physical block is faulty, data that would otherwise be stored in that physical block can be transferred to a spare physical block. This allows unused physical blocks reserved for flash memory expansion in each partition to be reused as spare physical blocks when needed, thus achieving full utilization of the unused physical blocks within each partition. Furthermore, by treating unused physical blocks within each partition of the flash memory as spare physical blocks, this embodiment of the application eliminates the need to reserve spare physical blocks in the flash memory, reducing the waste of flash memory resources caused by reserving spare physical blocks, thereby improving the resource utilization efficiency of the flash memory, extending its lifespan, and ultimately increasing the lifespan of the electronic device to which it belongs.

[0106] The following will provide exemplary descriptions of S101-S104 respectively:

[0107] In S101, in one possible embodiment, the first data write request may directly include a write address and the first target data. In this case, the logical block index identifier corresponding to the write address included in the first data write request can be directly used as the second index identifier. In another possible embodiment, the first data write request may include an identifier associated with the write address and the first target data. In this embodiment, the write address associated with the identifier can be determined using the identifier included in the first data write request, the logical block index identifier corresponding to the write address can be used as the second index identifier, and the data associated with the identifier can be determined as the first target data. For example, this identifier may be a stream identifier (SID).

[0108] In S102-S104, it can be understood that logical blocks and physical blocks are usually associated through a logical lookup table, and the second index identifier is the index identifier of the logical block. Therefore, the physical block corresponding to the second index identifier can be determined through this logical lookup table.

[0109] In one possible embodiment, the flash memory can mark damaged or unusable physical blocks as bad blocks. In this embodiment, the flash memory can determine whether the physical block corresponding to the second index identifier is a bad block by judging whether the physical block is marked as bad. If the physical block corresponding to the second index identifier is marked as bad, then the physical block is a bad block; if the physical block is not marked as bad, then the physical block is not a bad block.

[0110] In another possible embodiment, the flash memory can store identifiers for all bad blocks. In this embodiment, the flash memory can determine whether the physical block corresponding to the second index identifier is a bad block by checking whether the flash memory stores the identifier of the physical block corresponding to the second index identifier. If the flash memory stores the identifier of the physical block corresponding to the second index identifier, then the physical block corresponding to the second index identifier is a bad block; if the flash memory does not store the identifier of the physical block corresponding to the second index identifier, then the physical block corresponding to the second index identifier is not a bad block. In this embodiment, the identifiers of all bad blocks can be stored in the flash memory in the form of a table, or in other forms besides tables, such as an array.

[0111] If the physical block corresponding to the second index identifier is a bad block, it means that the physical block corresponding to the second index identifier cannot be used. Therefore, it is necessary to allocate a new unused physical block for the second index identifier. At this time, the physical block corresponding to the determined third index identifier can be used as the new physical block allocated for the second index identifier by determining the third index identifier from the pre-stored first index identifier, and the first target data can be written into the physical block corresponding to the third index identifier.

[0112] Understandable, Figure 1b This embodiment is merely a flowchart illustrating one possible flash memory bad block management method. Figure 1bIn the illustrated embodiment, if the physical block corresponding to the second index identifier is not a bad block, the first target data can be directly written into the physical block corresponding to the second index identifier. In other possible embodiments, if the physical block corresponding to the second index identifier is not a bad block, it can first be determined whether the physical block corresponding to the second index identifier is being used. If it is not being used, the first target data can be written into the physical block corresponding to the second index identifier; if it is being used, a new unused physical block can be allocated to the second index identifier according to the method in S103. That is, if the physical block corresponding to the second index identifier is not a bad block and the physical block corresponding to the second index identifier is being used, a third index identifier is determined from the pre-stored first index identifiers, and the first target data is written into the physical block corresponding to the third index identifier.

[0113] S103-S104 have been described by example above. Referring to the above description, it can be understood that the implementation of the flash memory bad block management method provided in this application embodiment depends on the first index identifier pre-stored in the flash memory. Therefore, the method of pre-stored first index identifier in flash memory will be described by example below.

[0114] In one possible embodiment, the flash memory can read each physical block in the flash memory each time the electronic device is powered on. For each physical block, it is determined whether the physical block is used by checking whether data is read from it. If data is read from the physical block, the physical block is used; if no data is read from the physical block, the physical block is not used. Then, based on the above determination result, the flash memory stores the index identifier of each unused physical block, that is, stores the first index identifier.

[0115] In another possible embodiment, the index identifiers of each unused physical block are pre-stored in the flash memory by: in response to completing the operation of burning the offline burning package to the flash memory, storing the original data of each partition in the offline burning package and the first index identifier.

[0116] In this embodiment, see Figure 2 The offline flashing package can be generated in the following ways:

[0117] S201, obtain the partition address of each partition and the raw data to be stored.

[0118] S202, for each partition, based on the partition address and the size of the original data, determine the index address of at least one unused physical block in the partition as the first index identifier.

[0119] The size of the raw data refers to the amount of space required to store the raw data in flash memory. The raw data can be in any format, such as binary, decimal, or hexadecimal. To facilitate direct storage of raw data in flash memory, it is generally in binary format.

[0120] The method for determining the first index identifier is consistent for each partition. Therefore, the following explanation will use partition A as an example to illustrate the method for determining the first index identifier. Assume that the space in the flash memory between address 1 and address 2 is divided into partition A. Then, the partition address of partition A is address 1 - address 2. Address 1 can be used as the starting address of partition A, and address 2 as the ending address of partition A. Add the starting address of partition A to the size of the original data to be stored in partition A to obtain the intermediate address. The space between the starting address and the intermediate address stores the original data of partition A. The unused physical blocks in the space between the intermediate address and the ending address are the unused physical blocks in partition A. The index address of the unused physical blocks in partition A can be determined in the above way and used as the first index identifier.

[0121] S203, generate an offline burning package based on the first index identifier and the original data of each partition.

[0122] The first index identifier includes the index identifiers of each unused physical block in each partition. Each first index identifier occupies one block in the offline flashing package. The block storing the first index identifier is distinguished from the block storing the original data in the offline flashing package by setting different identifiers for the block occupied by the first index identifier and the block storing the original data. The first index identifier can be stored in the offline flashing package in any form, such as a table or array.

[0123] The flowchart illustrating the generation of the offline burning package in this embodiment can also be as follows: Figure 3 As shown, it includes:

[0124] S301, retrieves the partition table and the burning files in each partition.

[0125] S302 combines the various burning files into a single binary burning file based on the partition table.

[0126] In S301-S302, the partition table refers to a table that can represent the partition address of each partition, and the binary burning file is the original data of each partition mentioned above. S301-S302 is equivalent to S201 mentioned above, and you can refer to the relevant explanation of S201 above, which will not be repeated here.

[0127] S303 obtains the index of unused blocks in each partition by using the partition table and the size of each burned file.

[0128] The index of the unused block in each partition is the index identifier of the unused physical block in each of the aforementioned partitions, which is also the aforementioned first index identifier. S303 is equivalent to the aforementioned S202. Please refer to the relevant explanation of S202 above, which will not be repeated here.

[0129] S304 stores the index of unused blocks in a specific format in the offline burning package.

[0130] The index of the unused block is the first index identifier mentioned above. S304 is equivalent to S203 mentioned above. Please refer to the relevant explanation of S203 mentioned above. It will not be repeated here.

[0131] Using this embodiment, the partition address of each partition and the original data to be stored can be obtained. For each partition, based on the partition address and the size of the original data, the index address of at least one unused physical block in the partition is determined as an index identifier for the unused physical block. Based on the index identifiers of each unused physical block and the original data of each partition, an offline programming package is generated. An offline programming package including the first index identifier and the original data of each partition is pre-generated in the above manner. By programming the offline programming package to the flash memory, the flash memory can directly store the original data of each partition and the first index identifier in the offline programming package. In the above process, the first index identifier is already stored after the flash memory electronic device is powered on, eliminating the need to spend a lot of time determining which physical blocks are unused after the electronic device is powered on. This improves the resource utilization of the flash memory and the startup speed of the electronic device.

[0132] The method of pre-storing the first index identifier in flash memory has been described above. See the foregoing description of... Figure 1b As can be understood from the related descriptions of the embodiments, the implementation of the flash memory bad block management method provided in this application relies not only on the first index identifier pre-stored in the flash memory, but also on the determination of whether the physical block corresponding to the second index identifier is a bad block. In one possible embodiment, the flash memory can store the identifiers of all bad blocks, and the flash memory can determine whether the physical block corresponding to the second index identifier is a bad block by determining whether the flash memory stores the identifier of the physical block corresponding to the second index identifier. In this embodiment, the flash memory stores not only the first index identifier, but also the identifiers of all bad blocks (hereinafter referred to as original bad blocks). The following will provide an exemplary description of the method by which the flash memory stores the first index identifier and the identifiers of the original bad blocks in the flash memory.

[0133] In one possible embodiment, the flash memory also includes a management block for storing a first index identifier and an identifier of an original bad block in the flash memory. See also Figure 4 The first index identifier and the identifier of the original bad block are stored in the management block in the following ways:

[0134] S401, in response to the start signal, determines whether the i-th physical block in the flash memory is a bad block.

[0135] Initially, i is 1, and the first physical block is the first physical block when the physical blocks in the flash memory are sorted from smallest to largest according to their index addresses.

[0136] For example, suppose there are 10 physical blocks in the flash memory, from physical block 1 to physical block 10, and the physical blocks in the flash memory are sorted in ascending order of index address as follows: physical block 1, physical block 2, physical block 3, physical block 4, physical block 5, physical block 6, physical block 7, physical block 8, physical block 9, physical block 10. Then, the first physical block is physical block 1, the second physical block is physical block 2, and so on, with the tenth physical block being physical block 10.

[0137] S402, if the i-th physical block in the flash memory is a bad block, then the i-th physical block is recorded as the original bad block.

[0138] Specifically, if the i-th physical block is a bad block, a flag indicating that the i-th physical block is a bad block is set. After S402, i is incremented by 1, and it is determined whether i is greater than the total number of physical blocks in the flash memory. If i is greater than the total number of physical blocks in the flash memory, in response to the initial boot flag, the recorded flag of the bad block and the first index flag are stored in the management block. If i is not greater than the total number of physical blocks in the flash memory, the process returns to the step of determining whether the i-th physical block in the flash memory is a bad block. In this way, the determination of whether each physical block is a bad block is achieved.

[0139] S403, if the i-th physical block in the flash memory is not a bad block, then determine whether the i-th physical block is a management block.

[0140] The management blocks in the flash memory are equipped with management block identifiers. The i-th physical block is determined by whether it has a management block identifier. If the i-th physical block has a management block identifier, then the i-th physical block is a management block; if the i-th physical block does not have a management block identifier, then the i-th physical block is not a management block.

[0141] S404, if the i-th physical block is a management block, then record the index address of the i-th management block as the address of the management block.

[0142] S405, if the i-th physical block is not a management block, then determine whether the i-th physical block stores the first index identifier.

[0143] In S404-S405, if the i-th physical block is a management block, it means that the flash memory is not receiving the boot signal for the first time and a management block has been set up inside the flash memory. In this case, the index address of the i-th physical block can be directly recorded as the index address of the management block. The first index identifier and the identifier of the original bad block stored in the management block can be found through the index address of the management block.

[0144] If the i-th physical block is not a management block, it means that it is necessary to determine whether the current flash memory has received the boot signal for the first time by checking whether the i-th physical block stores the first index identifier.

[0145] S406, if the i-th physical block stores the first index identifier, then record the first index identifier, set the initial startup identifier, and increment i by 1.

[0146] S407, if the i-th physical block does not store the first index identifier, then increment i by 1.

[0147] In S406-S407, if the first index identifier is stored in the i-th physical block, it means that the flash memory is receiving the boot signal for the first time. The flash memory has not yet set up a management block, nor has it stored the identifier of the original bad block. In this case, the first index identifier is recorded, the initial boot identifier is set, and by incrementing i by 1, it is possible to determine whether each physical block is a bad block, so as to obtain the identifier of all original bad blocks based on the determination result.

[0148] If the first index identifier is not stored in the i-th physical block, then the above judgment needs to be performed on the other physical blocks by incrementing i by 1.

[0149] S408 determines whether i is greater than the total number of physical blocks in the flash memory.

[0150] S409, if i is greater than the total number of physical blocks in flash memory, then in response to the initial boot flag, the recorded original bad block flag and the first index flag are stored in the management block.

[0151] S410, if i is not greater than the total number of physical blocks in the flash memory, then return to the step of determining whether the i-th physical block in the flash memory is a bad block.

[0152] In steps S405-S410, if i is greater than the total number of physical blocks in the flash memory, it indicates that all physical blocks in the flash memory have been judged as bad blocks, and that the identifiers of all original bad blocks in the flash memory have been recorded. In this case, in response to the initial boot flag, the recorded identifiers of the original bad blocks and the first index identifier are stored in the management block. The management block can be the physical block whose first index identifier is stored, or it can be any physical block selected from all unused physical blocks in the flash memory.

[0153] If i is not greater than the total number of physical blocks in the flash memory, it means that the current determination of whether all physical blocks in the flash memory are bad blocks has not been performed. In this case, it is necessary to return to the step of determining whether the i-th physical block in the flash memory is a bad block.

[0154] In this embodiment, the flowchart illustrating the method of storing the first index identifier and the identifier of the original bad block in the management block can also be as follows: Figure 5 As shown, it includes:

[0155] S501, the device is powered on.

[0156] When the electronic device is powered on, it generates a startup signal. In response to the startup signal, the flash memory executes the following steps S502-S513.

[0157] S502, determine if the block is a bad block?

[0158] If yes, then execute S503; otherwise, execute S504. S502 is equivalent to the aforementioned S401, and you can refer to the relevant explanation of S401 above, which will not be repeated here.

[0159] S503, this block is recorded as an original bad block.

[0160] S503 is followed by S507. S503 is equivalent to the aforementioned S402, and you can refer to the relevant explanation of S402 above, which will not be repeated here.

[0161] S504, Determine if this block is a management block?

[0162] If yes, then execute S512; otherwise, execute S505. S504 is equivalent to the aforementioned S403, and you can refer to the relevant explanation of S403 above, which will not be repeated here.

[0163] S505, Determine if the block stores an unused block index table?

[0164] If yes, then execute S506-S507; otherwise, execute S507 directly. S505 is equivalent to the aforementioned S405, and you can refer to the relevant explanation of S405 above, which will not be repeated here.

[0165] S506 records the unused block index table and identifies the device's first power-on.

[0166] S507, increment the block index by 1.

[0167] S506-S507 are equivalent to the aforementioned S406-S407. Please refer to the previous explanations of S406-S407, which will not be repeated here.

[0168] S508, determine if the address has reached the maximum value?

[0169] If yes, then execute S509; otherwise, return to execute S502. S508 is equivalent to the aforementioned S408, and you can refer to the previous explanation of S408, which will not be repeated here.

[0170] S509, determine if it is the first power-on?

[0171] If yes, then execute S510; otherwise, execute S511.

[0172] S510 generates management blocks and deletes unused block indexes based on the unused block index table and the original bad block table.

[0173] S509-S510 are equivalent to the aforementioned S409. Please refer to the previous explanation of S409, which will not be repeated here.

[0174] S511, this solution was not used.

[0175] S512 records the address of the management block.

[0176] S512 is equivalent to the aforementioned S404. Please refer to the previous explanation of S404, which will not be repeated here.

[0177] S513, initialization complete.

[0178] The method of storing the first index identifier and the identifier of the original bad block in the management block has been described above as an example. In one possible embodiment, the flash memory also stores the correspondence between the index identifiers of unused physical blocks and the logical block index identifiers. In this embodiment, see [link to relevant documentation]. Figure 6 The flash memory bad block management method provided in this application includes:

[0179] S601, in response to the second data write request, obtain the logical block index identifier corresponding to the write address requested by the second data write request, use it as the fourth index identifier, and obtain the second target data requested by the second data write request.

[0180] The method of obtaining the fourth index identifier and the second target data in S601 is the same as the method of obtaining the second index identifier and the first target data in S101, so it will not be described again here.

[0181] S602, determine whether the fourth index identifier is found in the correspondence.

[0182] S603, if the fourth index identifier is found in the correspondence, the second target data is written into the unused physical block corresponding to the fourth index identifier.

[0183] S604 If the fourth index identifier is not found in the correspondence, determine whether the physical block corresponding to the fourth index identifier is a bad block.

[0184] In S602-S604, if the fourth index identifier is found in the correspondence, it means that the physical block corresponding to the fourth index identifier has been identified as a bad block, and a new unused physical block has been allocated for the fourth index identifier. Therefore, in this case, the new unused physical block allocated for the fourth index identifier can be found directly in the correspondence, that is, the unused physical block corresponding to the fourth index identifier can be found, and the second target data can be written into the unused physical block corresponding to the fourth index identifier.

[0185] If the fourth index identifier is not found in the correspondence, it is necessary to determine whether the physical block corresponding to the fourth index identifier is a bad block in order to determine whether a new unused physical block needs to be allocated for the fourth index identifier. The method for determining whether the physical block corresponding to the fourth index identifier is a bad block is the same as the method for determining whether the physical block corresponding to the second index identifier is a bad block in the aforementioned S102, so it will not be described again here.

[0186] S605, if the physical block corresponding to the fourth index identifier is a bad block, then the fifth index identifier is determined from the pre-stored first index identifier, the second target data is written into the physical block corresponding to the fifth index identifier, and the fifth index identifier and the fourth index identifier are stored accordingly.

[0187] If the physical block corresponding to the fourth index identifier is a bad block, a fifth index identifier is determined from the pre-stored first index identifiers. The second target data is then written into the physical block corresponding to the fifth index identifier. This process allocates a new unused physical block to the fourth index identifier and writes the second target data into that new unused physical block. In this embodiment, the fifth and fourth index identifiers need to be stored to establish a correspondence between the index identifiers of unused physical blocks and the logical block index identifiers. This allows the system to determine whether the logical block index identifier corresponding to the write address requested by the data write request can be found in the correspondence when a data write request is received again.

[0188] S606, if the physical block corresponding to the fourth index identifier is not a bad block, then write the second target data into the physical block corresponding to the fourth index identifier.

[0189] In one possible embodiment, if the physical block corresponding to the fourth index identifier is not a bad block, the second target data can be directly written into the physical block corresponding to the fourth index identifier. In another possible embodiment, if the physical block corresponding to the fourth index identifier is not a bad block, it is necessary to determine whether the physical block corresponding to the fourth index identifier is in use. If the physical block corresponding to the fourth index identifier is not in use, then the second target data is written into the physical block corresponding to the fourth index identifier. In other words, if the physical block corresponding to the fourth index identifier is not a bad block and is not in use, the second target data is written into the physical block corresponding to the fourth index identifier.

[0190] In this embodiment, the correspondence between the index identifiers of unused physical blocks and the index identifiers of logical blocks can be stored in the aforementioned management block. Therefore, the management block stores the correspondence between the index identifiers of unused physical blocks and the index identifiers of logical blocks, the first index identifier, and the identifiers of all original bad blocks in the flash memory. The management block includes a management table, which can store the aforementioned correspondence, the first index identifier, and the identifiers of all original bad blocks in the flash memory using bitmaps, hash tables, or other methods.

[0191] A management block typically consists of two physical blocks, both storing identical data and serving as backups for each other. A management table generally occupies one page within a management block. When the management table is updated, it is written to the next page of the management block, and the previous page is marked as invalid. Once all pages in a management block have been written, the data in all pages marked as invalid is erased. This process prevents frequent writes and erasures of the management block.

[0192] The flowchart of the flash memory bad block management method provided in this application embodiment can also be as follows: Figure 7 As shown, it includes:

[0193] S701, data writing.

[0194] S702: Obtain the corresponding logical block index number based on the write address.

[0195] S701-S702 are equivalent to the aforementioned S601. Please refer to the previous explanation of S601, which will not be repeated here.

[0196] S703, Determine if a logic block is mapped?

[0197] If yes, then execute S710; otherwise, execute S704. S703 is equivalent to the aforementioned S602, and you can refer to the relevant explanation of S602 above, which will not be repeated here.

[0198] S704, Determine if the physical block corresponding to the logical block is a bad block?

[0199] If yes, then execute S705-S707; otherwise, execute S708. S704 is equivalent to the aforementioned S604, and you can refer to the relevant explanation of S604 above, which will not be repeated here.

[0200] S705, allocate a good block based on the unused physical block index table.

[0201] S706 stores the logical block and the index number of the allocated good block into the mapping table.

[0202] S707 writes data to the allocated good block.

[0203] S705-S707 are equivalent to the aforementioned S605. Please refer to the previous explanation of S605, which will not be repeated here.

[0204] S708, determine whether the physical block corresponding to the logical block is occupied? If not, execute S709.

[0205] S709 writes the data to the corresponding physical block.

[0206] S708-S709 are equivalent to the aforementioned S606, and can be found in the previous explanation of S606, which will not be repeated here.

[0207] S710 writes the data to the corresponding mapping block.

[0208] S710 is equivalent to the aforementioned S603. Please refer to the previous explanation of S603, which will not be repeated here.

[0209] S711, write complete.

[0210] In practical applications, data is not only written to flash memory but also read from it. The following will provide an exemplary description of the data reading method in the flash memory management method provided in this application. (See [link to relevant documentation]). Figure 8 The methods include:

[0211] S801, in response to the data read request, obtains the logical block index identifier corresponding to the read address requested by the data read request, and uses it as the sixth index identifier.

[0212] The method for obtaining the sixth index identifier in S801 is the same as the method for obtaining the second index identifier in S101, so it will not be described again here.

[0213] S802, determine whether the sixth index identifier is found in the correspondence.

[0214] S803, if the sixth index identifier is found in the correspondence, then read the data in the unused physical block corresponding to the sixth index identifier in the correspondence.

[0215] S804 If the sixth index identifier is not found in the correspondence, then read the data in the physical block corresponding to the sixth index identifier.

[0216] In S802-S804, if the sixth index identifier is found in the correspondence, it means that the physical block corresponding to the sixth index identifier has been identified as a bad block, and a new unused physical block has been allocated for the sixth index identifier. The data in the physical block corresponding to the sixth index identifier is stored in the new unused physical block allocated for the sixth index identifier. Therefore, in this case, the new unused physical block allocated for the sixth index identifier can be found directly in the correspondence, that is, the unused physical block corresponding to the sixth index identifier can be found, and the data in the unused physical block corresponding to the sixth index identifier in the correspondence can be read.

[0217] If the sixth index identifier is not found in the correspondence, it means that the physical block corresponding to the sixth index identifier is not a bad block, and the data in the physical block corresponding to the sixth index identifier can be read directly.

[0218] A flowchart of the data reading process can also be shown as follows: Figure 9 As shown, it includes:

[0219] S901 receives a data read request.

[0220] S902: Obtain the corresponding logical block index number based on the read address.

[0221] S902 is equivalent to the aforementioned S801. Please refer to the previous explanation of S801, which will not be repeated here.

[0222] S903, determine whether the logic block is mapped?

[0223] If yes, then execute S904; otherwise, execute S905. S903 is equivalent to the aforementioned S802, and you can refer to the relevant explanation of S802 above, which will not be repeated here.

[0224] S904: Obtain the mapping block index from the management table and read the corresponding mapping block data.

[0225] S904 is equivalent to the aforementioned S803. Please refer to the previous explanation of S803, which will not be repeated here.

[0226] S905 reads the corresponding physical block data.

[0227] S905 is equivalent to the aforementioned S804. Please refer to the previous explanation of S804, which will not be repeated here.

[0228] S906, Read complete.

[0229] Corresponding to the aforementioned flash memory bad block management method, this application embodiment also provides a flash memory bad block management device, applied to flash memory in an electronic device, the flash memory including multiple partitions, each partition including: at least one physical block storing the original data of the partition and at least one unused physical block, the flash memory pre-stores a first index identifier, the first index identifier being the index identifier of each unused physical block;

[0230] See Figure 10 The device includes:

[0231] The first acquisition module 1001 is used to respond to the first data write request by acquiring the logical block index identifier corresponding to the write address requested by the first data write request, using it as the second index identifier, and acquiring the first target data requested by the first data write request.

[0232] The first judgment module 1002 is used to determine whether the physical block corresponding to the second index identifier is a bad block;

[0233] The first write module 1003 is used to determine the third index identifier from the pre-stored first index identifier if the physical block corresponding to the second index identifier is a bad block, and write the first target data into the physical block corresponding to the third index identifier.

[0234] In one possible embodiment, the index identifiers of each unused physical block are pre-stored in the flash memory in the following manner:

[0235] In response to the completion of the offline programming package being burned to flash memory, the original data of each partition in the offline programming package and the first index identifier are stored;

[0236] The offline burning package is generated in the following way:

[0237] Obtain the partition address of each partition and the original data to be stored;

[0238] For each partition, based on the partition address and the size of the original data, determine the index address of at least one unused physical block in the partition, which will be used as the first index identifier.

[0239] Based on the first index identifier and the original data of each partition, an offline burning package is generated.

[0240] In one possible embodiment, the flash memory further includes a management block for storing a first index identifier and an identifier of an original bad block in the flash memory; the apparatus further includes:

[0241] The second judgment module is used to determine whether the i-th physical block in the flash memory is a bad block in response to the start signal; initially, i is 1, and the first physical block is the first physical block when the physical blocks in the flash memory are sorted from smallest to largest according to the index address;

[0242] The first recording module is used to record the i-th physical block as an original bad block if the i-th physical block in the flash memory is a bad block;

[0243] The third judgment module is used to determine whether the i-th physical block is a management block if the i-th physical block in the flash memory is not a bad block;

[0244] The second recording module is used to record the index address of the i-th management block as the address of the management block if the i-th physical block is a management block;

[0245] The fourth judgment module is used to determine whether the i-th physical block stores the first index identifier if the i-th physical block is not a management block;

[0246] The third recording module is used to record the first index identifier if the i-th physical block stores the first index identifier, set the initial startup identifier, and increment i by 1;

[0247] The add-a-block module is used to increment i by 1 if the i-th physical block does not store the first index identifier;

[0248] The fifth judgment module is used to determine whether i is greater than the total number of physical blocks in the flash memory; if yes, in response to the initial boot flag, the recorded original bad block flag and the first index flag are stored in the management block; if no, the process returns to the step of determining whether the i-th physical block in the flash memory is a bad block.

[0249] In one possible embodiment, the flash memory also stores the correspondence between the index identifiers of unused physical blocks and the index identifiers of logical blocks;

[0250] The device also includes:

[0251] The second acquisition module is used to respond to the second data write request by acquiring the logical block index identifier corresponding to the write address requested by the second data write request, using it as the fourth index identifier, and acquiring the second target data requested by the second data write request.

[0252] The sixth judgment module is used to determine whether the fourth index identifier is found in the correspondence;

[0253] The second write module is used to write the second target data into the unused physical block corresponding to the fourth index identifier if the fourth index identifier is found in the correspondence.

[0254] The seventh judgment module is used to determine whether the physical block corresponding to the fourth index identifier is a bad block if the fourth index identifier is not found in the correspondence.

[0255] The third write module is used to determine the fifth index identifier from the pre-stored first index identifier if the physical block corresponding to the fourth index identifier is a bad block, write the second target data into the physical block corresponding to the fifth index identifier, and store the fifth index identifier and the fourth index identifier accordingly.

[0256] In one possible embodiment, the device further includes:

[0257] The fourth write module is used to write the second target data into the physical block corresponding to the fourth index if the physical block corresponding to the fourth index is not a bad block and the physical block corresponding to the fourth index is not used.

[0258] In one possible embodiment, the device further includes:

[0259] The third acquisition module is used to respond to a data read request by acquiring the logical block index identifier corresponding to the read address requested by the data read request, and using it as the sixth index identifier;

[0260] The eighth judgment module is used to determine whether the sixth index identifier is found in the correspondence;

[0261] The first reading module is used to read the data in the unused physical block corresponding to the sixth index identifier in the correspondence if the sixth index identifier is found in the correspondence.

[0262] The second reading module is used to read the data in the physical block corresponding to the sixth index identifier if the sixth index identifier is not found in the correspondence.

[0263] This application also provides an electronic device, such as... Figure 11 As shown, it includes:

[0264] Memory 1101 is used to store computer programs;

[0265] When processor 1102 executes the program stored in memory 1101, it performs the following steps:

[0266] In response to the first data write request, obtain the logical block index identifier corresponding to the write address requested by the first data write request, use it as the second index identifier, and obtain the first target data requested by the first data write request.

[0267] Determine whether the physical block corresponding to the second index identifier is a bad block;

[0268] If the physical block corresponding to the second index identifier is a bad block, then the third index identifier is determined from the pre-stored first index identifier, and the first target data is written into the physical block corresponding to the third index identifier.

[0269] Furthermore, the aforementioned electronic device may also include a communication bus and / or a communication interface, with the processor 1102, the communication interface, and the memory 1101 communicating with each other via the communication bus.

[0270] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.

[0271] The communication interface is used for communication between the aforementioned electronic devices and other devices.

[0272] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.

[0273] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0274] In another embodiment provided in this application, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements the steps of any of the above-described flash memory bad block management methods.

[0275] In another embodiment provided in this application, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute any of the flash memory bad block management methods described above.

[0276] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a solid-state drive (SSD), etc.

[0277] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0278] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments of apparatus, electronic devices, computer-readable storage media, and computer program products containing instructions are basically similar to the method embodiments, and therefore the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0279] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the scope of protection of this application.

Claims

1. A flash memory bad block management method, characterized in that, A flash memory used in an electronic device, the flash memory including multiple partitions, each partition including: at least one physical block storing the original data of the partition and at least one unused physical block, the flash memory pre-stores a first index identifier, the first index identifier being the index identifier of each of the unused physical blocks; The method includes: In response to the first data write request, obtain the logical block index identifier corresponding to the write address requested by the first data write request, use it as the second index identifier, and obtain the first target data requested by the first data write request. Determine whether the physical block corresponding to the second index identifier is a bad block; If the physical block corresponding to the second index identifier is a bad block, then a third index identifier is determined from the pre-stored first index identifier, and the first target data is written into the physical block corresponding to the third index identifier.

2. The method according to claim 1, characterized in that, The index identifiers of each of the unused physical blocks are pre-stored in the flash memory in the following manner, including: In response to completing the operation of burning the offline programming package to the flash memory, the original data of each partition in the offline programming package and the first index identifier are stored; The offline burning package is generated in the following way: Obtain the partition address of each partition and the original data to be stored; For each partition, based on the partition address and the size of the original data, determine the index address of at least one unused physical block in the partition as a first index identifier; An offline burning package is generated based on the first index identifier and the original data of each partition.

3. The method according to claim 2, characterized in that, The flash memory also includes a management block, which stores the first index identifier and the identifier of the original bad block in the flash memory; the method further includes: In response to the start signal, it is determined whether the i-th physical block in the flash memory is a bad block; initially, i is 1, and the first physical block is the first physical block when the physical blocks in the flash memory are sorted from smallest to largest according to their index addresses; If the i-th physical block in the flash memory is a bad block, then the i-th physical block is recorded as the original bad block; If the i-th physical block in the flash memory is not a bad block, then determine whether the i-th physical block is the management block; If the i-th physical block is the management block, then the index address of the i-th management block is recorded as the address of the management block; If the i-th physical block is not the management block, then determine whether the i-th physical block stores the first index identifier; If the i-th physical block stores the first index identifier, then record the first index identifier, set the initial startup identifier, and increment i by 1; If the i-th physical block does not store the first index identifier, then increment i by 1; Determine whether i is greater than the total number of physical blocks in the flash memory; if yes, then in response to the initial boot identifier, store the recorded original bad block identifier and the first index identifier in the management block; if no, return to the step of determining whether the i-th physical block in the flash memory is a bad block.

4. The method according to claim 1, characterized in that, The flash memory also stores the correspondence between the index identifiers of the unused physical blocks and the index identifiers of the logical blocks; The method further includes: In response to the second data write request, obtain the logical block index identifier corresponding to the write address requested by the second data write request, use it as the fourth index identifier, and obtain the second target data requested by the second data write request. Determine whether the fourth index identifier is found in the correspondence; If the fourth index identifier is found in the correspondence, the second target data is written into the unused physical block corresponding to the fourth index identifier; If the fourth index identifier is not found in the correspondence, then it is determined whether the physical block corresponding to the fourth index identifier is a bad block; If the physical block corresponding to the fourth index identifier is a bad block, then the fifth index identifier is determined from the pre-stored first index identifier, the second target data is written into the physical block corresponding to the fifth index identifier, and the fifth index identifier and the fourth index identifier are stored accordingly.

5. The method according to claim 4, characterized in that, The method further includes: If the physical block corresponding to the fourth index identifier is not a bad block and the physical block corresponding to the fourth index identifier is not used, then the second target data is written into the physical block corresponding to the fourth index identifier.

6. The method according to claim 4, characterized in that, The method further includes: In response to a data read request, obtain the logical block index identifier corresponding to the read address requested by the data read request, and use it as the sixth index identifier; Determine whether the sixth index identifier is found in the correspondence; If the sixth index identifier is found in the correspondence, then the data in the unused physical block corresponding to the sixth index identifier in the correspondence is read; If the sixth index identifier is not found in the correspondence, then the data in the physical block corresponding to the sixth index identifier is read.

7. A flash memory bad block management device, characterized in that, A flash memory used in an electronic device, the flash memory including multiple partitions, each partition including: at least one physical block storing the original data of the partition and at least one unused physical block, the flash memory pre-stores a first index identifier, the first index identifier being the index identifier of each of the unused physical blocks; The device includes: The first acquisition module is used to, in response to the first data write request, acquire the logical block index identifier corresponding to the write address requested by the first data write request, use it as the second index identifier, and acquire the first target data requested by the first data write request. The first judgment module is used to determine whether the physical block corresponding to the second index identifier is a bad block; The first write module is configured to determine a third index identifier from the pre-stored first index identifier if the physical block corresponding to the second index identifier is a bad block, and write the first target data into the physical block corresponding to the third index identifier.

8. The apparatus according to claim 7, characterized in that, The index identifiers of each of the unused physical blocks are pre-stored in the flash memory in the following manner, including: In response to completing the operation of burning the offline programming package to the flash memory, the original data of each partition in the offline programming package and the first index identifier are stored; The offline burning package is generated in the following way: Obtain the partition address of each partition and the original data to be stored; For each partition, based on the partition address and the size of the original data, determine the index address of at least one unused physical block in the partition as a first index identifier; Based on the first index identifier and the original data of each partition, an offline burning package is generated; The flash memory further includes a management block for storing the first index identifier and identifiers of original bad blocks in the flash memory; the device further includes: The second judgment module is used to determine whether the i-th physical block in the flash memory is a bad block in response to the start signal; initially, i is 1, and the first physical block is the first physical block when the physical blocks in the flash memory are sorted from smallest to largest according to the index address; The first recording module is used to record the i-th physical block as an original bad block if the i-th physical block in the flash memory is a bad block; The third judgment module is used to determine whether the i-th physical block is the management block if the i-th physical block in the flash memory is not a bad block; The second recording module is used to record the index address of the i-th management block as the address of the management block if the i-th physical block is the management block; The fourth judgment module is used to determine whether the i-th physical block stores the first index identifier if the i-th physical block is not the management block. The third recording module is used to record the first index identifier, set the initial startup identifier, and increment i by 1 if the i-th physical block stores the first index identifier; The add-a-block module is used to increment i by 1 if the i-th physical block does not store the first index identifier; The fifth judgment module is used to determine whether i is greater than the total number of physical blocks in the flash memory; if yes, in response to the initial boot identifier, the recorded original bad block identifier and the first index identifier are stored in the management block; if no, the process returns to the step of determining whether the i-th physical block in the flash memory is a bad block. The flash memory also stores the correspondence between the index identifiers of the unused physical blocks and the index identifiers of the logical blocks; The device further includes: The second acquisition module is used to, in response to the second data write request, acquire the logical block index identifier corresponding to the write address requested by the second data write request, use it as the fourth index identifier, and acquire the second target data requested by the second data write request. The sixth judgment module is used to determine whether the fourth index identifier is found in the correspondence; The second writing module is used to write the second target data into the unused physical block corresponding to the fourth index identifier if the fourth index identifier is found in the correspondence. The seventh judgment module is used to determine whether the physical block corresponding to the fourth index identifier is a bad block if the fourth index identifier is not found in the correspondence. The third writing module is used to determine the fifth index identifier from the pre-stored first index identifier if the physical block corresponding to the fourth index identifier is a bad block, write the second target data into the physical block corresponding to the fifth index identifier, and store the fifth index identifier and the fourth index identifier accordingly. The device further includes: The fourth write module is used to write the second target data into the physical block corresponding to the fourth index identifier if the physical block corresponding to the fourth index identifier is not a bad block and the physical block corresponding to the fourth index identifier is not used. The device further includes: The third acquisition module is used to respond to a data read request by acquiring the logical block index identifier corresponding to the read address requested by the data read request, and using it as the sixth index identifier; The eighth judgment module is used to determine whether the sixth index identifier is found in the correspondence; The first reading module is used to read the data in the unused physical block corresponding to the sixth index identifier in the correspondence if the sixth index identifier is found in the correspondence. The second reading module is used to read the data in the physical block corresponding to the sixth index identifier if the sixth index identifier is not found in the correspondence.

9. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the method of any one of claims 1-6.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method described in any one of claims 1-6.