Bootloader update method, device, equipment and medium
By dividing the flash memory area in the microcontroller unit and using Bootloader to manage the firmware judgment flag bits, alternate updates between Bootloader and application firmware are solved, and the problem of crashes and bricks after the Bootloader program is updated is reduced, and the maintenance cost is improved and product reliability is improved.
Patent Information
- Application Number
- CN202211714232.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-27
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2042-12-27
AI Technical Summary
In the existing Bootloader self-update method, the Bootloader program has crashed due to defects and bricked products caused by product after the Bootloader program is updated, which increases the maintenance cost.
By dividing the flash memory area of the microcontroller unit into multiple areas, using Bootloader management firmware to determine the flag bits of the current startup area, and after verification is passed, the update program is flashed to the backup area, so as to realize alternating updates between Bootloader and application firmware, reducing the risk of becoming bricked after program updates.
The self-update of Bootloader is realized, reducing the risk of product bricking caused by crashes after program updates, reducing maintenance costs, and improving product reliability and customer satisfaction.
Smart Images

Figure CN115993985B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a Bootloader updating method, device, equipment and medium. Background Art
[0002] The bootloader is the first program that runs after a product is powered on. It verifies the integrity of the application firmware to ensure data security. It also allows for updates to the application firmware through online upgrades if the firmware doesn't meet customer requirements or has defects. Therefore, the bootloader is crucial, affecting the successful operation of the application firmware and ensuring that it can be safely updated when necessary. However, if the bootloader is designed with defects or doesn't meet customer requirements, it will need to be upgraded.
[0003] The most commonly used bootloader self-update method is a dual bootloader solution. This involves running the first bootloader (boot1) after the product is powered on. After boot1 runs, it jumps to the second bootloader (boot2). Boot2 is responsible for verifying and upgrading the application firmware. When boot2 needs to be updated, boot1 completes the update to boot2, thus achieving bootloader self-update. While this method can meet the bootloader self-update requirements, it has a drawback: once boot2 is updated, it may not operate normally due to a boot2 defect. After the product restarts, boot1 passes the boot2 integrity check and jumps to boot2. However, due to the defective boot2 program, it cannot run, causing the system to freeze and brick the product.
[0004] In summary, how to implement self-update of the Bootloader program and reduce the risk of bricking after the program update is a problem that needs to be solved. Summary of the Invention
[0005] In view of this, the purpose of the present invention is to provide a bootloader update method, device, equipment and medium, which can realize the self-update of the bootloader program and reduce the risk of bricking after the program is updated. The specific scheme is as follows:
[0006] In a first aspect, the present application discloses a Bootloader update method, comprising:
[0007] Power on the microcontroller, and determine the current boot region according to the boot information in the boot information storage area through the bootloader management firmware. If the current boot region is the first bootloader region, determine whether the current flag bit of the first bootloader region is a first preset value;
[0008] If so, updating the current flag to a second preset value through the first Bootloader area, and verifying the first application firmware area corresponding to the first Bootloader area;
[0009] If the verification passes, running the current application for updating the bootloader and the application firmware in the first application firmware area, and updating the current flag bit to a third preset value;
[0010] After obtaining the update instruction, the upgrade flag is set, and when the current flag is the third preset value, the next application is flashed to the second Bootloader area and its corresponding second application firmware area;
[0011] The current flag of the second Bootloader area is updated to the first preset value, the startup information is updated to the option value corresponding to the second Bootloader area, the upgrade flag is reset, and then the process jumps back to the step of powering on and starting the microcontroller unit.
[0012] Optionally, the Bootloader update method further includes:
[0013] The flash memory area in the micro control unit is pre-divided into the Bootloader management firmware, the startup information storage area, the first Bootloader area, the first application firmware area, the second Bootloader area and the second application firmware area.
[0014] Optionally, the Bootloader update method further includes:
[0015] A first update program currently used to update the bootloader and a second update program currently used to update the application firmware are determined, and the first update program and the second update program are packaged to obtain an application program for updating the bootloader and updating the application firmware.
[0016] Optionally, after determining whether the current flag bit of the first Bootloader region is a first preset value, the method further includes:
[0017] If the current flag of the first Bootloader region is the second preset value, running the second Bootloader region and determining whether the second Bootloader region has a corresponding upgrade flag;
[0018] If there is no upgrade flag, checking the second application firmware area, so that after the verification passes, running the current application for updating the bootloader and updating the application firmware in the second application firmware area;
[0019] If there is an upgrade flag, the next application is flashed to the first Bootloader area and the first application firmware area, the current flag of the first Bootloader area is updated to the first preset value, and the startup information is updated to the option value corresponding to the first Bootloader area, and the upgrade flag is reset, and then the process jumps back to the step of powering on and starting the microcontroller unit.
[0020] Optionally, after determining whether the current flag bit of the first Bootloader region is a first preset value, the method further includes:
[0021] If the current flag bit of the first Bootloader region is the third preset value, determining whether the first Bootloader region has a corresponding upgrade flag bit;
[0022] If there is no upgrade flag, directly jump to the step of verifying the first application firmware area corresponding to the first Bootloader area;
[0023] If there is an upgrade flag, the process directly jumps to the step of flashing the next application program to the second Bootloader area and its corresponding second application firmware area.
[0024] Optionally, after verifying the first application firmware area corresponding to the first Bootloader area, the method further includes:
[0025] If the verification fails, the current application program for updating the Bootloader and the application firmware is run in the second application firmware area, and the current flag bit of the second Bootloader area is updated to a third preset value.
[0026] Optionally, determining the current startup area according to the startup information in the startup information storage area through the Bootloader management firmware includes:
[0027] Starting the Bootloader management firmware and reading the startup information in the startup information storage area through the Bootloader management firmware; the startup information storage area also includes a current flag bit and an upgrade flag bit;
[0028] Determine a target option value corresponding to the startup information, so as to determine a current startup area according to the target option value; the target option value is an option value corresponding to the first Bootloader area or the second Bootloader area.
[0029] In a second aspect, the present application discloses a Bootloader update device, comprising:
[0030] a boot region determination module, configured to power on the microcontroller and determine, through the bootloader management firmware, a current boot region based on the boot information in the boot information storage area; and, if the current boot region is a first bootloader region, determine whether a current flag bit of the first bootloader region is a first preset value;
[0031] an application firmware verification module, configured to, if yes, update the current flag to a second preset value through the first Bootloader area, and verify the first application firmware area corresponding to the first Bootloader area;
[0032] an application running module, configured to run the current application for updating the bootloader and the application firmware in the first application firmware area if the verification passes, and update the current flag bit to a third preset value;
[0033] an application flashing module, configured to, upon receiving an update instruction, set an upgrade flag and, when the current flag is the third preset value, flash the next application to the second bootloader area and its corresponding second application firmware area;
[0034] The restart module is used to update the current flag of the second Bootloader area to the first preset value, update the startup information to the option value corresponding to the second Bootloader area, reset the upgrade flag, and then jump to the step of powering on and starting the micro control unit.
[0035] In a third aspect, the present application discloses an electronic device, comprising:
[0036] Memory, used to store computer programs;
[0037] The processor is used to execute the computer program to implement the steps of the aforementioned disclosed Bootloader update method.
[0038] In a fourth aspect, the present application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the steps of the aforementioned disclosed Bootloader update method are implemented.
[0039] It can be seen that the present application starts the microcontroller unit by powering on, and determines the current startup area according to the startup information in the startup information storage area through the Bootloader management firmware. If the current startup area is the first Bootloader area, it is determined whether the current flag of the first Bootloader area is the first preset value; if so, the current flag is updated to the second preset value through the first Bootloader area, and the first application firmware area corresponding to the first Bootloader area is verified; if the verification passes, the current application for updating the Bootloader and updating the application firmware is run in the first application firmware area, and the current flag is updated to the third preset value; after obtaining the update instruction, the upgrade flag is set, and when the current flag is the third preset value, the next application is flashed to the second Bootloader area and its corresponding second application firmware area; the current flag of the second Bootloader area is updated to the first preset value, and the startup information is updated to the option value corresponding to the second Bootloader area, and the upgrade flag is reset, and then the process jumps to the step of powering on the microcontroller unit again. It can be seen that after the microcontroller is powered on, the Bootloader management firmware in the microcontroller is started first. The Bootloader management firmware determines the current startup area based on the startup information in the startup information storage area. The current startup area includes the first Bootloader area and the second Bootloader area. If the current startup area is the first Bootloader area, first determine whether its current flag is the first preset value. If so, update the current flag to the second preset value through the first Bootloader area, and verify the integrity of the corresponding first application firmware area. After the verification is passed, run the current application for updating the Bootloader and updating the application firmware in the first application firmware area, and then update the current flag to the third preset value. That is, by packaging the bootloader program and the application firmware program into one application, the present application also completes the self-update of the bootloader when upgrading the application firmware. After the application firmware is running, it waits for update. Then, after obtaining the update instruction, the upgrade flag is set first, and the next application is flashed to the second Bootloader area and its corresponding second application firmware area, and then the current flag of the second Bootloader area is updated to the first preset value, and the startup information is updated to the option value corresponding to the second Bootloader area, and the upgrade flag is reset, and then the microcontroller is restarted.Since the startup information in the startup information storage area has been updated to the option value corresponding to the second Bootloader area, after power is restored, the current startup area determined by the Bootloader management firmware based on the startup information in the startup information storage area is the second Bootloader area. In this way, the Bootloader rollback strategy is implemented by alternately flashing the first Bootloader area and the second Bootloader area in sequence, reducing the risk of bricking after the program is updated, thereby reducing the maintenance cost caused by bricking. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without any creative work.
[0041] Figure 1 This is a flowchart of a Bootloader update method disclosed in this application;
[0042] Figure 2 A specific schematic diagram of flash memory partition disclosed in this application;
[0043] Figure 3 This is a flowchart of a specific Bootloader update method disclosed in this application;
[0044] Figure 4 A schematic diagram of a specific Bootloader update process disclosed in this application;
[0045] Figure 5 This is a schematic diagram of the structure of a Bootloader update device disclosed in this application;
[0046] Figure 6 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION
[0047] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0048] Currently, the most commonly used method for Bootloader self-update is a dual Bootloader solution, that is, the first Bootloader (i.e., boot1) runs after the product is powered on, and after boot1 runs, it jumps to the second Bootloader (i.e., boot2). Boot2 is responsible for verifying and upgrading the application firmware. When boot2 needs to be updated, boot1 completes the update of boot2 to achieve Bootloader self-update. Although this method can achieve the Bootloader self-update requirement, one shortcoming is that once the update of boot2 is completed, if boot2 is defective, boot2 cannot run normally. Then after the product is restarted, boot1 passes the integrity check of boot2 and jumps to boot2 to run, but the program cannot run due to the defect of boot2, causing a crash, and causing the product to become bricked. To this end, the embodiments of the present application disclose a Bootloader self-update method, device, equipment and medium, which can achieve self-update of the Bootloader program and reduce the risk of bricking after the program is updated.
[0049] See also Figure 1 As shown, the embodiment of the present application discloses a Bootloader update method, which includes:
[0050] Step S11: Power on and start the microcontroller unit, and determine the current startup area according to the startup information in the startup information storage area through the Bootloader management firmware. If the current startup area is the first Bootloader area, determine whether the current flag bit of the first Bootloader area is a first preset value.
[0051] In this embodiment, it should be noted that the Bootloader update method in this application further includes: pre-dividing the flash memory area in the microcontroller unit into the Bootloader management firmware, the startup information storage area, the first Bootloader area, the first application firmware area, the second Bootloader area, and the second application firmware area. That is, in this embodiment, the flash memory area of the microcontroller unit (MCU) is pre-divided into six areas. Figure 2 As shown in Figure 2This is a schematic diagram of a specific flash memory partition disclosed in this application. The six areas are BooM, or Bootloader Management Firmware, denoted as T1; Boot_Information, or the boot information storage area, denoted as T2; Bootloaer_A, or the first Bootloader area, denoted as T3; APP_A, or the first application firmware area, denoted as T4; Bootloader_B, or the second Bootloader area, denoted as T5; and APP_B, or the second application firmware area, denoted as T6. Among them, BooM is used to start the boot and determine whether it is Bootloader_A or Bootloader_B; Boot_Information is used to store the boot information of the Bootloader and the status of the flag bit during the upgrade process; Bootloader_A and Bootloader_B belong to the bootloader firmware area and form the A / B area, which are used alternately during the upgrade. According to the startup option, when one of the areas is the current startup area, the other area is the backup area; APP_A and APP_B are application programs and belong to the application firmware area. The two areas form the A / B area and are used alternately during the upgrade. According to the startup option, when one of the areas is the current use area, the other area is the backup area. After the flash memory area is divided into areas, the firmware is burned, that is, T1, T2, T3, T4, T5, and T6 are burned into the micro control unit through the burner, among which the current startup area recorded in the startup information storage area T2 runs from the first Bootloader T3 area by default. In addition, the data of the first Bootloader area T3 and the second Bootloader area T5, the first application firmware area T4 and the second application firmware area T6 are completely consistent, and the initial values of the current flag bits of the first Bootloader area T3 and the second Bootloader area T5 are both set to 1 by default, that is, T3_OK=1, T5_OK=1.
[0052] After the microcontroller is powered on, the bootloader management firmware determines the current boot region based on the boot information in the boot information storage area, specifically whether the current boot region is the first bootloader region T3 or the second bootloader region T5. If the current boot region is the first bootloader region T3, the firmware determines whether the current flag bit T3_OK of the first bootloader region T3 is a first preset value. In this embodiment, the first preset value is specifically set to 0.
[0053] Step S12: If yes, then update the current flag to a second preset value through the first Bootloader area, and verify the first application firmware area corresponding to the first Bootloader area.
[0054] In this embodiment, if the current flag T3_OK is 0, it means that it is the first time that T3 is started after being flashed. The first Bootloader area T3 updates T3_OK to the second preset value, the second preset value is set to 2, and the first application firmware area corresponding to the first Bootloader area is verified, specifically, the integrity of the APP program in the T4 area is verified.
[0055] Step S13: If the verification passes, the current application program for updating the Bootloader and the application firmware is run in the first application firmware area, and the current flag is updated to a third preset value.
[0056] In this embodiment, if the verification passes, it jumps to APP operation, that is, the current application for updating the Bootloader and updating the application firmware is run in the first application firmware area T4. If the current application can be successfully started and run, the current flag T3_OK is updated to a third preset value, and the third preset value is specifically set to 1. It should be pointed out that the above method also includes: determining the first update program currently used to update the Bootloader and the second update program for updating the application firmware, and packaging the first update program and the second update program to obtain an application for updating the Bootloader and updating the application firmware. In other words, this embodiment packages the bootloader program that currently needs to be updated and the current latest application firmware program into an upgraded application in a splicing manner. When upgrading the application, the self-update of the bootloader is completed, and the update of the application firmware is also completed, and the self-update of the bootloader implemented in this way is relatively safe.
[0057] Step S14: after obtaining the update instruction, the upgrade flag is set, and when the current flag is the third preset value, the next application is flashed to the second Bootloader area and its corresponding second application firmware area.
[0058] In this embodiment, after the current application is running in the T4 area, it waits for update in real time. After obtaining the update instruction, it first sets the upgrade flag, that is, assigns the value of the upgrade flag upgrade_flag to 1, and jumps to the first Bootloader area T3. From the above content, it can be seen that T3_OK has been updated to the third preset value 0 at this time. Then, when the current flag is 1, it is determined whether the upgrade flag upgrade_flag has been assigned to 1 at this time. If upgrade_flag is 1, the next application is flashed to the second Bootloader area T5 and its corresponding second application firmware area T6.
[0059] Step S15: Update the current flag of the second Bootloader area to the first preset value, update the startup information to the option value corresponding to the second Bootloader area, reset the upgrade flag, and then jump to the step of powering on and starting the microcontroller unit.
[0060] In this embodiment, the current flag T5_OK of the second Bootloader area T5 is updated to 0, and the startup information in the startup information storage area is updated to the option value corresponding to the T5 area, and the upgrade flag is reset, that is, upgrade_flag is assigned to 0 to clear the upgrade flag. In this way, the update of the bootloader and application firmware is completed. Then the microcontroller unit is powered on again. At this time, the current startup area determined by the Bootloader management firmware based on the startup information in the startup information storage area is the second Bootloader area T5, and the current flag T5_OK of the T5 area is 0. The subsequent process is similar to the aforementioned T3 area. In this way, the Bootloader rollback strategy is implemented by alternately flashing the first Bootloader area and the second Bootloader area in sequence, which can ensure that the product clock is active and the entire product will not be bricked due to update failure, thereby reducing the cost of returning the product to the factory for unpacking due to bricking, thereby achieving economic benefits and improving customer satisfaction.
[0061] It can be seen that the present application starts the microcontroller unit by powering on, and determines the current startup area according to the startup information in the startup information storage area through the Bootloader management firmware. If the current startup area is the first Bootloader area, it is determined whether the current flag of the first Bootloader area is the first preset value; if so, the current flag is updated to the second preset value through the first Bootloader area, and the first application firmware area corresponding to the first Bootloader area is verified; if the verification passes, the current application for updating the Bootloader and updating the application firmware is run in the first application firmware area, and the current flag is updated to the third preset value; after obtaining the update instruction, the upgrade flag is set, and when the current flag is the third preset value, the next application is flashed to the second Bootloader area and its corresponding second application firmware area; the current flag of the second Bootloader area is updated to the first preset value, and the startup information is updated to the option value corresponding to the second Bootloader area, and the upgrade flag is reset, and then the process jumps to the step of powering on the microcontroller unit again. It can be seen that after the microcontroller is powered on, the Bootloader management firmware in the microcontroller is started first. The Bootloader management firmware determines the current startup area based on the startup information in the startup information storage area. The current startup area includes the first Bootloader area and the second Bootloader area. If the current startup area is the first Bootloader area, first determine whether its current flag is the first preset value. If so, update the current flag to the second preset value through the first Bootloader area, and verify the integrity of the corresponding first application firmware area. After the verification is passed, run the current application for updating the Bootloader and updating the application firmware in the first application firmware area, and then update the current flag to the third preset value. That is, by packaging the bootloader program and the application firmware program into one application, the present application also completes the self-update of the bootloader when upgrading the application firmware. After the application firmware is running, it waits for update. Then, after obtaining the update instruction, the upgrade flag is set first, and the next application is flashed to the second Bootloader area and its corresponding second application firmware area, and then the current flag of the second Bootloader area is updated to the first preset value, and the startup information is updated to the option value corresponding to the second Bootloader area, and the upgrade flag is reset, and then the microcontroller is restarted.Since the startup information in the startup information storage area has been updated to the option value corresponding to the second Bootloader area, after power is restored, the current startup area determined by the Bootloader management firmware based on the startup information in the startup information storage area is the second Bootloader area. In this way, the Bootloader rollback strategy is implemented by alternately flashing the first Bootloader area and the second Bootloader area in sequence, reducing the risk of bricking after the program is updated, thereby reducing the maintenance cost caused by bricking.
[0062] See also Figure 3 and Figure 4 As shown, the embodiment of the present application discloses a specific Bootloader update method. Compared with the previous embodiment, this embodiment further illustrates and optimizes the technical solution.
[0063] Specifically include:
[0064] Step S21: Power on and start the microcontroller unit, start the Bootloader management firmware, and read the startup information in the startup information storage area through the Bootloader management firmware; the startup information storage area also includes a current flag bit and an upgrade flag bit.
[0065] In this embodiment, after the microcontroller is powered on, the bootloader management firmware therein starts first. The bootloader management firmware then reads the boot information in the boot information storage area to determine whether the current boot area is the first bootloader area T3 or the second bootloader area T5. It should be noted that in addition to storing the boot information, the boot information storage area also stores the current flags: T3_OK, T5_OK, and the upgrade flag: upgrade_flag. Therefore, when the current flag and the upgrade flag change, it indicates that the stored information in the area has been rewritten.
[0066] Step S22: Determine the target option value corresponding to the startup information, so as to determine the current startup area according to the target option value. If the current startup area is the first Bootloader area, determine whether the current flag bit of the first Bootloader area is a first preset value; the target option value is the option value corresponding to the first Bootloader area or the second Bootloader area.
[0067] In this embodiment, a target option value corresponding to the startup information is determined, so as to determine the current startup region according to the target option value. The target option value is an option value corresponding to the first bootloader region or the second bootloader region.
[0068] Step S23: If yes, then update the current flag to a second preset value through the first Bootloader area, and verify the first application firmware area corresponding to the first Bootloader area.
[0069] In a first specific implementation, if the current flag bit of the first Bootloader area is a first preset value, i.e., T3_OK=0, the current flag bit is updated to a second preset value, i.e., T3_OK=2, through the first Bootloader area, and the integrity of the first application firmware area corresponding to the first Bootloader area is verified.
[0070] In a second specific embodiment, after the above judgment of whether the current flag of the first Bootloader area is the first preset value, it also includes: if the current flag of the first Bootloader area is the second preset value, then run the second Bootloader area, and determine whether the second Bootloader area has a corresponding upgrade flag; if there is no upgrade flag, then check the second application firmware area, so that after the check is passed, run the current application for updating the Bootloader and updating the application firmware in the second application firmware area; if there is an upgrade flag, then write the next application to the first Bootloader area and the first application firmware area, update the current flag of the first Bootloader area to the first preset value, and update the startup information to the option value corresponding to the first Bootloader area, and reset the upgrade flag, and then jump to the step of powering on the microcontroller unit again. Figure 4As shown in , if the current flag of the first Bootloader area is the second preset value, that is, T3_OK=2, it means that the last startup was a startup after the upgrade and the application firmware did not run successfully, then it is necessary to jump to the second Bootloader area T5 to run and return to the state before the upgrade. Then determine whether the T5 area has a corresponding upgrade flag, that is, whether upgrade_flag is 1 at this time; if upgrade_flag=0, it means that there is no upgrade flag, then check the second application firmware area T6, so that after the check passes, run the current application for updating the Bootloader and updating the application firmware in the T6 area; if upgrade_flag=1, it means that there is an upgrade flag, then flash the next application to the T3 area and T4 area, update T3_OK in the T3 area to 0, and update the startup information to the option value corresponding to the T3 area, and reset the upgrade flag, that is, set upgrade_flag=0, and then power on the micro control unit again.
[0071] In a third specific implementation, after determining whether the current flag of the first Bootloader area is the first preset value, the method further includes: if the current flag of the first Bootloader area is the third preset value, determining whether the first Bootloader area has a corresponding upgrade flag; if there is no upgrade flag, directly jumping to the step of verifying the first application firmware area corresponding to the first Bootloader area; if there is an upgrade flag, directly jumping to the step of flashing the next application to the second Bootloader area and its corresponding second application firmware area. Figure 4 As shown in , if the current flag bit of the first Bootloader area is the third preset value, that is, T3_OK=1, it means that the application firmware is intact and can run normally, and further determine whether the first Bootloader area has a corresponding upgrade flag bit, that is, whether upgrade_flag is 1 at this time; if upgrade_flag=0, it means that there is no upgrade flag bit, then jump directly to the step of verifying the first application firmware area corresponding to the first Bootloader area; if upgrade_flag=1, it means that there is an upgrade flag bit, then jump directly to the step of flashing the next application to the second Bootloader area and its corresponding second application firmware area.
[0072] Step S24: If the verification passes, the current application program for updating the Bootloader and the application firmware is run in the first application firmware area, and the current flag is updated to a third preset value.
[0073] In this embodiment, after verifying the first application firmware area corresponding to the first Bootloader area, the method further includes: if the verification fails, running the current application for updating the Bootloader and the application firmware in the second application firmware area, and updating the current flag bit of the second Bootloader area to a third preset value. It is understandable that if the verification of the first application firmware area fails, running the current application for updating the Bootloader and the application firmware in the second application firmware area, and updating the current flag bit of the second Bootloader area to the third preset value, that is, at this time T5_OK=1.
[0074] Step S25: after obtaining the update instruction, the upgrade flag is set, and when the current flag is the third preset value, the next application is flashed to the second Bootloader area and its corresponding second application firmware area.
[0075] Step S26: Update the current flag of the second Bootloader area to the first preset value, update the startup information to the option value corresponding to the second Bootloader area, reset the upgrade flag, and then jump to the step of powering on and starting the microcontroller unit.
[0076] For more specific processing procedures of the above steps S25 and S26, reference may be made to the corresponding contents disclosed in the aforementioned embodiments, which will not be elaborated here.
[0077] It can be seen that in the embodiment of the present application, after the microcontroller is powered on and started, the bootloader management firmware therein is started first, and then the boot information in the boot information storage area is read by the bootloader management firmware, and the target option value corresponding to the boot information is determined to further determine the current boot area. In addition, the boot information storage area also stores the current flag bit and the upgrade flag bit. When the current flag bit and the upgrade flag bit change subsequently, it means that the stored information in the area has been rewritten. When the microcontroller is restarted, after determining the current flag bit of the current boot area, the corresponding steps will be executed according to the different values of the current flag bit.
[0078] See also Figure 5 As shown, the embodiment of the present application discloses a Bootloader update method, which includes:
[0079] The boot region determination module 11 is configured to power on the microcontroller and determine the current boot region based on the boot information in the boot information storage area through the bootloader management firmware. If the current boot region is the first bootloader region, the module determines whether the current flag bit of the first bootloader region is a first preset value.
[0080] an application firmware verification module 12, configured to, if yes, update the current flag to a second preset value through the first Bootloader area, and verify the first application firmware area corresponding to the first Bootloader area;
[0081] an application program running module 13, configured to run the current application program for updating the bootloader and the application firmware in the first application firmware area if the verification passes, and update the current flag bit to a third preset value;
[0082] The application flashing module 14 is configured to set the upgrade flag after receiving the update instruction, and flash the next application to the second bootloader area and its corresponding second application firmware area when the current flag is the third preset value;
[0083] The restart module 15 is used to update the current flag of the second Bootloader area to the first preset value, update the startup information to the option value corresponding to the second Bootloader area, reset the upgrade flag, and then jump to the step of powering on and starting the micro control unit.
[0084] It can be seen that the present application starts the microcontroller unit by powering on, and determines the current startup area according to the startup information in the startup information storage area through the Bootloader management firmware. If the current startup area is the first Bootloader area, it is determined whether the current flag of the first Bootloader area is the first preset value; if so, the current flag is updated to the second preset value through the first Bootloader area, and the first application firmware area corresponding to the first Bootloader area is verified; if the verification passes, the current application for updating the Bootloader and updating the application firmware is run in the first application firmware area, and the current flag is updated to the third preset value; after obtaining the update instruction, the upgrade flag is set, and when the current flag is the third preset value, the next application is flashed to the second Bootloader area and its corresponding second application firmware area; the current flag of the second Bootloader area is updated to the first preset value, and the startup information is updated to the option value corresponding to the second Bootloader area, and the upgrade flag is reset, and then the process jumps to the step of powering on the microcontroller unit again. It can be seen that after the microcontroller is powered on, the Bootloader management firmware in the microcontroller is started first. The Bootloader management firmware determines the current startup area based on the startup information in the startup information storage area. The current startup area includes the first Bootloader area and the second Bootloader area. If the current startup area is the first Bootloader area, first determine whether its current flag is the first preset value. If so, update the current flag to the second preset value through the first Bootloader area, and verify the integrity of the corresponding first application firmware area. After the verification is passed, run the current application for updating the Bootloader and updating the application firmware in the first application firmware area, and then update the current flag to the third preset value. That is, by packaging the bootloader program and the application firmware program into one application, the present application also completes the self-update of the bootloader when upgrading the application firmware. After the application firmware is running, it waits for update. Then, after obtaining the update instruction, the upgrade flag is set first, and the next application is flashed to the second Bootloader area and its corresponding second application firmware area, and then the current flag of the second Bootloader area is updated to the first preset value, and the startup information is updated to the option value corresponding to the second Bootloader area, and the upgrade flag is reset, and then the microcontroller is restarted.Since the startup information in the startup information storage area has been updated to the option value corresponding to the second Bootloader area, after power is restored, the current startup area determined by the Bootloader management firmware based on the startup information in the startup information storage area is the second Bootloader area. In this way, the Bootloader rollback strategy is implemented by alternately flashing the first Bootloader area and the second Bootloader area in sequence, reducing the risk of bricking after the program is updated, thereby reducing the maintenance cost caused by bricking.
[0085] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Specifically, the device may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps of the bootloader update method performed by the electronic device disclosed in any of the aforementioned embodiments.
[0086] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device. The communication protocol it follows is any communication protocol that can be applied to the technical solution of this application and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world. Its specific interface type can be selected according to specific application needs and is not specifically limited here.
[0087] Among them, the processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 can be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 21 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 21 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 21 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
[0088] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or CD, etc. The resources stored thereon include an operating system 221, a computer program 222 and data 223, etc. The storage method can be temporary storage or permanent storage.
[0089] Among them, the operating system 221 is used to manage and control the various hardware devices and computer programs 222 on the electronic device 20 to enable the processor 21 to calculate and process the massive data 223 in the memory 22. It can be Windows, Unix, Linux, etc. In addition to including computer programs that can be used to complete the bootloader update method performed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include computer programs that can be used to complete other specific tasks. In addition to including data transmitted from an external device to the electronic device, the data 223 can also include data collected by its own input and output interface 25.
[0090] Furthermore, an embodiment of the present application also discloses a computer-readable storage medium, in which a computer program is stored. When the computer program is loaded and executed by a processor, the method steps performed by the Bootloader update process disclosed in any of the aforementioned embodiments are implemented.
[0091] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from the other embodiments. Reference can be made to the descriptions of the identical or similar parts between the various embodiments. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple, and the relevant parts can be referred to the descriptions of the methods.
[0092] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0093] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0094] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.
[0095] The above is a detailed introduction to the Bootloader update method, device, equipment and storage medium provided by the present invention. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method and core ideas of the present invention. At the same time, for those skilled in the art, according to the ideas of the present invention, there will be changes in the specific implementation methods and application scopes. In summary, the content of this specification should not be understood as limiting the present invention.
Claims
1. A Bootloader update method, characterized in that: include: Power on the microcontroller, and determine the current boot region according to the boot information in the boot information storage area through the bootloader management firmware. If the current boot region is the first bootloader region, determine whether the current flag bit of the first bootloader region is a first preset value; If so, updating the current flag to a second preset value through the first Bootloader area, and verifying the first application firmware area corresponding to the first Bootloader area; If the verification passes, running the current application for updating the bootloader and the application firmware in the first application firmware area, and updating the current flag bit to a third preset value; After obtaining the update instruction, the upgrade flag is set, and when the current flag is the third preset value, the next application is flashed to the second Bootloader area and its corresponding second application firmware area; The current flag of the second Bootloader area is updated to the first preset value, the startup information is updated to the option value corresponding to the second Bootloader area, the upgrade flag is reset, and then the process jumps back to the step of powering on and starting the microcontroller unit.
2. The Bootloader update method according to claim 1, wherein: Also includes: The flash memory area in the micro control unit is pre-divided into the Bootloader management firmware, the startup information storage area, the first Bootloader area, the first application firmware area, the second Bootloader area and the second application firmware area.
3. The Bootloader update method according to claim 1, wherein: Also includes: A first update program currently used to update the bootloader and a second update program currently used to update the application firmware are determined, and the first update program and the second update program are packaged to obtain an application program for updating the bootloader and updating the application firmware.
4. The Bootloader update method according to claim 1, wherein: After determining whether the current flag bit of the first Bootloader region is a first preset value, the method further includes: If the current flag of the first Bootloader region is the second preset value, running the second Bootloader region and determining whether the second Bootloader region has a corresponding upgrade flag; If there is no upgrade flag, checking the second application firmware area, so that after the verification passes, running the current application for updating the bootloader and updating the application firmware in the second application firmware area; If there is an upgrade flag, the next application is flashed to the first Bootloader area and the first application firmware area, the current flag of the first Bootloader area is updated to the first preset value, and the startup information is updated to the option value corresponding to the first Bootloader area, and the upgrade flag is reset, and then the process jumps back to the step of powering on and starting the microcontroller unit.
5. The Bootloader update method according to claim 1, wherein: After determining whether the current flag bit of the first Bootloader region is a first preset value, the method further includes: If the current flag bit of the first Bootloader region is the third preset value, determining whether the first Bootloader region has a corresponding upgrade flag bit; If there is no upgrade flag, directly jump to the step of verifying the first application firmware area corresponding to the first Bootloader area; If there is an upgrade flag, the process directly jumps to the step of flashing the next application program to the second Bootloader area and its corresponding second application firmware area.
6. The Bootloader update method according to claim 1, wherein: After verifying the first application firmware area corresponding to the first Bootloader area, the method further includes: If the verification fails, the current application program for updating the Bootloader and the application firmware is run in the second application firmware area, and the current flag bit of the second Bootloader area is updated to a third preset value.
7. The Bootloader update method according to any one of claims 1 to 6, characterized in that: The step of determining the current startup area according to the startup information in the startup information storage area by the Bootloader management firmware includes: Starting the Bootloader management firmware and reading the startup information in the startup information storage area through the Bootloader management firmware; the startup information storage area also includes a current flag bit and an upgrade flag bit; Determine a target option value corresponding to the startup information, so as to determine a current startup area according to the target option value; the target option value is an option value corresponding to the first Bootloader area or the second Bootloader area.
8. A Bootloader update device, characterized in that: include: a boot region determination module, configured to power on the microcontroller and determine, through the bootloader management firmware, a current boot region based on the boot information in the boot information storage area; and, if the current boot region is a first bootloader region, determine whether a current flag bit of the first bootloader region is a first preset value; an application firmware verification module, configured to, if yes, update the current flag to a second preset value through the first Bootloader area, and verify the first application firmware area corresponding to the first Bootloader area; an application running module, configured to run the current application for updating the bootloader and the application firmware in the first application firmware area if the verification passes, and update the current flag bit to a third preset value; an application flashing module, configured to, upon receiving an update instruction, set an upgrade flag and, when the current flag is the third preset value, flash the next application to the second bootloader area and its corresponding second application firmware area; The restart module is used to update the current flag of the second Bootloader area to the first preset value, update the startup information to the option value corresponding to the second Bootloader area, reset the upgrade flag, and then jump to the step of powering on and starting the micro control unit.
9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the steps of the Bootloader updating method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that Used to store a computer program; wherein, when the computer program is executed by a processor, the steps of the Bootloader update method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Vehicle machine Boot Loader self-updating method
CN110618825A
Method for online upgrading BootLoader through single-chip microcomputer APP
CN113127043A