System-on-chip power down protection method and system
By using a power-loss protection log table and a file log page management table in the on-chip system, the efficient and low-cost implementation of power-loss protection in complex systems is solved, ensuring data integrity and rapid recovery, and improving system reliability.
Patent Information
- Application Number
- CN202310041373.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-12
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2043-01-12
AI Technical Summary
In complex on-chip systems, existing technologies struggle to achieve efficient and low-cost data protection in file data storage and management systems, particularly in the face of data loss and incomplete recovery issues during sudden power outages.
A power failure protection log table is used to record the identifier, power failure protection type, and status of the target file. Combined with the file record page and data storage area management table, the power failure protection status is recorded and restored during file creation, writing, and deletion operations to ensure data integrity.
It enables fast and reliable power-loss protection without increasing cache space, improves data storage utilization and data operation speed, and ensures that the system can recover to the correct state when power is restored.
Smart Images

Figure CN116126594B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of embedded systems, specifically relating to a power-down protection method and system for a system-on-a-chip. Background Technology
[0002] If an on-chip system experiences a sudden power outage during normal operation, it may lose important data and damage the system. Therefore, a power-loss protection function needs to be incorporated into the system design to ensure the determinism of the system's operating status and the integrity of recorded data in the event of an unexpected power failure. Once power is restored, the field control parameters and data from the time of the power outage can be promptly recovered, ensuring the stable and reliable operation of the application system.
[0003] Besides employing uninterruptible power supplies, backup power supplies, and spare registers for power-down protection, simpler on-chip systems, where the amount of data to be protected each time is small, can directly protect the storage units and thus utilize interrupt services for power-down protection. However, more complex on-chip systems typically access data via file read / write operations, and the data volume is generally larger, making interrupt-based power-down protection unreliable. Only by integrating power-down protection with file data storage and management, and designing accordingly, can the implementation of power-down protection functionality be more effective.
[0004] Therefore, how to design a power-loss protection function on the basis of a file data storage and management system, and how to implement the power-loss protection function conveniently, quickly and cost-effectively, has become an urgent problem to be solved. Summary of the Invention
[0005] The purpose of this invention is to provide a power-loss protection method and system for on-chip systems to address the needs of on-chip system file data writing and system management power-loss protection.
[0006] This invention uses a power-loss protection log table to record the target file's identifier, power-loss protection type, and status. It uses file record pages to store the target file's control information, as well as the space information allocated for file data storage during file creation and each data write operation. When executing commands to create a file, write file data, or delete a file, the power-loss protection log table records the target file's identifier and power-loss protection type, initiating the system's power-loss protection. After completing the relevant file data and system management operations in the command, the power-loss protection for that command ends. If a sudden power outage occurs during the execution of the command, the system can determine the command's execution status at the time of the power outage based on the records in the power-loss protection log table and file record pages when power is restored, and then execute the power-loss protection recovery process. Specifically: 1. The technical solution of this invention can conveniently and quickly implement the power-loss protection function without setting any power-loss protection data buffer storage space, overcoming the problems of rapid wear and short service life of power-loss protection data buffers, and improving the utilization rate of on-chip system data storage.
[0007] 2. The technical solution of this invention closely integrates power failure protection with file data storage management system. During the power failure protection process, only one erase and write operation is required on the relevant storage block to complete the file creation, deletion and data writing functions, thereby improving the speed of file creation, deletion and data writing. Attached Figure Description
[0008] Figure 1 This is a schematic diagram of a power-down protection system for a system-on-a-chip according to an embodiment of the present invention. Detailed Implementation
[0009] Example 1: This embodiment provides a power-down protection method for a system-on-a-chip. The method includes: constructing a power-down protection record table to record the identifier, power-down protection type, and power-down protection status of a target file; creating a file record page area, where each file record page corresponds to a file and is used to store file control information and file data storage space information; constructing a file record page management table to control the cyclic allocation and erasure / reclaiming of file record pages; and constructing a data storage area management table to control the cyclic allocation and erasure / reclaiming of data storage blocks in the data storage area. When a file is created, file record pages and file data storage space are allocated for the file, and file control information and file data storage space information are recorded in the file record pages of the file; each time file data is written, the modified data storage blocks of the file are erased and reclaimed, new data storage blocks are allocated for the file to store the modified data, and the file data storage space information is reconstructed and recorded in the file record pages of the file; when a file is deleted, the file record pages and data storage blocks occupied by the file are erased and reclaimed. When executing commands to create a file, write file data, or delete a file, before releasing and erasing file record pages and data storage blocks, the power-loss protection log table records the target file's identifier and power-loss protection type, sets the power-loss protection status to "activated," and initiates the system's power-loss protection. After completing the release and erasure of the corresponding file record pages and data storage blocks in the command, the power-loss protection status of the target file in the power-loss protection log table is set to "completed," completing the power-loss protection for the command and ending the execution of the command. Entries in the power-loss protection log table with a power-loss protection status equal to "activated" are valid records. When the system is powered on again, the valid records in the power failure protection record table are queried, and the power failure protection recovery process is executed. Based on the power failure protection type and the valid file records in the file record page corresponding to the target file, the execution status of the command before the power failure is determined, and the remaining functions of the command are executed or the system state before the command execution is restored according to the execution status. After completion, the power failure protection status is changed to the completed status. The valid file record is the last file record that contains the file data storage space information.
[0010] Preferably, the construction of the power failure protection record table is used to record the identifier of the target file, the power failure protection type, and the power failure protection status, specifically including: A power failure protection log table is constructed, with each entry corresponding to a command to create a file, write file data, or delete a file. This log table records the target file's identifier, power failure protection type, and power failure protection status. Power failure protection types include power failure protection for file creation, file deletion, and file data writing. The log table is contiguous. A power failure protection pointer is set to point to the currently available entry. When a command to create a file, write file data, or delete a file is executed, the target file's identifier and power failure protection type are written to the currently available entry, and the power failure protection status is set to "activated." Before the command completes normally and returns to the system, the power failure protection status is set to "completed," and the power failure protection pointer is moved down one entry. The aforementioned construction of a file record page management table, used to control the cyclic allocation and erasure / recycling of file record pages, specifically includes: A file record page management table is constructed, where each entry records the identifier of a file record page and its usage status. The file record page management table is contiguous. A head pointer and a tail pointer are set, with the head pointer pointing to the currently available entry and the tail pointer pointing to the farthest available entry. When a new file record page is needed, the identifier of the file record page in the currently available entry is obtained, the corresponding file record page is used to record file control information and file data storage space information, a used flag is written to the currently available entry, and the head pointer is moved down one entry. When a file record page is erased or recycled, the identifier of the erased or recycled file record page is written to the next entry of the farthest available entry in the file record page management table, and the tail pointer is moved down one entry. The aforementioned data storage area management table, used to control the cyclic allocation and erasure / reclaim of data storage blocks in the data storage area, specifically includes: A data storage area management table is constructed, with each entry recording the identifier of a data storage block and its usage status. The data storage area management table is contiguous, with a head pointer and a tail pointer. The head pointer points to the currently available entry, and the tail pointer points to the remotely available entry. When a new data storage block is needed, the identifier of the data storage block in the currently available entry is retrieved, the corresponding data storage block is used to store file data, a "used" flag is written to the currently available entry, and the head pointer is moved down one entry. When data storage blocks are erased or reclaimed, the identifier of each erased or reclaimed data storage block is written to the next entry in the remotely available entry of the data storage area management table, and the tail pointer is moved down one entry.
[0011] Preferably, during initialization, the power failure protection pointer of the power failure protection record table points to the first address of the table, and the power failure protection record table area is erased to put it into a state waiting for data to be written. Erase the file record page area and data storage area to put them in a state waiting for data to be written; sequentially write the identifier of each available file record page into the corresponding entry in the file record page management table; in the file record page management table, among the entries that record the identifiers of available file record pages, make the first entry the currently available entry and the last entry the remote available entry; set the head pointer of the file record page management table to the currently available entry and the tail pointer to the remote available entry; and add one or more empty entries after the remote available entry. Write the identifier of each available data storage block into the corresponding entry in the data storage area management table in sequence; in the entries of the data storage area management table that record the identifier of available data storage blocks, make the first entry its current available entry and the last entry its remote available entry, set the head pointer of the data storage area management table to the current available entry and the tail pointer to the remote available entry, and add one or more empty entries after the remote available entry.
[0012] Preferably, when creating a file, the file identifier and file size are obtained, and the file record page area and data storage area management table are searched to check whether the file creation conditions are met; if the file creation conditions are not met, the file creation fails and the file creation process is exited. Write the file identifier and power-loss protection type into the currently available entry of the power-loss protection log table, where the power-loss protection type is "Create File Power-loss Protection" and the power-loss protection status is set to "Started". Write a "Used" flag into the currently available entry of the file record page management table. Based on the file record page identifier recorded in the entry, write the file identifier and file control information into the corresponding file record page, and move the head pointer of the file record page management table down one item. In the data storage area management table, search downwards from its currently available entry to obtain entries for N available data storage blocks that match the file size space. Write the identifiers of the N available data storage blocks into the corresponding file record entries of the file record pages. Write the "Used" flag into each of the N entries in sequence, and move the head pointer of the data storage area management table down N items, where N is a positive integer. Write a "Completed" flag into the corresponding file record entries of the file record pages. In the valid record entries of the power-loss protection log table, change the power-loss protection status to "Completed" and move the power-loss protection pointer of the power-loss protection log table down one item.
[0013] The valid entries in the power failure protection log table mentioned here refer to the entries in the power failure protection log table that have been written with the file identifier and power failure protection type and whose power failure protection status is set to the enabled state.
[0014] In this embodiment, when creating a file, checking whether the file creation conditions are met includes: searching for the existence of a file identifier in the file record page area; if it exists, the file creation conditions are not met; and checking whether there is storage space that meets the file size in the data storage area management table; if the storage space is insufficient, the file creation conditions are not met; otherwise, the file creation conditions are met.
[0015] Preferably, when the system is powered on again, the valid records in the power failure protection record table are queried. If the power failure protection type is file creation power failure protection, the following steps are performed: S101. Search for the target file identifier in the file record page area; if the target file identifier does not exist, proceed to step S106. S102. Check whether the control information of the file in the file record page corresponding to the target file is complete; if it is incomplete, the target file creation fails, the file record page is erased and recycled, and step S106 is executed. S103. Check whether the number of data storage block identifiers in the first file record entry of the file record page is consistent with the amount of storage space occupied by the file; if they are inconsistent, calculate the number of data storage block identifiers X that have been written and the number of data storage block identifiers N that still need to be written. In the data storage area management table, start from the currently available table entry and search downwards to obtain the table entries of X+N available data storage blocks that match the file size space. Write the identifiers of the N available data storage blocks into the file record entry. Write the used flags into the X+N table entries in sequence, and move the head pointer of the data storage area management table down by X+N entries; where N is a positive integer, X is an integer and X≥0; S104. Based on the data storage block identifier in the first file record item in the file record page and the head pointer of the data storage area management table, determine whether the data storage block allocated to the file has been released. If it has not been released, release the corresponding data storage block and adjust the head pointer of the data storage area management table accordingly. S105. Write a completion flag into the first file record item of the file record page; file creation is complete. S106. In the valid record entries of the power failure protection record table, change the power failure protection status from the start state to the completed state, and end the file creation power failure protection recovery process.
[0016] Preferably, when writing file data, the file identifier is obtained, and the file record page area is searched to check if the file identifier exists. If it does not exist, the writing of file data fails and the writing process is exited. The file length information is read to determine whether the length of the written file data exceeds the storage boundary of the file data. If it exceeds the storage boundary of the file data, the writing of file data fails and the writing process is exited. Otherwise, initiate a file data write operation. Write the file identifier and power-loss protection type (file data write power-loss protection) to the currently available entry in the power-loss protection record table, setting the power-loss protection status to "activated." Calculate the number of data storage blocks M to be modified based on the length of the file data to be written. In the data storage area management table, starting from the currently available entry, retrieve M entries, write a "used" flag to each entry, and move the head pointer of the data storage area management table down by M entries. Based on the data storage block identifiers in the M entries, write file data to the corresponding M data storage blocks, erase and reclaim the M data storage blocks whose data was replaced. Create a new file record entry in the file record page where the file identifier is located, writing the space information of the relocated file data storage; where M is a positive integer. If there is not enough space in the file record page where the file identifier is located to store the new file record entry, then write a used flag into the currently available entry of the file record page management table. Based on the file record page identifier recorded in the table, copy the file identifier and file control information from the original file record page into the corresponding file record page, create a new file record entry, and write the file data storage space information constructed after reallocation; erase and reclaim the original file record page. Write a completion flag into the new valid file record; in the valid record of the power failure protection record table, change the power failure protection status to the completed status, and move the power failure protection pointer of the power failure protection record table down one item.
[0017] The new valid file record here refers to the file record that was newly created this time and has been written with the space information of the file data constructed after the reallocation.
[0018] Preferably, when the system is powered on again, the valid records in the power failure protection record table are queried. If the power failure protection type is write file data power failure protection, the target file identifier is searched in the file record page area. If the target file identifier is unique and exists, then perform the following steps: S201. Check if the valid file record entries in the file record page corresponding to the target file are complete; if complete, proceed to step S205. S202. Check whether the number of data storage block identifiers in the valid file record entries in the file record page is consistent with the amount of storage space occupied by the file; if consistent, compare the valid file record entries in the file record page with the previous file record entry, construct an array of data storage block identifiers that need to be released and those that need to be erased and reclaimed, release and erase and reclaim the corresponding data storage blocks in sequence accordingly, and write a completion flag in the valid file record entry to complete the file data writing, and execute step S205; S203. Locate the data storage block of the file. Find the data storage block whose identifier is inconsistent with the data storage block of the previous file record in the valid file record in the file record page. Erase and reclaim the data storage block and write a completion flag in the valid file record. Determine whether the file record page meets the requirements for storing a file data storage space information. If it does, copy the information of the previous file record in the valid file record and write it to the next available file record. Execute step S205. S204. Write a used flag into the currently available entry of the file record page management table. Based on the file record page identifier recorded in the entry, copy the file identifier and file control information from the original file record page into the corresponding file record page. Create a new file record entry and write the information of the previous file record entry of the valid file record entry in the original file record page. Erase and reclaim the original file record page. S205. Change the power failure protection status of the valid record in the power failure protection log table from the start state to the completed state, and end the file data writing power failure protection recovery process. If the identifier of the target file is not unique, then perform the following steps: S301. Determine whether two file record pages are new file record pages or original file record pages; S302. Check if the number of data storage block identifiers of valid file record entries in the new file record page is consistent with the amount of storage space occupied by the file; if not, proceed to S304. S303. Compare the last file record item in the original file record page with the valid file record item in the new file record page, construct an array of data storage block identifiers that need to be released and those that need to be erased and recycled, release and erase the corresponding data storage blocks in turn, and write a completion flag in the valid file record item of the new file record page to complete the file data writing, erase and recycle the original file record page, and execute step S305. S304. Locate the data storage block of the file, find the data storage block identifier that is inconsistent with the data storage block identifier recorded in the last file record entry of the original file record page, erase and reclaim it, and write a completion flag into the valid file record entry of the new file record page; copy the content of the last file record entry of the original file record page and write it into the next available file record entry in the new file record page, and erase and reclaim the original file record page. S305. Change the power failure protection status of the valid record in the power failure protection log table from the start state to the completed state, and end the file data writing power failure protection recovery process.
[0019] Preferably, when deleting a file, the file identifier is obtained, and the file record page area is searched to check if the file identifier exists. If it does not exist, the file deletion fails and the file deletion process is exited. Write the file identifier and power failure protection type into the currently available entries of the power failure protection log table, where the power failure protection type is "delete file power failure protection" and set the power failure protection status to "activated". Initiate the file deletion operation, and based on the data storage block identifier recorded in the valid file record entries of the file record page where the file identifier is located, erase and reclaim the corresponding data storage blocks in sequence; erase and reclaim the file record page where the file identifier is located; in the valid record entries of the power failure protection log table, change the power failure protection status from "activated" to "completed" and move the power failure protection pointer of the power failure protection log table down one item.
[0020] Preferably, when the system is powered on again, the valid records in the power failure protection log table are queried. If the power failure protection type is file deletion power failure protection, the following steps are performed: S401. Search for the target file identifier in the file record page area; if the target file identifier does not exist, proceed to step S405. S402. Based on the data storage block identifier of the valid file record entry in the file record page corresponding to the target file, and the data storage block identifier indicated by the tail pointer of the data storage area management table, determine whether the data storage block occupied by the file has been erased and reclaimed. If not, continue to erase and reclaim the data storage block. S404. Determine whether the file record page has been erased and recycled. If it has not been erased and recycled, erase and recycle the file record page. S405. File deletion complete. Change the power failure protection status of the valid record in the power failure protection log table from the started state to the completed state, and end the file deletion power failure protection recovery process.
[0021] Example 2: This embodiment provides a power-loss protection system for an on-chip system, such as... Figure 1 As shown, it includes a power failure protection log table, a file record page area, a file record page management table, and a data storage area management table. The power failure protection log table records the target file's identifier, power failure protection status, and power failure protection type. The file record page area includes multiple file record pages, each corresponding to a file, used to record file control information and file data storage space information. The file record page management table controls the cyclic allocation and erasure / reclaiming of file record pages. The data storage area management table controls the cyclic allocation and erasure / reclaiming of data storage blocks in the data storage area.
[0022] When a file is created, file record pages and file data storage space are allocated for the file, and file control information and file data storage space information are recorded in the file record pages of the file. Each time file data is written, the modified data storage blocks of the file are erased and reclaimed, and new data storage blocks are allocated for the file to store the modified file data. The file data storage space information is reconstructed and recorded in the file record pages of the file. When a file is deleted, the file record pages and data storage blocks occupied by the file are erased and reclaimed.
[0023] When executing commands to create a file, write file data, or delete a file, before releasing and erasing file record pages and data storage blocks, the power-loss protection log table records the target file's identifier and power-loss protection type, sets the power-loss protection status to "activated," and activates the system's power-loss protection. After completing the release and erasure of the corresponding file record pages and data storage blocks in the command, the power-loss protection status of the target file in the power-loss protection log table is rewritten to "completed," completing the power-loss protection for the command and ending the execution of the command. If a power outage occurs suddenly during the execution of the command, entries in the power-loss protection log table with a power-loss protection status equal to "activated" are valid records. When the system is powered on again, the valid records in the power failure protection record table are queried, and the power failure protection recovery process is executed. Based on the power failure protection type and the valid file records in the file record page corresponding to the target file, the execution status of the command before the power failure is determined, and the remaining functions of the command are executed or the system status before the command execution is restored according to the execution status of the command. After completion, the power failure protection status is changed to the completed status.
[0024] Preferably, each entry in the power failure protection log table corresponds to one execution of a command to create a file, write file data, or delete a file. It records the target file's identifier, power failure protection type, and power failure protection status. The power failure protection types include power failure protection for creating a file, power failure protection for deleting a file, and power failure protection for writing file data. The power failure protection log table is contiguous. A power failure protection pointer is set to point to the currently available entry. When a command to create a file, write file data, or delete a file is executed, the target file's identifier and power failure protection type are written to the currently available entry. The power failure protection status is set to "activated." Before the command completes normally and returns to the system, the power failure protection status is changed to "completed," and the power failure protection pointer is moved down one entry. Each entry in the file record page management table records the identifier of a file record page and its usage status. The file record page management table is contiguous. A head pointer and a tail pointer are set, with the head pointer pointing to the currently available entry and the tail pointer pointing to the farthest available entry. When a new file record page is needed, the identifier of the file record page in the currently available entry is retrieved, the corresponding file record page is used to record file control information and file data storage space information, a used flag is written to the currently available entry, and the head pointer is moved down one entry. When a file record page is erased and reclaimed, the identifier of the erased and reclaimed file record page is written to the next entry in the file record page management table after the farthest available entry, and the tail pointer is moved down one entry. Each entry in the data storage area management table records the identifier of a data storage block and its usage status. The data storage area management table is contiguous, with a head pointer and a tail pointer. The head pointer points to the currently available entry, and the tail pointer points to the remotely available entry. When a new data storage block is needed, the identifier of the data storage block in the currently available entry is retrieved, the corresponding data storage block is used to store the file data, a "used" flag is written to the currently available entry, and the head pointer is moved down one entry. When a data storage block is erased and reclaimed, the identifier of each erased and reclaimed data storage block is written to the next entry in the remotely available entry of the data storage area management table, and the tail pointer is moved down one entry.
[0025] In this embodiment, the number of files that can be created = the number of file record pages - 1; each file dynamically occupies one file record page.
[0026] In the file record page management table, two words can be used to represent the usage status of a record page. The first word represents the identifier (or logical address) of the file record page, and the second word represents the usage status of the file record page. The initialization status of the second word (such as all FF) indicates that the file record page is ready for use, while other data indicates that the file record page is already in use.
[0027] To manage the file record page management table, a head and tail pointer of the file record page management table structure is set. After initialization, the head pointer points to the first file record page to be released, and the tail pointer points to the last file record page to be released.
[0028] When a file record page is released, the file record page pointed to by the head pointer is released, that is, the used flag is written to the flag word pointed to by the head pointer, the head pointer is incremented by 1 to point to the next file record page to be released; when a file record page is reclaimed, the tail pointer is incremented by 1, the reclaimed file record page identifier is written to the first word pointed to by the tail pointer, and the file record page is erased.
[0029] The head and tail pointers of the file record page management table form a circular queue with a fixed space and a first-in-first-out (FIFO) operation. When the head and tail pointers are incremented by 1 to equal the maximum value of the queue, the queue is automatically adjusted to its minimum value. The length of the queue is set to be at least 1 greater than the number of file record pages.
[0030] When the remaining space of a file record page is insufficient to store the next record, a new file record page is created, and the file identifier and file control information written in the original file record page are copied. After the new file data storage space information record is rewritten, the original file record page is erased and recycled for later use.
[0031] When a user program modifies the data in a specified data storage block of a file, the corresponding data storage block is reclaimed and a new data storage block is allocated. Unmodified data storage blocks remain unchanged. The unmodified data storage blocks and the newly allocated data storage block identifiers together form a new file record entry to indicate the storage space of the file data.
[0032] The data storage area management table is used to manage the storage space of system file data. It can also manage a data storage block using two words: the first word is the logical address of the data storage block, and the second word is a status word indicating the usage status of the data storage block, enabling the release and reclamation of data storage blocks. A certain amount of storage space forms a first-in, first-out circular queue, and head and tail pointers are set for the currently available data storage area management table. Its management and organization are similar to those of the file record page management table.
[0033] Each entry in the power-down protection log table can also consist of two words; the first word records the power-down protection object and type, and the second word records the power-down protection status. For example, the power-down protection object and type can be defined as follows: the high 16 bits represent the ID number of the application directory where the file is located; the high two bits of the low 16 bits represent the power-down protection type: 00 is reserved, 01 indicates power-down protection for file creation, 10 indicates power-down protection for file deletion, and 11 indicates power-down protection for file data writing; the low 14 bits represent the file ID number. The second word, in the initialization state (e.g., all FF), indicates that the target object has entered the power-down protection state; other data indicates that the power-down protection is complete.
[0034] 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 power-down protection method for a system-on-a-chip, characterized in that, include: Construct a power failure protection log table to record the target file's identifier, power failure protection type, and power failure protection status; Create a file record page area, which includes multiple file record pages, each corresponding to a file, used to record file control information and file data storage space information; construct a file record page management table to control the cyclic allocation and erasure / reclaiming of file record pages; construct a data storage area management table to control the cyclic allocation and erasure / reclaiming of data storage blocks in the data storage area. When a file is created, file record pages and file data storage space are allocated for the file, and file control information and data storage space information are recorded in the file record pages of the file; each time file data is written, the modified data storage blocks of the file are erased and reclaimed, new data storage blocks are allocated for the file to store the modified data, and the file data storage space information is reconstructed and recorded in the file record pages of the file; when a file is deleted, the file record pages and data storage blocks occupied by the file are erased and reclaimed. When executing commands to create a file, write file data, or delete a file, before releasing and erasing file record pages and data storage blocks, the power-loss protection log table records the target file's identifier and power-loss protection type, sets the power-loss protection status to "activated," and activates the system's power-loss protection. After completing the release and erasure of the corresponding file record pages and data storage blocks in the command, the power-loss protection status of the target file in the power-loss protection log table is set to "completed," completing the power-loss protection for the command and ending the execution of the command. If a power failure occurs during the execution of the command, the entries in the power failure protection record table where the power failure protection status is equal to the start status are valid records. When the system is powered on again, the valid records in the power failure protection record table are queried, and the power failure protection recovery process is executed. Based on the power failure protection type and the valid file records in the file record page corresponding to the target file, the execution status of the command before the power failure is determined, and the remaining functions of the command are executed or the system state before the command execution is restored according to the execution status. After completion, the power failure protection status is changed to the completed status. The valid file record is the last file record that contains the file data storage space information.
2. The power-down protection method for a system-on-a-chip according to claim 1, characterized in that: The aforementioned construction of a power-loss protection record table is used to record the target file's identifier, power-loss protection type, and power-loss protection status, specifically including: A power failure protection record table is constructed, with each entry corresponding to a command to create a file, write file data, or delete a file. The record table is used to record the target file's identifier, power failure protection type, and power failure protection status. The power failure protection types include power failure protection for creating a file, power failure protection for deleting a file, and power failure protection for writing file data. The power failure protection record table is connected end to end. Set the power-down protection pointer to point to the currently available entry; when executing commands to create a file, write file data, or delete a file, write the target file identifier and power-down protection type to the currently available entry, set the power-down protection status to the enabled state, and write the power-down protection status to the completed state before returning to the system after the command is executed normally, and move the power-down protection pointer down one item. The aforementioned construction of a file record page management table, used to control the cyclic allocation and erasure / recycling of file record pages, specifically includes: A file record page management table is constructed, where each entry records the identifier of a file record page and its usage status. The file record page management table is contiguous. A head pointer and a tail pointer are set, with the head pointer pointing to the currently available entry and the tail pointer pointing to the farthest available entry. When a new file record page is needed, the identifier of the file record page in the currently available entry is obtained, the corresponding file record page is used to record file control information and file data storage space information, a used flag is written to the currently available entry, and the head pointer is moved down one entry. When a file record page is erased or recycled, the identifier of the erased or recycled file record page is written to the next entry of the farthest available entry in the file record page management table, and the tail pointer is moved down one entry. The aforementioned data storage area management table, used to control the cyclic allocation and erasure / reclaim of storage blocks in the data storage area, specifically includes: A data storage area management table is constructed, with each entry recording the identifier of a data storage block and its usage status. The data storage area management table is contiguous, with a head pointer and a tail pointer. The head pointer points to the currently available entry, and the tail pointer points to the remotely available entry. When a new data storage block is needed, the identifier of the data storage block in the currently available entry is retrieved, the corresponding data storage block is used to store file data, a "used" flag is written to the currently available entry, and the head pointer is moved down one entry. When data storage blocks are erased or reclaimed, the identifier of each erased or reclaimed data storage block is written to the next entry in the remotely available entry of the data storage area management table, and the tail pointer is moved down one entry.
3. The power-down protection method for a system-on-a-chip according to claim 2, characterized in that: During initialization, the power failure protection pointer of the power failure protection record table points to the first address of the table, and the power failure protection record table area is erased to put it into a state waiting for data to be written. Erase the file record page area and data storage area to put them in a state waiting for data to be written; sequentially write the identifier of each available file record page into the corresponding entry in the file record page management table; in the file record page management table, among the entries that record the identifiers of available file record pages, make the first entry the currently available entry and the last entry the remote available entry; set the head pointer of the file record page management table to the currently available entry and the tail pointer to the remote available entry; and add one or more empty entries after the remote available entry. Write the identifier of each available data storage block into the corresponding entry in the data storage area management table in sequence; in the entries of the data storage area management table that record the identifier of available data storage blocks, make the first entry its current available entry and the last entry its remote available entry, set the head pointer of the data storage area management table to the current available entry and the tail pointer to the remote available entry, and add one or more empty entries after the remote available entry.
4. The power-down protection method for a system-on-a-chip according to claim 2, characterized in that: When creating a file, obtain the file identifier and file size, and search the file record page area and data storage area management table to check whether the file creation conditions are met; If the conditions for file creation are not met, file creation will fail and the file creation process will be exited. Write the file identifier and power-loss protection type into the currently available entry of the power-loss protection log table, where the power-loss protection type is "Create File Power-loss Protection" and the power-loss protection status is set to "Active". Write a "Used" flag into the currently available entry of the file record page management table. Based on the file record page identifier recorded in the entry, write the file identifier and file control information into the corresponding file record page, and move the head pointer of the file record page management table down one item. In the data storage area management table, start searching downwards from its currently available entry to obtain entries for N available data storage blocks that match the file size space. Write the identifiers of the N available data storage blocks into the corresponding file record entries of the file record pages. Write the "Used" flag into each of the N entries in sequence, and move the head pointer of the data storage area management table down N items, where N is a positive integer. Write a completion flag in the corresponding file record entry on the file record page; In the valid entries of the power failure protection log, the power failure protection status is rewritten to "completed", and the power failure protection pointer in the power failure protection log is moved down one item.
5. The power-down protection method for a system-on-a-chip according to claim 2, characterized in that: When the system is powered on again, query the valid records in the power failure protection log table. If the power failure protection type is file creation power failure protection, then perform the following steps: S101. Search for the target file identifier in the file record page area; If the target file identifier does not exist, proceed to step S106; S102. Check whether the control information of the file in the file record page corresponding to the target file is complete; if it is incomplete, the target file creation fails, the file record page is erased and recycled, and step S106 is executed. S103. Check whether the number of data storage block identifiers in the first file record item in the file record page is consistent with the amount of storage space occupied by the file; If they are inconsistent, calculate the number of data storage block identifiers X that have been written and the number of data storage block identifiers N that still need to be written. In the data storage area management table, start from the currently available table entry and search downwards to obtain the table entries of X+N available data storage blocks that match the file size space. Write the identifiers of the N available data storage blocks into the file record entry. Write the used flag into the X+N table entries in sequence, and move the head pointer of the data storage area management table down by X+N entries; where N is a positive integer, X is an integer and X≥0; S104. Based on the data storage block identifier in the first file record item in the file record page and the head pointer of the data storage area management table, determine whether the data storage block allocated to the file has been released. If it has not been released, release the corresponding data storage block and adjust the head pointer of the data storage area management table accordingly. S105. Write a completion flag into the first file record item of the file record page; file creation is complete. S106. In the valid record entries of the power failure protection record table, change the power failure protection status from the start state to the completed state, and end the file creation power failure protection recovery process.
6. The power-down protection method for a system-on-a-chip according to claim 2, characterized in that: When writing file data, obtain the file identifier, search the file record page area to check if the file identifier exists. If it does not exist, the file data writing fails and the file data writing process exits. Read the file length information and determine whether the length of the data to be written to the file exceeds the storage boundary of the file data. If it exceeds the storage boundary of the file data, the writing of file data will fail and the process of writing file data will be exited. Otherwise, initiate a file data write operation. Write the file identifier and power-loss protection type (write file data power-loss protection) into the currently available entries of the power-loss protection record table, and set the power-loss protection status to enabled. Calculate the number of data storage blocks M to be modified based on the length of the file data to be written. In the data storage area management table, starting from the currently available entries, obtain M entries, write a used flag into each entry, and move the head pointer of the data storage area management table down by M entries. Based on the data storage block identifiers in the M entries, write file data into the corresponding M data storage blocks, erase and reclaim the M data storage blocks that the file has replaced. Create a new file record entry in the file record page where the file identifier is located, and write the file data storage space information constructed after reallocation. Where M is a positive integer; If there is not enough space in the file record page where the file identifier is located to store the new file record entry, then write a used flag into the currently available entry of the file record page management table. Based on the file record page identifier recorded in the table, copy the file identifier and file control information from the original file record page into the corresponding file record page, create a new file record entry, and write the file data storage space information constructed after reallocation; erase and reclaim the original file record page. Write a completion flag into the new valid file record; In the valid entries of the power failure protection log, the power failure protection status is rewritten to "completed", and the power failure protection pointer in the power failure protection log is moved down one item.
7. The power-down protection method for a system-on-a-chip according to claim 2, characterized in that: When the system is powered on again, query the valid records in the power failure protection record table. If the power failure protection type is write file data power failure protection, search for the target file identifier in the file record page area. If the target file identifier is unique and exists, then perform the following steps: S201. Check whether the valid file record entries in the file record page corresponding to the target file are complete; If complete, proceed to step S205; S202. Check whether the number of data storage block identifiers in the valid file record entries in the file record page is consistent with the amount of storage space occupied by the file; if consistent, compare the valid file record entries in the file record page with the previous file record entry, construct an array of data storage block identifiers that need to be released and those that need to be erased and reclaimed, release and erase and reclaim the corresponding data storage blocks in sequence accordingly, and write a completion flag in the valid file record entry to complete the file data writing, and execute step S205; S203. Locate the data storage block of the file, find the data storage block that is inconsistent with the data storage block identifier recorded in the previous file record entry of the valid file record entry in the file record page, erase and reclaim it, and write a completion flag into the valid file record entry; Determine whether the file record page meets the requirements for storing a file data storage space information. If it does, copy the information of the previous file record item to the next available file record item and write it to the next available file record item. Execute step S205. S204. Write a used flag into the currently available entry of the file record page management table. Based on the file record page identifier recorded in the entry, copy and write the file identifier and file control information from the original file record page into the corresponding file record page. Create a new file record entry, write the information of the previous file record entry of the valid file record entry in the original file record page, and erase and reclaim the original file record page. S205. Change the power failure protection status of the valid record in the power failure protection log table from the start state to the completed state, and end the file data writing power failure protection recovery process. If the identifier of the target file is not unique, then perform the following steps: S301. Determine whether two file record pages are new file record pages or original file record pages; S302. Check whether the number of data storage block identifiers for valid file record entries in the new file record page is consistent with the amount of storage space occupied by the file; If there is a discrepancy, then execute S304; S303. Compare the last file record item in the original file record page with the valid file record item in the new file record page, construct an array of data storage block identifiers that need to be released and those that need to be erased and recycled, release and erase the corresponding data storage blocks in turn, and write a completion flag in the valid file record item of the new file record page to complete the file data writing, erase and recycle the original file record page, and execute step S305. S304. Locate the data storage block of the file, find the data storage block that is inconsistent with the data storage block identifier recorded in the last file record entry of the original file record page, erase and reclaim it, and write a completion flag into the valid file record entry of the new file record page; Copy the contents of the last file record entry in the original file record page and write them to the next available file record entry in the new file record page, then erase and reclaim the original file record page; S305. Change the power failure protection status of the valid record in the power failure protection log table from the start state to the completed state, and end the file data writing power failure protection recovery process.
8. The power-down protection method for a system-on-a-chip according to claim 2, characterized in that: When deleting a file, obtain the file identifier and search the file record page area to check if the file identifier exists. If it does not exist, the file deletion fails and the file deletion process exits. Write the file identifier and power failure protection type into the currently available entries of the power failure protection log table, where the power failure protection type is "delete file power failure protection" and the power failure protection status is set to "enabled". Initiate the file deletion operation, and based on the data storage block identifiers recorded in the valid file record entries of the file record page where the file identifier is located, sequentially erase and reclaim the corresponding data storage blocks; erase and reclaim the file record page where the file identifier is located; In the valid entries of the power failure protection log, the power failure protection status is changed from the activated state to the completed state, and the power failure protection pointer in the power failure protection log is moved down one item.
9. The power-down protection method for a system-on-a-chip according to claim 2, characterized in that: When the system is powered on again, query the valid records in the power failure protection log table. If the power failure protection type is file deletion power failure protection, then perform the following steps: S401. Search for the target file identifier in the file record page area; If the target file identifier does not exist, proceed to step S405; S402. Based on the data storage block identifier of the valid file record entry in the file record page corresponding to the target file, and the data storage block identifier indicated by the tail pointer of the data storage area management table, determine whether the data storage block occupied by the file has been erased and reclaimed. If not, continue to erase and reclaim the data storage block. S404. Determine whether the file record page has been erased and recycled. If it has not been erased and recycled, erase and recycle the file record page. S405. File deletion complete. Change the power failure protection status of the valid record in the power failure protection log table from the started state to the completed state, and end the file deletion power failure protection recovery process.
10. A power-loss protection system for a system-on-a-chip, characterized in that: This includes a power failure protection log table, a file log page area, a file log page management table, and a data storage area management table; The power failure protection log table records the target file's identifier, power failure protection type, and power failure protection status; the file record page area includes multiple file record pages, each corresponding to a file, used to record file control information and file data storage space information; The file record page management table is used to control the cyclic allocation and erasure / reclaiming of file record pages; the data storage area management table is used to control the cyclic allocation and erasure / reclaiming of data storage blocks in the data storage area. When a file is created, file record pages and file data storage space are allocated for the file, and file control information and data storage space information are recorded in the file record pages of the file; each time file data is written, the modified data storage blocks of the file are erased and reclaimed, new data storage blocks are allocated for the file to store the modified file data, and the file data storage space information is reconstructed and recorded in the file record pages of the file; when a file is deleted, the file record pages and data storage blocks occupied by the file are erased and reclaimed. When executing commands to create a file, write file data, or delete a file, before releasing and erasing file record pages and data storage blocks, the power-loss protection log table records the target file's identifier and power-loss protection type, sets the power-loss protection status to "activated," and activates the system's power-loss protection. After completing the release and erasure of the corresponding file record pages and data storage blocks in the command, the power-loss protection status of the target file in the power-loss protection log table is rewritten to "completed," completing the power-loss protection for the command and ending the execution of the command. If a power failure occurs during the execution of the command, the entries in the power failure protection record table where the power failure protection status is equal to the start status are valid records. When the system is powered on again, the valid records in the power failure protection record table are queried, and the power failure protection recovery process is executed. Based on the power failure protection type and the valid file records in the file record page corresponding to the target file, the execution status of the command before the power failure is determined, and the remaining functions of the command are executed or the system status before the command execution is restored according to the execution status of the command. After completion, the power failure protection status is changed to the completed status.
Citation Information
Patent Citations
Smart card storage system and managing method for file creation in the system
CN101042696A
Abnormal power failure recovery method and system based on block management
CN113791933A
