Mirror image processing method, device and equipment and readable storage medium

By writing the same image in non-flash memory and monitoring hash consistency, the problem that dm-verity cannot verify the integrity of the RAW partition mirror is solved, and the integrity checksum repair of the mirror is realized to ensure system stability.

CN120540669APending Publication Date: 2025-08-26FIBOCOM AUTO INC
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510729573.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-30
Publication Date
2025-08-26

AI Technical Summary

Technical Problem

The existing dm-verity technology cannot effectively verify the A/B system image integrity of RAW partitions in non-flash memory, and cannot perform data checksum repair.

Method used

When the system is burned, the same target image is written in the first partition and the second partition. The hash value of the partition is calculated and compared at the start of the system, the hash value is continuously monitored during the runtime, and data recovery processing is performed when inconsistent.

Benefits of technology

The integrity checksum repair of the A/B system image of RAW partitions in non-flash memory is realized, ensuring the normal operation of the system and improving data reliability and stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120540669A_ABST
    Figure CN120540669A_ABST
Patent Text Reader

Abstract

The invention discloses a mirror image processing method, device and equipment and a readable storage medium, and the method comprises the steps: reading mirror image data of two partitions and calculating an original hash value in a system starting process; the target mirror images are written into the two partitions in the system burning process. And the data burning integrity can be verified by comparing the original hash values of different partitions. If verification is passed, the system can continue to run. In the process of operating the system, hash values during operation are obtained respectively. And comparing the runtime hash value with the corresponding original hash value to verify the integrity of the runtime mirror image. And performing data recovery according to the integrity verification condition, and performing exception handling under the condition that the data recovery fails. According to the method, the mirror image integrity can be verified, mirror image repair can be carried out on the corresponding partitions under the condition that the mirror image integrity verification is not passed, so that the mirror image integrity is guaranteed, and exception handling is carried out as little as possible to guarantee normal operation of a system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of storage technology, and in particular to a mirror processing method, apparatus, device, and readable storage medium. Background Art

[0002] dm-verity (block device data integrity verification) technology is used to check the integrity of the image at startup to prevent malicious tampering. dm-verity uses a hash tree to implement data verification, ensuring the integrity of the image by verifying the hash value of the system image at startup.

[0003] However, dm-verity still has some limitations. These include: It's typically used to verify the integrity of a single partition and only supports image partitions on block devices with file systems. It's also typically used for large partitions and isn't suitable for small NandFlash (or non-NandFlash) partitions. This means that dm-verity technology cannot verify the integrity of A / B system images on RAW NandFlash partitions (unformatted (or unassigned file system) partitions). Without data verification, it's impossible to repair tampered data.

[0004] In summary, how to effectively solve the problem of repairing the A / B system image of the RAW partition in the non-flash memory is a technical problem that those skilled in the art urgently need to solve. Summary of the Invention

[0005] The purpose of this application is to provide an image processing method, device, equipment and readable storage medium, which can realize A / B system image repair with RAW partitions in non-flash memory.

[0006] To solve the above technical problems, this application provides the following technical solutions:

[0007] A mirror processing method, comprising:

[0008] When burning the system, write the same target image into the first and second partitions;

[0009] When the system is started for the first time, the mirror data of the first partition is read, and a first original hash value corresponding to the mirror data of the first partition is calculated and saved; the mirror data of the second partition is read, and a second original hash value corresponding to the mirror data of the second partition is calculated and saved;

[0010] If the first original hash value is inconsistent with the second original hash value, perform exception processing;

[0011] If the first original hash value is consistent with the second original hash value, running the system;

[0012] During the system operation, the real-time image data of the first partition is read, and a first runtime hash value corresponding to the real-time image data of the first partition is calculated and saved; the real-time image data of the second partition is read, and a second runtime hash value corresponding to the real-time image data of the second partition is calculated and saved;

[0013] Obtain an integrity check result of the first partition by comparing the first runtime hash value with the first original hash value to determine whether they are consistent; obtain an integrity check result of the second partition by comparing the second runtime hash value with the second original hash value to determine whether they are consistent;

[0014] If the first partition and / or the second partition fails the integrity check, data recovery processing is performed; if the data recovery processing fails, exception processing is performed.

[0015] Preferably, if the first partition and / or the second partition fails the integrity check, data recovery processing is performed, including:

[0016] If the first partition fails the integrity check and the second partition passes the integrity check, the mirror data of the second partition is copied to the first partition to restore the data of the first partition.

[0017] Preferably, if the first partition and / or the second partition fails the integrity check, data recovery processing is performed, including:

[0018] If the second partition fails the integrity check and the first partition passes the integrity check, the mirror data of the first partition is copied to the second partition to restore the data of the first partition.

[0019] Preferably, if the first partition and / or the second partition fails the integrity check, data recovery processing is performed, including:

[0020] If both the first partition and the second partition fail the integrity check, the first real-time page hash value corresponding to each page in the first partition is compared with the first original page hash value one by one to determine the abnormal page of the first partition; the second real-time page hash value corresponding to each page in the first partition is compared with the second original page hash value one by one to determine the abnormal page of the second partition;

[0021] If the positions of the abnormal page of the first partition do not overlap with the abnormal page of the second partition, the data of the corresponding page is read from the second partition and copied to the abnormal page of the first partition; the data of the corresponding page is read from the first partition and copied to the abnormal page of the second partition to restore the data of the abnormal page.

[0022] Preferably, it also includes:

[0023] If the positions of the abnormal page of the first partition and the abnormal page of the second partition overlap, it is determined that the data recovery process has failed.

[0024] Preferably, if the data recovery process fails, an exception process is performed, including:

[0025] Reading the real-time mirror data in the target partition that has undergone data recovery processing, and calculating and saving a recovery hash value corresponding to the real-time mirror data;

