Method, device and electronic equipment for running a single-chip computer

By obtaining the execution status flag and performing security verification or restoring to the initial state when the microcontroller restarts, the problem of device damage and stability during traditional microcontroller firmware upgrades is solved, achieving higher upgrade feasibility and stability.

CN122285374APending Publication Date: 2026-06-26SUNGROW CHARGING TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SUNGROW CHARGING TECH CO LTD
Filing Date
2024-12-23
Publication Date
2026-06-26

AI Technical Summary

Technical Problem

Traditional microcontroller firmware upgrade methods can easily brick devices, and cannot be recovered if there is a power outage or software operation failure during the upgrade process, reducing the feasibility and stability of the upgrade.

Method used

When the microcontroller restarts, it obtains the execution status identifier, determines the upgrade status through the first bootloader firmware, and performs a security check if the conditions are met; otherwise, it restores to the initial firmware state, ensuring the security and stability of the upgrade process.

Benefits of technology

It reduces the risk of device damage due to power outages or software operation failures, improves the feasibility and stability of firmware upgrades, and avoids problems such as devices failing to work properly.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122285374A_ABST
    Figure CN122285374A_ABST
Patent Text Reader

Abstract

This application discloses a method, apparatus, and electronic device for operating a microcontroller, belonging to the field of microcontrollers. The method for operating the microcontroller includes: obtaining the microcontroller's execution state based on a first bootloader firmware when the microcontroller restarts; performing a security verification on a target executable firmware based on a second bootloader firmware if the execution state indicator meets a first condition; and restoring the microcontroller based on an initial bootloader firmware and an initial executable firmware if the execution state indicator does not meet the first condition. The microcontroller operation method of this application can reduce the risk of device failure or malfunction due to power outages, software operation failures, or logical or version compatibility issues in the executable firmware itself during the process of upgrading the bootloader firmware via the executable firmware, thereby improving the resilience and reliability of upgrading the bootloader firmware via the executable firmware.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of microcontrollers, and in particular relates to a method, apparatus and electronic device for operating a microcontroller. Background Technology

[0002] Microcontroller firmware is generally divided into two parts: boot (bootloader) and application (executable program). Secure boot is a feature used to ensure the legitimacy of the microcontroller software. It's typically implemented by hardware ensuring the bootloader cannot be tampered with externally and cannot be bypassed during power-on. The bootloader code then performs signature verification on the application code to ensure its legitimacy. To better ensure system security, the key used for signature verification is changed periodically; therefore, the bootloader used for signature verification needs frequent upgrades. Traditionally, bootloader upgrades are done manually. However, with a large number of existing devices, manual flashing is extremely labor-intensive and prone to version inconsistencies. This can lead to the mixing of bootloaders and applications that support secure boot with those that don't, causing devices to fail to boot properly or even preventing online upgrades from fixing faults, effectively bricking the device and requiring manual firmware updates in the future.

[0003] In related technologies, bootloaders can be upgraded via an app. However, if a power outage or software failure occurs during the bootloader erasure or writing process, irreversible damage can occur, bricking the device and preventing it from booting normally. This increases the risk of bricking the device, especially since bootloaders frequently require upgrades. Furthermore, even if the app itself is legitimate, problems with the software, such as software logic issues or hardware version compatibility problems, can prevent the system from functioning properly or even entering the subsequent upgrade process. This also leads to subsequent device malfunctions, and the problem cannot be resolved through online upgrades, reducing the feasibility and stability of bootloader upgrades via an app. Summary of the Invention

[0004] This application aims to address at least one of the technical problems existing in the related art. To this end, this application proposes a method, apparatus, and electronic device for operating a microcontroller, which can improve the feasibility, risk resistance, and stability of upgrading the bootloader firmware through the execution of program firmware.

[0005] Firstly, this application provides a method for operating a microcontroller, the method comprising:

[0006] When the microcontroller restarts, the execution status identifier of the microcontroller is obtained based on the first bootloader firmware; the execution status identifier includes an identifier that no upgrade has occurred, an identifier that the operation was successful, an identifier that the firmware was successfully updated, or an identifier that the firmware was not successfully updated; the microcontroller is a microcontroller that has been upgraded by pre-processing the initial bootloader firmware and the initial execution firmware based on the target bootloader firmware and the target execution firmware, respectively, and the target bootloader firmware includes the first bootloader firmware and the second bootloader firmware.

[0007] If the execution status identifier meets the first condition, the target executable firmware is subjected to security verification based on the second bootloader firmware.

[0008] If the execution status identifier does not meet the first condition, the microcontroller is restored based on the initial bootloader firmware and the initial execution firmware.

[0009] According to the microcontroller operation method of this application, when the microcontroller restarts, the execution status identifier of the microcontroller is obtained based on the first boot program firmware. If the execution status identifier meets the first condition, the target executable firmware is security-verified based on the second boot program firmware. If the execution status identifier does not meet the first condition, the microcontroller is restored based on the initial boot program firmware and the initial executable firmware. This allows for the determination of the firmware update execution status identifier after the microcontroller firmware upgrade process but before the security verification. In the event of firmware update failure or executable firmware failure, the firmware before the upgrade is restored. This reduces the risk of device bricking or malfunction during the process of upgrading the boot program firmware via the executable firmware, due to power outages, software operation failures, or logical or version compatibility issues in the executable firmware itself. This improves the feasibility, risk resistance, and stability of upgrading the boot program firmware via the executable firmware.

[0010] According to one embodiment of this application, the execution status identifier satisfies a first condition, including:

[0011] The execution status identifier is the "no upgrade occurred" identifier;

[0012] Alternatively, the execution status identifier may be the successful execution identifier;

[0013] Alternatively, the execution status identifier may be the firmware update success identifier, and the target executable firmware may not have been run.

[0014] According to one embodiment of this application, the execution status identifier not satisfying the first condition includes:

[0015] The execution status identifier is an identifier indicating that the firmware update was unsuccessful.

[0016] Alternatively, the execution status identifier may be the firmware update success identifier, and the target executable firmware may have been run.

[0017] According to one embodiment of this application, in the event of a microcontroller restart, after obtaining the execution status identifier of the microcontroller based on the first bootloader firmware, the method further includes:

[0018] If the execution status identifier is the successful execution identifier, during the second run, the execution status identifier will be updated to the no-upgrade identifier.

[0019] According to one embodiment of this application, after determining that a first condition is met based on the execution status identifier, and after performing a security verification on the target executable firmware based on the second bootloader firmware, the method further includes:

[0020] If the security verification passes, control the target execution program firmware to run for the target duration and obtain the running parameters;

[0021] If the target executable firmware is determined to be running normally based on the operating parameters, and the target executable firmware is running for the first time, the execution status identifier is updated to the running success identifier, and the target executable firmware continues to run.

[0022] If the target executable firmware is determined to be running normally based on the operating parameters, and the target executable firmware is not running for the first time, the target executable firmware shall continue to run.

[0023] Alternatively, if the target executable firmware is determined to be malfunctioning based on the operating parameters, the microcontroller can be restarted.

[0024] According to one embodiment of this application, after determining that a first condition is met based on the execution status identifier, and after performing a security verification on the target executable firmware based on the second bootloader firmware, the method further includes:

[0025] If the security check fails, the microcontroller is restored based on the initial bootloader firmware and the initial executable firmware.

[0026] According to one embodiment of this application, in the event of a microcontroller restart, before obtaining the execution status identifier of the microcontroller based on the first bootloader firmware, the method further includes:

[0027] The firmware of the microcontroller is updated based on a firmware upgrade package; the firmware upgrade package is obtained by embedding the target bootloader firmware within the target executable firmware.

[0028] Based on the firmware update result, the execution status identifier is set.

[0029] According to one embodiment of this application, the firmware update of the microcontroller based on the firmware upgrade package includes:

[0030] The initial bootloader firmware includes a first initial bootloader firmware and a second initial bootloader firmware. If the version of the second bootloader firmware is higher than that of the second initial bootloader firmware, the second initial bootloader firmware is updated based on the second bootloader firmware, and the initial executor firmware is updated based on the target executor firmware.

[0031] In the case where the initial bootloader firmware includes a first initial bootloader firmware, the initial bootloader firmware is updated based on the first bootloader firmware, the second bootloader firmware is written into the updated initial bootloader firmware, and the initial executor firmware is updated based on the target executor firmware.

[0032] According to one embodiment of this application, setting the execution status identifier based on the firmware update result includes:

[0033] If the firmware update result is successful, the execution status flag is set to the firmware update success flag;

[0034] If the firmware update fails, the execution status flag is set to the firmware update failure flag.

[0035] Secondly, this application provides a microcontroller operating device, the device comprising:

[0036] The first processing module is used to obtain the execution status identifier of the microcontroller based on the first bootloader firmware when the microcontroller restarts; the execution status identifier includes an identifier that no upgrade has occurred, an identifier that the operation was successful, an identifier that the firmware was successfully updated, or an identifier that the firmware was not successfully updated; the microcontroller is a microcontroller that has been pre-upgraded based on the target bootloader firmware and the target executable firmware, respectively, to the initial bootloader firmware and the initial executable firmware, the target bootloader firmware including the first bootloader firmware and the second bootloader firmware.

[0037] The second processing module is used to perform a security verification on the target executable firmware based on the second bootloader firmware when the execution status identifier meets the first condition.

[0038] The third processing module is used to restore the microcontroller based on the initial bootloader firmware and the initial execution program firmware when the execution status identifier does not meet the first condition.

[0039] According to the microcontroller operating device of this application, when the microcontroller restarts, the execution status identifier of the microcontroller is obtained based on the first boot program firmware. If the execution status identifier meets the first condition, the target executable firmware is security-verified based on the second boot program firmware. If the execution status identifier does not meet the first condition, the microcontroller is restored based on the initial boot program firmware and the initial executable firmware. This allows for the determination of the firmware update execution status identifier after the microcontroller firmware upgrade process but before the security verification. In the event of firmware update failure or executable firmware failure, the firmware before the upgrade is restored. This reduces the risk of device bricking or malfunction due to power outages, software operation failures, or logical or version compatibility issues in the executable firmware itself during the process of upgrading the boot program firmware via the executable firmware. This improves the feasibility, risk resistance, and stability of upgrading the boot program firmware via the executable firmware.

[0040] Thirdly, this application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the microcontroller operation method described in the first aspect above.

[0041] Fourthly, this application provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the microcontroller operation method as described in the first aspect above.

[0042] Fifthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements the microcontroller operation method described in the first aspect above.

[0043] The above-described one or more technical solutions in the embodiments of this application have at least one of the following technical effects:

[0044] By obtaining the microcontroller's execution status identifier based on the first bootloader firmware when the microcontroller restarts, and performing a security verification on the target executable firmware based on the second bootloader firmware if the execution status identifier meets a first condition, and restoring the microcontroller based on the initial bootloader firmware and the initial executable firmware if the execution status identifier does not meet the first condition, the microcontroller can be restored. This allows for the determination of the firmware update execution status identifier after the microcontroller's firmware upgrade process but before the security verification. In the event of firmware update failure or executable firmware failure, the microcontroller's firmware before the upgrade can be restored. This reduces the risk of device bricking or malfunction due to power outages, software operation failures, or logical or version compatibility issues in the executable firmware itself during the process of upgrading the bootloader firmware via the executable firmware, thereby improving the feasibility, risk resistance, and stability of upgrading the bootloader firmware via the executable firmware.

[0045] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description

[0046] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which:

[0047] Figure 1 This is one of the flowcharts illustrating the operation method of a microcontroller provided in the embodiments of this application;

[0048] Figure 2 This is a second flowchart illustrating the operation method of the microcontroller provided in the embodiments of this application;

[0049] Figure 3 This is the third flowchart illustrating the operation method of the microcontroller provided in the embodiments of this application;

[0050] Figure 4 This is the fourth flowchart illustrating the operation method of the microcontroller provided in the embodiments of this application;

[0051] Figure 5 This is a schematic diagram of the structure of the microcontroller operating device provided in the embodiments of this application;

[0052] Figure 6 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0053] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.

[0054] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.

[0055] The following description, in conjunction with the accompanying drawings, details the microcontroller operation method, microcontroller operation device, electronic device, and readable storage medium provided in this application through specific embodiments and application scenarios.

[0056] The microcontroller's operating method can be applied to the terminal, specifically executed by the hardware or software within the terminal.

[0057] The terminal includes, but is not limited to, portable communication devices such as mobile phones or tablets. It should also be understood that, in some embodiments, the terminal may not be a portable communication device, but rather a desktop computer.

[0058] The microcontroller operation method provided in this application embodiment can be executed by a functional module or functional entity inside the microcontroller, or by an electronic device that is communicatively connected to the microcontroller. The electronic devices mentioned in this application embodiment include, but are not limited to, mobile phones, tablets, computers, cameras, and wearable devices. The following uses an electronic device as the execution subject to illustrate the microcontroller operation method provided in this application embodiment.

[0059] like Figure 1 As shown, the operation method of the microcontroller includes steps 110, 120 and 130.

[0060] A microcontroller is an integrated circuit chip that integrates multiple functions of a computer, such as CPU, memory, input interface, and output interface, onto a single chip.

[0061] The firmware of a microcontroller can be divided into two parts: the bootloader and the executable program (APP).

[0062] Among them, the Bootloader is the boot code that is executed upon power-up, and it is the first program to run when the microcontroller starts up; the APP is the business code, which may have online upgrade functionality, and it is loaded and run after the Bootloader has finished executing.

[0063] In actual execution, the Bootloader can detect external storage to determine whether to update the APP code. If an update is required, the APP code is upgraded; otherwise, it directly jumps to execute the APP code. If signature verification is required, the APP code can be verified. If the verification passes, it jumps to execute the APP code, i.e., executes the business code.

[0064] In the event that the Bootloader updates the APP code and the update is complete, the microcontroller will restart and re-enter the Bootloader for execution.

[0065] Step 110: When the microcontroller restarts, obtain the microcontroller's execution status identifier based on the first bootloader firmware;

[0066] In this step, the microcontroller is a microcontroller that has been upgraded based on the target bootloader firmware and the target executable firmware, respectively, by upgrading the initial bootloader firmware and the initial executable firmware.

[0067] The initial bootloader firmware is the bootloader firmware before the microcontroller bootloader was upgraded.

[0068] The initial executable firmware is the firmware used before the microcontroller executable was upgraded.

[0069] The target bootloader firmware is the bootloader firmware used to upgrade the initial bootloader firmware of the microcontroller.

[0070] The target executable firmware is the executable firmware used to upgrade the initial executable firmware of the microcontroller.

[0071] The target bootloader firmware includes a first bootloader firmware and a second bootloader firmware.

[0072] The first bootloader firmware is used to detect the firmware execution status identifier information of the microcontroller.

[0073] The second bootloader firmware is used to verify the signature of the executable firmware.

[0074] Signature verification is used to ensure the legitimacy of the executable firmware and better protect system security.

[0075] In actual execution, the microcontroller's external memory may include a first flag bit. The information stored in the first flag bit can be used to indicate whether there is a bootloader firmware and an executable firmware to be upgraded stored in the external memory. When the microcontroller's bootloader firmware is executed, the information stored in the flag bit can be detected. If the information indicates that there is a bootloader firmware and an executable firmware to be upgraded in the external memory, the microcontroller's bootloader firmware and executable firmware can be upgraded based on the bootloader firmware and executable firmware to be upgraded.

[0076] Upgrading the microcontroller's bootloader firmware and executable firmware based on the bootloader firmware and executable firmware to be upgraded includes: upgrading the microcontroller's executable firmware or upgrading both the microcontroller's bootloader firmware and executable firmware simultaneously.

[0077] It is understandable that the target bootloader firmware and the target executable firmware can be stored in the microcontroller's external memory, and the information in the first flag bit can be modified accordingly. When the initial bootloader firmware is executed, the initial bootloader firmware and the initial executable firmware are upgraded based on the target bootloader firmware and the target executable firmware, respectively.

[0078] It should be noted that, based on the target bootloader firmware and the target executable firmware, the initial bootloader firmware and the initial executable firmware of the microcontroller are upgraded respectively, including two cases: 1) upgrade failure; 2) upgrade success.

[0079] In actual execution, based on the target bootloader firmware and target executable firmware, the microcontroller after upgrading the initial bootloader firmware and initial executable firmware respectively includes the following situations: 1) Upgrade process performed but unsuccessful, and the microcontroller not running; 2) Upgrade process performed and successful, but the microcontroller not running; 3) Upgrade process performed and successful, and the microcontroller running at least once, where the microcontroller may run successfully or unsuccessfully. The above situations are those that may have occurred before this reboot.

[0080] It is understandable that microcontroller restarts can include: 1) the first run of a microcontroller after a firmware upgrade (i.e., the firmware upgrade process has just been completed, but the target executable firmware has not yet been executed, i.e., the first run); 2) the second run of a microcontroller after a firmware upgrade; 3) the third and subsequent runs of a microcontroller after a firmware upgrade.

[0081] The second run of the microcontroller after firmware upgrade is as follows: after upgrading the microcontroller based on the target bootloader firmware and the target executable firmware, the microcontroller successfully executes the target executable firmware (i.e., the business code) once based on the target bootloader firmware, and no new firmware to be upgraded is detected in the microcontroller's external memory, then the microcontroller starts up; or, after upgrading the microcontroller based on the target bootloader firmware and the target executable firmware, the first execution of the target executable firmware based on the target bootloader firmware fails.

[0082] Successfully executing the target executable firmware once based on the target bootloader firmware can be understood as successfully performing signature verification on the target executable firmware based on the second bootloader firmware in the target bootloader firmware, and successfully running the target executable firmware after signature verification.

[0083] It is understandable that the third and subsequent runs of a microcontroller after firmware upgrades are defined as: successfully executing the target executable firmware two or more times based on the target bootloader firmware.

[0084] The execution status indicators include an indicator that no upgrade has occurred, an indicator that the operation was successful, an indicator that the firmware update was successful, or an indicator that the firmware update was unsuccessful.

[0085] The execution status flag is "No upgrade has occurred," which means that the microcontroller has successfully run two or more times since the last upgrade process, that is, it has been upgraded for a period of time and no new upgrade has occurred; if there is a new upgrade requirement in the future, it can continue to be upgraded.

[0086] The execution status is marked as a successful execution, indicating that the microcontroller has successfully run once after the firmware upgrade, that is, the target executable firmware, i.e., the business code, has been successfully executed once based on the target bootloader firmware.

[0087] The execution status is marked as a firmware update success flag, indicating that the microcontroller has performed a firmware upgrade and successfully replaced the initial bootloader firmware with the target bootloader firmware.

[0088] Among them, the execution status identifier being a firmware update success identifier can include: the initial executor firmware update was successful (when the initial executor firmware is updated); or, both the initial bootloader firmware and the initial executor firmware (when both the initial bootloader firmware and the initial executor firmware are updated simultaneously) were successfully updated.

[0089] An execution status marked as "Firmware update unsuccessful" indicates that the microcontroller underwent a firmware upgrade but failed to replace the initial firmware with the new firmware. Situations where the execution status is marked as "Firmware update unsuccessful" include: failure to update the initial firmware (initial executable firmware, initial bootloader firmware, or both); or problems with the target executable firmware's business logic or incompatibility with the system hardware.

[0090] It should be noted that at the starting point of the microcontroller restart, the microcontroller's execution status identifier can only be one of the above-mentioned execution status identifiers. The microcontroller can select the corresponding execution operation based on the current execution status identifier. In some cases, it can further update the execution status identifier based on the execution result. That is, the execution status identifier can be dynamically updated based on the task nodes in the microcontroller firmware upgrade process. Moreover, each microcontroller restart will judge according to the order of no upgrade, successful operation, successful firmware update, or failed firmware update, until the execution status identifier is determined to be one of the above-mentioned identifiers, and then execute the corresponding process.

[0091] It is understandable that, in the case of the microcontroller restarting for the first time after firmware upgrade, the initial execution status of the microcontroller may include: firmware update successful or firmware update unsuccessful.

[0092] When the execution status is a firmware update success flag, the target executable firmware can be executed based on the target bootloader firmware. However, the execution result may be successful or unsuccessful. In the case of successful execution, the execution status flag can be updated from the firmware update success flag to the run success flag. In the case of execution failure, the execution status flag remains unchanged (firmware update success flag). The program is terminated when the execution status is a firmware update success flag.

[0093] In the case of the microcontroller restarting for the first time after firmware upgrade, the execution status indicators of the microcontroller termination can include: firmware update success (running unsuccessful) or run success.

[0094] When the microcontroller restarts for the second time after a firmware upgrade, the initial execution status indicators of the microcontroller may include: a firmware update success indicator or a successful execution indicator.

[0095] In the case of a second run where the microcontroller's initial state is marked as "firmware update successful," it indicates that the microcontroller failed to execute the target executable firmware based on the target bootloader firmware during its first run. In this case, other corresponding execution processes can be set for subsequent processing. If the microcontroller's initial state is marked as "run successful," it indicates that the microcontroller can subsequently run normally. Therefore, in the case of a second run after the microcontroller restarts for firmware upgrade processing, the microcontroller's termination execution status can be marked as "run successful" or updated to "no upgrade occurred."

[0096] In the case of the microcontroller restarting for the third or subsequent run after a firmware upgrade, the start and end execution status indicators of the microcontroller are the same as the end execution status indicator of the microcontroller in the case of the microcontroller restarting for the second run after a firmware upgrade.

[0097] Step 120: If the execution status indicator meets the first condition, perform a security verification on the target executable firmware based on the second bootloader firmware;

[0098] In this step, security verification, also known as signature verification, is used to ensure the legitimacy of the target executable firmware and better protect system security.

[0099] In actual execution, if the security check passes, the target executable firmware will run; otherwise, the microcontroller will terminate.

[0100] The first condition may include: 1) the microcontroller has not been upgraded; 2) the target executable firmware of the microcontroller has been successfully run; 3) the microcontroller firmware has been successfully updated and the target executable firmware has not been run.

[0101] Among them, 1) the microcontroller has not been upgraded: the microcontroller has successfully run two or more times since the last upgrade, and no new upgrade has occurred; 2) the target executable firmware of the microcontroller has been successfully run: the microcontroller has been successfully run once after the firmware update; 3) the microcontroller firmware has been successfully updated, but the target executable firmware has not been run: the microcontroller has undergone firmware upgrade and successfully replaced the initial bootloader firmware with the target bootloader firmware, and replaced the initial bootloader firmware with the target bootloader firmware, but the target executable firmware has not yet been executed based on the target bootloader firmware.

[0102] In actual execution, the reason why signature verification can be performed if the following conditions are met: 1) the microcontroller has not been upgraded, and 2) the target executable firmware of the microcontroller has been successfully run, is that since the upgraded executable firmware has been successfully executed, it is complete, usable, and legal, and the next step of the normal process can be directly executed, i.e., signature verification can be performed directly. The reason why signature verification can be performed if the following condition is met: 3) the microcontroller firmware has been successfully updated, and the target executable firmware has not been run, is that the microcontroller firmware has just been upgraded, and the signature verification of the upgraded executable firmware has not yet been performed. It can be understood that the next step can be to directly perform signature verification to determine whether the verification is successful and whether it can run normally.

[0103] like Figure 4 As shown, in the actual execution process, it can be determined whether the above first condition is met based on the execution status identifier. If it is met, it means that signature verification can be performed directly, and then the target executable firmware is verified for security based on the second bootloader firmware.

[0104] Step 130: If the execution status indicator does not meet the first condition, restore the microcontroller based on the initial bootloader firmware and the initial execution program firmware.

[0105] In this step, the following situations may not meet the first condition: 1) The microcontroller firmware was not updated successfully; 2) The microcontroller firmware was updated successfully, and the target executable firmware was run, but the run failed.

[0106] Among them, 1) the microcontroller failed to update: the microcontroller underwent firmware update processing, but failed to replace the initial firmware with the new firmware; 2) the microcontroller firmware update was successful and the target executable firmware was run, but failed to run: the microcontroller underwent firmware update processing and successfully replaced the initial bootloader firmware with the target bootloader firmware, and the target executable firmware was run, but failed to run due to problems with the business logic of the target executable firmware itself or incompatibility with the hardware.

[0107] In actual execution, the reasons for the failure of the microcontroller firmware update in 1) above can be: during the process of updating the initial bootloader firmware and initial execution program firmware based on the target bootloader firmware and target execution program firmware, a power outage or software operation failure may occur, which will cause irreversible damage to the target bootloader firmware and target execution program firmware, thus causing the firmware update to fail; the reasons for the failure of the microcontroller firmware update in 2) above can be: the target execution program firmware itself has problems with its business logic or is incompatible with the hardware, which will cause the target execution program firmware to fail to run.

[0108] Restoring a microcontroller based on the initial bootloader firmware and initial executable firmware can be understood as overwriting the failed target bootloader firmware and target executable firmware with the initial bootloader firmware and initial executable firmware.

[0109] In actual implementation, such as Figure 3 As shown, the initial bootloader firmware and initial executable firmware can be backed up in advance in the microcontroller's external memory, thus enabling... Figure 4 As shown, during the microcontroller restart process, if the execution status flag indicates that the first condition is not met, the microcontroller can be restored based on the initial bootloader firmware and the initial execution firmware to reduce the risk of the device becoming unusable.

[0110] like Figure 4 As shown, in some embodiments, if it is determined that the first condition is not met based on the execution status identifier, the reason for not meeting the first condition can also be reported to the system so that the user can obtain the reason for not meeting the first condition and facilitate the user to perform remedial operations based on the reason.

[0111] During the research and development process, the inventors discovered that in related technologies, when upgrading the bootloader firmware via an executable program firmware (APP), irreversible damage can occur if a power outage or software operation failure occurs during the bootloader erasure or writing process, leading to device bricking and subsequent inability to boot normally. This increases the risk of device bricking, especially since bootloader upgrades are frequent. Furthermore, when upgrading the bootloader via an APP, problems with the APP software itself, such as software logic issues or hardware version compatibility problems, can cause the system to malfunction, even preventing it from entering the subsequent upgrade process, thus also causing the device to malfunction and making it impossible to resolve the issue through online upgrades.

[0112] In this application, by obtaining the microcontroller's execution status identifier based on the new bootloader firmware used to detect execution status identifier information when the microcontroller restarts, and then performing a security verification on the target executable firmware based on the second bootloader firmware when the execution status identifier determines that a first condition is met, the bootloader firmware is upgraded via the executable firmware. Conversely, if the execution status identifier determines that the first condition is not met, the microcontroller is restored based on the initial bootloader firmware and the initial executable firmware. This allows for the determination of the firmware update execution status identifier before the firmware upgrade process, and the restoration of the microcontroller's firmware before the upgrade in case of firmware update failure or executable firmware failure. This reduces the risk of device bricking due to power outages or software operation failures during the bootloader firmware upgrade process, and also reduces the risk of system malfunction due to problems with the executable firmware software itself, such as software logic issues or hardware version compatibility issues. This improves the feasibility, resilience, and stability of upgrading the bootloader firmware via the executable firmware.

[0113] The control logic for determining the first condition based on the execution status flag is explained below.

[0114] In some embodiments, the execution status indicator satisfying the first condition may include:

[0115] The execution status is marked as "no upgrade has occurred";

[0116] Alternatively, the execution status can be marked as a successful execution;

[0117] Alternatively, the execution status is marked as a firmware update success flag, and the target executable firmware has not been run.

[0118] In this embodiment, such as Figure 4 As shown, in actual execution, if the execution status is marked as "no upgrade" or "run successfully", it can be directly determined that the first condition is met, and the target executable firmware can be directly verified based on the second bootloader firmware. However, if the execution status is marked as "firmware update successfully", it is necessary to further determine whether the target executable firmware has been run before determining whether the first condition is met.

[0119] One method is to determine whether the target executable firmware has been run by examining the information in the second flag bit of the target executable firmware.

[0120] In actual execution, an initial information can be set in the second flag bit of the target executable firmware. This initial information can be used to indicate that the target executable firmware has not been run. This initial information remains unchanged unless subsequent security verification of the target executable firmware is performed.

[0121] For example, the initial information of the second flag bit in the target executable firmware can be set to 0. If the execution status is marked as a firmware update success flag and the initial information is detected to be 0, it can be determined that the target executable firmware has not been run, and the first condition can be satisfied.

[0122] Understandably, if the execution status is marked as "firmware update successful" and the target executable firmware has not been run, meaning the microcontroller firmware has just been upgraded and the upgraded executable firmware has not yet been signed, then the first condition is met, and the next step can be to directly perform signature verification.

[0123] It should be noted that, as Figure 4 As shown, in the actual execution process, the execution status flag is judged to meet the first condition based on the order of the "no upgrade" flag, the "run successful" flag, and the "firmware update successful" flag. That is, first, it is judged whether the execution status flag is the "no upgrade" flag. If not, it is judged whether it is the "run successful" flag. If not, it is judged whether it is the "firmware update successful" flag.

[0124] In this embodiment, by determining that the first condition is met when the execution status identifier is an "no upgrade occurred" identifier, a "successful run" identifier, or a "successful firmware update" identifier, and the target executable firmware has not been run, the process of determining whether the first condition is met based on the execution status identifier can be realized and simplified, thereby improving system operating efficiency. In addition, by judging whether the execution status identifier meets the first condition based on the chronological order from the "no upgrade occurred" identifier, the "successful run" identifier to the "successful firmware update" identifier, the logic and rigor of the judgment can be improved, and the reliability of the judgment result can be increased.

[0125] In some embodiments, after obtaining the microcontroller's execution status identifier based on the first bootloader firmware in the event of a microcontroller restart, the method may further include:

[0126] like Figure 4As shown, if the execution status is initially set to "run successful," the execution status will be updated to "no upgrade occurred" during the second run. It's understandable that "second run" refers to any period during the second run; the status change could occur immediately upon entering the second run, during runtime, or after the second run is complete.

[0127] In this embodiment, it can be understood that since the execution status identifier being a successful execution identifier indicates that the target executable firmware could run normally in the previous run, the successful execution identifier can be directly updated to an upgrade-free identifier in this run. Thus, after the microcontroller restarts, it can directly determine that the first condition is met when the execution status identifier is identified as an upgrade-free identifier, thereby directly performing signature verification of the target executable firmware, simplifying the process of determining whether the first condition is met after the microcontroller restarts.

[0128] In this embodiment, when the execution status is marked as "run successful", the execution status is updated to "no upgrade occurred" during the second run. This simplifies the process of determining whether the first condition is met after the microcontroller restarts, thus improving system operating efficiency.

[0129] The control logic after performing security verification on the target executable firmware based on the second bootloader firmware is explained below.

[0130] In some embodiments, after performing a security verification on the target executable firmware based on the second bootloader firmware when the execution status identifier meets the first condition, the method may further include:

[0131] If the security check passes, control the target execution program firmware to run for the target duration and obtain the running parameters;

[0132] If the target executable firmware is running normally based on the operating parameters and this is the first time the target executable firmware is running, the execution status flag will be updated to the running success flag, and the target executable firmware will continue to run.

[0133] Alternatively, if the target executable firmware is determined to be running normally based on the operating parameters, and this is not the first time the target executable firmware has been run, then the target executable firmware may continue to run.

[0134] In this embodiment, the target duration can be a user-defined duration, such as 5 minutes, 6 minutes, or 7 minutes.

[0135] Running parameters can include response time, memory usage, CPU utilization, FPS (smoothness), and GPU rendering.

[0136] In actual execution, after the security verification is passed, the target executable firmware can be run for a period of time and the running parameters can be obtained to determine whether the target executable firmware can run normally.

[0137] like Figure 4 As shown, it is understandable that after the security verification is passed, the target executable firmware can be controlled to run for a period of time, and based on the running parameters, if the target executable firmware can run normally, it can be further determined whether the target executable is running for the first time.

[0138] The target executable firmware is running for the first time, meaning it has not been run before; conversely, the target executable firmware is not running for the first time, meaning it has been run before.

[0139] In actual execution, the method to determine whether the target executable firmware is running for the first time can be as follows: The first time is determined by checking the information in the second flag bit of the target executable firmware. Specifically, an initial information can be set in the second flag bit of the target executable firmware beforehand, indicating that the target executable firmware has not been run before. After the security check passes, this initial information is modified to obtain first information, which can be used to indicate that the target executable firmware is running for the first time. Then, after determining that the target executable firmware is running normally based on the running parameters, and after determining that the target executable firmware is running for the first time based on the initial information, the first information can be modified to obtain second information, which can be used to indicate that the target executable firmware is not running for the first time. That is, in the next microcontroller restart, the second information can be used to determine that the target executable firmware is not running for the first time.

[0140] For example, the initial information of the second flag bit in the target executable firmware can be set to 0. After subsequent security verification, the initial information can be updated to 1. Then, after determining that the target executable firmware is running for the first time based on the initial information of 1, the initial information can be modified to 2. Here, 0 can indicate that the target executable firmware has not been run before, 1 can indicate that the target executable firmware is running for the first time, and 2 can indicate that the target executable firmware is not running for the first time.

[0141] like Figure 4 As shown, before the target executable firmware is determined to be running normally based on the operating parameters and before the target executable firmware is running for the first time, the microcontroller's execution status is marked as a firmware update success, and the target executable firmware has not been run before. This means that the microcontroller firmware has just been upgraded and the upgraded executable firmware has not yet been signed and verified.

[0142] Understandably, if the microcontroller's execution status is set to "firmware update successful," and the target executable firmware is subsequently determined to be running normally based on the operating parameters, and this is the first time the target executable firmware is being run, the execution status can be updated to "run successful." This allows for direct determination of the first condition based on the execution status being "run successful," without needing to check whether the target executable firmware has not been run before when the execution status is "firmware update successful." This reduces process redundancy and improves system operating efficiency.

[0143] In this embodiment, by controlling the target execution program firmware's execution duration and acquiring execution parameters after the security verification passes, the system can continue executing the target program if the firmware is determined to be running normally based on the execution parameters, thereby improving system security. Furthermore, if the execution parameters determine that the firmware is running normally and this is the first run of the target program firmware, the execution status identifier is updated from a firmware update success identifier to a running success identifier. This allows for easy verification upon the next microcontroller restart, directly using the running success identifier to determine if the first condition is met, simplifying the judgment process, reducing redundancy, and improving system efficiency.

[0144] In some embodiments, after performing a security verification on the target executable firmware based on the second bootloader firmware when the execution status identifier meets the first condition, the method may further include:

[0145] like Figure 4 As shown, if the security check passes, the target execution program firmware is controlled to run for a specified duration and the running parameters are obtained.

[0146] If the target executable firmware is found to be malfunctioning based on the operating parameters, the microcontroller is restarted.

[0147] In this embodiment, if the target executable firmware is found to be running abnormally based on the running parameters, it can be understood that the business logic of the target executable firmware itself has a problem or is incompatible with the system hardware. In this case, the microcontroller can be controlled to restart and re-execute the judgment based on the execution status identifier to determine whether the first condition is met.

[0148] In actual execution, if the security check passes, the information of the second flag bit in the target executable firmware has been updated to the first information, which means that the target executable firmware is executed for the first time. It can be understood that the target executable has been executed, but due to business logic problems or incompatibility issues with the system hardware, the target executable firmware did not continue to execute subsequent steps, that is, the first information was not updated to the second information. In this case, the microcontroller can be restarted and the execution status flag can be used to determine whether the first condition is met again.

[0149] In this embodiment, by controlling the microcontroller to restart when the target executable firmware is determined to be running abnormally based on the running parameters, a control closed loop can be formed with the case where the first condition is not met based on the execution status identifier, thereby improving the rigor of the system's operating logic and reducing the system's error rate.

[0150] The control logic for cases where the first condition is not met is explained below based on the execution status flag.

[0151] In some embodiments, the execution status identifier not satisfying the first condition may include:

[0152] The execution status is marked as firmware update unsuccessful;

[0153] Alternatively, the execution status is marked as a firmware update success identifier, and the target executable firmware has been run.

[0154] In this embodiment, such as Figure 4 As shown, in actual execution, if the execution status is marked as "firmware not updated successfully", it can be directly determined that the first condition is not met, and the microcontroller can be directly restored based on the initial bootloader firmware and the initial execution program firmware. However, if the execution status is marked as "firmware updated successfully", it is necessary to further determine whether the target execution program firmware has been run before determining whether the first condition is not met.

[0155] The method for determining whether the target executable firmware has been run is similar to the above embodiment. That is, it can be determined whether the information of the second flag bit in the target executable firmware is initial information. If it is not initial information, it can be determined that the target executable firmware has been run.

[0156] It is understandable that if the execution status is marked as a firmware update success, and the target executable firmware is further judged as having been run, and the result of the judgment is that the target executable firmware has been run, that is, if the target executable firmware itself has business logic problems or incompatibility problems with system hardware, then it can be determined that the first condition is not met.

[0157] like Figure 4As shown, it should be noted that, in the case where the target executable firmware is found to be running abnormally based on the running parameters, after the microcontroller is restarted, since the microcontroller's execution status is marked as a firmware update success indicator, and the target executable firmware has been run and is running abnormally, it can be determined that the first condition is not met, and the firmware update can be considered to have failed. Thus, the microcontroller can be restored based on the initial bootloader firmware and the initial executable firmware.

[0158] In this embodiment, by determining that the first condition is not met when the execution status is marked as "firmware not updated successfully" or "firmware updated successfully" and the target executable firmware has been run, the process of determining that the first condition is not met based on the execution status can be realized and simplified, thereby improving system operating efficiency. In addition, it can also form a control closed loop with the situation of controlling the microcontroller to restart when the target executable firmware is determined to be running abnormally based on the running parameters, thereby improving the rigor of the system operating logic and reducing the system operation error rate.

[0159] The control logic for cases where the security check fails is explained below.

[0160] In some embodiments, after performing a security verification on the target executable firmware based on the second bootloader firmware when the execution status identifier meets the first condition, the method may further include:

[0161] like Figure 4 As shown, if the security check fails, the microcontroller is restored based on the initial bootloader firmware and the initial execution firmware.

[0162] In this embodiment, a security check failure can be understood as the target executable firmware being invalid, and the microcontroller can then be restored based on the initial bootloader firmware and the initial executable firmware.

[0163] In this embodiment, by restoring the microcontroller based on the initial bootloader firmware and the initial executable firmware when the security verification fails, the installation of target executable firmware that does not support secure boot functionality can be reduced, thereby improving the security of the system.

[0164] In some embodiments, if the security verification fails, the abnormal situation can be reported to the system to inform the user that the target executable firmware is invalid, so that the user can perform subsequent related operations.

[0165] The control logic before the microcontroller restarts is explained below.

[0166] In some embodiments, before obtaining the microcontroller's execution status identifier based on the first bootloader firmware in the event of a microcontroller restart, the method may further include:

[0167] like Figure 3 As shown, the firmware of the microcontroller is updated based on the firmware upgrade package;

[0168] Based on the firmware update results, set the execution status flag.

[0169] In this embodiment, the firmware upgrade package is obtained by embedding the target bootloader firmware within the target executable firmware.

[0170] It is understood that the firmware upgrade package is a firmware upgrade package that contains the target executable firmware and the target bootloader firmware.

[0171] like Figure 2 As shown, in the actual execution process, the target executable firmware and the target boot firmware with secure boot function can be downloaded in advance from external servers or the cloud. After the download is completed, the target boot firmware can be exported as an array and embedded in the target executable firmware to obtain the firmware upgrade package. The target boot firmware can then be updated based on the target executable firmware through the firmware upgrade package.

[0172] The firmware update result can be either "firm firmware update successful" or "firm firmware update failed".

[0173] Different firmware update results lead to different execution status flags for the microcontroller, resulting in different control flows after the microcontroller restarts.

[0174] In this embodiment, updating the microcontroller's firmware based on the firmware upgrade package can improve the update efficiency of the target bootloader firmware by updating the target executable firmware. Furthermore, by setting an execution status flag based on the firmware update result, it is possible to follow up with different control flows based on the execution status flag after the microcontroller restarts, thereby improving the control logic of the system.

[0175] In some embodiments, updating the firmware of a microcontroller based on a firmware upgrade package may include:

[0176] If the initial bootloader firmware includes a first initial bootloader firmware and a second initial bootloader firmware, and the version of the second bootloader firmware is higher than that of the second initial bootloader firmware, the second initial bootloader firmware is updated based on the second bootloader firmware, and the initial executor firmware is updated based on the target executor firmware.

[0177] In the case where the initial bootloader firmware includes a first initial bootloader firmware, the initial bootloader firmware is updated based on the first bootloader firmware, the second bootloader firmware is written into the updated initial bootloader firmware, and the initial executor firmware is updated based on the target executor firmware.

[0178] In this embodiment, when updating the firmware of the microcontroller based on the firmware upgrade package, it is first determined whether the initial bootloader firmware includes both the first initial bootloader firmware and the second initial bootloader firmware, or whether it does not include the second initial bootloader firmware.

[0179] In the case where the initial bootloader firmware includes a first initial bootloader firmware and a second initial bootloader firmware, it indicates that the initial bootloader firmware is a new version that supports the "first initial bootloader firmware + second initial bootloader firmware" structure; while in the case where the initial bootloader firmware does not include the second initial bootloader firmware, it indicates that the initial bootloader firmware is an old version that does not support the above structure.

[0180] like Figure 2 As shown, in the actual execution process, after the target executable firmware and the target bootloader firmware are downloaded and before the target bootloader firmware is embedded in the target executable firmware, attribute information, such as specific strings and firmware description information, can be added to a specified address of the first bootloader firmware in the target bootloader firmware. In subsequent execution, the existence of this attribute information at the specified address of the current initial bootloader firmware can be detected, thereby determining whether the current initial bootloader firmware is a new version or an old version.

[0181] The specified address can be any address in the microcontroller's internal memory.

[0182] like Figure 3 As shown, when the initial bootloader firmware is a new version, i.e., when the initial bootloader firmware includes a first initial bootloader firmware and a second initial bootloader firmware, since the first initial bootloader firmware is used to check the execution status indicator, it is not necessary to upgrade the first initial bootloader firmware again if it is determined to be a new version. However, if the initial bootloader firmware includes a second initial bootloader firmware, it is necessary to determine the version of the second initial bootloader firmware to determine whether the second bootloader firmware needs to be updated.

[0183] like Figure 2As shown, in actual execution, after the target executable firmware and the target bootloader firmware are downloaded and before the target bootloader firmware is embedded in the target executable firmware, information such as version number, attributes, and special identifiers can be set at a specified address of the second bootloader firmware in the target bootloader firmware. In subsequent execution, the version number set at the specified address of the current initial bootloader firmware can be detected and judged to be higher or lower than the version number set at the specified address of the initial bootloader firmware. If the version number of the second bootloader firmware is higher than that of the second initial bootloader firmware, the initial executable firmware is updated based on the target executable firmware. If the version number of the second bootloader firmware is lower than that of the second initial bootloader firmware, the second initial bootloader firmware is not updated.

[0184] In some embodiments, it can also be determined whether the second bootloader firmware is a bootloader firmware that supports secure boot functionality by detecting information such as a special identifier at a specified address of the second bootloader firmware; wherein, the special identifier is used to identify that the firmware is firmware that supports secure boot functionality, and in actual execution, the special identifier can be a custom fixed string, such as "I am sungrow", etc.

[0185] like Figure 3 As shown, if the initial bootloader firmware is an older version, that is, if the initial bootloader firmware does not include the second initial bootloader firmware, and it is necessary to replace the older version of the initial bootloader firmware with a bootloader firmware that supports the new version structure, then the initial bootloader firmware can be updated based on the first bootloader firmware first, and then the second bootloader firmware can be written into the updated initial bootloader firmware to form a complete target bootloader firmware.

[0186] It is understandable that regardless of whether the initial bootloader firmware is a new or old version, the initial executable firmware will be updated based on the target executable firmware.

[0187] In some embodiments, the signature and digest information of the target executable firmware may also be set at the specified address of the second bootloader firmware, thereby facilitating subsequent security verification of the target executable based on the second bootloader firmware.

[0188] like Figure 2 As shown, in some embodiments, after the target executable firmware and the target bootloader firmware are downloaded and before the target bootloader firmware is embedded in the target executable firmware, information such as version number, attributes, and special identifiers can be set at a specified address in the target executable firmware. In this way, by detecting the special identifiers and other information at the specified address of the target executable firmware, it can be determined whether the target executable firmware is an executable firmware that supports secure boot functionality.

[0189] In this embodiment, different update methods are adopted depending on whether the initial bootloader firmware is a new version or an old version. Updating and upgrading the initial bootloader firmware based on the target bootloader firmware can improve the flexibility and feasibility of updating the target bootloader firmware based on the target executable firmware.

[0190] In some embodiments, setting an execution status flag based on the firmware update result may include:

[0191] If the firmware update is successful, the execution status flag will be set to the firmware update success flag.

[0192] If the firmware update fails, the execution status flag will be set to the firmware update failure flag.

[0193] In this embodiment, a successful firmware update can include the following scenarios: if the initial bootloader firmware includes a first initial bootloader firmware and a second initial bootloader firmware, and the version of the second bootloader firmware is higher than that of the second initial bootloader firmware, then both the second bootloader firmware and the target executable firmware are successfully updated.

[0194] Alternatively, if the initial bootloader firmware includes a first initial bootloader firmware and a second initial bootloader firmware, and the version of the second bootloader firmware is lower than that of the second initial bootloader firmware, the target executable firmware update is successful.

[0195] Alternatively, if the initial bootloader firmware includes a first initial bootloader firmware, the first bootloader firmware, the second bootloader firmware, and the target executable firmware are all successfully updated.

[0196] In the above context, a firmware update failure can occur in any firmware update attempt.

[0197] Understandably, if any of the firmware update results are successful, the microcontroller's execution status flag can be set to the firmware update success flag; if any of the firmware update results in failure, the microcontroller's execution status flag can be set to the firmware update failure flag.

[0198] In this embodiment, by setting the execution status flag to the firmware update success flag when the firmware update result is successful, and setting the execution status flag to the firmware update failure flag when the firmware update result is unsuccessful, it is convenient to execute the corresponding control flow with the execution status flag set to firmware update success flag or firmware update failure flag after restarting the microcontroller.

[0199] The microcontroller operation method provided in this application can be executed by a microcontroller operating device. This application uses the microcontroller operating device executing the microcontroller operation method as an example to illustrate the microcontroller operating device provided in this application.

[0200] This application also provides a microcontroller operating device.

[0201] like Figure 5 As shown, the operating device of the microcontroller includes: a first processing module 510, a second processing module 520, and a third processing module 530.

[0202] The first processing module 510 is used to obtain the execution status identifier of the microcontroller based on the first boot program firmware when the microcontroller restarts. The execution status identifier includes an identifier that no upgrade has occurred, an identifier that the operation was successful, an identifier that the firmware was successfully updated, or an identifier that the firmware was not successfully updated. The microcontroller is a microcontroller that has been upgraded by pre-processing the initial boot program firmware and the initial execution program firmware based on the target boot program firmware and the target execution program firmware, respectively. The target boot program firmware includes the first boot program firmware and the second boot program firmware.

[0203] The second processing module 520 is used to perform security verification on the target executable firmware based on the second bootloader firmware when the execution status identifier meets the first condition.

[0204] The third processing module 530 is used to restore the microcontroller based on the initial boot program firmware and the initial execution program firmware when the execution status identifier does not meet the first condition.

[0205] According to the microcontroller operating device provided in the embodiments of this application, when the microcontroller restarts, the execution status identifier of the microcontroller is obtained based on the first boot program firmware. If the execution status identifier meets the first condition, the target executable firmware is security verified based on the second boot program firmware. If the execution status identifier does not meet the first condition, the microcontroller is restored based on the initial boot program firmware and the initial executable firmware. The execution status identifier can be judged after the firmware upgrade process of the microcontroller and before the security verification. In the case of firmware update failure or executable firmware failure, the firmware before the upgrade of the microcontroller is restored. This reduces the risk of the device becoming bricked or unable to work properly due to power failure, software operation failure, or logical or version compatibility problems in the executable firmware itself during the process of upgrading the boot program firmware through the executable firmware. This improves the feasibility, risk resistance and stability of upgrading the boot program firmware through the executable firmware.

[0206] In some embodiments, the device may further include a fourth processing module for:

[0207] When the microcontroller restarts, after obtaining the microcontroller's execution status identifier based on the first bootloader firmware, if the execution status identifier is a successful run identifier, the execution status identifier will be updated to a no-upgrade identifier during the second run.

[0208] In some embodiments, the device may further include a fifth processing module for:

[0209] If the execution status indicator meets the first condition, after performing a security check on the target executable firmware based on the second bootloader firmware, if the security check passes, the target executable firmware is controlled to run for the target duration and the running parameters are obtained.

[0210] If the target executable firmware is running normally based on the operating parameters and this is the first time the target executable firmware is running, the execution status flag will be updated to the running success flag, and the target executable firmware will continue to run.

[0211] Alternatively, if the target executable firmware is determined to be running normally based on the operating parameters and this is not the first time the target executable firmware has been run, the target executable firmware may continue to run.

[0212] Alternatively, if the target executable firmware is found to be malfunctioning based on the operating parameters, the microcontroller can be restarted.

[0213] In some embodiments, the device may further include a sixth processing module for:

[0214] If the execution status indicator meets the first condition, the target executable firmware is security verified based on the second bootloader firmware. If the security verification fails, the microcontroller is restored based on the initial bootloader firmware and the initial executable firmware.

[0215] In some embodiments, the device may further include a seventh processing module for:

[0216] In the event of a microcontroller restart, before obtaining the microcontroller's execution status identifier based on the first bootloader firmware, the microcontroller is firmware updated based on a firmware upgrade package; the firmware upgrade package is obtained by embedding the target bootloader firmware within the target executable firmware.

[0217] Based on the firmware update results, set the execution status flag.

[0218] In some embodiments, the seventh processing module can also be used for:

[0219] If the initial bootloader firmware includes a first initial bootloader firmware and a second initial bootloader firmware, and the version of the second bootloader firmware is higher than that of the second initial bootloader firmware, the second initial bootloader firmware is updated based on the second bootloader firmware, and the initial executor firmware is updated based on the target executor firmware.

[0220] In the case where the initial bootloader firmware includes a first initial bootloader firmware, the initial bootloader firmware is updated based on the first bootloader firmware, the second bootloader firmware is written into the updated initial bootloader firmware, and the initial executor firmware is updated based on the target executor firmware.

[0221] In some embodiments, the seventh processing module can also be used for:

[0222] If the firmware update is successful, the execution status flag will be set to the firmware update success flag.

[0223] If the firmware update fails, the execution status flag will be set to the firmware update failure flag.

[0224] The microcontroller running device in this embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this embodiment does not specifically limit its use.

[0225] The microcontroller operating device provided in this application embodiment can achieve Figures 1 to 4 The various processes implemented in the method implementation examples will not be described again here to avoid repetition.

[0226] like Figure 6 As shown, this application embodiment also provides an electronic device 600, including a processor 601, a memory 602, and a computer program stored in the memory 602 and executable on the processor 601. When the program is executed by the processor 801, it implements the various processes of the above-described microcontroller operation method embodiment and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0227] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.

[0228] This application also provides a non-transitory computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the various processes of the above-described microcontroller operation method embodiments and achieves the same technical effect. To avoid repetition, it will not be described again here.

[0229] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.

[0230] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described microcontroller operation method.

[0231] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.

[0232] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above-described microcontroller operation method embodiment and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0233] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.

[0234] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.

[0235] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the related technology, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0236] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.

[0237] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0238] Although embodiments of this application have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of this application, the scope of which is defined by the claims and their equivalents.

Claims

1. A method for operating a microcontroller, characterized in that, include: When the microcontroller restarts, the execution status identifier of the microcontroller is obtained based on the first bootloader firmware; The execution status identifiers include an identifier that no upgrade has occurred, an identifier that the operation was successful, an identifier that the firmware was successfully updated, or an identifier that the firmware was not successfully updated; the microcontroller is a microcontroller that has been upgraded in advance based on the target bootloader firmware and the target executable firmware, respectively, and the target bootloader firmware includes the first bootloader firmware and the second bootloader firmware. If the execution status identifier meets the first condition, the target executable firmware is subjected to security verification based on the second bootloader firmware. If the execution status identifier does not meet the first condition, the microcontroller is restored based on the initial bootloader firmware and the initial execution firmware.

2. The method for operating a microcontroller according to claim 1, characterized in that, The execution status indicator satisfies the first condition, including: The execution status identifier is the "no upgrade occurred" identifier; Alternatively, the execution status identifier may be the successful execution identifier; Alternatively, the execution status identifier may be the firmware update success identifier, and the target executable firmware may not have been run.

3. The method for operating a microcontroller according to claim 1, characterized in that, The execution status indicator does not meet the first condition, including: The execution status identifier is an identifier indicating that the firmware update was unsuccessful. Alternatively, the execution status identifier may be the firmware update success identifier, and the target executable firmware may have been run.

4. The method for operating a microcontroller according to any one of claims 1-3, characterized in that, In the event of a microcontroller restart, after obtaining the microcontroller's execution status identifier based on the first bootloader firmware, the method further includes: If the execution status identifier is the successful execution identifier, during the second run, the execution status identifier will be updated to the no-upgrade identifier.

5. The method for operating a microcontroller according to any one of claims 1-3, characterized in that, If the execution status identifier satisfies the first condition, after performing a security verification on the target executable firmware based on the second bootloader firmware, the method further includes: If the security verification passes, control the target execution program firmware to run for the target duration and obtain the running parameters; If the target executable firmware is determined to be running normally based on the operating parameters, and the target executable firmware is running for the first time, the execution status identifier is updated to the running success identifier, and the target executable firmware continues to run. Alternatively, if the target executable firmware is determined to be running normally based on the operating parameters, and the target executable firmware is not running for the first time, the target executable firmware may continue to run. Alternatively, if the target executable firmware is determined to be malfunctioning based on the operating parameters, the microcontroller can be restarted.

6. The method for operating a microcontroller according to any one of claims 1-3, characterized in that, If the execution status identifier satisfies the first condition, after performing a security verification on the target executable firmware based on the second bootloader firmware, the method further includes: If the security check fails, the microcontroller is restored based on the initial bootloader firmware and the initial executable firmware.

7. The method for operating a microcontroller according to any one of claims 1-3, characterized in that, In the event of a microcontroller restart, before obtaining the microcontroller's execution status identifier based on the first bootloader firmware, the method further includes: The firmware of the microcontroller is updated based on a firmware upgrade package; the firmware upgrade package is obtained by embedding the target bootloader firmware within the target executable firmware. Based on the firmware update result, the execution status identifier is set.

8. The method for operating a microcontroller according to claim 7, characterized in that, The firmware update of the microcontroller based on the firmware upgrade package includes: The initial bootloader firmware includes a first initial bootloader firmware and a second initial bootloader firmware. If the version of the second bootloader firmware is higher than that of the second initial bootloader firmware, the second initial bootloader firmware is updated based on the second bootloader firmware, and the initial executor firmware is updated based on the target executor firmware. In the case where the initial bootloader firmware includes a first initial bootloader firmware, the initial bootloader firmware is updated based on the first bootloader firmware, the second bootloader firmware is written into the updated initial bootloader firmware, and the initial executor firmware is updated based on the target executor firmware.

9. The method for operating a microcontroller according to claim 7, characterized in that, The step of setting the execution status identifier based on the firmware update result includes: If the firmware update result is successful, the execution status flag is set to the firmware update success flag; If the firmware update fails, the execution status flag is set to the firmware update failure flag.

10. A microcontroller operating device, characterized in that, include: The first processing module is used to obtain the execution status identifier of the microcontroller based on the first bootloader firmware when the microcontroller restarts. The execution status identifiers include an identifier that no upgrade has occurred, an identifier that the operation was successful, an identifier that the firmware was successfully updated, or an identifier that the firmware was not successfully updated; the microcontroller is a microcontroller that has been upgraded in advance based on the target bootloader firmware and the target executable firmware, respectively, and the target bootloader firmware includes the first bootloader firmware and the second bootloader firmware. The second processing module is used to perform a security verification on the target executable firmware based on the second bootloader firmware when the execution status identifier meets the first condition. The third processing module is used to restore the microcontroller based on the initial bootloader firmware and the initial execution program firmware when the execution status identifier does not meet the first condition.

11. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the microcontroller operation method as described in any one of claims 1-9.

12. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the microcontroller operation method as described in any one of claims 1-9.

13. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the microcontroller operation method as described in any one of claims 1-9.