MCU firmware flashing methods, devices, systems, flashing host computers and products
By obtaining the secure boot status and signature verification results during the MCU firmware flashing process, sending the image file in blocks and performing hash verification, the firmware version mismatch problem between the development and mass production stages is solved, the risk of vehicle controllers becoming bricked is reduced, and the compliance and reliability of the flashing process are improved.
Patent Information
- Application Number
- CN202611447541.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-17
- Publication Date
- 2026-11-10
AI Technical Summary
During the development and mass production phase of vehicle controllers, firmware version mismatch can easily occur due to human error during MCU firmware flashing, increasing the risk of bricking the vehicle controller. Existing technologies cannot effectively solve this problem.
The system obtains the firmware image file to be flashed and the secure boot status information of the target MCU by flashing the host computer. After verifying the signature and determining the permission status, the image file is sent to the MCU in blocks, and streaming hash calculation and final verification are performed to ensure the compliance of the flashing process.
This improves the compliance of the MCU firmware flashing process, reduces the risk of vehicle controllers becoming bricked due to firmware version mismatch, and enhances the reliability and efficiency of the flashing process.
Smart Images

Figure CN123067906A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of vehicle technology, and in particular to MCU firmware flashing methods, devices, systems, flashing host computers and products. Background Technology
[0002] The MCU integrated in the vehicle controller supports a secure boot mechanism. During the development phase, disabling the secure boot mechanism allows the MCU to run unsigned firmware image files, facilitating iterative debugging and multiple firmware flashing verifications, thus improving development and verification efficiency. During mass production, the secure boot mechanism is permanently enabled, allowing the MCU to run only legally signed firmware image files, meeting the vehicle information security compliance requirements after mass production. However, vehicle controllers in the development phase and those in the mass production phase are often indistinguishable in appearance. During MCU firmware flashing, human error can easily lead to firmware version mismatches, increasing the risk of bricking the vehicle controller. Summary of the Invention
[0003] The main purpose of this application is to provide MCU firmware flashing methods, devices, systems, flashing host computers and products, with the aim of improving the compliance of the MCU firmware flashing process during the development and mass production stages.
[0004] To achieve the above objectives, the first aspect of this application proposes an MCU firmware flashing method, applied to flashing a host computer, the method comprising: Obtain the firmware image file to be flashed and the secure boot status information of the target MCU; The header information of the firmware image file is verified to obtain the verification result. Based on the security startup status information of the target MCU and the signature verification result, write permission status information is generated; When the flashing permission status information indicates that flashing is allowed, the firmware image file is divided into multiple data blocks and sent to the target MCU one by one, so that the target MCU writes to the target partition of the internal Flash when it receives each data block, and performs streaming hash calculation synchronously. After writing the multiple data blocks to the target partition, the final hash value is verified. When the verification is successful, the target partition is activated.
[0005] In some embodiments of this application, the secure boot status information of the target MCU is obtained in the following ways: A diagnostic service request is sent to the target MCU, so that after receiving the diagnostic service request, the target MCU reads the secure boot enable flag stored in its internal target register, generates the secure boot status information of the target MCU based on the secure boot enable flag, and sends it to the flashing host computer.
[0006] In some embodiments of this application, the step of verifying the signature of the header information of the firmware image file to obtain the signature verification result includes: When the header information of the firmware image file contains a digital signature and a target key identifier used for signing, the target key identifier is used to filter the public key repository built into the flashing host computer to obtain the filtering result; wherein, the public key repository stores multiple different public keys, and each public key carries a corresponding key identifier. When the filtering result contains only one target public key, the digital signature is verified based on the target public key; When the signature verification is successful, the signature verification result indicating successful verification is generated; When the signature verification fails, the filtering result is empty, or the header information of the firmware image file does not contain the digital signature, a signature verification result indicating that the signature verification has failed is generated.
[0007] In some embodiments of this application, generating write permission status information based on the secure boot status information of the target MCU and the signature verification result includes: When the security boot status information of the target MCU indicates that the security boot mechanism is not enabled, or when the security boot status information of the target MCU indicates that the security boot mechanism is enabled, and the signature verification result indicates that the signature verification is successful, the write permission status information indicating that write is allowed is generated. When the target MCU's secure boot status information indicates that the target MCU has enabled the secure boot mechanism, and the signature verification result indicates that the signature verification failed, the write permission status information indicating that the write operation is refused is generated.
[0008] In some embodiments of this application, the method further includes: When the write permission status information indicates that write is refused, an error message is generated.
[0009] To achieve the above objectives, a second aspect of this application proposes an MCU firmware flashing system, the system comprising a flashing host computer and a target MCU; The flashing host computer is used to obtain the firmware image file to be flashed and the security boot status information of the target MCU, verify the signature of the header information of the firmware image file, obtain the signature verification result, generate flashing permission status information based on the security boot status information of the target MCU and the signature verification result, and when the flashing permission status information indicates that flashing is allowed, divide the firmware image file into multiple data blocks and send them to the target MCU one by one. The target MCU is used to write to the target partition of the internal Flash when each data block is received, and to perform streaming hash calculation synchronously. After writing the multiple data blocks to the target partition, the final hash value is verified. When the verification is successful, the target partition is activated.
[0010] In some embodiments of this application, when the secure boot status information of the target MCU indicates that the target MCU has enabled the secure boot mechanism, the target MCU is also used to perform signature verification on the firmware image file stored in the target partition through the internal bootloader after rebooting. When the signature verification is successful, the application corresponding to the firmware image file stored in the target partition is run.
[0011] To achieve the above objectives, a third aspect of this application provides an MCU firmware flashing device for flashing a host computer, the device comprising: The acquisition module is used to acquire the firmware image file to be flashed and the secure boot status information of the target MCU; The verification module is used to verify the signature of the header information of the firmware image file and obtain the signature verification result. The generation module is used to generate write permission status information based on the security startup status information of the target MCU and the signature verification result; The sending module is used to divide the firmware image file into multiple data blocks and send them to the target MCU one by one when the flashing permission status information indicates that flashing is allowed. This allows the target MCU to write the data block into the target partition of its internal Flash memory and perform streaming hash calculation simultaneously. After writing the multiple data blocks into the target partition, the module verifies the final hash value. When the verification is successful, the target partition is activated.
[0012] To achieve the above objectives, a fourth aspect of this application provides a flashing host computer, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the above-described MCU firmware flashing method.
[0013] To achieve the above objectives, a fifth aspect of this application provides a computer program product, including a computer program, which, when executed by a processor, is used to implement the above-described MCU firmware flashing method.
[0014] The embodiments of this application include at least the following beneficial effects: by first obtaining the firmware image file to be flashed and the secure boot status information of the target MCU through the flashing host computer, then verifying the signature of the header information of the firmware image file to obtain the signature result, and then generating flashing permission status information based on the secure boot status information of the target MCU and the signature result, and then, if the flashing permission status information indicates that flashing is allowed, the firmware image file is divided into multiple data blocks and sent to the target MCU one by one, so that the target MCU writes to the target partition of the internal Flash when it receives each data block and performs streaming hash calculation simultaneously. After writing multiple data blocks to the target partition, the final hash value calculated is verified, and the target partition is activated when the verification is successful. This can improve the compliance of the MCU firmware flashing process in the development and mass production stages, thereby effectively reducing the risk of the vehicle controller becoming bricked due to firmware version mismatch.
[0015] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description
[0016] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which: Figure 1 This is a flowchart illustrating an MCU firmware flashing method provided in an embodiment of this application; Figure 2 This is a schematic diagram of the composition of an MCU firmware flashing system provided in an embodiment of this application; Figure 3 This is a schematic diagram of the composition of an MCU firmware flashing device provided in an embodiment of this application; Figure 4 This is a schematic diagram of the hardware structure for flashing the host computer provided in an embodiment of this application. Detailed Implementation
[0017] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the reference to "embodiment" herein means that a specific feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments. The implementation methods described in the following exemplary embodiments do not represent all implementation methods consistent with the embodiments of this application; they are merely examples of apparatuses and methods consistent with some aspects of the embodiments of this application as detailed in the appended claims.
[0018] It is understood that the terms "first," "second," etc., used in this application may be used to describe various concepts herein, but unless specifically stated otherwise, these concepts are not limited by these terms. These terms are only used to distinguish one concept from another. For example, without departing from the scope of the embodiments of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the words "if" or "when" as used herein may be interpreted as "when," "in response to a determination," or "at least one," "multiple," "each," "any," etc., as used in this application, at least one includes one, two, or more than two, multiple includes two or more, each refers to each of the corresponding multiple, and any refers to any one of the multiple.
[0019] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0020] To facilitate understanding of the inventive concept of this application, before providing a detailed description of the embodiments of this application, the English abbreviations (terms) / related concepts involved in the embodiments of this application will first be explained. The English abbreviations (terms) / related concepts involved in the embodiments of this application are subject to the following interpretations.
[0021] Secure Boot is a hardware and software mechanism implemented on an MCU (Microcontroller Unit) to verify the integrity and authenticity of boot code such as firmware and bootloader during system startup. It prevents insecure, tampered, or malicious code from running during the boot process, ensuring the system is not affected by malicious code or unauthorized modifications. The basic process of Secure Boot includes bootloader verification, firmware verification, and application loading. Bootloader verification refers to the MCU's boot program first verifying the bootloader's signature through hardware. This hardware can be a built-in secure boot module within the MCU. Firmware verification involves loading the system firmware after the bootloader's signature verification is successful and verifying its signature. The system firmware can be an operating system image file. Application loading refers to loading and executing the system application after firmware verification is successful.
[0022] The MCU integrated in the vehicle controller supports a secure boot mechanism. During the development phase, this mechanism is typically disabled, allowing the MCU to run unsigned or legally signed firmware image files. This facilitates iterative debugging and multiple firmware flashing verifications, improving development and verification efficiency. In the mass production phase, the secure boot mechanism is permanently enabled, allowing only legally signed firmware image files to run, meeting the vehicle information security compliance requirements after mass production. However, vehicle controllers in the development and mass production phases are often indistinguishable visually. During MCU firmware flashing, human error can easily lead to firmware version mismatches, increasing the risk of the vehicle controller becoming bricked. A bricked vehicle controller typically refers to a controller that completely loses responsiveness after an upgrade or operation, failing to boot normally, load applications, or even be reprogrammed or restored via conventional software / communication interfaces.
[0023] For example, since the dual-partition rollback mechanism built into the MCU during the update and upgrade process can only solve faults such as upgrade interruption or image corruption, it cannot solve the problem of bricking caused by violation of the secure boot policy. Once an unsigned firmware image file is flashed to an MCU with the secure boot mechanism enabled, the BootROM inside the MCU will fail to verify the signature in the first stage after the MCU is powered on, causing the MCU to stop. At this time, neither partition can be booted, the rollback mechanism cannot be triggered, causing irreversible failure of the vehicle controller equipped with the MCU, resulting in the risk of scrapping the vehicle controller or cost of after-sales repair.
[0024] In view of this, this application proposes an MCU firmware flashing method, apparatus, system, flashing host computer, and product. This solution proposes that the flashing host computer first obtains the firmware image file to be flashed and the secure boot status information of the target MCU, then verifies the header information of the firmware image file to obtain the verification result. Next, based on the target MCU's secure boot status information and the verification result, flashing permission status information is generated. Subsequently, if the flashing permission status information indicates that flashing is permitted, the firmware image file is divided into multiple data blocks and sent to the target MCU one by one. This allows the target MCU to write to the target partition of its internal Flash memory upon receiving each data block, and simultaneously perform streaming hash calculation. After writing multiple data blocks to the target partition, the final hash value is verified, and the target partition is activated upon successful verification. This improves the compliance and reliability of the MCU firmware flashing process during development and mass production, thereby effectively reducing the risk of vehicle controller bricking due to firmware version mismatch. Typically, firmware version mismatch issues occur during the transition between development and mass production.
[0025] This application provides an MCU firmware flashing method, which can be applied to the flashing host computer provided in this application. The flashing host computer can be a terminal or a server. The terminal can be a tablet computer, a laptop computer, a desktop computer, etc., but is not limited to these. The server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks, and big data and artificial intelligence platforms.
[0026] Please refer to Figure 1 , Figure 1 This is a flowchart illustrating an MCU firmware flashing method provided in an embodiment of this application. It should be noted that the steps shown in the flowchart can be executed in a computer system, such as a computer system containing a set of computer-executable instructions. Although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0027] The MCU firmware flashing method provided in this application embodiment is mainly applied to flashing host computers. This method may include, but is not limited to, the four steps S101 to S104, as detailed below: S101. Obtain the firmware image file to be flashed and the secure boot status information of the target MCU; S102. Verify the signature of the header information of the firmware image file to obtain the signature verification result; S103. Generate write permission status information based on the target MCU's secure boot status information and signature verification result; S104. When the flashing permission status information indicates that flashing is allowed, the firmware image file is divided into multiple data blocks and sent to the target MCU one by one, so that the target MCU writes to the target partition of the internal Flash when it receives each data block and performs streaming hash calculation simultaneously. After writing multiple data blocks to the target partition, the final hash value is verified. When the verification is successful, the target partition is activated.
[0028] The four steps S101 to S104 shown in this application embodiment can improve the compliance of the MCU firmware flashing process during the development or mass production stage by determining the flashing permission based on the MCU secure boot state and signature verification state before firmware flashing, thereby effectively reducing the risk of the vehicle controller becoming bricked due to firmware version mismatch.
[0029] In S101 of some embodiments, the flashing host computer can initiate a flashing session with the target MCU and read the secure boot status information of the target MCU through the UDS diagnostic service. The secure boot status information of the target MCU is used to characterize whether the secure boot mechanism is enabled by the target MCU. The UDS diagnostic service can be any of Service 22 (ReadDataByIdentifier), Service 2C, Service 2E, etc. Specifically, the flashing host computer sends a diagnostic service (UDS) request to the target MCU, so that after receiving the diagnostic service request, the target MCU reads the secure boot enable flag stored in its internal target register. The target register can be an eFuse register or an OTP (One Time Programmable) register. The secure boot enable flag is generally SEC_BOOT_EN, which is a Boolean flag. Then, the secure boot status information of the target MCU is generated based on the secure boot enable flag and sent to the flashing host computer.
[0030] When the target MCU receives a diagnostic service request, it generally means that the bootloader or application within the target MCU receives the request. The target MCU's secure boot status information is generated based on the secure boot enable flag. This can be achieved by using a predefined DID (Data Identifier) to convert the secure boot enable flag into the target MCU's secure boot status information. For example, when the logical value of SEC_BOOT_EN is 1, it indicates that the target MCU has enabled the secure boot mechanism, generating target MCU secure boot status information represented by 0x01; when the logical value of SEC_BOOT_EN is 0, it indicates that the target MCU has not enabled the secure boot mechanism, generating target MCU secure boot status information represented by 0x00.
[0031] By utilizing the UDS diagnostic service to read the hardware security boot status of the target MCU, without the need for complex access permission verification, the efficiency of obtaining key information can be improved, which in turn helps to improve the efficiency of subsequent MCU firmware flashing.
[0032] In some embodiments, S102, the header of the firmware image file contains at least six fields: Magic Number, Image Type, Firmware Version Number, Signature Key Identifier (ID), Digital Signature, and Hash Value. The Magic Number field is used to identify a legitimate image format, the Image Type field is used to distinguish between Bootloader, App, calibration data, etc., the Firmware Version Number field is used for anti-rollback version checking, the Signature Key Identifier field is used to match the hardware trust list, the Digital Signature field is used to implement signature verification in the host computer and the target MCU, and the Hash Value field is used to implement streaming hash verification in the target MCU. The header fields for the magic number, firmware version number, and signature key identifier are 4 bytes long; the image type field is 1 byte long; the hash value field is 32 bytes long; and the length of the digital signature field can be determined based on the asymmetric encryption algorithm and key length used in the signing stage. For example, if the RSA algorithm is used, the digital signature field length is determined to be 256 bytes or 512 bytes; if the ECC elliptic curve algorithm is used, the digital signature field length is determined to be 64 bytes or 96 bytes; and if the SM2 algorithm is used, the digital signature field length is determined to be 64 bytes. If it is clear that the header information of the firmware image file does not need to include a digital signature, firmware version differentiation can be achieved by setting both the digital signature field and the signature key identifier field to zero.
[0033] Based on this, the implementation method for verifying the signature of the header information of the firmware image file and obtaining the signature verification result may include the following: When the header information of the firmware image file does not contain a digital signature, a signature verification result indicating that the verification failed is generated. Alternatively, when the firmware image file header contains a digital signature and the target key identifier used for signing, the results are filtered from the public key repository built into the flashing host computer based on the target key identifier. The public key repository stores multiple different public keys, each carrying a corresponding key identifier. These multiple public keys typically include a development public key and a production public key. Private keys, independently paired with each public key, are stored in a signature server or an HSM (Hardware Security Module), minimizing the risk of data leakage. When the filtering result is empty, a verification result indicating a failed signature is generated. Alternatively, when the filtering result contains only one target public key, the digital signature is verified based on the target public key to determine if it was issued by the private key matching the target public key and has not been tampered with, thus verifying the authenticity of the digital signature. When the verification is successful, a verification result indicating a successful signature is generated; when the verification fails, a verification result indicating a failed signature is generated.
[0034] By comprehensively judging whether the firmware image file carries a digital signature and whether the digital signature carried by the firmware image file is genuine and legal, the final signature verification result can be determined, which can provide a reliable basis for subsequent flashing permission determination.
[0035] In some embodiments, S103, regarding the generation of write permission status information based on the target MCU's secure boot status information and signature verification results, the corresponding implementation methods may include the following: When the target MCU's secure boot status information indicates that the secure boot mechanism is not enabled, regardless of whether the signature verification result indicates successful or failed verification, the current MCU firmware flashing process in the development phase is executed, and flashing permission status information indicating that flashing is allowed is directly generated; or when the target MCU's secure boot status information indicates that the secure boot mechanism is enabled and the signature verification result indicates successful verification, the current MCU firmware flashing process in the mass production phase is executed, and flashing permission status information indicating that flashing is allowed is generated; or when the target MCU's secure boot status information indicates that the secure boot mechanism is enabled and the signature verification result indicates failed verification, the current MCU firmware flashing process in the mass production phase is executed, and flashing permission status information indicating that flashing is denied is generated.
[0036] By determining flashing permissions based on the MCU's secure boot state and signature verification state, the problem of firmware version mismatch caused by human error can be solved, thereby effectively reducing the risk of the vehicle controller becoming bricked due to firmware version mismatch.
[0037] In some embodiments, when the flashing permission status information indicates that flashing is refused, the flashing host computer generates an error message and displays it visually. The error message is used to inform the operator that the flashing host computer refuses to write the firmware image file to the target MCU. The error message can also include the reason for the refusal, such as the target MCU having enabled secure boot mechanism but the firmware image file does not carry a digital signature, the target MCU having enabled secure boot mechanism but the digital signature carried in the firmware image file cannot be verified due to unsuccessful public key matching, or the target MCU having enabled secure boot mechanism but the digital signature carried in the firmware image file has failed to be verified. This allows the operator to check and adjust the MCU firmware flashing process.
[0038] Please refer to Figure 2 , Figure 2 This is a schematic diagram of the composition of an MCU firmware flashing system provided in an embodiment of this application. The system includes a flashing host computer and a target MCU. The flashing host computer communicates with the target MCU. Specifically, the flashing host computer can communicate with the target MCU through UDS (Unified Diagnostic Service), or it can communicate with the target MCU through a CAN / LIN bus. This application does not limit the specific communication method.
[0039] In the specific implementation process, the host computer first obtains the firmware image file to be flashed and the secure boot status information of the target MCU. Then, it verifies the signature of the header information of the firmware image file to obtain the signature result. Next, based on the secure boot status information of the target MCU and the signature result, it generates flashing permission status information. Subsequently, when the flashing permission status information indicates that flashing is allowed, the firmware image file is divided into multiple data blocks and sent to the target MCU one by one. The target MCU writes each data block it receives to the target partition of its internal Flash memory and performs streaming hash calculation simultaneously. After writing multiple data blocks to the target partition, it verifies the final hash value obtained. When the verification is successful, the target partition is activated; when the verification fails, the target partition is not activated and is marked as invalid.
[0040] In some embodiments, the firmware image file includes header information and firmware image data. When the host computer performs the operation of dividing the firmware image file into multiple data blocks and sending them one by one to the target MCU, it can be configured as follows: the firmware image data is divided into multiple data blocks according to a preset data block length, and the length of the last data block can be less than the preset data block length. During the first data transmission, the header information is concatenated with the first data block to obtain a new data block, which is then sent to the target MCU. During the second data transmission, the second data block is sent directly to the target MCU. During the third data transmission, the third data block is sent directly to the target MCU, and so on, until the last data transmission, where the last data block is sent directly to the target MCU. The preset data block length can be determined according to the RAM space size of the target MCU. The preset data block length should generally not exceed 1 / 2 of the RAM space size, and preferably is less than 1 / 3 of the RAM space size. If the Flash programming page size of the target MCU is much smaller than the RAM space size, the preset data block length can be the Flash programming page size.
[0041] By flashing the host computer and transmitting the firmware image file in chunks, the memory usage of the target MCU can be reduced, eliminating the need to cache the complete firmware image data.
[0042] It should be noted that for explanations of other functions implemented by flashing the host computer and their corresponding beneficial effects, please refer to the above method embodiments, which will not be repeated here.
[0043] In some embodiments, the target partition of the Flash memory inside the target MCU is generally configured with a first sub-region and a second sub-region, which can be physically arranged consecutively in the address space of the Flash.
[0044] Based on this, when the target MCU executes the operation of writing to the target partition of its internal Flash memory upon receiving each data block, and simultaneously performing streaming hash calculation, and then verifying the final hash value after writing multiple data blocks to the target partition, it can be configured as follows: Initialize the hash operation context, load the standard initial vector corresponding to the preset hash algorithm (i.e., use the standard initial vector as the initial hash intermediate state stored within the hash operation context), and upon the first data reception, split the header information and the first data block from the received new data block. Input the first data block into the hash operation unit, use the standard initial vector as the current operation input, and perform group compression operation on the first data block according to the original group length of the preset hash algorithm to update the hash intermediate state currently stored within the hash operation context. Subsequently, write the header information to the first sub-region, write the first data block to the second sub-region, and release the temporary receive buffer corresponding to the new data block. Upon the second data reception, input the received second data block into the hash operation unit, use the hash intermediate state currently stored within the hash operation context as the current operation input, and continue to perform group compression operation according to the original group length of the preset hash algorithm. The second data block is compressed and grouped to update the intermediate hash state currently stored in the hash operation context. Then, the second data block is written to the second sub-region, and the temporary receive buffer corresponding to the second data block is released. This process continues until the last data reception. The last received data block is input to the hash operation unit, and the intermediate hash state currently stored in the hash operation context is used as the current input. The last data block is compressed and grouped again according to the original group length of the preset hash algorithm to update the intermediate hash state again. Then, the last data block is written to the second sub-region, and the temporary receive buffer corresponding to the last data block is released. The entire process can be understood as follows: each time a data block is received, a streaming hash algorithm is used to synchronously update the hash state when the received data block is written to Flash. Based on the hash operation context obtained from the final iterative update, end padding and padded operations are performed to complete the final round of hash compression calculation, obtaining the final hash value. The original hash value is extracted from the header information, and then the final hash value is compared with the original hash value. If they match, the verification is successful; if they do not match, the verification is unsuccessful.
[0045] It should be noted that the preset hash algorithm running inside the target MCU is the same as the hash algorithm used when calculating the original hash value contained in the header information. It can be any of the SHA-256 algorithm, SHA-384 algorithm, SHA-512 algorithm, etc.
[0046] By synchronously executing data block reception, hash iteration calculation, and flash memory writing within the target MCU, and performing hash verification after the flashing process is completed, the efficiency and reliability of MCU firmware flashing can be improved.
[0047] In some embodiments, when the target MCU's secure boot status information indicates that the target MCU has enabled the secure boot mechanism, the target MCU is also used to perform signature verification on the firmware image file stored in the target partition through its internal bootloader after rebooting. This can be done by calling HSM or HSE (Hardware Security Engine). When the signature verification is successful, the application corresponding to the firmware image file stored in the target partition is run. This can be understood as the bootloader directly jumping to the physical starting address of the second sub-region in Flash to run the application. The physical starting address is the entry address of the application corresponding to the firmware image file stored in the target partition, thereby ensuring the security and trustworthiness of the bootloader startup phase. Alternatively, when the target MCU's secure boot status information indicates that the target MCU has not enabled the secure boot mechanism, the target MCU is also used to directly run the application corresponding to the firmware image file stored in the target partition through its internal bootloader after rebooting, in order to improve development and verification efficiency.
[0048] In some embodiments, the target MCU's internal Flash is configured with a primary partition and a backup partition. The backup partition is the target partition mentioned above, and the primary partition is used to store old firmware image files. The target MCU is also used to wait for the watchdog timeout reset when the Bootloader determines that the signature verification has failed or detects that the application corresponding to the newly written firmware image file is running abnormally. Then, the Bootloader automatically rolls back to the primary partition to run the application corresponding to the old firmware image file stored in the primary partition, thereby ensuring that the vehicle controller equipped with the target MCU is always available.
[0049] Please refer to Figure 3 , Figure 3 This is a schematic diagram of an MCU firmware flashing device provided in an embodiment of this application. This device can implement the above-described MCU firmware flashing method applied to flashing a host computer. The device may include, but is not limited to, the following components: The acquisition module 201 is used to acquire the firmware image file to be flashed and the secure boot status information of the target MCU; Verification module 202 is used to verify the signature of the header information of the firmware image file and obtain the signature verification result; The generation module 203 is used to generate write permission status information based on the security boot status information and signature verification result of the target MCU; The sending module 204 is used to divide the firmware image file into multiple data blocks and send them to the target MCU one by one when the flashing permission status information indicates that flashing is allowed. This allows the target MCU to write the data block into the target partition of its internal Flash memory and perform streaming hash calculation simultaneously. After writing multiple data blocks into the target partition, the final hash value is verified. When the verification is successful, the target partition is activated.
[0050] It is understood that the content of the above method embodiments is applicable to the present device embodiments. The functions specifically implemented by the present device embodiments are the same as those specifically implemented by the above method embodiments, and the beneficial effects achieved by the present device embodiments are also the same as those achieved by the above method embodiments.
[0051] This application also provides a flashing host computer, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the above-described MCU firmware flashing method. The flashing host computer can include any smart terminal such as a tablet computer or desktop computer.
[0052] It is understood that the content of the above method embodiments is applicable to this brushing host computer embodiment. The specific functions implemented by this brushing host computer embodiment are the same as those implemented by the above method embodiments, and the beneficial effects achieved by this brushing host computer embodiment are also the same as those achieved by the above method embodiments.
[0053] Please see Figure 4 , Figure 4 This is a schematic diagram illustrating the hardware structure of a flashing host computer according to another embodiment. The flashing host computer includes: The processor 301 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application. The memory 302 can be implemented in the form of read-only memory (ROM), static storage device, dynamic storage device, or random access memory (RAM). The memory 302 can store the operating system and other applications. When the technical solution provided in the embodiments of this application is implemented by software or firmware, the relevant program code is stored in the memory 302 and is called and executed by the processor 301. Input / output interface 303 is used to implement information input and output; The communication interface 304 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.). Bus 305 transmits information between various components of the device (e.g., processor 301, memory 302, input / output interface 303, and communication interface 304); The processor 301, memory 302, input / output interface 303 and communication interface 304 are connected to each other within the device via bus 305.
[0054] This application also provides a computer program product, which includes a computer program that, when executed by one or more processors, is used to implement the above-described MCU firmware flashing method.
[0055] It is understood that the content of the above method embodiments is applicable to this computer program product. The specific functions implemented by the embodiments of this computer program product are the same as those implemented by the above method embodiments, and the beneficial effects achieved by the embodiments of this computer program product are also the same as those achieved by the above method embodiments.
[0056] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0057] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.
[0058] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0059] Those skilled in the art will understand that all or some of the steps, apparatuses, or functional modules / units in the methods disclosed above can be implemented as software, firmware, hardware, or suitable combinations thereof.
[0060] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, apparatus, product, or device that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.
[0061] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0062] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed between the devices or units may be through some interfaces, and the indirect coupling or communication connection may be electrical, mechanical, or other forms.
[0063] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0064] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0065] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0066] The preferred embodiments of this application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of this application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of this application shall be within the scope of the claims of this application.
Claims
1. A method for flashing MCU firmware, characterized in that, The method, applied to writing to a host computer, includes: Obtain the firmware image file to be flashed and the secure boot status information of the target MCU; The header information of the firmware image file is verified to obtain the verification result. Based on the security startup status information of the target MCU and the signature verification result, write permission status information is generated; When the flashing permission status information indicates that flashing is allowed, the firmware image file is divided into multiple data blocks and sent to the target MCU one by one, so that the target MCU writes to the target partition of the internal Flash when it receives each data block, and performs streaming hash calculation synchronously. After writing the multiple data blocks to the target partition, the final hash value is verified. When the verification is successful, the target partition is activated.
2. The MCU firmware flashing method according to claim 1, characterized in that, The secure startup status information of the target MCU is obtained through the following method: A diagnostic service request is sent to the target MCU, so that after receiving the diagnostic service request, the target MCU reads the secure boot enable flag stored in its internal target register, generates the secure boot status information of the target MCU based on the secure boot enable flag, and sends it to the flashing host computer.
3. The MCU firmware flashing method according to claim 1, characterized in that, The signature verification of the header information of the firmware image file to obtain the signature verification result includes: When the header information of the firmware image file contains a digital signature and a target key identifier used for signing, the target key identifier is used to filter the public key repository built into the flashing host computer to obtain the filtering result; wherein, the public key repository stores multiple different public keys, and each public key carries a corresponding key identifier. When the filtering result contains only one target public key, the digital signature is verified based on the target public key; When the signature verification is successful, the signature verification result indicating successful verification is generated; When the signature verification fails, the filtering result is empty, or the header information of the firmware image file does not contain the digital signature, a signature verification result indicating that the signature verification has failed is generated.
4. The MCU firmware flashing method according to claim 1, characterized in that, The step of generating write permission status information based on the security boot status information of the target MCU and the signature verification result includes: When the security boot status information of the target MCU indicates that the security boot mechanism is not enabled, or when the security boot status information of the target MCU indicates that the security boot mechanism is enabled, and the signature verification result indicates that the signature verification is successful, the write permission status information indicating that write is allowed is generated. When the target MCU's secure boot status information indicates that the target MCU has enabled the secure boot mechanism, and the signature verification result indicates that the signature verification failed, the write permission status information indicating that the write operation is refused is generated.
5. The MCU firmware flashing method according to claim 1, characterized in that, The method further includes: When the write permission status information indicates that write is refused, an error message is generated.
6. An MCU firmware flashing system, characterized in that, The system includes a host computer for flashing and a target MCU; The flashing host computer is used to obtain the firmware image file to be flashed and the security boot status information of the target MCU, verify the signature of the header information of the firmware image file, obtain the signature verification result, generate flashing permission status information based on the security boot status information of the target MCU and the signature verification result, and when the flashing permission status information indicates that flashing is allowed, divide the firmware image file into multiple data blocks and send them to the target MCU one by one. The target MCU is used to write to the target partition of the internal Flash when each data block is received, and to perform streaming hash calculation synchronously. After writing the multiple data blocks to the target partition, the final hash value is verified. When the verification is successful, the target partition is activated.
7. The MCU firmware flashing system according to claim 6, characterized in that, When the secure boot status information of the target MCU indicates that the secure boot mechanism has been enabled, the target MCU is also used to perform signature verification on the firmware image file stored in the target partition through the internal bootloader after reboot. When the signature verification is successful, the application corresponding to the firmware image file stored in the target partition is run.
8. An MCU firmware flashing device, characterized in that, The device, used for writing to a host computer, includes: The acquisition module is used to acquire the firmware image file to be flashed and the secure boot status information of the target MCU; The verification module is used to verify the signature of the header information of the firmware image file and obtain the signature verification result. The generation module is used to generate write permission status information based on the security startup status information of the target MCU and the signature verification result; The sending module is used to divide the firmware image file into multiple data blocks and send them to the target MCU one by one when the flashing permission status information indicates that flashing is allowed. This allows the target MCU to write the data block into the target partition of its internal Flash memory and perform streaming hash calculation simultaneously. After writing the multiple data blocks into the target partition, the module verifies the final hash value. When the verification is successful, the target partition is activated.
9. A host computer for writing and flashing, characterized in that, The host computer for flashing firmware includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the MCU firmware flashing method as described in any one of claims 1 to 5.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it is used to implement the MCU firmware flashing method as described in any one of claims 1 to 5.