[0026] Determining whether the restored hash value is consistent with the original hash value of the target partition;

[0027] If yes, determining that the image recovery of the target partition is successful;

[0028] If not, it is determined that the image recovery of the target partition has failed, and exception processing is performed.

[0029] Preferably, exception handling is performed, including:

[0030] The target image is written in the first partition and the second partition.

[0031] A mirror processing device, comprising:

[0032] The burning module is used to write the same target image into the first partition and the second partition when the system is burned;

[0033] a startup verification module, configured to, when the system is first started, read the mirror data of the first partition, calculate and save a first original hash value corresponding to the mirror data of the first partition; read the mirror data of the second partition, calculate and save a second original hash value corresponding to the mirror data of the second partition; if the first original hash value and the second original hash value are inconsistent, perform exception processing; if the first original hash value and the second original hash value are consistent, run the system;

[0034] The operation verification module is configured to, during system operation, read the real-time image data of the first partition, calculate and save a first runtime hash value corresponding to the real-time image data of the first partition; read the real-time image data of the second partition, calculate and save a second runtime hash value corresponding to the real-time image data of the second partition; obtain an integrity check result of the first partition by comparing the first runtime hash value with the first original hash value to determine whether they are consistent; obtain an integrity check result of the second partition by comparing the second runtime hash value with the second original hash value to determine whether they are consistent; and perform exception processing if both the first partition and the second partition fail the integrity check;

[0035] The data recovery module is configured to perform data recovery processing if the first partition and / or the second partition fails the integrity check, and perform exception processing if the data recovery processing fails.

[0036] An electronic device, comprising:

[0037] memory for storing computer programs;

[0038] A processor is used to implement the steps of the above-mentioned image processing method when executing a computer program.

[0039] A readable storage medium stores a computer program, which implements the steps of the above-mentioned image processing method when executed by a processor.

[0040] Using the method provided in the embodiments of the present application, when the system is burned, the same target image is written into the first partition and the second partition; when the system is first started, the image data of the first partition is read, and a first original hash value corresponding to the image data of the first partition is calculated and saved; the image data of the second partition is read, and a second original hash value corresponding to the image data of the second partition is calculated and saved; if the first original hash value and the second original hash value are inconsistent, exception processing is performed; if the first original hash value and the second original hash value are consistent, the system is run; during the system operation, the real-time image data of the first partition is read, and a first runtime hash value corresponding to the real-time image data of the first partition is calculated and saved; the real-time image data of the second partition is read, and a second runtime hash value corresponding to the real-time image data of the second partition is calculated and saved; by comparing the first runtime hash value with the first original hash value to see whether they are consistent, an integrity check result of the first partition is obtained; by comparing the second runtime hash value with the second original hash value to see whether they are consistent, an integrity check result of the second partition is obtained; if the first partition and / or the second partition fails the integrity check, data recovery processing is performed, and if the data recovery processing fails, exception processing is performed.

[0041] In this application, during system startup, the mirror data of the first and second partitions is read. The target image is written to both partitions during the system burn process. That is, if the data is complete, the corresponding raw hash values ​​should be consistent. Based on this, after reading the mirror data of the first and second partitions, the corresponding raw hash values ​​can be calculated and then compared to determine whether the images of the first and second partitions are consistent. If they are consistent, the data remains intact after burning. If they are inconsistent, the data is incomplete after burning, and exception handling is required. If the images of the two partitions are consistent, the system can continue to operate. During system operation, the real-time image data of the first and second partitions are read again and the corresponding runtime hash values ​​are calculated. The runtime hash values ​​are compared with the raw hash values ​​corresponding to the first and second image data, respectively, to determine whether the images of the first and second partitions pass the integrity check. If the first and / or second partitions fail the integrity check, data recovery is performed. If the data recovery fails, exception handling is performed. In other words, this application can not only verify the integrity of the image, but also repair the partition image if the image integrity check fails, thereby ensuring the integrity of the image and performing as little exception processing as possible to ensure the normal operation of the system.

[0042] Accordingly, the embodiments of the present application also provide an image processing apparatus, device, and readable storage medium corresponding to the above-mentioned image processing method, which have the above-mentioned technical effects and are not described in detail here. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the following briefly introduces the drawings required for use in the embodiments or related technical descriptions. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0044] Figure 1 This is a flowchart of an implementation method of a mirror image processing method in an embodiment of the present application;

[0045] Figure 2 This is a schematic diagram of mirror storage of a RAW partition in a non-flash memory according to an embodiment of the present application;

[0046] Figure 3 This is a schematic diagram of a system startup raw hash value calculation in an embodiment of the present application;

[0047] Figure 4 A schematic diagram of hash value calculation during partition runtime in a system operation process according to an embodiment of the present application;

[0048] Figure 5 This is a schematic diagram of hash verification when a system is flashed and started for the first time in an embodiment of the present application;

[0049] Figure 6 This is a schematic diagram of a hash comparison of partition A in an embodiment of the present application;

[0050] Figure 7 This is a schematic diagram of a B partition hash comparison in an embodiment of the present application;

[0051] Figure 8 This is a schematic diagram of a partition-based image repair in an embodiment of the present application;

[0052] Figure 9 This is a schematic diagram of an abnormal page in an embodiment of the present application;

[0053] Figure 10 This is another schematic diagram of an abnormal page in an embodiment of the present application;

[0054] Figure 11 This is a flowchart of another mirror processing method in an embodiment of the present application;

[0055] Figure 12 This is a structural diagram of an image processing device according to an embodiment of the present application;

[0056] Figure 13 This is a schematic structural diagram of an electronic device according to an embodiment of the present application;

[0057] Figure 14 This is a schematic diagram of the specific structure of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION

[0058] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below in conjunction with the accompanying drawings and specific embodiments. Obviously, the embodiments described are only a part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without making any creative efforts are within the scope of protection of the present application.

[0059] Please refer to Figure 1 , Figure 1 This is a flowchart of a mirror processing method according to an embodiment of the present application, which includes the following steps:

[0060] When the system is burned, the same target image is written into the first partition and the second partition.

[0061] When the system is started for the first time, the mirror data of the first partition is read, and the first original hash value corresponding to the mirror data of the first partition is calculated and saved.

[0062] The mirror data of the second partition is read, and a second original hash value corresponding to the mirror data of the second partition is calculated and saved.

[0063] If the first original hash value is inconsistent with the second original hash value, an exception is handled.

[0064] If the first original hash value is consistent with the second original hash value, the system is run.

[0065] During the system operation, the real-time image data of the first partition is read, and a first runtime hash value corresponding to the real-time image data of the first partition is calculated and saved; the real-time image data of the second partition is read, and a second runtime hash value corresponding to the real-time image data of the second partition is calculated and saved;

[0066] By comparing the first runtime hash value with the first original hash value to see if they are consistent, an integrity check result of the first partition is obtained; by comparing the second runtime hash value with the second original hash value to see if they are consistent, an integrity check result of the second partition is obtained;

[0067] If the first partition and / or the second partition fails the integrity check, data recovery processing is performed. If the data recovery processing fails, exception processing is performed.

[0068] That is to say, in this application, the mirror processing method has three stages.

[0069] The first stage is the system burning stage, in which the same target image is written to the first and second partitions respectively. In other words, after a successful normal burning, the images of the first and second partitions are exactly the same, both being the target image.

[0070] The second stage is the first startup of the system. In this stage, the integrity of the images of the first partition and the second partition will be verified. The verification method is to read the image data from the first partition and the second partition respectively, and calculate the corresponding original hash value. Since the same target image is written to the first partition and the second partition during the burning process. Therefore, when the original hash values ​​of the first partition and the second partition are consistent, it means that the images of the first partition and the second partition have passed the integrity check. Subsequent system startups can continue. In the case that the original hash values ​​of the first partition and the second partition are inconsistent, it can be clearly seen that the image of at least one of the first partition and the second partition is incomplete. At this time, exception handling can be performed directly. Specifically, in actual applications, exception handling includes: writing the target image in the first partition and the second partition. That is, rewriting the same target image to the first partition and the second partition.

[0071] In the third phase, during system operation, the integrity of the images in the first and second partitions is verified. Specifically, the real-time image data of the first and second partitions can be read separately while the system is running. Runtime hash values ​​are then calculated for each partition. These run-time hash values ​​are then compared with the corresponding original hash values ​​to perform integrity checks on the image data in each partition. If at least one of the first and second partitions fails the integrity check, data recovery can be performed. If data recovery fails, exception handling is performed.

[0072] If the first partition and / or the second partition fails the integrity check, data recovery processing is performed, including:

[0073] If the first partition fails the integrity check and the second partition passes the integrity check, the mirror data of the second partition is copied to the first partition to restore the data of the first partition.

[0074] If the first partition and / or the second partition fails the integrity check, data recovery processing is performed, including:

[0075] If the second partition fails the integrity check and the first partition passes the integrity check, the mirror data of the first partition is copied to the second partition to restore the data of the first partition.

[0076] If the first partition and / or the second partition fails the integrity check, data recovery is performed, including:

[0077] If the integrity check fails in both the first partition and the second partition, the first real-time page hash value corresponding to each page in the first partition is compared with the first original page hash value one by one to determine the abnormal page of the first partition; the second real-time page hash value corresponding to each page in the first partition is compared with the second original page hash value one by one to determine the abnormal page of the second partition;

[0078] If the positions of the abnormal page of the first partition do not overlap with the abnormal page of the second partition, the data of the corresponding page is read from the second partition and copied to the abnormal page of the first partition; the data of the corresponding page is read from the first partition and copied to the abnormal page of the second partition to restore the data of the abnormal page.

[0079] That is to say, when calculating the hash value, a hash value can be calculated for each page. Then, the page can be compared one by one to find the abnormal page. When it is clear that the abnormal pages of the first partition and the second partition do not overlap, the data of the abnormal page can be restored, thereby realizing data recovery.

[0080] Furthermore, if the positions of the abnormal pages of the first partition and the abnormal pages of the second partition overlap, then the data recovery process is determined to have failed. If the abnormal pages exist at the same position, it indicates that data recovery cannot be achieved by copying the data. In this case, the data recovery process can be directly determined to have failed and the abnormal process can be performed.

[0081] In a specific embodiment, if the data recovery process fails, an exception process is performed, including:

[0082] Reading the real-time mirror data in the target partition that has undergone data recovery processing, and calculating and saving the recovery hash value corresponding to the real-time mirror data;

[0083] Determine whether the restored hash value is consistent with the original hash value of the target partition;

[0084] If yes, it is determined that the image recovery of the target partition is successful;

[0085] If not, it is determined that the image recovery of the target partition has failed, and exception handling is performed.

[0086] After data recovery, in order to determine the integrity of the image, hash calculation and integrity verification can be performed again.

[0087] Using the method provided in the embodiments of the present application, when the system is burned, the same target image is written into the first partition and the second partition; when the system is first started, the image data of the first partition is read, and a first original hash value corresponding to the image data of the first partition is calculated and saved; the image data of the second partition is read, and a second original hash value corresponding to the image data of the second partition is calculated and saved; if the first original hash value and the second original hash value are inconsistent, exception processing is performed; if the first original hash value and the second original hash value are consistent, the system is run; during the system operation, the real-time image data of the first partition is read, and a first runtime hash value corresponding to the real-time image data of the first partition is calculated and saved; the real-time image data of the second partition is read, and a second runtime hash value corresponding to the real-time image data of the second partition is calculated and saved; by comparing the first runtime hash value with the first original hash value to see whether they are consistent, an integrity check result of the first partition is obtained; by comparing the second runtime hash value with the second original hash value to see whether they are consistent, an integrity check result of the second partition is obtained; if the first partition and / or the second partition fails the integrity check, data recovery processing is performed, and if the data recovery processing fails, exception processing is performed.

