A flash data storage method

By defining a META_DATA data structure for each data item in the FLASH memory and allocating two independent BLOCK blocks, the problem of data loss during power outages in the FLASH memory is solved, thus achieving data integrity and reliability.

CN115237350BActive Publication Date: 2026-04-28SICHUAN HONGMEI INTELLIGENT TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SICHUAN HONGMEI INTELLIGENT TECH CO LTD
Filing Date
2022-07-29
Publication Date
2026-04-28

AI Technical Summary

Technical Problem

In existing technologies, FLASH memory is prone to data loss under abnormal power outage conditions, especially when power failure occurs during erasure and programming processes. Data cannot be stored completely, and inconsistent CRC checks result in invalid data.

Method used

By employing CRC checksum and dual-block backup, a META_DATA data structure is defined for each piece of data to be stored in the FLASH memory, and the data is allocated to two independent BLOCK blocks, stored in BLOCK1 and BLOCK2 respectively, to achieve mutual backup of the data and ensure that the data can be recovered and synchronized in the event of a power outage.

Benefits of technology

It effectively prevents the loss of FLASH data in the event of a power outage, ensuring data integrity and reliability, and achieving data recoverability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115237350B_ABST
    Figure CN115237350B_ABST
Patent Text Reader

Abstract

The application discloses a FLASH data storage method and relates to the technical field of data storage.The application comprises the following steps: step S1, defining a data structure of constructing META_DATA for each original data RAW to be stored; step S2, allocating two independent BLOCK blocks, recorded as BLOCK1 and BLOCK2, for each META_DATA data structure in a FLASH memory, and storing the META_DATA in the BLOCK1 and BLOCK2 respectively and backing up each other; step S3, writing the BLOCK1 for the META_DATA data structure in each BLOCK1 and BLOCK2 in the FLASH memory when the system is powered on; and step S4, erasing the BLOCK2 and writing the META_DATA data structure into the BLOCK2 after the operation is successful.The application constructs the data structure of constructing META_DATA for each original data RAW to be stored, allocates two independent blocks for each META_DATA data structure in the FLASH memory, and stores the META_DATA in the independent blocks respectively, so that the FLASH data is not lost under the abnormal power-off condition, and the data is ensured to be complete, not lost and recoverable under the abnormal condition.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of data storage technology, and in particular relates to a FLASH data storage method that ensures the integrity, reliability and non-loss of flash data in the event of a power outage. Background Technology

[0002] like Figure 2 As shown, in existing technologies, the characteristic of FLASH memory is that it must be erased before being programmed. When storing data in FLASH, the block (BLOCK or SECTOR) containing the current data must be erased first, and then new data can be stored. To ensure correct data storage, CRC (CRC16 or CRC32) verification is used. The specific steps are as follows: Calculate the length (SIZE) and CRC for data A, obtaining SIZE(A) and CRC(A). Then, concatenate SIZE(A), A, and CRC(A) together sequentially and store them in a specific block (BLOCK or SECTOR) of the FLASH memory. When reading data, read SIZE(A), A, and CRC(A) simultaneously from the specific block, and calculate %CRC(A) based on the read SIZE(A) and A. If the calculated %CRC(A) and CRC(A) are equal, the data is valid; otherwise, the data is invalid.

[0003] This method has the following problems: During the erasure and programming of FLASH data blocks, abnormal situations such as power outages may occur; for example:

[0004] 1. Power was cut off immediately after erasing, so no data was written;

[0005] 2. If power is interrupted during programming after erasure and data storage is incomplete, the %CRC(A) and CRC(A) checks will be inconsistent, indicating that the data is incorrect or invalid.

[0006] Although we can use CRC checks to determine that the data is invalid and will not use it again, we have already lost the original data because the data was erased before being written. Figure 2 As shown. Summary of the Invention

[0007] The purpose of this invention is to provide a FLASH data storage method that uses CRC checksum and two blocks to store FLASH data, thus solving the problem of easy loss of FLASH data under abnormal conditions.

[0008] To solve the above-mentioned technical problems, the present invention is achieved through the following technical solution:

