Software upgrading method and device of embedded system, equipment and storage medium
By extracting target keywords and checksums from the embedded system, generating an integrated file, and verifying the external storage, the problems of file integrity and security during the upgrade process are solved, automatic update function is realized, and system crashes are prevented.
Patent Information
- Application Number
- CN202511579977.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-30
- Publication Date
- 2026-02-13
AI Technical Summary
Embedded systems lack verification code checks during upgrades, making it impossible to confirm file integrity and posing security risks. Furthermore, power outages or interference during the upgrade process may cause the system to crash.
In embedded systems, by extracting the target keywords and checksums of the application, integrating them to generate an integrated file and calculating a second checksum, the integrity of the file is ensured. During the upgrade process, the backup program in the external storage is verified to prevent automatic updates under abnormal circumstances.
Ensure file integrity and security during embedded system upgrades, prevent system crashes, and enable automatic updates, allowing for normal upgrades even in the event of power outages or interference.
Smart Images

Figure CN121523705A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a software upgrade method, apparatus, device, and storage medium for embedded systems. Background Technology
[0002] Application-layer programs in embedded systems are typically stored in memory. Upgrading these programs relies on checksum verification of data packets sent by the upgrade endpoint. However, some remote upgrade endpoints lack checksums for transmitted files, making it impossible to verify file integrity. If errors occur during transmission, such as lost or corrupted data packets, the system will be unable to detect these issues, posing a security risk. Furthermore, embedded system upgrades often involve storing a backup program in region B, which overwrites the code in region A to complete the upgrade. However, during this backup program overwriting process, a power outage or other interference causing internal memory malfunction can lead to system crashes. Summary of the Invention
[0003] Based on this, it is necessary to provide a software upgrade method, apparatus, device, and storage medium for embedded systems to address the above-mentioned technical problems. This would solve the technical issues that some remote upgrade terminals lack verification codes for transmitted files, making it impossible to confirm file integrity and leading to system security risks. Additionally, it would address the issue that system crashes can occur if a power outage or other interference causes an internal memory malfunction during the upgrade backup process.
[0004] This invention provides a software upgrade method for an embedded system, comprising: The embedded system includes internal memory and external memory. The internal memory is configured with a boot sector and a runtime sector. The boot sector is used to store upgrade boot programs, and the runtime sector is used to store application programs. The external memory is used to store upgrade backup programs. The method includes: When the system starts running, extract the target keywords of the application and determine the target checksum of the application; The target keyword is verified, and the target verification code is verified against the first verification code, wherein the first verification code is determined in advance based on the length of the application before the application is started and run; If the target keyword verification fails or the target check code verification fails, the upgrade backup program in the external storage is verified based on the pre-generated target file. The target file is generated based on the first check code, the upgrade boot program and the application program to obtain an integrated file and the second check code corresponding to the integrated file. If the upgrade backup program is successfully verified, the upgrade backup program is retrieved from the external storage and the upgrade is performed.
[0005] Optionally, according to the software upgrade method for an embedded system provided by the present invention, the target file is generated based on the following steps: Write the first verification code to the end of the application to obtain the target file; The upgrade bootloader and the target file are integrated to obtain the integrated file; Calculate the second checksum of the integrated file based on its length; The second verification code is written to the end of the integrated file to form the target file.
[0006] Optionally, according to the software upgrade method for an embedded system provided by the present invention, before writing the first checksum to the end of the application program to obtain the target file, the method further includes: Obtain the code length of the application and determine the keywords of the application; The application's keywords are written to a first fixed address in the runtime area, and the code length is written to a second fixed address in the runtime area.
[0007] Optionally, according to a software upgrade method for an embedded system provided by the present invention, the step of extracting the target keywords of the application and determining the target checksum of the application when the system is started includes: When the system starts running, the target keyword is extracted from the first fixed address, and the code length of the application is extracted from the second fixed address; The target checksum of the application is determined based on the application's code length.
[0008] Optionally, according to the software upgrade method for an embedded system provided by the present invention, the step of verifying the upgrade backup program in the external memory based on a pre-generated target file includes: Determine the code length based on the application, and determine the fixed length occupied by the upgrade bootloader; The target length of the target file is determined based on the code length and the fixed length. Based on the target length of the target file, determine the checksum of the target file; Verify the second verification code and the verification code of the target file.
[0009] Optionally, according to the software upgrade method for an embedded system provided by the present invention, the step of retrieving the upgrade backup program from the external memory for upgrade includes: After destroying the target keyword in the application in the runtime area, the system restarts and then upgrades the application stored in the runtime area by overwriting the upgrade backup program with the upgrade program. If a power outage occurs during the upgrade process, the target keywords of the application will be extracted again. If the target keyword verification is successful, restart the application. If the target keyword verification fails, the upgrade backup program will overwrite the application stored in the running area for upgrade.
[0010] Optionally, according to a software upgrade method for an embedded system provided by the present invention, the step of verifying the target keyword and verifying the target checksum with the first checksum includes: The target keyword and the stored keyword are matched and verified, and the target verification code is verified to be consistent with the first verification code. If the target keyword verification is successful and the target checksum verification is successful, then the application will run.
[0011] The present invention also provides a software upgrade device for an embedded system, the embedded system including an internal memory and an external memory, the internal memory being configured with a boot area, a runtime area, and a parameter area, the boot area being used to store an upgrade boot program, the runtime area being used to store an application program, and the external memory being used to store an upgrade backup program, including: The extraction module is used to extract the target keywords of the application and determine the target checksum of the application when the system starts running. The first verification module is used to verify the target keyword and to verify the target verification code with the first verification code, wherein the first verification code is determined in advance based on the length of the application before the application is started and run. The second verification module is used to verify the upgrade backup program in the external storage based on the pre-generated target file if the target keyword verification fails or the target verification code verification fails. The target file is generated based on the first verification code, the upgrade boot program and the application program to obtain an integrated file and the second verification code corresponding to the integrated file. The upgrade module is used to retrieve the upgrade backup program from the external storage and perform the upgrade if the upgrade backup program verification is successful.
[0012] The present invention also provides a computer device, including a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor, wherein the processor implements the above-described software upgrade method for the embedded system when executing the computer-readable instructions.
[0013] The present invention also provides one or more readable storage media storing computer-readable instructions, which, when executed by one or more processors, cause the one or more processors to perform the software upgrade method for the embedded system described above.
[0014] The aforementioned embedded system software upgrade method, apparatus, device, and storage medium, wherein the embedded system includes internal memory and external memory, the internal memory is configured with a boot area, a runtime area, and a parameter area, the boot area is used to store an upgrade boot program, the runtime area is used to store an application program, and the external memory is used to store an upgrade backup program, the method includes: when the system starts running, extracting the target keyword of the application program and determining the target checksum of the application program; verifying the target keyword and verifying the target checksum against a first checksum, wherein the first checksum is pre-determined based on the length of the application program before starting running; if the target keyword verification fails or the target checksum verification fails, verifying the upgrade backup program in the external memory based on a pre-generated target file, wherein the target file is generated based on an integrated file obtained by integrating the first checksum, the upgrade boot program, and the application program, and a second checksum corresponding to the integrated file; if the upgrade backup program verification is successful, retrieving the upgrade backup program from the external memory for upgrade. This invention writes the upgrade backup program and application program into the chip in one go, and pre-calculates the checksum of the application program and the checksum of the entire target file. Then, when the system starts running, it verifies the target keywords of the application program to prevent application code that is not native to the machine from being burned in. It also verifies the target checksum with the first checksum to ensure that the code is executable and prevents unexpected code crashes. Based on the second checksum of the target file, it verifies the upgrade backup program in the external storage to ensure the integrity of the file and then performs the upgrade operation. Therefore, even if a power outage or other interference causes the program in the internal storage to malfunction, the application program in the internal storage can be automatically updated by the upgrade backup program in the external storage. Attached Figure Description
[0015] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 This is a schematic diagram of the storage area of a memory in an embedded system according to an embodiment of the present invention; Figure 2 This is a flowchart illustrating a software upgrade method for an embedded system according to an embodiment of the present invention; Figure 3 This is a detailed structural diagram of an embedded system memory according to an embodiment of the present invention; Figure 4 This is a schematic diagram of a software upgrade device for an embedded system according to an embodiment of the present invention; Figure 5 This is a schematic diagram of a computer device according to an embodiment of the present invention. Detailed Implementation
[0017] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0018] The terminology used in one or more embodiments of the present invention is for the purpose of describing particular embodiments only and is not intended to limit the scope of the invention. The singular forms “a,” “the,” and “the” used in one or more embodiments of the invention are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” used in one or more embodiments of the invention refers to and includes any or all possible combinations of one or more associated listed items.
[0019] like Figure 1 As shown, Figure 1This is a schematic diagram of the memory area in an embedded system according to an embodiment of the present invention. In this embodiment, the embedded system can refer to a microcontroller, or other types of embedded systems in the prior art. The embedded system includes at least a memory, which can be integrated into the embedded system. Specifically, the memory can be flash memory, programmable read-only memory (PROM), electrically alterable read-only memory (EAROM), erasable programmable read-only memory (EPROM), and electrically erasable programmable read-only memory (EEPROM), etc.
[0020] In this embodiment, the memory in the embedded system is divided into internal memory and external memory. The internal memory is configured with multiple storage areas, such as a boot area, a runtime area, and a parameter area. The boot area is used to store the upgrade boot program, the runtime area is used to store the application program, and the external memory is used to store the upgrade backup program. In specific implementations, the embedded system can achieve specific functions based on each storage area by storing different data in each storage area.
[0021] For example: the boot sector stores the upgrade bootloader, which guides the embedded system to start and instructs it to perform upgrade operations. When the embedded system starts, it first runs the program stored in the boot sector. The runtime sector stores the application program, which instructs the embedded system to implement business functions. After the program stored in the boot sector finishes executing, the system jumps to run the program stored in the runtime sector. The parameter sector stores the program's configuration parameters, and external storage stores the upgrade backup program.
[0022] In one embodiment, specifically, as Figure 2 As shown, Figure 2 This is a flowchart illustrating a software upgrade method for an embedded system according to an embodiment of the present invention. The embodiment of the present invention provides a software upgrade method for an embedded system. The method includes the following steps: Step S11: When the system starts running, extract the target keywords of the application and determine the target checksum of the application. It should be noted that the first fixed address in app.hex (the application) contains a keyword of preset bytes, used to identify the code and prevent incorrect code burning. The second fixed address contains a placeholder of preset bytes, used to indicate the code length of the application.
[0023] Specifically, when the system starts running, the target keywords of the application are extracted based on a first fixed address, and the code length of the application is extracted based on a second fixed address. Then, based on the determined code length, the target checksum of the application is calculated. Step S12: Verify the target keyword and verify the target verification code with the first verification code; It should be noted that the first verification code is determined in advance based on the application's length before the application is launched. Specifically, the target keyword is matched and verified against the stored keywords, and the target verification code is checked to see if it matches the first verification code. If both the target keyword and the target verification code are verified successfully, the application is run.
[0024] Step S13: If the target keyword verification fails or the target check code verification fails, then the upgrade backup program in the external storage is verified based on the pre-generated target file. It should be noted that, referring to Figure 3 , Figure 3 This is a detailed structural diagram of an embedded system memory in one embodiment of the present invention. The target file is an integrated file obtained by integrating the first verification code, the upgrade boot program and the application program, and a second verification code corresponding to the integrated file is generated; the first verification code refers to the verification code of the application program.
[0025] Specifically, if the target keyword verification or the target checksum verification fails, it indicates that the application code has been altered or corrupted during storage or transmission. Then, based on the second fixed address, the application code length is extracted. Further, this code length is added to the fixed length occupied by the upgrade bootloader to calculate the target file length. Then, based on the target file length, the checksum of the target file is determined. Finally, it is determined whether the checksum matches the pre-calculated second checksum in the target file. If they match, it proves that the upgrade backup program in the external storage is normal.
[0026] Step S14: If the upgrade backup program verification is successful, the upgrade backup program is retrieved from the external storage and the upgrade is performed.
[0027] Specifically, if the upgrade backup program is successfully verified, it proves that the upgrade backup program in the external storage is normal. Then, the upgrade backup program is retrieved from the external storage to replace the original application program for upgrade. The specific upgrade process is described in detail in the following embodiments and will not be repeated here.
[0028] This invention writes the upgrade backup program and the application program into the chip at once, and pre-calculates the checksum of the application program and the checksum of the entire target file. Then, when the system starts running, it verifies the target keywords of the application program to prevent application code that is not for this machine from being burned in. It also verifies the target checksum with the first checksum to ensure that the code is executable code and prevents unexpected code crashes. Based on the second checksum of the target file, it verifies the upgrade backup program in the external storage to ensure the integrity of the file and then performs the upgrade operation. Therefore, even if a power outage or other interference causes the program in the internal storage to malfunction, the application program in the internal storage can be automatically updated by the upgrade backup program in the external storage.
[0029] In one embodiment of the present invention, the target file is generated based on the following steps: Write the first checksum to the end of the application to obtain the target file; integrate the upgrade bootloader and the target file to obtain the integrated file; calculate the second checksum of the integrated file based on the length of the integrated file; write the second checksum to the end of the integrated file to form the target file.
[0030] Specifically, please refer to Figure 3 , Figure 3 This is a detailed structural diagram of an embedded system memory in one embodiment of the present invention. The first checksum is written to the end of the application to obtain the target file. For example, the first checksum is placed at the end of app.hex (application) to generate appcrc.hex (target file). Then, srec_cat.exe is used to integrate bootloader.hex (upgrade bootloader) and appcrc.hex (target file) to obtain CompositingBootApp.hex (integrated file). Further, based on the length of the integrated file, srec_cat.exe is used to calculate the second checksum of the entire CompositingBootApp.hex file, and then the second checksum is placed at the end of the CompositingBootApp.hex file to obtain ObjectCode.hex (target file).
[0031] This invention, through pre-determining the verification code of the application and the verification code of the entire file formed by the upgrade bootloader and the application, forms the final target file. This ensures the executability of the code and the integrity of the file based on the verification codes of the application and the entire file.
[0032] In one embodiment of the present invention, before writing the first verification code to the end of the application to obtain the target file, the method further includes: Obtain the code length of the application and determine the keywords of the application; write the keywords of the application to a first fixed address in the runtime area and write the code length to a second fixed address in the runtime area.
[0033] It should be noted that this can be referred to Figure 3 The system pre-sets a keyword for the application at a first fixed address in memory, representing an identification identifier for the application and used to mark the code's uniqueness, preventing incorrect code burning. A placeholder of pre-set bytes is written at a second fixed address in memory to store the application's code length. Specifically, the application's code length is calculated, and the application's keyword is extracted. The keyword is then stored at the first fixed address in the runtime area, and the code length is written at the second fixed address in the runtime area. This allows for rapid keyword extraction during the upgrade process to prevent application code not originating from this machine from being burned, and the application's checksum is calculated based on the code length for verification, ensuring the code is executable and valid.
[0034] In one embodiment of the present invention, the step of extracting the target keywords of the application and determining the target checksum of the application when the system is started includes: When the system starts running, the target keyword is extracted from the first fixed address, and the code length of the application is extracted from the second fixed address; based on the code length of the application, the target checksum of the application is determined.
[0035] Specifically, when the system starts running, the target keyword is extracted based on the first fixed address, and the code length of the application is extracted based on the second fixed address. Then, based on the code length of the application, the target checksum of the application is calculated. Optionally, the algorithm for calculating the target checksum is not specifically limited here. Thus, the application can be verified based on the target keyword and the target checksum.
[0036] In one embodiment of the present invention, the step of verifying the upgrade backup program in the external storage based on the pre-generated target file includes: Determine the code length based on the application and the fixed length occupied by the upgrade bootloader; determine the target length of the target file based on the code length and the fixed length; determine the checksum of the target file based on the target length of the target file; and verify the second checksum and the checksum of the target file.
[0037] It should be noted that when running the app, the ObjectCode.hex file (target file) is obtained through communication via Wi-Fi, serial port, or USB flash drive, and then stored on external storage.
[0038] Specifically, based on the second fixed address, the code length of the application is extracted, and then the fixed length occupied by the upgrade bootloader is determined. The code length and the fixed length occupied by the upgrade bootloader are added together to obtain the target length of the target file. Further, based on the target length, a checksum of the target file is calculated. The checksum is then verified to see if it matches the pre-calculated second checksum in the target file. If they match, it proves that the upgrade backup program in the external storage is normal. This achieves verification of the upgrade backup program in the external storage based on the second checksum of the target file, ensuring the integrity of the transmitted file.
[0039] In one embodiment of the present invention, the step of retrieving the upgrade backup program from the external storage for upgrade includes: After corrupting the target keyword in the application in the running area, the system restarts and upgrades the application stored in the running area by overwriting the upgrade backup program. If a power outage occurs during the upgrade process, the target keyword of the application is retrieved again. If the target keyword verification is successful, the application is restarted. If the target keyword verification fails, the upgrade backup program is overwritten with the application stored in the running area for upgrade.
[0040] Specifically, the upgrade process requires corrupting target keywords in the applications stored in the runtime environment and then restarting to ensure the new applications load and run correctly, while avoiding remnants or conflicts from the old version. The upgrade backup program is then used to overwrite the applications stored in the runtime environment for the upgrade. Furthermore, it should be noted that the machine will upgrade or run normally even if the following abnormal situations occur during the upgrade process: 1. If a power outage occurs during the upgrade process, the target keyword of the application will be extracted again. If the target keyword verification is successful, it proves that the power outage occurred before the keyword in the internal memory was corrupted. The code stops running. Since the target keyword of the application in the internal memory has not been corrupted, the upgrade fails. After restarting, the code will still run normally as before.
[0041] 2. If the target keyword verification fails, and it is proven that the power was cut off after the application's keyword in the internal memory was corrupted, the external memory already has a verified upgrade backup program. When the machine is powered on again, since the target keyword of the application has been corrupted, the internal code will be detected as abnormal, and the upgrade backup program in the external memory will be extracted to overwrite the application stored in the running area for upgrade.
[0042] 3. If a power outage occurs during the upgrade process, the final verification code will not be written yet. Upon the next power-on, the upgrade backup program will be retrieved from the external storage to perform the upgrade because the verification will fail.
[0043] 4. If an unexpected power outage during the upgrade causes an error in the external storage and the second checksum fails to pass verification, the bootloader (upgrade loader) can also replace the application program to receive the external upgrade backup program ObjectCode.hex (target file) and store it in the external storage for repair.
[0044] 5. If the machine is turned on when not upgrading and the target keyword verification or target check code verification fails in the internal storage, the upgrade backup program in the external storage can be used to perform the upgrade.
[0045] In this embodiment of the invention, if an internal memory malfunctions due to unforeseen reasons during the upgrade process, causing the application verification to fail, the application in the internal memory can be automatically updated using an upgrade backup program on the external memory. Furthermore, the upgrade backup program is executed before each run, checking the application's keywords and checksum for validity. Each time the system boots, the code is guaranteed to be executable and valid, preventing unexpected code-related crashes.
[0046] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0047] In one embodiment, a software upgrade apparatus for an embedded system is provided, which corresponds one-to-one with the software upgrade method for the embedded system described in the above embodiments. For example... Figure 4 As shown, Figure 4 This is a schematic diagram of a software upgrade device for an embedded system according to an embodiment of the present invention. The embedded system includes an internal memory and an external memory. The internal memory is configured with a boot area, a runtime area, and a parameter area. The boot area is used to store the upgrade boot program, the runtime area is used to store the application program, and the external memory is used to store the upgrade backup program, including: Extraction module 21 is used to extract the target keywords of the application and determine the target verification code of the application when the system starts running. The first verification module 22 is used to verify the target keyword and to verify the target verification code with the first verification code, wherein the first verification code is determined in advance based on the length of the application before the application is started and run. The second verification module 23 is used to verify the upgrade backup program in the external storage based on the pre-generated target file if the target keyword verification fails or the target verification code verification fails. The target file is generated based on the first verification code, the upgrade boot program and the application program to obtain an integrated file and the second verification code corresponding to the integrated file. The upgrade module 24 is used to extract the upgrade backup program from the external storage and perform the upgrade if the upgrade backup program verification is successful.
[0048] The software upgrade device for the embedded system further includes: Write the first verification code to the end of the application to obtain the target file; The upgrade bootloader and the target file are integrated to obtain the integrated file; Calculate the second checksum of the integrated file based on its length; The second verification code is written to the end of the integrated file to form the target file.
[0049] The software upgrade device for the embedded system further includes: Obtain the code length of the application and determine the keywords of the application; The application's keywords are written to a first fixed address in the runtime area, and the code length is written to a second fixed address in the runtime area.
[0050] The software upgrade device for the embedded system further includes: When the system starts running, the target keyword is extracted from the first fixed address, and the code length of the application is extracted from the second fixed address; The target checksum of the application is determined based on the application's code length.
[0051] The software upgrade device for the embedded system further includes: Determine the code length based on the application, and determine the fixed length occupied by the upgrade bootloader; The target length of the target file is determined based on the code length and the fixed length. Based on the target length of the target file, determine the checksum of the target file; Verify the second verification code and the verification code of the target file.
[0052] The software upgrade device for the embedded system further includes: After destroying the target keyword in the application in the runtime area, the system restarts and then upgrades the application stored in the runtime area by overwriting the upgrade backup program with the upgrade program. If a power outage occurs during the upgrade process, the target keywords of the application will be extracted again. If the target keyword verification is successful, restart the application. If the target keyword verification fails, the upgrade backup program will overwrite the application stored in the running area for upgrade.
[0053] The software upgrade device for the embedded system further includes: The target keyword and the stored keyword are matched and verified, and the target verification code is verified to be consistent with the first verification code. If the target keyword verification is successful and the target checksum verification is successful, then the application will run.
[0054] Specific limitations regarding the software upgrade device for embedded systems can be found in the limitations on the software upgrade method for embedded systems described above, and will not be repeated here. Each module in the aforementioned software upgrade device for embedded systems can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in hardware or independently of the processor in the computer device, or stored in software in the memory of the computer device, so that the processor can call and execute the operations corresponding to each module.
[0055] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 5 As shown, Figure 5This is a schematic diagram of a computer device according to an embodiment of the present invention. The computer device includes a processor, a memory, a network interface, and a database connected via a device bus. The processor of the computer device provides computing and control capabilities. The memory of the computer device includes a readable storage medium and internal memory. The readable storage medium stores operating devices, computer-readable instructions, and a database. The internal memory provides an environment for the operation of the operating devices and computer-readable instructions in the readable storage medium. The database of the computer device stores data involved in a software upgrade method for an embedded system. The network interface of the computer device is used for communication with an external terminal via a network connection. When the computer-readable instructions are executed by the processor, a software upgrade method for an embedded system is implemented. The readable storage medium provided in this embodiment includes a non-volatile readable storage medium and a volatile readable storage medium.
[0056] In one embodiment, a computer device is provided, which may be a terminal device, and its internal structure diagram may be as follows: Figure 5 As shown, the computer device includes a processor, memory, and a network interface connected via a device bus. The processor provides computing and control capabilities. The memory includes a readable storage medium storing computer-readable instructions. The network interface communicates with an external terminal via a network connection. When executed by the processor, the computer-readable instructions implement a software upgrade method for an embedded system. The readable storage medium provided in this embodiment includes both non-volatile and volatile readable storage media.
[0057] In one embodiment, a computer device is provided, including a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor. When the processor executes the computer-readable instructions, it implements the steps of the software upgrade method for the embedded system described above.
[0058] In one embodiment, a readable storage medium is provided, which stores computer-readable instructions. When executed by a processor, these computer-readable instructions implement the software upgrade method steps of the embedded system described above. Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by instructing related hardware using computer-readable instructions. These computer-readable instructions can be stored in a non-volatile readable storage medium or a volatile readable storage medium. When executed, these computer-readable instructions can include the processes of the embodiments of the methods described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0059] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0060] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.
Claims
1. A software upgrade method for an embedded system, characterized in that, The embedded system includes internal memory and external memory. The internal memory is configured with a boot sector and a runtime sector. The boot sector is used to store upgrade boot programs, and the runtime sector is used to store application programs. The external memory is used to store upgrade backup programs. The method includes: When the system starts running, extract the target keywords of the application and determine the target checksum of the application; The target keyword is verified, and the target verification code is verified against the first verification code, wherein the first verification code is determined in advance based on the length of the application before the application is started and run; If the target keyword verification fails or the target check code verification fails, the upgrade backup program in the external storage is verified based on the pre-generated target file. The target file is generated based on the first check code, the upgrade boot program and the application program to obtain an integrated file and the second check code corresponding to the integrated file. If the upgrade backup program is successfully verified, the upgrade backup program is retrieved from the external storage and the upgrade is performed.
2. The software upgrade method for an embedded system according to claim 1, characterized in that, The target file is generated based on the following steps: Write the first verification code to the end of the application to obtain the target file; The upgrade bootloader and the target file are integrated to obtain the integrated file; Calculate the second checksum of the integrated file based on its length; The second verification code is written to the end of the integrated file to form the target file.
3. The software upgrade method for an embedded system according to claim 2, characterized in that, Before writing the first verification code to the end of the application to obtain the target file, the method further includes: Obtain the code length of the application and determine the keywords of the application; The application's keywords are written to a first fixed address in the runtime area, and the code length is written to a second fixed address in the runtime area.
4. The software upgrade method for an embedded system according to claim 3, characterized in that, When the system starts running, extracting the target keywords of the application and determining the target checksum of the application includes: When the system starts running, the target keyword is extracted from the first fixed address, and the code length of the application is extracted from the second fixed address; The target checksum of the application is determined based on the application's code length.
5. The software upgrade method for an embedded system according to claim 1, characterized in that, The verification of the upgrade backup program in the external storage based on the pre-generated target file includes: Determine the code length based on the application, and determine the fixed length occupied by the upgrade bootloader; The target length of the target file is determined based on the code length and the fixed length. Based on the target length of the target file, determine the checksum of the target file; Verify the second verification code and the verification code of the target file.
6. The software upgrade method for an embedded system according to claim 1, characterized in that, The step of retrieving the upgrade backup program from the external storage and performing the upgrade includes: After destroying the target keyword in the application in the runtime area, the system restarts and then upgrades the application stored in the runtime area by overwriting the upgrade backup program with the upgrade program. If a power outage occurs during the upgrade process, the target keywords of the application will be extracted again. If the target keyword verification is successful, restart the application. If the target keyword verification fails, the upgrade backup program will overwrite the application stored in the running area for upgrade.
7. The software upgrade method for an embedded system according to claim 1, characterized in that, The step of verifying the target keyword and verifying the target verification code with the first verification code includes: The target keyword and the stored keyword are matched and verified, and the target verification code is verified to be consistent with the first verification code. If the target keyword verification is successful and the target checksum verification is successful, then the application will run.
8. A software upgrade device for an embedded system, characterized in that, The embedded system includes internal memory and external memory. The internal memory is configured with a boot sector, a runtime sector, and a parameter sector. The boot sector stores the upgrade boot program, the runtime sector stores the application program, and the external memory stores the upgrade backup program, including: The extraction module is used to extract the target keywords of the application and determine the target checksum of the application when the system starts running. The first verification module is used to verify the target keyword and to verify the target verification code with the first verification code, wherein the first verification code is determined in advance based on the length of the application before the application is started and run. The second verification module is used to verify the upgrade backup program in the external storage based on the pre-generated target file if the target keyword verification fails or the target verification code verification fails. The target file is generated based on the first verification code, the upgrade boot program and the application program to obtain an integrated file and the second verification code corresponding to the integrated file. The upgrade module is used to retrieve the upgrade backup program from the external storage and perform the upgrade if the upgrade backup program verification is successful.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that, When the processor executes the program, it implements the software upgrade method for the embedded system as described in any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the software upgrade method for the embedded system as described in any one of claims 1 to 7.