CN114115700A - Flash memory data read-write method and flash memory data read-write device - Google Patents

Flash memory data read-write method and flash memory data read-write device Download PDF

Info

Publication number
CN114115700A
CN114115700A CN202010893456.0A CN202010893456A CN114115700A CN 114115700 A CN114115700 A CN 114115700A CN 202010893456 A CN202010893456 A CN 202010893456A CN 114115700 A CN114115700 A CN 114115700A
Authority
CN
China
Prior art keywords
data
recording area
flash memory
data recording
written
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010893456.0A
Other languages
Chinese (zh)
Inventor
卢明红
陈荣
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Schneider Electric China Co Ltd
Original Assignee
Schneider Electric China Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Schneider Electric China Co Ltd filed Critical Schneider Electric China Co Ltd
Priority to CN202010893456.0A priority Critical patent/CN114115700A/en
Publication of CN114115700A publication Critical patent/CN114115700A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0646Horizontal data movement in storage systems, i.e. moving data in between storage devices or systems
    • G06F3/0652Erasing, e.g. deleting, data cleaning, moving of data to a wastebasket
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0602Interfaces specially adapted for storage systems specifically adapted to achieve a particular effect
    • G06F3/0614Improving the reliability of storage systems
    • G06F3/0616Improving the reliability of storage systems in relation to life time, e.g. increasing Mean Time Between Failures [MTBF]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0602Interfaces specially adapted for storage systems specifically adapted to achieve a particular effect
    • G06F3/0614Improving the reliability of storage systems
    • G06F3/0617Improving the reliability of storage systems in relation to availability
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0638Organizing or formatting or addressing of data
    • G06F3/064Management of blocks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0668Interfaces specially adapted for storage systems adopting a particular infrastructure
    • G06F3/0671In-line storage system
    • G06F3/0673Single storage device
    • G06F3/0679Non-volatile semiconductor memory device, e.g. flash memory, one time programmable memory [OTP]

Abstract

The present disclosure relates to a flash memory data read/write method and a flash memory data read/write apparatus capable of reducing wear of flash memory blocks. The flash memory data reading and writing method comprises the following steps: determining a data recording area to be written in an empty data recording area of the flash memory, wherein each data recording area is used for writing a data record; if no empty data recording area exists in the flash memory and is used as a data recording area to be written, erasing at least one flash memory block of the flash memory, and determining the data recording area to be written in the erased flash memory block; and writing the data to be written into the data record area to be written in the form of data records, wherein the data records comprise a load field and an identification field for setting an identification value, and the identification value of the newly written data record is increased by a preset value on the basis of the identification value of the last written data record.

Description