[0088] In this application, during system startup, the mirror data of the first and second partitions is read. The target image is written to both partitions during the system burn process. That is, if the data is complete, the corresponding raw hash values ​​should be consistent. Based on this, after reading the mirror data of the first and second partitions, the corresponding raw hash values ​​can be calculated and then compared to determine whether the images of the first and second partitions are consistent. If they are consistent, the data remains intact after burning. If they are inconsistent, the data is incomplete after burning, and exception handling is required. If the images of the two partitions are consistent, the system can continue to operate. During system operation, the real-time image data of the first and second partitions is read again, and the corresponding runtime hash values ​​are calculated. The runtime hash values ​​are compared with the raw hash values ​​corresponding to the first and second image data, respectively, to determine whether the images of the first and second partitions pass the integrity check. If the first and / or second partitions fail the integrity check, data recovery is performed. If the data recovery fails, exception handling is performed. In other words, this application can not only verify the integrity of the image, but also repair the image of the partition if the image integrity check fails, thereby ensuring the integrity of the image and performing as little exception processing as possible to ensure the normal operation of the system.

[0089] To facilitate those skilled in the art to understand and implement the mirror processing method adopted in the embodiments of the present application, the mirror processing method is described in detail below with reference to a specific scenario as an example.

[0090] The process of integrity checking and repairing the A / B system image in the RAW partition of NandFlash is as follows:

[0091] Please refer to Figure 2 When burning the system, write the same image (target image) to partition A (first partition) and partition B (second partition).

[0092] Please refer to Figure 3 When the system starts for the first time, it reads the data of each page of partition A and calculates the MD5 value, which is saved as the original A partition MD5 value file;

[0093] Read the data of each page of partition B and calculate the MD5 value, and save it as the original B partition MD5 value file.

[0094] Please refer to Figure 4 During system operation, the MD5 of each page data of partition A is calculated and recorded as the runtime A partition MD5 value file; at the same time, the MD5 of each page data of partition B is calculated and recorded as the runtime B partition MD5 value file.

[0095] Please refer to Figure 5 When the system is flashed and started for the first time, the original A partition MD5 value and the original B partition MD5 value are generated and verified. If they are inconsistent, the system is notified to perform abnormal processing (such as mirror copy).

[0096] Please refer to Figure 6 , compare the MD5 value of partition A during runtime with the MD5 value of the original partition A. If they are consistent, it means that the image of partition A is complete.

[0097] Please refer to Figure 7 , compare the runtime B partition MD5 value with the original B partition MD5 value. If they are consistent, it means that the B partition image is complete.

[0098] Please refer to Figure 8 If the A partition image is complete and the B partition image verification fails, the B partition image can be repaired using the A partition image.

[0099] If the B partition image is complete and the A partition image verification fails, the A partition image can be repaired using the B partition image.

[0100] If both AB partition images fail to be verified, the system can be notified to perform exception processing.

[0101] Under normal circumstances, the MD5 value of the original A partition, the MD5 value of the A partition during operation, the MD5 value of the original B partition, and the MD5 value of the B partition during operation are all the same.

[0102] In addition, since MD5 saves the MD5 value of each page data, a page data can be repaired by comparing the MD5 value.

[0103] Scenario 1: Please refer to Figure 9 , the Page2 data of partition B is abnormal.

[0104] At this point, the data in Page 2 of partition A can be copied to Page 2 of partition B to achieve data repair.

[0105] Scenario 2: Please refer to Figure 10 , Page1 of partition A is abnormal, and Page2 of partition B is abnormal.

[0106] Although there are multiple abnormal pages in the partition, since the abnormal pages are different, data repair can still be achieved by exchanging data on the abnormal pages.

[0107] It can be seen that the image processing method adopted in this application can improve data reliability and system stability by verifying the integrity of the A / B system image of the RAW partition in NandFlash.

[0108] Please refer to Figure 11 , Figure 11 This is a flowchart of another image processing method in an embodiment of the present application, which includes the following steps:

[0109] S101 . During system operation, data is read from a first partition to obtain first mirror data, and data is read from a second partition to obtain second mirror data.

[0110] The target images are written to the first and second partitions during the system flash process, and data integrity checks are performed on the first and second partitions during the initial system startup. If the data is incomplete, abnormal data is detected. Therefore, during system operation, the original hash value representing the target image is obtained. Therefore, in this application, the runtime hash values ​​of the two different partitions can be directly compared during system operation to ensure consistency.

[0111] In the present application, the first partition and the second partition may be RAW partitions in a NAND flash memory.

[0112] like Figure 2 As shown, when the system is burned, the same image is written into partition A (i.e., the first partition) and partition B (i.e., the second partition). It should be noted that the first partition and the second partition in this application are not limited in terms of priority or order.

[0113] During the system startup process, the integrity of the images in the first partition and the second partition needs to be checked. In order to check the integrity of the images in the first partition and the second partition, the first image data can be read from the first partition and the second image data can be read from the second partition respectively.

[0114] In this application, data repair is performed in consideration of the possibility of data tampering, incompleteness, etc. Therefore, in order to distinguish different data, this application refers to the mirror data read from the first partition as the first mirror data, and the data read from the second partition as the second mirror data.

[0115] S102: Calculate runtime hash values ​​corresponding to the first image data and the second image data respectively, and compare them.

[0116] It should be noted that, since the first partition and the second partition both store target images, under normal circumstances, the read first image data and second image data should be completely identical.

[0117] Therefore, by comparing the first image data and the second image data to see if they are consistent, it can be determined whether the image passes the integrity check. To improve the comparison efficiency, in this embodiment, the runtime hash values ​​corresponding to the first image data and the second image data can be calculated and compared to determine whether the first image data and the second image data are consistent.

[0118] In this embodiment of the present application, when calculating the runtime hash values ​​of the first and second image data, only the hash values ​​of all image data read from the first partition, i.e., the real-time zone hash value, can be calculated. That is, the first partition has a real-time zone hash value, and the second partition has a real-time zone hash value.

[0119] Of course, when calculating the runtime hash value, you can also calculate the hash value corresponding to the mirror data read from each page in the partition based on the page. In this way, for the first partition, the number of its runtime hash values ​​is consistent with the number of its pages, and correspondingly, the number of runtime hash values ​​corresponding to the second partition is also consistent with the number of its pages.

[0120] In addition, when calculating the runtime hash value, you can calculate the hash value corresponding to the zone or the hash value corresponding to the page.

[0121] When comparing the runtime hash values, the real-time zone hash value of the first partition is compared with the real-time zone hash value of the second partition; the real-time page hash value of the i-th page of the first partition is compared with the real-time page hash value of the i-th page of the second partition (where i can be 0 to the number of pages in the partition minus 1).

[0122] For two hash values ​​being compared, if they are consistent, it indicates that the corresponding data are consistent; for two hash values ​​being compared, if they are inconsistent, it indicates that the corresponding data are inconsistent.

[0123] S103 : When it is determined based on the comparison result that the current images of the first partition and the second partition are different, obtain the original area hash value of the target image.

[0124] Regardless of whether the runtime hash value is one of the real-time zone hash value and the real-time page hash value, or both, it can be determined based on the comparison result whether the current images of the first partition and the second partition are the same.

[0125] When it is determined that the current images of the first partition and the second partition are different, it can be clear that the image of at least one of the first partition and the second partition is incomplete, that is, cannot pass the image integrity check.

[0126] At this point, you can get the original area hash value of the target image, so as to further clarify which partition of the partition image is incomplete and perform subsequent data repair.

[0127] The original area hash value is the target image hash value. It should be noted that in this application, the hash algorithm used to calculate the hash value is the same algorithm.

[0128] S104: Perform image repair based on the original hash value and the runtime hash value, so that the first partition and the second partition store the target image.

[0129] Since the original hash value refers to the target image with integrity, the image repair can be performed on at least one of the first partition and the second partition that has an incomplete image by combining the original hash value and the runtime hash value.

[0130] In a specific embodiment of the present application, the original hash value includes the original zone hash value, and the runtime hash value includes the real-time zone hash value. The image repair is performed by combining the original hash value and the runtime hash value, including:

[0131] The partition whose real-time zone hash value is the same as the original hash value is determined as the source partition;

[0132] Determine a partition where the hash value of the real-time zone is different from the original hash value as a target partition;

[0133] Write the mirrored data in the source partition to the target partition.

[0134] For ease of description, the above steps are combined and explained below.

[0135] When calculating the hash value, the hash value is calculated only in units of zones, and the first partition corresponds to a real-time zone hash value, and the second partition corresponds to a real-time zone hash value. For the original hash value, the first partition also corresponds to an original zone hash value, and the second partition corresponds to an original zone hash value. However, because the images stored in the first partition and the second partition are the same, the original zone hash values ​​corresponding to the two partitions are the same, and therefore the original zone hash values ​​do not make a distinction between different partitions. Therefore, when performing image repair, for a partition whose real-time zone hash value is the same as the original hash value, it indicates that the image of the partition is consistent with the target image, and it can pass the image integrity check, so its corresponding partition can be used as the source partition during image repair. For a partition whose real-time zone hash value is different from the original hash value, it indicates that the image of the partition is inconsistent with the target image, and it cannot pass the image integrity check, so its corresponding partition can be used as the target partition during image repair.

[0136] After the source partition and the target partition are clearly identified, the mirror data in the source partition can be directly written to the target partition, so that the mirrors of the two partitions can pass the integrity check. Of course, in actual applications, if the source partition does not exist, an error message can be output in this embodiment.

[0137] In a specific embodiment of the present application, the original hash value includes the original page hash value, and the runtime hash value includes the real-time page hash value. The image repair is performed by combining the original hash value and the runtime hash value, including:

[0138] For pages at the same position in the first partition and the second partition, the page whose real-time page hash value is the same as the original page hash value is determined as the source page, and the page whose real-time page hash value is different from the original page hash value is determined as the target page;

[0139] Use the source page to repair data on the target page.

[0140] For ease of description, the above steps are combined and explained below.

[0141] In this embodiment, when calculating the hash value, the hash calculation can be performed in units of pages. Since the images in the first partition and the second partition are both target images, the pages corresponding to the same sequence number should contain the same data, and the corresponding real-time page hash values ​​should also be the same.

[0142] Therefore, for pages at the same location in the first and second partitions, the page with the same runtime hash value as the original page hash value can be directly determined as the source page, while the page with a different real-time page hash value can be determined as the target page. When performing data repair, the data on the source page is copied to the target page, thereby implementing data modification to ensure that it can pass the data integrity check.

[0143] Of course, in actual applications, the data of pages at the same location may be damaged. In this case, repair is impossible and an error can be directly reported. That is, for pages at the same location in the first and second partitions, if both are target pages, an error message is output.

[0144] In a specific embodiment of the present application, the original hash value includes the original zone hash value, and the runtime hash value includes the real-time zone hash value and the real-time page hash value. The image repair is performed by combining the original hash value and the runtime hash value, including:

[0145] The partition whose real-time zone hash value is the same as the original hash value is determined as the source partition;

[0146] Determine a partition where the hash value of the real-time zone is different from the original hash value as a target partition;

[0147] Write the mirror data in the source partition to the target partition;

[0148] If there is no source partition, the real-time page hash value is used for data modification, and the original area hash value is used for data verification.

[0149] In other words, hash values ​​can be both zone hash values ​​and page hash values. If it's clear that the mirror images of the first and second partitions are different, we can first determine whether the mirror image within a certain partition is complete. Specifically, the partition whose real-time zone hash value matches the original hash value is identified as the source partition, and correspondingly, the partition whose real-time zone hash value differs from the original hash value is identified as the target partition. If a source partition exists, the mirror data of the source partition can be directly written to the target partition, completing the data modification.

[0150] If there is no source partition, it is necessary to further use page hash values ​​to search one by one to achieve data repair.

[0151] In a specific embodiment of the present application, data modification is performed using the real-time page hash value, and data verification is performed using the original area hash value, including:

[0152] Compare the real-time page hash values ​​to identify the difference pages;

[0153] Exchanging data between the difference pages in the first partition and the second partition;

[0154] After the exchange, the runtime hash values ​​corresponding to the first mirror data and the second mirror data are calculated, and the newly obtained runtime hash values ​​are compared with the original area hash values;

[0155] The partition whose real-time zone hash value is the same as the original hash value is determined as the source partition;

[0156] Determine a partition where the hash value of the real-time zone is different from the original hash value as a target partition;

[0157] Use the mirror data in the source partition to repair the data in the target partition.

[0158] That is to say, when it is found that no zone has a complete target image, you can try to repair the data by patching it together.

[0159] Specifically, the real-time page hash values ​​can be compared to identify the discrepant pages. For example, if the real-time page hash values ​​corresponding to the first page of the first partition and the second page of the second partition are different, it is possible that the data in one of the first and second pages of the first partition is correct. In this case, data exchange can be used to attempt to determine which page is correct, namely the source page.

[0160] After swapping the data on the difference pages, the real-time zone hash value can be calculated. The newly calculated real-time zone hash value is then compared with the original zone hash value to determine whether the target image has been restored after the data swap. If the target image has been restored, the data on another partition can be repaired based on the target image.

[0161] In a specific implementation of the present application, data exchange is performed on the difference pages between the first partition and the second partition, including:

[0162] If there is one differential page, the data of the differential page in the first partition is written into the differential page in the second partition, and the data of the differential page in the second partition is written into the differential page in the first partition;

[0163] If there are multiple difference pages and the difference is lower than the difference threshold, each difference page is exchanged as an element, and the data is exchanged according to the current permutation and combination method;

[0164] If the number of different pages is not less than the difference threshold, an error message is output.

[0165] That is, different repair measures can be adopted for different numbers of differential pages.

[0166] Specifically, when there is only one differential page, the data on the differential page can be directly swapped to calculate whether the real-time zone hash value corresponding to the mirrored data of the partition after the data swap is consistent with the original zone hash value. If they are consistent, it indicates that the target mirror has been found, and data synchronization between the two partitions can continue. If the target mirror cannot be found, it indicates that the data of the pages at the same location in the two partitions has been damaged, and data repair cannot be completed at this time, and an error processing can be performed.

[0167] When there are multiple difference pages but they do not exceed the difference threshold, the exchange of one difference page can be regarded as an element, so that these elements can be arranged and combined, and data exchange can be performed according to the arrangement and combination. For example, when there are two difference pages, such as page 3 and page 4, the corresponding exchange combinations can include exchanging data only for page 3, exchanging data only for page 4, and exchanging data for page 3 and page 4 at the same time. The data exchange here means exchanging the data of page 3 in the first partition to the position of page 3 in the second partition. After each data exchange, a new real-time zone hash value can be calculated to try to find the target image. If the target image is still not found after all attempts, an error message can be output. Considering that too many attempts may delay the operation of the system, in actual applications, the difference threshold can be set to 3 (of course, it can also be set to other values ​​in actual applications).

[0168] When there are too many difference pages, in order to avoid an infinite loop, an error can be reported directly.

[0169] By using the method provided in the embodiments of the present application, during the system startup process, data is read from the first partition to obtain first image data, and data is read from the second partition to obtain second image data; target images are written to the first partition and the second partition respectively during the system burning process; runtime hash values ​​corresponding to the first image data and the second image data are calculated and compared; when it is determined by the comparison result that the current images of the first partition and the second partition are different, the original area hash value of the target image is obtained; and the image is repaired by combining the original hash value and the runtime hash value so that the first partition and the second partition store the target image.

[0170] In the present application, during the system startup process, the mirror data of the first partition and the second partition are read. The target image is written to the first partition and the second partition during the system burning process. That is to say, when the data is complete, the runtime hash values ​​corresponding to the two should be consistent. Based on this, after reading the first mirror data and the second mirror data, the runtime hash values ​​corresponding to the first mirror data and the second mirror data can be calculated respectively. By comparing the runtime hash values, it can be clearly determined whether the images of the first partition and the second partition are the same. When it is determined that the current images of the first partition and the second partition are different, the original image hash can be obtained, and the image can be repaired with the help of the original image hash and the runtime hash value. This ensures that the first partition and the second partition maintain the same image. In other words, the present application can not only verify the integrity of the image, but also repair the image of the first partition and the second partition if the image integrity check fails, thereby ensuring the integrity of the image.

[0171] Corresponding to the above method embodiment, the embodiment of the present application further provides a mirror processing device. The mirror processing device described below and the mirror processing method described above can refer to each other.

[0172] See also Figure 12 As shown, the device includes the following modules:

[0173] The burning module 101 is used to write the same target image into the first partition and the second partition during system burning;

[0174] The startup verification module 102 is used to read the mirror data of the first partition when the system is first started, calculate and save the first original hash value corresponding to the mirror data of the first partition; read the mirror data of the second partition, calculate and save the second original hash value corresponding to the mirror data of the second partition; if the first original hash value and the second original hash value are inconsistent, perform exception processing; if the first original hash value and the second original hash value are consistent, run the system;

[0175] The operation verification module 103 is used to read the real-time image data of the first partition during system operation, calculate and save a first runtime hash value corresponding to the real-time image data of the first partition; read the real-time image data of the second partition, calculate and save a second runtime hash value corresponding to the real-time image data of the second partition; obtain an integrity verification result of the first partition by comparing the first runtime hash value with the first original hash value to determine whether they are consistent; and obtain an integrity verification result of the second partition by comparing the second runtime hash value with the second original hash value to determine whether they are consistent;

[0176] The data recovery module 104 is configured to perform data recovery processing if the first partition and / or the second partition fails the integrity check, and perform exception processing if the data recovery processing fails.

[0177] Using the device provided in the embodiments of the present application, when the system is burned, the same target image is written into the first partition and the second partition; when the system is first started, the image data of the first partition is read, and a first original hash value corresponding to the image data of the first partition is calculated and saved; the image data of the second partition is read, and a second original hash value corresponding to the image data of the second partition is calculated and saved; if the first original hash value and the second original hash value are inconsistent, exception processing is performed; if the first original hash value and the second original hash value are consistent, the system is run; during the system operation, the real-time image data of the first partition is read, and a first runtime hash value corresponding to the real-time image data of the first partition is calculated and saved; the real-time image data of the second partition is read, and a second runtime hash value corresponding to the real-time image data of the second partition is calculated and saved; by comparing the first runtime hash value with the first original hash value to see whether they are consistent, an integrity check result of the first partition is obtained; by comparing the second runtime hash value with the second original hash value to see whether they are consistent, an integrity check result of the second partition is obtained; if the first partition and / or the second partition fails the integrity check, data recovery processing is performed, and if the data recovery processing fails, exception processing is performed.

[0178] In this application, during system startup, the mirror data of the first and second partitions is read. The target image is written to both partitions during the system burn process. That is, if the data is complete, the corresponding raw hash values ​​should be consistent. Based on this, after reading the mirror data of the first and second partitions, the corresponding raw hash values ​​can be calculated and then compared to determine whether the images of the first and second partitions are consistent. If they are consistent, the data remains intact after burning. If they are inconsistent, the data is incomplete after burning, and exception handling is required. If the images of the two partitions are consistent, the system can continue to operate. During system operation, the real-time image data of the first and second partitions are read again and the corresponding runtime hash values ​​are calculated. The runtime hash values ​​are compared with the raw hash values ​​corresponding to the first and second image data, respectively, to determine whether the images of the first and second partitions pass the integrity check. If the first and / or second partitions fail the integrity check, data recovery is performed. If the data recovery fails, exception handling is performed. In other words, this application can not only verify the integrity of the image, but also repair the partition image if the image integrity check fails, thereby ensuring the integrity of the image and performing as little exception processing as possible to ensure the normal operation of the system.

[0179] In a specific embodiment of the present application, the data recovery module is specifically configured to copy the mirror data of the second partition to the first partition to restore the data of the first partition if the first partition fails the integrity check and the second partition passes the integrity check.

[0180] In a specific embodiment of the present application, the data recovery module is specifically configured to copy the mirror data of the first partition to the second partition to restore the data of the first partition if the second partition fails the integrity check and the first partition passes the integrity check.

[0181] In a specific embodiment of the present application, the data recovery module is specifically used to compare the first real-time page hash value corresponding to each page in the first partition with the first original page hash value one by one to determine the abnormal page of the first partition if both the first partition and the second partition fail the integrity check; compare the second real-time page hash value corresponding to each page in the first partition with the second original page hash value one by one to determine the abnormal page of the second partition; if the position of the abnormal page of the first partition does not overlap with the abnormal page of the second partition, read the data of the corresponding page from the second partition and copy it to the abnormal page of the first partition; read the data of the corresponding page from the first partition and copy it to the abnormal page of the second partition to recover the data of the abnormal page.

[0182] In a specific implementation of the present application, the data recovery module is further configured to: determine that the data recovery process has failed if the positions of the abnormal page of the first partition and the abnormal page of the second partition overlap.

[0183] In a specific embodiment of the present application, the data recovery module is specifically configured to, after performing data recovery processing, read the real-time mirror data in the target partition that has undergone data recovery processing, calculate and save a recovery hash value corresponding to the real-time mirror data; determine whether the recovery hash value is consistent with the original hash value of the target partition; if so, determine that the image recovery of the target partition is successful; if not, determine that the image recovery of the target partition has failed, and perform exception processing.

[0184] In a specific implementation of the present application, performing exception handling includes: writing a target image into the first partition and the second partition.

[0185] Corresponding to the above method embodiment, an embodiment of the present application further provides an electronic device. The electronic device described below and the mirror processing method described above can refer to each other.

[0186] See also Figure 13 As shown, the electronic device includes:

[0187] Memory 332, for storing computer programs;

[0188] The processor 322 is configured to implement the steps of the image processing method of the above method embodiment when executing a computer program.

[0189] For details, please refer to Figure 14 , Figure 14 This is a schematic diagram of the specific structure of an electronic device provided in this embodiment. This electronic device may vary significantly due to different configurations or performance. It may include one or more central processing units (CPUs) (for example, one or more processors) and memory 332. The memory 332 stores one or more computer programs 342 or data 344. The memory 332 may be temporary storage or permanent storage. The program stored in the memory 332 may include one or more modules (not shown), each of which may include a series of instruction operations in the data processing device. Furthermore, the processor 322 may be configured to communicate with the memory 332 to execute the series of instruction operations in the memory 332 on the electronic device 301.