[0009] This invention relates to a FLASH data storage method, comprising the following steps:

[0010] Step S1: Define and construct the META_DATA data structure for each piece of raw data to be stored (RAW);

[0011] Step S2: In the FLASH memory, allocate two independent BLOCK blocks for each META_DATA data structure, denoted as BLOCK1 and BLOCK2. The META_DATA is stored in BLOCK1 and BLOCK2 respectively, with mutual backup.

[0012] Step S3: When the system is powered on, write the META_DATA data structure in each BLOCK1 and BLOCK2 of the FLASH memory to BLOCK1;

[0013] Step S4: After the operation is successful, erase BLOCK2 and write the META_DATA data structure into BLOCK2;

[0014] Step S5: If a power outage occurs during step S3 or S4, the system will restore and synchronize the lost data through step S3 when the system is powered on.

[0015] As a preferred technical solution, the data structure of META_DATA is SIZE+NO+RAW+CRC; SIZE is the length field, used to record the length of RAW, occupying four bytes; NO is the column number field, with a value range of 0 to 2^32-1, occupying four bytes, used to record the order of data storage; RAW is the raw data field, used to store the required data; CRC is the check field of META_DATA, occupying four bytes.

[0016] As a preferred technical solution, in step S3, when the system is powered on, the META_DATA in BLOCK1 and BLOCK2 of each data RAW is read into memory and recorded as META_DATA1 and META_DATA2 respectively, and CRC verification is performed.

[0017] As a preferred technical solution, if the CRC checks of META_DATA1 and META_DATA2 are both incorrect, it indicates that the RAW data has never been stored. In this case, the initial value is META_DATA. RAW is set to the initial value, NO is set to 0, and the data is written to BLOCK1 and BLOCK2 in sequence.

[0018] As a preferred technical solution, if the CRC checks of META_DATA1 and META_DATA2 are both correct, then the NO values ​​of META_DATA1 and META_DATA2 are compared.

[0019] If the NO values ​​are the same, it means that the RAW data is up-to-date and does not need to be synchronized or rebuilt.

[0020] If the NO value of META_DATA1 is greater than the NO value of META_DATA2, then META_DATA1 is the latest data structure. Copy META_DATA1 to META_DATA2, erase BLOCK2, and write META_DATA2 into BLOCK2.

[0021] If the NO value of META_DATA2 is greater than the NO value of META_DATA1, then META_DATA2 is the latest data structure. Copy META_DATA2 to META_DATA1, erase BLOCK1, and write META_DATA1 into BLOCK1.

[0022] As a preferred technical solution, if the CRC check of META_DATA1 is correct and the CRC check of META_DATA2 is incorrect, it indicates that a power failure occurred when writing back to BLOCK2. The solution is to copy META_DATA1 to META_DATA2, erase BLOCK2, and then write META_DATA2 back to BLOCK2.

[0023] As a preferred technical solution, if the CRC check of META_DATA2 is correct and the CRC check of META_DATA1 is incorrect, it indicates that a power failure occurred when writing back to BLOCK1. The solution is to copy META_DATA2 to META_DATA1, erase BLOCK1, and then write META_DATA1 back to BLOCK1.

[0024] As a preferred technical solution, when storing RAW data, the META_DATA in BLOCK1 corresponding to the RAW data is read into memory, the old RAW data in META_DATA is replaced with new RAW data, and the SIZE field, NO value field of META_DATA are updated by 1 and the CRC is updated.

[0025] As a preferred technical solution, the NO value is incremented by 1 to distinguish between new and old data; if the NO value is large, it indicates that the data was written later, and the data is newer. BLOCK1 is erased, and after the erasure is completed, META_DATA is written to BLOCK1. Then BLOCK2 is erased, and after the erasure is completed, META_DATA is written to BLOCK2.

[0026] The present invention has the following beneficial effects:

[0027] This invention constructs a META_DATA data structure for each piece of raw data to be stored (RAW). In the FLASH memory, each META_DATA data structure is distributed into two independent blocks, and the META_DATA is stored in the independent blocks respectively. This prevents the loss of FLASH data in the event of a power outage, and ensures the integrity, non-loss, and recoverability of the data in abnormal situations.

[0028] Of course, any product implementing this invention does not necessarily need to achieve all of the advantages described above at the same time. Attached Figure Description

[0029] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0030] Figure 1 This invention provides a FLASH data storage method.

[0031] Figure 2 This is a schematic diagram of the FLASH data storage structure using a common method.

[0032] Figure 3 This is a schematic diagram of the FLASH data storage structure of the present invention. Detailed Implementation

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

[0034] Please see Figure 1 As shown, the present invention is a FLASH data storage method, comprising the following steps:

[0035] Step S1: Define and construct the META_DATA data structure for each piece of raw data to be stored (RAW);

[0036] Step S2: In the FLASH memory, allocate two independent BLOCK blocks for each META_DATA data structure, denoted as BLOCK1 and BLOCK2. The META_DATA is stored in BLOCK1 and BLOCK2 respectively, with mutual backup.

[0037] Step S3: When the system is powered on, write the META_DATA data structure in each BLOCK1 and BLOCK2 of the FLASH memory to BLOCK1;

[0038] Step S4: After the operation is successful, erase BLOCK2 and write the META_DATA data structure into BLOCK2;

[0039] Step S5: If a power outage occurs during step S3 or S4, the system will restore and synchronize the lost data through step S3 when the system is powered on.

[0040] Please see Figure 3 As shown, the data structure of META_DATA is SIZE+NO+RAW+CRC; SIZE is the length field, used to record the length of RAW, occupying four bytes; NO is the column number field, with a value range of 0 to 2^32-1, occupying four bytes, used to record the order of data storage; RAW is the raw data field, used to store the required data; CRC is the check field of META_DATA, occupying four bytes.

[0041] In step S3, when the system is powered on, META_DATA in BLOCK1 and BLOCK2 of each data RAW is read into memory and recorded as META_DATA1 and META_DATA2 respectively, and CRC check is performed.

[0042] If the CRC checksums of META_DATA1 and META_DATA2 are both incorrect, it means that the RAW data has never been stored. Therefore, the initial value is META_DATA. Set RAW to the initial value, set NO=0, and write it into BLOCK1 and BLOCK2 in sequence.

[0043] If both META_DATA1 and META_DATA2 have correct CRC checks, then compare the NO values ​​of META_DATA1 and META_DATA2.

[0044] If the NO values ​​are the same, it means that the RAW data is up-to-date and does not need to be synchronized or rebuilt.

[0045] If the NO value of META_DATA1 is greater than the NO value of META_DATA2, then META_DATA1 is the latest data structure. Copy META_DATA1 to META_DATA2, erase BLOCK2, and write META_DATA2 into BLOCK2.

[0046] If the NO value of META_DATA2 is greater than the NO value of META_DATA1, then META_DATA2 is the latest data structure. Copy META_DATA2 to META_DATA1, erase BLOCK1, and write META_DATA1 into BLOCK1.

[0047] The CRC check of META_DATA1 is correct, while the CRC check of META_DATA2 is incorrect, indicating that a power failure occurred when writing back to BLOCK2. The solution is to copy META_DATA1 to META_DATA2, erase BLOCK2, and then write META_DATA2 back to BLOCK2.

[0048] The CRC check of META_DATA2 is correct, while the CRC check of META_DATA1 is incorrect, indicating that a power failure occurred when writing back to BLOCK1. Copy META_DATA2 to META_DATA1, erase BLOCK1, and write META_DATA1 back to BLOCK1.

[0049] When storing RAW data, the META_DATA in BLOCK1 corresponding to the RAW data is read into memory, the old RAW data in META_DATA is replaced with the new RAW data, and the SIZE field, NO value field of META_DATA are updated by 1 and the CRC is updated.

[0050] The NO value is incremented by 1 to distinguish between new and old data; a larger NO value indicates that the data was written later, meaning the data is newer. After erasing BLOCK1, META_DATA is written to BLOCK1. Then BLOCK2 is erased, and META_DATA is written to BLOCK2 after the erasure is complete.

