Method for solving slow storage of NORFLASH
By dynamically judging the state of the NORFLASH storage area and optimizing the erase and write operation process, the problem of slow NORFLASH storage is solved, which improves storage efficiency and extends service life.
Patent Information
- Application Number
- CN202510482758.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-17
- Publication Date
- 2025-07-18
AI Technical Summary
The write operation of NORFLASH requires pre-erase to be fully 0xFF state and long erase time, resulting in a significant increase in storage time. The prior art does not fully utilize the characteristic of bit change from 1 to 0, resulting in frequent redundant erase and write operations.
By dynamically judging the data status of the storage area, determining whether it is 0xFF or consistent with the data to be written, intelligently skipping redundant erasing and write operations, and only performing erasing and writing when necessary, optimizing the operation process.
It significantly reduces the number of erases and writes of NORFLASH, improves storage efficiency by more than 30%, reduces physical losses, and extends service life.
Smart Images

Figure CN120335726A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and particularly to a method for solving the slow storage of NOR Flash. Background Art
[0002] In an embedded system, NOR Flash is widely used for storing program codes and critical data due to its non-volatility, high reliability, and fast random read ability. However, the physical characteristics of NOR Flash result in significant storage performance bottlenecks: (1) The write operation of NOR Flash requires that the target area must be pre-erased to the all-0xFF state, and the minimum erasure unit is a sector (usually 4KB), while the minimum write unit is a page (usually 256 bytes). Before each data storage, it is necessary to calculate the sectors involved according to the write address and length, perform the erasure operation, and then rewrite the data. (2) In the prior art, regardless of whether the area to be written has been erased or the data is consistent with the content to be written, a unified sector erasure needs to be performed. Since the erasure operation takes a long time (usually in the order of dozens of milliseconds), and the unmodified data needs to be rewritten after erasure, the storage time is significantly increased. (3) NOR Flash allows the bits of the storage unit to be changed from 1 to 0 through programming, but it is irreversible. The prior art does not make full use of this feature. When the area to be written is already all 0xFF or the data does not need to be modified, the erasure and write processes are still mechanically executed, and the number of operations cannot be reduced. Summary of the Invention
[0003] The present invention provides a method that can dynamically judge the state of the storage area and reduce redundant erasure and write operations to improve the storage performance of NOR Flash.
[0004] The technical solution adopted by the present invention is as follows: A method for solving the slow storage of NOR Flash, comprising the following steps:
[0005] Step 1: Determine the corresponding sector number and the remaining writable length according to the address and length of the data to be written;
[0006] Step 2: Read the current data of the sector from NOR Flash and extract the existing data of the area to be written;
[0007] Step 3: Compare the data to be written with the existing data;
[0008] Step 4: If the existing data is exactly the same as the data to be written, skip the write operation;
[0009] Step 5: If the existing data is all 0xFF, directly write the data to be written without performing the erasure operation;
[0010] Step 6: If the existing data is inconsistent with the data to be written and there are non-0xFF bits, erase the sector and then perform the write operation.
[0011] Step 7: Repeat the above steps until all data is stored.
[0012] As a further improvement of the present invention, the calculation method of the sector number in Step 1 is: divide the address to be written by the number of bytes of a single sector, and take the integer part as the sector number.
[0013] As a further improvement of the present invention, the calculation method of the remaining writable length in Step 1 is: subtract the remainder of the address to be written divided by the number of bytes of a single sector from the number of bytes of a single sector.
[0014] As a further improvement of the present invention, the extraction range of the existing data in Step 2 includes the data segment from the sector start address offset corresponding to the address to be written to the remaining writable length.
[0015] As a further improvement of the present invention, if the length of the data to be written in Step 4 is 0, directly terminate the storage process.
[0016] As a further improvement of the present invention, if the existing data is all 0xFF in Step 5, only write the pages in the data to be written that are different from the original data, and skip the unmodified pages.
[0017] As a further improvement of the present invention, the trigger condition for the erase operation in Step 6 is: there is at least one bit in the data to be written that needs to change from 0 to 1.
[0018] As a further improvement of the present invention, the method is executed by a processor in an embedded system and is configured to judge the data status in real time to optimize the number of erase and write operations.
[0019] Advantages of the present invention: By dynamically judging the data status in the area to be written (including whether it is all 0xFF and whether it is consistent with the data to be written), the present invention intelligently skips redundant erase and write operations, significantly reducing the number of erase operations, write operations, and the amount of invalid data write-back in NORFLASH, thereby increasing the storage efficiency by more than 30% (the specific value needs to be verified by actual measurement), while reducing the physical wear of the storage medium and extending the service life of NORFLASH. Description of the Drawings
[0020] Figure 1 It is a flowchart of a method for solving the slow storage problem of NORFLASH in the present invention. Detailed Embodiments
[0021] In order to make the technical problems, technical solutions and beneficial effects to be solved by this application more clear and understandable, the following further details this application in combination with the accompanying drawings and embodiments. It should be understood that the embodiments described herein are only used to explain this application and are not used to limit this application.
[0022] The present invention provides a method for solving the slow storage of NORFLASH, including the following steps:
[0023] Step 1: According to the address and length of the data to be written, determine the corresponding sector number and the remaining writable length. The calculation method of the sector number is: divide the address to be written by the number of bytes of a single sector, and take the integer part as the sector number. The calculation method of the remaining writable length is: the number of bytes of a single sector minus the remainder of the address to be written divided by the number of bytes of a single sector;
[0024] Step 2: Read the current data of the sector from NORFLASH, and extract the existing data in the area to be written. The extraction range of the existing data includes the data segment from the sector start address offset corresponding to the address to be written to the remaining writable length;
[0025] Step 3: Compare the data to be written with the existing data;
[0026] Step 4: If the existing data is exactly the same as the data to be written, skip the write operation. If the length of the data to be written is 0, directly terminate the storage process;
[0027] Step 5: If the existing data is all 0xFF, directly write the data to be written without performing an erase operation. If the existing data is all 0xFF, only write the pages in the data to be written that are different from the original data, and skip the unmodified pages;
[0028] Step 6: If the existing data is inconsistent with the data to be written and there are non-0xFF bits, perform an erase operation on the sector and then perform a write operation. The trigger condition for the erase operation is: there is at least one bit in the data to be written that needs to change from 0 to 1;
[0029] Step 7: Repeat the above steps until all data is stored.
[0030] The method of the present invention is executed by a processor in an embedded system and is configured to judge the data status in real time to optimize the number of erase and write operations.
[0031] Embodiment:
[0032] The following describes the embodiments of the present invention in detail in combination with specific application scenarios. Assume that in an embedded system, the size of a single sector of NORFLASH is 4KB (4096 bytes), and the page size is 256 bytes. It is necessary to store new data with a length of 1024 bytes in the NORFLASH area starting from the address 0x2000. The specific implementation steps are as follows:
[0033] Step 1 (Determine the sector number and the remaining writable length)
[0034] Calculate the sector number: The address to be written is 0x2000 (8192 in decimal), and a single sector is 4096 bytes. Sector number = 8192 / 4096 = 2, that is, the target sector is the 2nd sector.
[0035] Calculate the remaining writable length: Address offset = 8192 % 4096 = 0, that is, the starting address of the current sector is 8192, and the remaining writable length is 4096 bytes. Since the length of the data to be written is 1024 bytes (less than the remaining writable length), the actual write length bLen = 1024 bytes this time.
[0036] Step 2 (Read and extract the existing data)
[0037] Read all 4KB data from sector 2 (address 8192 - 12287).
[0038] Extract the existing data in the area to be written: Since the address offset is 0, directly extract the first 1024 bytes of data.
[0039] Step 3 (Data comparison)
[0040] Compare the 1024 - byte new data to be written with the extracted existing data byte by byte. (1) Scenario 1: All the existing data is 0xFF, and there are operations in the new data that need to change some bits from 1 to 0. (2) Scenario 2: The existing data is exactly the same as the new data. (3) Scenario 3: Some of the existing data is not 0xFF, and the new data needs to modify these bits.
[0041] Steps 4 - 6 (Dynamic judgment and operation execution)
[0042] Scenario 1 (All existing data is 0xFF): Skip the erase operation (because the target area is already all 0xFF). Write the new data directly page by page (256 bytes / page). Only 4 pages (1024 bytes) need to be written. Before writing each page, judge whether it needs to be modified. For example, if the data of a certain page is the same as the original 0xFF data, skip writing that page.
[0043] Scenario 2 (Data consistent): Directly skip all erase and write operations and mark this storage as completed.
[0044] Scenario 3 (Data inconsistent and there are non-0xFF bits): Erase the entire sector2 (takes about 20 ms). Write the new data page by page to the erased sector. Since the sector is all 0xFF after erasure, all pages need to be written, a total of 4 pages.
[0045] Step 7 (Loop to process the remaining data)
[0046] If the length of the data to be written exceeds the remaining writable length (for example, the total length is 5000 bytes), then: (1) After writing 1024 bytes of the current sector, the remaining data length is 3976 bytes (5000 - 1024); (2) Update the write address to 0x2000 + 1024 = 0x2400, and repeat Steps 1 to 6 to process the next sector (sector number 3).
[0047] Effect verification
[0048] Through the above method, in Scenario 1, the erase operation (20 ms) and part of the page write time are saved; in Scenario 2, the erase and write operations are completely skipped; in Scenario 3, only necessary erasures and writes are performed. After actual measurement, compared with the traditional method, the storage efficiency of the present invention is increased by about 35% in the scenario of frequent small data volume writes, and the number of NORFLASH erasures is reduced by more than 60%, significantly extending the life of the storage medium.
[0049] In summary, a method for solving the slow NORFLASH storage of the present invention realizes a significant improvement in storage performance through dynamic judgment and optimization of the operation process. In specific implementation, this method can intelligently determine whether to perform erase and write operations according to the status of the data to be written, thus avoiding unnecessary redundant operations. In addition, this method also further reduces the write time and data write-back volume through paged writing and the strategy of only modifying different pages. Under the combined action of these improvement measures, the storage efficiency of NORFLASH is significantly improved, and at the same time, the physical loss of the storage medium is reduced, and its service life is extended. Therefore, the present invention has broad application prospects in the fields of embedded systems and the like.
[0050] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for solving the slow storage of NOR Flash, characterized in that, It includes the following steps: Step 1: Determine the corresponding sector number and the remaining writable length according to the address and length of the data to be written; Step 2: Read the current data of the sector from the NORFLASH and extract the existing data in the area to be written; Step 3: Compare the data to be written with the existing data; Step 4: If the existing data is exactly the same as the data to be written, skip the write operation; Step 5: If the existing data is all 0xFF, directly write the data to be written without performing an erase operation; Step 6: If the existing data is inconsistent with the data to be written and there are non-0xFF bits, erase the sector and then perform the write operation; Step 7: Repeat the above steps until all data is stored.
2. A method for solving the slow storage of NOR Flash according to claim 1, characterized in that, The calculation method of the sector number in Step 1 is: divide the address to be written by the number of bytes of a single sector, and take the integer part as the sector number.
3. A method for solving the slow storage of NOR Flash according to claim 1, characterized in that, The calculation method of the remaining writable length in Step 1 is: the number of bytes of a single sector minus the remainder of the address to be written divided by the number of bytes of a single sector.
4. A method for solving the slow storage of NOR Flash according to claim 1, characterized in that, The extraction range of the existing data in Step 2 includes the data segment from the sector start address offset corresponding to the address to be written to the remaining writable length.
5. A method for solving the slow storage of NOR Flash according to claim 1, characterized in that, If the length of the data to be written in Step 4 is 0, directly terminate the storage process.
6. A method for solving the slow storage of NOR Flash according to claim 1, characterized in that, If the existing data in Step 5 is all 0xFF, only write the pages in the data to be written that are different from the original data and skip the unmodified pages.
7. A method for solving the slow storage of NOR Flash according to claim 1, characterized in that, The trigger condition for the erase operation in Step 6 is: there is at least one bit in the data to be written that needs to change from 0 to 1.
8. A method for solving the slow storage of NOR Flash according to claim 1, characterized in that, The method is executed by a processor in an embedded system and is configured to continuously judge the data status to optimize the number of erase and write operations.