Firmware updating method and device, electronic equipment and storage medium

By encapsulating the firmware update code into an application update control program, and combining it with the bootloader to control the target device to obtain the application update control program from the host computer for verification and update, the cumbersome and security issues of existing firmware update methods are solved, and a safe and reliable firmware update is achieved.

CN121658047BActive Publication Date: 2026-07-10贵州航天控制技术有限公司

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
贵州航天控制技术有限公司
Filing Date
2026-02-05
Publication Date
2026-07-10

AI Technical Summary

Technical Problem

Existing firmware update methods rely on physical interfaces, are cumbersome, pose high security risks, can easily damage devices, and cannot effectively solve the problem of incomplete firmware functionality.

Method used

The code for each step of the firmware update is encapsulated into an application update control program. Combined with a fixed bootloader, the target device obtains the application update control program from the host computer, runs it in memory, and performs correctness verification and update processing through the application update control program.

Benefits of technology

It reduces the risk of accidental erasure caused by bootloader anomalies, saves device boot sector storage space, improves the success rate of firmware updates and the maintainability of embedded products, and achieves safe and reliable firmware updates.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121658047B_ABST
    Figure CN121658047B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of software updating, in particular to a firmware updating method and device, an electronic device and a storage medium. The method comprises the following steps: when a boot program in a first flash memory area of a target device is running, determining a loading mode of a main program in a second flash memory area of the target device; if the loading mode is a forced updating mode, obtaining an application updating control program from an upper computer, and writing the application updating control program into a memory after the application updating control program is verified; controlling the boot program to jump to the application updating control program, obtaining a firmware file to be updated based on the application updating control program, and writing the firmware file into a temporary flash memory area; performing a correctness verification process on the firmware file based on the application updating control program; and when the correctness verification is passed, jumping to the second flash memory area of the target device to perform updating processing on the firmware file. The problems of erasing function mis-erasing product programs, insufficient product storage space, power supply abnormalities and firmware bricks in firmware updating of an embedded system are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of firmware update apparatus technology, and more particularly to a firmware update method, apparatus, electronic device and storage medium. Background Technology

[0002] Embedded systems are widely used in industrial control, smart homes, medical devices, automotive electronics, and defense. Firmware updates are an essential process in embedded development, and improving the reliability, security, and accuracy of firmware updates is crucial for product development. Currently, the most common firmware update method involves pre-installing a bootloader in the product and then updating the working program in the product area (hereinafter referred to as "FLASH_CD area") in the boot area (hereinafter referred to as "FLASH_A area") during the development process.

[0003] Therefore, the current firmware update method has the following problems:

[0004] 1. Reliance on physical interfaces and cumbersome manual operation: The programmer needs to be connected through physical peripherals (such as JTAG, emulator, etc.) or by disassembling the device, which is time-consuming and can easily damage the hardware.

[0005] Second, high security risks: The rollback mechanism is weak. When the firmware update fails, there is no safe rollback mechanism, which may brick the device or cause malfunctions. Power outages or communication interruptions during the update process may also cause firmware damage, increasing maintenance costs.

[0006] Third, the online update function and some other functions are fixed in the FLASH_A area. If the FLASH_A area is abnormal, it may cause the firmware data in the FLASH_CD area to be erased, resulting in an unrecoverable security problem.

[0007] Fourth, judging the data stored at special addresses in the FLASH_CD area within the FLASH_A area cannot effectively solve the incomplete firmware functions, resulting in a higher probability of product failure. Summary of the Invention

[0008] In view of this, one of the technical problems solved by the embodiments of this application is to provide a firmware update method, apparatus, device and medium, which solves the problems of incorrect erasure of product programs by the erase function, insufficient product storage space, abnormal power supply and firmware bricking in embedded system firmware updates.

[0009] According to a first aspect of the embodiments of this application, a firmware update method is provided, the method comprising:

[0010] When the bootloader of the first flash memory area of ​​the target device runs, the loading mode of the main program of the target device is determined;

[0011] If the loading mode is forced update mode, the application update control program is obtained from the host computer and written to memory after the application update control program is verified.

[0012] The bootloader is redirected to the application update control program, which then retrieves the firmware file to be updated and writes it to a temporary flash memory area.

