A verification method, apparatus, device and storage medium
By performing dual verification on the code copying process in the embedded system, the problem of data inconsistency during code copying is solved, achieving efficient data integrity verification and system startup reliability, and improving the initialization success rate of the embedded system.
Patent Information
- Application Number
- CN202611336889.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-31
- Publication Date
- 2026-11-17
AI Technical Summary
In embedded systems, during the process of loading code from non-volatile storage to executable memory, bit errors are prone to occur due to hardware characteristics and environmental factors, leading to data inconsistency. Existing technologies cannot effectively perform data verification during the copying process, resulting in system startup failure or crash.
A dual verification mechanism is adopted, including a first verification (pre-verification) before each data block copy begins and a second verification (post-verification) after the copy. The copy verification result of each data block is determined by the CRC32 verification algorithm or other verification algorithms, and retransmission is performed when necessary. Combined with dynamic block length adjustment for high-risk and low-risk areas, the integrity verification of the code copying process is achieved.
It effectively improves the reliability of code loading and the success rate of system startup. It can proactively detect and locate data anomalies during the copying phase, avoid system failures caused by hidden errors, and improve the reliability of system initialization.
Smart Images

Figure CN123114848A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of embedded system technology, and in particular to a verification method, apparatus, device and storage medium. Background Technology
[0002] In embedded systems, chip booting, and secure firmware loading scenarios, code needs to be copied from the load address in non-volatile memory to the execution address in executable memory. This process is a core part of system initialization. Since code integrity directly determines whether the system can start or run normally, the reliability of the copying process is crucial.
[0003] However, due to hardware characteristics (such as memory bit flips and flash memory erase / write losses), environmental factors (such as electromagnetic interference and power fluctuations), or transmission link anomalies (such as direct memory access controller failures), bit errors (such as single-bit or multi-bit flips) may occur during code copying, leading to inconsistencies between the runtime address data and the original load address data. Therefore, how to effectively perform data verification during code copying to proactively intercept data anomalies caused by hardware or environmental factors has become an urgent technical problem to be solved. Summary of the Invention
[0004] This application provides a verification method, apparatus, device, and storage medium to at least solve the above-mentioned technical problems existing in the prior art.
[0005] According to a first aspect of this application, a verification method is provided, the method comprising: Obtain the starting load address, starting execution address, and code length of the code to be copied; Obtain the preset block length of the code to be copied, divide the code to be copied into multiple data blocks in sequence according to the code length and the preset block length, and determine the load address and execution address of each data block; Each data block is copied from its corresponding load address to its corresponding execution address. Before each data block copying begins, a first verification is performed on each data block, and after the copying begins, a second verification is performed on each data block. The copy verification result of each data block is determined based on the results of the first and second verifications. Based on the copy verification results of all data blocks, determine the verification result of the code to be copied.
[0006] In one possible implementation, obtaining the preset block length of the code to be copied includes: The code to be copied is divided into high-risk areas and low-risk areas. The high-risk areas include the code area where the interrupt vector table and / or the entry point of the key function are located. The preset block length corresponding to the high-risk area is determined as a first preset length, and the preset block length of the low-risk area is determined as a second preset block length; the first preset block length is less than the second preset block length.
[0007] In one possible implementation, copying each data block from its corresponding load address to its corresponding execution address includes: copying each data block from its corresponding load address to its corresponding execution address via a direct memory access controller or a central processing unit; correspondingly, The second verification of each data block after copying includes: When the central processing unit copies each data block from the corresponding load address to the corresponding runtime address, after the memory copy function returns, a cache clearing operation or a cache invalidation operation is performed, and the copied data is read from the corresponding runtime address for a second verification; or, the copied data is directly read from the physical memory corresponding to the runtime address and a second verification is performed. When each data block is copied from the corresponding load address to the corresponding runtime address through the direct memory access controller, after the direct memory access controller triggers a transmission completion interrupt, the copied data is read from the corresponding runtime address and a second verification is performed.
[0008] In one possible implementation, the first verification of each data block before the start of each data block copy includes: Read all the data of the data block from the load address corresponding to the data block; Based on all the data read, a first verification value is calculated using a verification algorithm, and the first verification value is used as the first verification result.
[0009] In one possible implementation, the method further includes: The first verification value is compared with the preset standard verification value; If the first check value is inconsistent with the preset standard check value, it is determined that the original data of the data block in the starting loading address is corrupted, the copying is terminated and an error code is reported. If the first verification value is consistent with the preset standard verification value, then the first verification value is taken as the first verification result.
[0010] In one possible implementation, the second verification of each data block after copying includes: Read all copied data from the running address corresponding to the data block; Based on all the data read, a second verification value is calculated using a verification algorithm, and the second verification value is used as the second verification result.
[0011] In one possible implementation, the verification algorithm includes a CRC32 verification algorithm, which is executed by a lookup table method or hardware acceleration instructions.
[0012] In one possible implementation, determining the copy verification result of each data block based on the first verification result and the second verification result includes: If the first verification result is consistent with the second verification result, then the copy verification result of the data block is determined to be a successful copy. If the first verification result is inconsistent with the second verification result, the copy verification result of the data block is determined to be incorrect, and the retransmission operation of the data block is triggered. The retransmission operation includes: copying the data block from the corresponding load address to the corresponding run address; reading the copied data from the corresponding run address and performing a second verification; comparing the new second verification result with the first verification result; if the comparison is consistent, the copy verification result of the data block is determined to be successful; if the comparison is inconsistent and the cumulative number of retransmissions has not reached the preset maximum number of retries, the retransmission operation continues.
[0013] In one possible implementation, the method further includes: If the new second verification result obtained after the retransmission operation is still inconsistent with the first verification result, the current verification algorithm will be switched to the backup verification algorithm. The backup verification algorithm is used to re-perform the second verification on the data block, and the second verification result after switching algorithms is compared with the first verification result; if the comparison is consistent, the copy verification result of the data block is determined to be successful; if the comparison is still inconsistent, the retransmission operation is continued. If the cumulative number of retransmissions has reached the preset maximum number of retransmissions, then the copy verification result of the data block is determined to be a permanent error. The generator polynomial of the backup verification algorithm is different from that of the current verification algorithm, and the Hamming distance of the backup verification algorithm is greater than that of the current verification algorithm; the backup verification algorithm includes an enhanced CRC32 verification algorithm, which is executed by a lookup table method or hardware acceleration instructions.
[0014] In one possible implementation, the method further includes: Count the number of data blocks whose copy verification results are determined to be permanent errors across all data blocks; If the number of data blocks with permanent errors exceeds a preset threshold, it is determined that there is a hardware fault in the storage medium where the starting load address is located, the copying is terminated and an error code is reported.
[0015] In one possible implementation, the method further includes: If the copy verification results of a preset number of data blocks are all determined to be permanently failed, then it is determined that there is a hardware fault in the storage medium where the starting loading address of the code to be copied is located, the copying is terminated and an error code is reported.
[0016] In one possible implementation, determining the verification result of the code to be copied based on the copy verification results of all data blocks includes: Count the number of data blocks whose copy verification results are determined to be successfully copied; If the proportion of successfully copied data blocks to all data blocks exceeds the target threshold, then the verification result of the code to be copied is determined to be successfully copied. If the proportion of successfully copied data blocks to all data blocks does not exceed the target threshold, then the verification result of the code to be copied is determined to be a copy failure.
[0017] According to a second aspect of this application, a verification apparatus is provided, the apparatus comprising: The acquisition module is used to obtain the starting load address, starting execution address, and code length of the code to be copied; The block segmentation module is used to obtain the preset block length of the code to be copied, divide the code to be copied into multiple data blocks in sequence according to the code length and the preset block length, and determine the load address and execution address of each data block; The dual verification module is used to copy each data block from the corresponding load address to the corresponding execution address, and to perform a first verification on each data block before the copying begins and a second verification on each data block after the copying. The copy verification result of each data block is determined based on the results of the first and second verifications. The determination module is used to determine the verification result of the code to be copied based on the copy verification results of all data blocks.
[0018] According to a third aspect of this application, an electronic device is provided, comprising: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method described in this application.
[0019] According to a fourth aspect of this application, a non-transitory computer-readable storage medium is provided storing computer instructions for causing the computer to perform the methods described in this application.
[0020] The verification method, apparatus, device, and storage medium of this application obtain the starting load address, starting execution address, and code length of the code to be copied; obtain the preset block length of the code to be copied; divide the code to be copied into multiple data blocks sequentially according to the code length and the preset block length; determine the load address and execution address of each data block; copy each data block from its corresponding load address to its corresponding execution address; perform a first verification on each data block before copying begins and a second verification on each data block after copying; determine the copy verification result of each data block based on the first and second verification results; and determine the verification result of the code to be copied based on the copy verification results of all data blocks. This achieves dual verification before and after copying, thereby effectively improving the reliability of code loading and the success rate of system startup.
[0021] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this application, nor is it intended to limit the scope of this application. Other features of this application will become readily apparent from the following description. Attached Figure Description
[0022] The above and other objects, features, and advantages of exemplary embodiments of this application will become readily apparent from the following detailed description taken in conjunction with the accompanying drawings. Several embodiments of this application are illustrated in the drawings by way of example and not limitation, in which: In the accompanying drawings, the same or corresponding reference numerals indicate the same or corresponding parts.
[0023] Figure 1 A schematic diagram illustrating the implementation flow of the verification method provided in an embodiment of this application is shown; Figure 2 A schematic diagram illustrating the implementation flow of the verification operation of the verification method provided in the embodiments of this application is shown; Figure 3 A schematic diagram illustrating the implementation flow of the algorithm switching operation of the verification method provided in this application embodiment is shown; Figure 4 A schematic diagram of the composition structure of the verification device provided in the embodiments of this application is shown; Figure 5 A schematic diagram of the composition structure of an electronic device according to an embodiment of this application is shown. Detailed Implementation
[0024] To make the objectives, features, and advantages of this application more apparent and understandable, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0025] In existing solutions, code copying largely relies on automatic hardware transfer, indirectly detecting copying problems only through runtime verification (such as capturing errors during program execution via assertions and interrupt exceptions). This has two major drawbacks: first, error detection is delayed (it only becomes apparent when the program reaches the erroneous code segment); second, it cannot pinpoint the stage at which the error occurs (it's difficult to distinguish whether the source data is corrupted or the copying process is flawed). Therefore, there is an urgent need for a mechanism that proactively detects errors during the copying process. Through dual verification before and after copying, data anomalies can be intercepted in advance, preventing system startup failures or crashes due to hidden copying errors. CRC32 (Acyclic Redundancy Check 32), as a classic lightweight verification algorithm, has become one of the preferred technologies for data integrity verification in embedded scenarios due to its computational efficiency (hardware-accelerated) and strong detection capability (detecting 99.998% of single-bit and multi-bit errors).
[0026] Based on the characteristics of CRC32, existing technologies mainly derive the following two types of verification schemes: ① CRC verification scheme for data transmission. Its core logic is: the sending end calculates the CRC32 checksum of the source data before data transmission and sends it along with the data; the receiving end, after receiving the data, recalculates the CRC32 and compares it with the sending end's checksum. If they do not match, retransmission is triggered. This scheme is suitable for large file transfers in network communication or general storage devices (such as USB flash drives and hard drives), where the data length is typically in the MB range and the transmission link is asynchronous (such as TCP / IP). Packet loss and out-of-order issues need to be considered. However, for code copying from load address to execution address in embedded systems (typically in the KB range, synchronous memory transfer), the problem to be solved is the consistency of in-situ data on local storage media such as memory / Flash, without needing to handle network protocol overhead. ② Integrity verification scheme for embedded system startup. Its core logic is: during the Bootloader stage, the image file of the startup program is hash-verified (e.g., SHA-256). If the verification passes, it is loaded into RAM for execution; if the verification fails, startup is rejected and an error message is displayed. This scheme only verifies the "complete image after being loaded into RAM", which is a "one-time verification after copying". It cannot detect real-time errors during the copying process (such as the intermediate link from reading from Flash to writing to RAM) (such as instantaneous bit flips during DMA transfer). If an error occurs during the copying process, it will only be discovered after the entire image is loaded, which wastes a lot of time and makes it difficult to locate the error.
[0027] In summary, existing technologies only support post-processing verification or one-time verification after copying, failing to achieve dual verification both before and after copying, and thus unable to distinguish between corrupted source data and errors during the copying process. Furthermore, the general-purpose large-scale large-volume verification is unsuitable for embedded small-volume block copying requirements, and it does not utilize memory paging characteristics to locate error blocks. Therefore, this application provides a verification method, apparatus, device, and storage medium to address the technical problems existing in the prior art.
[0028] Figure 1 A schematic diagram illustrating the implementation flow of the verification method provided in this application embodiment is shown.
[0029] refer to Figure 1 This application provides a verification method for performing integrity verification during code copying, which can be executed by an electronic device, specifically by an embedded system within the electronic device. The method includes: Operation 101: Obtain the starting load address, starting execution address, and code length of the code to be copied; In embedded system startup, chip initialization, or security firmware loading scenarios, the program code to be executed is typically stored in non-volatile memory (NVM) and needs to be moved to executable memory before it can be executed by the central processing unit (CPU). This moving process, known as code copying, is one of the core steps in system initialization. The program code to be executed is the code to be copied, which can be understood as a sequence of binary instructions or a block of data that needs to be loaded from the storage medium into memory for execution. Non-volatile memory can include, but is not limited to, flash memory, read-only memory (ROM), and electrically erasable programmable read-only memory (EEPROM). Executable memory includes, but is not limited to, random access memory (RAM), static random access memory (SRAM), and dynamic random access memory (DRAM).
[0030] To perform integrity verification during code copying, the code to be copied, its starting load address, starting execution address, and code length are first obtained. The starting load address can be considered as the starting position of the code to be copied in non-volatile storage medium, i.e., the starting address of the source data; the starting execution address can be considered as the target starting position of the code to be copied in executable memory, i.e., the starting address of the destination; the code length can be considered as the total size of the code to be copied, used to determine the boundaries of the copy operation.
[0031] Operation 102: Obtain the preset block length of the code to be copied, divide the code to be copied into multiple data blocks in sequence according to the code length and the preset block length, and determine the load address and execution address of each data block.
[0032] The preset block length is the size of each pre-defined data block, used to divide the code to be copied into multiple smaller data blocks for processing block by block. Based on the code length and the preset block length, the code to be copied is sequentially divided into multiple data blocks, starting from the initial load address and proceeding according to the preset block length, with the last data block not exceeding the preset block length. Each data block corresponds to a load address and a run address. The load address is the starting position of the data block in the storage medium, and the run address is the target starting position of the data block in memory. Both are determined based on the initial load address, the initial run address, and the offset of the data block within the overall code to be copied. By processing in blocks, the task of copying and verifying large-scale code can be decomposed into multiple smaller subtasks, reducing the complexity and risk of a single operation.
[0033] For example, suppose the starting load address of the code to be copied is... The starting address is The code length is The preset block length is The number of data blocks into which the code to be copied is divided. for: That is, the code length divided by the preset block length and then rounded up. For the first... Data blocks ( Starting from 0), its load address and runtime address They are respectively:
[0034] Among them, the The length of each data block is The length of the last data block is This means that the code should not exceed the preset block length. Through the above block processing, the task of copying and verifying large-scale code can be decomposed into multiple small-scale subtasks, reducing the complexity and risk of a single operation.
[0035] Operation 103 involves copying each data block from its corresponding load address to its corresponding execution address, performing a first verification on each data block before the copying begins, and a second verification on each data block after the copying begins, and determining the copy verification result of each data block based on the results of the first and second verifications.
[0036] After partitioning the data into blocks and determining the load and execution addresses of each block, copy and verification operations are performed on each block sequentially according to their order. The verification operation includes a first verification and a second verification. The first verification, also known as pre-verification, is performed before copying begins by reading data from the load address; the second verification, also known as post-verification, is performed after copying is complete by reading data from the execution address. Specifically, the block-by-block processing flow is as follows: First, before copying each data block begins, all data of that data block is read from its load address. A verification algorithm is used to calculate the first verification result, which is then used as the baseline verification value. This step verifies the integrity of the original data in the load address, confirming that the source data to be copied has not been corrupted before copying.
[0037] The data block is then copied from the load address to the corresponding execution address. This copying can be performed via a Direct Memory Access (DMA) controller or the central processing unit.
[0038] Then, after the data block is copied, all the copied data is read from the running address of the data block, and the second verification result is recalculated using the same verification algorithm. This step is used to verify whether the copied data is consistent with the original data before copying, that is, to confirm that no errors were introduced during the copying process.
[0039] Finally, the first verification result is compared with the second verification result. If they match, the copy verification result of the data block is successful; if they do not match, the copy verification result of the data block is incorrect, and it needs to be copied again. After all data blocks have been processed, proceed to operation 104.
[0040] In one embodiment of this application, the verification algorithm includes, but is not limited to, CRC algorithm, parity check, checksum, hash algorithm, etc. The verification result can be regarded as the verification value calculated by the verification algorithm for each piece of read data.
[0041] For example, suppose the code to be copied is divided into... The data block, for the first... Data blocks ( Starting from 0), its loading address is The running address is , length is Before copying begins, from Read the data and calculate the first verification result. Then the data block is from Copy to After copying, from Read the data and calculate the second verification result. Finally, and If the data block copy verification is successful, the data block copy verification is successful; otherwise, the data block copy verification fails.
[0042] Operation 104: Determine the verification result of the code to be copied based on the copy verification results of all data blocks.
[0043] The copy verification results of all data blocks are summarized. If the copy verification results of all data blocks or data blocks meeting the preset ratio requirement are successful, the code to be copied is determined to have been copied successfully, indicating that the code has been completely and correctly moved to the runtime address and can be executed safely. If the number or ratio of data blocks with successful copy verification results does not meet the preset ratio requirement, the code to be copied is determined to have failed to copy. By comprehensively judging the verification results of all data blocks, the reliability of the entire code copying process can be evaluated, providing a clear basis for integrity for subsequent system startup or program execution.
[0044] Thus, this embodiment verifies the integrity of the original data at the load address by performing a first check before each data block copy begins, solving the problem of source data corruption not being detected in time. A second check is performed after copying, and the result is compared with the first check result to confirm whether errors were introduced during the copying process from the load address to the runtime address. Combined with block processing, errors can be precisely located to specific data blocks, solving the problem of difficulty in distinguishing errors at the error occurrence stage. Therefore, this application implements dual verification before and after code copying, eliminating the need to wait for the program to reach the erroneous code segment before exposing exceptions. Data anomalies can be proactively and in real-time detected and located during the copying stage, effectively improving the reliability of code loading and the success rate of system startup.
[0045] In one embodiment of this application, the above operation 102, obtaining the preset block length of the code to be copied, includes: dividing the code to be copied into a high-risk region and a low-risk region, wherein the high-risk region includes the code region where the interrupt vector table and / or the entry point of the key function are located; determining the preset block length corresponding to the high-risk region as a first preset length and determining the preset block length of the low-risk region as a second preset block length; wherein the first preset block length is less than the second preset block length.
[0046] The preset block length can be dynamically adjusted based on the risk level of the code region. Specifically, the code to be copied can be divided into high-risk and low-risk regions. High-risk regions may include the code regions containing the interrupt vector table and critical function entry points. The interrupt vector table is the core entry point for the system to respond to interrupts and exceptions, and its contents determine the target address of the program's jump after an interrupt occurs. If the data in this region is corrupted during the copying process, the system will crash directly upon the first interrupt trigger, and the error will be difficult to locate. Critical function entry points (such as the reset entry point and the main function entry point) are also essential paths for system startup and operation, and their integrity directly affects whether the system can start normally. Therefore, classifying these two types of code regions as high-risk regions can improve the accuracy of verification in a targeted manner. Low-risk regions include relatively minor code regions such as the initialization data segment.
[0047] For high-risk areas, a smaller first preset block length, such as 128 bytes, can be used to pinpoint the error location within a smaller area when an error occurs in that area. For low-risk areas (such as the initialization data segment), a larger second preset block length, such as 2 kilobytes, can be used to reduce the number of checks while maintaining basic verification capabilities, thus reducing CPU resource consumption.
[0048] By dynamically adjusting the block length as described above, a balance is achieved between verification accuracy and system overhead, resulting in finer verification granularity and higher positioning accuracy in high-risk areas, and lower verification overhead in low-risk areas.
[0049] It is understood that the above-described division of high-risk and low-risk areas is merely illustrative. Those skilled in the art can set more risk levels (such as medium-risk areas) and configure corresponding preset block lengths for different risk levels based on actual application scenarios and system reliability requirements. Furthermore, the adjustment of the preset block length is not limited to the risk level of the code area; it can also be dynamically adjusted based on other dimensions such as the physical page size of the storage medium, the running frequency of data blocks, or historical error rates. All of these fall within the scope of protection of this application.
[0050] In one embodiment of this application, the determination of the preset block size is also related to the physical page size of the non-volatile storage medium (such as Flash) where the code to be copied is located.
[0051] During system initialization, the configuration parameters of the storage medium can be read first to obtain its physical page size information. Then, based on the obtained physical page size, the preset block size is dynamically set. For example, the preset block size can be set to an integer multiple of the physical page size, aligning the boundary of each data block with the boundary of one or more physical pages. For example, if the physical page size is 2KB, the preset block size can be set to 2KB or 4KB. If the physical page size is 512 bytes, the preset block size can be set to 512 bytes or 1KB. Optionally, the preset block size can be determined and fixed once at system startup until the next system restart; or it can be recalculated based on the current hardware configuration before each copy task begins. This application does not specifically limit this.
[0052] In this way, when reading a data block from the storage medium for the first check or retransmission, each read operation at the hardware level can completely cover one or more physical pages, avoiding cross-page reads or redundant reads caused by misalignment between block size and page size, thereby improving data read efficiency and DMA transfer efficiency.
[0053] Figure 2 The diagram illustrates the implementation flow of the verification operation of the verification method provided in the embodiments of this application.
[0054] refer to Figure 2 In one embodiment of this application, in operation 103, copying each data block from its corresponding load address to its corresponding execution address includes: copying each data block from its corresponding load address to its corresponding execution address via a direct memory access controller or a central processing unit. Accordingly, in operation 103 above, a second verification is performed on each data block after copying, including: Operation 201: When each data block is copied from the corresponding load address to the corresponding runtime address by the central processing unit, after the memory copy function returns, a cache clearing operation or a cache invalidation operation is performed, and the copied data is read from the corresponding runtime address for a second verification; or, the copied data is directly read from the physical memory corresponding to the runtime address and a second verification is performed. Operation 202: When each data block is copied from the corresponding load address to the corresponding runtime address through the direct memory access controller, after the direct memory access controller triggers a transfer completion interrupt, the copied data is read from the corresponding runtime address and a second verification is performed.
[0055] Copying can be performed via a DMA controller or the CPU. Using a DMA controller is preferred to minimize CPU intervention, freeing the CPU from data transfer tasks and allowing it to handle other computational tasks simultaneously. If the system lacks a DMA controller (e.g., a small-capacity microcontroller unit, MCU), the CPU is used to perform the copy, i.e., a second check is performed immediately after each memory copy function (such as memcpy) call.
[0056] When the CPU copies each data block from its corresponding load address to its corresponding execution address, after the memory copy function returns, a cache clean or cache invalidate operation needs to be performed before reading the copied data from the corresponding execution address for a second verification. This is because if data is read directly from the execution address, the CPU cache may still contain old data from before the copy, leading to inaccurate verification results as the data read might be stale data from the cache instead of the new data actually stored in physical memory. The cache clean operation writes modified data from the cache back to physical memory, ensuring that the data in physical memory is up-to-date; the cache invalidate operation invalidates stale data in the cache, allowing subsequent read operations to retrieve data directly from physical memory.
[0057] Another approach is to read the copied data directly from the physical memory corresponding to the runtime address, bypassing the CPU cache. This method can directly access the actual data in physical memory, avoiding cache consistency issues, but the read speed is relatively slow.
[0058] When each data block is copied from its corresponding load address to its corresponding run address via the DMA controller, a second verification is performed by reading the copied data from the run address after the DMA controller triggers a Transfer Complete Interrupt. The DMA controller's Transfer Complete Interrupt is a hardware notification signal sent to the CPU after completing the data transfer task. Upon receiving this interrupt, the CPU confirms that the copy operation is complete before reading data from the run address for verification. Triggering the second verification within the interrupt callback function ensures that the verification operation is executed immediately after the copy is complete, preventing subsequent operations from overwriting the copied data due to delays. Optionally, a cache invalidation operation can be performed before executing the second verification, invalidating the old data at that address in the CPU cache, thereby ensuring that the CPU reads the latest data written by the DMA from physical memory.
[0059] In one embodiment of this application, in operation 103 above, a first verification is performed on each data block before the copying of each data block begins, including: reading all the data of the data block from the load address corresponding to the data block; calculating a first verification value based on all the read data using a verification algorithm, and using the first verification value as the first verification result.
[0060] Before each data block copy begins, all data for that data block is read from its corresponding load address. Then, based on the read data, a verification algorithm is used to calculate a first checksum, which is then used as the first verification result. This first verification result serves as the benchmark for subsequent comparison with the second verification result.
[0061] In one embodiment of this application, the first check value is also compared with a preset standard check value; if the first check value is inconsistent with the preset standard check value, it is determined that the original data of the data block in the starting loading address is corrupted, the copying is terminated and an error code is reported; if the first check value is consistent with the preset standard check value, the first check value is used as the first check result.
[0062] The first check is a pre-check operation performed before each data block copy begins. Its purpose is to verify the integrity of the original data in the load address. The check value generated by this check process (i.e., the first check value) needs to be compared with a preset standard check value. The preset standard check value can be understood as a check value pre-calculated and stored during the compilation, burning, or building phase, serving as the integrity benchmark for the data block in its initial state.
[0063] If the first checksum does not match the preset standard checksum, the original data in the starting load address of the data block is determined to be corrupted. This corruption may stem from physical wear and tear of the storage medium (such as bit flips caused by Flash erase / write wear), abnormalities during the storage process (such as data write errors caused by unstable programming voltage), environmental factors (such as changes in the state of the storage cell caused by electromagnetic interference), or defects in the storage medium itself (such as bad blocks). In this case, since the source data itself is corrupted, the copy operation cannot obtain correct data, and continuing to copy will only write erroneous data to the running address. Therefore, the copy is terminated and an error code is reported. If the first checksum matches the preset standard checksum, it indicates that the original data in the load address of the data block is intact, and the first checksum is saved as the first checksum result of the data block.
[0064] In this way, the pre-verification mechanism enables the system to accurately locate the stage at which the error occurs, avoiding invalid copying and system startup failure caused by corrupted source data.
[0065] In one embodiment of this application, in the above operation 103, a second verification is performed on each data block after copying, including: reading all the copied data from the running address corresponding to the data block; calculating a second verification value based on the read data using a verification algorithm; and using the second verification value as the second verification result.
[0066] The second verification is executed in a similar manner to the first verification, except that the source of the data is different. Specifically, after copying the data block from the load address to the corresponding runtime address, all the copied data is read from the runtime address corresponding to the data block. Then, based on all the copied data read, the same verification algorithm is used to calculate the second verification value, and this second verification value is used as the second verification result.
[0067] Thus, through the above method, the first check verifies the original data in the loading address and establishes a baseline value, and the second check verifies the copied data in the running address and compares it with the baseline value. The two checks together constitute a dual verification mechanism of "pre-copy verification + post-copy verification".
[0068] In one embodiment of this application, the verification algorithm includes the CRC32 verification algorithm, which is executed by a lookup table method or hardware acceleration instructions.
[0069] The verification algorithms used for the first and second verifications mentioned above can be the CRC32 verification algorithm, or other types of verification algorithms; this application does not specifically limit this. Optionally, the verification algorithm can be executed through hardware acceleration instructions or through a software look-up table method. The specific implementation method can be flexibly selected according to the hardware resources of the embedded system. Among them, this application preferentially uses the CRC32 verification algorithm, which is a verification algorithm based on polynomial division. Its basic principle is: the data block to be verified is regarded as a large binary number, divided by a preset generator polynomial (such as the standard CRC32 generator polynomial), and the 32-bit remainder is the verification value. The CRC32 algorithm can detect more than 99.998% of single-bit and multi-bit errors, and has low computational overhead, making it suitable for real-time verification of code copying in embedded systems.
[0070] The CRC32 checksum algorithm can be implemented in the following two ways: The look-up table method pre-calculates the CRC32 checksums for all possible single-byte inputs (256 in total), constructing a lookup table with 256 entries, each containing a 32-bit checksum. During actual verification, data is read byte by byte, and the checksum is updated by looking up the table based on the current CRC state, thus avoiding bit-by-bit polynomial division operations. The look-up table method transforms bit-by-bit iteration into byte-by-byte table lookup operations, significantly reducing the computational overhead of the central processing unit (CPU) and requiring only 1KB of memory, making it suitable for resource-constrained environments in embedded systems.
[0071] Hardware Accelerated Instructions: Modern processor architectures incorporate dedicated instructions for accelerating CRC checksum calculations, enabling the computation of multiple bytes within a single cycle. When using hardware-accelerated instructions for CRC32 checksums, the processor's internal dedicated computation unit directly performs polynomial division operations, eliminating the need for software bit-by-bit or byte-by-byte processing. This can improve checksum speed by 2 to 3 times compared to the lookup table method. This approach is suitable for processor platforms that support CRC hardware-accelerated instructions.
[0072] During the pre-checking of a data block, a 32-bit checksum is calculated using the CRC32 engine. Regardless of whether a lookup table method or hardware acceleration instructions are used, the final checksum is a 32-bit (4-byte) value. This checksum can be stored in a register or a dedicated checksum buffer to avoid consuming general-purpose memory.
[0073] In one embodiment of this application, in operation 103, determining the copy verification result of each data block based on the first verification result and the second verification result includes: if the first verification result is consistent with the second verification result, the copy verification result of the data block is determined to be successful; if the first verification result is inconsistent with the second verification result, the copy verification result of the data block is determined to be incorrect, and a retransmission operation of the data block is triggered. The retransmission operation includes: recopying the data block from the corresponding load address to the corresponding runtime address; reading the copied data from the corresponding runtime address and performing the second verification again; comparing the new second verification result with the first verification result; if the comparison is consistent, the copy verification result of the data block is determined to be successful; if the comparison is inconsistent and the cumulative retransmission count has not reached the preset maximum retry count, the retransmission operation continues.
[0074] If the first and second verification results match, it indicates that the copying process of the data block from the load address to the runtime address did not introduce any errors, and data integrity is maintained. The data block is then marked as successful, and its copy verification result is confirmed as successful. If the two results do not match, it indicates that the data has changed during the copying process. The data block is then marked as an error block, and its copy verification result is confirmed as incorrect. To distinguish between random errors and hardware failures, a retransmission is triggered immediately after the first verification failure, and the copying and verification process for the data block is re-executed.
[0075] The retransmission operation includes: copying the data block from the corresponding load address to the corresponding run address; reading the copied data from the corresponding run address and performing a second verification; comparing the new second verification result with the first verification result; if the comparison is consistent, the data block copy verification result is determined to be a successful copy; if the comparison is inconsistent and the cumulative number of retransmissions has not reached the preset maximum number of retries (e.g., 3 times), the retransmission operation continues.
[0076] This retransmission mechanism only retransmits erroneous blocks that fail verification, improving efficiency by more than 70% compared to traditional full retransmission. Furthermore, by limiting the maximum number of retries, it avoids the impact of invalid retries on hardware lifespan. If the verification still fails after the cumulative number of retransmissions reaches the preset maximum number of retries, the data block is marked as a "permanent error block," confirming that its copy verification result is a permanent error.
[0077] Figure 3 The diagram illustrates the implementation flow of the algorithm switching operation of the verification method provided in this application embodiment.
[0078] refer to Figure 3 In one embodiment of this application, a verification algorithm switching mechanism is also designed, specifically including: Operation 301: If the new second verification result obtained after the retransmission operation is still inconsistent with the first verification result, then the current verification algorithm will be switched to the backup verification algorithm. The retransmission operation in this application adopts a dynamic retransmission control strategy, triggering a retransmission operation for the data block immediately after the first verification fails. If the... Second-rate( If, after retransmission, the new second verification result still does not match the first verification result, it indicates that the copy error of the data block may not be caused by sporadic factors (such as instantaneous bit flips caused by electromagnetic pulses), but rather by persistent transmission link anomalies or storage media problems. In this case, continuing to use the same verification algorithm for retransmission will make it difficult to eliminate the aforementioned sporadic interference and will also fail to effectively distinguish between "random errors" and "systematic errors." Therefore, this application introduces a verification algorithm switching mechanism to switch the current verification algorithm to a backup verification algorithm. When different algorithms are used to verify the same data block, if the backup algorithm passes the verification while the current algorithm fails, it indicates that the error may be caused by a specific error mode not covered by the current verification algorithm, rather than data corruption itself.
[0079] Operation 302: Re-execute the second verification on the data block using the backup verification algorithm, and compare the second verification result after switching algorithms with the first verification result; if the comparison is consistent, the copy verification result of the data block is determined to be successful; if the comparison is still inconsistent, continue to execute the retransmission operation.
[0080] The backup verification algorithm is used to re-perform the second verification on the data block, and the result of the second verification after switching algorithms is compared with the result of the first verification. If they match, the copy verification result of the data block is determined to be successful; if they still do not match, the retransmission operation continues.
[0081] Operation 303: If the cumulative number of retransmissions has reached the preset maximum number of retransmissions, the copy verification result of the data block is determined to be a permanent error.
[0082] Among them, the generator polynomial of the backup check algorithm is different from that of the current check algorithm, and the Hamming distance of the backup check algorithm is greater than that of the current check algorithm; the backup check algorithm includes the enhanced CRC32 check algorithm, which is executed by table lookup or hardware acceleration instructions.
[0083] If the cumulative number of retransmissions has reached the preset maximum number of retransmissions (e.g., 3 times), the copy verification result of the data block is determined to be a permanent error, and the data block is marked as a permanent error block.
[0084] In this embodiment of the application, the backup verification algorithm is designed with a different generator polynomial than the current verification algorithm, and the Hamming distance of the backup verification algorithm is greater than that of the current verification algorithm. Hamming distance is an important indicator of the error detection capability of a verification algorithm; the larger the Hamming distance, the more error patterns the algorithm can detect, and the stronger its error detection capability. For example, the standard CRC32 generator polynomial is... An alternative algorithm could be an enhanced CRC32 (such as CRC32-C, with a generator polynomial of...). The enhanced CRC32 checksum algorithm has a different generator polynomial and a larger Hamming distance. In engineering implementation, the enhanced CRC32 checksum algorithm can also be executed efficiently through table lookup or hardware acceleration instructions to ensure that the system's real-time requirements are still met after the algorithm switch.
[0085] In one embodiment of this application, the number of data blocks whose copy verification results are determined to be permanent errors is also counted. If the proportion of the number of data blocks with permanent errors to the total number of data blocks exceeds a preset threshold, it is determined that there is a hardware failure in the storage medium where the starting load address is located, the copying is terminated and an error code is reported.
[0086] In one embodiment of this application, if the copy verification results of a preset number of data blocks are all determined to be permanently failed, it is determined that there is a hardware fault in the storage medium where the starting loading address of the code to be copied is located, the copying is terminated and an error code is reported.
[0087] The copy verification results of all data blocks are statistically analyzed. If the percentage of permanently corrupted blocks exceeds a preset threshold (e.g., 5%), or if errors repeatedly occur in the same physical memory area (e.g., three consecutive data blocks), it is determined that there is a hardware fault in the storage medium where the load address is located, such as bad blocks in Flash or bit flipping in RAM. The copying process is terminated and an alarm is triggered, such as lighting up an LED or writing to the error log. Simultaneously, error codes are reported. These error codes are predefined numerical codes used to identify different error types, such as 0x01 indicating corrupted source data, 0x02 indicating copying verification failure, 0x03 indicating excessive retransmissions, and 0x04 indicating storage medium hardware failure.
[0088] In one embodiment of this application, the above operation 104, which determines the verification result of the code to be copied based on the copy verification results of all data blocks, includes: counting the number of data blocks whose copy verification results are determined to be successfully copied; if the proportion of the number of successfully copied data blocks to all data blocks exceeds a target threshold, then the verification result of the code to be copied is determined to be successfully copied; if the proportion of the number of successfully copied data blocks to all data blocks does not exceed the target threshold, then the verification result of the code to be copied is determined to be a copy failure.
[0089] After the copy verification process for all data blocks is completed, the number of data blocks whose copy verification result is successful is counted. If the proportion of successfully copied data blocks to all data blocks exceeds the target threshold (e.g., 95%), the final verification result of the code to be copied is determined to be a successful copy; if the proportion of successfully copied data blocks to all data blocks does not exceed the target threshold (i.e., the proportion of erroneous blocks exceeds 5%), the verification result of the code to be copied is determined to be a failed copy.
[0090] To further illustrate the technical solution of this application, a specific application example is provided below. In this specific application example, a verification method, also known as the CRC32 double verification and dynamic retransmission method for embedded system code copying, is executed by the embedded system and specifically includes the following steps: ① Enter the code to be copied (starting load address) Code length Set the default block size. (For example, 512 bytes, which can be dynamically adjusted based on memory page size or error risk). ②According Divide the code into One data block, , for the Data blocks ( Starting from 0, the initial load address is Perform the first check (CRC32 pre-check) to generate a baseline check value. And temporarily store; ③The first A data block from the load address Copy to runtime address ; ④ From the running address Read the first For each data block that has been copied, perform a second check (CRC32 post-check) and calculate the check value. ,and Comparison; ⑤ Based on the comparison results, if Mark the first If the data block is successfully copied, proceed to process the next data block; otherwise, mark the data block as an "error block" and trigger a retransmission operation (maximum retries). (e.g., 3 times) ⑥ After all data blocks have been processed, if the percentage of erroneous blocks is less than or equal to the threshold (e.g., 5%), output "Copy successful"; otherwise, it is determined to be a systemic error (e.g., a memory failure at the loading address), the process is terminated and an error code is reported.
[0091] Thus, this specific application example achieves the following technical effects: Pre-copying intercepts corrupted source address data (e.g., flash memory bit flips), and post-copy block-level verification detects transmission errors in real time (e.g., instantaneous bit flips in the direct memory access controller). Dual verification covers the entire process, effectively preventing system crashes due to hidden copy errors. Block-based verification (e.g., 512 bytes / block) controls error location accuracy within the data block size range. Combined with a dynamic retransmission strategy (retransmitting only erroneous blocks, with a maximum of 3 retries), efficiency is improved by over 70% compared to traditional full retransmission, reducing system startup time and avoiding the impact of invalid retries on hardware lifespan. Furthermore, through dynamic block size adjustment (reducing data block granularity in high-risk areas), verification algorithm switching (switching to a backup verification algorithm after multiple failures), and systematic error detection (terminating when erroneous blocks exceed a threshold), complex scenarios such as electromagnetic interference and power fluctuations can be addressed, effectively distinguishing between random errors and hardware failures, avoiding invalid operations, and enhancing system autonomy.
[0092] In summary, this specific application example, through the collaborative design of CRC32 block dual verification and dynamic retransmission, realizes real-time error detection and autonomous recovery during the code copying process, effectively reducing the startup failure rate caused by copying errors.
[0093] Figure 4 A schematic diagram of the composition structure of the verification device provided in the embodiments of this application is shown.
[0094] refer to Figure 4 This application also provides a verification device, which includes: Module 401 is used to obtain the starting load address, starting execution address, and code length of the code to be copied. The block segmentation module 402 is used to obtain the preset block length of the code to be copied, divide the code to be copied into multiple data blocks in sequence according to the code length and the preset block length, and determine the load address and execution address of each data block. The dual verification module 403 is used to copy each data block from the corresponding load address to the corresponding execution address, and to perform a first verification on each data block before the copying begins and a second verification on each data block after the copying. The copy verification result of each data block is determined based on the first verification result and the second verification result. The determination module 404 is used to determine the verification result of the code to be copied based on the copy verification results of all data blocks.
[0095] In one embodiment of this application, the block module 402 is used for: The code to be copied is divided into high-risk and low-risk areas. The high-risk areas include the code area where the interrupt vector table and / or the entry point of critical functions are located. The preset block length corresponding to the high-risk area is determined as the first preset length, and the preset block length of the low-risk area is determined as the second preset block length; the first preset block length is less than the second preset block length.
[0096] In one embodiment of this application, the dual verification module 403 is used to: copy each data block from its corresponding load address to its corresponding execution address via a direct memory access controller or a central processing unit; correspondingly, the dual verification module 403 is also used to: When each data block is copied from the corresponding load address to the corresponding runtime address by the central processing unit, after the memory copy function returns, a cache clearing operation or a cache invalidation operation is performed, and the copied data is read from the corresponding runtime address for a second verification; or, the copied data is directly read from the physical memory corresponding to the runtime address and a second verification is performed. When each data block is copied from its corresponding load address to its corresponding runtime address via the direct memory access controller, after the direct memory access controller triggers a transfer completion interrupt, the copied data is read from the corresponding runtime address and a second verification is performed.
[0097] In one embodiment of this application, the dual verification module 403 is further configured to: Read all the data of the data block from the load address corresponding to the data block; Based on all the data read, a verification algorithm is used to calculate the first verification value, which is then used as the first verification result.
[0098] In one embodiment of this application, the device is further configured to: The first check value is compared with the preset standard check value; If the first check value is inconsistent with the preset standard check value, it is determined that the original data of the data block in the starting load address is corrupted, the copying is terminated and an error code is reported. If the first check value matches the preset standard check value, then the first check value is taken as the first check result.
[0099] In one embodiment of this application, the dual verification module 403 is further configured to: Read all copied data from the runtime address corresponding to the data block; Based on all the data read, a second verification value is calculated using a verification algorithm, and the second verification value is used as the second verification result.
[0100] In one embodiment of this application, the dual verification module 403 is further configured to: If the first verification result is consistent with the second verification result, then the copy verification result of the data block is determined to be a successful copy. If the first verification result is inconsistent with the second verification result, the copy verification result of the data block is determined to be incorrect, and the retransmission operation of the data block is triggered. The retransmission operation includes: copying the data block from the corresponding load address to the corresponding run address; reading the copied data from the corresponding run address and performing a second verification; comparing the new second verification result with the first verification result; if the comparison is consistent, the data block copy verification result is determined to be a successful copy; if the comparison is inconsistent and the cumulative number of retransmissions has not reached the preset maximum number of retries, the retransmission operation continues.
[0101] In one embodiment of this application, the device is further configured to: If the new second verification result obtained after the retransmission operation still does not match the first verification result, the current verification algorithm will be switched to the backup verification algorithm. The backup verification algorithm is used to re-perform the second verification on the data block, and the result of the second verification after switching algorithms is compared with the result of the first verification. If the comparison is consistent, the copy verification result of the data block is determined to be successful. If the comparison is still inconsistent, the retransmission operation is continued. If the cumulative number of retransmissions has reached the preset maximum number of retransmissions, the copy verification result of the data block is determined to be a permanent error. Among them, the generator polynomial of the backup check algorithm is different from that of the current check algorithm, and the Hamming distance of the backup check algorithm is greater than that of the current check algorithm; the backup check algorithm includes the enhanced CRC32 check algorithm, which is executed by table lookup or hardware acceleration instructions.
[0102] In one embodiment of this application, the device is further configured to: Count the number of data blocks whose copy verification results are determined to be permanent errors across all data blocks; If the number of data blocks with permanent errors exceeds a preset threshold, it is determined that there is a hardware failure in the storage medium where the starting load address is located, the copying is terminated and an error code is reported.
[0103] In one embodiment of this application, the device is further configured to: If the copy verification results of a preset number of data blocks are all determined to be permanent failures, it is determined that there is a hardware fault in the storage medium where the starting load address of the code to be copied is located, the copying is terminated and an error code is reported.
[0104] In one embodiment of this application, the determining module 404 is used for: Count the number of data blocks whose copy verification results are determined to be successfully copied; If the proportion of successfully copied data blocks to all data blocks exceeds the target threshold, then the verification result of the code to be copied is determined to be successfully copied. If the proportion of successfully copied data blocks to all data blocks does not exceed the target threshold, then the verification result of the code to be copied is determined to be a copy failure.
[0105] It should be noted that the description of the apparatus in this application embodiment is similar to the description of the method embodiment above, and has similar beneficial effects as the method embodiment; therefore, it will not be repeated. For any technical details not covered in the verification apparatus provided in this application embodiment, please refer to... Figures 1 to 3 The meaning is understood in accordance with the description of any of the accompanying drawings.
[0106] According to embodiments of this application, this application also provides an electronic device and a readable storage medium.
[0107] Figure 5 A schematic block diagram of an example electronic device 500 that can be used to implement embodiments of this application is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the application described and / or claimed herein.
[0108] like Figure 5 As shown, the electronic device 500 includes a computing unit 501, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 502 or a computer program loaded from a storage unit 508 into a random access memory (RAM) 503. The RAM 503 may also store various programs and data required for the operation of the electronic device 500. The computing unit 501, ROM 502, and RAM 503 are interconnected via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0109] Multiple components in electronic device 500 are connected to I / O interface 505, including: input unit 506, such as keyboard, mouse, etc.; output unit 507, such as various types of monitors, speakers, etc.; storage unit 508, such as disk, optical disk, etc.; and communication unit 509, such as network card, modem, wireless transceiver, etc. Communication unit 509 allows electronic device 500 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0110] The computing unit 501 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 501 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 501 performs the various methods and processes described above, such as verification methods. For example, in some embodiments, the verification method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 508. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 500 via ROM 502 and / or communication unit 509. When the computer program is loaded into RAM 503 and executed by the computing unit 501, one or more steps of the verification method described above may be performed. Alternatively, in other embodiments, the computing unit 501 may be configured to perform verification methods by any other suitable means (e.g., by means of firmware).
[0111] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), system-on-a-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transferring data and instructions to the storage system, the at least one input device, and the at least one output device.
[0112] The program code used to implement the methods of this application may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing device, such that when executed by the processor or controller, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0113] In the context of this application, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0114] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0115] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.
[0116] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other. Servers can be cloud servers, servers in distributed systems, or servers incorporating blockchain technology.
[0117] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this application can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this application can be achieved, and this is not limited herein.
[0118] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "a plurality of" means two or more, unless otherwise explicitly specified.
[0119] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A verification method, characterized in that, The method includes: Obtain the starting load address, starting execution address, and code length of the code to be copied; Obtain the preset block length of the code to be copied, divide the code to be copied into multiple data blocks in sequence according to the code length and the preset block length, and determine the load address and execution address of each data block; Each data block is copied from its corresponding load address to its corresponding execution address. Before each data block copying begins, a first verification is performed on each data block, and after the copying begins, a second verification is performed on each data block. The copy verification result of each data block is determined based on the results of the first and second verifications. Based on the copy verification results of all data blocks, determine the verification result of the code to be copied.
2. The method according to claim 1, characterized in that, The step of obtaining the preset block length of the code to be copied includes: The code to be copied is divided into high-risk areas and low-risk areas. The high-risk areas include the code area where the interrupt vector table and / or the entry point of the key function are located. The preset block length corresponding to the high-risk area is determined as a first preset length, and the preset block length of the low-risk area is determined as a second preset block length; the first preset block length is less than the second preset block length.
3. The method according to claim 1, characterized in that, The step of copying each data block from its corresponding load address to its corresponding execution address includes: copying each data block from its corresponding load address to its corresponding execution address via a direct memory access controller or a central processing unit; correspondingly, The second verification of each data block after copying includes: When the central processing unit copies each data block from the corresponding load address to the corresponding runtime address, after the memory copy function returns, a cache clearing operation or a cache invalidation operation is performed, and the copied data is read from the corresponding runtime address for a second verification; or, the copied data is directly read from the physical memory corresponding to the runtime address and a second verification is performed. When each data block is copied from the corresponding load address to the corresponding runtime address through the direct memory access controller, after the direct memory access controller triggers a transmission completion interrupt, the copied data is read from the corresponding runtime address and a second verification is performed.
4. The method according to claim 1, characterized in that, The first verification of each data block before the copying of each data block begins includes: Read all the data of the data block from the load address corresponding to the data block; Based on all the data read, a first verification value is calculated using a verification algorithm, and the first verification value is used as the first verification result.
5. The method according to claim 4, characterized in that, The method further includes: The first verification value is compared with the preset standard verification value; If the first check value is inconsistent with the preset standard check value, it is determined that the original data of the data block in the starting loading address is corrupted, the copying is terminated and an error code is reported. If the first verification value is consistent with the preset standard verification value, then the first verification value is taken as the first verification result.
6. The method according to claim 1, characterized in that, The second verification of each data block after copying includes: Read all copied data from the running address corresponding to the data block; Based on all the data read, a second verification value is calculated using a verification algorithm, and the second verification value is used as the second verification result.
7. The method according to claim 4 or 6, characterized in that, The verification algorithm includes the CRC32 verification algorithm, which is executed by a lookup table method or hardware acceleration instructions.
8. The method according to claim 1, characterized in that, The step of determining the copy verification result of each data block based on the first verification result and the second verification result includes: If the first verification result is consistent with the second verification result, then the copy verification result of the data block is determined to be a successful copy. If the first verification result is inconsistent with the second verification result, the copy verification result of the data block is determined to be incorrect, and the retransmission operation of the data block is triggered. The retransmission operation includes: copying the data block from the corresponding load address to the corresponding run address; reading the copied data from the corresponding run address and performing a second verification; comparing the new second verification result with the first verification result; if the comparison is consistent, the copy verification result of the data block is determined to be successful; if the comparison is inconsistent and the cumulative number of retransmissions has not reached the preset maximum number of retries, the retransmission operation continues.
9. The method according to claim 8, characterized in that, The method further includes: If the new second verification result obtained after the retransmission operation is still inconsistent with the first verification result, the current verification algorithm will be switched to the backup verification algorithm. The backup verification algorithm is used to re-perform the second verification on the data block, and the second verification result after switching algorithms is compared with the first verification result; if the comparison is consistent, the copy verification result of the data block is determined to be successful; if the comparison is still inconsistent, the retransmission operation is continued. If the cumulative number of retransmissions has reached the preset maximum number of retransmissions, then the copy verification result of the data block is determined to be a permanent error. The generator polynomial of the backup verification algorithm is different from that of the current verification algorithm, and the Hamming distance of the backup verification algorithm is greater than that of the current verification algorithm; the backup verification algorithm includes an enhanced CRC32 verification algorithm, which is executed by a lookup table method or hardware acceleration instructions.
10. The method according to claim 9, characterized in that, The method further includes: Count the number of data blocks whose copy verification results are determined to be permanent errors across all data blocks; If the number of data blocks with permanent errors exceeds a preset threshold, it is determined that there is a hardware fault in the storage medium where the starting load address is located, the copying is terminated and an error code is reported.
11. The method according to claim 9, characterized in that, The method further includes: If the copy verification results of a preset number of data blocks are all determined to be permanently failed, then it is determined that there is a hardware fault in the storage medium where the starting loading address of the code to be copied is located, the copying is terminated and an error code is reported.
12. The method according to claim 1, characterized in that, The step of determining the verification result of the code to be copied based on the copy verification results of all data blocks includes: Count the number of data blocks whose copy verification results are determined to be successfully copied; If the proportion of successfully copied data blocks to all data blocks exceeds the target threshold, then the verification result of the code to be copied is determined to be successfully copied. If the proportion of successfully copied data blocks to all data blocks does not exceed the target threshold, then the verification result of the code to be copied is determined to be a copy failure.
13. A verification device, characterized in that, The device includes: The acquisition module is used to obtain the starting load address, starting execution address, and code length of the code to be copied; The block segmentation module is used to obtain the preset block length of the code to be copied, divide the code to be copied into multiple data blocks in sequence according to the code length and the preset block length, and determine the load address and execution address of each data block; The dual verification module is used to copy each data block from the corresponding load address to the corresponding execution address, and to perform a first verification on each data block before the copying begins and a second verification on each data block after the copying. The copy verification result of each data block is determined based on the results of the first and second verifications. The determination module is used to determine the verification result of the code to be copied based on the copy verification results of all data blocks.
14. An electronic device, characterized in that, include: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-12.
15. A non-transitory computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-12.
