CN115718610A - Reliable method for updating application program of single chip microcomputer - Google Patents

Reliable method for updating application program of single chip microcomputer Download PDF

Info

Publication number
CN115718610A
CN115718610A CN202211506169.5A CN202211506169A CN115718610A CN 115718610 A CN115718610 A CN 115718610A CN 202211506169 A CN202211506169 A CN 202211506169A CN 115718610 A CN115718610 A CN 115718610A
Authority
CN
China
Prior art keywords
upgrading
area
app
identifier
backup
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211506169.5A
Other languages
Chinese (zh)
Inventor
李振文
李振威
贤健军
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Smart Li Ion Energy Technology Co ltd
Original Assignee
Shenzhen Smart Li Ion Energy Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Smart Li Ion Energy Technology Co ltd filed Critical Shenzhen Smart Li Ion Energy Technology Co ltd
Priority to CN202211506169.5A priority Critical patent/CN115718610A/en
Publication of CN115718610A publication Critical patent/CN115718610A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Stored Programmes (AREA)

Abstract

The invention discloses a reliable method for updating an application program of a single chip microcomputer, which comprises the following steps: s1: an upgrade identifier 1, an upgrade identifier 2, an upgrade identifier 3 and a lifting identifier 4 are preset and respectively correspond to a communication mode, a copy mode, a recovery mode and a backup mode; s2: initializing hardware, checking whether an upgrading identifier exists, and if the upgrading identifier exists, upgrading the software according to an upgrading mode corresponding to the upgrading identifier; s3: if the upgrade identifier is not checked in the S2, whether the app is normal or not is checked, and if the app is checked to be abnormal, the recovery mode is directly adopted for software upgrade; s4: and if the program verification of the backup area is abnormal, copying the normal program from the running area to the backup area to complete the program backup. The method is stable and reliable, and can automatically recover the firmware of the previous version when the file cannot run due to power failure or interruption caused by other reasons in the upgrading process, thereby ensuring the normal running of the software.

Description

