A system-on-chip file data management method and system for prolonging the service life of memory
Patent Information
- Application Number
- CN202311081558.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-25
- Publication Date
- 2026-09-22
- Estimated Expiration
- 2043-08-25
AI Technical Summary
现有技术中,还有使用缓存以减少擦写操作次数等方法,但仅对于片上系统单次使用过程有效,受掉电的影响也非常大
1.本发明技术方案通过使用备用空间,将片上系统原本的每次文件数据修改都必须对原文件数据相应存储块进行一次擦除写入操作,转化为多次文件数据修改才需要对文件数据相应存储块进行一次擦除写入操作,而备用空间也只需一次擦除与多次写入,有效地降低了存储块的擦除次数,延长了存储块的使用寿命。
Smart Images

Figure CN117130552B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of data storage management and chip design, specifically relating to an on-chip system file data management method and system for extending the lifespan of memory. Background Technology
[0002] The ISO / IEC 7816 standard for smart cards defines four basic file structures for the basic working file of a smart card. These, as seen from the interface, include: a transparent file structure with a sequence of data units, a fixed-length record file structure with fixed-length records, a variable-length record file structure with variable-length records, and a circular file structure with fixed-length records. Modifications to the latter three types of record files are performed on a record-by-record basis, exhibiting locality of reference. For transparent files, the most common modification method is to start at a specific offset address and modify the area stored in the original file, also exhibiting locality of reference. Therefore, there are numerous instances of locality of reference in smart card file write operations.
[0003] Smart cards typically use Flash memory for storing file data. Before writing data, Flash memory must erase relevant areas. The number of erase cycles is a crucial indicator of memory lifespan. Once the erase cycle reaches its nominal limit, the stored data may become unpredictable, leading to errors and ending the smart card's lifespan. Flash memory erases data in blocks; even modifying a single byte requires erasing the corresponding data block before writing the entire block. Due to the locality of data storage in file systems, there are frequent instances of multiple local modifications to a single data block, such as modifying passwords or keys after incorrect authentication attempts, or overwriting records. Each modification necessitates erasing and writing to the corresponding storage block, thus reducing the memory's lifespan. Minimizing the number of erase / write cycles and extending the smart card's lifespan will yield significant social and economic benefits.
[0004] To extend the lifespan of on-chip system memory, wear leveling algorithms are often used to distribute erase and write operations evenly across the entire storage medium. However, their effectiveness is limited when dealing with numerous localized modifications. Existing technologies also employ caching to reduce the number of erase and write operations, but these are only effective for a single use of the on-chip system and are highly susceptible to power outages.
[0005] Therefore, how to reduce the number of erase / write cycles of on-chip system memory blocks to address numerous local modifications to file data, thereby extending the lifespan of the memory, has become an urgent problem to be solved. Summary of the Invention
[0006] The purpose of this invention is to address the need to reduce the number of erase / write cycles of memory blocks due to numerous local modifications to on-chip system file data, and to provide an on-chip system file data management method and system that extends the lifespan of the memory.
[0007] This invention divides the storage space allocated for files into a file space and a spare space. When file data needs to be modified, the relevant control information and data for each modification are written to the spare space, while the original file space remains unchanged. Only when the spare space is insufficient is the corresponding storage block in the file space erased, the modified file data written, and the spare space erased for future modifications. When reading file data, the data stored in the corresponding storage block in the file space is read first, and then the final read data is constructed using data within a specified read range from the spare space, or a specified record stored in the spare space is read directly. This invention has substantial features and advancements compared to existing technologies, specifically: 1. The technical solution of the present invention uses spare space to transform the original on-chip system, which required an erase and write operation on the corresponding storage block of the original file data for each file data modification, into a system that only needs to perform an erase and write operation on the corresponding storage block of the file data after multiple file data modifications. The spare space only needs to perform one erase and multiple write operations, which effectively reduces the number of erase operations on the storage block and extends the service life of the storage block.
[0008] 2. Due to the stability of the spare space, the technical solution of the present invention is not limited to being effective only in a single use. Even when the file data is modified by repeatedly turning the computer on and off, it can still effectively reduce the number of times the storage block is erased.
[0009] 3. The technical solution of the present invention writes the relevant control information and data directly to the spare space each time the data is modified, so the integrity of the file data will not be affected in the event of a sudden power failure, and it has a power failure protection function, which effectively improves the efficiency of the storage management system. Attached Figure Description
[0010] Figure 1 This is a schematic diagram of an on-chip system file data management method for extending the lifespan of a memory according to an embodiment of the present invention.
[0011] Figure 2 This is a diagram illustrating the file space and spare space allocated to a file when it is created. Detailed Implementation
[0012] TLV format is an encoding format in which data consists of three fields: tag, length, and value. The TLV triple is called Type-length-value. The lengths of the tag and length fields are usually fixed, typically 1 to 4 bytes, while the length of the value field is variable.
[0013] Example 1: This embodiment provides an on-chip system file data management method to extend the lifespan of memory, such as... Figure 1 As shown, the method includes: When a file is created, the storage space allocated to the file includes a file space and a spare space. The spare space includes at least one storage block for storing TLV format file write information, which includes the target write location and the write data. The storage block identifiers of the file space and the spare space of the file are recorded in the file control information. When you need to write data to a file, follow these steps: S101. Determine whether the data to be written exceeds the file space. If it does, stop the writing operation and proceed to step S106. S102. Determine whether the target write position in the file space is in a pending state. If so, write the pending data directly to the target write area and execute step S106. S103. Based on the access control parameters and data provided by the write command, construct TLV format file write information, determine whether the write space of the spare space is sufficient to accommodate the file write information, and if it is sufficient, write the file write information to the write space of the spare space and execute step S106. S104. Read all the data in the file space into the buffer storage area, and then copy the write data in the file write information stored in the spare space to the corresponding buffer storage area according to its target write position. Then, use the data to be written this time to make the final modification of the buffer storage area to form the final file data of this write operation. S105. Erase the corresponding storage block in the file space based on the modified storage block in the buffer storage area, and write the modified data in the buffer storage area to the corresponding file space storage block. The unmodified file storage block remains unchanged, and then erase the spare space. S106. End the write operation and return; When deleting part of the file data, first check if the deleted part of the file data exceeds the file space. If so, stop the deletion operation; otherwise, write the deletion identifier, deletion length and the starting address of the deleted data in TLV format to the write space of the spare space. When reading file data, first determine whether the file data to be read exceeds the file space. If so, stop the reading operation; otherwise, if the spare space stores data within the specified reading range, replace the corresponding data in the file space with the data within the specified reading range in the spare space to construct the final data output of the specified file space. Otherwise, directly read the corresponding data from the file space.
[0014] Figure 2 The diagram below illustrates the file space and spare space allocated to a file during file creation. The spare space includes at least one storage block. A larger spare space significantly reduces the number of write cycles to both the file space and the spare space, but this also leads to a decrease in data read speed. Therefore, the allocation of spare space should be based on the file size and modification history, ensuring an appropriate amount of space is allocated.
[0015] To ensure data integrity and security, the file data stored in the spare space can be formatted in TLV format with an additional CRC checksum. When using CRC, in step S103, based on the access control parameters and data provided by the write command, TLV format file data information needs to be constructed, and its CRC code calculated to obtain the information written to the spare space. In step S104, all data in the file space needs to be read into the buffer storage area. Then, the data stored in the spare space is sequentially checked for CRC errors, copied to the corresponding buffer storage area according to its position information in the file space, and the buffer storage area is finally modified using the data written this time, forming the final file data for this write operation. When reading file data, if the data stored in the spare space is within the specified read range, the specified file data is first read from the file space into the buffer storage area. Then, the spare storage information associated with the file space is sequentially read, and CRC checks are performed. The spare file data with correct CRC checks replaces the corresponding data in the buffer storage area, constructing the final data output for the specified file space.
[0016] It is important to note that in the file space and spare space, the state of being ready to be written refers to the state when the file has been erased but has not yet been written to. The area in the state of being ready to be written is called the space to be written.
[0017] In practical implementation, the basic working file structures for smart cards defined in the ISO / IEC 7816 standard include: a transparent file structure with a sequence of data units, a fixed-length record file structure with fixed-length records, a variable-length record file structure with variable-length records, and a circular file structure with fixed-length records. The control information related to data stored in the spare space and the methods for reading file data differ for each of these four structures.
[0018] Preferably, when the file is a transparent file structure of data unit sequences, in the file write data information stored in the spare space, T is the offset address of the write data in the file space, L is the write data length, and V is the write data. In this case, when reading file data, if the spare space stores data within a specified read range, the corresponding data in the file space is first read into the buffer storage area, then the corresponding data in the buffer storage area is modified using the data within the specified read range in the spare space, and then the corresponding data is read from the buffer storage area according to the file read command.
[0019] Preferably, when the file is a fixed-length record file structure with fixed-length records, in the file data information stored in the spare space, T is the record sequence number written to the file space, and V is the written record. In this case, when reading file data, if the spare space stores a record with the record sequence number specified in the command, the last record specified by that record sequence number in the spare space is directly read. In this case, L can be the fixed length of the record, or it can be omitted.
[0020] Preferably, when the file is a variable-length record file structure with variable-length records, in the file data information stored in the spare space, T is the record identifier of the written record in the file space, L is the length of the written record, and V is the written record. In this case, when reading file data, if the spare space stores a record with the identifier specified in the command, then the last record specified by that identifier in the spare space is directly read.
[0021] Preferably, when the file is a circular file structure with fixed-length records, in the file data information stored in the spare space, T is the circular record number of the written record in the file space, and V is the written record. In this case, when reading file data, if the spare space stores a record with the circular record number specified in the command, the record specified by that circular record number in the spare space is read directly. In this case, L can be the fixed length of the record, or it can be omitted.
[0022] Example 2: This embodiment provides an on-chip system file data management system to extend the lifespan of memory. The system includes a file creation module, a file writing module, a file deletion module, and a file reading module; wherein... The file creation module is used to allocate storage space for a file when creating a file, including file space and spare space. The spare space includes at least one storage block for storing TLV format file write information, which includes the target write location and write data. The file control information records the storage block identifiers of the file space and spare space of the file respectively. The file writing module, when needing to write file data, first determines whether the data to be written exceeds the file space; if so, it terminates the write operation and returns. Then, it checks if the target write position in the file space is in a write-ready state; if so, it directly writes the data to be written to the target write area, terminates the write operation, and returns. Next, based on the access control parameters and data provided by the write command, it constructs TLV format file write information and determines whether the spare space is sufficient to accommodate the file write information. If sufficient, it writes the file write information to the spare space, terminates the write operation, and returns. Otherwise, it reads all data in the file space into the buffer storage area, then sequentially copies the write data from the file write information stored in the spare space to the corresponding buffer storage area according to its target write position, and uses the data to be written to the buffer storage area for final modification, forming the final file data for this write operation. Based on the modified storage blocks in the buffer storage area, it erases the corresponding storage blocks in the file space and writes the modified data from the buffer storage area to the corresponding file space storage blocks. Unmodified file storage blocks remain unchanged. Finally, it erases the spare space, terminates the write operation, and returns. The file deletion module is used to determine whether the deleted part of the file data exceeds the file space when deleting part of the file data. If so, the deletion operation is stopped; otherwise, the deletion identifier, deletion length and the starting address of the deleted data are written in TLV format to the write space of the spare space. The file reading module is used to determine whether the file data to be read exceeds the file space when reading file data. If so, the reading operation is stopped; otherwise, if the spare space stores data within the specified reading range, the corresponding data in the file space is replaced with the data within the specified reading range in the spare space to construct the final data output of the specified file space; otherwise, the corresponding data is read directly from the file space.
[0023] When reading file data, for transparent file structures where the file structure is a sequence of data units, if the spare space stores data within the specified read range, the data within the specified range in the file space is read first, and then the data within the specified read range in the spare space is read to replace the corresponding data in the file space, constructing the final data output for the specified file space. Otherwise, the corresponding data is read directly from the file space. For other file structures, if the spare space contains data for the specified read record, the data of the last specified record is read directly and output; otherwise, the data is read from the file space and output.
[0024] The above content is only for illustrating the technical concept of the present invention and should not be construed as limiting the scope of protection of the present invention. Any modifications made to the technical solution based on the technical concept proposed in this invention shall fall within the scope of protection of the claims of this invention.
Claims
1. A method for managing file data on a system-on-chip to extend the lifespan of a memory, characterized in that, include: When a file is created, the storage space allocated to the file includes file space and spare space, wherein the spare space includes at least one storage block for storing file write information in TLV format, the file write information including the target write location and the write data; The file control information records the storage block identifiers of the file space and the spare space of the file, respectively; When you need to write data to a file, follow these steps: S101. Determine whether the data to be written exceeds the file space. If it does, stop the writing operation and proceed to step S106. S102. Determine whether the target write position in the file space is in a pending state. If so, write the pending data directly to the target write area and execute step S106. S103. Based on the access control parameters and data provided by the write command, construct TLV format file write information, determine whether the write space of the spare space is sufficient to accommodate the file write information, and if it is sufficient, write the file write information to the write space of the spare space and execute step S106. S104. Read all the data in the file space into the buffer storage area, and then copy the write data in the file write information stored in the spare space to the corresponding buffer storage area according to its target write position. Then, use the data to be written this time to make the final modification of the buffer storage area to form the final file data of this write operation. S105. Erase the corresponding storage block in the file space based on the modified storage block in the buffer storage area, and write the modified data in the buffer storage area to the corresponding file space storage block. The unmodified file storage block remains unchanged, and then erase the spare space. S106. End the write operation and return; When deleting part of the file data, first check if the deleted part of the file data exceeds the file space. If so, stop the deletion operation; otherwise, write the deletion identifier, deletion length and the starting address of the deleted data into the spare space to be written. When reading file data, first check if the file data to be read exceeds the file space; if so, stop the read operation. Otherwise, if the spare space contains data within the specified read range, the corresponding data in the file space is replaced with the data within the specified read range from the spare space to construct the final data output of the specified file space; otherwise, the corresponding data is read directly from the file space.
2. The on-chip system file data management method for extending the lifespan of memory according to claim 1, characterized in that: The file is a transparent file structure that is a sequence of data units. The target write location of the file write information includes the starting address of the write data in the file space and the length of the write data. The write data of the file write information is the data to be written.
3. The on-chip system file data management method for extending the lifespan of memory according to claim 2, characterized in that: When reading file data, if the spare space contains data within the specified read range, the corresponding data in the file space is first read into the buffer storage area. Then, the corresponding data in the buffer storage area is modified using the data within the specified read range in the spare space. Finally, the corresponding data is read from the buffer storage area according to the file read command.
4. The on-chip system file data management method for extending the lifespan of memory according to claim 1, characterized in that: The file is a fixed-length record file structure with fixed-length records. The target write location of the file write information includes the record sequence number of the record to be written in the file space. The write data of the file write information is the record to be written.
5. The on-chip system file data management method for extending the lifespan of memory according to claim 4, characterized in that: When reading file data, if the spare space contains a record with the specified record number in the command, then the last record specified by that record number in the spare space is read directly.
6. The on-chip system file data management method for extending the lifespan of memory according to claim 1, characterized in that: The file is a variable-length record file structure with variable-length records. The target write location of the file write information includes the record identifier of the write record in the file space and the length of the write record. The write data of the file write information is the record to be written.
7. The on-chip system file data management method for extending the lifespan of memory according to claim 6, characterized in that: When reading file data, if the spare space contains a record with the identifier specified in the command, then the last record specified by that identifier in the spare space is read directly.
8. The on-chip system file data management method for extending the lifespan of memory according to claim 1, characterized in that: The file is a circular file structure with a fixed-length record. The target write position of the file write information includes the circular record number of the record to be written in the file space. The write data of the file write information is the record to be written.
9. The on-chip system file data management method for extending the lifespan of memory according to claim 8, characterized in that: When reading file data, if the spare space contains a record with the cycle number specified in the command, then the record specified by that cycle number in the spare space is read directly.
10. An on-chip system file data management system for extending the lifespan of memory, characterized in that, include: The module includes a file creation module, a file writing module, a file deletion module, and a file reading module; among them, The file creation module is used to allocate storage space for a file when creating a file, including file space and spare space. The spare space includes at least one storage block for storing TLV format file write information, which includes the target write location and write data. The file control information records the storage block identifiers of the file space and spare space of the file respectively. The file writing module, when needing to write file data, first determines whether the data to be written exceeds the file space; if so, it terminates the write operation and returns. Then, it checks if the target write position in the file space is in a write-ready state; if so, it directly writes the data to be written to the target write area, terminates the write operation, and returns. Next, based on the access control parameters and data provided by the write command, it constructs TLV format file write information and determines whether the spare space is sufficient to accommodate the file write information. If sufficient, it writes the file write information to the spare space, terminates the write operation, and returns. Otherwise, it reads all data in the file space into the buffer storage area, then sequentially copies the write data from the file write information stored in the spare space to the corresponding buffer storage area according to its target write position, and uses the data to be written to the buffer storage area for final modification, forming the final file data for this write operation. Based on the modified storage blocks in the buffer storage area, it erases the corresponding storage blocks in the file space and writes the modified data from the buffer storage area to the corresponding file space storage blocks. Unmodified file storage blocks remain unchanged. Finally, it erases the spare space, terminates the write operation, and returns. The file deletion module is used to determine whether the deleted part of the file data exceeds the file space when deleting part of the file data. If so, the deletion operation is stopped; otherwise, the deletion identifier, deletion length and the starting address of the deleted data are written to the write space of the spare space. The file reading module is used to determine whether the file data to be read exceeds the file space when reading file data. If so, the reading operation is stopped; otherwise, if the spare space stores data within the specified reading range, the corresponding data in the file space is replaced with the data within the specified reading range in the spare space to construct the final data output of the specified file space; otherwise, the corresponding data is read directly from the file space.
Citation Information
Patent Citations
Data storage structure of Flash memory and data manipulation mode thereof
CN102081577A
Recovery key for unlocking data storage device
CN113383511A