[0051] One specific application of this embodiment is:

[0052] I. META_DATA data structure definition:

[0053] A META_DATA data structure is defined for each piece of raw data (RAW) to be stored. The META_DATA data structure is as follows: SIZE (4 bytes) + NO (4 bytes) + RAW (N bytes) + CRC (4 bytes). SIZE is the length field, recording the length of the RAW data, occupying 4 bytes; NO is the column number field, taking values ​​from 0 to 2^32-1, used to record the order in which data is stored; RAW is the raw data field, i.e., the data to be stored; CRC is the check field of META_DATA (SIZE + RAW + NO), occupying 4 bytes.

[0054] II. Allocating storage blocks:

[0055] In the FLASH memory, two independent blocks (BLOCK) are allocated for each META_DATA data structure, denoted as BLOCK1 and BLOCK2. META_DATA is stored in BLOCK1 and BLOCK2 respectively.

[0056] III. Synchronization and Reconstruction of META_DATA Data Structure:

[0057] When the system powers on, the META_DATA from BLOCK1 and BLOCK2 of each data RAW (as shown in Figure 3, data A, data B to data N) is read into memory and denoted as META_DATA1 and META_DATA2, and a CRC check is performed. The following situations may occur:

[0058] The CRC checks of META_DATA1 and META_DATA2 are both incorrect, indicating that the RAW data has never been stored. Construct the initial META_DATA according to the following step #Step 4 RAW Data Storage#, set RAW to the initial value, set NO=0, and write it into BLOCK1 and BLOCK2 in sequence.

[0059] Both META_DATA1 and META_DATA2 have correct CRC checks. Compare the NO values ​​of META_DATA1 and META_DATA2:

[0060] If the NO values ​​are the same, it means that the RAW data is up-to-date and does not need to be synchronized or rebuilt.

[0061] If the NO value of META_DATA1 is greater than the NO value of META_DATA2, then META_DATA1 is the latest data structure. Copy META_DATA1 to META_DATA2, erase BLOCK2, and write META_DATA2 into BLOCK2.

[0062] If the NO value of META_DATA2 is greater than the NO value of META_DATA1, then META_DATA2 is the latest data structure. Copy META_DATA2 to META_DATA1, erase BLOCK1, and write META_DATA1 into BLOCK1.

[0063] The CRC check of META_DATA1 is correct, while the CRC check of META_DATA2 is incorrect, indicating that a power failure occurred when writing back to BLOCK2. Copy META_DATA1 to META_DATA2, erase BLOCK2, and write META_DATA2 back to BLOCK2.

[0064] The CRC check of META_DATA2 is correct, while the CRC check of META_DATA1 is incorrect, indicating that a power failure occurred when writing back to BLOCK1. Copy META_DATA2 to META_DATA1, erase BLOCK1, and write META_DATA1 back to BLOCK1.

[0065] IV. RAW data storage:

[0066] After the power-on META_DATA data structure synchronization and reconstruction steps, the META_DATA stored in BLOCK1 and BLOCK2 for each RAW should be the same and valid.

[0067] When storing new RAW data, the META_DATA field in BLOCK1 corresponding to that RAW data is read into memory. The old RAW data in META_DATA is replaced with the new RAW data, and the SIZE field, NO value field, and CRC field of META_DATA are updated. The NO value increment is key to distinguishing between new and old data; a larger NO value indicates that the data was written later, and therefore the newer the data. First, BLOCK1 is erased. After erasing, META_DATA is written to BLOCK1. Then, BLOCK2 is erased, and after erasing, META_DATA is written to BLOCK2.

[0068] It is worth noting that the various units included in the above system embodiments are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be achieved; in addition, the specific names of each functional unit are only for easy differentiation and are not used to limit the scope of protection of the present invention.

[0069] Furthermore, those skilled in the art will understand that all or part of the steps in the methods of the above embodiments can be implemented by a program instructing related hardware, and the corresponding program can be stored in a computer-readable storage medium.

[0070] The preferred embodiments of the present invention disclosed above are merely illustrative of the invention. These preferred embodiments do not exhaustively describe all details, nor do they limit the invention to the specific implementations described. Clearly, many modifications and variations can be made based on the content of this specification. This specification selects and specifically describes these embodiments to better explain the principles and practical applications of the invention, thereby enabling those skilled in the art to better understand and utilize the invention. The invention is limited only by the claims and their full scope and equivalents.

Claims

1. A FLASH data storage method, characterized in that, Includes the following steps: Step S1: Define and construct the META_DATA data structure for each piece of raw data to be stored (RAW). The META_DATA data structure is SIZE+NO+RAW+CRC. SIZE is the length field, used to record the length of RAW, occupying four bytes. NO is the column number field, with a value range of 0 to 2^32-1, occupying four bytes, used to record the order in which data is stored. RAW is the raw data field, used to store the required data. CRC is the check field of META_DATA, occupying four bytes. Step S2: In the FLASH memory, allocate two independent BLOCK blocks for each META_DATA data structure, denoted as BLOCK1 and BLOCK2. The META_DATA is stored in BLOCK1 and BLOCK2 respectively, with mutual backup. Step S3: When the system is powered on, write the META_DATA data structure in each BLOCK1 and BLOCK2 of the FLASH memory to BLOCK1; Step S4: After the operation is successful, erase BLOCK2 and write the META_DATA data structure into BLOCK2; Step S5: If a power outage occurs during step S3 or S4, the system will restore and synchronize the lost data through step S3 when the system is powered on. In step S3, when the system is powered on, META_DATA in BLOCK1 and BLOCK2 of each data RAW is read into memory and recorded as META_DATA1 and META_DATA2 respectively, and CRC check is performed. If the CRC checks of META_DATA1 and META_DATA2 are both incorrect, it means that the RAW data has never been stored, so the initial construction is META_DATA; Set RAW to the initial value, set NO = 0, and write it to BLOCK1 and BLOCK2 in sequence; If both META_DATA1 and META_DATA2 have correct CRC checks, then compare their NO values. If the NO values ​​are the same, it means the RAW data is up-to-date and does not need to be synchronized or rebuilt. If the NO value of META_DATA1 is greater than the NO value of META_DATA2, then META_DATA1 is the latest data structure. Copy META_DATA1 to META_DATA2, erase BLOCK2, and write META_DATA2 into BLOCK2. If the NO value of META_DATA2 is greater than the NO value of META_DATA1, then META_DATA2 is the latest data structure. Copy META_DATA2 to META_DATA1, erase BLOCK1, and write META_DATA1 into BLOCK1. The CRC check of META_DATA1 is correct, while the CRC check of META_DATA2 is incorrect, indicating that a power failure occurred when writing back to BLOCK2. Copy META_DATA1 to META_DATA2, erase BLOCK2, and write META_DATA2 back to BLOCK2. The CRC check of META_DATA2 is correct, while the CRC check of META_DATA1 is incorrect, indicating that a power failure occurred when writing back to BLOCK1. The solution is to copy META_DATA2 to META_DATA1, erase BLOCK1, and then write META_DATA1 back to BLOCK1.

2. The FLASH data storage method according to claim 1, characterized in that, When storing the RAW data, the META_DATA in BLOCK1 corresponding to the RAW data is read into memory, the old RAW data in META_DATA is replaced with the new RAW data, and the SIZE field, NO value field of META_DATA are updated by 1 and the CRC is updated.

3. The FLASH data storage method according to claim 2, characterized in that, The NO value plus 1 is used to distinguish between new and old data; if the NO value is large, it indicates that the data was written later, and the data is newer. Erase BLOCK1, and after erasing, write META_DATA to BLOCK1. Then erase BLOCK2, and after erasing, write META_DATA to BLOCK2.

Citation Information

Patent Citations

  • Memory data backup method and device

    CN103294570A

  • Key data safety redundancy storage algorithm

    CN108228380A