Firmware online upgrading method and system
By using the backup area and upgrade area of external memory in the online firmware upgrade, the problems of low efficiency and poor security of traditional firmware upgrades are solved, rapid recovery and efficient updates are achieved, and the stability and maintenance convenience of the system are improved.
Patent Information
- Application Number
- CN202411300436.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-18
- Publication Date
- 2024-12-31
AI Technical Summary
Traditional firmware online upgrade efficiency and poor security, communication errors are difficult to recover during the upgrade process, and the MCU startup time and maintenance costs are increased.
Use the backup area and upgrade area of external memory. BootLoader checks whether there are programs backups in the backup area at startup. If so, jump to the application; when receiving the upgrade request, the upgrade file is stored in the upgrade area and during the upgrade process Automatically copy and backup from the backup area to the processor to ensure stable system operation.
It improves the efficiency and security of online firmware upgrades, shortens the startup time, extends the service life of the microcontroller's internal memory, achieves seamless automatic recovery and high fault tolerance, and enhances the stability and maintenance convenience of the system.
Smart Images

Figure CN119226039A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of firmware online upgrade, and in particular to a firmware online upgrade method and system. Background Art
[0002] In traditional embedded systems, bootloader code and application code are generally used to update the application online to achieve firmware upgrade. The bootloader code is used to receive the upgrade file, then write it into the internal Flash of the MCU, enter the application through the microcontroller, and then complete the firmware upgrade operation through the application code.
[0003] In the prior art, application upgrades require receiving the upgrade file from the serial port through the Bootloader code when the device starts. This process needs to be completed during the device startup phase, which increases the startup time. In addition, traditional firmware online upgrades are generally performed when the device is powered on. After the serial port of the Bootloader program receives the upgrade file, it is written frame by frame into the internal Flash of the MCU. This type of firmware online upgrade is relatively inefficient, and if a communication error occurs during the upgrade process, it will make the original firmware program difficult to restore and there will be omissions. In addition, there is a delay when the Bootloader determines whether an upgrade is required, which increases the time it takes for the MCU to enter the APP program; resulting in a longer startup time for the application. At the same time, there are certain security risks in upgrading applications through the serial port, such as unencrypted transmissions that may be intercepted or tampered with, and unverified firmware that may introduce security vulnerabilities. Summary of the invention
[0004] The problem solved by the present invention is how to improve the efficiency and security of online firmware upgrade.
[0005] In order to solve the above problems, the present invention provides a firmware online upgrade method and system.
[0006] In a first aspect, the present invention provides a firmware online upgrade method, which is applied to a processor, wherein the processor includes an external memory, and the external memory includes a backup area and an upgrade area. The method includes:
[0007] When the processor is started, determining whether the backup area is provided with a program backup of the application program through a BootLoader program;
[0008] If the backup area is configured with the program backup, jumping into the application program through the upgrade area;
[0009] When receiving a firmware upgrade request, storing the upgrade file in the upgrade area of the external memory;
[0010] The application is upgraded according to the upgrade file in the upgrade area to complete the online update of the firmware. If the upgrade fails, the program backup in the backup area is copied to the processor, and the processor is restarted.
[0011] Optionally, when the processor is started, determining whether the backup area is provided with a program backup of the application program through a BootLoader program includes:
[0012] When the processor is started, judging whether the backup area is provided with the program backup through the BootLoader program;
[0013] If the judgment result is that it is not set, obtaining the program code of the application, and storing the program code as the program backup in the backup area;
[0014] If the judgment result is that it has been set, it is confirmed that the backup area is set with the program backup.
[0015] Optionally, judging whether the backup area is provided with the program backup by the BootLoader program includes:
[0016] Obtaining a flag bit of the backup area, and determining whether the flag bit is non-empty;
[0017] If the flag bit is not empty, it is determined that the backup area is provided with the program backup;
[0018] If the flag is empty, it is determined that the backup area does not have the program backup set.
[0019] Optionally, if the backup area is provided with the program backup, jumping into the application program through the upgrade area includes:
[0020] Determining whether the upgrade area is provided with the upgrade code;
[0021] If the result of the judgment is that an upgrade code is set, the application is upgraded according to the upgrade file in the upgrade area;
[0022] If the result of the determination is that the upgrade code is not set, the application is jumped into.
[0023] Optionally, the determining whether the upgrade area is provided with the upgrade code comprises:
[0024] Obtaining a flag bit of the upgrade area, and determining whether the program in the upgrade area is a new version according to the flag bit;
[0025] If the flag indicates a new version, it is determined that the upgrade area is provided with the upgrade code;
[0026] If the flag indicates an old version or is empty, it is determined that the upgrade code does not exist in the upgrade area.
[0027] Optionally, when receiving a firmware upgrade request, storing the upgrade file in the upgrade area of the external memory includes:
[0028] When a firmware upgrade request is received, obtaining an upgrade file through the application;
[0029] The upgrade file is stored in the upgrade area of the external memory, and a flag bit of the upgrade area is updated.
[0030] Optionally, when a firmware upgrade request is received, storing the upgrade file in the upgrade area of the external memory further comprises:
[0031] When the upgrade file is stored in the upgrade area, determining whether the upgrade area has storage abnormality;
[0032] If the judgment result is that no abnormality is stored, the flag bit of the backup area is set to non-empty, and the BootLoader is restarted;
[0033] If the judgment result is that the storage is abnormal, the flag bit of the backup area is set to empty and the BootLoader is restarted.
[0034] Optionally, the upgrading the firmware according to the upgrade file in the upgrade area includes:
[0035] When it is determined that the upgrade area is provided with the upgrade code, the upgrade file of the upgrade area is updated to the processor to complete the application upgrade.
[0036] Optionally, jumping into the application through the upgrade area includes:
[0037] When the upgrade area jumps into the application, determining whether the jump fails;
[0038] If the result of the judgment is that the jump fails, the program backup in the backup area is copied to the single-chip microcomputer; and the BootLoader is restarted.
[0039] In a second aspect, the present invention provides a firmware online upgrade system, the online upgrade system is applied to a processor, the processor includes an external memory, the external memory includes a backup area and an upgrade area, the system includes:
[0040] Backup unit: used for determining whether the backup area is provided with a program backup of the application program through a BootLoader program when the processor is started;
[0041] An upgrade unit: used for jumping into the application program through the upgrade area if the backup area is provided with the program backup;
[0042] A transfer unit: used for storing the upgrade file in the upgrade area of the external memory when receiving a firmware upgrade request;
[0043] Upgrading unit: also used to upgrade the application according to the upgrade file in the upgrade area to complete the online update of the firmware. If the upgrade fails, the program backup in the backup area is copied to the processor and the processor is restarted.
[0044] The firmware online upgrade method and system of the present invention quickly checks the backup area through BootLoader when the system starts, ensuring that even if any abnormality occurs during the application upgrade process, it can quickly restore to a stable application backup, thereby ensuring the continuous operation of the system and the security of the data. Secondly, when the backup area confirms the existence of a valid backup, the system can directly skip the lengthy upgrade judgment logic and quickly enter the application, reducing the startup delay. At the same time, in the application, there is no need to wait for the upgrade instruction for the application upgrade request and the reception of the upgrade file, which greatly shortens the boot time. In addition, storing the upgrade file in the upgrade area of the external memory not only reduces the read and write pressure on the internal memory of the single-chip microcomputer and extends its service life, but also realizes the rapid update of the firmware. Moreover, in the present invention, the key fault-tolerant mechanism is that when an application upgrade request is received, the storage of the upgrade file and the upgrade process are both performed in an external memory. If any problem is encountered during the upgrade process, such as communication error, file damage or system instability, the BootLoader will terminate the upgrade process and automatically copy the firmware backup from the backup area to the single-chip microcomputer to ensure that the system can quickly recover to the previous stable operation state; this process is seamless and automatic, avoiding the need for manual intervention, thereby significantly improving the stability and upgrade efficiency of the system. In addition, since the upgrade file is only operated in the upgrade area, even if the upgrade fails, it will not affect the stable firmware in the backup area, ensuring the security and high fault tolerance of the system. Finally, by simplifying the functions of the BootLoader and optimizing the data interaction process, the speed and success rate of the application upgrade are improved, and the stability of the system and the convenience of maintenance are enhanced. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] Figure 1 This is a flowchart of a method for online firmware upgrade according to an embodiment of the present invention;
[0046] Figure 2 This is a second flowchart of the firmware online upgrade method according to an embodiment of the present invention;
[0047] Figure 3 The figure is a schematic diagram of the structure of the firmware online upgrade system according to an embodiment of the present invention. DETAILED DESCRIPTION
[0048] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0049] In the related art, in traditional embedded systems, the online firmware upgrade has the following problems:
[0050] Bootloader is a program in embedded system and runs first when the device starts. It is used to initialize hardware and load the main application (APP) code. In the application upgrade scenario, Bootloader is also used to receive and write new firmware code. However, Bootloader code is determined at design time and is static and will not change due to application upgrades, which means that the function and efficiency of Bootloader will limit the performance and efficiency of the entire upgrade process.
[0051] In the prior art, application upgrades are usually performed through serial port communication. The Bootloader receives firmware files from the outside through the serial port. This process relies on stable communication connections and accurate data transmission. Any communication errors may cause firmware damage or upgrade failure. However, the serial port transmission speed is relatively slow, and the firmware files are usually large, which makes the entire upgrade process time-consuming; this inefficient transmission and writing process also increases the user's waiting time and affects the user experience. In addition, during the application upgrade process, if a communication error or data corruption occurs, the traditional Bootloader usually does not have an effective error recovery mechanism, which will also cause the device to be unable to recover to the original stable firmware state after the application upgrade fails, resulting in the device being unusable. In addition, the Bootloader needs to determine whether the application needs to be upgraded each time the device is started. This judgment process also increases the time for the device to start and delays the time for users to access the application. This delay is particularly obvious in the scenario of frequent upgrades. In addition, during the application upgrade process, the new firmware code is usually written directly to the internal Flash memory of the MCU. Frequent write operations may shorten the service life of the Flash memory and increase the maintenance cost of the device. Furthermore, application upgrades via the serial port may present security risks, such as unencrypted transmissions that may be intercepted or tampered with, and unverified firmware that may introduce security vulnerabilities.
[0052] In summary, traditional firmware online upgrade methods have problems such as low efficiency, poor error recovery, upgrade delay and security.
[0053] In view of the problems existing in the above-mentioned related technologies, Figure 1 As shown, the present invention provides a firmware online upgrade method, the firmware online upgrade method is applied to a processor, the processor includes an external memory, the external memory includes a backup area and an upgrade area, the method includes:
[0054] When the processor is started, it is determined through the BootLoader program whether the backup area is provided with a program backup of the application program.
[0055] Specifically, when the processor starts, it first checks whether the backup area of the external memory is set with a program backup of the application. This step ensures that the system can start from a known good state. By using the fast access capability of the external memory, the BootLoader can quickly determine the system state, thereby reducing the system startup time. Ensure that the program backup of the application is stored to ensure that when an application error occurs in the processor, it can be restored through the program backup.
[0056] If the backup area is provided with the program backup, the application program is entered through the upgrade area.
[0057] Specifically, when it is confirmed that the backup area has been set up for program backup, the BootLoader will jump into the application program through the upgrade area. The dual redundancy feature of the external memory is utilized to ensure that even if a problem occurs during the upgrade process, the system can be restored from the backup area, thereby improving the stability and reliability of the system.
[0058] When a firmware upgrade request is received, the upgrade file is stored in the upgrade area of the external memory.
[0059] Specifically, when the system receives an application upgrade request, the application will be responsible for receiving the upgrade file. When the user actively initiates the upgrade, the participation of the software program reduces the burden of the BootLoader and simplifies the upgrade process. The received upgrade file will be stored in the upgrade area of the external memory, thereby ensuring the safe storage of the new firmware. At the same time, due to the use of external memory, the number of writes to the internal memory of the microcontroller is reduced, extending its service life.
[0060] The application is upgraded according to the upgrade file in the upgrade area to complete the online update of the firmware. If the upgrade fails, the program backup in the backup area is copied to the processor, and the processor is restarted.
[0061] Specifically, after the storage is completed, the system will upgrade the application according to the upgrade file in the upgrade area. This step is the ultimate goal of the entire upgrade process. By copying the upgrade file in the upgrade area to the processor, the application in the processor is updated and upgraded. If any problem is encountered during the upgrade process, that is, the upgrade fails, such as file corruption, write errors or system instability, the BootLoader will immediately stop the upgrade operation and start the rollback mechanism. The system will automatically extract the previously stored stable program backup from the backup area and copy it to the processor to ensure that the application can be restored to a known and stable working state. After completing this process, the system will restart the processor, load the new stable firmware, and continue to operate normally; ensuring that the continuous operation of the system is not affected.
[0062] The firmware online upgrade method of the present invention quickly checks the backup area through BootLoader when the system starts, ensuring that even if any abnormality occurs during the application upgrade process, it can quickly restore to a stable application backup, thereby ensuring the continuous operation of the system and the security of the data. Secondly, when the backup area confirms that there is a valid backup, the system can directly skip the lengthy upgrade judgment logic and quickly enter the application, reducing the startup delay. At the same time, in the application, there is no need to wait for the upgrade instruction for the application upgrade request and the reception of the upgrade file, which greatly shortens the boot time. In addition, storing the upgrade file in the upgrade area of the external memory not only reduces the read and write pressure on the internal memory of the single-chip microcomputer, prolongs its service life, but also realizes the rapid update of the firmware. Moreover, in the present invention, the key fault-tolerant mechanism is that when an application upgrade request is received, the storage of the upgrade file and the upgrade process are both performed in an external memory. If any problem is encountered during the upgrade process, such as communication error, file damage or system instability, the BootLoader will terminate the upgrade process and automatically copy the firmware backup from the backup area to the single-chip microcomputer to ensure that the system can quickly recover to the previous stable operation state; this process is seamless and automatic, avoiding the need for manual intervention, thereby significantly improving the stability and upgrade efficiency of the system. In addition, since the upgrade file is only operated in the upgrade area, even if the upgrade fails, it will not affect the stable firmware in the backup area, ensuring the security and high fault tolerance of the system. Finally, by simplifying the functions of the BootLoader and optimizing the data interaction process, the speed and success rate of the application upgrade are improved, and the stability of the system and the convenience of maintenance are enhanced.
[0063] Optionally, when the processor is started, determining whether the backup area is provided with a program backup of the application program through a BootLoader program includes:
[0064] When the processor is started, judging whether the backup area is provided with the program backup through the BootLoader program;
[0065] If the judgment result is that it is not set, obtaining the program code of the application, and storing the program code as the program backup in the backup area;
[0066] If the judgment result is that it has been set, it is confirmed that the backup area is set with the program backup.
[0067] Specifically, when the processor is started, the first thing executed is to determine whether the backup area already contains the program backup of the application. This determination process is completed by checking the specific identifier of the backup area. If the backup area has not set up a program backup, the BootLoader will actively obtain the currently running application code and store these codes as backups in the backup area, ensuring that even if problems occur during the subsequent upgrade process, the system can be restored to the original stable state from the backup area. If the backup area has already set up a program backup, the BootLoader will confirm this and continue the subsequent startup process.
[0068] In this optional embodiment, through the automatic detection and backup mechanism of BootLoader, it is ensured that there is always a reliable application backup in the external memory, reducing the dependence on the internal memory of the microcontroller and reducing the risk of the system failing to start due to damage to the internal memory.
[0069] Optionally, judging whether the backup area is provided with the program backup by the BootLoader program includes:
[0070] Obtaining a flag bit of the backup area, and determining whether the flag bit is non-empty;
[0071] If the flag bit is not empty, it is determined that the backup area is provided with the program backup;
[0072] If the flag is empty, it is determined that the backup area does not have the program backup set.
[0073] Specifically, first, BootLoader obtains the flag bit of the backup area. This flag bit is key information for indicating whether the backup area has stored a program backup of the application. If the flag bit is not empty, that is, there is a clear value, BootLoader determines that the backup area has set up a program backup, which means that the system can safely restore or continue to execute the application from the backup area. If the flag bit is empty, it means that the backup area has not yet stored a program backup, or the backup information has not been successfully written. In a preferred embodiment of the present invention, BootLoader first determines whether there is a program backup in the backup area when the module is started. If not, the current code is written to the backup area of the external memory. If so, it further determines whether the upgrade area is an upgrade code, thereby determining the status of the backup area through the flag bit.
[0074] In this optional embodiment, by checking the flag bit, the BootLoader can make a decision quickly, reducing the time of system startup and recovery, and improving the response speed and reliability of the system. In addition, when the flag bit is empty, the BootLoader can identify the need to update the backup area, thereby triggering the backup or upgrade process to ensure that the system always has the latest application backup.
[0075] Optionally, if the backup area is provided with the program backup, jumping into the application program through the upgrade area includes:
[0076] Determining whether the upgrade area is provided with the upgrade code;
[0077] If the judgment result is that an upgrade code is set, the application is upgraded according to the upgrade file in the upgrade area;
[0078] If the result of the determination is that the upgrade code is not set, the application is jumped into.
[0079] Specifically, when the BootLoader determines that the backup area has been set up with a program backup, the system will proceed to the next step, that is, jump into the application through the upgrade area. First, it is necessary to determine whether the upgrade code has been set up in the upgrade area. If the upgrade area already contains new firmware code, the firmware update process will be executed according to these upgrade files. In a preferred embodiment of the present invention, the user actively initiates an application upgrade request and sends the corresponding firmware file. The application then receives these firmware files and stores them in the upgrade area of the external memory, copies the upgrade files in the upgrade area to the processor, and updates the application in the processor. After the storage is completed, the flag is updated and reset. After startup, the BootLoader checks the upgrade flag and executes the firmware write operation. If the upgrade code is not set in the upgrade area, that is, there is no application that needs to be updated, the system will directly jump into the application and continue to execute the existing functions.
[0080] In this optional embodiment, by setting up dual redundant partitions in the external memory, the system can ensure the existence of the current application program even if the upgrade fails, greatly improving the stability and reliability of the system. Secondly, by determining whether there is an upgrade code in the upgrade area, the system can flexibly decide whether to perform the upgrade or continue to use the existing application program, avoiding unnecessary upgrade operations and improving efficiency.
[0081] Optionally, the determining whether the upgrade area is provided with the upgrade code comprises:
[0082] Obtaining a flag bit of the upgrade area, and determining whether the program in the upgrade area is a new version according to the flag bit;
[0083] If the flag indicates a new version, it is determined that the upgrade area is provided with the upgrade code;
[0084] If the flag indicates an old version or is empty, it is determined that the upgrade code does not exist in the upgrade area.
[0085] Specifically, when the BootLoader program is started, it first obtains the flag bit of the upgrade area. This flag bit is a status indicator used to distinguish whether the program in the upgrade area is the latest version. If the flag bit indicates new, it means that the upgrade area contains new firmware code. The BootLoader will determine that the upgrade area is set with the code to be upgraded and execute the firmware update process based on these codes. If the flag bit indicates "old", it means that the program in the upgrade area is not a new version, it may be a previous backup or old firmware. At this time, the BootLoader will determine that there is no code to be upgraded in the upgrade area, thereby avoiding unnecessary upgrade operations and directly jumping into the application.
[0086] In this optional embodiment, by checking the flag bit of the upgrade area, the BootLoader can quickly determine whether the upgrade operation needs to be performed, which reduces the judgment time of the system at each startup and improves the startup efficiency. Secondly, it ensures that the upgrade is only performed when new firmware is indeed available, avoiding repeated writing of old firmware.
[0087] Optionally, when receiving a firmware upgrade request, storing the upgrade file in the upgrade area of the external memory includes:
[0088] When a firmware upgrade request is received, obtaining an upgrade file through the application;
[0089] The upgrade file is stored in the upgrade area of the external memory, and a flag bit of the upgrade area is updated.
[0090] Specifically, when the system receives an application upgrade request, the application will be responsible for obtaining the upgrade file, wherein the user actively initiates an application upgrade request and sends the corresponding firmware file, and then the application receives these firmware files and stores them in the upgrade area. After receiving the firmware files, the application stores these files in the upgrade area of the external memory and performs a key operation, which is to set the flag bit of the upgrade area to new. This operation is an important part of the upgrade process because it provides a clear indication to the BootLoader that the upgrade area now contains new firmware code and is ready for upgrading. The upgrade can be performed after the next BootLoader startup.
[0091] In this optional embodiment, the upgrade file is obtained and stored by the application, which ensures the user interactivity and flexibility of the upgrade process, allowing the user to actively initiate the upgrade when necessary. The upgrade file is stored in the upgrade area of the external memory and the flag is updated, providing the BootLoader with clear upgrade instructions, improving the reliability and certainty of the upgrade process.
[0092] Optionally, the upgrading the firmware according to the upgrade file in the upgrade area includes:
[0093] When it is determined that the upgrade area is provided with the upgrade code, the upgrade file of the upgrade area is updated to the processor to complete the application upgrade.
[0094] Specifically, once the BootLoader confirms the existence of new upgrade code by checking the flag bit of the upgrade area, the application upgrade operation will be executed. The BootLoader will be responsible for transferring these codes from the upgrade area of the external memory to the internal memory of the single-chip microcomputer to complete the firmware update. If the write is successful, the system will update and run the new firmware. Among them, the upgrade process is to burn the upgrade file. In a preferred embodiment of the present invention, the upgrade file of the Bootloader program is imported into the J-Flash software, and the Flash address IROM burned into the chip is set to 0x8000000 through the J-Flash software, size: 0x100000, and the partition is completed and the program is burned. The hex file of the application is imported into the J-Flash software, and the Flash address IROM burned into the chip is set to 0x8010000 through the J-Flash software, size: 0x100000, and the partition is completed and the program is burned.
[0095] In this optional embodiment, by performing the firmware upgrade operation on the external memory, the reliance on the internal memory of the single-chip microcomputer is reduced, thereby extending its service life and reducing the loss caused by frequent writing.
[0096] Optionally, when a firmware upgrade request is received, storing the upgrade file in the upgrade area of the external memory further comprises:
[0097] When the upgrade file is stored in the upgrade area, determining whether the upgrade area has storage abnormality;
[0098] If the judgment result is that no abnormality is stored, the flag bit of the backup area is set to non-empty, and the BootLoader is restarted;
[0099] If the judgment result is a storage exception, the flag bit of the backup area is set to empty, and the BootLoader is restarted. Specifically, when the application receives an application upgrade request and sends the corresponding upgrade file, these upgrade files are stored in the upgrade area. In the process of storing the upgrade file, the system will determine whether a storage exception has occurred in the upgrade area. If the storage process is normal, the system sets the flag bit of the backup area to non-empty, indicating that there is a valid program backup in the backup area, and then restarts the BootLoader so that the application can be upgraded according to the new upgrade file at the next startup. On the contrary, if an exception occurs in the storage process, the system sets the flag bit of the backup area to empty, which indicates that the storage operation in the upgrade area has failed, and the BootLoader needs to take corresponding error recovery measures when restarting. In a preferred embodiment of the present invention, after the source code is written, the firmware will be compiled by the programming software Keil to generate a firmware hex file, that is, an upgrade file. This file generated is generated by the programming software compilation and does not need to be verified. The upgrade file will be checked frame by frame during the transmission of the upgrade file. A sum check is generated for one byte at the end of each frame, and the data of this frame is determined to be correct by comparing the checksum. If there is an error, the BootLoader will take corresponding error recovery measures when restarting.
[0100] In summary, combined with Figure 2As shown, in a preferred embodiment of the present invention, the backup area of the external memory is set to the external Flash partition 1, the upgrade area is set to the external Flash partition 2, and the application is the APP program. The application upgrade process of the present invention is that when the system or module is powered on, the BootLoader is started, and the flag is used to determine whether the external Flash partition 1 is empty. If so, the APP program is written to the Flash partition 1. If not, it continues to determine whether the external Flash partition 2 is new. If so, it means that the application needs to be upgraded. Therefore, the program of Flash partition 2 is updated to the single-chip microcomputer, and when the update is completed, it jumps to the APP program. If not, it directly jumps to the APP program. During the jump process, if the jump fails, the Flash partition 2 is set to have no program, and then the backup program in the external Flash partition 1 is used for backup and reset, that is, the BootLoader is restarted. If the jump to the APP program is successful, the APP program is executed. When an application upgrade request appears, the firmware file, that is, the upgrade file, is received and stored in Flash partition 2. At the same time, it is determined whether there is an abnormality in the reception of Flash partition 2. If so, Flash partition 1 is set to have no backup program and the BootLoader is restarted. If not, the firmware is stored in Flash partition 2, and the flag of Flash partition 2 is set to new and then the BootLoader is restarted for upgrading.
[0101] Optionally, jumping into the application through the upgrade area includes:
[0102] When the upgrade area jumps into the application, determining whether the jump fails;
[0103] If the result of the judgment is that the jump fails, the program backup in the backup area is copied to the single-chip microcomputer; and the BootLoader is restarted.
[0104] Specifically, when the BootLoader completes the check of the upgrade area and determines that there is an upgrade code, the system will try to jump into the application. However, this process may fail for a variety of reasons, such as defects or incompatibility issues after the application is upgraded. In a preferred embodiment of the present invention, if the BootLoader program started after self-reset fails to jump to execute the application after writing the upgraded firmware file to the single-chip microcomputer, the system will restore the backup program through the backup area of the external memory. This means that if the jump fails, the system will automatically fall back to the program backup in the backup area and restart the BootLoader to ensure the stable operation of the system.
[0105] In this optional embodiment, by automatically falling back to the program backup in the backup area when the jump fails, the system can quickly recover from possible application upgrade errors, reducing system downtime and ensuring business continuity. Secondly, because the system can automatically detect upgrade failures and perform necessary recovery steps without manual intervention, the fault recovery process is simplified.
[0106] The present invention also provides a firmware online upgrade system, the online upgrade system is applied to a processor, the processor includes an external memory, the external memory includes a backup area and an upgrade area, the system includes:
[0107] Backup unit: used for determining whether the backup area is provided with a program backup of the application program through a BootLoader program when the processor is started;
[0108] An upgrade unit: used for jumping into the application program through the upgrade area if the backup area is provided with the program backup;
[0109] A transfer unit: used for storing the upgrade file in the upgrade area of the external memory when receiving a firmware upgrade request;
[0110] Upgrading unit: also used to upgrade the application according to the upgrade file in the upgrade area to complete the online update of the firmware. If the upgrade fails, the program backup in the backup area is copied to the processor and the processor is restarted.
[0111] The firmware online upgrade system of the present invention quickly checks the backup area through BootLoader when the system starts, ensuring that even if any abnormality occurs during the application upgrade process, it can quickly restore to a stable application backup, thereby ensuring the continuous operation of the system and the security of the data. Secondly, when the backup area confirms that there is a valid backup, the system can directly skip the lengthy upgrade judgment logic and quickly enter the application, reducing the startup delay. At the same time, in the application, there is no need to wait for the upgrade instruction for the application upgrade request and the reception of the upgrade file, which greatly shortens the boot time. In addition, storing the upgrade file in the upgrade area of the external memory not only reduces the read and write pressure on the internal memory of the single-chip microcomputer, prolongs its service life, but also realizes the rapid update of the firmware. Moreover, in the present invention, the key fault-tolerant mechanism is that when an application upgrade request is received, the storage of the upgrade file and the upgrade process are both performed in an external memory. If any problem is encountered during the upgrade process, such as communication error, file damage or system instability, the BootLoader will terminate the upgrade process and automatically copy the firmware backup from the backup area to the single-chip microcomputer to ensure that the system can quickly recover to the previous stable operation state; this process is seamless and automatic, avoiding the need for manual intervention, thereby significantly improving the stability and upgrade efficiency of the system. In addition, since the upgrade file is only operated in the upgrade area, even if the upgrade fails, it will not affect the stable firmware in the backup area, ensuring the security and high fault tolerance of the system. Finally, by simplifying the functions of the BootLoader and optimizing the data interaction process, the speed and success rate of the application upgrade are improved, and the stability of the system and the convenience of maintenance are enhanced.
[0112] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a non-volatile computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided by the present invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0113] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0114] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A firmware online upgrade method, characterized in that: The firmware online upgrade method is applied to a processor, the processor includes an external memory, the external memory includes a backup area and an upgrade area, and the method includes: When the processor is started, determining whether the backup area is provided with a program backup of the application program through a BootLoader program; If the backup area is configured with the program backup, jumping into the application program through the upgrade area; When receiving a firmware upgrade request, storing the upgrade file in the upgrade area of the external memory; The application is upgraded according to the upgrade file in the upgrade area to complete the online update of the firmware. If the upgrade fails, the program backup in the backup area is copied to the processor, and the processor is restarted.
2. The method for online firmware upgrade according to claim 1, characterized in that: When the processor is started, determining whether the backup area is provided with a program backup of the application program through the BootLoader program includes: When the processor is started, judging whether the backup area is provided with the program backup through the BootLoader program; If the judgment result is that it is not set, obtaining the program code of the application, and storing the program code as the program backup in the backup area; If the judgment result is that it has been set, it is confirmed that the backup area is set with the program backup.
3. The method for online firmware upgrade according to claim 2, characterized in that: The determining, by the BootLoader program, whether the backup area is provided with the program backup comprises: Obtaining a flag bit of the backup area, and determining whether the flag bit is non-empty; If the flag bit is not empty, it is determined that the backup area is provided with the program backup; If the flag is empty, it is determined that the backup area does not have the program backup set.
4. The method for online firmware upgrade according to claim 3, characterized in that: If the backup area is provided with the program backup, jumping into the application program through the upgrade area comprises: Determining whether the upgrade area is provided with the upgrade code; If the judgment result is that an upgrade code is set, the application is upgraded according to the upgrade file in the upgrade area; If the result of the determination is that the upgrade code is not set, the application is jumped into.
5. The method for online firmware upgrade according to claim 4, characterized in that: The determining whether the upgrade area is provided with the upgrade code comprises: Obtaining a flag bit of the upgrade area, and determining whether the program in the upgrade area is a new version according to the flag bit; If the flag indicates a new version, it is determined that the upgrade area is provided with the upgrade code; If the flag indicates an old version or is empty, it is determined that the upgrade code does not exist in the upgrade area.
6. The method for online firmware upgrade according to claim 5, characterized in that: When receiving a firmware upgrade request, storing the upgrade file in the upgrade area of the external memory comprises: When a firmware upgrade request is received, obtaining an upgrade file through the application; The upgrade file is stored in the upgrade area of the external memory, and a flag bit of the upgrade area is updated.
7. The method for online firmware upgrade according to claim 6, characterized in that: The step of upgrading the firmware according to the upgrade file in the upgrade area includes: When it is determined that the upgrade area is provided with the upgrade code, the upgrade file of the upgrade area is updated to the processor to complete the application upgrade.
8. The method for online firmware upgrade according to claim 6, characterized in that: When receiving a firmware upgrade request, storing the upgrade file in the upgrade area of the external memory also includes: When the upgrade file is stored in the upgrade area, determining whether the upgrade area has storage abnormality; If the judgment result is that no abnormality is stored, the flag bit of the backup area is set to non-empty, and the BootLoader is restarted; If the judgment result is that the storage is abnormal, the flag bit of the backup area is set to empty and the BootLoader is restarted.
9. The method for online firmware upgrade according to claim 1, characterized in that: The step of jumping into the application through the upgrade area includes: When jumping from the upgrade area to the application, determining whether the jump fails; If the result of the determination is that the jump fails, the program backup in the backup area is copied to the processor, and then the BootLoader is restarted.
10. A firmware online upgrade system, characterized in that: The online upgrade system is applied to a processor, the processor includes an external memory, the external memory includes a backup area and an upgrade area, and the system includes: Backup unit: used for determining whether the backup area is provided with a program backup of the application program through a BootLoader program when the processor is started; An upgrade unit: used for jumping into the application program through the upgrade area if the backup area is provided with the program backup; A transfer unit: used for storing the upgrade file in the upgrade area of the external memory when receiving a firmware upgrade request; Upgrading unit: also used to upgrade the application according to the upgrade file in the upgrade area to complete the online update of the firmware. If the upgrade fails, the program backup in the backup area is copied to the processor and the processor is restarted.
Citation Information
Cited By
Remote upgrading method and device for firmware program and computer equipment
CN119557145A
Online upgrading method and device based on ZYNQ
CN119645472A
