CN-121996278-A - Firmware upgrading method of MCU, electronic equipment and storage medium
Abstract
The invention discloses a firmware upgrading method of an MCU (micro control Unit), electronic equipment and a storage medium, wherein the firmware upgrading method of the MCU comprises the steps of running initial firmware, copying an App code of the firmware to be upgraded into a RAM of the MCU, calling a switching function in an App main cycle execution process of the initial firmware, acquiring a return address based on a function calling mechanism, and replacing the App code of the initial firmware in the RAM by using the App code of the firmware to be upgraded when the switching function is executed. According to the firmware upgrading method, the electronic equipment and the storage medium of the MCU, the firmware code to be upgraded is copied to the appointed area in the RAM in advance, and then the nanosecond instantaneous switching from the current firmware to the firmware to be upgraded is realized through a safety mechanism for automatically pushing the return address to the stack when a function is called. The code copying process can be normally interrupted by system interruption, so that real-time performance is not affected, and firmware upgrading of 'business noninductivity' is realized.
Inventors
- DENG JIAWEI
- WANG HAO
Assignees
- 芯弦半导体(苏州)有限公司
Dates
- Publication Date
- 20260508
- Application Date
- 20260130
Claims (10)
- 1. The firmware upgrading method of the MCU is characterized by comprising the following steps of: Running an initial firmware; Copying an App code of firmware to be upgraded into a RAM of the MCU; and in the process of executing the App main loop of the initial firmware, calling a switching function and acquiring a return address based on a function calling mechanism, wherein the App code of the initial firmware is replaced in the RAM by using the App code of the firmware to be upgraded when the switching function is executed.
- 2. The firmware upgrading method of the MCU according to claim 1, wherein the RAM is divided into a first area and a second area, the first area is divided into a first interrupt code sub-area, a first interrupt vector sub-area, a first read-only code sub-area and a first fixed code sub-area, the second area is divided into a second interrupt code sub-area, a second interrupt vector sub-area, a second read-only code sub-area and a second fixed code sub-area, the first interrupt code sub-area and the second interrupt code sub-area are used for storing an App interrupt code of the corresponding firmware, the first interrupt vector sub-area and the second interrupt vector sub-area are used for storing an App interrupt vector of the corresponding firmware, the first read-only code sub-area and the second read-only code sub-area are used for storing an App read-only code of the corresponding firmware, and the first fixed code sub-area and the second fixed code sub-area are used for storing an App () function of the corresponding firmware; When the switching function is executed, the corresponding codes in each sub-area of the first area are replaced by the corresponding codes in each sub-area of the second area.
- 3. The firmware upgrade method of the MCU according to claim 2, wherein the corresponding code segments in the first interrupt code sub-area and the first interrupt vector table sub-area are replaced by the corresponding code segments in the second interrupt code sub-area and the second interrupt vector table sub-area, and the corresponding code segments in the first read-only code sub-area and the first fixed code sub-area are replaced by the corresponding code segments in the second read-only code sub-area and the second fixed code sub-area.
- 4. The method for upgrading firmware of the MCU according to claim 1, wherein a section of the same fixed code is set in the App main () function of the initial firmware and the App main () function of the firmware to be upgraded, and the switching function is stored in a fixed area in the RAM of the MCU.
- 5. The method for upgrading firmware of the MCU according to claim 1, wherein a plurality of firmware App partitions are divided in Flash of the MCU, app key metadata of the initial firmware and App key metadata of the firmware to be upgraded are respectively stored in different firmware App partitions, and the operation of the initial firmware comprises setting up an App operation environment of the initial firmware based on the App key metadata of the initial firmware through Bootload programs.
- 6. The method for upgrading firmware of an MCU according to claim 1, wherein when an App code of firmware to be upgraded is copied into a RAM of the MCU, the copying is performed asynchronously in a background of an App main loop of an initial firmware or by a DMA controller.
- 7. The method for upgrading firmware of an MCU according to claim 1, wherein the method for upgrading firmware further comprises: setting a switching request mark with fixed address in the RAM; Copying the code of the firmware to be upgraded into a second area, and setting a switching request mark; Detecting a switching request mark at a preset position in the process of executing the App main loop of the initial firmware, and calling a switching function if the switching request mark is set.
- 8. The method for upgrading firmware of an MCU according to claim 1, wherein the function call mechanism is a standard function call mechanism of C language.
- 9. An electronic device comprising at least one processor, and A memory storing instructions that, when executed by the at least one processor, cause the at least one processor to perform the firmware upgrade method of the MCU of any of claims 1-8.
- 10. A machine readable storage medium storing executable instructions that, when executed, cause the machine to perform a firmware upgrade method of an MCU of any of claims 1-8.
Description
Firmware upgrading method of MCU, electronic equipment and storage medium Technical Field The invention belongs to the technical field of firmware upgrading, and particularly relates to a firmware upgrading method of an MCU, electronic equipment and a storage medium. Background In order to meet the high availability requirement of the server, industry standards place clear demands on digital power firmware upgrades, which must ensure that power supply is not interrupted, critical business logic continues to operate, and system reset time is extremely short when firmware updates are implemented. Against this background, the prior art provides the following two main schemes: 1. The double-Bank firmware upgrading scheme is characterized in that new and old firmware is alternately stored by dividing two independent storage areas (banks) so as to realize seamless switching of interrupt service in the upgrading process. However, the implementation of the scheme is seriously dependent on the dual-band mapping function of MCU hardware, and requires to support the online instant switching of Flash. This increases the threshold for chip hardware specifications, increasing design and procurement costs. 2. Ti (Texas instruments) on-line firmware upgrade scheme-this scheme emphasizes the completion of firmware update switches under fast hardware reset conditions, aimed at shortening system unavailability times. The scheme not only highly depends on the hardware dual-band mapping and the quick interrupt function, but also has an inherent performance bottleneck in a core quick resetting mechanism. The actual measurement data shows that the reset window period is 3.5 microseconds, so that service response is delayed, and the real seamless inheritance of the state cannot be realized, thereby limiting the application of the scheme in high-end scenes with strict requirements on switching time. The information disclosed in this background section is only for enhancement of understanding of the general background of the invention and should not be taken as an acknowledgement or any form of suggestion that this information forms the prior art already known to a person of ordinary skill in the art. Disclosure of Invention The invention aims to provide a firmware upgrading method of an MCU, electronic equipment and a storage medium, which can realize quick firmware upgrading and switching on the MCU with a single-band architecture. In order to achieve the above object, a specific embodiment of the present invention provides the following technical solution: the firmware upgrading method of the MCU comprises the steps of running initial firmware, copying an App code of the firmware to be upgraded into a RAM of the MCU, calling a switching function and acquiring a return address based on a function calling mechanism in an App main loop execution process of the initial firmware, and replacing the App code of the initial firmware in the RAM by using the App code of the firmware to be upgraded when the switching function is executed. In one or more embodiments of the present invention, the RAM is divided into a first area and a second area, the first area is divided into a first interrupt code sub-area, a first interrupt vector sub-area, a first read-only code sub-area and a first fixed code sub-area, the second area is divided into a second interrupt code sub-area, a second interrupt vector sub-area, a second read-only code sub-area and a second fixed code sub-area, the first interrupt code sub-area and the second interrupt code sub-area are used for storing an App interrupt code of a corresponding firmware, the first interrupt vector sub-area and the second interrupt vector sub-area are used for storing an App read-only code of the corresponding firmware, the first fixed code sub-area and the second fixed code sub-area are used for storing an App main () function of the corresponding firmware, and when the switching function is executed, the corresponding codes in the sub-areas of the second area are used for replacing the corresponding codes in the sub-areas of the first area. In one or more embodiments of the present invention, the corresponding code segments in the first interrupt code sub-region and the first interrupt vector table sub-region are replaced first with the corresponding code segments in the second interrupt code sub-region and the second interrupt vector table sub-region, and the corresponding code segments in the first read-only code sub-region and the first fixed code sub-region are replaced second with the corresponding code segments in the second read-only code sub-region and the second fixed code sub-region. In one or more embodiments of the present invention, a section of the same fixed code is set in the App main () function of the initial firmware and the App main () function of the firmware to be upgraded, and the switching function is stored in a fixed area in the RAM of the MCU. In one or more embodiments