Program upgrading method of embedded system, embedded system and electronic equipment
By trial-running by slaves after program upgrade and counting the number of resets in an embedded system, the frequent crashes caused by IAP technology are solved, ensuring the reliability of the upgraded data and system stability.
Patent Information
- Application Number
- CN202411048281.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-31
- Publication Date
- 2024-11-26
AI Technical Summary
During the program upgrade process of embedded systems, methods based on IAP technology can easily lead to frequent crashes, and existing CRC verification cannot effectively detect complete but incorrect program data, resulting in crashes.
The target application upgrade data is obtained and stored separately through the host and slave. After verification, the slave will run within the preset time limit and count the reset times. If the reset times are less than the threshold, the host will switch to the data running the upgrade program to avoid crashing .
It effectively prevents frequent crashes of embedded system hosts during program upgrade, ensuring the reliability of upgraded data and system stability.
Smart Images

Figure CN119025304A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of program upgrade, and more specifically to a program upgrade method for an embedded system, an embedded system, and an electronic device. Background Art
[0002] During the application of embedded systems, the firmware (program data) of embedded systems may need to be upgraded to fix vulnerabilities, add new functions or improve performance. Currently, a program upgrade method based on IAP (In Application Programming) is usually used for upgrading. However, when the firmware of an embedded system is upgraded using the program upgrade method based on IAP in the related art, the embedded system may frequently freeze. Summary of the invention
[0003] The present application is proposed to solve at least one of the above problems. According to the first aspect of the present application, a method for program upgrading of an embedded system is provided, the method comprising: the host and the slave of the embedded system respectively obtain the upgrading program data for the target application, and respectively store the upgrading program data as the target upgrading program data; the host and the slave respectively verify the stored target upgrading program data; after the target upgrading program data is verified, the slave runs the target upgrading program data within a preset time length, and counts the number of resets of the slave within the preset time length; if the number of resets is less than a preset threshold, the host switches from running the original program data of the target application to running the target upgrading program data.
[0004] In one embodiment of the present application, the host and the slave of the embedded system respectively obtain upgrade program data for the target application, and respectively store the upgrade program data as target upgrade program data, including: the host and the slave respectively obtain upgrade program data for the target application, and respectively store the upgrade program data as the target upgrade program data in a storage area different from the original program data.
[0005] In one embodiment of the present application, the host and the slave respectively obtain upgrade program data for the target application, and respectively store the upgrade program data as the target upgrade program data in a storage area different from the original program data, including: the first host storage area of the host stores the original program data, and the first slave storage area of the slave stores the original program data; the host obtains the upgrade program data for the target application from an external program storage medium, stores the upgrade program data as the target upgrade program data in the second host storage area of the host, and transmits the target upgrade program data to the slave, and the slave stores the target upgrade program data in the second slave storage area of the slave.
[0006] In one embodiment of the present application, the host and the slave respectively verify the stored target upgrade program data, including: the host verifies the target upgrade program data stored in the second host storage area; the slave verifies the target upgrade program data stored in the second slave storage area.
[0007] In one embodiment of the present application, if the number of reset times is less than a preset threshold, the host switches from running the original program data of the target application to running the target upgrade program data, including: if the number of reset times is less than the preset threshold, the slave sends information to the host indicating that the target upgrade program data is valid; after the host verifies the target upgrade program data stored in the second host storage area and receives the information indicating that the target upgrade program data is valid, it switches from running the original program data to running the target upgrade program data.
[0008] In one embodiment of the present application, the program upgrade method also includes: if the number of resets is not less than the preset threshold, the slave sends information to the host indicating that the target upgrade program data is invalid; after receiving the information indicating that the target upgrade program data is invalid, the host keeps running the original program data unchanged.
[0009] In one embodiment of the present application, while the slave sends information indicating that the target upgrade program data is invalid to the host, it also deletes the target upgrade program data stored in the slave; after receiving the information indicating that the target upgrade program data is invalid, the host keeps running the original program data unchanged and also deletes the target upgrade program data stored in the host.
[0010] In one embodiment of the present application, the program upgrade method also includes: after the host receives information indicating that the target upgrade program data is invalid, the host again obtains the upgrade program data for the target application; uses the again obtained upgrade program data as the target upgrade program data, and continues to execute the above steps until the host switches from running the original program data to running the target upgrade program data.
[0011] According to the second aspect of the present application, an embedded system is also provided, which includes: a storage medium and a processor, wherein the storage medium stores a computer program run by the processor, and when the computer program is run by the processor, the processor builds a host and a slave, and the host and the slave execute any one of the above-mentioned embedded system program upgrade methods.
[0012] According to a third aspect of the present application, an electronic device is also provided, and the electronic device includes: any one of the above-mentioned embedded systems.
[0013] According to the program upgrade method of the embedded system, the embedded system, and the electronic device provided by the embodiments of the present application, after the target upgrade program data is verified, the slave machine first runs the verified target upgrade program data for a preset time and counts the number of slave machine resets. If the number of slave machine resets is less than the preset threshold, it means that the host machine running the target upgrade program data will not cause frequent crashes. Thereafter, the host machine is switched from running the original program data of the target application program to running the target upgrade program data, thereby preventing the embedded system host machine from frequently crashing during the program upgrade process. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0015] Figure 1 A flowchart of a method for upgrading a program in an embedded system according to an embodiment of the present invention;
[0016] Figure 2 A flowchart of a method for upgrading a program in an embedded system according to another embodiment of the present invention;
[0017] Figure 3 A schematic block diagram of the operation of a host of an embedded system shown in an embodiment of the present invention;
[0018] Figure 4A schematic block diagram of the operation of a slave device of an embedded system shown in an embodiment of the present invention;
[0019] Figure 5 A flowchart of a method for upgrading a program in an embedded system according to another embodiment of the present invention;
[0020] Figure 6 A schematic block diagram of an embedded system according to an embodiment of the present invention. DETAILED DESCRIPTION
[0021] In order to make the purpose, technical scheme and advantages of the present invention more obvious, the exemplary embodiments according to the present invention will be described in detail with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments of the present invention, and it should be understood that the present invention is not limited to the exemplary embodiments described herein. Based on the embodiments of the present invention described in the present invention, all other embodiments obtained by those skilled in the art without creative work should fall within the protection scope of the present invention.
[0022] In the following description, a large number of specific details are provided to provide a more thorough understanding of the present invention. However, it is apparent to those skilled in the art that the present invention can be implemented without one or more of these details. In other examples, in order to avoid confusion with the present invention, some technical features well known in the art are not described.
[0023] It should be understood that the present invention can be implemented in different forms and should not be interpreted as limited to the embodiments set forth herein. On the contrary, these embodiments are provided to make the disclosure thorough and complete and to fully convey the scope of the present invention to those skilled in the art.
[0024] The purpose of the terms used herein is only to describe specific embodiments and is not intended to be limiting of the present invention. When used herein, the singular forms "one", "an" and "said / the" are also intended to include plural forms, unless the context clearly indicates otherwise. It should also be understood that the terms "consisting of" and / or "comprising", when used in this specification, confirm the presence of the features, integers, steps, operations, elements and / or parts, but do not exclude the presence or addition of one or more other features, integers, steps, operations, elements, parts and / or groups. When used herein, the term "and / or" includes any and all combinations of the relevant listed items.
[0025] In actual applications, the firmware of embedded systems may need to be upgraded to fix vulnerabilities, add new features or improve performance. Traditional firmware upgrade methods usually require the use of external programmers or other hardware devices, which will increase development and production costs and are not flexible enough. At present, there is also the use of IAP technology to upgrade the firmware at runtime through software, thus providing a more convenient and flexible firmware upgrade method, which is of great help to product iterative optimization, demand customization, stability improvement and other aspects.
[0026] It should be explained that the program upgrade method shown in the embodiment of the present application can be implemented based on IAP technology. IAP is programming in the application. The user's own program burns part of the User FLASH (user flash memory) during operation. It is a programming scheme for erasing the FLASH of an embedded microcontroller. Normally, a piece of FLASH has only one user program, and IAP programming divides the FLASH of the embedded microcontroller into at least two major areas, one called the BootLoader area, and one called the APP user code area. A part of the area can also be reserved as a code backup area. That is, in IAP application programming, the MCU (microprocessing unit) of the embedded system can obtain new code in the embedded system and reprogram itself, that is, use the program to change the program.
[0027] In the related art, the process of the program upgrade method based on IAP technology is roughly as follows: the host receives the upgrade instruction of the target application (target APP) → the host of the MCU is reset or jumps to the BOOT program storage area → the host erases the original program data stored in the FLASH storage area corresponding to the target APP → the host obtains the upgrade program data of the target APP → the host writes the upgrade program data to the FLASH storage area corresponding to the target APP → the host verifies the upgrade program data stored in the FLASH storage area corresponding to the target APP → after the host verifies and passes, it jumps to the upgrade program data stored in the FLASH storage area corresponding to the target APP to run the newly upgraded upgrade program data.
[0028] Defects of related technology: When the host is upgrading the target program, after the host writes the upgraded program data into the FLASH storage area corresponding to the target APP, a CRC (Cyclic Redundancy Check) check will be performed. The CRC check is a data transmission error detection function. It performs polynomial calculations on the data and attaches the obtained results to the back of the data frame. The receiving device also executes a similar algorithm to ensure the correctness and integrity of the data transmission. However, when the program is upgraded, the CRC check cannot 100% guarantee the correctness of the written program data. Secondly, if the written program data itself is wrong, such as a bunch of garbled codes, it can still pass the CRC check, so that the written program data can still be upgraded. However, when the host runs the written program data, it will cause the program loop to jump to the BOOT area for program upgrade, causing the embedded system to freeze.
[0029] The reason why the related technology has the above defects is that the CRC check can only detect whether the program data written into the FLASH is complete. For incomplete program data, the CRC check fails. However, for complete program data, the CRC check will pass. During the program upgrade process, the program data may be complete but not the target upgrade program data ("fake program"), or it may be attacked by the network, and the program data content in the FLASH area is rewritten, which will cause the program to jump to the BOOT area in a loop for program upgrade, but the program upgrade cannot be performed, causing the embedded system to freeze.
[0030] To solve at least part of the problems described above, the present application proposes the following embodiments.
[0031] In order to fully understand the present invention, a detailed structure will be proposed in the following description to illustrate the technical solution proposed by the present invention. The optional embodiments of the present invention are described in detail as follows, but in addition to these detailed descriptions, the present invention may also have other implementations.
[0032] Some embodiments of the present invention are described in detail below in conjunction with the accompanying drawings. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.
[0033] First, an application scenario of the program upgrade method for an embedded system illustrated in the example of the present application is introduced. The program upgrade method is applied in the process of upgrading the application program of the embedded system.
[0034] refer to Figure 1 , an embodiment of the present application provides a program upgrade method for an embedded system, the program upgrade method comprising:
[0035] Step 1: The host and the slave of the embedded system respectively obtain the upgrade program data for the target application program, and respectively store the upgrade program data as target upgrade program data;
[0036] Step 2: The host and the slave respectively verify the stored target upgrade program data;
[0037] Step 3: After the target upgrade program data is verified, the slave runs the target upgrade program data within a preset time, and counts the number of resets of the slave within the preset time;
[0038] Step 4: If the number of reset times is less than a preset threshold, the host switches from running the original program data of the target application to running the target upgraded program data.
[0039] In the above scheme, after the target upgrade program data is verified, the slave first runs the verified target upgrade program data for a preset time and counts the number of resets of the slave. If the number of resets of the slave is less than the preset threshold, it means that the host running the target upgrade program data will not cause frequent crashes. Then the host is switched from running the original program data of the target application to running the target upgrade program data, thereby preventing the host of the embedded system from frequently crashing during the program upgrade process. The above steps are described in detail below with reference to the accompanying drawings.
[0040] First, refer to Figure 1 , Figure 2 , Figure 3 and Figure 4 The host and the slave respectively obtain the upgrade program data for the target application, and store the upgrade program data as the target upgrade program data. It should be explained that the target application refers to the target APP, which is the application that needs to be upgraded. There are multiple applications set in the embedded system. As for how to find out whether each application needs to be upgraded, it can be determined by obtaining the upgrade program running identifier or the default program running identifier of each application. Reference Figure 5 If the application is found to have an upgrade program running identifier, it means that the application has an upgrade requirement. If the application is found to have a default program running identifier, it means that the application has no upgrade requirement. Any relevant method can be used to obtain the upgrade program running identifier or the default program running identifier of each application. Exemplarily, whether each application has an upgrade program running identifier can be obtained by running the BOOT area of the embedded system (i.e., calling the IAP program of the embedded system).
[0041] When the host and the slave respectively obtain the upgrade program data for the target application and store the upgrade program data as the target upgrade program data, multiple methods can be used. Figure 3 and Figure 4 , the host and the slave respectively obtain the upgrade program data for the target application, and store the upgrade program data as the target upgrade program data, which may include: the host and the slave respectively obtain the upgrade program data for the target application, and store the upgrade program data as the target upgrade program data in a storage area different from the original program data. That is, in this embodiment, after the host and the slave respectively obtain the upgrade program for the target application, they also store the obtained upgrade program data as the target upgrade program data in a storage area different from the original program data, so that there is no need to delete the original program data, so that when the program data to be upgraded cannot run normally, the original program data can be jumped to execute the task of the target application. Of course, in some embodiments, the host can also store the target upgrade program in a storage area different from the original program data, and the slave directly uses the target upgrade program data to overwrite the original program data stored therein.
[0042] Exemplarily, when the host and the slave respectively obtain the upgrade program data for the target application, and respectively use the upgrade program data as the target upgrade program data and store them in a storage area different from the original program data, multiple methods can be used. Exemplarily, refer to Figure 3 and Figure 4 , the host and the slave respectively obtain the upgrade program data for the target application, and respectively store the upgrade program data as the target upgrade program data in a storage area different from the original program data, which may include: the first host storage area of the host stores the original program data, and the first slave storage area of the slave stores the original program data, and the implementation method may be: the host stores the original program data in the first host storage area of the host, and the slave stores the original program data in the first slave storage area of the slave. At this time, the host obtains the upgrade program data for the target application from an external program storage medium, stores the upgrade program data as the target upgrade program data in the second host storage area of the host, and transmits the target upgrade program data to the slave, and the slave stores the target upgrade program data in the second slave storage area of the slave. Exemplarily, the external program storage medium may be any storage medium capable of storing target upgrade program data, such as but not limited to a host computer or a cloud platform.
[0043] Specifically, in this embodiment, the embedded system not only starts the host of the embedded system but also starts the slave of the embedded system for the target application, and the host and the slave process the original program data and the target upgrade program data of the target application respectively.
[0044] refer to Figure 3 and Figure 4 , the specific processing method is: the host stores the original program data in the first host storage area of the host, and obtains the upgrade program data for the target application from the external program storage medium, and stores the target upgrade program data in the second host storage area different from the first host storage area. Exemplarily, the first host storage area and the second host storage area can be different FLASH areas allocated to the host in the embedded system. Exemplarily, the APP_A area can be the first host storage area, and the APP_B area can be the second host storage area. The slave stores the original program data in the first slave storage area of the slave, and stores the target upgrade program data received from the host in the second slave storage area different from the first slave storage area. Exemplarily, the first slave storage area and the second slave storage area can be different FLASH areas allocated to the slave in the embedded system. Exemplarily, the APP_A area can be the first slave storage area, and the APP_B area can be the second slave storage area.
[0045] Next, refer to Figure 1 , the host and the slave respectively verify the stored target upgrade program data. The specific verification method can be that the host and the hierarchy respectively verify the stored program to be upgraded. Exemplarily, the host and the slave respectively verify the stored target upgrade program data, which may include: the host verifies the target upgrade program data stored in the second host storage area, and the slave verifies the target upgrade program data stored in the second slave storage area. That is, the host verifies the program to be upgraded just stored in the second host storage area to verify whether the program to be upgraded has been changed during the process of being transferred from the external program storage medium to the host. The slave verifies the program to be upgraded just stored in the second slave storage area to verify whether the program to be upgraded has been changed during the process of being transferred from the host to the slave.
[0046] Exemplarily, the algorithm for verifying the stored target upgrade program data may adopt a verification algorithm such as, but not limited to, CRC verification. Exemplarily, when verifying the target upgrade program data, it may also include: the host performs a CRC verification on the target upgrade program data stored in the second host storage area to verify whether the program to be upgraded is completely transmitted during the process of being transmitted from the external host computer or cloud platform to the host; the slave performs a CRC verification on the target upgrade program data stored in the second slave storage area to verify whether the program to be upgraded is completely transmitted during the process of being transmitted from the host to the slave.
[0047] Next, refer to Figure 1, after the target upgrade program data is verified, the slave of the embedded system runs the target upgrade program data within a preset time length, and counts the number of resets of the slave within the preset time length. That is, in the embodiment of the present application, one of the differences compared to the related art is that this step is added. In the related art, after the host verifies the target upgrade program data, the host directly jumps to call the target upgrade program data to process the target application task, that is, after the target upgrade program data is verified, the host directly confirms that the upgrade of the target application is completed. In the embodiment of the present application, after the host verifies the target upgrade program data, the host does not directly confirm that the upgrade of the target application is completed, but the slave runs the target upgrade program data for a period of time and observes the effect of the trial run to determine whether the upgrade of the target application is completed, so that the host runs the program to be upgraded to prevent the host from freezing due to the direct operation of the host when the trial run effect is not good.
[0048] The specific trial operation mode of the slave to be upgraded is: the slave runs the target upgrade program data within a preset time length, and counts the number of resets of the slave within the preset time length. Exemplarily, the preset time length can be any time length preset in advance, and exemplary, the preset time length can be any time length such as 1 minute, 2 minutes, 3 minutes, etc. In the process of the slave running the target upgrade program data, even if the program to be upgraded has been verified, if the target upgrade program data is not the program data of the target application ("fake program"), or it may be attacked by a network, when the content of the target upgrade program data in the FLASH area is rewritten, the slave can identify it by running the target upgrade program data. Specifically, if the slave runs the target upgrade program data within the preset time length, and the slave resets too many times within the preset time length, it means that the target upgrade program data may not be the program data of the target application ("fake program"), or it may be attacked by a network, and the content of the target upgrade program data in the FLASH area is rewritten, so as to identify that the target upgrade program data is unreliable. Of course, if the slave runs the target upgrade program data within the preset time, and the slave is not reset many times within the preset time, it means that the reliability verification of the target upgrade program data has passed.
[0049] Regarding the way that the slave runs the target upgrade program data within a preset time length and counts the number of resets of the slave within the preset time length, a variety of ways can be used. Exemplarily, after the target upgrade program data is verified, the slave of the embedded system runs the target upgrade program data within the preset time length, and counts the number of resets of the slave within the preset time length, which can include: after the target upgrade program data stored in the second slave storage area is verified, the slave runs the target upgrade program data stored in the second slave storage area within the preset time length, and the watchdog program of the slave counts the number of resets of the slave within the preset time length. That is, a watchdog program is set for whether the slave is reset, and the watchdog program specifically counts the number of resets of the slave within the preset time length.
[0050] For example, the watchdog program can reset the slave once every ts (seconds), and the IAP program can read the number of resets of the slave's RTC (clock chip) within the T time period (preset duration). For example, the preset threshold can be equal to T / t. If the number of resets is not less than the preset threshold, it means that the slave is almost always cyclically jumping between freezing and reset, and the target upgrade program data is unavailable. Of course, it should be noted that the method of counting the number of resets of the slave within the preset duration is not limited to the watchdog program shown above. In addition, other methods can also be used.
[0051] Next, continue to refer to Figure 1 If the number of resets is less than the preset threshold, the host of the embedded system switches from running the original program data of the target application to running the target upgrade program data. That is, within the preset time of the slave trial running the target upgrade program data, if the number of resets of the slave is less than the preset threshold, it means that the number of crashes caused by running the target upgrade program data is small and within an acceptable range. It can be confirmed that the target upgrade program data is reliable, and the host can switch from running the original program data of the target application to running the target upgrade program data to complete the upgrade of the target application.
[0052] Compared with the related art, in the embodiment of the present application, after the target upgrade program data is verified, the slave machine first tests the verified target upgrade program data for a preset time and counts the number of slave machine resets. If the number of slave machine resets is less than the preset threshold, it means that the host machine running the target upgrade program data will not cause frequent crashes. Thereafter, the host machine is switched from running the original program data of the target application to running the target upgrade program data, thereby preventing the host machine of the embedded system from frequently crashing during the program upgrade process.
[0053] There are many ways for the host to know the trial operation effect of the slave. Exemplarily, if the number of resets is less than a preset threshold, the host of the embedded system switches from running the original program data of the target application to running the target upgrade program data, which may include: if the number of resets is less than the preset threshold, the slave sends information indicating that the target upgrade program data is valid to the host; after the host verifies the target upgrade program data stored in the second host storage area and receives the information indicating that the target upgrade program data is valid, it switches from running the original program data to running the target upgrade program data. That is, in this embodiment, the slave actively sends the trial operation effect to the host. Specifically, after the slave runs the target upgrade program data for a preset period of time, if the number of resets of the slave is less than the preset threshold, the slave sends the host information indicating that the target upgrade program data is valid. After receiving the information indicating that the target upgrade program data sent by the slave is valid, the host confirms that the reliability of the target upgrade program data is good, so that after the host verifies the target upgrade program data stored in the second host storage area, when it needs to run the target application, it switches from running the original program data to running the target upgrade program data to complete the upgrade of the target application. Exemplarily, refer to Figure 3 and Figure 4 At this time, the host and extension can also delete the original program data in the corresponding storage area respectively and clear the reset times.
[0054] Of course, it should be noted that, in addition to the above-mentioned method, the host can also know the trial operation effect of the slave by the host inquiry method, that is, the host actively obtains the trial operation effect of the slave from the slave.
[0055] Exemplary, reference Figure 3 and Figure 4 , the program upgrade method may also include: if the number of resets is not less than the preset threshold, the slave sends information indicating that the target upgrade program data is invalid to the host; after the host receives the information indicating that the target upgrade program data is invalid, the original program data remains unchanged. That is, in this embodiment, the processing method for the reset number of the slave within the preset time period is not less than the preset threshold is also described. Specifically, after the slave runs the target upgrade program data for a preset time period, if the reset number of the slave is not less than the preset threshold, that is, the reset number of the slave is equal to or greater than the preset threshold, it means that the reliability of the target upgrade program data is poor, and if the host switches from running the original program data to running the target upgrade program data, frequent crashes will occur. In this embodiment, in this case, the slave sends information indicating that the target upgrade program data is invalid to the host. After receiving the information indicating that the target upgrade program data is invalid, the host keeps running the original program data unchanged, that is, the host does not switch to run the target upgrade program data.
[0056] Exemplary, reference Figure 3 and Figure 4 , while the slave sends the information indicating that the target upgrade program data is invalid to the host, it also deletes the target upgrade program data stored in the slave, and by deleting the invalid program stored in the slave storage area, it prepares storage space for the subsequent storage of other target upgrade program data. After receiving the information indicating that the target upgrade program data is invalid, the host keeps running the original program data unchanged, and also deletes the target upgrade program data stored in the host, and by deleting the invalid program stored in the host storage area, it prepares storage space for the subsequent storage of other target upgrade program data.
[0057] Exemplary, reference Figure 3 and Figure 4 The program upgrade method may also include: if the number of resets is not less than a preset threshold, the slave deletes the target upgrade program data stored in the second slave storage area, and sends information indicating that the target upgrade program data is invalid to the host; after receiving the information indicating that the target upgrade program data is invalid, the host keeps running the original program data stored in the first host storage area unchanged, and deletes the target upgrade program data stored in the second host storage area.
[0058] That is, in this embodiment, the processing method of the reset number of the slave within the preset time length is not less than the preset threshold value is also described. Specifically, after the slave runs the target upgrade program data for a preset time length, if the reset number of the slave is not less than the preset threshold value, that is, the reset number of the slave is equal to or greater than the preset threshold value, it means that the reliability of the target upgrade program data is poor. If the host switches from running the original program data to running the target upgrade program data, frequent crashes will occur. In this embodiment, in this case, the slave will delete the target upgrade program data stored in the second slave storage area, thereby deleting the invalid program stored in the slave storage area, so as to prepare storage space for subsequent storage of other target upgrade program data. And the slave also sends information indicating that the target upgrade program data is invalid to the host. After receiving the information indicating that the target upgrade program data is invalid, the host keeps running the original program data stored in the first host storage area unchanged, that is, the host does not switch to run the target upgrade program data, and the host also deletes the target upgrade program data stored in the second host storage area, thereby deleting the invalid program stored in the host storage area, so as to prepare storage space for subsequent storage of other target upgrade program data.
[0059] Exemplarily, the program upgrade method may also include: after receiving the information indicating that the target upgrade program data is invalid, the host again obtains the upgrade program data for the target application; and uses the upgraded program data obtained again as the target upgrade program data, and continues to perform the above steps until the host switches from running the original program data to running the target upgrade program data. That is, in this embodiment, after the host receives the information indicating that the target upgrade program data is invalid sent by the slave, the host will again obtain the upgrade program data for the target application, and the specific acquisition method can be through interaction with an external program storage medium to obtain the upgrade program data for the target application again. And the host also uses the upgraded program data obtained again as the target upgrade program data, and continues to perform the above steps until the host switches from running the original program data to running the target upgrade program data to complete the upgrade of the target application.
[0060] Exemplarily, the embedded system can be applied to electronic devices such as but not limited to energy storage devices, and the energy storage devices can be such as but not limited to household energy storage devices. Exemplarily, the embedded system can be an embedded single-chip microcomputer. Exemplarily, when a bug is found in the application of the embedded system, engineers need to modify and upgrade the application data of the single-chip microcomputer. The upgrade strategy shown in the embodiment of the present application is applied to the online upgrade of the program. The online upgrade of the program can quickly repair the program bugs in the product, avoid the risks brought by the product recall that lasts for several months, and provide a safe and effective upgrade method.
[0061] Exemplarily, a program upgrade verification process shown in the embodiment of the present application is as follows: Figure 2 As shown, in the process of program upgrade, it is first necessary to determine whether the CRC check of the written target upgrade program data passes. If the check fails, it directly jumps to the Boot Loader area to call the IAP program to perform operations such as but not limited to deleting the target upgrade program data just written, clearing the reset times, etc. If the check passes, the slave runs the target upgrade program data for a preset time, and counts the number of resets of the slave within the preset time. After that, the size relationship between the number of resets and the preset threshold is determined. If the number of resets is less than the preset threshold, the program upgrade is realized. If the number of resets is not less than the preset threshold, since the external watchdog of the slave's APP program is reset many times in a short period of time, it is considered that the target upgrade program data is unavailable, the reset times are cleared, the program upgrade fails, the slave jumps to the Boot Loader area, and the host does not call the target upgrade program data. This upgrade strategy effectively avoids the phenomenon of host crash in energy storage devices.
[0062] Exemplary, reference Figure 3 and Figure 4, the embedded system can be a household energy storage device, and the program upgrade method shown in the embodiment of the present application is used for the maintenance and upgrade of the target application of the embedded system. Exemplarily, the host and the slave partition their respective FLASH areas into BootLoader area, APP_A area, APP_B area and Param area for storing the statistical reset times. Exemplarily, the BootLoader area is used to call the IAP program for use, and is used to perform the above-mentioned injection but not limited to writing target upgrade program data, deleting target upgrade program data, deleting original program data, reset number writing and clearing operations. Among them, the APP_A area of the host is the first host storage area, and the APP_B area of the host is the second host storage area. The APP_A area of the slave is the first slave storage area, and the APP_B area of the host is the second slave storage area.
[0063] When the embedded system is powered on, refer to Figure 5 When the MCU of the embedded system is powered on, the IAP program in the BootLoader area is first executed. The APP program is executed after the IAP program in the BootLoader area jumps. When the target upgrade program data of the target application is upgraded or no upgrade request is received within a certain period of time, it is necessary to jump from the BootLoader area to the APP area to execute the user program function. When the jump is successful, the application needs to clear the statistical reset times. However, before executing the APP program, it is necessary to first verify whether the APP program is valid before jumping.
[0064] Exemplary, reference Figure 5 If a device failure caused by a program problem occurs during the actual use of the embedded system, it is necessary to perform an online program upgrade on the program in the embedded system. The entire online program upgrade process is as follows: first, check whether there is an upgrade or default program running mark. If there is no upgrade or default program running mark, run the IAP program in the BootLoader area and obtain the default running program mark, then determine whether there is a default running program mark. If so, take out the default running mark and reset the IAP program in the BootLoader area; if the IAP program in the BootLoader area is not running, wait for the program upgrade. If there is an upgrade program mark, determine whether the CRC check passes, and check whether the number of resets is less than the preset threshold. When the CRC check passes and the number of resets is less than the preset threshold, the host switches from running the original program data to running the target upgrade program data to complete the program upgrade of the target program. When the CRC check fails, run the IAP program in the BootLoader area and wait for the program upgrade.
[0065] In the various embodiments shown above, after the target upgrade program data is verified, the slave machine first test-runs the verified target upgrade program data for a preset time and counts the number of slave machine resets. If the number of slave machine resets is less than a preset threshold, it means that the host machine running the target upgrade program data will not cause frequent crashes. Thereafter, the host machine is switched from running the original program data of the target application to running the target upgrade program data, thereby preventing the host machine from frequently crashing during the program upgrade process.
[0066] In some of the above embodiments, for the relevant program upgrade process based on IAP technology, after the CRC check is passed, the embodiment of the present application sets a reset counting program to count the number of resets of the slave within the preset time length of the target upgrade program data. In order to prevent the CRC check from passing "a false program" (the program is complete but not the target upgrade program), causing the program to continuously jump in a loop, but the program upgrade cannot be successfully implemented, causing the host of the embedded system to freeze. When the number of resets is zero or less than the preset threshold, the program upgrade is implemented, and the host switches from running the original program data to running the target upgrade program data to complete the program upgrade; when the number of resets is not less than the preset threshold, it is judged that the program upgrade fails, and there may be a problem with the CRC check, and the count value is cleared, and the slave jumps to the Boot Loader area, and the host still runs the original original program data unchanged, avoiding the frequent freeze of the host. By adding a reset counting program after the CRC check, the error detection capability of the program can be improved, and it can be realized that when the number of resets of the slave is too many, the host does not jump to the target upgrade program data, avoiding the occurrence of the host freeze, and improving the safety of the operation of upgrading the embedded system.
[0067] The differences from related technologies are as follows:
[0068] (1) In some embodiments of the present application, a reset count program is set to determine the program upgrade status after the CRC check is passed, so as to prevent program upgrade failure caused by CRC check errors, problems with the program to be upgraded itself, failure of the host computer to send the complete program content, rewriting of the FLASH area content, etc.
[0069] (2) After the program upgrade fails, the host does not run the target upgrade program data. At this time, the host can replace the normal program data to continue upgrading the program in the target APP area, avoiding the program from falling into a jump loop and causing the host to "freeze", thereby improving the safety of program upgrades.
[0070] Furthermore, the present application embodiment also provides an embedded system, referring to Figure 6The embedded system includes: a storage medium and a processor, the storage medium stores a computer program run by the processor, when the computer program is run by the processor, the processor builds a host and a slave, and the host and the slave execute any one of the above-mentioned embedded system program upgrade methods.
[0071] Figure 6 FIG. 1 shows a schematic block diagram of an embedded system 100 according to an embodiment of the present application. Figure 6 As shown, the embedded system 100 according to the embodiment of the present application may include a storage medium 110 and a processor 120, the storage medium 110 stores a computer program run by the processor 120, and when the computer program is run by the processor 120, the processor 120 builds a host and a slave, and the host and the slave execute the program upgrade method of the embedded system according to the embodiment of the present application in the foregoing text. Those skilled in the art can understand the specific operation of the embedded system 100 deployment device according to the embodiment of the present application in combination with the content of the foregoing text, and for the sake of brevity, it will not be repeated here.
[0072] The storage medium 110 may include, for example, a memory card of a smart phone, a storage component of a tablet computer, a hard disk of a personal computer, a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a portable compact disk read-only memory (CD-ROM), a USB memory, or any combination of the above storage media. The computer-readable storage medium may be any combination of one or more computer-readable storage media.
[0073] In addition, the present application also provides an electronic device, referring to Figure 1 to Figure 6 , the electronic device includes: any one of the above-mentioned embedded systems. Exemplarily, the electronic device may be, for example, but not limited to, an energy storage device, a terminal device, etc. The energy storage device may be, for example, but not limited to, a household energy storage device, a power station energy storage device, a power battery pack for an electric vehicle, etc. The terminal device may be, for example, but not limited to, a smart wearable device, a smart home device, etc. That is, any device that can use an embedded system belongs to the electronic device of the embodiment of the present application.
[0074] The present invention has been described by the above embodiments, but it should be understood that the above embodiments are only for the purpose of example and description, and are not intended to limit the present invention to the scope of the described embodiments. In addition, it can be understood by those skilled in the art that the present invention is not limited to the above embodiments, and more variations and modifications can be made according to the teachings of the present invention, and these variations and modifications all fall within the scope of the protection claimed by the present invention. The protection scope of the present invention is defined by the attached claims and their equivalents.
Claims
1. A program upgrade method for an embedded system, characterized in that: include: The host and the slave of the embedded system respectively obtain the upgrade program data for the target application program, and respectively store the upgrade program data as target upgrade program data; The host and the slave respectively verify the stored target upgrade program data; After the target upgrade program data is verified, the slave runs the target upgrade program data within a preset time period, and counts the number of resets of the slave within the preset time period; If the number of reset times is less than a preset threshold, the host switches from running the original program data of the target application to running the target upgraded program data.
2. The program upgrade method according to claim 1, characterized in that: The host and the slave of the embedded system respectively obtain the upgrade program data for the target application program, and respectively store the upgrade program data as target upgrade program data, including: The host and the slave respectively obtain the upgrade program data for the target application, and respectively use the upgrade program data as the target upgrade program data and store them in a storage area different from the original program data.
3. The program upgrade method according to claim 2, characterized in that: The host and the slave respectively obtain the upgrade program data for the target application, and respectively use the upgrade program data as the target upgrade program data and store them in a storage area different from the original program data, including: The first host storage area of the host stores the original program data, and the first slave storage area of the slave stores the original program data; The host obtains the upgrade program data for the target application from an external program storage medium, stores the upgrade program data as the target upgrade program data in the second host storage area of the host, and transmits the target upgrade program data to the slave, which stores the target upgrade program data in the second slave storage area of the slave.
4. The program upgrade method according to claim 3, characterized in that: The host and the slave respectively verify the stored target upgrade program data, including: The host verifies the target upgrade program data stored in the second host storage area; The slave machine verifies the target upgrade program data stored in the storage area of the second slave machine.
5. The program upgrade method according to claim 4, characterized in that: If the number of resets is less than a preset threshold, the host switches from running the original program data of the target application to running the target upgraded program data, including: If the number of resets is less than the preset threshold, the slave sends information indicating that the target upgrade program data is valid to the host; After the host verifies the target upgrade program data stored in the second host storage area and receives information indicating that the target upgrade program data is valid, the host switches from running the original program data to running the target upgrade program data.
6. The program upgrade method according to claim 1, characterized in that: Also includes: If the number of resets is not less than the preset threshold, the slave sends information indicating that the target upgrade program data is invalid to the host; After receiving the information indicating that the target upgraded program data is invalid, the host keeps running the original program data unchanged.
7. The program upgrade method according to claim 6, characterized in that: The slave machine, while sending information indicating that the target upgrade program data is invalid to the host machine, also deletes the target upgrade program data stored in the slave machine; After receiving the information indicating that the target upgrade program data is invalid, the host keeps running the original program data unchanged and deletes the target upgrade program data stored in the host.
8. The program upgrade method according to claim 6, characterized in that: Also includes: After receiving the information indicating that the target upgrade program data is invalid, the host again obtains the upgrade program data for the target application; The upgraded program data acquired again is used as the target upgraded program data, and the above steps are continuously performed until the host switches from running the original program data to running the target upgraded program data.
9. An embedded system, characterized in that: include: A storage medium and a processor, wherein the storage medium stores a computer program executed by the processor, and when the computer program is executed by the processor, the processor builds a host and a slave, and the host and the slave execute the program upgrade method of the embedded system as described in any one of claims 1 to 8.
10. An electronic device, characterized in that: include: The embedded system as claimed in claim 9.