[0190] The electronic device 301 may further include one or more power supplies 326 , one or more wired or wireless network interfaces 350 , one or more input / output interfaces 358 , and / or one or more operating systems 341 .

[0191] The steps in the mirror processing method described above can be implemented by the structure of an electronic device.

[0192] Corresponding to the above method embodiment, an embodiment of the present application further provides a readable storage medium. The readable storage medium described below and the mirror processing method described above can refer to each other.

[0193] A readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the mirror processing method of the above method embodiment.

[0194] The readable storage medium may specifically be any readable storage medium capable of storing program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0195] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from the other embodiments. Reference can be made to the descriptions of the identical or similar parts between the various embodiments. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple, and the relevant parts can be referred to the descriptions of the methods.

[0196] Those skilled in the art may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0197] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0198] Finally, it should be noted that, in this document, relationships such as first and second, etc., are used solely to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms include, comprise, or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that includes a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.

[0199] This document uses specific examples to illustrate the principles and implementation methods of this application. The description of the above embodiments is only used to help understand the method and core ideas of this application. At the same time, for those skilled in the art, based on the ideas of this application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting this application.

Claims

1. A mirror processing method, characterized in that: include: When burning the system, write the same target image into the first and second partitions; When the system is started for the first time, the mirror data of the first partition is read, and a first original hash value corresponding to the mirror data of the first partition is calculated and saved; Read the mirror data of the second partition, calculate and save a second original hash value corresponding to the mirror data of the second partition; If the first original hash value is inconsistent with the second original hash value, perform exception processing; If the first original hash value is consistent with the second original hash value, running the system; During the system operation, the real-time image data of the first partition is read, and a first runtime hash value corresponding to the real-time image data of the first partition is calculated and saved; Reading the real-time image data of the second partition, calculating and saving a second runtime hash value corresponding to the real-time image data of the second partition; Obtaining an integrity check result of the first partition by comparing the first runtime hash value with the first original hash value to determine whether they are consistent; Obtaining an integrity check result of the second partition by comparing the second runtime hash value with the second original hash value to determine whether they are consistent; If the first partition and / or the second partition fails the integrity check, data recovery processing is performed; if the data recovery processing fails, exception processing is performed.

2. The mirror processing method according to claim 1, wherein: If the first partition and / or the second partition fails the integrity check, data recovery processing is performed, including: If the first partition fails the integrity check and the second partition passes the integrity check, the mirror data of the second partition is copied to the first partition to restore the data of the first partition.

3. The mirror processing method according to claim 1, wherein: If the first partition and / or the second partition fails the integrity check, data recovery processing is performed, including: If the second partition fails the integrity check and the first partition passes the integrity check, the mirror data of the first partition is copied to the second partition to restore the data of the first partition.

4. The mirror processing method according to claim 1, wherein: If the first partition and / or the second partition fails the integrity check, data recovery processing is performed, including: If both the first partition and the second partition fail the integrity check, the first real-time page hash value corresponding to each page in the first partition is compared with the first original page hash value one by one to determine the abnormal page of the first partition; the second real-time page hash value corresponding to each page in the first partition is compared with the second original page hash value one by one to determine the abnormal page of the second partition; If the positions of the abnormal page of the first partition do not overlap with the abnormal page of the second partition, the data of the corresponding page is read from the second partition and copied to the abnormal page of the first partition; the data of the corresponding page is read from the first partition and copied to the abnormal page of the second partition to restore the data of the abnormal page.

5. The mirror processing method according to claim 4, characterized in that: Also includes: If the positions of the abnormal page of the first partition and the abnormal page of the second partition overlap, it is determined that the data recovery process has failed.

6. The mirror processing method according to claim 1, wherein: If data recovery fails, exception handling is performed, including: Reading the real-time mirror data in the target partition that has undergone data recovery processing, and calculating and saving a recovery hash value corresponding to the real-time mirror data; Determining whether the restored hash value is consistent with the original hash value of the target partition; If yes, determining that the image recovery of the target partition is successful; If not, it is determined that the image recovery of the target partition has failed, and exception processing is performed.

7. The mirror processing method according to any one of claims 1 to 6, characterized in that: Perform exception handling, including: The target image is written in the first partition and the second partition.

8. A mirror processing device, characterized in that: include: The burning module is used to write the same target image into the first partition and the second partition when the system is burned; A startup verification module, configured to read the mirror data of the first partition and calculate and save a first original hash value corresponding to the mirror data of the first partition when the system is started for the first time; Read the mirror data of the second partition, calculate and save a second original hash value corresponding to the mirror data of the second partition; If the first original hash value is inconsistent with the second original hash value, perform exception processing; If the first original hash value is consistent with the second original hash value, running the system; An operation verification module is used to read the real-time image data of the first partition during the operation of the system, and calculate and save a first runtime hash value corresponding to the real-time image data of the first partition; Reading the real-time image data of the second partition, calculating and saving a second runtime hash value corresponding to the real-time image data of the second partition; obtaining an integrity check result of the first partition by comparing the first runtime hash value with the first original hash value to determine whether they are consistent; obtaining an integrity check result of the second partition by comparing the second runtime hash value with the second original hash value to determine whether they are consistent; The data recovery module is configured to perform data recovery processing if the first partition and / or the second partition fails the integrity check, and perform exception processing if the data recovery processing fails.

9. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the mirror processing method according to any one of claims 1 to 7 when executing the computer program.

10. A readable storage medium, characterized in that: The readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the mirror processing method according to any one of claims 1 to 7 are implemented.