CN-122018950-A - Firmware upgrading method and device, electronic equipment and storage medium
Abstract
The application provides a firmware upgrading method, a device, electronic equipment and a storage medium, wherein the method is applied to the field of software upgrading and comprises the steps of responding to a firmware upgrading request, obtaining an upgrading file of firmware to be upgraded and a partition zone bit of a current running program in a preset nonvolatile storage area, analyzing the upgrading file based on a preset data transmission service to obtain a target writing address, determining a logic partition where the partition zone bit is located according to the partition zone bit, determining the logic partition where the target writing address belongs, and writing the upgrading file into the logic partition where the target writing address belongs under the condition that the logic partition corresponding to the current running program and the logic partition where the target writing address belongs are different partitions so as to upgrade the firmware to be upgraded. According to the method, on a microcontroller only supporting a single program storage area, logical double partitions are divided through software, and address filtering and redundant flag bit management in running are combined, so that a safe and reliable background firmware upgrading and automatic rollback mechanism without shutdown is realized.
Inventors
- BI DANDAN
- ZHU BIN
Assignees
- 曼德电子电器有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20260108
Claims (10)
- 1. A method of firmware upgrade, the method comprising: Responding to a firmware upgrading request, and acquiring an upgrading file of firmware to be upgraded and a partition flag bit of a current running program in a preset nonvolatile storage area; Analyzing the upgrade file to obtain a target write-in address based on a preset data transmission service, and determining a logic partition corresponding to the current running program according to the partition zone bit of the current running program; determining a logic partition to which the target write address belongs, and writing the upgrade file into the logic partition to which the target write address belongs to upgrade the firmware to be upgraded under the condition that the logic partition corresponding to the current running program and the logic partition to which the target write address belongs are different partitions.
- 2. The method of claim 1, further comprising, prior to obtaining the upgrade file of the firmware to be upgraded and the partition flag bit of the currently running program in the preset nonvolatile storage area: Dividing a code storage area into a first logic partition, a second logic partition and a boot manager partition based on a preset address boundary; Configuring a first linking script according to the starting address of the first logical partition, compiling and linking a first source code of an operating program corresponding to the first linking script, and generating a first program mirror image corresponding to the first logical partition; Configuring a second linking script according to the starting address of the second logical partition, compiling and linking a second source code of an operating program corresponding to the second linking script, and generating a second program mirror image corresponding to the second logical partition; And merging the first program image and the second program image based on a first address space of the first program image and a second address space of the second program image, and filling a target system value into the boot manager partition to obtain an upgrade file of the firmware to be upgraded.
- 3. The method according to claim 1, further comprising, after acquiring an upgrade file of firmware to be upgraded and a partition flag bit of a currently running program in a preset nonvolatile memory area: Reading partition zone bit in the preset nonvolatile storage area, and reading a first logical partition and a second logical partition by utilizing the partition zone bit; judging whether the partition flag bit is invalid, or whether a first logic partition pointed by the partition flag bit is invalid, or whether a second logic partition pointed by the partition flag bit is invalid; If the partition flag bit is invalid, or the first logic partition pointed by the partition flag bit is invalid, or the second logic partition pointed by the partition flag bit is invalid, checking the logic partition in an invalid state and/or repairing the partition flag bit, otherwise, jumping to the starting address of the current running program.
- 4. The method of claim 3, wherein verifying the logical partition in the invalid state comprises: If the first logical partition pointed by the partition mark bit is invalid, performing cyclic redundancy check on the first logical partition to obtain a first verification result of the first logical partition, and starting the first logical partition when the first verification result meets a preset effective condition; and if the second logical partition pointed by the partition mark bit is invalid, performing cyclic redundancy check on the second logical partition to obtain a second verification result of the second logical partition, and starting the second logical partition when the second verification result meets the preset valid condition.
- 5. The method as recited in claim 1, further comprising: judging whether a rollback instruction is received or not; and if the rollback instruction is received, switching the zone bit from the current zone bit to a target zone bit, and controlling the current running program to run in a logical zone corresponding to the target zone bit when restarting.
- 6. The method of claim 1, further comprising, after determining the logical partition to which the target write address belongs: and if the logical partition corresponding to the current running program and the logical partition to which the target write-in address belongs are the same partition, discarding the upgrade file of the firmware to be upgraded.
- 7. A firmware upgrade apparatus, the apparatus comprising: The system comprises an acquisition module, a storage module and a control module, wherein the acquisition module is used for responding to a firmware upgrading request and acquiring an upgrading file of firmware to be upgraded and a partition zone bit of a current running program in a preset nonvolatile storage area; The determining module is used for analyzing the upgrade file to obtain a target write-in address based on a preset data transmission service, and determining a logic partition corresponding to the current running program according to the partition flag bit of the current running program; and the upgrading module is used for determining the logic partition to which the target write address belongs and writing the upgrading file into the logic partition to which the target write address belongs to upgrade the firmware to be upgraded under the condition that the logic partition corresponding to the current running program and the logic partition to which the target write address belongs are different partitions.
- 8. The apparatus of claim 7, wherein the acquiring module, before acquiring the upgrade file of the firmware to be upgraded and the partition flag bit of the currently running program in the preset nonvolatile storage area, further comprises: The dividing unit is used for dividing the code storage area into a first logic partition, a second logic partition and a guide manager partition based on a preset address boundary; the first generation unit is used for configuring a first link script according to the starting address of the first logical partition, compiling and linking a first source code of an operating program corresponding to the first link script, and generating a first program mirror image corresponding to the first logical partition; the second generation unit is used for configuring a second link script according to the starting address of the second logical partition, compiling and linking a second source code of an operating program corresponding to the second link script, and generating a second program mirror image corresponding to the second logical partition; And the merging unit is used for merging the first program image and the second program image based on the first address space of the first program image and the second address space of the second program image, and filling the target system value into the boot manager partition to obtain the upgrade file of the firmware to be upgraded.
- 9. An electronic device, characterized in that it comprises a firmware upgrade method as claimed in any one of the preceding claims 1-6.
- 10. A computer readable storage medium, characterized in that the computer readable storage medium stores a computer program which, when executed, implements the method according to any of claims 1 to 6.
Description
Firmware upgrading method and device, electronic equipment and storage medium Technical Field The present application relates to the field of software upgrade, and more particularly, to a firmware upgrade method, apparatus, electronic device, and storage medium in the field of software upgrade. Background With the intelligent development of automobiles, an on-board electronic control unit needs to support the functions of air upgrade and fault rollback, and higher requirements are put forward on firmware upgrade and fault recovery capability (rollback). In the related art, a high-end MCU (MicrocontrollerUnit) with a physical dual BankFlash is relied on, one of which runs a current program, and the other of which downloads new firmware in the background, so that seamless switching is realized. However, the low-medium-end MCUs of some manufacturers generally only provide a single BankCodeFlash, and the program codes thereof include instructions such as absolute address jumps, fixed interrupt vector tables and the like which depend on the starting address after compiling, and cannot be dynamically relocated, so that it is difficult to store two executable versions simultaneously, and background non-inductive upgrade and software version rollback are also difficult to realize. Disclosure of Invention The application provides a firmware upgrading method, a device, electronic equipment and a storage medium, wherein the method can divide logic double partitions through software on a microcontroller only supporting a single program storage area, and combines address filtering and redundant flag bit management in running to realize a safe and reliable background firmware upgrading and automatic rollback mechanism without shutdown. The firmware upgrading method comprises the steps of responding to a firmware upgrading request, obtaining an upgrading file of firmware to be upgraded and partition zone bit of a current running program in a preset nonvolatile storage area, analyzing the upgrading file based on a preset data transmission service to obtain a target writing address, determining a logic partition corresponding to the current running program according to the partition zone bit of the current running program, determining the logic partition to which the target writing address belongs, and writing the upgrading file into the logic partition to which the target writing address belongs under the condition that the logic partition corresponding to the current running program and the logic partition to which the target writing address belongs are different partitions so as to upgrade the firmware to be upgraded. Through the technical scheme, the logic double partition can be divided by software on the microcontroller only supporting a single program storage area, and the background firmware upgrading and automatic rollback mechanism which is free of shutdown, safe and reliable is realized by combining address filtering and redundant flag bit management during running. In combination with the first aspect, in some possible implementation manners, before obtaining the upgrade file of the firmware to be upgraded and the partition flag bit of the current running program in the preset nonvolatile storage area, the method further comprises dividing a code storage area into a first logic partition, a second logic partition and a boot manager partition based on a preset address boundary, configuring a first linking script according to the starting address of the first logic partition, compiling and linking a first source code of the running program corresponding to the first linking script to generate a first program image corresponding to the first logic partition, configuring a second linking script according to the starting address of the second logic partition, compiling and linking a second source code of the running program corresponding to the second linking script to generate a second program image corresponding to the second logic partition, merging the first program image and the second program image based on the first address space of the first program image and the second address space of the second program image, and filling a target system value into the boot manager partition to obtain the firmware to be upgraded. By the technical scheme, the generated upgrade file not only contains two complete, independent and directly executable application program copies, but also maintains the physical layout strictly aligned with the target MCU storage architecture, and lays a foundation for realizing safe and noninductive dual-version coexistence and switching on a single-Bank hardware platform. With reference to the first aspect and the implementation manner, in some possible implementation manners, after obtaining the upgrade file of the firmware to be upgraded and the partition flag bit of the current running program in the preset nonvolatile storage area, the method further comprises the steps of reading the parti