Program updating method and device, electronic equipment and computer storage medium
By setting the main area and backup area in the controller, copying the original program to the backup area, and resetting to the main area during the update process to run the updated program, the device is unavailable due to communication interruption during the program update process in the prior art. Issues, improving the security and reliability of the update.
Patent Information
- Application Number
- CN202411270369.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-11
- Publication Date
- 2025-02-11
AI Technical Summary
In the process of updating controller programs, there are risks such as communication interruptions, resulting in the loss of the original program, the equipment cannot be put into operation quickly, and the update process takes a long time and has a high failure rate.
By detecting the program update instructions, obtain the update type and update program, determine the main area and backup area, copy the original program to the backup area, and reset to the main area to run the update program after writing the update program to the main area.
It realizes that even if communication interruption or update failure occurs during program update, the original program can be promptly returned to ensure that the device always has normal program operation and ensure the normal operation of the device.
Smart Images

Figure CN119415111A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a program updating method, device, electronic device and computer storage medium. Background Art
[0002] In order to fix problems reported by customers or improve performance, the demand for controller program updates is gradually increasing. In addition, the integration of controllers is getting higher and higher, the program files are getting larger and larger, the upgrade process is taking longer, resulting in a higher failure rate, which requires the update program to be safer and more reliable.
[0003] In the process of program update, the related technology generally erases the original program first and then writes the new program. However, if communication is interrupted at this time, the original program will be lost, which will cause the equipment to be unable to be put into operation quickly.
[0004] With respect to the above-mentioned problems existing in the related technologies, no effective solutions have been found so far. Summary of the invention
[0005] The present application provides a program updating method, device, electronic device and computer storage medium to solve the above-mentioned technical problems existing in the related technologies.
[0006] According to one embodiment of the present application, a program update method is provided, comprising: detecting whether a program update instruction is received; in response to the detected program update instruction, obtaining an update type and an updated version of the program corresponding to the program update instruction; determining a main area corresponding to the update type, and copying the original program of the main area to a corresponding backup area, wherein the main area is used to store the program to be run, and the backup area is used to store the program in the main area; writing the updated version of the program into the main area, and after successful writing, resetting to the main area to run the updated version of the program.
[0007] According to another embodiment of the present application, a program updating device is provided, including: a first detection module, used to detect whether a program update instruction is received; an acquisition module, used to obtain an update type and an updated version of the program corresponding to the program update instruction in response to the detected program update instruction; a first copy module, used to determine a main area corresponding to the update type, and copy the original program of the main area to a corresponding backup area, wherein the main area is used to store the program to be run, and the backup area is used to store the program in the main area; a first writing module, used to write the updated version of the program into the main area, and after successful writing, reset to the main area to run the updated version of the program.
[0008] Optionally, the program updating device also includes a first erasing module, used to erase data in a first backup area, where the first backup area is used to store a startup program in a first main area, and the first main area is used to store a startup program to be run; a second copying module, used to copy the original startup program in the first main area to the first backup area, and after the copy is successful, jump to the first backup area to execute the original startup program; and a second writing module, used to write the updated startup program to the first main area during the process of executing the original startup program in the first backup area.
[0009] Optionally, the second writing module also includes a first reading unit, which is used to read the running backup area startup program flag during the process of executing the original startup program in the first backup area; an interrupt unit, which is used to set the address of the interrupt vector table to the starting address of the first backup area and enable interruption if the running backup area startup program flag is valid; a second reading unit, which reads the startup program update flag and the startup program flash flag in English; and a writing unit, which is used to erase the data in the first main area and write the updated version of the startup program to the first main area if the startup program update flag and the startup program flash flag are valid.
[0010] Optionally, the program updating device also includes a second erasing module, used to erase data in a second backup area, where the second backup area is used to store applications in a second main area, where the second main area is used to store applications to be run; a third copying module, used to copy the original application in the second main area to the second backup area; and a third writing module, used to write the updated application into the second main area after the copy is successful.
[0011] Optionally, the first writing module also includes a detection unit, which is used to detect whether the communication is interrupted through a timer during the process of writing the updated version of the program into the main area; a fallback unit, which is used to determine that the communication is normal and reset the timer if the controller receives information from the host computer within a preset time; if the controller times out when receiving the information from the host computer, it is determined that the communication is interrupted and the original program in the backup area is written back to the main area.
[0012] Optionally, the first detection module also includes an operation unit, which is used to first execute the original startup program in the first main area after the controller is powered on; a flag unit, which is used to set the corresponding update flag in the parameter area to valid if the first program update instruction is received within a preset time, and execute the subsequent corresponding program update; a jump unit, which is used to jump to execute the original application program in the second main area if the first program update instruction is not received within the preset time; and a reset unit, which is used to set the corresponding update flag in the parameter area to valid if the second program update instruction is received during the execution of the original application program, and reset back to the startup program to execute the subsequent corresponding program update.
[0013] Optionally, the program update device also includes a second detection module for detecting whether a program rollback instruction is received; and a reset module for erasing the data in the main area, copying the original application in the backup area back to the main area, and performing a reset if a program rollback instruction is received.
[0014] According to another embodiment of the present application, a computer storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above-mentioned device embodiments when running.
[0015] According to another embodiment of the present application, there is also provided an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; wherein: the memory is used to store computer programs; the processor is used to execute the steps in the above method by running the program stored in the memory.
[0016] According to yet another embodiment of the present application, a computer program product comprising instructions is also provided, which enables the computer to execute the steps in the above method when the computer program product is executed on the computer.
[0017] Through the embodiments of the present application, it is detected whether a program update instruction is received; in response to the detected program update instruction, the update type and updated program corresponding to the program update instruction are obtained; the main area corresponding to the update type is determined, and the original program of the main area is copied to the corresponding backup area, wherein the main area is used to store the program to be run, and the backup area is used to store the program in the main area; the updated program is written to the main area, and after the writing is successful, the main area is reset to run the updated program, and through multiple partitions, the program of the main area is copied to the backup area to back up the program. During the program update process, even if there is a communication interruption or the program is insufficient after the update is completed, the original program can be rolled back in time to ensure that the controller always has a normal program and the normal operation of the equipment is guaranteed. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0019] Figure 1 is a hardware structure block diagram of a computer according to an embodiment of the present application;
[0020] Figure 2 is a flow chart of a program updating method according to an embodiment of the present application;
[0021] Figure 3This is an example diagram of controller flash partition in an embodiment of the present application;
[0022] Figure 4 It is an example flow chart of a method for self-updating a startup program and updating an application program based on multiple partitions in an embodiment of the present application;
[0023] Figure 5 This is an example diagram of the change of flash storage content when the program is started to update itself in an embodiment of the present application;
[0024] Figure 6 This is an example diagram of the change of flash storage content when updating the application in the embodiment of the present application;
[0025] Figure 7 It is a structural block diagram of a program updating device according to an embodiment of the present application. DETAILED DESCRIPTION
[0026] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only embodiments of a part of the present application, not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work should fall within the scope of protection of the present application. It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other without conflict.
[0027] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0028] Example 1
[0029] The method embodiment provided in the first embodiment of the present application can be executed in a vehicle terminal, a computer, a tablet or a similar computing device. Taking running on a computer as an example, Figure 1 is a hardware structure block diagram of a computer in an embodiment of the present application. Figure 1 As shown, the computer may include one or more ( Figure 1Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data. Optionally, the computer may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above-mentioned computer. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.
[0030] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as a computer program corresponding to a program update method in an embodiment of the present application. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0031] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0032] In this embodiment, a program update method is provided, which can be applied to a vehicle controller. Figure 2 is a flowchart of a program updating method according to an embodiment of the present application, such as Figure 2 As shown, the process includes the following steps:
[0033] Step S10, detecting whether a program update instruction is received;
[0034] Step S20, in response to the detected program update instruction, obtaining an update type and an updated version of the program corresponding to the program update instruction;
[0035] Step S30, determining the main area corresponding to the update type, and copying the original program in the main area to the corresponding backup area, wherein the main area is used to store the program to be run, and the backup area is used to store the program in the main area;
[0036] Step S40, writing the updated version of the program into the main area, and after the writing is successful, resetting to the main area to run the updated version of the program.
[0037] In this embodiment, after the vehicle controller is powered on, the original startup program in the first main area is first run to detect whether the first program update instruction is received within a preset time (such as 2 seconds). If the first program update instruction is received within the preset time, the corresponding update flag in the parameter area is set to valid (specifically, the startup program update flag or the application program update flag) according to the type of the first program update instruction (specifically, the startup program self-update or the application program update), and the subsequent corresponding program update steps are performed. If the first program update instruction is not received within the preset time, jump to execute the original application in the second main area. In the process of executing the original application, detect whether the second program update instruction sent by the host computer is received. If the second program update instruction sent by the host computer is received during the execution of the original application, the corresponding update flag in the parameter area is set to valid according to the type of the second program update instruction (also the startup program update or the application program update), and finally reset back to the startup program to perform the subsequent corresponding program update steps.
[0038] In this embodiment, the non-volatile memory flash of the controller is partitioned into a main area, a backup area and a parameter area, wherein the main area is used to store the program to be run, the backup area is used to store the last program in the main area, and the parameter area is used to store the flag bits in the update process, and the flag bits include a startup program update flag, an application program update flag, an application program valid flag, a backup area startup program flag, a rollback startup program flag and a startup program flashing flag. Specifically, refer to Figure 3 The main area includes a first main area (bootloader area) for storing the startup program to be run, and a second main area (App area) for storing the application program to be run. The backup area includes a first backup area (bootloader backup area) for storing the startup program originally in the first main area, and a second backup area (App backup area) for storing the application program originally in the second main area. The controller reads the update flag in the parameter area in the startup program to determine the update type corresponding to the program update instruction. If the startup program update flag is valid, the update type is the startup program self-update, and the startup program self-update step is executed; if the application program update flag is valid, the update type is the application program update, and the application program update step is executed.
[0039] Determine the main area corresponding to the update type, and copy the original program in the main area to the corresponding backup area, where the main area is used to store the program to be run, and the backup area is used to back up the program in the main area; write the updated version of the program into the main area, and after the writing is successful, reset to the main area to run the updated version of the program.
[0040] This embodiment uses multiple partitions to copy the programs in the main area to the backup area to back up the programs. During the program update process, even if there is a communication interruption or the program is insufficient after the update is completed, the original program can be rolled back in time to ensure that the controller always has a normal program and guarantee the normal operation of the equipment.
[0041] In the related art, since the boot program is written through the burning port before the controller is installed, the boot program cannot be updated by itself, and the need to update the boot program as the technology improves or the security requirements increase is not considered. In this regard, in one implementation of this embodiment, the update type is the boot program self-update, the updated version program is the updated version boot program, and the method further includes:
[0042] A1, erasing data in the first backup area, where the first backup area is used to store the startup program in the first main area, and the first main area is used to store the startup program to be run;
[0043] A2, copying the original startup program in the first main area to the first backup area, and after the copy is successful, jumping to the first backup area to execute the original startup program;
[0044] A3, during the process of executing the original startup program in the first backup area, writing the updated startup program into the first main area.
[0045] Reference Figure 4 and Figure 5 When the boot program is updated, first erase the data in the first backup area, then copy the original boot program (i.e., the current boot program) in the first main area to the first backup area. Before updating the boot program, back up the original boot program currently in use to another storage area to prevent the update from failing or the new version from having problems, so that it can be quickly rolled back to the old version. Then set the backup area boot program run flag and the boot program write flag in the parameter area to be valid, and turn off the interrupt. By setting the run flag and the write flag, the system can identify the current state (that is, the backup area boot program will be run and the main area boot program will be updated). Turning off the interrupt can avoid external events from interfering during the update process, ensuring the smooth progress of the update process. Finally, jump to the first backup area to run the original boot program. After confirming that the backup area is ready, the system switches to the backup area to execute the boot program. In this way, even if the update of the main area fails, the system can continue to run, ensuring the availability and stability of the system.
[0046] In the startup program running the first backup area, first read the running backup area startup program flag in the parameter area. If the running backup area startup program flag is valid, set the address of the interrupt vector table to the starting address of the first backup area, and then enable the interrupt. After enabling the interrupt, the system can respond to external events, thereby improving the system's responsiveness and real-time performance.
[0047] Then read the boot program update flag and boot program flash flag in the parameter area. If the flag is valid, erase the data in the first main area first, and then write the updated boot program to the first main area. After successful writing, set the boot program flash flag, boot program update flag and running backup area boot program flag to invalid, and finally perform a system reset.
[0048] Through this implementation, the startup program has a self-update function. When updating, it first copies its own data to the startup program backup area, then jumps to the startup program backup area to execute the startup program, and then writes the new startup program to the startup program area, thereby realizing the self-update of the startup program and facilitating the maintenance and technical upgrade of the startup program.
[0049] In another implementation of this embodiment, the update type is an application update, the updated program is an updated application, and the method further includes:
[0050] B1, erasing data in the second backup area, where the second backup area is used to store applications in the second main area, where the second main area is used to store applications to be run;
[0051] B2, copying the original application in the second primary area to the second backup area;
[0052] B3, after the copy is successful, write the updated version of the application to the second main area.
[0053] Reference Figure 4 and Figure 6 When updating the application, first erase the data in the second backup area, then copy the original application (i.e., the current application) in the second main area to the second backup area. Before updating the application, back up the original application currently in use to another storage area to prevent the update from failing or the new version from having problems so that it can be quickly rolled back to the old version. After the copy is successful, write the updated application to the second main area. After the writing is successful, set the application valid flag to valid, set the application update flag to invalid, and finally perform a system reset.
[0054] When updating an application, this embodiment first copies the application to the application backup area, and then writes the new application to the application area, so that if communication is interrupted during the application update, the original program will not be lost, and the normal operation of the device can be maintained.
[0055] In the related art, when updating a program, communication interruption or deficiencies in the updated program cause the controller to fail to operate normally. For example, a laptop is connected to a CAN box via a USB cable, and the CAN box is connected to the interface of the controller or the vehicle via two wires, CAN_H and CAN_L. If the USB cable or CAN cable becomes loose and causes communication interruption, the update process will be interrupted or the transmitted program data will be lost, resulting in program update failure. In this regard, in another implementation of this embodiment, writing the updated version of the program into the main area includes:
[0056] S41, in the process of writing the updated version of the program into the main area, detecting whether the communication is interrupted by a timer;
[0057] S42, if the controller receives information from the host computer within a preset time, it determines that the communication is normal and resets the timer; if the controller times out when receiving information from the host computer, it determines that the communication is interrupted and writes the original program in the backup area back to the main area.
[0058] In the process of writing the updated version of the startup program or the updated version of the application program to the corresponding main area, the controller is equipped with a timer, which detects whether the communication is interrupted. The main function of the timer is to monitor the communication time between the controller and the host computer (such as a server, a personal computer, etc.). By setting a reasonable timeout, the timer can ensure that if the communication does not continue within a certain period of time, it is considered as a communication interruption. When the controller receives information from the host computer within the timed time, it means that the communication is still proceeding normally. At this time, the timer needs to be reset to restart the timing; if the controller times out when receiving the information from the host computer, it is determined that the communication is interrupted, and the original program in the backup area is written back to the main area.
[0059] Through this implementation, when the CAN communication line is poorly contacted during the update process, resulting in communication interruption or the updated program is insufficient, the normal program saved in the backup area can be rolled back, effectively improving the security and reliability of the controller update program.
[0060] In one application scenario, when the updated version of the boot program is written to the first main area, the controller runs the original boot program in the first backup area. If the timer times out, the interrupt processing function is entered to erase the data in the first main area, and then the data in the first backup area is written back to the first main area. After the write is successful, the backup area boot program flag, the boot program update flag and the boot program flash flag are set to invalid, and finally the interrupt is closed and the system is reset.
[0061] In another application scenario, when the updated application is written to the second main area, the controller runs the startup program of the first main area. If the timer times out, it enters the interrupt processing function, first erases the data in the second main area, then writes the data in the second backup area back to the second main area, sets the application update flag to invalid, and finally turns off the interrupt and performs a system reset.
[0062] In another implementation of this embodiment, after resetting to the main area to run the updated version of the program, the method further includes:
[0063] C1, detects whether a rollback program instruction is received;
[0064] C2: If a rollback program instruction is received, the data in the main area is erased, the original application program in the backup area is copied back to the main area, and a reset is performed.
[0065] After the program update is completed, if the updated program is found to have deficiencies during use, the controller can be powered on again. At this time, the controller runs the startup program of the first main area and sends a rollback program instruction through the host computer within a preset time (such as 2 seconds). After receiving the rollback program instruction, the controller performs the following corresponding operations.
[0066] If the rollback program instruction is to roll back the startup program, the parameter area run backup area startup program flag and the rollback startup program flag are set to be valid, and then jump to the first backup area to run the startup program. In the startup program, read that the run backup area startup program flag is valid, set the starting address of the interrupt vector table to the starting address of the startup program backup area, read that the rollback startup program flag is valid, erase the data in the first main area, and then write the data in the second backup area back to the first main area, and then set the run backup area startup program flag and the rollback startup program flag to invalid and reset.
[0067] If the rollback program instruction is to roll back the application program, the data in the second main area is erased, and then the data in the second backup area is written back to the second main area, and reset.
[0068] In this embodiment, if the updated program is insufficient, a rollback request can be sent through the host computer to write the original program back to the startup program main area or the application program main area, so that the controller can resume normal operation.
[0069] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can 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 a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0070] Example 2
[0071] In this embodiment, a program updating device is also provided to implement the above-mentioned embodiments and preferred implementation modes, which have been described and will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware is also possible and conceived.
[0072] Figure 7 is a structural block diagram of a program updating device according to an embodiment of the present application, such as Figure 7 As shown, the device comprises:
[0073] A first detection module 71, used to detect whether a program update instruction is received;
[0074] An acquisition module 72, configured to acquire, in response to a detected program update instruction, an update type and an updated program corresponding to the program update instruction;
[0075] A first copy module 73, used to determine the main area corresponding to the update type, and copy the original program in the main area to the corresponding backup area, wherein the main area is used to store the program to be run, and the backup area is used to store the program in the main area;
[0076] The first writing module 74 is used to write the updated version of the program into the main area, and after the writing is successful, reset to the main area to run the updated version of the program.
[0077] It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
[0078] Example 3
[0079] An embodiment of the present application further provides a computer storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
[0080] Optionally, in this embodiment, the computer storage medium may be configured to store a computer program for performing the following steps:
[0081] S1, detecting whether a program update instruction is received;
[0082] S2, in response to the detected program update instruction, obtaining an update type and an updated version of the program corresponding to the program update instruction;
[0083] S3, determining a main area corresponding to the update type, and copying the original program of the main area to the corresponding backup area, wherein the main area is used to store the program to be run, and the backup area is used to store the program in the main area;
[0084] S4, writing the updated version of the program into the main area, and after the writing is successful, resetting to the main area to run the updated version of the program.
[0085] Optionally, in this embodiment, the above-mentioned computer storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store computer programs.
[0086] An embodiment of the present application further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0087] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0088] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0089] S1, detecting whether a program update instruction is received;
[0090] S2, in response to the detected program update instruction, obtaining an update type and an updated version of the program corresponding to the program update instruction;
[0091] S3, determining a main area corresponding to the update type, and copying the original program of the main area to the corresponding backup area, wherein the main area is used to store the program to be run, and the backup area is used to store the program in the main area;
[0092] S4, writing the updated version of the program into the main area, and after the writing is successful, resetting to the main area to run the updated version of the program.
[0093] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.
[0094] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0095] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0096] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0097] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0098] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0099] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a computer storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned computer storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or CD-ROM and other media that can store program codes.
[0100] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A program updating method, characterized in that: The method comprises: Detect whether a program update instruction is received; In response to the detected program update instruction, obtaining an update type and an updated version of the program corresponding to the program update instruction; Determine a main area corresponding to the update type, and copy the original program in the main area to the corresponding backup area, wherein the main area is used to store the program to be run, and the backup area is used to store the program in the main area; The updated version of the program is written into the main area, and after the writing is successful, the main area is reset to run the updated version of the program.
2. The method according to claim 1, characterized in that The update type is startup program self-update, the updated version program is an updated version startup program, and the method further includes: Erasing data in a first backup area, where the first backup area is used to store a startup program in a first main area, where the first main area is used to store a startup program to be run; Copying the original startup program in the first main area to the first backup area, and after the copying is successful, jumping to the first backup area to execute the original startup program; During the process of executing the original version of the startup program in the first backup area, the updated version of the startup program is written into the first main area.
3. The method according to claim 2, characterized in that Writing the updated version of the boot program into the first main area comprises: During the process of executing the original startup program in the first backup area, reading a flag for running the startup program in the backup area; If the flag for starting the program in the backup area is valid, the address of the interrupt vector table is set to the starting address of the first backup area, and the interrupt is enabled; Read the boot program update flag and the boot program flash flag; If the boot program update flag and the boot program flash write flag are valid, the data in the first main area is erased and the updated boot program is written into the first main area.
4. The method according to claim 1, characterized in that: The update type is an application update, the updated program is an updated application, and the method further includes: Erasing data in a second backup area, where the second backup area is used to store application programs in a second main area, where the second main area is used to store application programs to be run; copying the original application in the second primary area to the second backup area; After the copy is successful, the updated application is written to the second main area.
5. The method according to claim 1, characterized in that: Writing the updated version of the program into the main area includes: In the process of writing the updated version of the program into the main area, detecting whether the communication is interrupted by a timer; If the controller receives information from the host computer within a preset time, it determines that the communication is normal and resets the timer; if the controller times out when receiving information from the host computer, it determines that the communication is interrupted and writes the original program in the backup area back to the main area.
6. The method according to claim 1, characterized in that Detecting whether a program update instruction is received includes: After the controller is powered on, the original startup program in the first main area is executed first; If the first program update instruction is received within the preset time, the corresponding update flag in the parameter area is set to be valid, and the subsequent corresponding program update is performed; If the first program update instruction is not received within the preset time, jump to execute the original application program in the second main area; During the execution of the original application program, if a second program update instruction is received, the corresponding update flag in the parameter area is set to be valid, and the program is reset back to the startup program to execute the subsequent corresponding program update.
7. The method according to claim 1, characterized in that After resetting to the main area to run the updated version of the program, the method further includes: Detect whether a rollback program instruction is received; If a rollback program instruction is received, the data in the main area is erased, the original application program in the backup area is copied back to the main area, and a reset is performed.
8. A program updating device, characterized in that: include: A first detection module, used to detect whether a program update instruction is received; An acquisition module, configured to, in response to a detected program update instruction, acquire an update type and an updated program corresponding to the program update instruction; A first copy module, used to determine a main area corresponding to the update type, and copy the original program in the main area to a corresponding backup area, wherein the main area is used to store programs to be run, and the backup area is used to store programs in the main area; The first writing module is used to write the updated version of the program into the main area, and after the writing is successful, reset to the main area to run the updated version of the program.
9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; wherein: Memory, used to store computer programs; A processor, configured to execute the program updating method according to any one of claims 1 to 7 by running a program stored in a memory.
10. A computer storage medium, characterized in that: The computer storage medium includes a stored program, wherein the program updating method according to any one of claims 1 to 7 is executed when the program is executed.
Citation Information
Cited By
Application program protection method and apparatus, and wearable device
CN120408646A