Method for upgrading program on line and electronic equipment
1. A method for upgrading a program on line is applied to an electronic device with an adapter board and a target board, and the method comprises the following steps:
the adapter board receives a first data packet from a host and sends a second data packet to the target board;
the target board controls the MCU to reset and switch to a guide mode;
the adapter board sends code verification information to the target board, and the target board stores the code verification information;
the adapter board sends code length information to the target board, the target board stores the code length information and sends target board link state information to the host through the adapter board;
the adapter board receives a code upgrading data packet from the host and sends the code upgrading data packet to the target board;
the target board executes write operation on a target storage area according to the code upgrading data packet, the code checking information and the code length information;
and after the upgrade is successful, the target board controls the MCU to reset and switch to a working mode, locks the target storage area, and sends upgrade success information to the host through the adapter board.
2. The method of claim 1, wherein the first data packet comprises a synchronization header, code identification information, the code check information, and the code length information.
3. The method of claim 1, wherein the second data packet is a command packet instructing the MCU of the target board to enter a boot mode.
4. The method of claim 1, wherein the target board performs a write operation to a target storage area according to the code upgrade data packet, the code verification information, and the code length information, and comprises:
the target board reads upgrading data with a preset length from the code upgrading data packet;
the target board merges the upgrade data with the preset length and executes write operation on the target storage area according to the upgrade data obtained by merging;
the target board updates the checksum of the received upgrade code and updates the length of the received upgrade code;
under the condition that the length of the received upgrade code is equal to the length information of the prestored code, the target board updates the checksum of the code written into the target storage area and updates the checksum of the received upgrade code;
and in the case that the checksum of the code written into the target storage area is equal to the pre-saved code verification information, the target board determines that the upgrade is successful.
5. An electronic device, comprising an interposer and a target board;
the adapter board is used for receiving a first data packet from a host and sending a second data packet to the target board;
the target board is used for controlling the MCU to reset and switching to a guide mode;
the adapter plate is also used for sending code verification information to the target plate;
the target board is also used for storing the code verification information;
the adapter plate is also used for sending code length information to the target plate;
the target board is also used for storing the code length information and sending target board link state information to the host through the adapter board;
the adapter board is also used for receiving a code upgrading data packet from the host and sending the code upgrading data packet to the target board;
the target board is further used for executing write operation on a target storage area according to the code upgrading data packet, the code checking information and the code length information; and after the upgrading is successful, the MCU is controlled to reset and switch to a working mode, the target storage area is locked, and upgrading success information is sent to the host through the adapter plate.
6. The electronic device of claim 5, wherein the first data packet includes a synchronization header, code identification information, the code check information, and the code length information.
7. The electronic device of claim 5, wherein the second data packet is a command packet that commands the MCU of the target board to enter a boot mode.
8. The electronic device of claim 5,
the target board is specifically used for reading upgrading data with a preset length from the code upgrading data packet; merging the upgrade data with the preset length, and executing write operation on the target storage area according to the upgrade data obtained by merging; updating the checksum of the received upgrade code, and updating the length of the received upgrade code; under the condition that the length of the received upgrade code is equal to the length information of the prestored code, updating the checksum of the code written into the target storage area, and updating the checksum of the received upgrade code; in the case where the checksum of the code written into the target storage area is equal to the pre-saved code check information, it is determined that the upgrade is successful.
9. An electronic device comprising a processor, a memory and a program stored on the memory and executable on the processor, the program, when executed by the processor, implementing the steps of the method of upgrading a program online as claimed in claims 1-4.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium has stored thereon a program which, when being executed by the processor, carries out the steps of the method of upgrading a program online as claimed in claims 1-4.
Background
Currently, in an online upgrade method for a user program in an existing MCU (Micro Control Unit), online upgrade is generally performed using a specific communication port and a dedicated command. That is, special commands are sent through these communication ports to enter online programming. And then sending a corresponding operation command to judge whether to enter online programming, and after judging that the online programming is entered, performing online upgrade on the Flash according to the communication port and an internal design circuit and according to the format of the read-write data of the Flash. And after the online programming is finished, sending a command for finishing the online programming, and judging whether to quit the online programming or not, thereby finishing the online upgrading process.
However, in the prior art, the user program in the MCU is upgraded online through a specific communication port, a dedicated command, and a corresponding internal design circuit, and this hardware logic control upgrade mode can only be performed through a specific mode defined by a chip, which results in a limitation on developing online upgrade software and a reduction in convenience of online upgrade.
Content of application
The embodiment of the application aims to provide a method for upgrading a program on line and electronic equipment, and the method and the electronic equipment can solve the problem that in the prior art, the development of on-line upgrading software is very limited, so that the on-line upgrading is inconvenient.
In order to solve the technical problem, the present application is implemented as follows:
in a first aspect, a method for upgrading a program online is provided, which is applied to an electronic device having an adapter board and a target board, and the method includes the following steps:
the adapter board receives a first data packet from a host and sends a second data packet to the target board;
the target board controls the MCU to reset and switch to a guide mode;
the adapter board sends code verification information to the target board, and the target board stores the code verification information;
the adapter board sends code length information to the target board, the target board stores the code length information and sends target board link state information to the host through the adapter board;
the adapter board receives a code upgrading data packet from the host and sends the code upgrading data packet to the target board;
the target board executes write operation on a target storage area according to the code upgrading data packet, the code checking information and the code length information;
and after the upgrade is successful, the target board controls the MCU to reset and switch to a working mode, locks the target storage area, and sends upgrade success information to the host through the adapter board.
In a second aspect, an electronic device is provided, comprising an interposer and a target board;
the adapter board is used for receiving a first data packet from a host and sending a second data packet to the target board;
the target board is used for controlling the MCU to reset and switching to a guide mode;
the adapter plate is also used for sending code verification information to the target plate;
the target board is also used for storing the code verification information;
the adapter plate is also used for sending code length information to the target plate;
the target board is also used for storing the code length information and sending target board link state information to the host through the adapter board;
the adapter board is also used for receiving a code upgrading data packet from the host and sending the code upgrading data packet to the target board;
the target board is further used for executing write operation on a target storage area according to the code upgrading data packet, the code checking information and the code length information; and after the upgrading is successful, the MCU is controlled to reset and switch to a working mode, the target storage area is locked, and upgrading success information is sent to the host through the adapter plate.
In a third aspect, an electronic device is provided, which comprises a processor, a memory and a program stored on the memory and being executable on the processor, which program, when executed by the processor, performs the steps of the method according to the first aspect.
In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored, which computer program, when being executed by a processor, realizes the steps of the method according to the first aspect.
In the embodiment of the application, the code upgrading data packet, the code checking information and the code length information are sent to the target board through the adapter board, so that the user program in the MCU on the target board is upgraded on line, and the convenience of on-line upgrading is improved.
Drawings
FIG. 1 is a flowchart of a method for upgrading a program online according to an embodiment of the present disclosure;
FIG. 2 is a flowchart of an implementation manner of an online upgrade program according to an embodiment of the present disclosure;
FIG. 3 is a flowchart of an implementation manner of implementing an online upgrade program on a target board according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some, but not all, embodiments of the present application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The method for upgrading a program online according to the embodiment of the present application is described in detail below with reference to the accompanying drawings through specific embodiments and application scenarios thereof.
As shown in fig. 1, a flowchart of a method for upgrading a program online according to an embodiment of the present application is provided, where the method is applied to an electronic device having an interposer and a target board, and the method includes the following steps:
step 101, the patch panel receives a first data packet from the host and sends a second data packet to the target panel.
And 102, the target board controls the MCU to reset and switch to a guide mode.
And 103, the adapter board sends code verification information to the target board, and the target board stores the code verification information.
And 104, the adapter board sends the code length information to the target board, the target board stores the code length information, and the adapter board sends the link state information of the target board to the host.
And 105, receiving the code upgrading data packet from the host by the adapter board, and sending the code upgrading data packet to the target board.
And 106, the target board executes write operation on the target storage area according to the code upgrading data packet, the code checking information and the code length information.
And step 107, after the upgrade is successful, the target board controls the MCU to reset and switch to a working mode, locks the target storage area, and sends upgrade success information to the host through the adapter board.
According to the method and the device, the code upgrading data packet, the code checking information and the code length information are sent to the target board through the adapter board, so that the user program in the MCU on the target board is upgraded on line, and the convenience of on-line upgrading is improved.
As shown in fig. 2, a flowchart of an implementation manner of an online upgrade program provided in an embodiment of the present application includes the following steps:
step 201, the host opens the serial port and sets the serial port number and the serial port baud rate.
Step 202, the host generates a first data packet and sends the first data packet to the adapter board through the serial port.
The first data packet comprises a synchronous head, code identification information, code check information and code length information. For example, the sync header is 0X 12345678.
Step 203, the patch panel sends a second data packet to the target panel.
The second data packet may be a command packet instructing the MCU of the target board to enter the boot mode.
And step 204, the target board releases the write protection, and controls the MCU to reset and switch to a guide mode.
Step 205, the patch panel sends a third data packet to the target panel, where the third data packet includes the code check information.
Wherein the code check information may be a checksum of the code.
In step 206, the target board saves the code verification information.
Step 207, the patch panel sends a fourth data packet to the target panel, where the fourth data packet includes the code length information.
And step 208, the target board stores the code length information, unlocks and erases the target storage area, and sends the state information to the adapter board.
And step 209, the adapter board sends the link state information of the target board to the host, and the host displays corresponding content according to the link state information of the target board.
And step 210, after the host successfully links the target board, the host sends a code upgrading data packet to the target board through the adapter board.
And step 211, the target board executes write operation on the target storage area according to the code upgrading data packet, and returns upgrading state information to the host through the adapter board.
And step 212, displaying corresponding contents by the host according to the upgrading state information.
According to the method and the device, the code upgrading data packet, the code checking information and the code length information are sent to the target board through the adapter board, so that the user program in the MCU on the target board is upgraded on line, and the convenience of on-line upgrading is improved.
As shown in fig. 3, a flowchart of an implementation manner for implementing an online upgrade program on a target board provided in an embodiment of the present application includes the following steps:
step 301, the target board reads upgrade data with a preset length from the code upgrade data packet.
The upgrade data with the preset length may be 8 bytes of upgrade data.
And step 302, merging the upgrade data with the preset length by the target board, and executing write operation on the target storage area according to the upgrade data obtained by merging.
Specifically, the target board may merge 8 bytes of upgrade data into 64-bit data and write the 64-bit data to the target memory area.
Step 303, the target board updates the checksum of the received upgrade code, and updates the length of the received upgrade code.
Step 304, the target board judges whether the length of the received upgrade code is equal to the length information of the prestored code, if so, step 306 is executed; otherwise, step 305 is performed.
The target board updates the checksum of the code written into the target storage area, step 305.
Step 306, the target board updates the checksum of the received upgrade code.
307, the target board judges whether the checksum of the code written into the target storage area is equal to the pre-stored code check information, if so, the step 308 is executed; otherwise, step 309 is performed.
And 308, the target board controls the MCU to reset and switch to a working mode, locks the target storage area and sends upgrading success information to the host through the adapter board.
Step 309, the target board locks the target storage area and sends the upgrade failure information to the host through the adapter board.
According to the method and the device, the code upgrading data packet, the code checking information and the code length information are sent to the target board through the adapter board, so that the user program in the MCU on the target board is upgraded on line, and the convenience of on-line upgrading is improved.
The scope of embodiments of the present application is not limited to the performance of functions in the order shown or discussed, but may include the performance of functions in a substantially simultaneous manner or in an inverted order depending on the functionality involved, e.g., the methods described may be performed in an order different than that described, and various steps may be added, omitted, or combined. In addition, features described with reference to certain examples may be combined in other examples.
As shown in fig. 4, a schematic structural diagram of an electronic device provided in the embodiment of the present application includes an interposer 410 and a target board 420;
the adapter board 410 is configured to receive a first data packet from a host, and send a second data packet to the target board 420;
the first data packet comprises a synchronous head, code identification information, code check information and code length information. The second data packet is a command packet that commands the MCU of the target board 420 to enter boot mode.
The target board 420 is used for controlling the MCU to reset and switch to a guide mode;
the adapter board 410 is further configured to send code verification information to the target board 420;
the target board 420 is further used for storing the code verification information;
the adapter board 410 is also used for sending code length information to the target board 420;
the target board 420 is further configured to store the code length information, and send target board link state information to the host through the adapter board 410;
the adapter board 410 is further configured to receive a code upgrade data packet from the host, and send the code upgrade data packet to the target board 420;
the target board 420 is further configured to perform a write operation on a target storage area according to the code upgrade data packet, the code verification information, and the code length information; and after the upgrade is successful, controlling the MCU to reset and switch to a working mode, locking the target storage area, and sending upgrade success information to the host through the adapter plate 410.
Specifically, the target board 420 is specifically configured to read upgrade data of a preset length from the code upgrade data packet; merging the upgrade data with the preset length, and executing write operation on the target storage area according to the upgrade data obtained by merging; updating the checksum of the received upgrade code, and updating the length of the received upgrade code; under the condition that the length of the received upgrade code is equal to the length information of the prestored code, updating the checksum of the code written into the target storage area, and updating the checksum of the received upgrade code; in the case where the checksum of the code written into the target storage area is equal to the pre-saved code check information, it is determined that the upgrade is successful.
According to the method and the device, the code upgrading data packet, the code checking information and the code length information are sent to the target board through the adapter board, so that the user program in the MCU on the target board is upgraded on line, and the convenience of on-line upgrading is improved.
The electronic device in the embodiment of the present application may be a terminal, or may be a component or a chip in the terminal. The electronic device may be a mobile electronic device or a non-mobile electronic device. By way of example, the mobile electronic device may be a mobile phone, a tablet computer, a notebook computer, a palm top computer, a vehicle-mounted electronic device, a wearable device, an ultra-mobile personal computer (UMPC), a netbook or a Personal Digital Assistant (PDA), and the like, and the non-mobile electronic device may be a server, a Personal Computer (PC), a Television (TV), a teller machine, a self-service machine, and the like, and the embodiments of the present application are not limited in particular.
The electronic device in the embodiment of the present application may be an apparatus having an operating system. The operating system may be an Android (Android) operating system, an ios operating system, or other possible operating systems, and embodiments of the present application are not limited specifically.
The electronic device provided in the embodiment of the present application can implement each process implemented by the electronic device in the method embodiments of fig. 1 to fig. 3, and is not described here again to avoid repetition.
According to the method and the device, the code upgrading data packet, the code checking information and the code length information are sent to the target board through the adapter board, so that the user program in the MCU on the target board is upgraded on line, and the convenience of on-line upgrading is improved.
Optionally, an embodiment of the present application further provides an electronic device, which includes a processor, a memory, and a program stored in the memory and capable of running on the processor, and when the program is executed by the processor, the program implements each process of the method embodiment of upgrading the program online, and can achieve the same technical effect, and details are not described here to avoid repetition.
The embodiment of the present application further provides a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the computer program implements each process of the method embodiment of the online upgrade program, and can achieve the same technical effect, and in order to avoid repetition, details are not repeated here. The computer-readable storage medium may be a Read-only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present application may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present application.
While the present embodiments have been described with reference to the accompanying drawings, it is to be understood that the invention is not limited to the precise embodiments described above, which are meant to be illustrative and not restrictive, and that various changes may be made therein by those skilled in the art without departing from the spirit and scope of the invention as defined by the appended claims.
- 上一篇:石墨接头机器人自动装卡簧、装栓机
- 下一篇:一种半导体测试程序阈值更新的方法及系统