Flash memory data read-write method and flash memory data read-write device
Technical Field
The disclosure relates to a flash memory data read-write method and a flash memory data read-write device.
Background
For embedded devices, data flash or embedded flash is typically utilized to hold information such as user configuration and system operational event records, requiring that such information be valid even after the device is powered down or restarted due to an anomaly. Currently, such information is stored in a designated location of a data flash memory or an embedded flash memory, that is, in designated flash blocks (blocks), and an erase (erase) operation is performed in units of flash blocks before a write operation is performed to store the information.
Disclosure of Invention
The flash memory block is divided into a plurality of data recording areas to write and read data, and only when no empty data recording area for writing data exists, the erasing operation of the flash memory block is executed without erasing the flash memory block every time data is written, so that the delay of data updating is short, the abrasion of the flash memory block is reduced, and in some embodiments, the data writing abnormity of equipment during power failure or restarting can be better processed, and the data availability is ensured.
According to an aspect of the present disclosure, a method for reading and writing data of a flash memory is provided. The flash memory data reading and writing method comprises the following steps: determining a data recording area to be written in an empty data recording area of a flash memory, wherein the flash memory comprises one or more flash memory blocks, each flash memory block is divided into a plurality of data recording areas, and each data recording area is used for writing one data record; if no empty data recording area exists in the flash memory and is used as the data recording area to be written, erasing at least one flash memory block of the flash memory, and determining the data recording area to be written in the erased flash memory block; and writing the data to be written into the data record area to be written in the form of data records, wherein the data records comprise a load field and an identification field for setting an identification value, and the identification value of the newly written data record is increased by a preset value on the basis of the identification value of the last written data record.
According to still another aspect of the present disclosure, a flash memory data read/write apparatus is provided. The flash memory data read-write device comprises: the flash memory comprises one or more flash memory blocks, each flash memory block is divided into a plurality of data recording areas, and each data recording area is used for writing one data record; an erasing module that erases at least one flash block of the flash memory if there is no empty data recording area in the flash memory for use as the data recording area to be written, in which case the determining module determines the data recording area to be written in the erased flash block; and the writing module writes the data to be written into the data recording area in a data record form, wherein the data record comprises a load field and an identification field for setting an identification value, and the identification value of the newly written data record is increased by a preset value on the basis of the identification value of the last written data record.
According to still another aspect of the present disclosure, a flash memory data read/write apparatus is provided. The flash memory data read-write device comprises a memory and a processor. The memory is for storing program code. The processor is configured to perform the following operations when executing the program code: determining a data recording area to be written in an empty data recording area of a flash memory, wherein the flash memory comprises one or more flash memory blocks, each flash memory block is divided into a plurality of data recording areas, and each data recording area is used for writing one data record; if no empty data recording area exists in the flash memory and is used as the data recording area to be written, erasing at least one flash memory block of the flash memory, and determining the data recording area to be written in the erased flash memory block; and writing the data to be written into the data record area to be written in the form of data records, wherein the data records comprise a load field and an identification field for setting an identification value, and the identification value of the newly written data record is increased by a preset value on the basis of the identification value of the last written data record.
According to the embodiment of the disclosure, the flash memory block does not need to be erased every time data is written, so that the data updating delay is short, the wear of the flash memory block is reduced, and in some embodiments, the data writing exception when the equipment is powered down or restarted can be better processed, and the data availability is ensured.
Drawings
The aspects, features and advantages of the disclosure will become more apparent and readily appreciated from the following description of the embodiments taken in conjunction with the accompanying drawings in which:
FIG. 1 is a flow chart of a method for reading and writing data to a flash memory according to an embodiment of the present disclosure;
FIG. 2 is an example of a data record according to an embodiment of the present disclosure;
FIG. 3 is a schematic diagram of determining a data recording area to be read and a data recording area to be written according to an embodiment of the present disclosure;
FIG. 4 is a schematic diagram of determining a data recording area to be written in the case where a flash memory includes three flash blocks according to an embodiment of the present disclosure;
FIG. 5 is a flow chart of a method for reading and writing data to a flash memory according to an embodiment of the present disclosure;
FIG. 6 is a flowchart illustrating initialization of a flash memory data read/write method at system power-up according to an embodiment of the present disclosure;
FIG. 7 is a schematic block diagram of a flash memory data read/write apparatus according to an embodiment of the present disclosure;
fig. 8 is a schematic block diagram of another flash data read-write apparatus according to an embodiment of the present disclosure.
Detailed Description
The present disclosure will be described in detail below with reference to exemplary embodiments thereof. However, the present disclosure is not limited to the embodiments described herein, which may be embodied in many different forms. The described embodiments are intended only to be exhaustive and complete of the disclosure and to fully convey the concept of the disclosure to those skilled in the art. Features of the various embodiments described may be combined with each other or substituted for each other unless expressly excluded or otherwise excluded in context.
As mentioned above, the current way to save data on flash memory is to utilize some of the flash blocks specified in the flash memory. When data needs to be written or updated, the corresponding flash memory block needs to be erased. Since the entire flash block needs to be erased every time a write operation is performed, the erase time is long, and the delay for performing data update is long. Furthermore, if a certain type of data is frequently written or updated, the flash memory blocks corresponding to the storage of that type of data will be frequently erased, and the number of times of erasing of each flash memory block is limited, and beyond the threshold number of times of erasing of the flash memory block, the flash memory block will fail, resulting in the inability to store data any more. In addition, if the device is powered down or restarted while a flash block is being erased or written, the data on the flash block may have been erased while the data to be written is not written, resulting in loss of data on the flash block.
The embodiment of the disclosure provides a flash memory data read-write method and a flash memory data read-write device, a flash memory block is divided into a plurality of data recording areas to write and read data, and only when no empty data recording area for writing data exists, the erasing operation of the flash memory block is executed, and the flash memory block is not required to be erased when data is written every time, so that the time delay of data updating is short, the abrasion of the flash memory block is reduced, and in some embodiments, the data writing abnormity when equipment is powered down or restarted can be better processed, and the data availability is ensured.
Fig. 1 is a flow chart of a method 100 for reading and writing data in a flash memory according to an embodiment of the disclosure. Steps S110-S130 of fig. 1 correspond to the flow of writing data. To write data, it is first determined where in the flash memory the data is written. As described above, the flash memory may include one or more flash blocks, which are used to store data and are the smallest unit of operation for an erase operation. In the flash memory data read-write method 100 according to the embodiment of the present disclosure, instead of using flash memory blocks as a unit for data writing and reading, each flash memory block is divided into a plurality of data recording areas, and each data recording area is used as a unit for data writing and reading, and each data recording area is used for writing and storing one data record. Each of the data recording areas described above may be a fixed-length area for storing data in a flash block. Thus, for example, each flash block is divided into 10 data recording areas, and the erasing operation of the flash block is performed only once after at least 10 data updates are performed, so that the delay of data update is reduced, and the wear of the flash block is reduced. On the basis of using the data recording area as the data writing and reading unit, if there is an empty data recording area in the flash memory, the data will be written into the empty data recording area, so as shown in fig. 1, in step S110 of the flash memory data reading and writing method 100, the data recording area to be written is determined in the empty data recording area of the flash memory. However, if there is no empty data recording area in the flash memory that can be used as a data recording area to be written, it is necessary to perform an erase operation on at least one flash block so that the flash memory has an empty data recording area again. Therefore, as shown in fig. 1, when there is no empty data recording area in the flash memory to be used as the data recording area to be written, in step S120 of the flash memory data reading and writing method 100, at least one flash block of the flash memory needs to be erased, and the data recording area to be written is determined in the erased flash block. After determining the data-to-be-written recording area via step S110 or S120, the data-to-be-written is written in the data-to-be-written recording area in the form of data recording in step S130. After the writing of data is completed, the data to be written recording area already stores the latest data therein, and therefore, optionally, in order to facilitate subsequent reading operations, the data to be written recording area may be directly determined as the data to be read recording area, and the data in the data to be read recording area is read while the reading operation is performed.
According to an embodiment of the present disclosure, data to be written is written in the form of data records. Fig. 2 is an example of a data record 200 according to an embodiment of the present disclosure. Data record 200 may include a payload field and an identification field for setting an identification value (ID). The payload field corresponds to the data to be written. As each data is written, an identification value is also set thereto. The identification value of the newly written data record is incremented by a predetermined value, e.g. by 1, on the basis of the identification value of the last data record that has been written. For example, if the identification value of the last data record that has been written is 5, the identification value of the newly written data record is 5+ a predetermined value (in the case where the predetermined value is 1, the identification value of the newly written data record is 6).
The identification value can provide reference for determining a data recording area to be read or written for subsequent data reading or writing operation. Fig. 3 is a schematic diagram of determining a data recording area to be read and a data recording area to be written according to an embodiment of the present disclosure. The maximum identification value corresponds to the most recently written data (i.e., the last written data), and thus, the non-empty data recording area storing the data record having the maximum identification value is the data recording area where the write operation was last performed, and such data recording area can be used as the data recording area to be read. Therefore, a data recording area to be read, which is a data recording area storing data records having the largest identification value, can be determined in a non-empty data recording area of the flash memory. For example, in fig. 3, the flash memory block is divided into a plurality of data recording areas including a non-empty data recording area and an empty data recording area. Assuming that the non-empty data recording area 310 stores the data record with the largest identification value, the data recording area 310 is the data recording area where the last write operation was previously performed, and can be used as the data recording area to be read.
The next data writing operation may be performed in an empty data recording area logically contiguous to (i.e., immediately adjacent to) the data recording area 310, i.e., the data recording area 320, and thus, such an empty data recording area is determined as a data recording area to be written. Thus, in one embodiment, if there is an empty data recording area in the flash memory, the determining of the data recording area to be written in step S110 may include determining the data recording area to be written as an empty data recording area (e.g., data recording area 320) of a non-empty data recording area (e.g., data recording area 310) of the flash memory logically and continuously storing data records with the largest identification value. In this specification, the terms "logically continuous", "logically adjacent" or "logically adjacent" mean that two data recording areas are accessed in sequential order, and they may or may not be physically adjacent.
In another embodiment, if there is an empty data recording area but there is no non-empty data recording area in the flash memory, that is, all empty data recording areas in the flash memory are empty data recording areas, the determining of the data recording area to be written in step S110 may include determining a first data recording area in the flash memory as the data recording area to be written.
Alternatively, the data recording area to be read and the data recording area to be written may each be indicated by a pointer to the corresponding data recording area.
To further reduce wear of flash blocks and reduce data loss, flash memories having multiple flash blocks may be used. In other words, the flash memory may include at least two flash blocks for storing data. In this way, after all the data recording area in one flash block is full, the next write operation can be performed in another different flash block. Thus, even when it is necessary to perform an erase operation for the next write operation, i.e., when there is no empty data recording area in the other flash block, the other flash block can be erased instead of the current flash block (i.e., the flash block storing the last written data). Thus, the use of multiple flash blocks may eliminate the need for the current flash block to be erased immediately after being written to full, thereby reducing wear on the flash blocks, as compared to a manner in which only one flash block is used. In addition, the last written data and the current data to be written correspond to data recording areas in different flash memory blocks, so that the last written data cannot be erased, the last written data can be read even if the data writing is abnormal due to power failure or restarting of the device, the risk of data loss is reduced, and the usability of the data is ensured. Thus, in one embodiment, the flash memory may comprise at least two flash blocks. If no empty data recording area exists in the at least two flash memory blocks that can be used as a data recording area to be written, at least one flash memory block that does not store a data record having the largest identification value can be erased. Fig. 4 is a schematic diagram of determining a data recording area to be written in a case where a flash memory includes three flash memory blocks according to an embodiment of the present disclosure. In fig. 4, the flash blocks 1, 2, and 3 are divided into a plurality of data recording areas. Assuming that a data record having the largest identification value is stored in the non-empty data recording area 410 in the flash memory 1, the data recording area 410 is a data recording area where a write operation was previously performed for the last time, and thus is determined as a data recording area to be read. All data recording areas in the flash block 1 are already written, and therefore it is necessary to determine the data recording areas to be written in the flash blocks 2 and 3. In one example, if flash block 2 has not been written with data and flash block 3 is fully written, an empty data recording area 420 in flash block 2 may be determined, for example, as the data recording area to be written. In another example, if both the flash memory block 2 and the flash memory block 3 are fully written, an erasing operation may be performed on at least one of the flash memory block 2 and the flash memory block 3, and a data recording area to be written is determined in the erased flash memory block. For example, an erasing operation is performed on the flash memory block 2, and the empty data recording area 420 in the flash memory block 2 formed after the erasing operation is determined as a data recording area to be written; or, the erasing operation is performed on both the flash blocks 2 and 3, and the empty data recording area 420 in the flash block 2 formed after the erasing is determined as the data recording area to be written. In this way, wear of the flash block 1 is reduced, and even if the device is powered down or restarted, since the flash block 1 is not erased, the availability of data on the flash block 1, particularly data that was last written to the flash block 1 (written in the data recording area 410 of the flash block 1), is ensured, i.e., the history can be effectively retained.
In case the flash memory comprises at least two flash memory blocks, in order to further reduce wear of the flash memory blocks, the erase operation may further be limited to the next flash memory block adjacent to the currently fully written flash memory block. In other words, the flash block to which data is to be written and the flash block to be erased can be determined in order in the logical order of the flash blocks. Thus, in one embodiment, the data recording area to be written is determined sequentially from at least two flash blocks of the flash memory. For example, referring to the example in fig. 4, if the flash block 1 is not fully written, the determination of the data recording area to be written continues in the flash block 1. If the flash memory block 1 is fully written, determining a data recording area to be written in the flash memory block 2; if the flash memory block 2 is full, determining a data recording area to be written in the flash memory block 3; then, if the flash block 3 is also full, the data recording area to be written is determined in the flash block 1 in turn. Further, if a data record having the largest identification value is stored in the data recording area 410 of the flash block 1 in fig. 4, and no empty data recording area exists in the flash blocks 1, 2, 3 as a data recording area to be written, the next flash block (i.e., the flash block 2) of the flash block (i.e., the flash block 1) in which the data record having the largest identification value is stored (i.e., the data record stored in the data recording area 410) is erased, and the data recording area to be written is determined in the next flash block (i.e., the flash block 2). Thus, for a flash block, other flash blocks are erased only once, thereby further reducing the wear of the flash blocks. For example, in the case where the flash memory includes 10 flash blocks each of which is divided into 10 data recording areas, the flash block 1 is erased after the flash blocks 2 to 9 are erased once, respectively, that is, the flash block 1 is erased once every 100 data updates, thereby reducing wear of the flash block 1. The same is true for the other flash blocks 2-9.
During erase and write operations, the device is suddenly powered down or restarted, possibly resulting in a failure to write or a failure to properly write data records in the corresponding data recording area. Therefore, when reading data, it is necessary to detect whether the read data is correctly stored data. To this end, referring back to FIG. 2, in one embodiment, the data record 200 may also include a check field for storing a check code. The check code may be generated, for example, using a check algorithm based on the data to be written in the payload field and the identification value in the identification field. The check code may be generated using various known check algorithms, such as checksum check, exclusive-or check, cyclic redundancy check (e.g., CRC-16), and the like.
In case the data record comprises a check field, when reading data in the data record, a check may be performed based on the check code stored therein to detect whether the read data in the payload field is correctly stored data. Therefore, optionally, the flash memory data reading and writing method described with reference to fig. 1 may further include the flow shown in fig. 5. Fig. 5 is a flowchart of a method 500 for reading and writing data in a flash memory according to an embodiment of the disclosure, wherein steps S510-S550 correspond to a process for reading data. To read data, first the location of the data to be read is determined. For this, as already discussed above with reference to fig. 3, in step S510, a data recording area to be read, which is a data recording area storing data records having the largest identification value, may be determined in a non-empty data recording area of the flash memory.
In step S520, a data record is read from the determined data recording area to be read, and is verified by a verification code in the data record. For example, in the case of using the CRC-16 algorithm, the CRC-16 algorithm may be used to calculate the check codes of the load field and the ID field in the read data record, compare the actual check codes in the read data record, and if they are equal, the check is considered to be successful, otherwise, the check is considered to be unsuccessful.
In step S530, it is determined whether the verification is successful. If the verification is successful, the read data record is determined to be a valid data record in step S540. If the verification is unsuccessful, in step S550, the data recording area to be read is updated based on the identification value of the data record, and the last non-empty data recording area logically adjacent to the currently read data recording area is continuously read for a valid data record. That is, in step S550, the data recording area to be read is determined as the data recording area in which the data record having the identification value that is decremented by the above-mentioned predetermined value from the identification value of the read data record is stored, and it returns to step S520 to read the data record and verify based on the updated data recording area to be read until a valid data record is found. For example, in fig. 3, initially, the non-empty data recording area 310 is determined as the data recording area to be read due to storing the data record having the largest identification value. However, if the verification based on the verification code in the data record stored in the non-empty data recording area 310 is unsuccessful, the data recording area to be read needs to be further updated to the data recording area storing the data record having the identification value (e.g., 5-1-4) obtained by decrementing the identification value (e.g., 5) of the data record stored in the data recording area 310 by a predetermined value (e.g., 1), that is, the non-empty data recording area 330. If the verification based on the verification code in the data record stored in the data recording area 330 is still unsuccessful, the data recording area to be read needs to be further updated to the data recording area 340 until the verification is successful, and a valid data record is found.
Fig. 6 is an initialization flowchart 600 of a flash memory data read-write method at system power-up according to an embodiment of the present disclosure. As shown in fig. 6, when the system for loading the flash memory is powered on, the method for reading and writing data in the flash memory according to the embodiment of the present disclosure further includes steps S610 to S630. In step S610, it is necessary to determine whether all the data recording areas of the flash memory are empty data recording areas or non-empty data recording areas. The data recording area to be read must be located in the non-empty data recording area and the data recording area to be written must be located in the empty data recording area. In step S620, in order to determine which of the non-empty data recording areas is the data recording area to be read, it may be first determined whether the data recording is a valid data recording based on the check code in the data recording stored in each non-empty data recording area, whereby those non-empty data recording areas where the data recording is invalid although there is a data recording, for example, those data recording areas where the device is powered down or restarted to cause incorrect writing when a write operation is performed, may be excluded. The process of determining whether the data record is a valid record based on the check code has been described above with reference to step S520, and will not be described herein again. In step S630, the data recording area to be read and the data recording area to be written are determined. The data recording area storing the valid data record with the maximum identification value is determined as a data recording area to be read, and the data recording area to be written is determined as an empty data recording area logically closest to the determined data recording area to be read. As described above, the valid data record having the largest identification value is the latest record written last time, and therefore, the data recording area storing such data record is determined as the data recording area to be read. Further, the next data writing operation should logically follow the data recording area to be read, i.e., be logically closest to the data recording area to be read, and should be a blank data recording area, and thus such a blank data recording area is determined as the data recording area to be written.
Referring back to fig. 2, to make detection of the data recording area more convenient and faster, in one embodiment, the data record 200 may further include an encapsulation header field for identifying the start of the data record. The pack header field may be, for example, a special character such as 0xAA, 0x55, etc. for ease of detection. Therefore, the reading and the writing of the related data can be carried out only in the data recording area corresponding to the data record with the packaging head field, and the time for searching the data recording area in the memory is saved.
Therefore, the flash memory data reading and writing method reduces the delay of data updating and the abrasion of the flash memory blocks, and can better handle the data writing abnormity when the equipment is powered down or restarted in some embodiments, thereby ensuring the data availability.
Fig. 7 is a schematic block diagram of a flash data read/write apparatus 700 according to an embodiment of the present disclosure. The flash data read/write apparatus 700 may be used to implement the above-described flash data read/write method described with reference to fig. 1-6. The flash data read/write apparatus 700 may include a determination module 710, an erase module 720, and a write module 730.
The determining module 710 may determine a data recording area to be written in an empty data recording area of a flash memory, where the flash memory includes one or more flash memory blocks, each flash memory block is divided into a plurality of data recording areas, and each data recording area is used for writing one data record.
The erasing module 720 may erase at least one flash block of the flash memory if there is no empty data recording area in the flash memory for use as a data recording area to be written, in which case the determining module 710 may determine the data recording area to be written in the erased flash block.
The writing module 730 may write the data to be written in the data record area to be written in the form of a data record, where the data record includes a payload field and an identification field for setting an identification value, and the identification value of the newly written data record is incremented by a predetermined value based on the identification value of the last data record that has been written.
In one embodiment, the determining module 710 may determine the data recording area to be written as an empty data recording area of the non-empty data recording area of the flash memory logically contiguous to the data recording area storing the data record having the largest identification value. If there is no non-empty data recording area in the flash memory, the determining module 710 may determine the data recording area to be written as any first empty data recording area in the flash memory.
In one embodiment, the flash memory may include at least two flash blocks. The erase module 720 may erase at least one flash block that does not store a data record having the largest identification value if there is no empty data record area in at least two flash blocks to use as a data record area to be written.
In one embodiment, the determining module 710 may determine the data recording area to be written from at least two flash memory blocks in sequence when determining the data recording area to be written. If there is no empty data recording area in at least two flash memory blocks to be used as the data recording area to be written, the erasing module 720 may erase a next flash memory block of the flash memory block in which the data record having the largest identification value is stored, and the determining module 710 may determine the data recording area to be written in the next flash memory block.
In one embodiment, the data recording area may further include a check field for storing a check code.
In one embodiment, as shown in FIG. 7, the determination module 710 may also include a read and check module 740. The determining module 710 may determine a data recording area to be read in a non-empty data recording area of the flash memory, where the data recording area to be read is a data recording area storing data records having a maximum identification value. The read and verify module 740 can read the data record from the data record area to be read and verify it by the verification code. If the verification is successful, the read and verify module 740 may determine the read data record as a valid data record; if the verification is unsuccessful, the determination module 710 may determine the data record area to be read as a data record area storing data records having identification values that are decremented by a predetermined value from the identification values of the read data records, and the read and verify module 740 may read the data records and verify based on the updated data record area to be read until a valid data record is found.
In one embodiment, the determining module 710 may determine whether all data recording areas of the flash memory are empty data recording areas or non-empty data recording areas when the system loading the flash memory is powered on. The read and check module 740 may then determine whether the data record stored in the non-empty data recording area is a valid data record based on the check code. Then, the determining module 710 may determine the data recording area storing the valid data record having the largest identification value as a data recording area to be read, and determine the data recording area to be written as an empty data recording area logically closest to the data recording area to be read.
In one embodiment, after the writing module 730 completes writing, the determining module 710 may determine the data recording area to be written as the data recording area to be read.
In one embodiment, the data record may further include an encapsulation header field for identifying the start of the data record.
According to the flash memory data read-write device disclosed by the embodiment of the disclosure, the time delay of data updating is reduced, the abrasion of a flash memory block is reduced, the data write-in abnormity of equipment during power failure or restarting can be better processed, and the data availability is ensured.
Fig. 8 is a schematic block diagram of another flash data read/write device 800 according to an embodiment of the disclosure. The flash data read/write device 800 may be any device for reading and writing flash data, such as a notebook computer, a desktop computer, a tablet computer, and the like. The type of device 800 does not constitute a limitation of the present disclosure. As shown in fig. 8, the flash data read/write device 800 may include a memory 810 and a processor 820. The memory 810 is used to store program codes. The processor 820, when executing program code stored in the memory 810, is configured to perform the following operations: determining a data recording area to be written in an empty data recording area of a flash memory, wherein the flash memory comprises one or more flash memory blocks, each flash memory block is divided into a plurality of data recording areas, and each data recording area is used for writing one data record. If no empty data recording area exists in the flash memory and is used as a data recording area to be written, at least one flash memory block of the flash memory is erased, and the data recording area to be written is determined in the erased flash memory block. And writing the data to be written into the data record area to be written in the form of data records, wherein the data records comprise a load field and an identification field for setting an identification value, and the identification value of the newly written data record is increased by a preset value on the basis of the identification value of the last written data record.
In one embodiment, the processor 820, when executing the program code, further performs the following: and determining the data recording area to be written as an empty data recording area of the non-empty data recording area logically and continuously storing the data record with the maximum identification value in the flash memory. And if the flash memory does not have the non-empty data recording area, determining the data recording area to be written as any first empty data recording area in the flash memory.
In one embodiment, the flash memory includes at least two flash blocks, and the processor 820 when executing the program code further performs the following: if no empty data recording area exists in at least two flash memory blocks to be used as the data recording area to be written, erasing at least one flash memory block which does not store the data record with the maximum identification value.
In one embodiment, the processor 820, when executing the program code, further performs the following: when the data recording area to be written is determined, the data recording area to be written is determined from at least two flash memory blocks in sequence; if there is no empty data recording area in at least two flash memory blocks to be used as a data recording area to be written, erasing a next flash memory block of the flash memory block storing the data record having the largest identification value, and determining the data recording area to be written in the next flash memory block.
In one embodiment, the data recording area further includes a check field for storing a check code.
In one embodiment, the processor 820, when executing the program code, further performs the following: and determining a data recording area to be read in a non-empty data recording area of the flash memory, wherein the data recording area to be read is a data recording area for storing the data record with the maximum identification value. And reading the data record from the data record area to be read, and verifying through the verification code. If the verification is successful, the read data record is determined to be a valid data record. If the verification is unsuccessful, the data recording area to be read is determined as a data recording area storing data records having identification values decremented by a predetermined value from the identification values of the read data records, and the data records are read and verified based on the updated data recording area to be read until a valid data record is found.
In one embodiment, at power-up of a system that loads flash memory, the processor 820, when executing program code, also performs the following: it is determined whether all the data recording areas of the flash memory are empty data recording areas or non-empty data recording areas. It is determined whether the data record stored in the non-empty data recording area is a valid data record based on the check code. And determining a data recording area storing the effective data record with the maximum identification value as a data recording area to be read, and determining a data recording area to be written as an empty data recording area which is logically closest to the data recording area to be read.
In one embodiment, the processor 820, when executing the program code, further performs the following: after the writing is completed, the data recording area to be written is determined as the data recording area to be read.
In one embodiment, the data record further includes an encapsulation header field for identifying the start of the data record.
According to the flash memory data read-write device disclosed by the embodiment of the disclosure, the time delay of data updating is reduced, the abrasion of a flash memory block is reduced, the data write-in abnormity of equipment during power failure or restarting can be better processed, and the data availability is ensured.
The block diagrams of apparatuses, devices, systems involved in the present disclosure are only used as illustrative examples and are not intended to require or imply that the connections, arrangements, configurations, etc. must be made in the manner shown in the block diagrams. As will be appreciated by one skilled in the art, these circuits, devices, apparatus, devices, systems may be connected, arranged, configured in any manner that achieves the intended purposes.
Those skilled in the art will appreciate that the specific embodiments described above are by way of example only and not by way of limitation, and that various modifications, combinations, sub-combinations, and substitutions are possible in the embodiments of the disclosure, depending upon design requirements and other factors, insofar as they are within the scope of the appended claims or the equivalents thereof, as defined in the claims of the disclosure.

Claims (19)

1. A flash memory data read-write method comprises the following steps:
determining a data recording area to be written in an empty data recording area of a flash memory, wherein the flash memory comprises one or more flash memory blocks, each flash memory block is divided into a plurality of data recording areas, and each data recording area is used for writing one data record;
if no empty data recording area exists in the flash memory and is used as the data recording area to be written, erasing at least one flash memory block of the flash memory, and determining the data recording area to be written in the erased flash memory block; and
and writing the data to be written into the data record area to be written in the form of data records, wherein the data records comprise a load field and an identification field for setting an identification value, and the identification value of the newly written data record is increased by a preset value on the basis of the identification value of the last written data record.
2. The method of claim 1, wherein the flash memory data read/write operation is performed in a flash memory
The data recording area to be written is determined as an empty data recording area of a non-empty data recording area logically and continuously storing the data records with the maximum identification values in the flash memory;
and if the flash memory does not have a non-empty data recording area, determining the data recording area to be written as a first data recording area in the flash memory.
3. The method of claim 1, wherein the flash memory data read/write operation is performed in a flash memory
The flash memory comprises at least two flash memory blocks;
and if no empty data recording area exists in the at least two flash memory blocks and is used as the data recording area to be written, erasing at least one flash memory block which does not store the data record with the maximum identification value.
4. The method of claim 3, wherein the flash memory data read/write operation is performed in a flash memory
When the data recording area to be written is determined, sequentially determining the data recording area to be written from the at least two flash memory blocks;
and if no empty data recording area exists in the at least two flash memory blocks and is used as the data recording area to be written, erasing the next flash memory block of the flash memory block storing the data record with the maximum identification value, and determining the data recording area to be written in the next flash memory block.
5. The method for reading and writing data of a flash memory according to claim 1, wherein the data recording area further comprises a check field for storing a check code.
6. The method for reading and writing data of a flash memory according to claim 5, further comprising:
determining a data recording area to be read in a non-empty data recording area of the flash memory, wherein the data recording area to be read is a data recording area for storing data records with the maximum identification value;
reading data records from the data recording area to be read, and verifying through the verification code;
if the verification is successful, determining the read data record as a valid data record;
if the verification is unsuccessful, the data recording area to be read is determined as a data recording area storing data records having identification values decremented by the predetermined value from the identification values of the read data records, and the data records are read and verified based on the updated data recording area to be read until a valid data record is found.
7. The method of claim 5, further comprising, upon powering up a system in which the flash memory is loaded:
determining whether all data recording areas of the flash memory are empty data recording areas or non-empty data recording areas;
determining whether the data record stored in the non-empty data recording area is a valid data record based on the check code; and
and determining a data recording area storing valid data records with the maximum identification value as a data recording area to be read, and determining the data recording area to be written as an empty data recording area which is logically closest to the data recording area to be read.
8. The method of claim 1, further comprising:
and after the writing is finished, determining the data recording area to be written as a data recording area to be read.
9. The flash data read-write method of claim 1, wherein the data record further comprises an encapsulation header field, the encapsulation header field identifying a start of the data record.
10. A flash memory data read-write apparatus, comprising:
the flash memory comprises one or more flash memory blocks, each flash memory block is divided into a plurality of data recording areas, and each data recording area is used for writing one data record;
an erasing module that erases at least one flash block of the flash memory if there is no empty data recording area in the flash memory for use as the data recording area to be written, in which case the determining module determines the data recording area to be written in the erased flash block; and
and the writing module writes the data to be written into the data recording area in a data record form, wherein the data record comprises a load field and an identification field for setting an identification value, and the identification value of the newly written data record is increased by a preset value on the basis of the identification value of the last written data record.
11. The flash memory data read/write apparatus as claimed in claim 10, wherein
The determining module determines the data recording area to be written as an empty data recording area of a non-empty data recording area logically and continuously storing the data record with the maximum identification value in the flash memory;
and if the flash memory does not have a non-empty data recording area, the determining module determines the data recording area to be written as a first data recording area in the flash memory.
12. The flash memory data read/write apparatus as claimed in claim 10, wherein
The flash memory comprises at least two flash memory blocks;
and if no empty data recording area exists in the at least two flash memory blocks and is used as the data recording area to be written, the erasing module erases at least one flash memory block which does not store the data record with the maximum identification value.
13. The flash memory data read/write apparatus as claimed in claim 12, wherein
The determining module determines the data recording area to be written from the at least two flash memory blocks in sequence when determining the data recording area to be written;
if there is no empty data recording area in the at least two flash memory blocks to be used as the data recording area to be written, the erasing module erases a next flash memory block of the flash memory block in which the data record having the largest identification value is stored, and the determining module determines the data recording area to be written in the next flash memory block.
14. The flash data read/write apparatus of claim 10, wherein the data recording area further comprises a check field for storing a check code.
15. The flash data read-write apparatus according to claim 14, wherein the determining module further determines a data recording area to be read in a non-empty data recording area of the flash memory, the data recording area to be read being a data recording area storing a data record having a maximum identification value,
the flash memory data read-write device also comprises a read and check module which reads data records from the data record area to be read and checks the data records through the check code, wherein,
if the verification is successful, the read and verification module determines the read data record as a valid data record;
if the verification is unsuccessful, the determination module determines the data recording area to be read as a data recording area storing data records having identification values that are decremented by the predetermined value from the identification values of the read data records, and the reading and verifying module reads the data records and verifies based on the updated data recording area to be read until a valid data record is found.
16. The flash memory data read/write apparatus of claim 14, wherein, upon power-up of a system in which the flash memory is loaded:
the determining module determines whether all data recording areas of the flash memory are empty data recording areas or non-empty data recording areas;
the reading and checking module determines whether the data record stored in the non-empty data recording area is a valid data record based on the check code; and
the determining module determines a data recording area storing valid data records with the maximum identification value as a data recording area to be read, and determines the data recording area to be written as an empty data recording area logically closest to the data recording area to be read.
17. The flash memory data read/write apparatus of claim 10, further comprising:
after the writing module completes the writing, the determining module determines the data recording area to be written as a data recording area to be read.
18. The flash data read/write apparatus of claim 10, wherein the data record further comprises an envelope header field (0xAA) for identifying the start of the data record.
19. A flash memory data read-write device comprises a memory and a processor, wherein,
the memory is used for storing program codes;
the processor is configured to perform the following operations when executing the program code:
determining a data recording area to be written in an empty data recording area of a flash memory, wherein the flash memory comprises one or more flash memory blocks, each flash memory block is divided into a plurality of data recording areas, and each data recording area is used for writing one data record;
if no empty data recording area exists in the flash memory and is used as the data recording area to be written, erasing at least one flash memory block of the flash memory, and determining the data recording area to be written in the erased flash memory block; and
and writing the data to be written into the data record area to be written in the form of data records, wherein the data records comprise a load field and an identification field for setting an identification value, and the identification value of the newly written data record is increased by a preset value on the basis of the identification value of the last written data record.
CN202010893456.0A 2020-08-31 2020-08-31 Flash memory data read-write method and flash memory data read-write device Pending CN114115700A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010893456.0A CN114115700A (en) 2020-08-31 2020-08-31 Flash memory data read-write method and flash memory data read-write device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010893456.0A CN114115700A (en) 2020-08-31 2020-08-31 Flash memory data read-write method and flash memory data read-write device

