A flash-based data storage query method

By dividing the FLASH storage area into index, bad page, and data body areas and using CRC8 checksum, the problems of wasted storage capacity, slow query, and unreliability in embedded FLASH storage are solved, achieving continuous data writing and fast query, and monitoring the health status of FLASH.

CN117492653BActive Publication Date: 2026-01-23HENAN HANWEI ELECTRONICS
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202311493779.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-10
Publication Date
2026-01-23
Estimated Expiration
2043-11-10

AI Technical Summary

Technical Problem

Embedded FLASH storage suffers from problems such as wasted storage capacity, slow data storage and retrieval, unreliable data storage, and FLASH memory failure.

Method used

The FLASH storage area is divided into an index area, a bad page area, and a data storage area. The index area is used to quickly locate the data storage location, monitor the health status of the FLASH and skip bad pages to write data, and use CRC8 checksum to ensure data reliability.

Benefits of technology

It achieves continuous and reliable data writing, improves data query speed, monitors the health status of FLASH, reduces storage waste, and improves device performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117492653B_ABST
    Figure CN117492653B_ABST
Patent Text Reader

Abstract

The application provides a FLASH-based data storage query method, which comprises the following steps: dividing a FLASH storage area into an index area for storing basic information of data storage, a bad page area for storing bad page numbers and a data body storage area for storing final data; judging whether there is a bad page, if there is a bad page, skipping the page, if there is no bad page, judging whether the data written continuously is correct, if the data is not correct, writing the data into the bad page area, if the data is correct, writing the data into the data body storage area; obtaining index information through the index area, reading specific data information in the data body storage area according to the index information, and skipping a bad page when there is a bad page in the data body storage area. The application can realize data writing continuity, data storage reliability, bad page detection and fast data query, and can monitor the health status of the FLASH and improve data reliability.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application relates to the technical field of FLASH storage, in particular to a FLASH-based data storage query method in an embedded system. BACKGROUND

[0002] In the field of embedded systems, FLASH storage data has very wide applications, but the storage capacity of FLASH is relatively limited, and in embedded applications, it is often necessary to replace larger storage chips due to the inability to effectively and fully utilize the storage area, thereby increasing product costs and causing waste.

[0003] FLASH storage areas have lifetime limitations on the number of erasing and writing operations, and frequent erasing and writing operations are often required in applications. If a certain storage area is continuously erased and written, a bad page phenomenon is likely to occur, resulting in data that cannot be written or written incorrectly, thereby causing data unreliability, and causing embedded devices to malfunction due to data loss and errors. In the data query process, if the data in the entire FLASH storage area is traversed, due to the large amount of data, the corresponding data cannot be quickly queried and matched, resulting in low query efficiency and affecting device performance.

[0004] Invention patent No. 202111447408.X discloses a storage method of a storage device, comprising: dividing the storage device into a recording area and a storage area; wherein the storage area is used to store data, and the recording area is used to store at least one of storage information of the data and storage configuration information of the storage device; in response to a processing command for to-be-processed data, the target storage position of the to-be-processed data in the storage area is obtained by using the storage information stored in the recording area; and the to-be-processed data is processed in the target storage position. The above-mentioned application divides the storage device into a recording area and a storage area, and at least one of the storage information of the data and the storage configuration information of the storage device is stored in the recording area, while the storage area is only used to store data and does not store other information of the data, so as to reduce the waste of the space of the storage area; in response to the processing command for the to-be-processed data, the target storage position of the to-be-processed data in the storage area can be directly obtained by using the storage information stored in the recording area; and the to-be-processed data is processed in the target storage position, so that the role of the partition of the storage device is clear, and the storage efficiency of the storage device can be improved. However, the above-mentioned application has the defect that the storage device will appear a phenomenon of partial area necrosis due to too many erasing and writing operations during multiple data storage, and storing data in the necrotic area will cause data storage failure or data storage error and result in data loss. Examples of loss caused by data loss are not uncommon. SUMMARY

[0005] In view of the technical problems of the existing embedded FLASH data storage discontinuity resulting in space waste, slow data storage query, unreliable data storage and monitoring the damage degree of FALSH memory, the application provides a FLASH-based data storage query method, which divides the FLASH storage into three parts by partitioning, and can effectively solve the problems of space waste, slow data storage query, unreliable data storage and whether the FALSH memory is healthy.

[0006] In order to achieve the above purpose, the technical scheme of the application is as follows: a FLASH-based data storage query method, the steps of which are as follows:

[0007] Step one, region division: dividing the FLASH storage region into an index region for storing basic information of data storage, a bad page region for storing bad page numbers and a data body storage region for storing final data;

[0008] Step two: data writing: judging whether there is a bad page, if there is a bad page, skipping this page, if there is no bad page, judging whether the data continues to write is correct, if not, writing in the bad page region, if correct, writing the data in the data body storage region;

[0009] Step three: data query: obtaining index information through the index region, reading specific data information in the data body storage region according to the index information, and skipping the bad page when there is a bad page in the data body storage region.

[0010] Preferably, the FLASH storage region is divided in an address manner, and the index region is established in an address manner.

[0011] Preferably, the index region includes a public data region and a plurality of data unit information, the public data region is used for storing basic information of data, and the data unit information is used for storing information for data query.

[0012] Preferably, the public data region contains storage region full identification, written data address, valid data unit and bad page number identification, the storage region full identification is used to obtain the storage condition of the FLASH storage region, if full, the earliest data is updated to the latest data to form a ring-shaped storage; the written data address is used to quickly locate the address position of the data written to the data body storage region; the valid data unit is used to facilitate quick query matching of the data unit information and quick acquisition of target data; the bad page number identification is used to record the number of bad pages, obtain the health condition of the FLASH and traverse the bad page region to obtain the bad page number, and the bad page is skipped in advance for data reading and writing during data reading and writing;

[0013] The data unit information includes data storage time, data storage start address and data storage length, the data storage time records the specific time of storing the target data, the data storage start address records the specific position of storing the target data in the data body storage area, and the data storage length records the size of the target data.

[0014] The FLASH health status = the number of bad pages / the total number of pages of the FLASH * 100%.

[0015] Preferably, the method for writing data into the data body storage area is that: when storing data, it is judged whether the data is covered by the storage area full flag, if not, the data is stored in the current write data address, and then the data of the current write data address, the valid data unit and the data unit information are updated; if the write data is full, the number of units to be covered is calculated, the content of the covered and incomplete data unit information is deleted, and the data of the current write data address, the valid data unit and the data unit information are updated.

[0016] Preferably, the data of the storage area full flag, the write data address, the valid data unit and the number of bad pages of the public data area of the index area are obtained, if the content of the data is all FF, it is indicated that the FLASH storage area is written for the first time, otherwise it is indicated that the FLASH storage area has been written.

[0017] Preferably, when the FLASH storage area is written for the first time, the step of writing data is:

[0018] S2.1: updating the write data address to the data storage start address, the write data offset address to the write data length + the length of the check value, the data storage time to the storage time, and the start address of the data storage area to the start address of the data body storage area;

[0019] S2.2: calculating the check value Crc8Val of the write data by CRC8 check, and writing the value of the write data + the check value into the start address of the data storage area;

[0020] S2.3: comparing the check value calculated by the CRC8 check when reading back the data with the check value Crc8Val in step S2.2, if they are consistent, it is indicated that the data is written successfully, and step S2.4 is executed, otherwise, the writing fails and step S2.5 is executed;

[0021] S2.4: If the write data address + write data offset address WDataOffset does not exceed the data body storage area, then update the storage area full flag FlagFull = 0, write data address WDataAddr = WDataAddr + WDataOffset, valid data unit number ValidDataUnitNum = ValidDataUnitNum + 1, bad page area start address BadPageNum = 0, data storage length DataStoreLen = length of write data offset address WDataOffset, and data storage time Time = storage time;

[0022] S2.5: Record the bad page and skip this page to write data into the next page, update the bad page area start address BadPageNum = BadPageNum + 1, write data offset address WDataOffset = WDataOffset + FLASH page size, and record the page number and save it to the bad page area, then repeat steps S2.2 to S2.3 until the data is successfully written.

[0023] Preferably, if the FLASH storage area has been written with data, then update: data storage time Time = storage time, data storage start address DataStoreSAddr = write data address WDataAddr, and write data offset address WDataOffset = length of write data length WdataLen + length of check value Crc8Val; and the data writing method is:

[0024] Obtain the length of write data address WDataAddr + write data length WdataLen and determine whether there is a bad page in the write data (in the WDataAddr + WdataLen area), if there is a bad page, then skip this bad page and enter step S2.2, and if there is no bad page, then enter step S2.2;

[0025] When the write data address + write data offset address WDataOffset exceeds the data body storage area, the data writing method is as follows: Based on the length of write data address WDataAddr + write data offset address WdataOffset, the number of data unit information to be covered is known. Then, update: the data of the valid data unit ValidDataUnitNum = ValidDataUnitNum + 1 - the number of data unit information covered, the storage area full flag FlagFull = 1, the write data address WDataAddr = WDataAddr + write data offset address WDataOffset, and the data storage start address DataStoreLen = write data offset address WDataOffset.

[0026] Preferably, when data writing fails, the following updates are made: Bad PageNum = BadPageNum + 1 for the bad page region, and the write data offset address WDataOffset = WDataOffset + FLASH page size, until the data is successfully written; if the data is successfully written, bad pages are recorded and skipped, the bad page region is updated, and the write data offset address WDataOffset = WDataOffset + FLASH page size * number of bad pages in the write data region is updated.

[0027] Preferably, when obtaining data at a certain point in time from the query data information unit FinddataContext, the data query implementation method is as follows: Obtain the public data PublicAddr of the public data area of ​​the index region in the index region, and the information of the starting address DataUnitInfoAddr of the data unit information; obtain the number of bad pages through the bad page number identifier BadPageNum; The valid data unit ValidDataUnitNum traverses the data stored in the starting address DataUnitInfoAddr of the data unit information and matches it with the content in the query data information unit FinddataContext, i.e., the time, to obtain specific information in the data unit information, including the data storage starting address DataStoreSAddr and the data storage length DataStoreLen; calculate the tail address of the data storage starting address DataStoreSAddr + data storage length DataStoreLen to determine whether there are bad pages in the read area. If bad pages exist, skip them during the reading process. Then, the number of valid data reads RValidDataNum = DataStoreLen - number of bad pages in the area * FLASH page size; if no bad pages exist, read the data directly; perform CRC8 verification on the read data of the valid number RvalidDataNum and compare it with the verification value written by the RValidDataNum data. If they match, the data is usable; if they do not match, the data is abnormal.

[0028] Compared with existing technologies, the beneficial effects of this invention are as follows: The FLASH storage is divided into three regions by address: an index region, a bad page region, and a data storage region. The index region contains a public data region and data unit information. The fullness flag of the public data region indicates whether the data storage region is full. If full, the oldest data can be overwritten to update the latest data, forming a circular storage and achieving cyclic data storage. The write data address enables rapid location of the written data storage location. The valid data unit records the number of data unit information bodies, facilitating rapid data retrieval and matching of corresponding data. The bad page count has two functions: first, it monitors the health status of the FLASH memory, i.e., health status = bad page count / total FLASH pages * 100%; second, it allows traversing the bad page region by counting bad pages, skipping the bad page region during data writing and performing CRC8 verification on the written data to ensure data writing continuity and reliability.

[0029] In summary, this invention can achieve continuous data writing, reliable data storage, bad page detection, and fast data query; it can also monitor the health status of FLASH and improve data reliability. Attached Figure Description

[0030] To more clearly illustrate the technical solutions in the embodiments of the present invention 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 the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0031] Figure 1 This is a flowchart of the present invention.

[0032] Figure 2 This is a flowchart illustrating the creation of the index area in this invention.

[0033] Figure 3 This is a flowchart illustrating the data writing process of this invention.

[0034] Figure 4 This is a flowchart of the data query process of the present invention. Detailed Implementation

[0035] 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.

[0036] like Figure 1 As shown, a data storage and query method based on FLASH has the following steps:

[0037] Step 1: Area Division: Divide the FLASH storage area into an index area, a bad page area, and a data storage area.

[0038] The FLASH memory is divided into three regions, distinguished by address: index regions 1-3 for storing basic information for data storage and retrieval; bad page regions 1-2 for storing bad page numbers; and data body storage regions 1-4 for storing the final data. Data body storage regions 1-4 record data based on the information characteristics of data unit information 2-2 in the index regions. The data body in data body storage regions 1-4 contains the specific stored content, and the specific information of the stored data body can be obtained based on the data unit information 2-2.

[0039] like Figure 2 As shown, the index area is distinguished by address and includes a public data area 2-1 and data unit information 2-2. The public data area 2-1 is used to store basic data information, and the data unit information 2-2 is used to store data query information.

[0040] The establishment of the public data area 2-1 includes a storage area full identifier 2-3, a write data address 2-4, valid data units 2-5, and a bad page number identifier 2-6. The storage area full identifier 2-3 is used to obtain the FLASH storage status. If the storage is full, the oldest data needs to be overwritten and updated to the latest data to form a circular storage, achieving circular data storage. The write data address 2-4 is used to quickly locate the address where data is written to the data body storage area 1-4. The valid data unit 2-5 facilitates quick querying and matching of data unit information, thereby achieving the goal of quickly obtaining the target data. The bad page number identifier 2-6 records the number of bad pages, facilitating the acquisition of FLASH health status (number of bad pages / total number of FLASH pages * 100%) and facilitating the traversal of the bad page area to obtain the specific bad page number. This allows for skipping the bad page area during data read / write operations, achieving data write continuity and data reliability.

[0041] The establishment of the data unit information 2-2 includes data storage time 2-7, data storage start address 2-8, and data storage length 2-9. Data storage time 2-7 records the specific time the data body was stored. Data storage start address 2-8 records the specific location of the target data within data body storage area 1-4. Data storage length 2-9 records the size of the target data.

[0042] Step 2: Data Writing: Determine if bad pages exist. If bad pages exist, skip them. If no bad pages exist, determine if writing data is correct. If incorrect, write to the bad page area. If correct, write the data to the data body storage area.

[0043] During data writing, the system uses a full storage area indicator to determine if data has been overwritten. If the storage area is not full, the data is stored at the current write address, and the stored data, including the current write address, valid data units, and data unit information, is updated. If the write area is full, data overwriting is required. Overwritten and incomplete data unit information is deleted, and the system is then updated.

[0044] To facilitate the explanation of the data writing and query process, the definitions are as follows: The starting address of index area 1-3 is IndexAddr, the starting address of bad page area 1-2 is BadPageAddr, the starting address of data body storage area 1-4 is DataBodyAddr, the starting address of public data area 2-1 is PublicAddr, the starting address of data unit information 2-2 is DataUnitInfoAddr, the storage area full flag 2-3 is FlagFull, the write data address 2-4 is WDataAddr, the valid data unit 2-5 is ValidDataUnitNum, the bad page number flag 2-6 is BadPageNum, the data storage time 2-7 is Time, the data storage starting address 2-8 is DataStoreSAddr, and the data storage length 2-9 is DataStoreLen. The written data is denoted as WdataContext, the checksum is denoted as Crc8Val, the written data length is denoted as WdataLen, the write data offset address is denoted as WDataOffset, and the query data information unit is denoted as FinddataContext.

[0045] like Figure 3 As shown, in the implementation of steps 1-5, data writing requires obtaining the public data 3-1 of the public data area of ​​the index region to obtain the specific area to which the data is written to the data body storage area 1-4, namely the content of the PublicAddr address. If all the content obtained from the PublicAddr address is FF, it means that the FLASH memory is being written to for the first time; otherwise, it means that the FLASH has already been written to.

[0046] For the first write to the FLASH memory, the update write data address 2-4 WDataAddr = data storage start address 2-8 DataBodyAddr, the write data offset address WDataOffset = write data length WdataLen + length of checksum Crc8Val, data storage time Time is the storage time, and the start address of data storage area 1-4 DataStoreSAddr = start address of data body storage area 1-4 DataBodyAddr. Step 3-5: Calculate the checksum Crc8Val of the written data WdataContext using the CRC8 checksum formula. Step 3-6: Write the written data WdataContext + checksum Crc8Val to the start address DataStoreSAddr of data storage area 1-4. Step 3-7: Read back the data and compare the checksum calculated using the CRC8 checksum formula with the checksum Crc8Val. If they match, the data write was successful; otherwise, the write failed. The purpose of reading back data is to improve the reliability of data writing and to detect whether the page is bad. If the verification is inconsistent, it means that the page cannot be written to normally, so the page is marked as bad and needs to be skipped and the data is written to the next page.

[0047] Data verification is performed during data writing, with the verification value written to the end of the data being written, and then the data is read. The written data and the read data are compared. If they match, the data body is normal. If they do not match, the write and read operations are repeated 1-2 times. If they still do not match, it indicates that the page is bad. The bad page is then marked and skipped for write and read checks. If the check is successful, the information in the index area is updated to ensure data reliability.

[0048] Upon successful initial data write, implement steps 3-10: calculate the write data address WDataAddr + write data offset address WDataOffset. If the data does not exceed the data storage area, update the storage area full flag 2-3 FlagFull = 0, write data address WDataAddr = WDataAddr + WDataOffset, valid data unit 2-5 ValidDataUnitNum = 1, bad page area 1-2 starting address BadPageNum = 0, data storage length 2-9 DataStoreLen = the length of WDataOffset, and data storage time Time is the storage time.

[0049] If the initial data write fails, proceed with steps 3-8 to record the bad page and skip it, writing the data to the next page. Update the starting address of the bad page region 1-2 to BadPageNum = BadPageNum + 1, write the data offset address WDataOffset = WDataOffset + FLASH page size, record this page number, and save it to the bad page region. Then repeat steps 3-5 to 3-7 until the data is successfully written.

[0050] If the FLASH memory has already been written to, update the data storage time (2-7Time) to the storage time, the data storage start address (2-8DataStoreSAddr = WDataAddr), and the write data offset address (WDataOffset = WdataLen + the length of Crc8Val). Step 3-3 obtains the length of WDataAddr + WdataLen and checks if there are bad pages within the area containing the write data (write data address + write data length). If no bad pages exist, proceed to steps 3-5 and 3-6. If bad pages exist, proceed to step 3-4, skipping the bad page and proceeding to step 3-6. Step 3-7 checks if the CRC8 values ​​of the data write and readback are consistent. If they are consistent, the data write was successful; otherwise, the write failed. If bad pages exist, the final occupied area is the write data address + write data length + number of bad pages * page size. If no bad pages exist, the final occupied area is the write data address + write data length.

[0051] In the write failure implementation steps 3-8 to 3-9, the bad page region BadPageNum is updated to BadPageNum + 1, and the write data offset address WDataOffset is set to WDataOffset + FLASH page size, until the data is successfully written. During the data writing process, it is necessary to determine whether WDataAddr + WDataOffset exceeds the data body storage area. If it does, the data writing address continues from DataBodyAddr, overwriting the previous data and updating it to the latest data to form a circular storage. Implementation step 3-10 calculates whether WDataAddr + WDataOffset exceeds the data body storage area 1-4. If the data exceeds the data body storage area 1-4, the number of data units covered can be determined based on the length of the write data address WDataAddr + write data offset address WdataOffset. Then, update the valid data unit's data: ValidDataUnitNum = ValidDataUnitNum + 1 - the number of covered data units. Set the storage area full flag 2-3 FlagFull = 1, the write data address WDataAddr = (WDataAddr + WDataOffset) % of the data body storage area size, and the data storage start address DataStoreLen = write data offset address WDataOffset. If the data does not exceed the limit, update the valid data unit's data: ValidDataUnitNum = ValidDataUnitNum + 1, the storage area full flag FlagFull = 0, the write data address WDataAddr = WDataAddr + WDataOffset, and the data storage length DataStoreLen = WDataOffset.

[0052] Upon successful write, steps 3-8 to 3-9 update the write data offset address WDataOffset = WDataOffset + FLASH page size * number of bad pages within the write data area. During the data write process, it is necessary to determine whether WDataAddr + WDataOffset exceeds the data body storage area. If it does, the data write address continues from DataBodyAddr, overwriting the previous data and updating to the latest data to form a circular storage. Step 3-10 calculates whether WDataAddr + WDataOffset exceeds the data body storage area. If it does, the number of data units to be covered can be determined based on the length of WDataAddr + WDataOffset. Then, update the data ValidDataUnitNum = ValidDataUnitNum + 1 - the number of data units to be covered, set the storage area full flag FlagFull = 1, the write data address WDataAddr = (WDataAddr + WDataOffset)% data body storage area size, and the data storage starting address DataStoreLen = WDataOffset. If the data is not exceeded, update the data: ValidDataUnitNum = ValidDataUnitNum + 1, set the storage area full flag FlagFull to 0, WDataAddr = WDataAddr + WDataOffset, and DataStoreLen = WDataOffset. Finally, update the data within its respective address range.

[0053] Step 3: Data Query: Obtain index information through the index area, and read the specific data information in the data body storage area according to the index information. Skip bad pages when bad pages exist in the area.

[0054] Data queries can retrieve data at a specific point in time based on the data storage time. First, the index information for the storage query can be obtained to understand the distribution of relevant storage information and the current health status of the FLASH memory. Then, the data body at a specific point in time can be read based on the data storage time in the index information. During the reading process, the read data is verified by comparing it with the checksum stored at the end of the data body. If they match, the data is normal; otherwise, it indicates an anomaly.

[0055] like Figure 4As shown, the implementation steps for data query 1-9 are as follows: The target data information (the query data information unit) FinddataContext, i.e., data at a specific point in time, is obtained. Implementation step 4-1: Obtain the public data PublicAddr and DataUnitInfoAddr information from the public data area of ​​the index region. The number of bad pages is obtained through the bad page number identifier BadPageNum. Implementation step 4-2: Valid DataUnitNum iterates through the data stored in the DataUnitInfoAddr and matches it with the content in the Query Data Information Unit FinddataContext, i.e., the time, to obtain specific information from the data unit information, including the data storage start address DataStoreSAddr and the data storage length DataStoreLen. Implementation step 4-3: Calculate the tail address of the data storage start address DataStoreSAddr + DataStoreLen. Step 4-4: Based on the starting address of the data storage, DataStoreSAddr, and the ending address of DataStoreSAddr + DataStoreLen, it can be determined whether the area being read contains the addresses of bad pages within the bad page region. If bad pages exist, Step 4-5: Skip the bad pages during the reading process. The number of valid data read (RValidDataNum) is then calculated as: DataStoreLen - Number of bad pages in the region * FLASH page size. If no bad pages exist, Step 4-6: Read the data directly. Step 4-7: Perform a CRC8 check on the read valid data count RvalidDataNum and compare it with the CRC value of the RValidDataNum data (i.e., the previously written CRC value). If they match, the data is usable; otherwise, the data is abnormal.

[0056] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A data storage and query method based on FLASH, characterized in that, The steps are as follows: Step 1, Area Division: Divide the FLASH storage area into an index area for storing basic data storage information, a bad page area for storing bad page numbers, and a data body storage area for storing the final data. Step 2: Data writing: Determine if there are bad pages. If bad pages exist, skip this page. If no bad pages exist, determine if writing data is correct. If incorrect, write to the bad page area. If correct, write the data to the data body storage area. Step 3: Data Query: Obtain index information through the index area, read the specific data information in the data body storage area according to the index information, and skip bad pages when bad pages exist in the data body storage area; The index area includes a public data area and multiple data unit information. The public data area is used to store basic data information, and the data unit information is used to store data query information. The public data area includes a storage area full indicator, a write data address, valid data units, and a bad page number indicator. The storage area full indicator is used to obtain the storage status of the FLASH storage area. If it is full, the oldest data will be overwritten and updated to the latest data to form a circular storage. The write data address is used to quickly locate the address where the data is written to the data body storage area. The valid data unit is used to facilitate quick query and matching of data unit information and quick acquisition of target data. The bad page number identifier is used to record the number of bad pages, obtain the FLASH health status, and traverse the bad page area to obtain the bad page number, so as to skip bad pages in advance during data reading and writing. The data unit information includes data storage time, data storage start address, and data storage length. The data storage time records the specific time when the target data is stored; the data storage start address records the specific location of the target data in the data body storage area; and the data storage length records the size of the target data.

2. The FLASH-based data storage and query method according to claim 1, characterized in that, The FLASH storage area is divided by address, and the index area is also distinguished by address.

3. The FLASH-based data storage and query method according to claim 2, characterized in that, The Flash health status is calculated as: (Number of bad pages / Total number of Flash pages) * 100%.

4. The FLASH-based data storage and query method according to any one of claims 1-3, characterized in that, The method for writing data into the data storage area is as follows: when storing data, the full indicator of the storage area is used to determine whether the data has been overwritten. If the storage area is not full, the data is stored in the current write data address, and then the data of the current write data address, valid data unit, and data unit information are updated. If the write data is full, calculate the number of cells to be overwritten, delete the overwritten and incomplete data cell information, and update the current write data address, valid data cells, and data cell information.

5. The FLASH-based data storage and query method according to claim 4, characterized in that, Retrieve the data of the full storage area identifier, write data address, valid data unit, and bad page number identifier of the public data area of ​​the index region. If the data content is all FF, it means that the FLASH storage area is being written to for the first time; otherwise, it means that the FLASH storage area has been written to before.

6. The FLASH-based data storage and query method according to claim 1 or 5, characterized in that, When the FLASH storage area is being written to for the first time, the data writing steps are as follows: S2.1: Update the write data address to the data storage start address, the write data offset address to the write data length + the length of the check value, the data storage time to the storage time, and the data storage area start address to the data body storage area start address; S2.2: Calculate the check value Crc8Val of the written data using CRC8 check, and write the written data plus the check value to the starting address of the data storage area; S2.3: When reading back data, compare the check value calculated by CRC8 check with the check value Crc8Val in step S2.

2. If they match, it means that the data was written successfully and proceed to step S2.

4. Otherwise, if the writing fails, proceed to step S2.

5. S2.4: If the calculation of the write data address + write data offset address WDataOffset does not exceed the data body storage area, update the storage area full flag FlagFull = 0, write data address WDataAddr = WDataAddr + WDataOffset, valid data unit ValidDataUnitNum = ValidDataUnitNum + 1, bad page area start address BadPageNum = 0, data storage length DataStoreLen is equal to the length of the write data offset address WDataOffset, and data storage time Time is the storage time; S2.5: Record the bad page and skip this page to write the data to the next page. Update the starting address of the bad page area BadPageNum = BadPageNum + 1, write the data offset address WDataOffset = WDataOffset + FLASH page size, and record this page number to update the bad page area. Then repeat steps S2.2 to S2.3 until the data is successfully written.

7. The FLASH-based data storage and query method according to claim 6, characterized in that, If the FLASH storage area has already been written to, then update: the data storage time (Time) is the storage time, the data storage start address (DataStoreSAddr) is equal to the data write address (WDataAddr), and the data write offset address (WDataOffset) is equal to the data write length (WdataLen) plus the length of the checksum (Crc8Val). The data writing method is as follows: Obtain the length of the write data address WDataAddr + write data length WdataLen and determine whether there is a bad page within the write data area (WDataAddr + WdataLen). If a bad page exists, skip this bad page and proceed to step S2.2; otherwise, proceed to step S2.

2. When the write data address + write data offset address WDataOffset exceeds the data body storage area, the data writing method is as follows: Based on the length of write data address WDataAddr + write data offset address WdataOffset, the number of data unit information to be covered is known. Then, update: the data of the valid data unit ValidDataUnitNum = ValidDataUnitNum + 1 - the number of data unit information covered, the storage area full flag FlagFull = 1, write data address WDataAddr = WDataAddr + write data offset address WDataOffset, and the data storage start address DataStoreLen = write data offset address WDataOffset.

8. The FLASH-based data storage and query method according to claim 6, characterized in that, When data writing fails, update: BadPageNum = BadPageNum + 1 for the bad page region, and write the data offset address WDataOffset = WDataOffset + FLASH page size until the data is successfully written; If data is successfully written, record bad pages and skip them. Update the bad page area and update the write data offset address WDataOffset = WDataOffset + FLASH page size * number of bad pages in the write data area.

9. The FLASH-based data storage and query method according to any one of claims 3, 5, 7 or 8, characterized in that, When retrieving data from a specific point in time using the FinddataContext query data information unit, the data query implementation method is as follows: Obtain the public data PublicAddr of the public data area in the index region, and the starting address DataUnitInfoAddr of the data unit information. Obtain the number of bad pages using the BadPageNum identifier. Use the ValidDataUnitNum to iterate through the data stored in the starting address DataUnitInfoAddr of the data unit information and match it with the content (time) in the FinddataContext query data information unit to obtain specific information including the data storage starting address DataStoreSAddr and the data storage length DataStoreLen. Calculate the tail address of the data storage starting address DataStoreSAddr + data storage length DataStoreLen to determine if there are bad pages in the read area. If bad pages exist, skip them during the reading process. The valid data count RValidDataNum = DataStoreLen - number of bad pages in the area * FLASH page size. If no bad pages exist, read the data directly; perform a CRC8 check on the number of valid data read (RvalidDataNum) and compare it with the check value written for the RValidDataNum data. If they match, the data is usable; otherwise, the data is abnormal.

Citation Information

Patent Citations

  • Storage method of storage device and storage device

    CN114217741A

  • A Flash memory data storage method and a read method

    CN109271100A

  • Bad block processing method of NAND FLASH

    CN110597458A