Reliable method for updating application program of single chip microcomputer
Technical Field
The invention relates to the technical field of upgrading of single-chip microcomputer application programs, in particular to a reliable method for updating the single-chip microcomputer application programs.
Background
Embedded application software refers to system software and application software that are embedded within a dedicated computer system that performs independent functions. The embedded system has expandability in the application process, and the expandable equipment of the embedded system is roughly divided into three parts, wherein a single chip Microcomputer (MCU) is a core part, and a control function of a program is realized by combining a CPU device and peripheral hardware equipment in the system. In the specific application process, the CPU device is connected with a peripheral device of the system through an SPI (serial peripheral interface) to realize data information exchange between the CPU and the single chip microcomputer. The data information module is used for realizing information transmission between the single chip microcomputer and the peripheral hardware system, the application of the single chip microcomputer in the system can realize functional expansion through interfaces such as an I/O port, and functional conversion is realized under the combined action of the single chip microcomputer and the peripheral hardware system.
In practical use, due to the continuous change of the requirements of customers and the continuous change of application environments, software upgrading is difficult to avoid, and the conventional software upgrading methods of the MCU include the following methods:
1)ICP-(In-circuit programmer)
ICP indicates a mode in which a program is programmed in a circuit, and a program is not required in an MCU, and a program storage region can be programmed by directly powering on the MCU, such as JTAG or SWD used at ordinary times. The method is generally used in the process of development or production before factory shipment, and the method needs a special downloading tool and has limitation in application.
2)ISP-(In-system programer)
The ISP indicates that the system is programmed, and the MCU is programmed through a serial programming interface dedicated to the MCU, that is, the MCU needs to have external operating conditions, such as a crystal oscillator, etc., for example, stm32 used at ordinary times, sets a corresponding start mode by setting a boot pin, and then upgrades an internal Flash through a serial port, etc., so that a manufacturer may solidify a BootLoader program inside a chip, but this method cannot be used if hardware is not a solidified communication method or power control pins are different, and has the problems of being not universal, being unable to customize communication pins, etc., and is currently rarely used.
3)IAP-(In-application programer)
The IAP represents in application programming, is equivalent to customizing a bootstrap program, CAN realize various upgrading modes such as a serial port, a CAN, an Ethernet and the like by programming design, is very flexible, is a more popular mode used in the industry at present, and as shown in figure 1, for a common application case of the upgrading method, the method has two defects, namely, firstly, the updating firmware is to directly erase the original flash2 data, if the upgrading process is interrupted through a communication port after the erasing, the automatic recovery cannot be realized, and the upgrading is needed again; secondly, if the version is updated, the version cannot be restored without the original version, and the use is very inconvenient.
Disclosure of Invention
The invention aims to provide a reliable method for updating an application program of a single chip microcomputer, which is stable and reliable, can automatically recover to the firmware of the previous version when a file cannot run due to power failure or interruption of other reasons or upgrading errors in the upgrading process, ensures that software can run normally, has multiple modes for upgrading, can be freely selected by a user according to actual requirements, and has strong universality.
In order to realize the purpose, the following technical scheme is adopted:
a reliable method for updating an application program of a single chip microcomputer comprises the following steps:
s1: an upgrade identifier 1, an upgrade identifier 2, an upgrade identifier 3 and a lifting identifier 4 are preset, wherein the upgrade identifier 1 indicates that software upgrade is performed in a communication mode, the lifting identifier 2 indicates that software upgrade is performed in a copy mode, the upgrade identifier 3 indicates that software upgrade is performed in a recovery mode, and the upgrade identifier 4 indicates that software upgrade is performed in a backup mode;
s2: initializing hardware, checking whether an upgrading identifier exists or not, and if the upgrading identifier exists and is one of the upgrading identifiers S1, upgrading the software according to an upgrading mode corresponding to the upgrading identifier;
s3: if the upgrade identification is not checked in the S2, verifying whether the app is normal, if the app is abnormal, directly adopting a recovery mode to upgrade the software, and if the app is normal, verifying whether the program of the backup area is normal;
s4: and if the program verification of the backup area is abnormal, copying the normal program from the running area to the backup area to complete the program backup.
Further, the software upgrading method in the communication mode specifically includes the following steps:
s11: sending an upgrading instruction to the app so that the app jumps to a boot area to run a boot program BootLoader;
s12: directly writing the firmware data into an operation area of the internal flash through a communication interface;
s13: and after the firmware is downloaded, verifying the firmware data of the operation area, if the verification is successful, jumping to the operation area to operate the app, and if the verification is failed, restoring the original firmware from the backup area of the external flash.
Further, the software upgrading method in the copy mode specifically includes the following steps:
s11: sending an upgrading instruction to the app, and directly writing the firmware data into an external flash through a communication interface;
s12: after the firmware is downloaded, checking firmware data in the external flash, and if the checking is successful, jumping to a boot area to run a boot loader;
s13: copying firmware data from an external flash through a BootLoader of a bootstrap program, and writing the firmware data into an internal flash;
s14: and after the writing is finished, verifying the firmware data in the internal flash, if the verification is successful, jumping to the operation area to operate the app, and if the verification is failed, restoring the original firmware from the backup area of the external flash.
Further, the software upgrading method in the recovery mode specifically includes the following steps:
s11: copying firmware data from a backup area of an external flash to an internal flash directly;
s12: and after the copying is finished, checking the firmware data in the internal flash, and if the checking is successful, jumping to the running area to run the app.
Further, the backup mode includes an automatic backup mode and a manual backup mode.
Further, the software upgrading method in the automatic backup mode specifically includes the following steps:
s51: checking whether the data in the parameter area in the internal flash is correct or not, and if not, backing up the app data of the current running area to a backup area of the external flash;
s52: and checking the firmware data in the external flash, if the checking is successful, storing the checked parameter data into a parameter area in the internal flash, and jumping to a running area to run the app.
Further, the software upgrading method in the manual backup mode specifically includes the following steps:
s51: sending a backup instruction to the app to enable the app to jump to a boot area to run a boot loader;
s52: copying the firmware data of the running area to an external flash;
s53: and after the copying is finished, checking the firmware data of the internal flash, and after the checking is successful, jumping to the running area to run the app.
Further, the communication interface is any one of the following interfaces: UART communication interface, 485 communication interface, CAN communication interface.
By adopting the scheme, the invention has the beneficial effects that:
the method is stable and reliable, in the upgrading process, due to outage or interruption of other reasons or upgrading errors, the file cannot run, the file can be automatically recovered to be the firmware of the previous version, normal running of software is guaranteed, the upgrading mode is multiple, users can freely select the upgrading mode according to actual requirements, and universality is high.
Drawings
FIG. 1 is a schematic block diagram of a conventional IAP software upgrade;
FIG. 2 is a schematic block diagram of the present invention;
FIG. 3 is a schematic flow chart of the present invention;
Detailed Description
The invention is described in detail below with reference to the figures and the specific embodiments.
Referring to fig. 2 to 3, the invention provides a reliable method for updating an application program of a single chip microcomputer, which comprises the following steps:
s1: an upgrade identifier 1, an upgrade identifier 2, an upgrade identifier 3 and a lifting identifier 4 are preset, wherein the upgrade identifier 1 indicates that software upgrade is performed in a communication mode, the lifting identifier 2 indicates that software upgrade is performed in a copy mode, the upgrade identifier 3 indicates that software upgrade is performed in a recovery mode, and the upgrade identifier 4 indicates that software upgrade is performed in a backup mode;
s2: initializing hardware, checking whether an upgrading identifier exists or not, and if the upgrading identifier exists and is one of the upgrading identifiers S1, upgrading the software according to an upgrading mode corresponding to the upgrading identifier;
s3: if the upgrade identification is not checked in the S2, verifying whether the app is normal, if the app is abnormal, directly adopting a recovery mode to upgrade the software, and if the app is normal, verifying whether the program of the backup area is normal;
s4: and if the program verification of the backup area is abnormal, copying the normal program from the running area to the backup area to complete the program backup.
The software upgrading method in the communication mode specifically comprises the following steps:
s11: sending an upgrading instruction to the app so that the app jumps to a boot area to run a boot program BootLoader;
s12: directly writing the firmware data into an operation area of the internal flash through a communication interface;
s13: and after the firmware is downloaded, verifying the firmware data of the operation area, if the verification is successful, jumping to the operation area to operate the app, and if the verification is failed, restoring the original firmware from the backup area of the external flash.
The software upgrading method of the copy mode specifically comprises the following steps:
s11: sending an upgrading instruction to the app, and directly writing the firmware data into the external flash through a communication interface;
s12: after the firmware is downloaded, checking firmware data in the external flash, and if the checking is successful, jumping to a boot area to run a boot loader;
s13: copying firmware data from an external flash through a BootLoader of a bootstrap program, and writing the firmware data into an internal flash;
s14: and after the writing is finished, verifying the firmware data in the internal flash, if the verification is successful, jumping to the operation area to operate the app, and if the verification is failed, restoring the original firmware from the backup area of the external flash.
The software upgrading method of the recovery mode specifically comprises the following steps:
s11: copying firmware data from a backup area of an external flash to an internal flash directly;
s12: and after the copying is finished, checking the firmware data in the internal flash, and if the checking is successful, jumping to the running area to run the app.
The backup mode includes an automatic backup mode and a manual backup mode.
The software upgrading method in the automatic backup mode specifically comprises the following steps:
s51: checking whether the data in the parameter area in the internal flash is correct or not, and if the data in the parameter area in the internal flash is incorrect, backing up the app data in the current running area to a backup area of the external flash;
s52: and checking the firmware data in the external flash, if the checking is successful, storing the checked parameter data into a parameter area in the internal flash, and jumping to a running area to run the app.
The software upgrading method in the manual backup mode specifically comprises the following steps:
s51: sending a backup instruction to the app to enable the app to jump to a boot area to run a boot program BootLoader;
s52: copying the firmware data of the running area to an external flash;
s53: and after the copying is finished, checking the firmware data of the internal flash, and after the checking is successful, jumping to the running area to run the app.
The communication interface is any one of the following interfaces: UART communication interface, 485 communication interface, CAN communication interface.
The working principle of the invention is as follows:
continuing to refer to fig. 2-3, to illustrate this upgrade, the following concepts are introduced:
flash: one type of memory chip, which can modify the data in it by a specific program, is called flash memory for short;
firmware: the program is written into an EEPROM (electrically erasable programmable read-only memory, and a memory chip with data not lost after power failure), the firmware of the embedded MCU is a program for operating the whole system, and the memory format is generally hex and bin;
internal flash: in particular to an MCU internal flash which is divided into a boot area (storing a boot loader), an operation area (storing an application program app), and a parameter area (storing a mark of an upgrading process, firmware length, firmware verification and the like);
external flash: and the MCU external memory is divided into an upgrading area and a backup area.
In this embodiment, the upgrade flag is used to record external firmware data, so as to write the upgrade mode of the internal flash of the MCU into the memory, and four kinds of upgrade flags and multiple kinds of completion flags are set as shown in the following table.
Figure BDA0003968198090000061
TABLE 1 upgrade identification Table
And (3) communication mode: the app receives the upgrading instruction, records an upgrading identifier, and jumps to a boot area to run a BootLoader; then, the firmware data is directly written into the internal flash through a communication interface (a UART communication interface, a 485 communication interface, a CAN communication interface and the like); and finishing the firmware downloading, checking the firmware data of the operation area, if the check is passed, saving the finishing identifier, then jumping to the operation area to run the app, and if the check is failed, restoring the original firmware from the backup area of the external flash.
Copy mode: the app receives the upgrading instruction, enters an upgrading state, and directly writes the firmware data into the external flash through communication interfaces (a UART communication interface, a 485 communication interface, a CAN communication interface and the like); after the firmware is downloaded, checking the firmware data of the external flash, if the firmware data passes the checking, storing an upgrading identifier, and then jumping to a boot area to run a BootLoader; copying firmware data from an external flash to write into an internal flash by the BootLoader according to the upgrading identifier; and after the writing is finished, checking the firmware data of the internal flash, if the checking is passed, storing a finishing identifier, jumping to the operation area to run the app, and if the checking is failed, restoring the original firmware from the backup area.
And (3) recovery mode: after upgrading fails in other modes, copying firmware from a backup area of the external flash to the internal flash according to an upgrading failure completion identifier; and after the copying is finished, checking the firmware data of the internal flash, if the checking is passed, storing a finishing identifier, and jumping to a running area to run the app.
A backup mode: the method is divided into automatic backup and manual backup.
Automatic backup mode: and electrifying for the first time to check whether the backup check of the parameter area of the internal flash is correct, if not, backing up the app data of the current operation area to the backup area of the external flash, checking the firmware data of the external flash, if the check is passed, storing the completion identifier, then storing the completion identifier, the firmware length and the firmware check to the parameter area of the internal flash, and jumping to the operation area to operate the app.
Manual backup mode: the app receives the backup instruction, records the upgrade identifier, and jumps to a boot area to run a BootLoader; copying the firmware data of the running area to an external flash, verifying the firmware data of the internal flash after copying is completed, if verification is passed, storing a completion identifier, and jumping to the running area to run the app.
The upgrading method is stable and reliable, in the upgrading process, due to outage or interruption of other reasons or upgrading errors, files cannot run, the files can be automatically recovered to be the firmware of the previous version, normal running of software is guaranteed, the upgrading mode is in multiple modes, the common mode is a copy mode, the upgrading is directly carried out in the running of application programs, namely the original functions are continued (user experience is good), after data downloading is completed, the boot area is jumped to, and the boot program is run to complete software updating.
The present invention is not limited to the above preferred embodiments, and any modifications, equivalent substitutions and improvements made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (8)

