Off-chip storage read-write method and device and computer readable storage medium
By dividing off-chip storage into basic ermination units and using data block header information for verification, the read errors and shortened device life problems caused by frequent off-chip FLASH ermination are solved, achieving better fault tolerance and better performance Long service life of the equipment.
Patent Information
- Application Number
- CN202411758094.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-03
- Publication Date
- 2025-01-03
- Estimated Expiration
- 2044-12-03
Smart Images

Figure CN119248202A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data storage, and in particular to an off-chip storage reading and writing method, device and computer-readable storage medium. Background Art
[0002] In the prior art, off-chip FLASH (flash memory, i.e., non-volatile memory) is relative to the built-in FLASH of MCU (Micro Controller Unit). Usually, the erase and write life of FLASH is nominally greater than 100,000 times.
[0003] Generally, the built-in FLASH of MCU has a small capacity and is mainly used to store program code. It is not frequently erased and written. If it is frequently erased and written, the FLASH on the chip will be damaged, thus affecting the service life of the MCU.
[0004] In actual projects, a lot of data needs to be written to FLASH frequently. Considering the above factors, it is obviously not appropriate to use the MCU's on-chip FLASH. For this reason, many projects will match the appropriate off-chip FLASH.
[0005] However, there are still three technical problems to be solved in the process of using off-chip FLASH: First, the FLASH read data is wrong; Second, due to the change in the number of data structure members, errors occurred in reading data from FLASH after the software was upgraded; Third, due to frequent erasing of FLASH, FLASH is damaged, which shortens the service life of the product. Summary of the invention
[0006] In order to overcome the deficiencies in the prior art, the purpose of the present invention is to provide an off-chip storage reading and writing method, device and computer-readable storage medium, which are used to solve the current FLASH reading data errors, as well as the data reading errors from FLASH after software upgrade due to changes in the number of data structure members, and the FLASH damage caused by frequent erasing and writing of FLASH, thereby shortening the product life.
[0007] The present invention proposes an off-chip storage reading and writing method, wherein the off-chip storage is divided into a plurality of basic erasing and writing units, the starting page of each of the basic erasing and writing units is used for bad block identification, and the remaining pages are used for data storage, wherein the data block for performing data storage includes a header and a data field, and the method comprises: Finding a basic erase unit storing data to retrieve the head of a data block where data storage was performed most recently; According to the header information of the header, in the basic erasing and writing unit that meets the read condition, determining the first address of the data field of the data block, and reading the data according to the first address; or, According to the header information, in a basic erasing unit that meets the writing condition, the first address of the data block is determined, and the data is written according to the first address.
[0008] Optionally, searching for a basic erasable unit storing data specifically includes: Read the bad block identification of the basic erase unit in sequence, and calculate the first address of the first page without a bad block; The byte data of the header is read according to the first address, and it is determined whether the byte data are all reset values.
[0009] Optionally, the determining whether the byte data are all reset values further includes: If the byte data are all reset values, it is determined that the current basic erasing unit is empty; Jump to the next basic erasing unit to continue to perform the operation of sequentially reading the bad block identification of the basic erasing unit.
[0010] Optionally, the step of continuing to perform the operation of sequentially reading the bad block identification of the basic erasing unit further includes: If it is determined that all basic erasing units are empty, the first basic erasing unit is returned; Writing a preset default value from the first address of the first page without a bad block of the first basic erase unit, and performing a preset read-back verification operation; If the read-back check fails, the currently involved page is marked as a page with a bad block, and if the read-back check passes, it is determined that the default value is written successfully, and the operation ends.
[0011] Optionally, the determining whether the byte data are all reset values further includes: If the byte data are not all reset values, then the check value of the first byte of the header read is calculated and compared with the check code of the second byte pre-stored in the header; If they match, it is determined that the data in the header is valid, the header of the next data block is read according to the data in the header, and a header check of the next data block is performed; If they do not match, it is determined that the data in the header is invalid, and the current basic erasing unit is erased, and the currently involved page is marked as a page with a bad block.
[0012] Optionally, performing header verification of the next data block further includes: Determine whether all byte data in the header of the next data block are reset values; If the byte data are not all reset values, continue to perform the steps of calculating the check value of the first bytes of the read header and comparing it with the check code of the second bytes pre-stored in the header; If the byte data are all reset values, it is determined that the header of the data block that has stored data most recently has been retrieved.
[0013] Optionally, if the verification fails, marking the currently involved page as a page with a bad block further includes: Write the bad block information of the page with bad blocks into the starting page of the current basic erase unit; Move to the next basic erase unit and calculate the first address of the first page without bad blocks; Writing the default value starting from the first address and performing the read-back verification operation; If the read-back check fails, the current basic erase unit is erased and the currently involved page is marked as a page with a bad block. If the read-back check passes, it is determined that the default value is written successfully and the operation ends.
[0014] Optionally, the step of determining the first address of the data field of the data block in a basic erasing unit that meets the read condition according to the header information of the header, and reading the data according to the first address, further comprises: Calculating the check code of the data field and comparing it with the check code of the data field pre-stored in the header; If they match, the data in the read data field is determined to be valid, and the read operation ends; If they do not match, the current basic erase unit is erased and the page currently involved is marked as a page with a bad block.
[0015] Optionally, the step of determining the first address of a data block in a basic erasing unit that meets the writing condition according to the header information, and writing data according to the first address, further comprises: Obtaining the first address of the next data block according to the header information, and judging whether the last address of the next data block exceeds the last address of the current basic erase unit in combination with the byte length of the next data block; If exceeded, the current basic erasing unit is erased, and the bad block information of the current basic erasing unit is written into the starting page of the current basic erasing unit; the next basic erasing unit is transferred to continue to perform the step of determining the first address of the data block in the basic erasing unit that meets the read condition according to the header information of the header; If not exceeded, the header information of the current header is calculated and the member values of the data field are updated.
[0016] Optionally, after writing the data according to the first address, the method further includes: Read back the data of the written data block and perform verification; If the check fails, the page currently involved is marked as a page with a bad block, the current basic erasing unit is erased, and the bad block information is written into the starting page of the current basic erasing unit; the next basic erasing unit is transferred to continue to perform the step of determining the first address of the data block in the basic erasing unit that meets the read condition according to the header information of the header; If the verification passes, the data in the written data block is determined to be valid and the write operation ends.
[0017] The present invention also proposes an off-chip storage reading and writing device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the steps of the off-chip storage reading and writing method as described in any one of the above items are implemented.
[0018] The present invention also proposes a computer-readable storage medium, on which an off-chip storage read-write program is stored. When the off-chip storage read-write program is executed by a processor, the steps of the off-chip storage read-write method as described in any one of the above items are implemented.
[0019] The off-chip storage read-write method, device and computer-readable storage medium of the present invention are implemented to retrieve the header of the data block where the data storage was performed most recently by searching for the basic erase-write unit with stored data; according to the header information of the header, the first address of the data field of the data block is determined in the basic erase-write unit that meets the read condition, and the data is read according to the first address; or, according to the header information, the first address of the data block is determined in the basic erase-write unit that meets the write condition, and the data is written according to the first address. An off-chip storage read-write solution with better fault tolerance is realized, which effectively avoids data reading errors from FLASH after software upgrades due to changes in the number of data structure members, or FLASH damage caused by frequent erase-write of FLASH, thereby extending the service life of the product. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The present invention will be further described below with reference to the accompanying drawings and embodiments, in which: Figure 1 is a first flow chart of the off-chip storage reading and writing method of the present invention; Figure 2 is a second flow chart of the off-chip storage reading and writing method of the present invention; Figure 3 is a third flow chart of the off-chip storage reading and writing method of the present invention; Figure 4 is a fourth flow chart of the off-chip storage reading and writing method of the present invention; Figure 5 is a fifth flow chart of the off-chip storage reading and writing method of the present invention; Figure 6 is a sixth flow chart of the off-chip storage reading and writing method of the present invention; Figure 7 is the seventh flow chart of the off-chip storage reading and writing method of the present invention; Figure 8 is an eighth flow chart of the off-chip storage reading and writing method of the present invention; Fig. 9 is a ninth flow chart of the off-chip storage reading and writing method of the present invention; Fig.10 is the tenth flow chart of the off-chip storage reading and writing method of the present invention; Fig.11 is the eleventh flow chart of the off-chip storage reading and writing method of the present invention; Fig.12 is a twelfth flow chart of the off-chip storage reading and writing method of the present invention; Fig.13 is the thirteenth flow chart of the off-chip storage reading and writing method of the present invention; Fig.14 It is a working principle diagram of the minimum application system of the off-chip storage reading and writing method of the present invention; Fig.15 It is a data structure design diagram of a data block of the off-chip storage reading and writing method of the present invention. DETAILED DESCRIPTION
[0021] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0022] In the subsequent description, the suffixes such as "module", "component" or "unit" used to represent elements are only used to facilitate the description of the present invention, and have no specific meanings. Therefore, "module", "component" or "unit" can be used in a mixed manner.
[0023] Figure 1 This is the first flow chart of the off-chip storage reading and writing method of the present invention. This embodiment proposes an off-chip storage reading and writing method, wherein the off-chip storage is divided into a plurality of basic erasing and writing units, the starting page of each of the basic erasing and writing units is used for bad block identification, and the remaining pages are used for data storage, wherein the data block for data storage includes a header and a data field, and the method includes: S1, searching for a basic erase unit storing data to retrieve the header of a data block where data storage was performed most recently; S2, according to the header information of the header, in the basic erasing and writing unit that meets the read condition, determining the first address of the data field of the data block, and reading the data according to the first address; or, S2`, according to the header information, determine the first address of the data block in the basic erasing unit that meets the writing conditions, and write data according to the first address.
[0024] Please refer to Fig.14 The working principle diagram of the minimum application system of the off-chip storage read-write method of the present invention is shown. In this embodiment, the minimum system of the application external storage read-write method includes MCU, FLASH and supercapacitor. Among them, MCU is used to implement the logic algorithm and control algorithm of the method described in this embodiment, FLASH is the operation object in the method described in this embodiment, and the supercapacitor is used to ensure that when the external power supply fails abnormally, the minimum system can still maintain normal operation for a period of time, and ensure that FLASH safely completes the write operation before powering off to avoid the loss of important data. Optionally, in this embodiment, MCU can be replaced by MPU (Micro Processor Unit) or a single-chip microcomputer.
[0025] In this embodiment, the erasing modes of FLASH include sector erasing (Sector Erase), block erasing (BlockErase) and chip erasing (Chip Erase). In actual projects, Sector erasing or Block erasing is generally selected, so the basic unit of erasing is divided according to Sector or Block. Among them, the difference between Sector and Block is that the storage space of Block is much larger than that of Sector. Optionally, in this embodiment, the W25Q64FV off-chip storage chip is taken as an example for explanation. The chip has a total of 8Mbytes, divided into 2048 sectors, each sector has 16 pages; divided into 128 blocks, each block has 256 pages; each page has 256 bytes.
[0026] Please refer to Fig.15The data structure design diagram of the data block of the off-chip storage read-write method of the present invention is shown. In this embodiment, in order to accurately and effectively read the data stored in the FLASH, before writing data to the FLASH, it is necessary to reasonably design the data block structure. The data block structure includes a "header" and a "data field", wherein the "header" includes: Last_Addr, Next_Addr, Data_Len, CRC_Data, CRC_Head; the "data field" includes: Data_Field. Specifically, Last_Addr refers to the first address of the last written data; Next_Addr refers to the first address of the next written data; Data_Len refers to the total number of bytes filled in the data field; CRC_Data refers to the checksum of the data field, that is, the checksum of all the data in Data_Field; CRC_Head refers to the checksum of the header, that is, the data checksum of the header from Last_Addr to CRC_Data; Data_Field refers to the data field, that is, the data that really needs to be stored.
[0027] In this embodiment, the FLASH read operation method includes three main steps: first, find the basic erase unit with stored data; second, retrieve the header information of the most recently stored data; finally, determine the first address of the data field according to the header information of the most recently stored data, so as to read the data. Among them, the design is based on the Sector as the basic erase unit, and the first page (i.e., page 0) of each Sector is used as the bad block information identification page; after power-on, the search starts from the first basic erase unit until the header information of the most recently stored data block is obtained, and then the data field data of the data block is read to end the read operation.
[0028] In this embodiment, the FLASH write operation method includes three main steps: first, searching for the basic erase unit storing data; second, retrieving the header information of the most recently stored data; finally, determining the starting address of the next data write based on the header information of the most recently stored data block, and writing the data.
[0029] The beneficial effect of this embodiment is that by searching for the basic erase and write unit with stored data, the header of the data block where data storage was performed most recently is retrieved; according to the header information of the header, the first address of the data field of the data block is determined in the basic erase and write unit that meets the read condition, and the data is read according to the first address; or, according to the header information, the first address of the data block is determined in the basic erase and write unit that meets the write condition, and the data is written according to the first address. A more fault-tolerant off-chip storage read-write solution is implemented, which effectively avoids data reading errors from FLASH after software upgrades due to changes in the number of data structure members, or FLASH damage due to frequent erase and write of FLASH, thereby extending the product life.
[0030] Figure 2 4 is a second flow chart of the off-chip storage read-write method of the present invention. Based on the above embodiment, the step of searching for a basic erase unit storing data specifically includes: S100, reading the bad block identification of the basic erasing unit in sequence, and calculating the first address of the first page without a bad block; S200, reading the byte data of the header according to the first address, and determining whether the byte data are all reset values.
[0031] Figure 3 3 is a third flow chart of the off-chip storage reading and writing method of the present invention. Based on the above embodiment, the step of judging whether the byte data are all reset values further includes: S210, if the byte data are all reset values, determining that the current basic erasing unit is empty; S211, jumping to the next basic erasing unit to continue to execute the operation of sequentially reading the bad block identification of the basic erasing unit.
[0032] Figure 4 The fourth flow chart of the off-chip storage reading and writing method of the present invention is based on the above embodiment, and further includes the following steps to continue to perform the operation of sequentially reading the bad block identification of the basic erasing unit: S212: If it is determined that all basic erasing units are empty, return to the first basic erasing unit; S213, writing a preset default value starting from the first address of the first page without a bad block of the first basic erase unit, and performing a preset read-back verification operation; S214: If the read-back check fails, the currently involved page is marked as a page with a bad block; if the read-back check passes, it is determined that the default value is written successfully, and the operation ends.
[0033] Figure 5 5 is a fifth flow chart of the off-chip storage reading and writing method of the present invention. Based on the above embodiment, the step of judging whether the byte data are all reset values further includes: S220, if the byte data are not all reset values, calculate the check value of the first byte of the read header, and compare it with the check code of the second byte pre-stored in the header; S221, if it matches, determine that the data in the header is valid, read the header of the next data block according to the data in the header, and perform header verification on the next data block; S222: If there is no match, determine that the data in the header is invalid, erase the current basic erase unit, and mark the currently involved page as a page with a bad block.
[0034] Figure 6 This is a sixth flow chart of the off-chip storage reading and writing method of the present invention. Based on the above embodiment, the step of performing header verification of the next data block further includes: S230, determining whether all byte data in the header of the next data block are reset values; S231, if the byte data are not all reset values, continue to execute the step of calculating the check value of the first byte of the read header and comparing it with the check code of the second byte pre-stored in the header; S232: If the byte data are all reset values, it is determined that the header of the data block that most recently stored data has been retrieved.
[0035] Figure 7 This is the seventh flow chart of the off-chip storage reading and writing method of the present invention. Based on the above embodiment, if the verification fails, the step of marking the currently involved page as a page with a bad block further includes: S240, writing the bad block information of the page with bad blocks into the starting page of the current basic erasing unit; S241, transfer to the next basic erase unit, calculate the first address of the first page without bad blocks; S242, writing the default value starting from the first address, and performing the read-back verification operation; S243, if the read-back check fails, the current basic erase unit is erased, and the currently involved page is marked as a page with a bad block. If the read-back check passes, it is determined that the default value is written successfully, and the operation ends.
[0036] Figure 8 The eighth flow chart of the off-chip storage reading and writing method of the present invention, based on the above embodiment, according to the header information of the header, in the basic erasing and writing unit that meets the read condition, the step of determining the first address of the data field of the data block, and reading the data according to the first address further includes: S300, calculating the check code of the data field, and comparing it with the check code of the data field pre-stored in the header; S310, if matched, determining that the data in the read data field is valid, and ending the read operation; S320: If there is no match, the current basic erasing unit is erased, and the currently involved page is marked as a page with a bad block.
[0037] Fig. 9 The ninth flow chart of the off-chip storage reading and writing method of the present invention, based on the above embodiment, according to the header information, in the basic erasing unit that meets the writing condition, the step of determining the first address of the data block and writing data according to the first address further includes: S300`, obtaining the first address of the next data block according to the header information, and judging whether the last address of the next data block exceeds the last address of the current basic erase unit in combination with the byte length of the next data block; S310`, if exceeded, erase the current basic erasing unit, and write the bad block information of the current basic erasing unit into the starting page of the current basic erasing unit; transfer to the next basic erasing unit, and continue to perform the step of determining the first address of the data block in the basic erasing unit that meets the read condition according to the header information of the header; S320`: If not exceeded, calculate the header information of the current header and update the member value of the data field.
[0038] Fig.10 This is the tenth flow chart of the off-chip storage reading and writing method of the present invention. Based on the above embodiment, after the step of writing data according to the first address, it also includes: S330`, read back the data of the written data block and perform verification; S340`, if the check fails, the page currently involved is marked as a page with a bad block, the current basic erasing unit is erased, and the bad block information is written into the starting page of the current basic erasing unit; the next basic erasing unit is transferred to continue to perform the step of determining the first address of the data block in the basic erasing unit that meets the read condition according to the header information of the header; S350`: If the verification passes, it is determined that the data of the written data block is valid, and the write operation ends.
[0039] Please refer to Fig.11 The eleventh flow chart of the off-chip storage reading and writing method of the present invention is shown. In this embodiment, the operation flow of retrieving the header information of the most recently stored data block is as follows: Step 1, read the bad block information of the basic erase unit, calculate the first address of the first page without bad blocks, and execute step 2.
[0040] Step 2, read the first 14 bytes of data starting from the first address, and execute step 3.
[0041] Step 3, determine whether the data of the first 14 bytes are all reset values; if not, execute step 4; if so, determine that the current basic erase unit is empty, jump to the next basic erase unit, and return to step 1 to continue execution; if all basic erase units are empty, return to the first basic erase unit, write the preset default value starting from the first address of the first page without bad blocks, and perform a read back verification operation; if the verification fails, jump to step 9 to execute; if the verification succeeds, it is determined that the preset default value is written successfully, and the memory operation ends.
[0042] Step 4, calculate the check value of the first 12 bytes of the read header information, and compare it with the pre-stored check code (the last 2 bytes); if the comparison result matches, the header data is determined to be valid, and the header 14 bytes of data of the next data block are read according to the Next_Addr in the header information, and step 5 is executed; if the comparison result does not match, the header data is determined to be invalid, and step 8 is executed to erase the current basic erase unit.
[0043] Step 5, determine whether the data of the first 14 bytes are all reset values; if not, determine that the header information of the most recently stored data block has not been retrieved, and return to execute step 4; if so, determine that the header information of the most recently stored data block has been retrieved.
[0044] In this embodiment, the above-mentioned step 9 is a processing method for abnormal situations. In this step, the page currently involved is marked as a page with bad blocks, and the bad block information is written into the specified position of the bad block identification page of the current basic erase unit. Then, it is transferred to the next basic erase unit, and the first address of the first page without bad blocks is calculated. The preset default value is written starting from the first address, and a read-back verification operation is performed; if the verification fails, jump to step 8 for execution; if the verification succeeds, it is determined that the preset default value is written successfully, and the memory operation ends.
[0045] Furthermore, in this embodiment, for the FLASH read operation, a data reverse search is selectively performed, that is, to search for past modification records; at this time, the header information of the valid data block is required, and a reverse search is performed based on the first address (Last_Addr) written in the previous data block.
[0046] Please refer to Fig.12 The twelfth flow chart of the off-chip storage reading and writing method of the present invention is shown. In this embodiment, according to the header information of the header, in the basic erasing and writing unit that meets the read condition, the first address of the data field of the data block is determined, and the data is read according to the first address, which specifically includes: Step 6, calculate the first address of the data field according to the header information of the data block stored most recently, read the data field data, and execute step 7.
[0047] Step 7, calculate the data field data check code and compare it with the data field check code reserved in the header information; if the comparison result matches, it means that the read data field data is valid, and the memory read operation ends; if the comparison result does not match, execute step 8.
[0048] Step 8, erase the current basic erasing unit and execute step 9.
[0049] Step 9, marks the page currently involved as a page with bad blocks, and writes the bad block information to the specified position of the bad block identification page of the current basic erase unit, then transfers to the next basic erase unit, calculates the first address of the first page without bad blocks, writes the preset default value starting from the first address, and performs a read-back verification operation; if the verification fails, jumps to step 8 to execute; if the verification succeeds, it is determined that the preset default value is written successfully, and the memory read operation ends.
[0050] Please refer to Fig.13 The thirteenth flow chart of the off-chip storage reading and writing method of the present invention is shown. In this embodiment, according to the header information, in the basic erasing unit that meets the writing condition, the first address of the data block is determined, and the data is written according to the first address, which specifically includes: Step 1, retrieve the header information of the most recently stored data block, and execute step 2.
[0051] Step 2, obtain the first address of the next data block storage according to the header information, and determine whether the end address of the current data block exceeds the end address of the current basic erase unit in combination with the data block byte length; if it exceeds, execute step 3; if not, execute step 4.
[0052] Step 3, erase the current basic erasing unit, write the bad block information of the current basic erasing unit into the specified position of its bad block identification page; then, transfer to the next basic erasing unit; calculate the first address of the data block stored in the next basic erasing unit.
[0053] Step 4, calculate the header information of the data block and update the data field member value; wherein the calculation of the header information includes calculating the first address (Last_Addr) of the previous data block storage, calculating the first address (Next_Addr) of the next data block storage, calculating the byte length (Data_Len) of the data field of this data block, calculating the check value (CRC_Data) of the data field of this data block, and calculating the check value (CRC_Head) of the header information of this data block.
[0054] Step 5, based on the first address, write all the information of the data block to the memory, and read back the content just written for verification; if the verification fails, mark the current page involved as a page with bad blocks, and then return to step 3 to continue execution; if the verification succeeds, it indicates that the data is written successfully, and the memory write operation ends.
[0055] It can be seen that in this embodiment, data verification is performed on both the "header" and the "data field" of the data block to reduce the probability of parameter reading errors.
[0056] In this embodiment, by adopting the above-mentioned data structure design, the dependence of FLASH read and write operations on the data structure length is reduced. Therefore, when the number of members of the data field changes (increases or decreases), it will not cause technical problems such as FLASH read data addressing errors after software upgrades, thereby reducing the maintenance cost of the product.
[0057] In this embodiment, based on the above data structure design, the first and second storages do not depend on the continuity of the storage address.
[0058] In this embodiment, a plurality of basic erasing units are allocated for each group of parameters for cyclic erasing, thereby reducing the erasing frequency of the same address of the FLASH, thereby extending the service life of the product.
[0059] Based on the above embodiments, the present invention also proposes an off-chip storage read-write device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program, when executed by the processor, implements the steps of the off-chip storage read-write method as described in any one of the above items.
[0060] It should be noted that the above-mentioned device embodiment and method embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, and the technical features in the method embodiment are correspondingly applicable in the device embodiment, which will not be repeated here.
[0061] Based on the above embodiments, the present invention also proposes a computer-readable storage medium, which stores an off-chip storage read and write program. When the off-chip storage read and write program is executed by a processor, the steps of the off-chip storage read and write method as described in any of the above items are implemented.
[0062] It should be noted that the above-mentioned medium embodiment and method embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, and the technical features in the method embodiment are correspondingly applicable in the medium embodiment, which will not be repeated here.
[0063] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0064] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0065] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation modes, which are merely illustrative rather than restrictive. Under the guidance of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the present invention and the claims, all of which are within the protection of the present invention.
Claims
1. A method for reading and writing off-chip storage, characterized in that: The off-chip storage is divided into a plurality of basic erasing and writing units, the starting page of each basic erasing and writing unit is used for bad block identification, and the remaining pages are used for data storage, wherein the data block for performing data storage includes a header and a data field, and the method comprises: Finding a basic erase unit storing data to retrieve the head of a data block where data storage was performed most recently; According to the header information of the header, in the basic erasing and writing unit that meets the read condition, determining the first address of the data field of the data block, and reading the data according to the first address; or, According to the header information, in a basic erasing unit that meets the writing condition, the first address of the data block is determined, and the data is written according to the first address.
2. The off-chip storage reading and writing method according to claim 1, characterized in that: The step of searching for a basic erasable unit storing data specifically includes: Read the bad block identification of the basic erase unit in sequence, and calculate the first address of the first page without a bad block; The byte data of the header is read according to the first address, and it is determined whether the byte data are all reset values.
3. The off-chip storage reading and writing method according to claim 2, characterized in that: The determining whether the byte data are all reset values further includes: If the byte data are all reset values, it is determined that the current basic erasing unit is empty; Jump to the next basic erasing unit to continue to perform the operation of sequentially reading the bad block identification of the basic erasing unit.
4. The off-chip storage reading and writing method according to claim 3, characterized in that: The method further comprises: continuing to perform the operation of sequentially reading the bad block identification of the basic erasing unit; If it is determined that all basic erasing units are empty, the first basic erasing unit is returned; Writing a preset default value from the first address of the first page without a bad block of the first basic erase unit, and performing a preset read-back verification operation; If the read-back check fails, the currently involved page is marked as a page with a bad block, and if the read-back check passes, it is determined that the default value is written successfully, and the operation ends.
5. The off-chip storage reading and writing method according to claim 2, characterized in that: The determining whether the byte data are all reset values further includes: If the byte data are not all reset values, then the check value of the first byte of the header read is calculated and compared with the check code of the second byte pre-stored in the header; If they match, it is determined that the data in the header is valid, the header of the next data block is read according to the data in the header, and a header check of the next data block is performed; If they do not match, it is determined that the data in the header is invalid, and the current basic erasing unit is erased, and the currently involved page is marked as a page with a bad block.
6. The off-chip storage reading and writing method according to claim 5, characterized in that: The step of performing header verification of the next data block further comprises: Determine whether all byte data in the header of the next data block are reset values; If the byte data are not all reset values, continue to perform the steps of calculating the check value of the first bytes of the read header and comparing it with the check code of the second bytes pre-stored in the header; If the byte data are all reset values, it is determined that the header of the data block that has stored data most recently has been retrieved.
7. The off-chip storage reading and writing method according to claim 4, characterized in that: If the verification fails, marking the currently involved page as a page with a bad block further includes: Write the bad block information of the page with bad blocks into the starting page of the current basic erase unit; Move to the next basic erase unit and calculate the first address of the first page without bad blocks; Writing the default value starting from the first address and performing the read-back verification operation; If the read-back check fails, the current basic erase unit is erased and the currently involved page is marked as a page with a bad block. If the read-back check passes, it is determined that the default value is written successfully and the operation ends.
8. The off-chip storage reading and writing method according to claim 1, characterized in that: The method further comprises: determining the first address of the data field of the data block in the basic erasing unit that meets the read condition according to the header information of the header, and reading the data according to the first address. Calculating the check code of the data field and comparing it with the check code of the data field pre-stored in the header; If they match, the data in the read data field is determined to be valid, and the read operation ends; If they do not match, the current basic erase unit is erased and the page currently involved is marked as a page with a bad block.
9. The off-chip storage reading and writing method according to claim 1, characterized in that: The method further comprises: determining the first address of the data block in the basic erasing unit that meets the writing condition according to the header information, and writing the data according to the first address. Obtaining the first address of the next data block according to the header information, and judging whether the last address of the next data block exceeds the last address of the current basic erase unit in combination with the byte length of the next data block; If exceeded, the current basic erasing unit is erased, and the bad block information of the current basic erasing unit is written into the starting page of the current basic erasing unit; the next basic erasing unit is transferred to continue to perform the step of determining the first address of the data block in the basic erasing unit that meets the read condition according to the header information of the header; If not exceeded, the header information of the current header is calculated and the member values of the data field are updated.
10. The off-chip storage reading and writing method according to claim 1, characterized in that: After writing the data according to the first address, the method further comprises: Read back the data of the written data block and perform verification; If the check fails, the page currently involved is marked as a page with a bad block, the current basic erasing unit is erased, and the bad block information is written into the starting page of the current basic erasing unit; the next basic erasing unit is transferred to continue to perform the step of determining the first address of the data block in the basic erasing unit that meets the read condition according to the header information of the header; If the verification passes, the data in the written data block is determined to be valid and the write operation ends.
11. An off-chip storage read-write device, characterized in that: The device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the steps of the off-chip storage reading and writing method according to any one of claims 1 to 10 are implemented.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores an off-chip storage read-write program, and when the off-chip storage read-write program is executed by the processor, the steps of the off-chip storage read-write method according to any one of claims 1 to 10 are implemented.
Citation Information
Patent Citations
Flash memory management based on sector access
CN101075211A
Method for erasing and writing data of FLASH memory
CN102306125A
Data storage method based on NAND FLASH, terminal device and storage medium
CN109343790A
Bad block detection method, computer program product and electronic equipment
CN116264096A
Power-down messy code protection method for yaffs file system
CN117112290A