[0013] The application update control program performs a correctness verification process on the firmware file.

[0014] When the correctness check passes, the process jumps to the second flash memory area of ​​the target device to perform firmware file update.

[0015] A second aspect of this application discloses a firmware update apparatus, the apparatus comprising:

[0016] The boot sector determination and processing module is used to determine the loading mode of the main program of the target device when the boot program of the first flash memory area of ​​the target device is running;

[0017] The boot sector processing module is used to obtain the application update control program from the host computer if the loading mode is forced update mode, and write it into memory after the application update control program passes the verification.

[0018] The program switching processing module is used to control the bootloader to jump to the application update control program, and to obtain the firmware file to be updated based on the application update control program and write it to the temporary flash memory area.

[0019] The firmware file verification module is used to perform a correctness verification process on the firmware file based on the application update control program;

[0020] The firmware file update module is used to jump to the second flash memory area of ​​the target device to perform firmware file update processing when the correctness verification passes.

[0021] A third aspect of this application discloses an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the above-described method.

[0022] A fourth aspect of this application discloses a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the above-described method.

[0023] This application encapsulates the code for each stage of firmware update into an application update control program. This program, combined with a fixed bootloader, controls the target device to obtain the application update control program from the host computer and run it in memory. Since the erase and write code related to firmware updates is encapsulated into the application update control program running in memory, it reduces the risk of accidental erasure due to bootloader anomalies and saves storage space in the device's boot area. Furthermore, because the application update control program obtained from the host computer can be reloaded, even if the firmware update process is unexpectedly interrupted, it does not affect the device restarting the update process. This effectively improves the success rate of firmware updates and the maintainability of embedded products, achieving the goal of safe and reliable firmware updates. Attached Figure Description

[0024] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0025] Figure 1 A schematic flowchart illustrating a firmware update method provided in one embodiment of this application;

[0026] Figure 2 A schematic diagram of the verification process before adjusting the second flash memory area in a firmware update method provided in one embodiment of this application;

[0027] Figure 3 A schematic diagram of the architecture of an application system for a firmware update method provided in one embodiment of this application;

[0028] Figure 4 A flowchart illustrating an application system for a firmware update method provided in one embodiment of this application;

[0029] Figure 5 A schematic flowchart illustrating the uploading and downloading of program information in an application system for a firmware update method provided in one embodiment of this application;

[0030] Figure 6 A flowchart illustrating the download program code of an application system for a firmware update method provided in one embodiment of this application;

[0031] Figure 7 A schematic flowchart illustrating the program verification process of an application system for a firmware update method provided in one embodiment of this application;

[0032] Figure 8 A schematic diagram illustrating the process of erasing the product code area of ​​an application system using a firmware update method provided in one embodiment of this application;

[0033] Figure 9A schematic diagram illustrating the process of writing product code into an application system for a firmware update method provided in one embodiment of this application;

[0034] Figure 10 This is a block diagram of a firmware update apparatus provided in one embodiment of this application. Detailed Implementation

[0035] 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 specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0036] It should be noted that although the functional modules are divided in the device diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than the module division in the device or the order in the flowchart.

[0037] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.

[0038] According to one embodiment of this application, a firmware update method is provided, such as... Figure 1 As shown, the method includes steps S101 to S105.

[0039] Step S101: When the boot program of the first flash memory area of ​​the target device runs, determine the loading mode of the main program of the second flash memory area of ​​the target device;

[0040] It should be noted that in this embodiment, the storage area is divided into Flash_A area (i.e., the first flash memory area) and Flash_CD area (i.e., the second flash memory area). Flash_A is used to run the boot program. Generally speaking, the boot program is fixed in Flash_A area. Flash_CD area is used to run the main program and the product of the target device.

[0041] It should be noted that the loading mode in this embodiment refers to whether to directly jump to the Flash_CD area to run the main program after the bootloader has finished running. Specifically, the loading mode can be represented by a preset flag, such as a flag value of 1 indicating that it can directly jump to the Flash_CD area to run the main program, and a flag value of 0 indicating that jumping to the Flash_CD area to run the main program is paused.