1. A reliable method for updating an application program of a single chip microcomputer is characterized by comprising the following steps:
s1: an upgrade identifier 1, an upgrade identifier 2, an upgrade identifier 3 and a lifting identifier 4 are preset, wherein the upgrade identifier 1 indicates that software upgrade is performed in a communication mode, the lifting identifier 2 indicates that software upgrade is performed in a copy mode, the upgrade identifier 3 indicates that software upgrade is performed in a recovery mode, and the upgrade identifier 4 indicates that software upgrade is performed in a backup mode;
s2: initializing hardware, checking whether an upgrading identifier exists or not, and if the upgrading identifier exists and is one of the upgrading identifiers S1, upgrading the software according to an upgrading mode corresponding to the upgrading identifier;
s3: s2, if the upgrading identification is not checked, verifying whether the app is normal or not, if the app is abnormal, directly adopting a recovery mode to upgrade the software, and if the app is normal, verifying whether the program of the backup area is normal or not;
s4: and if the program verification of the backup area is abnormal, copying the normal program from the running area to the backup area to complete the program backup.
2. The method for reliably updating the application program of the single chip microcomputer according to claim 1, wherein the method for upgrading the software in the communication mode specifically comprises the following steps:
s11: sending an upgrading instruction to the app so that the app jumps to a boot area to run a boot program BootLoader;
s12: directly writing the firmware data into an operation area of an internal flash through a communication interface;
s13: and after the firmware is downloaded, verifying the firmware data of the operation area, if the verification is successful, jumping to the operation area to operate the app, and if the verification is failed, restoring the original firmware from the backup area of the external flash.
3. The method for reliably updating the application program of the single chip microcomputer according to claim 1, wherein the software upgrading method in the copy mode specifically comprises the following steps:
s11: sending an upgrading instruction to the app, and directly writing the firmware data into an external flash through a communication interface;
s12: after the firmware is downloaded, checking firmware data in the external flash, and if the checking is successful, jumping to a boot area to run a boot loader;
s13: copying firmware data from an external flash through a BootLoader of a bootstrap program, and writing the firmware data into an internal flash;
s14: and after the writing is finished, verifying the firmware data in the internal flash, if the verification is successful, jumping to the operation area to operate the app, and if the verification is failed, restoring the original firmware from the backup area of the external flash.
4. The method for reliably updating the application program of the single chip microcomputer according to claim 1, wherein the software upgrading method in the recovery mode specifically comprises the following steps:
s11: copying firmware data from a backup area of an external flash to an internal flash directly;
s12: and after the copying is finished, checking the firmware data in the internal flash, and if the checking is successful, jumping to the running area to run the app.
5. The method for reliable single-chip application updating of claim 1 wherein the backup modes include an automatic backup mode and a manual backup mode.
6. The method for reliably updating the application program of the single chip microcomputer according to claim 5, wherein the software upgrading method in the automatic backup mode specifically comprises the following steps:
s51: checking whether the data in the parameter area in the internal flash is correct or not, and if not, backing up the app data of the current running area to a backup area of the external flash;
s52: and checking the firmware data in the external flash, if the checking is successful, storing the checked parameter data into a parameter area in the internal flash, and jumping to a running area to run the app.
7. The method for reliably updating the application program of the single chip microcomputer according to claim 5, wherein the software upgrading method in the manual backup mode specifically comprises the following steps:
s51: sending a backup instruction to the app to enable the app to jump to a boot area to run a boot program BootLoader;
s52: copying the firmware data of the running area to an external flash;
s53: and after the copying is finished, checking the firmware data of the internal flash, and after the checking is successful, jumping to the running area to run the app.
8. The method for reliably updating the application program of the single chip microcomputer according to any one of claims 2 or 3, wherein the communication interface is any one of the following interfaces: UART communication interface, 485 communication interface, CAN communication interface.
CN202211506169.5A 2022-11-28 2022-11-28 Reliable method for updating application program of single chip microcomputer Pending CN115718610A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211506169.5A CN115718610A (en) 2022-11-28 2022-11-28 Reliable method for updating application program of single chip microcomputer

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211506169.5A CN115718610A (en) 2022-11-28 2022-11-28 Reliable method for updating application program of single chip microcomputer

