A Modular Layered Power Failure Protection Design Backup and Testing Method
By adopting a modular, hierarchical power outage protection design and testing method, the problems of high cost and long testing time of existing power outage equipment are solved, achieving efficient power outage protection testing and ensuring data integrity and security.
Patent Information
- Application Number
- CN202210386117.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-13
- Publication Date
- 2025-12-02
- Estimated Expiration
- 2042-04-13
AI Technical Summary
In existing technologies, firmware testing that simulates power outage scenarios requires the use of self-developed power-off equipment, which is costly and time-consuming. This is especially true for PCIe password card devices, where the power-on and power-off process involves restarting the PC, resulting in low testing efficiency.
A modular, hierarchical power failure protection design is adopted. By defining backup and recovery functions, the data to be modified is backed up to the backup area, and the data integrity is verified through hierarchical testing methods to avoid the involvement of external power failure devices.
It enables power outage protection testing without the need for external power disconnection equipment, improving testing efficiency and ensuring the safety and reliability of power outage protection design.
Smart Images

Figure CN115033422B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of information technology, and in particular to a modular, layered power failure protection design backup and testing method. Background Technology
[0002] In secure encryption products, firmware refers to the program stored in the secure chip's memory. It controls various product functions, enabling the product to operate normally. Functions such as key generation, key import, and PIN code authentication involve erasing and writing Flash data. If a power outage occurs during these operations (due to unstable voltage, incomplete operation, etc.), the Flash data may be corrupted. In this case, the Flash data is neither the original nor the new data, but rather a third-state data. For example, if the original data is 11111111 and the new data is 22222222, the new value after a power outage might be 11F83722. To address this issue, power-off protection is typically implemented in the firmware. However, common testing methods involve using a power-off device to automatically control power-on and power-off, perform a Flash data write operation, read the Flash data, and verify its correctness to simulate a power outage scenario.
[0003] In existing technologies, the correctness of the power-off function of a UKey product is determined by writing and reading Flash data through an automated power-off device. Typically, a PC is connected to the power-off device via a USB interface, and the UKey device under test is connected to the power-off device. The overall framework diagram is shown below. Figure 1 As shown, the test process is as follows: Figure 2 As shown, specifically including:
[0004] 1. The PC tool sends Flash control commands, data, and power-off time data to the power-off device;
[0005] 2. After receiving the data, the powered device parses the control commands, data, and power-off time. It then powers on the device under test (DUT), partially transmitting the commands and data to the DUT, and simultaneously setting the power-off timer. If the DUT returns data, it also needs to transmit this data to the PC testing tool. If no data is returned, it still needs to return a power-off success status code to the PC testing tool. The PC testing tool will not stop testing until it receives the returned data.
[0006] However, the above method requires the use of power-off equipment to achieve the above process. Matching power-off equipment is usually difficult to buy, and most of them are developed and designed by manufacturers themselves, which requires a certain amount of development costs and time.
[0007] For PCIe password card devices, powering on and off once involves restarting the PC, making a complete power-off test too time-consuming. Summary of the Invention
[0008] The purpose of this invention is to provide a modular, layered power failure protection design backup and testing method, thereby solving the aforementioned problems existing in the prior art.
[0009] To achieve the above objectives, the technical solution adopted by the present invention is as follows:
[0010] A modular, hierarchical power failure protection design backup method includes the following steps:
[0011] S1, back up the original data to be modified to the backup area, so that the backup area contains multiple backup items and a completion flag, specifically including:
[0012] S11, Define the backup function WriteBackupOldData, which backs up the original data to be modified to the backup area.
[0013] S12, Define the function WriteBackupInfo1. After the original backup is completed, use the function WriteBackupInfo1 to write information page 1 to indicate that the original data backup is complete; combine the backup data and information page 1 as a backup item;
[0014] S13, Define a new data writing function WriteNewData, and use the new data to be written to Flash to directly write to Flash, replacing the original data to be modified;
[0015] S14, After the Flash data replacement is completed, define the function WriteBackupInfo2, and use the function WriteBackupInfo2 to write the completion flag information page 2 to indicate that the Flash modification and replacement is complete;
[0016] S2, search for the largest index information page in the backup area. If the information page is the completion flag page 2, then data recovery is not required; if the largest index information page is the information page 1, then data recovery in the backup area is required.
[0017] Preferably, information page 1 in step S12 serves as an identifier indicating the completion of the original data backup, consisting of a 16-byte fixed value TAG1 + index value + original backup data address + backup data length + CRC check value; information page 2 serves as a completion marker, used to indicate that all backup items in a backup area are completed, consisting of a 16-byte fixed value TAG2 + index value + number of backup items + CRC check value.
[0018] Preferably, in step S2, the largest index information page in the backup area is searched. If the index information page is the completion flag information page 2 and the CRC value of the information page is correct, it means that no data recovery is required. If the CRC value of the information page is incorrect, information page 1 needs to be further judged. If the index information page is information page 1 and the CRC value of the information page is correct, it means that the data in the backup area needs to be recovered. Otherwise, the backup data does not need to be recovered.
[0019] Another objective of this invention is to provide a test method for modular hierarchical power failure protection data backup, which performs recovery tests on data that has not been fully backed up, including the following steps:
[0020] A1, define the backup function WriteBackupOldData, which backs up the original data to be modified to the backup area.
[0021] A2, Define the function WriteBackupInfo1. After the original backup is completed, use the function WriteBackupInfo1 to write information page 1 to indicate that the original data backup is complete.
[0022] A3, define the function WriteBackupInfo1Test, call the function WriteBackupInfo1Test to perform a test, and destroy the data content in information page 1;
[0023] A4 calls Recovery to restore the backup data. If the restoration fails, the data backup was unsuccessful, indicating that the test passed. If the restoration is successful, the test failed, indicating that the data backup protection mechanism failed.
[0024] The final objective of this invention is to provide a testing method for modular, layered power failure protection data backup, which performs recovery tests on data for which target data modifications have not been completed, including the following steps:
[0025] B1 defines the backup function WriteBackupOldData, which backs up the original data to be modified to the backup area.
[0026] B2, Define the function WriteBackupInfo1. After the original backup is completed, use the function WriteBackupInfo1 to write information page 1 to indicate that the original data backup is complete.
[0027] B3, Define a new data writing function WriteNewData. Use the new data writing function WriteNewData to directly write the new data to be written to Flash, replacing the original data to be modified.
[0028] B4. After the Flash data replacement is completed, define the function WriteBackupInfo2. Use the function WriteBackupInfo2 to write the completion information page 2, indicating that the Flash modification and replacement is complete.
[0029] B5, define the function WriteBackupInfo2Test, call the function WriteBackupInfo1Test to perform a test, and destroy the data content in the completion flag information page 2;
[0030] B6 calls Recovery to restore the backup data. If the restoration fails, the test fails and the power-loss protection mechanism fails. If the restoration succeeds, the test passes and the power-loss protection mechanism succeeds.
[0031] Preferably, the following steps are also included:
[0032] After the function logic processing is completed and no data corruption test is performed, a complete set of functions with Flash write operation is called. The backup area contains data, information page 1, and information page 2. After calling Recovery, it is determined that the data modification is complete. Since no power failure occurred, no data recovery is performed.
[0033] Preferably, the Recovery mechanism includes the following:
[0034] The recovery operation is initiated by the Recover function retrieving information from the backup area;
[0035] Backup data area retrieval process:
[0036] First, search the largest index information page in the backup area. If this information page is the completion flag page 2 and its CRC value is correct, it means there is no data to be recovered. If the information page is page 1 and its CRC value is correct, and there is no page 2 or page 2 is incomplete, then the data in the backup area needs to be recovered.
[0037] The preferred data recovery process is as follows:
[0038] Obtain the address and length information of the data to be restored from backup information page 1;
[0039] Write the backup data to the target address;
[0040] Write backup information page 2 after backup information page 1, and return to the data recovery success flag 0;
[0041] If data recovery is not required, exit directly and return to the "No recovery required" flag 1.
[0042] If the expected return value is 0, but the actual return value is 1, the test is considered to have failed.
[0043] If the expected return value is 1, but the actual return value is 0, the test is considered to have failed.
[0044] If the expected return identifier matches the actual return identifier, the test is considered successful.
[0045] The beneficial effects of this invention are:
[0046] This invention provides a modular, layered power-off protection data backup and testing method. This method implements a modular, layered design for the firmware power-off program and performs layered testing on each module according to its function. The system is considered successful after passing the corresponding tests. This solution eliminates the need for external power-off equipment during power-off testing and ensures the safety and reliability of the power-off protection design through layered testing. Attached Figure Description
[0047] Figure 1 This is a general framework diagram of the operation of automated power-off equipment in existing technology;
[0048] Figure 2 This is a schematic diagram of the testing process for automated power-off equipment in existing technology;
[0049] Figure 3 This is a schematic diagram of the backup data in the backup area provided in Example 1;
[0050] Figure 4 This is a schematic diagram of the backup items completed in the backup area in Example 1;
[0051] Figure 5 This is a schematic diagram of the backup area structure when data modification is completed in Example 1;
[0052] Figure 6 This is a diagram showing the status of the backup area after the original data backup was successful.
[0053] Figure 7 This is the data recovery test flowchart for incomplete data backup provided in Example 2;
[0054] Figure 8 This is the data recovery test flowchart for incomplete target data modification provided in Example 3;
[0055] Figure 9This is a diagram illustrating how to determine whether backup data needs to be restored. Detailed Implementation
[0056] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0057] Example 1
[0058] This embodiment provides a modular, hierarchical power failure protection design backup method, including the following steps:
[0059] S1, back up the original data to be modified to the backup area, so that the backup area contains multiple backup items and a completion flag, specifically including:
[0060] S11, Define the backup function WriteBackupOldData, which backs up the original data to be modified to the backup area.
[0061] S12, Define the function WriteBackupInfo1. After the original backup is completed, use the function WriteBackupInfo1 to write information page 1 to indicate that the original data backup is complete; combine the backup data and information page 1 as a backup item;
[0062] S13, Define a new data writing function WriteNewData, and use the new data to be written to Flash to directly write to Flash, replacing the original data to be modified;
[0063] S14, After the Flash data replacement is completed, define the function WriteBackupInfo2, and use the function WriteBackupInfo2 to write the completion flag information page 2 to indicate that the Flash modification and replacement is complete;
[0064] S2, search for the largest index information page in the backup area. If the information page is the completion flag page 2, then data recovery is not required; if the largest index information page is the information page 1, then data recovery in the backup area is required.
[0065] In step S12, information page 1 serves as an identifier indicating the completion of the original data backup, consisting of a 16-byte fixed value TAG1 + index value + original backup data address + backup data length + CRC check value; information page 2 serves as a completion flag, used to indicate that all backup items in a backup area are completed, consisting of a 16-byte fixed value TAG2 + index value + number of backup items + CRC check value.
[0066] In step S2, the largest index information page in the backup area is searched. If the index information page is the completion flag information page 2 and the CRC value of the information page is correct, it means that no data recovery is required. If the CRC value of the information page is incorrect, information page 1 needs to be further judged. If the index information page is information page 1 and the CRC value of the information page is correct, it means that the data in the backup area needs to be recovered. Otherwise, the backup data does not need to be recovered.
[0067] Example 2
[0068] This embodiment provides a test method for modular hierarchical power failure protection data backup, which performs recovery tests on data that has not been fully backed up, including the following steps:
[0069] A1, define the backup function WriteBackupOldData, which backs up the original data to be modified to the backup area.
[0070] A2, Define the function WriteBackupInfo1. After the original backup is completed, use the function WriteBackupInfo1 to write information page 1 to indicate that the original data backup is complete.
[0071] A3, define the function WriteBackupInfo1Test, call the function WriteBackupInfo1Test to perform a test, and destroy the data content in information page 1;
[0072] A4 calls Recovery to restore the backup data. If the restoration fails, the data backup was unsuccessful, indicating that the test passed. If the restoration is successful, the test failed, indicating that the data backup protection mechanism failed.
[0073] After the function logic processing is completed and no data corruption test is performed, a complete set of functions with Flash write operation is called. The backup area contains data, information page 1, and information page 2. After calling Recovery, it is determined that the data modification is complete. Since no power failure occurred, no data recovery is performed.
[0074] Example 3
[0075] This embodiment also provides a test method for modular hierarchical power failure protection data backup, which performs recovery tests on data for which the target data modification has not been completed, including the following steps:
[0076] B1 defines the backup function WriteBackupOldData, which backs up the original data to be modified to the backup area.
[0077] B2, Define the function WriteBackupInfo1. After the original backup is completed, use the function WriteBackupInfo1 to write information page 1 to indicate that the original data backup is complete.
[0078] B3, Define a new data writing function WriteNewData. Use the new data writing function WriteNewData to directly write the new data to be written to Flash, replacing the original data to be modified.
[0079] B4. After the Flash data replacement is completed, define the function WriteBackupInfo2. Use the function WriteBackupInfo2 to write the completion information page 2, indicating that the Flash modification and replacement is complete.
[0080] B5, define the function WriteBackupInfo2Test, call the function WriteBackupInfo1Test to perform a test, and destroy the data content in the completion flag information page 2;
[0081] B6 calls Recovery to restore the backup data. If the restoration fails, the test fails and the power-loss protection mechanism fails. If the restoration succeeds, the test passes and the power-loss protection mechanism succeeds.
[0082] After the function logic processing is completed and no data corruption test is performed, a complete set of functions with Flash write operation is called. The backup area contains data, information page 1, and information page 2. After calling Recovery, it is determined that the data modification is complete. Since no power failure occurred, no data recovery is performed.
[0083] The recovery operation is initiated by the Recover function retrieving information from the backup area;
[0084] Backup data area retrieval process:
[0085] First, search the largest index information page in the backup area. If this information page is the completion flag page 2 and its CRC value is correct, it means there is no data to be recovered. If the information page is page 1 and its CRC value is correct, and there is no page 2 or page 2 is incomplete, then the data in the backup area needs to be recovered.
[0086] The data recovery process is as follows:
[0087] Obtain the address and length information of the data to be restored from backup information page 1;
[0088] Write the backup data to the target address;
[0089] Write backup information page 2 after backup information page 1, and return to the data recovery success flag 0;
[0090] If data recovery is not required, exit directly and return to the "No recovery required" flag 1.
[0091] If the expected return value is 0, but the actual return value is 1, the test is considered to have failed.
[0092] If the expected return value is 1, but the actual return value is 0, the test is considered to have failed.
[0093] If the expected return identifier matches the actual return identifier, the test is considered successful.
[0094] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A modular, layered power failure protection design backup and testing method, characterized in that, The backup method includes the following steps: S1, back up the original data to be modified to the backup area, so that the backup area contains multiple backup items and a completion flag, specifically including: S11, Define the backup function WriteBackupOldData, which backs up the original data to be modified to the backup area. S12, Define the function WriteBackupInfo1. After the original backup is completed, use the function WriteBackupInfo1 to write information page 1 to indicate that the original data backup is complete; combine the backup data and information page 1 as a backup item. S13, Define a new data writing function WriteNewData, and use the new data to be written to Flash to directly write to Flash, replacing the original data to be modified; S14, After the Flash data replacement is completed, define the function WriteBackupInfo2, and use the function WriteBackupInfo2 to write the completion flag information page 2 to indicate that the Flash modification and replacement is complete; S2, search for the largest index information page in the backup area. If the information page is the completion flag page 2, then data recovery is not required; if the largest index information page is page 1, then data recovery in the backup area is required. In step S12, information page 1 serves as an identifier indicating the completion of the original data backup, consisting of a 16-byte fixed value TAG1 + index value + original backup data address + backup data length + CRC check value; information page 2 serves as a completion flag, used to indicate that all backup items in a backup area have been completed, consisting of a 16-byte fixed value TAG2 + index value + number of backup items + CRC check value. In step S2, the largest index information page in the backup area is searched. If the index information page is the completion flag information page 2 and the CRC value of the information page is correct, it means that no data recovery is required. If the CRC value of the information page is incorrect, information page 1 needs to be further judged. If the index information page is information page 1 and the CRC value of the information page is correct, it means that the data in the backup area needs to be recovered. Otherwise, the backup data does not need to be recovered. The testing methods include: a modular, layered power failure protection data backup testing method, used for recovering data from incomplete backups, specifically including the following steps: A1, define the backup function WriteBackupOldData, which backs up the original data to be modified to the backup area. A2, Define the function WriteBackupInfo1. After the original backup is completed, use the function WriteBackupInfo1 to write information page 1 to indicate that the original data backup is complete. A3, define the function WriteBackupInfo1Test, call the function WriteBackupInfo1Test to perform a test, and destroy the data content in information page 1; A4 calls Recovery to restore the backup data. If the restoration fails, the data backup was unsuccessful, indicating that the test passed; if the restoration is successful, the test failed, indicating that the data backup protection mechanism failed. It also includes: a test method for modular hierarchical power failure protection data backup, used to perform recovery tests on data for which target data modifications have not been completed, specifically including the following steps: B1 defines the backup function WriteBackupOldData, which backs up the original data to be modified to the backup area. B2, Define the function WriteBackupInfo1. After the original backup is completed, use the function WriteBackupInfo1 to write information page 1 to indicate that the original data backup is complete. B3, Define a new data writing function WriteNewData. Use the new data writing function WriteNewData to directly write the new data to be written to Flash, replacing the original data to be modified. B4. After the Flash data replacement is completed, define the function WriteBackupInfo2. Use the function WriteBackupInfo2 to write the completion information page 2, indicating that the Flash modification and replacement is complete. B5, define the function WriteBackupInfo2Test, call the function WriteBackupInfo1Test to perform a test, and destroy the data content in the completion flag information page 2; B6 calls Recovery to restore the backup data. If the restoration fails, the test fails and the power outage protection mechanism fails. If the restoration succeeds, the test passes and the power outage protection mechanism succeeds.
2. The modular hierarchical power failure protection design backup and testing method according to claim 1, characterized in that, It also includes the following steps: After the function logic processing is completed and no data corruption test is performed, a complete set of functions with Flash write operation is called. The backup area contains data, information page 1, and information page 2. After calling Recovery, it is determined that the data modification is complete. Since no power failure occurred, no data recovery is performed.
3. The modular layered power failure protection design backup and testing method according to claim 2, characterized in that, The Recovery mechanism includes the following: The recovery operation is initiated by the Recover function retrieving information from the backup area; Backup data area retrieval process: First, search the largest index information page in the backup area. If the information page is the completion flag information page 2 and the CRC value of the information page is correct, it means that there is no data that needs to be restored. If the information page is information page 1 and the CRC value of the information page is correct, and there is no information page 2 or information page 2 is incomplete, it means that the data in the backup area needs to be restored.
4. The modular layered power failure protection design backup and testing method according to claim 3, characterized in that, The data recovery process is as follows: Obtain the address and length information of the data to be recovered from information page 1; Write the backup data to the target address; Write information page 2 after information page 1, and return the data recovery success flag 0; If data recovery is not required, exit directly and return to the "No recovery required" flag 1. If the expected return value is 0, but the actual return value is 1, the test is considered to have failed. If the expected return value is 1, but the actual return value is 0, the test is considered to have failed. If the expected return identifier matches the actual return identifier, the test is considered successful.
Citation Information
Patent Citations
Flash storage space dynamic recovery method and device
CN105260270A
Intelligent electric meter embedded application-orientated test method
CN105738855A
Unmanned aerial vehicle firmware updating method, device, unmanned aerial vehicle and storage medium
CN109117168A