[0042] The loading mode in this embodiment is determined by the instructions received by the bootloader. For example, if a forced recovery instruction is received, the bootloader enters the forced update mode and jumps to the Flash_CD area to run the main program; if no instruction is received, the bootloader enters the second mode and jumps directly to the Flash_CD area to run the main program.

[0043] Step S102: If the loading mode is forced update mode, obtain the application update control program from the host computer and write it into memory after the application update control program is verified.

[0044] It should be noted that the target device in this embodiment can use main control chips of the DSP28 series, STM32, ARM, etc. After the main control chip and peripheral circuit design are completed, the boot program can be burned to the FLASH_A area for the first time through the serial port or emulator. The firmware update of the FLASH_CD area is completed using the application update control program.

[0045] When in use, the bootloader communicates with the host computer through the target device's communication interface, such as a serial port, USB interface, or wireless communication module, thereby enabling the host computer to send out the application update control program.

[0046] In practice, the bootloader uses an interrupt method to receive data (i.e., the application update control program issued by the host computer) in frames and stores it in a temporary storage area until the reception is complete and it is written into memory.

[0047] Step S103: Control the bootloader to jump to the application update control program.

[0048] Specifically, after receiving a program jump instruction sent by the bootloader, the bootloader can be controlled to jump to the application update control program, thereby enabling the target device to fetch and execute instructions from RAM memory.

[0049] In this embodiment, the FLASH memory is divided into FLASH_A area and FLASH_CD area, and when temporary storage is needed, a temporary flash memory area FLASH_GH area is also allocated.

[0050] Step S104: Obtain the firmware file to be updated based on the application update control program, and perform a correctness verification process after writing it to the temporary flash memory area.

[0051] Specifically, the target device verifies the correctness of its firmware file by using the application update control program. During application, the application update control program can employ Cyclic Redundancy Check (CRC) to perform the correctness verification.

[0052] Step S105: When the correctness check passes, jump to the second flash memory area of ​​the target device to perform firmware file update processing.

[0053] It should be noted that firmware file updates include two steps: erasing the original firmware in the FLASH_CD area and writing the new firmware. The application update control program performs the erasure process in the FLASH_CD area by calling the erase function to erase the main program in the FLASH_CD area. After the erasure is completed, the write function is called to read the new firmware file in the temporary flash memory area FLASH_GH area and write it to the FLASH_CD area.

[0054] This application encapsulates the code for each stage of firmware update into an application update control program. This program, combined with a fixed bootloader, controls the target device to obtain the application update control program from the host computer and run it in memory. Since the erase and write code related to firmware updates is encapsulated into the application update control program running in memory, it reduces the risk of accidental erasure due to bootloader anomalies and saves storage space in the device's boot area. Furthermore, because the application update control program obtained from the host computer can be reloaded, even if the firmware update process is unexpectedly interrupted, it does not affect the device restarting the update process. This effectively improves the success rate of firmware updates and the maintainability of embedded products, achieving the goal of safe and reliable firmware updates.

[0055] In some embodiments, step S102 further includes:

[0056] Obtain the application update control program from the host computer, including:

[0057] After the target device establishes a communication connection with the host computer based on the bootloader, the first verification information of the application update control program is obtained.

[0058] The bootloader obtains all frame data packets sent by the host computer and calculates the second check information of all frame data packets.

[0059] If the first and second verification information are consistent, then all frame data packets are written to memory.

[0060] In practice, since the host computer sends the application update control program frame by frame according to a preset communication protocol, to ensure the integrity of the application update control program received by the target device, the host computer sends verification information of the application update control program before sending each frame of data packet. This information includes the file size and checksum. The target device can then use the file size to determine if its memory is sufficient to avoid memory overflow and system crashes during reception, and use the received bytes to determine the reception completion time and progress. The checksum is used to verify the integrity of the application update control program.

[0061] Since the application update control program's verification is performed by the bootloader, and due to the bootloader's need for simplicity, in practice, the bootloader uses verification algorithms with relatively low computational complexity, such as cumulative summation and CRC16. This embodiment uses cumulative summation, and correspondingly, the host computer also uses cumulative summation.

[0062] In practice, after the target device's boot program sends a ready signal to the host computer, the host computer first sends verification information to the target device. When the target device determines that its memory is sufficient, it then receives the application update control program sent by the host computer. This application update control program is a binary data stream sent according to a preset communication protocol.

[0063] This embodiment ensures the integrity of the application update control program by comparing the first verification information and the second verification information, thus preventing damage to the application update control program during transmission and affecting subsequent firmware updates.

[0064] In some embodiments, the firmware file includes multiple data frames, each data frame's header including a sequence number and a first checksum. The firmware file to be updated is obtained based on the application update control program, and a correctness verification process is performed after writing it to a temporary flash memory area, including:

[0065] Receive the first data frame and write it to the temporary flash memory area;

[0066] The second checksum of the first data frame is calculated based on the application update control program;

[0067] If the first checksum matches the second checksum, an acknowledgment signal is sent to the host computer to receive the next data frame.

[0068] It should be noted that the firmware file in this embodiment consists of two parts: a file header and a data body, stored in the form of a bin file with the software name, time, and version number. The file header, as shown in Table 1, includes information such as the software version number, manufacturer identifier, total checksum of the software data body, byte length of the software data body, total number of frames in the software data body, and the starting address for storing the product software, occupying 16 characters. The data body is the executable file generated after compiling the source code.

[0069] Table 1 - File Header Bytes

[0070]

[0071] In this embodiment, a correctness check is performed once for each received data frame, and an acknowledgment or retransmission request is sent to the host computer based on the check result. Compared to the bootloader, the firmware file can use a more computationally intensive check algorithm, such as CRC32.

[0072] It should be noted that the application update control program can start the verification process for each data frame after receiving the program verification command issued by the host computer. This program verification command is issued by the host computer after receiving the confirmation data frame received by the target device.

[0073] Since the application update control program in this embodiment receives data in frames via interruption, when the firmware file receiving process is unexpectedly interrupted (such as by power failure), the target device sends an interrupt signal to the host computer. After the target device is powered on again, it can receive the data frames sent by the host computer based on the interrupt time position, thereby improving the efficiency of the target device in obtaining the new version of the target file and further enhancing the security and reliability of firmware updates.

[0074] In some embodiments, step S105 further includes:

[0075] The erase function of the application update control program is called to perform an erase operation on the main program;

[0076] When a signal indicating that erasure is complete is detected, the write function of the application update control program is called to read the data body of the firmware file from the temporary flash memory area and write it to the second flash memory area to complete the update.

[0077] When the application receives a signal indicating that the correctness verification has passed, it can automatically execute the erasure process in step S105 to automate the firmware update. Alternatively, after receiving the signal indicating that the correctness verification has passed, the application update control program can send corresponding confirmation information to the host computer, allowing the user to view the verification result of the firmware file on the host computer; after receiving the confirmation erasure command from the host computer, the application update control program can execute the erasure process in step S105.

[0078] In practice, the confirmation erase command issued by the host computer can be issued by the user based on the host computer, such as based on the selection operation of the visual user interface provided by the host computer, or it can be issued at a predetermined time when the user selection operation is detected.

[0079] When the application receives a signal indicating that erasure is complete, it can automatically execute the write process in step S105 to automate the firmware update. Alternatively, after receiving the signal indicating that erasure is complete, the application update control program can send a confirmation message to the host computer, allowing the user to view the firmware update progress via the host computer. After receiving the write command from the host computer, the application update control program can execute the write operation of the new version of the firmware file.

[0080] In practice, the write command issued by the host computer can be issued by the user based on the host computer, such as a confirmation write operation based on the visual user interface provided by the host computer, or it can be issued when the user's confirmation write operation is not detected within a predetermined time.

[0081] In some embodiments, step S105 further includes: after detecting that the firmware file has been updated in the second flash memory area, generating a power-off restart signal; when the target device is powered on again based on the power-off restart signal, the boot program in the first flash memory area runs and performs a correctness verification process on the firmware file updated to the second flash memory area; if the correctness verification passes, the boot program jumps to the second flash memory area to run the firmware file; if the correctness verification fails, the boot program stays in the first flash memory area to wait for the host computer to send an update instruction to update the main program.

[0082] Because embedded devices have limited memory and flash space, this embodiment clears the application update control program in memory by powering the device back on, thus preventing the device space from being occupied and affecting firmware operation. Specifically, the application update control program calls a reset function to trigger a hardware reset, causing the device to be powered off or back on. This allows the device to verify the correctness of the firmware file updated to the second flash memory area after power-on, ensuring the integrity of the updated firmware.

[0083] In some embodiments, step S101 further includes:

[0084] When the bootloader receives a forced recovery command from the host computer within the predetermined first time, the bootloader will remain in the first flash memory area.

[0085] If the bootloader receives an update command from the host computer within the predetermined second time period, it determines that the loading mode is the forced update mode.

[0086] In practical applications, the forced recovery command can be issued by the user on the host computer, or it can be issued by the host computer after receiving a message that the update process of the target device has been interrupted.

[0087] In some embodiments, the method further includes:

[0088] If the loading mode is not the forced update mode, the bootloader performs a correctness check on the main program, and if the correctness check passes, it jumps to the second flash memory area to run the main program.

[0089] It should be noted that the non-forced update mode refers to a situation where the bootloader needs to pre-determine the main program's functionality before execution, such as whether the main program is corrupted. Under normal circumstances, the process jumps to the FLASH_CD area to run the main program. For details, please refer to... Figure 2In the bootloader, the code area data correctness detection module reads the total check value of the code data from the specified address (FLASH_B area) and performs CRC check calculation word by word from FLASH_GH area. After the calculation is completed, it judges whether the check result is equal to the total check value read. If so, it jumps to the second flash memory area to run the main program.

[0090] The following is based on Figure 3 The following is a detailed description of the embodiments of this application, using the update system shown as an example.

[0091] This embodiment of the system includes a servo motor 100 and a host computer 200. The servo motor's Flash memory includes a boot area (FLASH_A area), a product area (FLASH_CD area), a FLASH_GH area (not shown in the figure), and a FLASH_B area (not shown in the figure). In this embodiment, the program information verification value is stored in the FLASH_B area. The boot program is burned into the FLASH_A area, the main program is burned into the FLASH_CD area, the FLASH_GH area is a temporary cache area for storing firmware files to be updated, and the FLASH_B area is an area for storing information (such as verification values). The main program (firmware) running in the FLASH_CD area includes firmware update functions, providing commands such as receiving program information and code from the host computer, calculating program verification values, initiating memory erasure, and writing code, and executing corresponding functions.

[0092] The bootloader in this embodiment is mainly used to handle abnormal issues during the upgrade process and increase the reliability and security of software updates. It mainly includes a FLASH_CD area code correctness detection module, a software forced recovery module, and an online update module.

[0093] The code correctness detection module is used to accumulate and verify the code in the FLASH_CD area upon power-up to confirm the correctness of the code in the FLASH_CD area. If the verification is correct, it jumps to the FLASH_CD area to execute the program. If the verification fails, it does not jump to the FLASH_CD area but stays in the boot area to wait for the update instruction to update the product code in the product's FLASH_CD area.

[0094] The software forced recovery module is used to handle abnormal situations such as data errors in the FLASH_CD area or distortion of individual data bits caused by external interference during the update process. After the servo motor powers on and enters the boot sector program, the software forced recovery module is executed first. After receiving the product software forced recovery signal sent by the host computer within a specified waiting time, this module forces the program flow to stop in the boot sector, waiting for the update instruction to update the code in the FLASH_CD area.

[0095] Reference Figure 4After the device is powered on, the online update module first checks whether a software forced recovery command has been received within a specified time. If so, the software forced recovery module handles the process, forcing the program flow to remain in the boot area, waiting for the update command to update the code in the FLASH_CD area. If not, the code correctness detection module is triggered to determine whether the product code verification is correct. If the product code verification is correct, the operation performed in this embodiment is not to jump to the FLASH_CD area and to enter the waiting for update command state. The host computer can issue an update command to update the process within a predetermined startup time. If the online update module does not receive an update command from the host computer within the predetermined startup time, or if it confirms an instruction to jump to the FLASH_CD area, the online update module uses the completed application update control program to update the main program in the FLASH_CD area.

[0096] Reference Figure 4 It can be seen that the communication between the servo motor and the host computer includes uploading and downloading program information, uploading and downloading program code, program verification, erasing of product code area, and writing of product code.

[0097] like Figure 5 As shown, the upload / download program information function receives a file header containing the total number of file frames, the total checksum, the data length, and the starting address for storing the code, and then parses and saves the file header information. The upload / download program code flow is used to receive and store the executable file code data of the product software to be updated in frames.

[0098] like Figure 6 As shown, the upload and download program code flow performs frame counting and checksum calculation on the received data frames, and returns the current frame count and checksum results to the host computer; and allocates a temporary buffer area (FLASH_GH area) to temporarily store the received code.

[0099] The program verification process is as follows: Figure 7 As shown, after the executable file data is received, the total CRC check value of the code in the temporary buffer area is calculated, compared with the total CRC check value received through the uploading and downloading program information function, and the comparison result is returned to the host computer.

[0100] The product code erasure process is used to erase the memory area where product code is stored, preparing it for writing the code to be updated. Figure 8 As shown. Because the FLASH_CD erasure process is slow, if the watchdog timer is enabled in the software, it must be disabled before erasure to prevent the controller from resetting and restarting during the erasure process. Simultaneously, the FLASH_CD erasure result needs to be evaluated and returned to the host computer. During application, after the servo receives the program verification command from the host computer, it calculates the code verification value of the FLASH_GH area and compares it with the stored program information verification value. The comparison is confirmed by the target device to complete the cached code verification.

[0101] The product code writing process is used to write the code stored in the temporary cache to the specified address area to complete the code update, such as... Figure 9 As shown. When using this function, similar to the erase function, if the watchdog timer is enabled, it must be disabled before writing to prevent the controller from resetting and restarting during the writing process; the writing result of the FLASH_CD area should be judged and the result returned to the host computer.

[0102] One embodiment of this application provides a firmware update apparatus, such as... Figure 10 As shown, the device 20 includes: a boot sector determination processing module 201, a boot sector processing module 202, a program switching processing module 203, a firmware file verification module 204, and a firmware file update module 205.

[0103] The boot sector determination and processing module is used to determine the loading mode of the main program of the target device when the boot program of the first flash memory area of ​​the target device is running;

[0104] The boot sector processing module is used to obtain the application update control program from the host computer if the loading mode is forced update mode, and write it into memory after the application update control program passes the verification.

[0105] The program switching processing module is used to control the bootloader to jump to the application update control program, and to obtain the firmware file to be updated based on the application update control program and write it to the temporary flash memory area.

[0106] The firmware file verification module is used to perform a correctness verification process on the firmware file based on the application update control program;

[0107] The firmware file update module is used to jump to the second flash memory area of ​​the target device to perform firmware file update processing when the correctness verification passes.

[0108] This application encapsulates the code for each stage of firmware update into an application update control program. This program, combined with a fixed bootloader, controls the target device to obtain the application update control program from the host computer and run it in memory. Since the erase and write code related to firmware updates is encapsulated into the application update control program running in memory, it reduces the risk of accidental erasure due to bootloader anomalies and saves storage space in the device's boot area. Furthermore, because the application update control program obtained from the host computer can be reloaded, even if the firmware update process is unexpectedly interrupted, it does not affect the device restarting the update process. This effectively improves the success rate of firmware updates and the maintainability of embedded products, achieving the goal of safe and reliable firmware updates.

[0109] Furthermore, the boot sector processing module includes:

[0110] The first verification information acquisition submodule is used to acquire the first verification information of the application update control program after the target device based on the boot program establishes a communication connection with the host computer.

[0111] The first verification information calculation module is used to obtain all frame data packets sent by the host computer based on the boot program, and to calculate the second verification information of all frame data packets.

[0112] The control software verification processing module is used to write all frame data packets into memory if the first verification information and the second verification information are consistent.

[0113] Furthermore, the firmware file includes multiple data frames, each data frame's header including a sequence number and a first checksum. The firmware file verification module includes:

[0114] Firmware frame data storage submodule, used to receive the first data frame and write it to the temporary flash memory area;

[0115] The firmware frame checksum calculation submodule is used to calculate the second checksum of the first data frame based on the application update control program.

[0116] The firmware frame verification processing submodule is used to send an acknowledgment signal to the host computer if the first checksum matches the second checksum, so as to receive the next data frame.

[0117] Furthermore, the firmware file update module includes:

[0118] The firmware erasure submodule is used to call the erase function of the application update control program to perform erasure processing on the main program;

[0119] The new firmware writing submodule is used to call the write function of the application update control program when the erase completion signal is detected. The write function reads the data body of the firmware file in the temporary flash memory area and writes it to the second flash memory area to complete the update.

[0120] Furthermore, the firmware update module also includes:

[0121] The control software clearing submodule is used to clear the application update control program from memory after the firmware file has been updated in the second flash memory area.

[0122] Furthermore, the boot sector judgment and processing module controls the boot program of the first flash memory area of ​​the target device to run when it detects at least one of the following situations: the main program is damaged; or a forced update command is received from the host computer.

[0123] Furthermore, the device also includes:

[0124] The main program runs a submodule that controls the bootloader to jump to the main program if the loading mode is the second mode.

[0125] The firmware update device in this embodiment can execute the firmware update method shown in the embodiment of this application. The implementation principle is similar, and will not be described again here.

[0126] Another embodiment of this application provides an electronic device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the above-described method.

[0127] Specifically, the processor can be a CPU, a general-purpose processor, a DSP, an ASIC, an FPGA, or other programmable logic device, transistor logic device, hardware component, or any combination thereof. It can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. The processor can also be a combination that implements computational functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.

[0128] Specifically, the processor connects to the memory via a bus, which may include a path for transmitting information. The bus can be a PCI bus or an EISA bus, etc. The bus can be divided into address bus, data bus, control bus, etc.

[0129] The memory may be ROM or other types of static storage devices that can store static information and instructions, RAM or other types of dynamic storage devices that can store information and instructions, or EEPROM, CD-ROM or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer, but is not limited thereto.

[0130] Optionally, the memory stores the code of a computer program that executes the scheme of this application, and the execution is controlled by a processor. The processor executes the application code stored in the memory to operate the apparatus provided in the above embodiments.

[0131] Another embodiment of this application provides a computer-readable storage medium storing computer-executable instructions for performing the above-described method.

[0132] 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.

[0133] Those skilled in the art will understand that all or some of the steps and systems in the methods disclosed above can be implemented as software, firmware, hardware, and suitable combinations thereof. Some or all of the physical components can be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit. Such software can be distributed on a computer-readable medium, which can include computer storage media (or non-transitory media) and communication media (or transient media). As is known to those skilled in the art, the term computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and is accessible to a computer. Furthermore, as is known to those skilled in the art, communication media typically contain computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.

[0134] The above is a detailed description of the preferred embodiments of this application. However, this application is not limited to the above embodiments. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of this application. All such equivalent modifications or substitutions are included within the scope defined by the claims of this application.

Claims

1. A firmware update method, characterized in that, include: When the bootloader of the first flash memory area of ​​the target device runs, the loading mode of the main program in the second flash memory area of ​​the target device is determined; If the loading mode is a forced update mode, the application update control program is obtained from the host computer and written into memory after the application update control program is verified. The bootloader is redirected to the application update control program. The application update control program obtains the firmware file to be updated and performs a correctness verification process after writing it to the temporary flash memory area. When the correctness check passes, the process jumps to the second flash memory area of ​​the target device to perform an update on the firmware file. The firmware file includes multiple data frames, each data frame's header including a sequence number and a first checksum. The process of obtaining the firmware file to be updated based on the application update control program and performing a correctness verification process after writing it to the temporary flash memory area includes: Receive the first data frame and write it to the temporary flash memory area; The application update control program calculates the second checksum of the first data frame; If the first checksum matches the second checksum, an acknowledgment signal is sent to the host computer to receive the next data frame. The procedure for obtaining application update control from the host computer includes: After the bootloader controls the target device to establish a communication connection with the host computer, it obtains the first verification information of the application update control program; Based on the bootloader, all frame data packets sent by the host computer are obtained, and the second verification information of all frame data packets is calculated; If the first verification information and the second verification information are consistent, then all frame data packets are written into memory; The step of jumping to the second flash memory area of ​​the target device to perform an update process on the firmware file includes: The erase function of the application update control program is invoked to perform an erase process on the main program; When a signal indicating that erasure is complete is detected, the write function of the application update control program is called to read the data body of the firmware file from the temporary flash memory area and write it to the second flash memory area to complete the update; The step of jumping to the second flash memory area of ​​the target device to perform update processing on the firmware file further includes: After detecting that the firmware file has been updated in the second flash memory area, a power-off restart signal is generated; When the target device is powered on again based on the power failure restart signal, the boot program in the first flash memory area runs and performs a correctness verification process on the firmware file updated to the second flash memory area. If the correctness check passes, then proceed to the second flash memory area to run the firmware file; If the correctness check fails, the boot program remains in the first flash memory area to wait for the host computer to send an update command to update the main program; When the boot program of the first flash memory area of ​​the target device is running, determining the loading mode of the main program of the second flash memory area of ​​the target device includes: When the bootloader receives a forced recovery command sent by the host computer within a predetermined first time, the bootloader remains in the first flash memory area. If the bootloader receives an update instruction from the host computer within a predetermined second time period, then the loading mode is determined to be a forced update mode. The method further includes: If the loading mode is not a forced update mode, then the bootloader performs a correctness check on the main program, and if the correctness check passes, it jumps to the second flash memory area to run the main program.

2. A firmware update device, characterized in that, include: The boot sector determination and processing module is used to determine the loading mode of the main program of the target device when the boot program of the first flash memory area of ​​the target device is running; The boot sector processing module is used to obtain the application update control program from the host computer if the loading mode is a forced update mode, and write it into memory after the application update control program passes the verification. The program switching processing module is used to control the bootloader to jump to the application update control program, and to obtain the firmware file to be updated based on the application update control program and write it to the temporary flash memory area. The firmware file verification module is used to perform a correctness verification process on the firmware file based on the application update control program. The firmware file update module is used to jump to the second flash memory area of ​​the target device to perform update processing on the firmware file when the correctness verification passes; The firmware file includes multiple data frames, and the header of each data frame includes a sequence number and a first checksum. The firmware file verification module is specifically used to: receive the first data frame and write it into the temporary flash memory area. The application update control program calculates the second checksum of the first data frame; if the first checksum matches the second checksum, an acknowledgment signal is sent to the host computer to receive the next data frame. The boot sector processing module is specifically used to obtain the first verification information of the application update control program after the boot program controls the target device to establish a communication connection with the host computer; obtain all frame data packets sent by the host computer based on the boot program, and calculate the second verification information of all frame data packets; if the first verification information and the second verification information are consistent, write all frame data packets into memory. The firmware file verification module is specifically used to call the erase function of the application update control program to perform erase processing on the main program; when a signal indicating that the erase is complete is detected, the write function of the application update control program is called to read the data body of the firmware file in the temporary flash memory area and write it to the second flash memory area to complete the update; after the firmware file is detected to have been updated in the second flash memory area, a power-off restart signal is generated; when the target device is powered on again based on the power-off restart signal, the boot program in the first flash memory area runs and performs a correctness verification process on the firmware file updated to the second flash memory area; If the correctness check passes, the program jumps to the second flash memory area to run the firmware file; if the correctness check fails, the boot program remains in the first flash memory area to wait for the host computer to send an update command to update the main program. The boot sector determination and processing module is specifically used to cause the boot program to remain in the first flash memory area when the boot program receives a forced recovery command sent by the host computer within a predetermined first time period; if the boot program receives an update command sent by the host computer within a predetermined second time period, it determines that the loading mode is a forced update mode. The boot sector processing module is also used to perform a correctness check on the main program based on the bootloader if the loading mode is not a forced update mode, and jump to the second flash memory area to run the main program if the correctness check passes.

3. An electronic device, characterized in that, The device includes a processor and a memory, the memory storing computer-readable instructions, and the processor being configured to execute the computer-readable instructions, wherein the computer-readable instructions, when executed, perform the method of claim 1.

4. A computer-readable storage medium, characterized in that, The device stores computer-executable instructions for performing the method of claim 1.