Publications (1)

Publication Number Publication Date
CN114115700A true CN114115700A (en) 2022-03-01

Family

ID=80359819

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010893456.0A Pending CN114115700A (en) 2020-08-31 2020-08-31 Flash memory data read-write method and flash memory data read-write device

Country Status (1)

Country Link
CN (1) CN114115700A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101923516A (en) * 2009-05-15 2010-12-22 旺宏电子股份有限公司 Block-based flash memory and its operation method
CN102314396A (en) * 2010-07-06 2012-01-11 旺宏电子股份有限公司 Method and device for accessing bytes by taking a block as base flash
CN102831072A (en) * 2012-08-10 2012-12-19 深圳市江波龙电子有限公司 Flash memory device, and management method, data read-write method and data read-write device thereof
CN102841851A (en) * 2012-07-19 2012-12-26 深圳市江波龙电子有限公司 Flash memory management method and flash memory device
CN103597444A (en) * 2011-06-09 2014-02-19 微软公司 Managing data placement on flash-based storage by use

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101923516A (en) * 2009-05-15 2010-12-22 旺宏电子股份有限公司 Block-based flash memory and its operation method
CN102314396A (en) * 2010-07-06 2012-01-11 旺宏电子股份有限公司 Method and device for accessing bytes by taking a block as base flash
CN103597444A (en) * 2011-06-09 2014-02-19 微软公司 Managing data placement on flash-based storage by use
CN102841851A (en) * 2012-07-19 2012-12-26 深圳市江波龙电子有限公司 Flash memory management method and flash memory device
CN102831072A (en) * 2012-08-10 2012-12-19 深圳市江波龙电子有限公司 Flash memory device, and management method, data read-write method and data read-write device thereof

