A method for managing data storage in Flash
By adopting the cyclic sequential writing method from low address to high address in the Flash storage system of the GNSS chip, the problem of large resource occupation and slow initialization speed is solved, fast initialization and data reading are achieved, and the life of the Flash is extended.
Patent Information
- Application Number
- CN202110600375.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-31
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2041-05-31
AI Technical Summary
The existing Flash storage system has the problems of consuming a lot of resources and slow initialization speed in the GNSS chip, and cannot meet the performance requirements of the GNSS chip.
Using the method of sequentially writing data from low address to high address in the Flash space, by determining the starting position of the address search during initialization, searching for the header data of the information in the direction of high and low addresses, and determining whether it has been erased. Manage the corresponding relationship between the index number and the storage address of the information in the memory until all valid information is searched.
It achieves fast initialization, shortens the initialization time, improves data reading efficiency, and supports wear-leveling write strategy, extending the life of Flash.
Smart Images

Figure CN113190182B
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of information processing, and more particularly to a method for managing data storage in Flash. Background Art
[0002] Currently, an effective way to improve the startup speed of GNSS chips is to store the ephemeris when the chip is working and directly read the ephemeris when starting. Since the time of receiving the ephemeris is eliminated, the chip can start quickly. Using this technology often requires establishing a file system in the Flash of the GNSS chip to save data.
[0003] Since Flash has a limited erase and write life, it cannot be erased and written infinitely. Based on this feature, when writing multiple types of information in Flash, a wear-leveling algorithm is implemented by establishing a storage system to balance the erase and write times of each sector in Flash to maximize the life of Flash. In addition, the storage system used by GNSS chips often needs to have the characteristics of occupying less system resources, fast initialization speed, fast garbage collection speed, and stability and reliability.
[0004] Currently, the following two storage solutions are supported for wear leveling:
[0005] The first method is the hot-cold data migration method. This method records the number of erase times of each sector in the flash memory. If the erase times of different sectors are unbalanced, the data of the sector with more erase times and the sector with less erase times are exchanged to achieve write balance between different sectors.
[0006] The second method is the random garbage collection (GC) method. In the JFFS2 file system, garbage collection is triggered when the free space is lower than a certain percentage. Based on the method using random numbers, sectors with a large proportion of expired data are recycled with a higher probability, sectors with a small proportion of expired data are recycled with a lower probability, and sectors with no expired data are recycled with an extremely low probability. This random method ensures that the space occupied by information with a low usage rate can also be released and have the opportunity to be used to store frequently modified information.
[0007] Since the above solutions have the problem of occupying more resources or having a slow initialization speed, they cannot meet the performance requirements of the storage system used by the GNSS chip. Therefore, it is urgent to provide a new storage solution. Summary of the invention
[0008] In order to solve any of the above technical problems, an embodiment of the present application provides a method for managing data storage in Flash.
[0009] In order to achieve the purpose of the embodiment of the present application, the embodiment of the present application provides a method for managing data storage in Flash, in which data is written in a cyclic sequence from low address to high address in Flash space; wherein the header data of each piece of information is recorded with an index number; the method comprises:
[0010] When performing an initialization operation, determining the starting position of the address search;
[0011] Taking the starting position as the search starting point, searching in a direction with an address higher than the starting position and searching in a direction with an address lower than the starting position respectively, to find the header data of each piece of information;
[0012] For the found header data, determine whether the header data has been erased;
[0013] If the header data is not erased, the corresponding relationship between the index number of the information in the memory and the storage address of the information is managed, and the search is continued until the header data searched in each search direction is erased.
[0014] A storage medium stores a computer program, wherein the computer program is configured to execute the method described above when running.
[0015] An electronic device comprises a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the method described above.
[0016] One of the above technical solutions has the following advantages or beneficial effects:
[0017] When performing the initialization operation, determine the starting position of the address search, take the starting position as the search starting point, search in the direction of addresses higher than the starting position and in the direction of addresses lower than the starting position, respectively, find the header data of each piece of information, and determine whether the header data is erased for the found header data. If the header data is not erased, manage the correspondence between the index number of the information in the memory and the storage address of the information, and continue searching until the header data searched in each search direction is erased, thereby realizing a fast search of all valid information and achieving the purpose of fast initialization.
[0018] Other features and advantages of the embodiments of the present application will be described in the subsequent description, and partly become apparent from the description, or can be understood by implementing the embodiments of the present application. The purpose and other advantages of the embodiments of the present application can be achieved and obtained by the structures specifically pointed out in the description, claims and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings are used to provide further understanding of the technical solutions of the embodiments of the present application and constitute a part of the specification. Together with the embodiments of the embodiments of the present application, they are used to explain the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions of the embodiments of the present application.
[0020] Figure 1 A flowchart of a method for managing data storage in Flash provided in an embodiment of the present application;
[0021] Figure 2 A flow chart of a method for initializing data in a Flash storage system provided in an embodiment of the present application;
[0022] Figure 3 A flow chart of a method for initializing data in a Flash storage system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0023] In order to make the purpose, technical solution and advantages of the embodiments of the present application more clear, the embodiments of the present application will be described in detail in conjunction with the accompanying drawings. It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other arbitrarily.
[0024] In the process of implementing this application, a technical analysis of the relevant technologies was conducted and it was found that the relevant technologies have at least the following problems, including:
[0025] The hot and cold data migration method in the related art consumes a lot of memory due to the complex algorithm and the need to record the number of times each sector is erased;
[0026] The JFFS2 (Journalling Flash File System Version 2) file system has a certain degree of randomness and cannot accurately control the difference in the number of erase times of each sector. Its stability and reliability need to be improved. In addition, the JFFS2 file system has the disadvantage of slow startup during initialization operations.
[0027] Based on the above analysis, the present application provides the following solutions, including:
[0028] Figure 1 Flow chart of the method for managing data storage in Flash provided by the embodiment of the present application. Figure 1 As shown, in the method, data is written in the Flash space in a cyclic order from low address to high address; wherein the header data of each piece of information is recorded with an index number; the method comprises:
[0029] Step 101, when performing an initialization operation, determining a starting position for address search;
[0030] Step 102, taking the starting position as the search starting point, searching in a direction with an address higher than the starting position and searching in a direction with an address lower than the starting position respectively, to find the header data of each piece of information;
[0031] Step 103: for the found header data, determine whether the header data is erased;
[0032] Step 104: If the header data is not erased, the corresponding relationship between the index number of the information in the memory and the storage address of the information is managed, and the search is continued until the header data searched in each search direction is erased.
[0033] The method provided by the embodiment of the present application determines the starting position of the address search when performing the initialization operation, takes the starting position as the search starting point, searches in the direction of addresses higher than the starting position and in the direction of addresses lower than the starting position, respectively, searches for the header data of each piece of information, and determines whether the header data is erased for the found header data. If the header data is not erased, manages the correspondence between the index number of the information in the memory and the storage address of the information, and continues to search until the header data searched in each search direction is erased, thereby realizing a fast search of all valid information and achieving the purpose of fast initialization.
[0034] The method provided in the embodiment of the present application is described below:
[0035] In an exemplary embodiment, the Flash includes at least two storage areas, and the first sector in each storage area stores initialization information;
[0036] Determining the starting position of the address search includes:
[0037] The storage location of each initialization information is determined, and each storage location of the initialization information is used as the starting location of the address search.
[0038] For example, the storage space is divided into two halves. The starting position of each half can only store information reserved by the system (Index0). Index0 is used to store system operation information and data used for system initialization. When the system is initialized for the first time, the Flash is empty, and the starting address of the system is used as the storage position of the index number Index0. That is, when initialized for the first time, Index0 is written at the starting position. Since Index0 only appears in the first sector position and the first sector after the 1 / 2 position of the Flash space, this feature is used to verify whether the storage space is legal.
[0039] For Flash that is not initialized for the first time, the address of Index0 is used as the starting position of the search, which effectively ensures targeted search and avoids long initialization time caused by searching blank space.
[0040] In an exemplary embodiment, the header data record of each piece of information also records the length of the current piece of information and the length of the previous piece of information;
[0041] The storage location of the header data of the information is obtained by:
[0042] When searching in a direction with an address higher than the starting position, the storage position of the header data of the next piece of information is determined by using the length of the current piece of information recorded in the header data;
[0043] When searching in a direction with an address lower than the start position, the storage position of the header data of the previous information is determined by using the length of the previous information recorded in the header data.
[0044] The length of this piece of information in the header data constitutes a linked list pointing to the high address direction, and the length of the previous piece of information constitutes a linked list pointing to the low address direction, realizing double-link query. With the help of the length of this piece of information and the length of the previous piece of information recorded in the header data, the storage location of the header data can be quickly found, shortening the initialization time.
[0045] In an exemplary embodiment, the header data of each piece of information also records a version number, and the version number of each piece of information is determined according to the number of times the piece of information is written;
[0046] The managing the correspondence between the index number of the information in the memory and the storage address of the information includes:
[0047] Determine whether the version number of the header data of the information is the highest version, and determine whether the verification data of the header and footer of the information is correct;
[0048] If the version number of the header data of the information is the highest version and the check data of the header and the footer of the information are correct, a corresponding relationship between the index number of the information and the storage address of the information in the Flash is established in the memory.
[0049] For example, when writing information with a certain index number, the version number of each written data is the version number of the previous index increased by 1. For example, the version number of the header data record in the information with index number 5 is 3. If the information with index number 5 is currently written, the version number of the header data in the information with index number 5 is updated to 4.
[0050] Each piece of information in the memory corresponds to a descriptor, and each descriptor records the index number of the information. The index number of the same piece of information in the memory is the same as the index number in the Flash, thereby realizing access to information based on the index number.
[0051] After each search for the header data, read the index number and version number in the header data. If the version number of the information is the latest version, and the header data and footer data of the information are verified correctly, it means that the information is valid data, and the Flash physical address of the entry is updated in the descriptor corresponding to the index number of the information in the memory. On the contrary, if the version number of the information is not the latest version, or there is at least one verification error in the header data and footer data of the information, it means that the information is not valid data, and it is not allowed to update the Flash physical address of the entry in the descriptor corresponding to the index number of the information in the memory.
[0052] By performing initialization operations based on the above process, the recording of valid data can be completed accurately.
[0053] In an exemplary embodiment, determining whether the header data of the information is the highest version is performed in the following manner, including:
[0054] Compare the version number of the header data record of the information with the version number corresponding to the index number in the memory to obtain a comparison result;
[0055] If the comparison result is inconsistent and the version number in the data record is higher than the version corresponding to the index number in the memory, it is determined that the version number of the header data of the information is the latest version.
[0056] In the memory, the descriptor of each piece of information can record the index number and the version number of the information. When the Flash is initialized, the version number of the information can be judged with the help of the version number in the descriptor of the information in the memory to realize the screening of valid data.
[0057] In an exemplary embodiment, the method further comprises:
[0058] When the corresponding relationship between the index number of the information and the storage address of the information in the Flash is established in the memory, the corresponding relationship between the index number of the information and the information length of the information is also established in the memory.
[0059] By recording the information length in the descriptor of the information in the memory, when reading the information, the reading operation can be directly performed using the storage address and information length stored in the memory; conversely, if the information length is not recorded in the memory, when reading the information, it is necessary to first obtain the length of the data from the header data of the information in the Flash, which will increase the read operation on the Flash and increase the reading time of the information.
[0060] From the above comparison, it can be seen that storing the information length of the information in the memory can shorten the memory's information reading time and improve data reading efficiency.
[0061] In an exemplary embodiment, when searching in a direction with an address higher than the start position, if header data of a certain information is erased, the last write end position is determined based on the erased header data;
[0062] When searching in a direction of an address lower than the start position, if header data of another information is erased, the start address of the erase operation is determined based on the erased header data.
[0063] When searching in the direction of an address higher than the starting position, if every byte in the header data is 0xFF, it means that this place has been erased. Check the data after the header data. If it is also 0xFF, it can be considered that this is the location after the last write was completed. After the initialization is completed, new data will continue to be written from here.
[0064] When searching in the direction of an address lower than the starting position, if every byte in the header data is 0xFF, it means that this place has been erased, and the next information of this information is the oldest unerased data stored in the Flash. During garbage collection, data is checked and erased from this position.
[0065] In an exemplary embodiment, the method further comprises:
[0066] After completing the initialization operation of the Flash, determine the sector corresponding to the last write end position;
[0067] The data writing operation is performed on the sector next to the sector corresponding to the last writing end position.
[0068] By determining the sector corresponding to the end position of the last write, the sector used for the current data write operation is determined to be the next sector of the sector, so that each write starts with a new sector, which facilitates the management of sectors according to the write time.
[0069] In an exemplary embodiment, after detecting that the size of the remaining space in the Flash storage space reaches a preset space threshold, if the Flash is erased for the first time, the data erase operation is performed starting from the sector corresponding to the starting position of the storage area of the Flash; if the Flash is not erased for the first time, the data erase operation is performed starting from the next sector of the last erased sector.
[0070] Since each data write starts with a new sector, the data can be erased in sectors when erasing is performed.
[0071] For example, if the starting position of the data written for the mth time is the ath sector, and the ath sector also stores the data written for the m-1th time, if the data written for the m-1th time is to be deleted, the data in the ath sector will be completely erased, affecting the data written for the mth time; while using the scheme provided in the present application, the starting position of the data written for the mth time is the a+1th sector, if the data written for the m-1th time is to be deleted, the data in the ath sector will be completely erased, and will not affect the data written for the mth time, where m is an integer greater than or equal to 2, and a is an integer greater than or equal to 1.
[0072] During the first erasing, the sector with the earliest data written is erased, that is, the sector where Index0 is located is used as the starting position of the erasing operation; the sector erased each time thereafter is the next sector of the sector erased last time.
[0073] In an exemplary embodiment, the number of sectors that can be erased in each erase operation is determined according to the maximum write time that a user can tolerate.
[0074] The maximum write time refers to the total time consumed by the user to write valid information, including the time taken by the Flash to write information and the time taken by the garbage collection operation caused by the write operation.
[0075] Since the data erase operation affects the external writing time to the Flash, the number of sectors to be erased each time can be determined according to the maximum writing time of the Flash, and the number of sectors to be erased can be set to be less than or equal to 3.
[0076] In an exemplary embodiment, before performing an erase operation on a sector to be erased, valid data in the sector to be erased is determined, wherein the valid data is data having a highest version number;
[0077] The valid data is backed up, and after the backup is completed, the sector to be erased is erased.
[0078] If the data to be erased is valid data, it is copied to the location to be written and then erased to ensure the integrity of the data stored in the Flash.
[0079] In an exemplary embodiment, during the initialization operation, it is detected whether there is a sector in the Flash that has not completed the erase operation after performing the erase operation;
[0080] If there is a sector that has not completed the erase operation, the sector that has not completed the erase operation is determined;
[0081] Re-erase the sectors where the erase operation was not completed.
[0082] Many Flash memories have the following problem: when performing an erase operation, if a power outage occurs while erasing a sector, when power is turned on again, it may be found that individual data in other sectors belonging to the same bank as the erased sector has changed in different forms, causing data corruption, affecting the accuracy of the read data, and even making it impossible to initialize the system due to verification failure.
[0083] Based on the above situation, the embodiment of the present application provides a method of restoring the data in other affected sectors to be correct by re-erasing the sector.
[0084] In an exemplary embodiment, when performing an erase operation on a selected sector, the sector to be erased is recorded in the Flash, and after the sector is completely erased, the sector that has been completely erased is recorded;
[0085] The determining of the sectors for which the erasing operation has not been completed comprises:
[0086] According to the sectors to be erased and the sectors on which the erasing operation is completed, the sectors on which the erasing operation is not completed are determined.
[0087] An erase log table is maintained in the Flash. During the garbage collection process, when a sector to be erased is encountered, the address of the sector to be erased is recorded in the log table, and the address is recorded again after erasing. When the system is initialized, the erase log table is checked. If it is found that there is no record of erasing completion for the sector to be erased, the sector is erased again, which can make the data in the system safe from power failure.
[0088] The method provided in the embodiment of the present application is described below:
[0089] The embodiment of the present application is explained by taking the application to a navigation ephemeris storage system as an example. The ephemeris storage has the following characteristics: 1. The number of navigation satellites is limited, so the total number of ephemeris entries is limited; 2. The amount of ephemeris data for a single satellite is small.
[0090] The embodiment of the present application provides an access system based on an index number (Index), which has the characteristics of wear leveling, fast initialization speed, and less occupation of system resources.
[0091] In this access system, each piece of information corresponds to an index number. In Flash, two pieces of information written adjacently in time are also closely adjacent in space. A descriptor is stored in front of each piece of information to save the index number, version number and verification information of this piece of information; as well as the length of this piece of information and the previous piece of information, that is, a double linked list is implemented to connect adjacent information. In the memory, another descriptor is created for each piece of information to save the index number, information length and its location in Flash. Through this storage scheme, a double linked list can be used to quickly search for all valid information when the system is powered on, complete fast initialization, and quickly access content during runtime.
[0092] The Flash storage space is divided into two halves. The starting position of each half can only store system reserved information (Index0). Index0 is used to store system operation information and for system initialization. When the system is initialized for the first time (Flash is empty), Index0 is written to the starting address of the system.
[0093] Figure 2 The present invention provides a method flow chart for initializing data in a Flash storage system according to an embodiment of the present invention. Figure 2 As shown, the method includes:
[0094] Step 201, determine the legal Index0;
[0095] For an empty Flash, write Index 0 at the starting position. Since Index 0 only appears at the first sector position and the first sector after the 1 / 2 position of the Flash space, this feature is used to check whether the non-volatile memory (NVM) storage space is legal.
[0096] Step 202: Use the double linked list in the Index header to search towards a higher address;
[0097] Based on the address of Index0, use the length information of each entry stored in the header to search towards higher addresses.
[0098] Step 203: Determine whether the data in the Index header is erased;
[0099] If all bytes in the header are 0xFF, it means that the data in the Index header is erased, and step 205 is executed; otherwise, the data in the Index header is not erased, and step 204 is executed;
[0100] Step 204: Verify the data in the Index header and update the memory descriptor according to the verification result, and continue to execute step 202 until the searched data in the Index header is erased;
[0101] Each time the next address is searched, there is a header of an entry saved, and the index number and version in the header are checked. If it is the latest version of an entry and the header and footer of the entry are verified to be correct, the Flash physical address of the entry is updated in the memory descriptor.
[0102] Step 205, terminate the search in the direction of higher addresses, and record the current position as the next write position;
[0103] If every byte in the header is 0xFF, check the data after the header. If it is also 0xFF, it can be considered that this is the location after the last write. After the initialization is completed, continue to write new data from here.
[0104] Step 206: Search in the direction of lower addresses using the length of the previous entry stored in the header;
[0105] Step 207: Determine whether the data in the Index header is erased;
[0106] If all bytes in the header are 0xFF, it means that the data in the Index header is erased, and step 208 is executed; otherwise, the data in the Index header is not erased, and step 209 is executed;
[0107] Step 208: Verify the data in the Index header and update the memory descriptor according to the verification result, and continue to execute step 207 until the searched data in the Index header is erased;
[0108] Step 209: Record the location of the oldest unerased data, where garbage collection checks and erases data from this location.
[0109] The method provided in the embodiment of the present application can realize the search for valid data in Flash and achieve the purpose of fast initialization.
[0110] Figure 3 The present invention provides a method flow chart for initializing data in a Flash storage system according to an embodiment of the present invention. Figure 3 As shown, the method includes:
[0111] Step 301, determine whether the position to be written is the starting position of the storage half area;
[0112] The starting position of the storage half area corresponds to the data corresponding to Index 0, and the user is not allowed to actively write the data of Index 0.
[0113] If it is the starting position of the storage half area, execute step 302;
[0114] If it is not the starting position of the storage half area, execute step 303;
[0115] Step 302, write the data of Index0, and after the writing is completed, execute step 303;
[0116] Step 303, write the data to be written into the Index;
[0117] Step 304: determine whether the remaining space after the data is written is greater than or equal to half of the total storage space;
[0118] If no, execute steps 305 to 307; if yes, the process ends.
[0119] Step 305: determine whether the oldest data is expired;
[0120] If the oldest data has expired, execute step 306;
[0121] If the oldest data is not expired, execute step 307;
[0122] Step 306: Erase the expired data, and execute step 304 after erasing;
[0123] Step 307: back up the oldest data, and after the backup is completed, execute step 306.
[0124] The method of the embodiment of the present application, after initialization is completed, first writes new data, then backs up the old data to be erased, and then performs the erase operation; when new data needs to be written at the starting position of the half area, first backs up Index0, and then writes the new data, to achieve write management of data in Flash.
[0125] In summary, the solution provided by this application has the following advantages:
[0126] 1. Satisfy the garbage collection strategy with a deterministic worst-case time, ensuring that the write delay does not exceed 300ms in the worst case;
[0127] 2. Short initialization time: the initialization time of a 4MB storage system is no more than 30ms, thus ensuring the receiver's fast first positioning time;
[0128] 3. Support wear-leveling write strategy to ensure a long enough life of the flash;
[0129] 4. For data disorder caused by power failure during the erasing process of some NOR flash, the power failure event can be recorded and the data can be restored in time when the power is turned on next time, making the system highly reliable.
[0130] An embodiment of the present application provides a storage medium, in which a computer program is stored, wherein the computer program is configured to execute any of the methods described above when running.
[0131] An embodiment of the present application provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute any of the methods described above.
[0132] It will be appreciated by those skilled in the art that all or some of the steps, systems, and functional modules / units in the methods disclosed above may be implemented as software, firmware, hardware, and appropriate combinations thereof. In hardware implementations, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed by several physical components in cooperation. Some or all components may be implemented as software executed by a processor, such as a digital signal processor or a microprocessor, or implemented as hardware, or implemented as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or non-transitory medium) and a communication medium (or transient medium). As is known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information, such as computer-readable instructions, data structures, program modules, or other data. Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer. In addition, it is well known to those skilled in the art that communication media typically contain computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.
Claims
1. A method for managing data storage in Flash, It is characterized in that In the Flash space, data is written in a cyclic sequence from low address to high address; The header data of each piece of information is recorded with an index number; the method comprises: When performing an initialization operation, determining the starting position of the address search; Taking the starting position as the search starting point, searching in a direction with an address higher than the starting position and searching in a direction with an address lower than the starting position respectively, to find the header data of each piece of information; For the found header data, determine whether the header data has been erased; If the header data is not erased, the corresponding relationship between the index number of the information in the memory and the storage address of the information is managed, and the search is continued until the header data searched in each search direction is erased; The managing of the correspondence between the index number of the information in the memory and the storage address of the information includes: when the information is the latest valid data of the information, establishing the correspondence between the index number of the information in the memory and the storage address of the information in the Flash.
2. The method according to claim 1, Features: The Flash includes at least two storage areas, and the first sector in each storage area stores initialization information; Determining the starting position of the address search includes: The storage location of each initialization information is determined, and each storage location of the initialization information is used as the starting location of the address search.
3. The method according to claim 1, Features: The header data record of each message also records the length of this message and the length of the previous message; The storage location of the header data of the information is obtained by: When searching in a direction with an address higher than the starting position, the storage position of the header data of the next piece of information is determined by using the length of the current piece of information recorded in the header data; When searching in a direction with an address lower than the start position, the storage position of the header data of the previous information is determined by using the length of the previous information recorded in the header data.
4. The method according to claim 1, Features: The header data of each piece of information also records a version number, and the version number of each piece of information is determined according to the number of times the information is written; When the information is the latest valid data of the information, establishing a corresponding relationship between the index number of the information and the storage address of the information in the Flash in the memory includes: Determine whether the version number of the header data of the information is the highest version, and determine whether the verification data of the header and footer of the information is correct; If the version number of the header data of the information is the highest version and the check data of the header and the footer of the information are correct, a corresponding relationship between the index number of the information and the storage address of the information in the Flash is established in the memory.
5. The method according to claim 4, It is characterized in that Determine whether the header data of the information is the highest version by the following methods, including: Compare the version number of the header data record of the information with the version number corresponding to the index number in the memory to obtain a comparison result; If the comparison result is inconsistent and the version number in the data record is higher than the version corresponding to the index number in the memory, it is determined that the version number of the header data of the information is the latest version.
6. The method according to claim 5, It is characterized in that The method further comprises: When the corresponding relationship between the index number of the information and the storage address of the information in the Flash is established in the memory, the corresponding relationship between the index number of the information and the information length of the information is also established in the memory.
7. The method according to claim 1, Features: When searching in a direction with an address higher than the starting position, if the header data of a certain information is erased, determining the last writing end position according to the erased header data; When searching in a direction of an address lower than the start position, if header data of another information is erased, the start address of the erase operation is determined based on the erased header data.
8. The method according to claim 7, It is characterized in that The method further comprises: After completing the initialization operation of the Flash, determine the sector corresponding to the last write end position; The data writing operation is performed on the sector next to the sector corresponding to the last writing end position.
9. The method according to claim 7, It is characterized in that The method further comprises: After detecting that the size of the remaining space in the Flash storage space reaches the preset space threshold, if the Flash is erased for the first time, the data erase operation is performed starting from the sector corresponding to the starting position of the Flash storage area; if the Flash is not erased for the first time, the data erase operation is performed starting from the next sector of the last erased sector.
10. The method according to claim 9, It is characterized in that The number of sectors that can be erased in each erase operation is determined based on the maximum write time that the user can tolerate.
11. The method according to claim 9, Features: Before performing an erase operation on the sector to be erased, determining valid data in the sector to be erased, wherein the valid data is data with a highest version number; The valid data is backed up, and after the backup is completed, the sector to be erased is erased.
12. The method according to claim 1, Features: During the initialization operation, it is detected whether there are sectors in the Flash that have not completed the erase operation after the erase operation is performed; If there are sectors for which the erasing operation has not been completed, the sectors for which the erasing operation has not been completed are determined; Re-erase the sectors where the erase operation was not completed.
13. The method according to claim 12, Features: When performing an erase operation on a selected sector, the sector to be erased is recorded in the Flash, and after the sector is erased, the sector that has been erased is recorded; The determining of the sectors for which the erasing operation has not been completed comprises: According to the sectors to be erased and the sectors on which the erasing operation is completed, the sectors on which the erasing operation is not completed are determined.
14. A storage medium, It is characterized in that The storage medium stores a computer program, wherein the computer program is configured to execute the method according to any one of claims 1 to 13 when executed.
15. An electronic device comprising a memory and a processor, It is characterized in that A computer program is stored in the memory, and the processor is configured to run the computer program to perform the method according to any one of claims 1 to 13.
