An Embedded Flash Memory Integrity Protection Method and System Based on General Hardware Collaboration
By using a DMA controller and a hardware verification calculation engine to collaboratively protect the integrity of embedded flash memory, the problem of real-time performance degradation caused by processor involvement in verification is solved. This achieves firmware integrity protection with low storage overhead and continuous monitoring, and is suitable for various hardware platforms.
Patent Information
- Application Number
- CN202611012631.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-08
- Publication Date
- 2026-11-10
AI Technical Summary
Existing technologies require the use of a processor when verifying firmware in embedded systems, which leads to a decrease in real-time system performance and may even cause task timeouts.
An embedded flash memory integrity protection method based on general hardware collaboration is adopted. The flash memory data is transferred to the hardware verification calculation engine for verification calculation through the DMA controller. The processor only participates during initialization and interrupt result processing. Periodic verification is achieved by using the hardware verification calculation engine and timers.
It greatly reduces the impact on real-time system performance, enables continuous monitoring and tamper detection of firmware, has low storage overhead, and is easy to port between different hardware platforms.
Smart Images

Figure CN123069447A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of firmware security technology. Specifically, this invention relates to an embedded flash memory integrity protection method and system based on general hardware collaboration. Background Technology
[0002] Embedded systems, especially in safety-critical fields such as automotive electronics, industrial control, and aerospace, typically store their firmware in non-volatile flash memory. Firmware integrity is the cornerstone of the entire system's secure and reliable operation. However, firmware can face several threats: programming errors (abnormalities during chip programming leading to data errors) and data corruption (bit flips in FLASH memory cells caused by hardware aging, environmental interference such as high-energy particle bombardment, etc.).
[0003] Chinese Patent 102637461A discloses a boot method supporting bad block flash memory scanning. A storage space is allocated on the NAND flash memory for storing firmware. During firmware download, the storage space is first scanned for bad blocks, and the downloaded firmware is stored in the good blocks, with multiple backups stored. The host boots from the connected NAND flash memory. Based on the NAND flash memory scanned during host boot, firmware is searched for in the storage space, and the found firmware undergoes error verification. Firmware that passes error verification is then loaded. If the current firmware fails error verification and cannot be corrected, the next available firmware is searched sequentially. If the search in the storage space overflows, a boot failure handling step is initiated.
[0004] Existing technologies require the use of a processor to verify firmware in flash memory, which consumes the processor's computing power for a long time, leading to a decline in real-time system performance and even causing task timeouts. Summary of the Invention
[0005] The present invention aims to provide an embedded flash memory integrity protection method and system based on general hardware collaboration, so as to achieve the technical objective of verifying firmware in flash memory without consuming processor computing power and improving the real-time performance of the system.
[0006] To achieve the above objectives, the technical solution adopted by the present invention is as follows:
[0007] This invention provides an embedded flash memory integrity protection method based on general hardware collaboration, including an offline preprocessing stage and an online runtime monitoring stage;
[0008] The offline preprocessing stage includes the following steps:
[0009] Step 1: Based on the firmware's logical structure and security level, divide the storage area of the firmware in the flash memory that requires integrity protection into multiple blocks to be protected. Define the starting address, length, and block identifier of each block to be protected through the configuration file; compile and link the firmware to generate a firmware image file.
[0010] Step 2: Read the compiled firmware image file using the verification calculation tool, calculate the verification digest value for the original binary data of each block to be protected in the firmware image file, and generate a block verification information table; each entry in the block verification information table contains the start address, length, block identifier and pre-calculated verification digest value of the corresponding block to be protected;
[0011] Step 3: Write the block verification information table back to the specified area of the flash memory in the firmware image file, and burn it into the flash memory along with the firmware image file;
[0012] The online runtime monitoring phase includes:
[0013] Step 4: After the system powers on and the processor completes its initialization configuration, the data of the block to be protected in the flash memory is transferred to the hardware verification calculation engine through the DMA controller. The hardware verification calculation engine calculates the verification digest value of the current data in real time.
[0014] Step 5: The DMA controller generates an interrupt after each block to be protected is transferred. In the interrupt service routine, it reads the current check digest value output by the hardware check calculation engine and compares it with the corresponding pre-calculated check digest value in the block check information table. If the comparison is inconsistent, a security response is triggered.
[0015] Step Six: Repeat the verification steps in Steps Four and Five at a preset period using a hardware timer to perform polling-style periodic verification on all blocks to be protected.
[0016] In step two, the verification calculation tool uses verification algorithms including CRC32 verification algorithm and SHA-256 verification algorithm.
[0017] In step two, the verification method of the verification calculation tool includes: parsing the configuration file, extracting the number of blocks to be protected, the address range of each block to be protected, and the corresponding algorithm configuration; loading the firmware image file into memory; performing data integrity verification on each block to be protected, extracting the original binary data after confirming that there are no data holes, calculating the verification digest value of each block to be protected according to the configured verification algorithm, and writing it into the corresponding position of the block verification information table in the firmware image file; and saving the updated firmware image file.
[0018] In step three, the block check information table is located to a fixed address in the flash memory address space according to the linker's segment placement rules, and is accessed at runtime as a read-only constant array.
[0019] In step four, the processor completes the following initialization configuration steps:
[0020] The source address of the DMA channel is configured to be the starting address of the first block to be protected in the flash memory, the transfer length is the data length of the block to be protected, the destination address is the data input register of the hardware verification calculation engine, and the transfer mode is chain transfer;
[0021] The algorithm parameters configured for the hardware verification calculation engine to verify the protection block are consistent with the algorithm parameters used by the verification calculation tool when verifying the protection block in the offline preprocessing stage;
[0022] Configure the timing period of the hardware timer;
[0023] Create a DMA transfer descriptor for each block to be protected. Each descriptor contains a source address, transfer length, and a link pointer to the next descriptor. The link pointer of the DMA transfer descriptor of the block at the end of the queue points to the block at the head of the queue.
[0024] Step six, the periodic verification steps include:
[0025] When the hardware timer reaches the preset period, it outputs a trigger signal. The DMA controller reads the data of the current block to be protected from the flash memory and sends it to the hardware verification calculation engine.
[0026] The hardware verification calculation engine performs verification calculations on the received data and outputs the current verification digest value.
[0027] After each block to be protected completes data transmission, an interrupt is triggered. The processor reads and compares the check digest value output by the current check calculation engine with the pre-calculated check digest value of the block to be protected in the block check information table through a comparator. If the comparison results are consistent, the check passes, the DMA controller loads the next block to be protected, and starts the check process for the next block to be protected.
[0028] Once all blocks to be protected have completed one round of verification, the DMA controller automatically switches to the block to be protected at the head of the circular queue through a circular queue to start the next round of verification. This process is continuously repeated during system operation.
[0029] In step five, the security response includes at least one of the following operations: generating a security alarm signal; writing fault information into a fault register, the fault information including the block identifier and address information of the tampered block to be protected; and triggering a system reset.
[0030] It also includes a method for adjusting the online monitoring time for each round: by adjusting the preset period of the hardware timer and the size of the block to be protected, the total duration of a full-coverage online monitoring round can be configured.
[0031] This invention provides a system for applying an embedded flash memory integrity protection method based on general hardware collaboration, deployed on a system-on-a-chip, including a processor, a DMA controller, a hardware verification calculation engine, a hardware timer, and a comparator;
[0032] The processor is used for initialization configuration;
[0033] The DMA controller is used to receive the trigger signal, output the data of the block to be protected in the flash memory to the hardware verification calculation engine;
[0034] The hardware verification calculation engine is used to perform real-time calculations on the received block data to be protected and output the current verification digest value to the comparator.
[0035] The hardware timer is used to output a trigger signal according to a preset period to trigger the DMA controller to start the data transmission process.
[0036] The comparator is used to compare the current check digest value with the pre-calculated check digest value of the corresponding block to be protected in the block check information table after the DMA controller has completed the transfer; and to trigger a security response when the comparison results are inconsistent.
[0037] The processor, DMA controller, hardware verification calculation engine, hardware timer, and comparator are interconnected via a bus, and the flash memory is connected to the on-chip system via the bus.
[0038] The technical effects of this invention are as follows:
[0039] (1) The verification data stream of the present invention does not require processor computation. It utilizes the DMA controller to autonomously transport flash memory data to the hardware verification calculation engine for verification calculation. The processor only participates during the initialization configuration and interrupt result processing. The core processes of data transport and verification calculation do not occupy processor computing resources at all. Compared with the existing technology where the processor needs to read data byte by byte and perform software verification calculations, the present invention greatly reduces the impact on the real-time performance of the system.
[0040] (2) This invention does not require an encryption engine or key management. It uses a hardware verification calculation engine to calculate the verification digest value and does not require the maintenance of encryption keys. Due to the non-volatility of flash memory and the physical write protection mechanism, attackers cannot simultaneously modify the flash memory content and the corresponding verification value without damaging the physical package. Therefore, the verification digest value is sufficient to detect tampering.
[0041] (3) This invention pre-calculates and stores the benchmark value offline. Utilizing the non-volatile nature of flash memory, the verification digest values of all blocks to be protected are pre-calculated using PC-side tools during the compilation phase, and the results are stored in a designated read-only area of the flash memory. Compared with existing technologies that dynamically calculate benchmark values at runtime, this solution eliminates the runtime overhead of benchmark value calculation.
[0042] (4) The storage overhead of the present invention is extremely low, occupying only a small read-only area in the flash memory for the verification information table, without requiring RAM resources. Compared with the existing technology where hash trees occupy about 25% of memory space, the storage overhead of the present invention is negligible.
[0043] (5) This invention provides continuous protection during flash memory operation. Periodic scanning enables continuous monitoring of the firmware. Compared to schemes that perform verification only once at startup, this invention can detect tampering throughout the entire lifecycle of the system.
[0044] (6) This invention does not rely on dedicated security IP. It utilizes the on-chip system's common DMA controller, hardware verification calculation engine, and timer, which are standard peripherals of most SoC / MCU platforms and are easy to port between different hardware platforms.
[0045] (7) The present invention has the advantages of being flexible and configurable, supporting different verification algorithms for areas with different security levels, and allowing a trade-off between security strength and verification speed. Attached Figure Description
[0046] This manual includes the following figures, which illustrate the following:
[0047] Figure 1 This is a flowchart of an embedded flash memory integrity protection method and system based on general hardware collaboration according to the present invention;
[0048] Figure 2 This is a system architecture diagram of an embedded flash memory integrity protection method and system based on general hardware collaboration according to the present invention;
[0049] Figure 3 This is a schematic diagram of the internal layout of the flash memory in an embedded flash memory integrity protection method and system based on general hardware collaboration according to the present invention. Detailed Implementation
[0050] The specific embodiments of the present invention will be further described in detail below with reference to the accompanying drawings, in order to help those skilled in the art to have a more complete, accurate and in-depth understanding of the inventive concept and technical solution of the present invention, and to facilitate its implementation.
[0051] This invention provides an embedded flash memory integrity protection method based on general hardware collaboration, including an offline preprocessing stage and an online runtime monitoring stage;
[0052] The offline preprocessing stage includes the following steps:
[0053] Step 1: Based on the firmware's logical structure and security level, divide the storage area of the firmware in the flash memory that requires integrity protection into multiple blocks to be protected. Define the starting address, length, and block identifier of each block to be protected through the configuration file; compile and link the firmware to generate a firmware image file.
[0054] Step 2: Read the compiled firmware image file using the verification calculation tool, calculate the verification digest value for the original binary data of each block to be protected in the firmware image file, and generate a block verification information table; each entry in the block verification information table contains the start address, length, block identifier and pre-calculated verification digest value of the corresponding block to be protected;
[0055] Step 3: Write the block verification information table back to the specified area of the flash memory in the firmware image file, and burn it into the flash memory along with the firmware image file;
[0056] The online runtime monitoring phase includes:
[0057] Step 4: After the system powers on and the processor completes its initialization configuration, the data of the block to be protected in the flash memory is transferred to the hardware verification calculation engine through the DMA controller. The hardware verification calculation engine calculates the verification digest value of the current data in real time.
[0058] Step 5: The DMA controller generates an interrupt after each block to be protected is transferred. In the interrupt service routine, it reads the current check digest value output by the hardware check calculation engine and compares it with the corresponding pre-calculated check digest value in the block check information table. If the comparison is inconsistent, a security response is triggered.
[0059] Step Six: Repeat the verification steps in Steps Four and Five at a preset period using a hardware timer to perform polling-style periodic verification on all blocks to be protected.
[0060] In step two, the verification calculation tool uses verification algorithms including CRC32 verification algorithm and SHA-256 verification algorithm.
[0061] In step two, the verification method of the verification calculation tool includes: parsing the configuration file, extracting the number of blocks to be protected, the address range of each block to be protected, and the corresponding algorithm configuration; loading the firmware image file into memory; performing data integrity verification on each block to be protected, extracting the original binary data after confirming that there are no data holes, calculating the verification digest value of each block to be protected according to the configured verification algorithm, and writing it into the corresponding position of the block verification information table in the firmware image file; and saving the updated firmware image file.
[0062] In step three, the block check information table is located to a fixed address in the flash memory address space according to the linker's segment placement rules, and is accessed at runtime as a read-only constant array.
[0063] In step four, the processor completes the following initialization configuration steps:
[0064] The source address of the DMA channel is configured to be the starting address of the first block to be protected in the flash memory, the transfer length is the data length of the block to be protected, the destination address is the data input register of the hardware verification calculation engine, and the transfer mode is chain transfer;
[0065] The algorithm parameters configured for the hardware verification calculation engine to verify the protection block are consistent with the algorithm parameters used by the verification calculation tool when verifying the protection block in the offline preprocessing stage;
[0066] Configure the timing period of the hardware timer;
[0067] Create a DMA transfer descriptor for each block to be protected. Each descriptor contains a source address, transfer length, and a link pointer to the next descriptor. The link pointer of the DMA transfer descriptor of the block at the end of the queue points to the block at the head of the queue.
[0068] Step six, the periodic verification steps include:
[0069] When the hardware timer reaches the preset period, it outputs a trigger signal. The DMA controller reads the data of the current block to be protected from the flash memory and sends it to the hardware verification calculation engine.
[0070] The hardware verification calculation engine performs verification calculations on the received data and outputs the current verification digest value.
[0071] After each block to be protected completes data transmission, an interrupt is triggered. The processor reads and compares the check digest value output by the current check calculation engine with the pre-calculated check digest value of the block to be protected in the block check information table through a comparator. If the comparison results are consistent, the check passes, the DMA controller loads the next block to be protected, and starts the check process for the next block to be protected.
[0072] Once all blocks to be protected have completed one round of verification, the DMA controller automatically switches to the block to be protected at the head of the circular queue through a circular queue to start the next round of verification. This process is continuously repeated during system operation.
[0073] In step five, the security response includes at least one of the following operations: generating a security alarm signal; writing fault information into the fault register, the fault information including the block identifier and address information of the tampered block to be protected; and triggering a system reset.
[0074] It also includes a method for adjusting the online monitoring time for each round: by adjusting the preset period of the hardware timer and the size of the block to be protected, the total duration of a full-coverage online monitoring round can be configured.
[0075] This invention provides a system for applying an embedded flash memory integrity protection method based on general hardware collaboration, deployed on a system-on-a-chip, including a processor, a DMA controller, a hardware verification calculation engine, a hardware timer, and a comparator;
[0076] The processor is used for initializing the configuration;
[0077] The DMA controller receives the trigger signal, extracts the data of the block to be protected in the flash memory, and outputs it to the hardware verification calculation engine.
[0078] The hardware verification calculation engine is used to perform real-time calculations on the received block data to be protected and output the current verification digest value to the comparator.
[0079] The hardware timer is used to output a trigger signal according to a preset period to trigger the DMA controller to start the data transfer process;
[0080] The comparator is used to compare the current check digest value with the pre-calculated check digest value of the corresponding block to be protected in the block check information table after the DMA controller has completed the transfer; a security response is triggered when the comparison results are inconsistent.
[0081] The processor, DMA controller, hardware verification calculation engine, hardware timer and comparator are interconnected via a bus, and the flash memory is connected to the on-chip system via the bus.
[0082] The present invention will now be described in detail.
[0083] The present invention discloses an embedded flash memory integrity protection method, which includes an offline preprocessing stage and an online runtime monitoring stage;
[0084] The offline preprocessing stage includes the following steps:
[0085] Based on the firmware's logical structure and security level, the storage area of the firmware requiring integrity protection in the flash memory is divided into multiple blocks to be protected. The starting address, length, and block identifier of each block are defined through a configuration file. The firmware is then compiled and linked to generate a firmware image file. The significance of dividing the firmware into protected areas based on its logical structure lies in the fact that the natural logical partitioning layout within the flash memory storage space, formed according to functional attributes, link segments, and module boundaries, represents the modular organization of the firmware itself. Dividing the blocks along the boundaries of the logical structure ensures that each protected block corresponds to a complete and independent functional unit. The security level refers to the security priority hierarchy based on the degree of risk and impact on system security after tampering with each storage area; it is a grading standard based on security protection requirements.
[0086] The PC-based verification calculation tool reads the compiled firmware image file, calculates the checksum value for the raw binary data of each block to be protected in the firmware image file, and generates a block verification information table. Each entry in the block verification information table contains the starting address, length, block identifier, and pre-calculated checksum value of the corresponding block to be protected. The verification calculation tool uses verification algorithms including CRC32 and SHA-256, and different verification algorithms can be configured for different blocks to be protected. The verification method of the verification calculation tool is as follows: parse the configuration file to extract the number of blocks to be protected, the address range of each block to be protected, and the corresponding algorithm configuration; load the firmware image file into memory; perform data integrity verification on each block to be protected, and after confirming that there are no data gaps, extract the raw binary data, calculate the checksum value of each block to be protected according to the configured verification algorithm, and write it into the corresponding position in the block verification information table of the firmware image file; save the updated firmware image file.
[0087] The block checksum table is written back to a designated area of the flash memory in the firmware image file and then burned into the flash memory along with the firmware image file. The block checksum table is located at a fixed address in the flash memory address space according to the linker's segment placement rules and is accessed at runtime as a read-only constant array.
[0088] In this invention, the offline preprocessing stage is executed in the PC development environment and does not occupy the running resources of the embedded on-chip system.
[0089] The online runtime monitoring phase includes the following steps:
[0090] After the system powers on and the processor (CPU) completes its initialization configuration, the DMA controller transfers the data of the blocks to be protected in the flash memory to the hardware verification calculation engine. The hardware verification calculation engine calculates the verification digest value of the current data in real time. The initialization configuration steps completed by the processor include: configuring the source address of the DMA channel to be the starting address of the first block to be protected in the flash memory, the transfer length to be the data length of the block to be protected, the destination address to be the data input register of the hardware verification calculation engine, and the transfer mode to be chained transfer; configuring the algorithm parameters of the hardware verification calculation engine to verify the protected block to be consistent with the algorithm parameters used by the verification calculation tool to verify the protected block in the offline preprocessing stage; configuring the timing period of the hardware timer; creating a DMA transfer descriptor for each block to be protected, each descriptor containing a source address, a transfer length, and a link pointer to the next descriptor, with the link pointer of the DMA transfer descriptor of the block to be protected at the end of the queue pointing to the block to be protected at the head of the queue.
[0091] The DMA controller generates an interrupt after each protected block transfer is completed. In the interrupt service routine, it reads the current checksum value output by the hardware check calculation engine and compares it with the corresponding pre-calculated checksum value in the block check information table. If the comparison is inconsistent, a security response is triggered. The security response includes at least one of the following operations: generating a security alarm signal; writing fault information to a fault register, including the block identifier and address information of the tampered protected block; and triggering a system reset.
[0092] The above verification steps are repeatedly executed by a hardware timer at a preset period to perform polling-style periodic verification on all blocks to be protected. Specifically, when the hardware timer reaches the preset period, it outputs a trigger signal. The DMA controller reads the data of the current block to be protected from the flash memory and sends it to the hardware verification calculation engine. The hardware verification calculation engine performs verification calculation on the received data and outputs the current verification digest value. After the data transmission of each block to be protected is completed, an interrupt is triggered. The processor reads and compares the verification digest value output by the current verification calculation engine with the pre-calculated verification digest value of the block to be protected in the block verification information table through a comparator. If the comparison results are consistent, the verification passes, the DMA controller loads the next block to be protected, and starts the verification process for the next block to be protected. When all blocks to be protected have completed one round of verification, the DMA controller automatically switches to the block to be protected at the head of the circular queue through a circular queue and starts the next round of verification. This process is continuously executed in a loop during system operation.
[0093] The present invention also includes a method for adjusting the online monitoring time for each round: by adjusting the preset period of the hardware timer and the size of the blocks to be protected, the total duration of a full-coverage online monitoring round is configured. For example, if there are 100 blocks to be protected in the flash memory and the timing period is 10ms, then completing a full-coverage scan takes 100 × 10ms = 1 second, meaning that any tampering with the blocks to be protected can be detected within a maximum of 1 second.
[0094] During the online runtime monitoring phase, the processor-free verification data flow occurs as follows: After the processor completes its initial configuration, data is directly transferred from flash memory to the hardware verification calculation engine via the DMA controller for verification calculation. The calculation results are compared by a comparator to determine whether to trigger a security response. Throughout this process, the processor does not need to intervene in data transfer or verification calculation.
[0095] This invention provides an embedded flash memory integrity protection system deployed on a system-on-a-chip (SoC), including a processor, a DMA controller, a hardware verification calculation engine, a hardware timer, and a comparator. The processor is used for initialization and configuration. The DMA controller receives a trigger signal, transfers the data of the block to be protected in the flash memory, and outputs it to the hardware verification calculation engine. The hardware verification calculation engine performs real-time calculations on the received data of the block to be protected and outputs the current verification digest value to the comparator. The hardware timer outputs a trigger signal at a preset period to trigger the DMA controller to start the data transmission process. After the DMA controller completes the transmission, the comparator compares the current verification digest value with the pre-calculated verification digest value of the corresponding block to be protected in the block verification information table; a security response is triggered when the comparison results are inconsistent.
[0096] The processor, DMA controller, hardware verification calculation engine, hardware timer, and comparator are interconnected via a bus. The flash memory communicates with the on-chip system via the bus, storing firmware and block verification information tables. Figure 3 As shown, the flash memory space is logically divided into a security code area, a security constant data area, and a block checksum table area. The security code area needs to be partitioned to form a block to be protected. The block checksum table is stored in a designated read-only memory area within the flash memory. This area is located at a fixed position in the flash memory address space according to the linker's segment placement rules, ensuring that the table can be accessed at a fixed address during runtime. The block checksum table is accessed at runtime as a read-only constant array. This array is filled by the PC-side checksum calculation tool after compilation and before burning; its contents are permanently stored in the flash memory and cannot be modified by runtime software.
[0097] In multi-core processors, each core may have its own independent code flash memory region, while multiple cores share a secure code region and a secure constant data region. This invention can be extended to multi-core scenarios: a verification queue is established for each core's independent code region and shared secure region, and verification is performed in parallel by multiple DMA channels. Each DMA channel uses an independent hardware timer and verification calculation engine instance, without interference. The verification results from each channel are aggregated for a global security decision.
[0098] The beneficial effects of the present invention are described in detail below.
[0099] The verification data stream of this invention requires no processor computation. It utilizes a DMA controller to autonomously move flash memory data to a hardware verification engine for verification calculations. The processor only participates during initialization configuration and interrupt result processing. The core processes of data movement and verification calculations do not consume processor computing resources. Compared to existing technologies where the processor needs to read data byte-by-byte and perform software verification operations, this invention significantly reduces the impact on system real-time performance.
[0100] This invention eliminates the need for an encryption engine and key management, employing a hardware verification calculation engine to compute the checksum value, thus eliminating the need to maintain encryption keys. Due to the non-volatility of flash memory and its physical write protection mechanism, attackers cannot simultaneously modify the flash memory content and the corresponding checksum value without damaging the physical package; therefore, the checksum value is sufficient to detect tampering.
[0101] This invention pre-calculates and stores the benchmark values offline. Utilizing the non-volatile nature of flash memory, it pre-calculates the checksum values of all blocks to be protected using PC-based tools during the compilation phase and stores the results in a designated read-only area of the flash memory. Compared to existing technologies that dynamically calculate benchmark values at runtime, this solution eliminates the runtime overhead of benchmark value calculation.
[0102] The storage overhead of this invention is extremely low, occupying only a small read-only area in flash memory for the verification information table, without requiring RAM resources. Compared to existing solutions where hash trees occupy approximately 25% of memory space, the storage overhead of this invention is negligible.
[0103] This invention provides continuous protection during flash memory operation. Periodic scanning enables continuous monitoring of the firmware. Compared to schemes that perform verification only once at boot, this invention can detect tampering throughout the entire lifecycle of the system.
[0104] This invention does not rely on dedicated security IP. Instead, it utilizes the on-chip system's common DMA controller, hardware verification calculation engine, and timer, which are standard peripherals for most SoC / MCU platforms and are easy to port between different hardware platforms.
[0105] This invention has the advantage of being flexible and configurable, supporting the configuration of different verification algorithms for areas with different security levels, and allowing a trade-off between security strength and verification speed.
[0106] The present invention has been described above by way of example with reference to the accompanying drawings. Obviously, the specific implementation of the present invention is not limited to the above-described manner. Any non-substantial improvements made using the inventive concept and technical solution; or the direct application of the inventive concept and technical solution to other situations without modification, are all within the protection scope of the present invention.
Claims
1. A method for protecting the integrity of embedded flash memory based on general hardware collaboration, characterized in that, This includes an offline preprocessing stage and an online runtime monitoring stage; The offline preprocessing stage includes the following steps: Step 1: Based on the firmware's logical structure and security level, divide the storage area of the firmware in the flash memory that requires integrity protection into multiple blocks to be protected. Define the starting address, length, and block identifier of each block to be protected through the configuration file; compile and link the firmware to generate a firmware image file. Step 2: Read the compiled firmware image file using the verification calculation tool, calculate the verification digest value for the original binary data of each block to be protected in the firmware image file, and generate a block verification information table; each entry in the block verification information table contains the start address, length, block identifier and pre-calculated verification digest value of the corresponding block to be protected; Step 3: Write the block verification information table back to the specified area of the flash memory in the firmware image file, and burn it into the flash memory along with the firmware image file; The online runtime monitoring phase includes: Step 4: After the system powers on and the processor completes its initialization configuration, the data of the block to be protected in the flash memory is transferred to the hardware verification calculation engine through the DMA controller. The hardware verification calculation engine calculates the verification digest value of the current data in real time. Step 5: The DMA controller generates an interrupt after each block to be protected is transferred. In the interrupt service routine, it reads the current check digest value output by the hardware check calculation engine and compares it with the corresponding pre-calculated check digest value in the block check information table. If the comparison is inconsistent, a security response is triggered. Step Six: Repeat the verification steps in Steps Four and Five at a preset period using a hardware timer to perform polling-style periodic verification on all blocks to be protected.
2. The embedded flash memory integrity protection method based on general hardware collaboration as described in claim 1, characterized in that: In step two, the verification calculation tool uses verification algorithms including CRC32 verification algorithm and SHA-256 verification algorithm.
3. The embedded flash memory integrity protection method based on general hardware collaboration as described in claim 1, characterized in that: In step two, the verification method of the verification calculation tool includes: parsing the configuration file, extracting the number of blocks to be protected, the address range of each block to be protected, and the corresponding algorithm configuration; loading the firmware image file into memory; performing data integrity verification on each block to be protected, extracting the original binary data after confirming that there are no data holes, calculating the verification digest value of each block to be protected according to the configured verification algorithm, and writing it into the corresponding position of the block verification information table in the firmware image file; and saving the updated firmware image file.
4. The embedded flash memory integrity protection method based on general hardware collaboration as described in claim 1, characterized in that: In step three, the block check information table is located to a fixed address in the flash memory address space according to the linker's segment placement rules, and is accessed at runtime as a read-only constant array.
5. The embedded flash memory integrity protection method based on general hardware collaboration as described in claim 1, characterized in that: In step four, the processor completes the following initialization configuration steps: The source address of the DMA channel is configured to be the starting address of the first block to be protected in the flash memory, the transfer length is the data length of the block to be protected, the destination address is the data input register of the hardware verification calculation engine, and the transfer mode is chain transfer; The algorithm parameters configured for the hardware verification calculation engine to verify the protection block are consistent with the algorithm parameters used by the verification calculation tool when verifying the protection block in the offline preprocessing stage; Configure the timing period of the hardware timer; Create a DMA transfer descriptor for each block to be protected. Each descriptor contains a source address, transfer length, and a link pointer to the next descriptor. The link pointer of the DMA transfer descriptor of the block at the end of the queue points to the block at the head of the queue.
6. The embedded flash memory integrity protection method based on general hardware collaboration as described in claim 1, characterized in that: Step six, the periodic verification steps include: When the hardware timer reaches the preset period, it outputs a trigger signal. The DMA controller reads the data of the current block to be protected from the flash memory and sends it to the hardware verification calculation engine. The hardware verification calculation engine performs verification calculations on the received data and outputs the current verification digest value. After each block to be protected completes data transmission, an interrupt is triggered. The processor reads and compares the check digest value output by the current check calculation engine with the pre-calculated check digest value of the block to be protected in the block check information table through a comparator. If the comparison results are consistent, the check passes, the DMA controller loads the next block to be protected, and starts the check process for the next block to be protected. Once all blocks to be protected have completed one round of verification, the DMA controller automatically switches to the block to be protected at the head of the circular queue through a circular queue to start the next round of verification. This process is continuously repeated during system operation.
7. The embedded flash memory integrity protection method based on general hardware collaboration as described in claim 1, characterized in that: In step five, the safety response includes at least one of the following operations: generating a safety alarm signal; The fault information is written into the fault register, including the block identifier and address information of the tampered block to be protected; a system reset is triggered.
8. The embedded flash memory integrity protection method based on general hardware collaboration as described in claim 1, characterized in that: It also includes a method for adjusting the online monitoring time for each round: by adjusting the preset period of the hardware timer and the size of the block to be protected, the total duration of a full-coverage online monitoring round can be configured.
9. A system for applying the embedded flash memory integrity protection method based on general hardware collaboration as described in any one of claims 1-8, deployed on a system-on-a-chip, characterized in that: This includes a processor, DMA controller, hardware verification calculation engine, hardware timer, and comparator; The processor is used for initialization configuration; The DMA controller is used to receive the trigger signal, output the data of the block to be protected in the flash memory to the hardware verification calculation engine; The hardware verification calculation engine is used to perform real-time calculations on the received block data to be protected and output the current verification digest value to the comparator. The hardware timer is used to output a trigger signal according to a preset period to trigger the DMA controller to start the data transmission process. The comparator is used to compare the current check digest value with the pre-calculated check digest value of the corresponding block to be protected in the block check information table after the DMA controller has completed the transfer, and to trigger a security response when the comparison results are inconsistent. The processor, DMA controller, hardware verification calculation engine, hardware timer, and comparator are interconnected via a bus, and the flash memory is connected to the on-chip system via the bus.
Citation Information
Patent Citations
Start method supporting bad block flash memory scanning
CN102637461A