Similar Documents

Publication Publication Date Title
US10552311B2 (en) Recovery for non-volatile memory after power loss
US6601132B2 (en) Nonvolatile memory and method of writing data thereto
JP4560408B2 (en) Method for controlling nonvolatile memory device
US8412879B2 (en) Hybrid implementation for error correction codes within a non-volatile memory system
US7543137B2 (en) Information processing device and information processing method
US6388919B2 (en) Memory controller for flash memory system and method for writing data to flash memory device
US7911840B2 (en) Logged-based flash memory system and logged-based method for recovering a flash memory system
US6687784B2 (en) Controller for controlling nonvolatile memory unit
US6711663B2 (en) Algorithm of flash memory capable of quickly building table and preventing improper operation and control system thereof
EP0589597A2 (en) Flash non-volatile memory
EP1533703A2 (en) Method for controlling non-volatile semiconductor memory system
US20020085433A1 (en) Data management system and data management method
CN103425589A (en) Control apparatus, storage device, and storage control method
JP2005284700A (en) Memory card
JP7143735B2 (en) memory controller and memory system
US8301981B2 (en) Data access method for flash memory and storage system and controller thereof
JP2004220068A (en) Memory card and method for writing data in memory
US7257030B2 (en) Operating a storage component
JP5660521B2 (en) Nonvolatile semiconductor memory device and memory management method
CN112347002A (en) flash data storage method and system, computer equipment and storage medium
CN114115700A (en) Flash memory data read-write method and flash memory data read-write device
CN113434086A (en) Data storage method and device, nonvolatile memory device and memory
US20070274302A1 (en) Data Storage Device, Memory Managing Method, and Program
JP2000357216A (en) Ic card
US7346730B2 (en) Mobile electronic device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination