CN-122018929-A - Firmware upgrading method and device based on MCU platform
Abstract
The invention relates to the technical field of embedded technology, and provides a firmware upgrading method and device based on an MCU platform. The method comprises the steps of determining an operation area based on a preset guiding strategy, operating original firmware in the operation area, storing target firmware corresponding to the upgrading to an un-operation area when a firmware downloading command is received, exchanging address ranges of the operation area and the un-operation area when a trial operation command is received, enabling the operation area to be configured into a new un-operation area, configuring the un-operation area into a new operation area to operate the target firmware, modifying operation values corresponding to the new operation area when a submitting command is received, enabling the modified operation values to be larger than operation values corresponding to an old operation area, ensuring that the firmware can normally jump to the new operation area after the firmware is upgraded, greatly simplifying firmware upgrading flow, and solving the problem that firmware versions in an A area and a B area in a module cannot be independent of each other.
Inventors
- LIU QING
- WANG XINYUE
- WEN HAO
- ZHOU QI
- ZHANG YING
- CHEN WEN
- XU WEI
- HUANG MINGHONG
- CAO SIYI
- WEI XIANGQUAN
Assignees
- 武汉光迅科技股份有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20241104
Claims (10)
- 1. The firmware upgrading method based on the MCU platform is characterized by comprising the following steps of: Determining an operation area based on a preset boot policy, and operating original firmware in the operation area; when a firmware downloading command is received, storing the target firmware corresponding to the upgrade to an un-running area; When a test run command is received, exchanging address ranges of the running area and the non-running area to enable the running area to be configured as a new non-running area, wherein the non-running area is configured as a new running area so as to run the target firmware; When a commit command is received, the operation value corresponding to the new operation area is modified, so that the modified operation value is larger than the operation value corresponding to the old operation area.
- 2. The firmware upgrading method based on the MCU platform according to claim 1, wherein the memory of the module comprises a first memory space and a second memory space, wherein the first memory space stores a first operation value and a first verification value, and the second memory space stores a second operation value and a second verification value; The module is provided with a cutting area identifier, wherein the cutting area identifier is used for indicating whether cutting area operation can be performed or not; the firmware upgrading method based on the MCU platform further comprises the following steps: when the test run command is received, if the cut area identifier is 1, setting the cut area identifier to 0, and then executing address range interchange.
- 3. The method for upgrading firmware based on the MCU platform according to claim 2, wherein the determining an operation area based on a preset boot policy, and operating the original firmware in the operation area comprises: The starting module is used for acquiring the first operation value and the second operation value, initializing the first storage space into an operation area if the first operation value and the second operation value are not the factory set values, and judging whether the cut area identifier is 1 or not; If the cutting area identification is 0, setting the cutting area identification as 1, and operating the original firmware in the operation area; If the second running value is greater than the first running value and the second verification value is 0, exchanging the address ranges of the first storage space and the second storage space so that the second storage space is used as a running area and the first storage space is used as an unoperated area; if the second running value is smaller than the first running value or the second verification value is not 0, the first storage space is still used as a running area, and the second storage space is used as an unoperated area.
- 4. The method for upgrading firmware based on the MCU platform according to claim 3, wherein the determining an operation area based on a preset boot policy, and operating the original firmware in the operation area further comprises: The starting module is used for setting the first verification value to 0 and acquiring the first running value and the second running value; If the first operation value and the second operation value are both factory setting values, setting the first operation value as 1, setting the second operation value as 0, configuring the first storage space as an operation area, configuring the second storage space as an unoperated area, and setting the cut area identifier as 1 to finish factory setting.
- 5. The method for upgrading firmware based on the MCU platform according to claim 2, wherein the determining an operation area based on a preset boot policy, and operating the original firmware in the operation area comprises: modifying a hardware pin corresponding to the module to configure a starting position of an MCU of the module as a starting address of a bootstrap program of the MCU; Resetting the MCU, starting to run the bootstrap program from the starting position, setting the first verification value to 0, and obtaining the first running value and the second running value; If the first operation value is larger than the second operation value, initializing the first storage space as an operation area, and initializing the second storage space as an un-operation area; And if the second operation value is larger than the first operation value, exchanging the address range of the first storage space and the address range of the second storage space so that the second storage space is used as an operation area, and the first storage space is used as an unoperated area.
- 6. The method for upgrading firmware based on the MCU platform according to claim 2, wherein the determining an operation area based on a preset boot policy, and operating the original firmware in the operation area comprises: Storing a first bootstrap program at a start address of the first storage space and storing the second bootstrap program at a start address of the second storage space; Resetting the MCU of the module, starting to run the first bootstrap program from the initial address of the first storage space, setting the first verification value to 0, and obtaining the first running value and the second running value; if the first running value is larger than the second running value, initializing the first storage space as a running area, initializing the second storage space as an unoperated area, and setting a reset vector address in an interrupt vector table of the MCU as a starting address of an application program in the running area so as to jump to the application program in the running area according to the reset vector address; and if the second running value is larger than the first running value, exchanging the address range of the first storage space and the second storage space to enable the second storage space to serve as a running area and the first storage space to serve as an unoperated area, and starting to run the second bootstrap program from the starting address of the second storage space to jump to run the application program in the running area.
- 7. The method for upgrading firmware on an MCU platform according to any one of claims 1 to 6, wherein when the commit command is received, modifying the operation value corresponding to the new operation region so that the modified operation value is greater than the operation value corresponding to the old operation region, includes: testing the target firmware to obtain a test result; When the test result has a problem, exchanging the address ranges of the new running area and the new non-running area again to switch the address ranges back, or resetting the MCU of the module; And when the test result has no problem, sending a commit command.
- 8. The method for upgrading firmware on an MCU platform according to any one of claims 1-6, wherein storing the target firmware corresponding to the current upgrade in the non-running area when receiving a firmware download command comprises: when a firmware downloading command is received and the firmware version in the running area is consistent with the firmware version in the non-running area, erasing the original firmware in the non-running area to ensure that the non-running area can normally receive the target firmware; When a verification command is received, CRC (cyclic redundancy check) is carried out on the target firmware based on the packet header information of the target firmware, so that a verification result is obtained; and when the verification result is that the firmware information is correct, storing the target firmware into an un-running area.
- 9. The firmware upgrading device based on the MCU platform is characterized by comprising at least one processor and a memory, wherein the at least one processor and the memory are connected through a data bus, the memory stores instructions which can be executed by the at least one processor, and the instructions are used for realizing the firmware upgrading method based on the MCU platform according to any one of claims 1-8 after being executed by the processor.
- 10. A non-transitory computer storage medium storing computer-executable instructions for execution by one or more processors for performing the MCU platform-based firmware upgrade method of any of claims 1-8.
Description
Firmware upgrading method and device based on MCU platform Technical Field The invention relates to the technical field of embedded technology, in particular to a firmware upgrading method and device based on an MCU platform. Background At present, optical modules are used in large batches in the optical communication industry, and the requirement on maintainability of the optical modules is more and more important due to the diversity of the functions of the optical modules. The development of firmware for the optical module requires consideration for firmware upgrade. For an optical module based on a micro control unit (Micro Controller Unit, abbreviated as MCU) platform, the traditional scheme is based on bootloader for MCU firmware upgrade. In the traditional double-area upgrading scheme, a Flash memory of the MCU is divided into two independent areas (namely an A area and a B area), when a bootloader area on the Flash memory operates, jump between the A area and the B area in the Flash memory is realized by reassigning an interrupt vector table, and firmware of a required upgrading version is backed up in a copying mode. When the jump is performed based on the interrupt vector table, since the firmware is obtained after the compiling is completed and can only perform the region jump with a fixed jump address, the firmware stored in the a region and the firmware stored in the B region must be in two identical versions. However, in most practical application scenarios, in order to facilitate testing, a comparison test is usually required between the firmware versions of the two versions, if the area a and the area B cannot be backed up independently, i.e., the firmware version stored in the area a and the firmware version stored in the area B have an interdependence relationship, in the comparison test process, the firmware version in the area B has to be upgraded each time when the firmware version in the area a is upgraded, the firmware version in the area a has to be upgraded each time when the firmware version in the area B is upgraded, which consumes too long time, resulting in poor practicality of the upgrade scheme, so that the conventional scheme does not meet the practical application requirements of the optical module. In view of this, overcoming the drawbacks of the prior art is a problem to be solved in the art. Disclosure of Invention The invention aims to provide a firmware upgrading method and device based on an MCU platform, which adopt a mode of exchanging address ranges to enable address mapping of two storage spaces to be overturned, so that the storage spaces are alternately used as operation areas to realize switching between the operation areas and non-operation areas, the operation areas are used for storing original firmware which is currently operated, the non-operation areas are used for receiving target firmware which is required by subsequent upgrading, so that the firmware in the two storage spaces are not affected by each other, the purpose that firmware versions in the two storage spaces are mutually independent is achieved, and the operation value corresponding to a new operation area is larger than the operation value corresponding to an old operation area, thereby finishing firmware upgrading, ensuring that the module can normally jump to the operation area before power failure, and greatly simplifying firmware upgrading flow. The invention adopts the following technical scheme: In a first aspect, the present invention provides a firmware upgrade method based on an MCU platform, including: Determining an operation area based on a preset boot policy, and operating original firmware in the operation area; when a firmware downloading command is received, storing the target firmware corresponding to the upgrade to an un-running area; When a test run command is received, exchanging address ranges of the running area and the non-running area to enable the running area to be configured as a new non-running area, wherein the non-running area is configured as a new running area so as to run the target firmware; When a commit command is received, the operation value corresponding to the new operation area is modified, so that the modified operation value is larger than the operation value corresponding to the old operation area. Further, the memory of the module comprises a first memory space and a second memory space, wherein the first memory space stores a first operation value and a first verification value, and the second memory space stores a second operation value and a second verification value; The module is provided with a cutting area identifier, wherein the cutting area identifier is used for indicating whether cutting area operation can be performed or not; the firmware upgrading method based on the MCU platform further comprises the following steps: when the test run command is received, if the cut area identifier is 1, setting the cut area identifier to 0, and then e