Publications (1)

Publication Number Publication Date
CN115718610A true CN115718610A (en) 2023-02-28

Family

ID=85256838

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211506169.5A Pending CN115718610A (en) 2022-11-28 2022-11-28 Reliable method for updating application program of single chip microcomputer

Country Status (1)

Country Link
CN (1) CN115718610A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117130639A (en) * 2023-10-26 2023-11-28 江苏华鲲振宇智能科技有限责任公司 BMC cluster management single-board MCU firmware upgrading method and system
CN117149242A (en) * 2023-11-01 2023-12-01 深圳市杰美康机电有限公司 Driver batch upgrading method and device

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117130639A (en) * 2023-10-26 2023-11-28 江苏华鲲振宇智能科技有限责任公司 BMC cluster management single-board MCU firmware upgrading method and system
CN117130639B (en) * 2023-10-26 2024-03-08 江苏华鲲振宇智能科技有限责任公司 BMC cluster management single-board MCU firmware upgrading method and system
CN117149242A (en) * 2023-11-01 2023-12-01 深圳市杰美康机电有限公司 Driver batch upgrading method and device
CN117149242B (en) * 2023-11-01 2024-02-23 深圳市杰美康机电有限公司 Driver batch upgrading method and device

Similar Documents

Publication Publication Date Title
CN115718610A (en) Reliable method for updating application program of single chip microcomputer
US8423991B2 (en) Embedded network device and firmware upgrading method
KR100506203B1 (en) Booting and boot code update method and system thereof
TWI384367B (en) System of updating firmware and method thereof
KR101427755B1 (en) Device and method for firmware upgrade using usb
TWI382346B (en) Computer system with dual bios protection mechanism and control method of the same
US20100180108A1 (en) Electronic device and method for secure operating system update in embedded system
WO2020062887A1 (en) Firmware upgrading method and system based on flash micro-controller, and flash micro-controller
CN105808292A (en) Firmware upgrade method of embedded terminal device
JP2000357095A (en) Method and device for downloading software to embedded system
CN101373451B (en) Computer system for protecting double-basic input /output system program and control method thereof
JP3629517B2 (en) A boot device switching method for an information processing apparatus.
CN102945173A (en) User program on-line upgrading system and method
CN111651174A (en) Method and system for remotely upgrading MCU (microprogrammed control Unit) program
CN108345464A (en) A kind of the startup method and Android vehicle device of Android system
WO2015184732A1 (en) Bootstrap storage method, bootstrap fault recovery method and device, and computer storage medium
CN111736882B (en) Remote upgrading method of DSP program
CN108664275A (en) Method, system and the storage medium of backup configuration parameter
JP2005284902A (en) Terminal device, control method and control program thereof, host device, control method and control program thereof, and method, system, and program for remote updating
CN116909611A (en) Electronic device firmware updating method, cleaning device and storage medium
WO2022199622A1 (en) Method for running startup program of electronic device, and electronic device
CN110377303A (en) Method and its equipment based on spare memory area mode upgrade procedure
CN113467797B (en) Program updating method, device and system and computer readable storage medium
CN211427090U (en) Micro control unit device
CN111045709B (en) Firmware upgrading method and firmware upgrading device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination