Embedded device upgrading method and device based on mobile storage device and storage medium
Through the embedded device upgrade method based on mobile storage devices, the version checksum startup priority mechanism is used to solve the upgrade problem of embedded devices in a network-free environment, and the secure booting of the device in the event of failure is achieved and the consistency of the system version.
Patent Information
- Application Number
- CN202510446351.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-10
- Publication Date
- 2025-07-25
AI Technical Summary
Embedded devices cannot successfully complete the system upgrade without a network environment, and the device may not start normally when the upgrade fails. The existing technology cannot effectively deal with problems such as upgrade failure, system file corruption and bit flip.
The embedded device upgrade method based on mobile storage devices is adopted. By detecting mobile storage devices, the hash algorithm is used for version verification. If the upgrade is consistent, skip the upgrade. Otherwise, the backup partition is upgraded, and the startup priority of the backup partition is set to be higher than the current partition. Combined with the bootable number mechanism, switch to the backup partition startup when the failure is faulty, and version synchronization is achieved.
Ensure that embedded devices can be upgraded smoothly in poor network environment or without network, avoid the risk of repeated upgrades, improve the reliability of upgrades and startup, ensure that the device starts safely in case of failure, and maintain the consistency and availability of system versions.
Smart Images

Figure CN120371346A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of industrial equipment for embedded devices, and particularly relates to a method, device, and storage medium for secure upgrade of embedded devices. Background Art
[0002] With the wide application of intelligent embedded devices in the industrial and other intelligent hardware fields, the upgrade of the device operating system has become particularly important. Over-The-Air (OTA) upgrade via wireless communication has become increasingly common, but it relies on a stable network connection to download system files, which poses great limitations for devices to be upgraded in a poor network environment or without a network. Especially for embedded industrial devices, in many scenarios, it is impossible to ensure that the device is always connected to the network, resulting in the upgrade process being unable to proceed smoothly. Moreover, OTA upgrade requires downloading the upgrade file into the device memory. For embedded devices with limited memory resources, there may be a situation where the upgrade cannot be performed due to insufficient memory.
[0003] Regarding the problem of system upgrade in a poor network connection or without a network environment, the patent with publication number CN117873513A discloses a USB upgrade method for an embedded system, which uses a USB flash drive for system upgrade. However, when upgrading, this technology directly writes the upgrade version into the current system partition. If there are problems with the new version to be upgraded, or power failure occurs during the upgrade process, etc., the device may not be able to start normally, and often requires manual intervention or recovery, increasing the maintenance cost and time.
[0004] In the prior art, there is also an OTA upgrade method based on A / B partitions. For example, the patent with publication number CN115291905A discloses a highly reliable automotive OTA upgrade method and system based on A / B systems. When upgrading, the backup partition is upgraded first, and if the upgrade fails, it switches back to the original partition. However, this solution only switches back to the original partition when the upgrade fails or when the upgrade file is invalid. If the upgrade file is valid but there are bugs that cause the device to be unable to start, it cannot switch back to the original partition. If faults such as power failure, incorrect writing, or bit flipping occur during normal operation after the upgrade, resulting in damage to the system files, the device will not be able to start again after restarting. Summary of the Invention
[0005] Object of the Invention: To overcome the deficiencies in the prior art, the present invention provides a method, device, and storage medium for upgrading an embedded device based on a removable storage device, enabling the embedded device to successfully complete system upgrade even in a poor network environment or without a network, and being able to effectively handle problems such as upgrade failure, system file damage, bit flipping, or incorrect operation, and the device can also start safely in case of faults or anomalies.
[0006] Technical solution: In the first aspect, an embedded device upgrade method based on a mobile storage device includes the following steps:
[0007] Detect whether a mobile storage device is connected through the communication interface. If it is detected that the device is connected, determine whether there is a system upgrade file in the mobile storage device. If not, skip the upgrade step;
[0008] When it is detected that there is a system upgrade file in the mobile storage device, calculate the version verification value of the current boot partition using a hashing algorithm and compare it with the version verification value in the upgrade file. If the two are inconsistent, perform an upgrade operation on the backup partition. If they are consistent, skip the upgrade step; the current boot partition and the backup partition are two system partitions divided from the local storage space;
[0009] If the backup partition is upgraded successfully, set the boot priority of the backup partition to be higher than that of the current boot partition, set the number of bootable times of the backup partition to a preset value, and save the relevant parameters to the local storage, and then perform a device restart operation. If the backup partition upgrade fails, record the upgrade log to the mobile storage device, and then execute the version synchronization process to restore the backup partition;
[0010] After the device restarts and enters the bootloader stage to initialize the hardware, select the partition with the higher boot priority from the two system partitions as the boot partition based on the boot priority, decrement the number of bootable times of this partition by 1 and save it to the local storage. If the number of bootable times of the partition with the higher boot priority is 0, select to boot from the other partition;
[0011] Read and load the system file of the currently selected boot partition. If the system starts successfully, set the boot priority of the current partition to be higher than that of the other partition, and set the number of bootable times of the current partition to a preset value. If the system fails to start, trigger a device restart until the number of bootable times of the current boot partition is decremented to 0, and the system switches to the other partition to boot;
[0012] After the system starts successfully, perform a version synchronization operation.
[0013] Furthermore, the local storage space of the embedded device is divided into a bootloader partition, a boot parameter partition, a first system partition, a second system partition, and a user partition. The bootloader partition is used to store the firmware for booting the operating system and is used to initialize the hardware when the device is powered on. The boot parameter partition is used to store the boot parameters of the two system partitions, including the boot priority and the number of bootable times. The first system partition and the second system partition are two mutually backup system partitions used to store the operating system or firmware of the embedded device. The user partition is used to store user-mode programs.
[0014] Further, the version synchronization operation is specifically as follows: Check the number of bootable times of the other partition. If it is 0, copy the current partition to the other partition; if it is not 0, calculate the checksum values of the current partition and the other partition. If the two are inconsistent, after the current partition has been running stably for a specified duration, copy the current partition to the other partition.
[0015] Further, calculate the version checksum value of the currently booted partition using a hashing algorithm, including: calculating the version checksum value of the currently booted partition using the MD5 algorithm or the SHA-1 algorithm.
[0016] Further, set the number of bootable times of the backup partition to a preset value, including: setting the number of bootable times of the backup partition to 2; set the number of bootable times of the current partition to a preset value, including: setting the number of bootable times of the current partition to 2.
[0017] Further, after the device boots successfully, it also includes performing a detection of the removable storage device, and when a system upgrade file is detected in the removable storage device, performing an operation of comparing the version checksum values.
[0018] In a second aspect, an embedded device upgrade system based on a removable storage device includes:
[0019] A removable storage device detection module, configured to detect whether a removable storage device is connected through a communication interface. If it is detected that the device is connected, determine whether there is a system upgrade file in the removable storage device. If not, skip the upgrade steps;
[0020] A version verification module, configured to when a system upgrade file is detected in the removable storage device, calculate the version checksum value of the currently booted partition using a hashing algorithm, and compare it with the version checksum value in the upgrade file. If the two are inconsistent, trigger the backup partition upgrade module; if they are consistent, skip the upgrade steps; the currently booted partition and the backup partition are two system partitions divided from the local storage space;
[0021] A backup partition upgrade module, configured to perform an upgrade operation on the backup partition. If the backup partition upgrade is successful, pass the result to the boot setting module. If the backup partition upgrade fails, record the upgrade log in the removable storage device, and then trigger the version synchronization and recovery module;
[0022] A boot setting module, configured to when the backup partition upgrade is successful, set the boot priority of the backup partition to be higher than that of the currently booted partition, set the number of bootable times of the backup partition to a preset value, and save the relevant parameters to the local storage, and then trigger the device restart module;
[0023] A device restart module, configured to perform a device restart operation to make the device enter the bootloader stage;
[0024] A startup partition selection module, which is used to, after the device restarts and enters the bootloader stage and initializes the hardware, select the partition with a higher startup priority as the startup partition from two system partitions based on the startup priority, decrement the bootable times of this partition by 1 and save it to the local storage; if the bootable times of the partition with a higher startup priority is 0, then select to boot from the other partition;
[0025] A system file loading module, which is used to read and load the system files of the currently selected startup partition. If the system starts successfully, it will pass the result to the startup priority reset module; if the system startup fails, it will trigger the device restart module until the bootable times of the current startup partition is decremented to 0 and the system switches to boot from the other partition;
[0026] A startup priority reset module, which is used to, after the system starts successfully, set the startup priority of the current partition to be higher than that of the other partition and set the bootable times of the current partition to a preset value;
[0027] A version synchronization and recovery module, which is used to execute the version synchronization process to recover the backup partition when the backup partition upgrade fails; and perform version synchronization operations after the system starts successfully.
[0028] In a third aspect, the present invention further provides an embedded device, including: a processor; a memory; and a computer program, where the computer program is stored in the memory and is configured to be executed by the processor, and when the computer program is executed by the processor, it implements the steps of the embedded device upgrade method based on a mobile storage device as described in the first aspect of the present invention.
[0029] In a fourth aspect, the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by the processor, it implements the steps of the embedded device upgrade method based on a mobile storage device as described in the first aspect of the present invention.
[0030] In a fifth aspect, the present invention further provides a computer program product, including a computer program, and when the computer program is executed by the processor, it implements the steps of the embedded device upgrade method based on a mobile storage device as described in the first aspect of the present invention.
[0031] Beneficial effects: Compared with the prior art, the beneficial effects of the present invention are as follows:
[0032] (1) Prevent invalid and repeated upgrades through version comparison: Before system upgrade, version comparison is carried out. If the versions are the same, the upgrade is skipped to avoid unnecessary upgrade operations and potential risks. During the restart process after upgrade, the system will detect the removable storage device and trigger the upgrade again. However, due to the version comparison mechanism, the risk of repeated upgrades is effectively avoided. Therefore, there is no need to use methods such as serial ports to prompt to remove the removable storage after upgrade, making the engineering upgrade safe and convenient. At the same time, the upgrade files are stored in the removable storage, saving the storage space of the embedded device.
[0033] (2) Use two system partitions to improve the reliability of upgrade and startup: The startup partition is selected through the combination of startup priority and the number of bootable times. Set the number of bootable times to a preset value. If the current startup partition fails to start successfully twice due to power failure during the upgrade process, incorrect upgrade files, damaged versions, etc., it is determined that the partition startup fails and switches to the backup partition for startup, so as to ensure that the device is not affected by upgrade failures, damaged versions, etc. and can continue to run normally.
[0034] (3) Automatic fault detection and recovery of the backup partition: After the system starts up and detects that the number of bootable times of the backup partition is 0, it will trigger version synchronization to repair the damaged version of the backup partition to ensure that the version of the backup partition is always available and avoid the device running in a single partition state.
[0035] (4) The version synchronization mechanism ensures that the versions of the two partitions are always the same and available: After the current partition runs stably for a period of time, it will be copied to the backup partition for version synchronization. This can effectively reduce the risk of failures during the upgrade process, ensure the stability of the system version, and avoid introducing new errors or unstable factors due to eagerness for synchronization. Synchronization ensures that when the system starts from the backup partition, it can continue to run with the latest version without the system reverting to an old version or failing to work properly due to version inconsistency. Description of the Drawings
[0036] Figure 1 It is a block diagram of the system architecture according to an embodiment of the present invention;
[0037] Figure 2 It is a flowchart of the embedded device upgrade method in an embodiment of the present invention;
[0038] Figure 3 It is a general flowchart combining the startup process and the upgrade process in an embodiment of the present invention. Detailed Embodiment
[0039] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the drawings.
[0040] Figure 1The architecture for upgrading an embedded device using a removable storage device in an embodiment of the present invention is shown. It mainly consists of two parts: a removable storage device and an embedded device. The removable storage device, as an external storage medium, is the carrier of upgrade data and is used to store system upgrade files and record the upgrade logs of the system. The removable storage device can be connected to the embedded device through a wired communication interface or a wireless communication interface. The embedded device includes a processor (CPU), a local memory (such as flash memory, EMMC, etc.), and a USB port (or other interfaces such as SDIO / WIFI) that supports the USB interface. The local storage space of the embedded device is divided into multiple areas: a bootloader partition, two system partitions (system partition A and system partition B), a boot parameter partition, and a user partition. The bootloader partition stores the firmware for booting the operating system and is used to initialize hardware and peripherals such as the CPU, memory, and local storage when the device is powered on. System partition A and system partition B are two mutually backup partitions and are used to store the operating system or firmware of the embedded device. The boot parameter partition is used to store the boot parameters of the two system partitions, including the boot priority and the number of bootable times. The user partition is used to store user-mode programs, that is, user-related data and settings.
[0041] Referring to Figure 2 , the upgrade process of the embedded device is as follows:
[0042] Step S1, detect whether a removable storage device is connected through the communication interface. If it is detected that a connection is made, then determine whether there is a system upgrade file in the removable storage device; if not, skip the upgrade steps;
[0043] The embedded device uses the Netlink mechanism provided by the operating system to detect whether a removable storage device is connected. For example, for the USB interface, the operating system will send a USB flash drive insertion event message through the Udev (user device) subsystem; the user-space application program receives these events by creating and listening to a Netlink socket, thereby detecting the insertion of the USB flash drive in real time and performing subsequent detection operations.
[0044] If it is detected that a removable storage device is connected, the device will traverse the file system of the device (which can be common formats such as FAT32, NTFS, etc.). It will search for the existence of a system upgrade file through a predefined system upgrade file naming rule or a specific file identifier. For example, if the upgrade file may be named "system_update.bin", the device will search for this file in the root directory and related subdirectories of the removable storage device.
[0045] Step S2, when it is detected that there is a system upgrade file in the removable storage device, calculate the version verification value of the current boot partition using a hashing algorithm, and compare it with the version verification value in the upgrade file. If the two are inconsistent, perform an upgrade operation on the backup partition; if they are consistent, skip the upgrade step; the current boot partition and the backup partition are two system partitions divided from the local storage space;
[0046] Hashing algorithm calculation: Use hashing algorithms such as MD5 or SHA-1. For the current boot partition, read the binary data of the key system files (such as kernel files, boot files, etc.) in the partition, and input this data into the hashing algorithm function to calculate the version verification value. For the upgrade file, also read the file content for hashing calculation.
[0047] Verification value comparison: Compare the two calculated hash values bit by bit. This can be done through a loop to sequentially compare whether the values of each byte or bit are equal. If any inequality is found, it is determined that the two are inconsistent.
[0048] Step S3, if the backup partition is successfully upgraded, set the boot priority of the backup partition to be higher than that of the current boot partition, set the number of bootable times of the backup partition to a preset value, and save the relevant parameters to the local storage, and then perform a device restart operation; if the backup partition upgrade fails, record the upgrade log to the removable storage device, and then execute the version synchronization process to restore the backup partition;
[0049] Set the boot priority of the backup partition: In the boot parameter partition of the embedded device, modify the boot priority flag bit of the backup partition so that it is higher than the priority flag bit of the current boot partition. This can be achieved by directly modifying a specific local storage area.
[0050] Set the number of bootable times: Store the preset value in a variable or storage area specifically used to record the number of bootable times.
[0051] The relevant parameters (such as boot priority, number of bootable times, etc.) can be serialized in a certain format (such as key-value pair form) and then written into a specific file or storage block in the local storage. For example, write it into the boot configuration file or a specific storage area.
[0052] Create a log file (such as "upgrade_log.txt") on the removable storage device, and write the key information during the upgrade process (such as upgrade time, upgrade result, error information encountered, etc.) into the file in a certain format.
[0053] Step S4, after the device restarts and enters the bootloader stage to initialize the hardware, select the partition with the higher boot priority from the two system partitions as the boot partition based on the boot priority, decrement the bootable times of this partition by 1 and save it to the local storage; if the bootable times of the partition with the higher boot priority is 0, then select to boot from the other partition;
[0054] Hardware initialization: In the bootloader stage, in accordance with the initialization sequence of the hardware devices, set the CPU registers in sequence (such as setting the stack pointer, interrupt vector, etc.), initialize the memory controller (such as setting the memory frequency, timing, etc.), and perform reset and initialization operations on various peripherals (such as serial ports, network interfaces, etc.).
[0055] Select the boot partition: According to the previously set boot priority, read the information from the place where the boot priority information is stored (such as the boot configuration file or a specific local storage area) to determine the partition with the higher boot priority.
[0056] Bootable times operation: Read the bootable times of this partition from the local storage, decrement it by 1, and then write it back to the corresponding position in the local storage.
[0057] Step S5, read and load the system file of the currently selected boot partition. If the system boots successfully, set the boot priority of the current partition to be higher than that of the other partition, and set the bootable times of the current partition to a preset value; if the system boots fails, trigger a device restart until the bootable times of the current boot partition is decremented to 0, and the system switches to boot from the other partition;
[0058] Read and load the system file: Read the system file in the selected boot partition into the memory through the file system driver, and then load it to a specific address in the memory according to the system boot process, and perform operations such as decompression and initialization.
[0059] Set the boot priority: Similar to the method of setting the boot priority of the backup partition in Step S3, modify the value of the boot configuration file or the relevant storage area to increase the boot priority of the current partition.
[0060] When the system boots fails, the device's bootloader (such as bootloader) will detect the failed boot status and then automatically trigger a device restart operation. Each time it restarts, it will try to boot from the current boot partition again until the bootable times is decremented to 0.
[0061] After the device boots successfully, it also includes performing a detection on the removable storage device, and when a system upgrade file is detected in the removable storage device, comparing the version verification values.
[0062] Step S6, after the system starts successfully, perform version synchronization operations. Specifically: check the bootable times of the other partition. If it is 0, copy the current partition to the other partition; if it is not 0, calculate the checksum values of the current partition and the other partition. If they are inconsistent, after the current partition runs stably for a specified duration, copy the current partition to the other partition.
[0063] The partition copy operation is as follows: If the bootable times of the other partition is 0, use the copy function of the file system (such as using the cp command or the corresponding system call in the Linux system) to copy the system files of the current partition completely to the other partition. If the bootable times of the other partition is not 0, after calculating the checksum values, if they are inconsistent, during the stable operation of the current partition, the partition copy operation can be triggered by using a background task or a specific system maintenance process under the condition of meeting the specified duration of stable operation (which can be monitored by a timer).
[0064] Through steps S1 and S2 of the present invention, version comparison is performed before system upgrade. If the versions are the same, the upgrade is skipped, avoiding unnecessary upgrade operations and potential risks; during the restart process after upgrade, the system will detect the removable storage device and trigger the upgrade again, but due to the version comparison mechanism, the risk of repeated upgrade is effectively avoided. Therefore, it is not necessary to use serial ports or other methods to prompt to remove the removable storage after upgrade, making the engineering upgrade safe and convenient. At the same time, the upgrade files are stored in the removable storage device, saving the storage space of the embedded device.
[0065] In step S3 of the present invention, the boot partition is selected through the combination of boot priority and bootable times, and the bootable times is set to a preset value. If the current boot partition fails to start successfully for the specified number of times due to power failure during the upgrade process, incorrect upgrade files, damaged versions, etc., it is determined that the partition fails to start and switches to the backup partition to start, so as to ensure that the device is not affected by upgrade failure, damaged versions, etc. and can continue to run normally.
[0066] After the system starts and checks that the bootable times of the backup partition is 0, it will trigger version synchronization to repair the damaged version of the backup partition, ensuring that the version of the backup partition is always available and avoiding the device running in a single partition state. The version synchronization mechanism ensures that the versions of the two partitions are always the same and available.
[0067] As Figure 3 shown, in an embodiment, the system upgrade and startup processes are combined, and the specific process is as follows:
[0068] Step A: Create a system upgrade file update_ab.img (such as an update package of firmware or operating system) on a PC or other computing device, and store update_ab.img in a USB flash drive. The file format and naming should meet the requirements of the device.
[0069] Step B: Insert the USB flash drive into the USB interface of the embedded device. The device recognizes the access of the USB flash drive through the hardware interface and prepares for the upgrade operation.
[0070] Step C: The operating system running on the embedded device detects whether the USB flash drive is connected. If the USB flash drive is detected to be connected, the upgrade program is started. The upgrade program scans the operating system files in the USB flash drive. If there is a valid upgrade file update_ab.img in the USB flash drive, the subsequent upgrade verification and comparison steps will continue. If there is no upgrade file update_ab.img in the USB flash drive, the upgrade ends. It should be understood that the upgrade file update_ab.img is only used as an example here and does not limit that this method can only execute the upgrade process for this file.
[0071] Step D: The upgrade program system uses the MD5 algorithm to calculate and compare the version md5 checksum in the current startup partition (Zone A in this embodiment) and the md5 checksum of the upgrade file in the USB flash drive. If the current version is the same as the upgrade file version, the upgrade process is skipped. If the versions are different, it means that the operating system needs to be upgraded.
[0072] Step E: The upgrade program upgrades the backup partition (Zone B in this embodiment). During the upgrade process, the normal operation of Zone A will not be affected. If the upgrade of Zone B fails, the system will not switch partitions and restart, but jump to Step L to recover Zone B.
[0073] Step F: If the upgrade of Zone B is successful, the upgrade program will set the startup priority of the backup partition (Zone B) to be greater than that of the current system startup partition (Zone A), and at the same time set the number of bootable times of Zone B to the preset value of 2. The device then restarts and enters the bootloader stage. In this embodiment, the preset value is set to 2. If it is set to 1, misjudgment may occur due to power failure or other reasons.
[0074] Step G: After the device restarts and enters the bootloader stage, it initializes peripherals such as the CPU, memory, and local storage, reads and loads the operating system in the local storage. Then it enters the operating system startup partition selection module.
[0075] Step H: Start the partition selection program. The program first reads the startup priorities of Zones A / B in the parameter partition, and then reads the number of bootable times of the partition with the higher priority (Zone B in this embodiment, because it has been set in Step F). If its number of bootable times is greater than 0, select Zone B as the current startup partition, and at the same time reduce the number of bootable times of this zone by 1. If the number of bootable times is 0, select Zone A as the current startup partition, and at the same time reduce the number of bootable times of Zone A by 1.
[0076] Step I: Read and load the operating system of the current startup partition. In this embodiment, the operating system refers to the linux operating system.
[0077] Step J: If the system fails to start, the embedded device will be restarted and the process will return to Step G. If the system fails to start successfully twice in a row, it will switch to Area A for startup.
[0078] Step K: If the system starts successfully, set the startup priority of the current startup partition (Area B in this embodiment) to 15, the startup priority of the backup partition (Area A) to 14, and the number of bootable times for Area B to 2. The next restart will still start from the current partition.
[0079] Step L: Start the partition synchronization program. The program reads the number of bootable times of the backup partition. If the number is 0, it means the version of this partition is damaged and cannot be started, and the current partition will be copied to the backup partition for version synchronization. If the number is not 0, calculate the md5 checksum values of the current partition (Area B in this embodiment) and the backup partition (Area A in this embodiment). If the checksum values are the same, the synchronization program ends; if the checksum values are different, after the program has run stably in the current partition for 24 hours, it will automatically copy the files in the current partition (Area B) to the backup partition (Area A) to ensure that the versions of the two partitions are always the same.
[0080] Step M: The process ends.
[0081] In this embodiment, if the current startup partition (Area B in this embodiment) is damaged due to power failure, bit flipping, incorrect writing, etc. after the partition synchronization is completed, and the system fails to start after restarting, when the number of startup times of Area B is reduced to 0, it will switch to Area A for startup, so that the system can resume normal operation and run the upgraded new version.
[0082] The present invention also provides an embedded device upgrade system based on a mobile storage device, including:
[0083] A mobile storage device detection module, used to detect whether a mobile storage device is connected through a communication interface. If it is detected that there is a connection, it will determine whether there is a system upgrade file in the mobile storage device. If not, the upgrade step will be skipped;
[0084] A version verification module, used to calculate the version verification value of the current startup partition using a hashing algorithm and compare it with the version verification value in the upgrade file when it is detected that there is a system upgrade file in the mobile storage device. If the two are inconsistent, the backup partition upgrade module will be triggered; if they are consistent, the upgrade step will be skipped; the current startup partition and the backup partition are two system partitions divided from the local storage space;
[0085] The backup partition upgrade module is used to perform an upgrade operation on the backup partition. If the backup partition upgrade is successful, the result is passed to the startup settings module. If the backup partition upgrade fails, the upgrade log is recorded to a removable storage device, and then the version synchronization and recovery module is triggered;
[0086] The startup settings module is used to, when the backup partition upgrade is successful, set the startup priority of the backup partition to be higher than the current startup partition, set the number of bootable times of the backup partition to a preset value, and save the relevant parameters to local storage. Subsequently, the device restart module is triggered;
[0087] The device restart module is used to perform a device restart operation to make the device enter the bootloader stage;
[0088] The startup partition selection module is used to, after the hardware is initialized when the device restarts and enters the bootloader stage, select the partition with the higher startup priority from the two system partitions as the startup partition, decrement the number of bootable times of this partition by 1 and save it to local storage; if the number of bootable times of the partition with the higher startup priority is 0, select to boot from the other partition;
[0089] The system file loading module is used to read and load the system files of the currently selected startup partition. If the system startup is successful, the result is passed to the startup priority reset module; if the system startup fails, the device restart module is triggered until the number of bootable times of the current startup partition is decremented to 0 and the system switches to boot from the other partition;
[0090] The startup priority reset module is used to, after the system startup is successful, set the startup priority of the current partition to be higher than the other partition and set the number of bootable times of the current partition to a preset value;
[0091] The version synchronization and recovery module is used to, when the backup partition upgrade fails, execute a version synchronization process to recover the backup partition; and to perform a version synchronization operation after the system startup is successful.
[0092] The version synchronization operation specifically is: check the number of bootable times of the other partition. If it is 0, copy the current partition to the other partition; if it is not 0, calculate the checksum values of the current partition and the other partition. If they are inconsistent, after the current partition has been running stably for a specified duration, copy the current partition to the other partition
[0093] The present invention also provides an embedded device, including: a processor; a memory; and a computer program, where the computer program is stored in the memory and is configured to be executed by the processor, and when the computer program is executed by the processor, the steps of the embedded device upgrade method based on a removable storage device as described above are implemented.
[0094] The present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-described method for upgrading an embedded device based on a removable storage device are implemented.
[0095] The present invention also provides a computer program product, including a computer program. When the computer program is executed by a processor, the steps of the above-described method for upgrading an embedded device based on a removable storage device are implemented.
[0096] The present invention is described with reference to the flowchart of the method according to an embodiment of the present invention. It should be understood that each process in the flowchart and the combination of processes in the flowchart can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose or special-purpose device, an embedded processor, or other programmable data processing devices to generate a machine, such that the instructions executed by the processor of the device, the embedded processor, or other programmable data processing devices generate components for implementing the functions specified in one Figure 1 process or multiple processes.
[0097] These computer program instructions can also be stored in a computer-readable memory that can direct a device, an embedded processor, or other programmable data processing devices to work in a specific manner, such that the instructions stored in the computer-readable memory generate a manufactured article including instruction components, and the instruction components implement the functions specified in one Figure 1 process or multiple processes.
[0098] These computer program instructions can also be loaded onto a computer or other programmable data processing devices, such that a series of operation steps are executed on the computer or other programmable devices to generate a computer-implemented process. Thus, the instructions executed on the computer or other programmable devices provide steps for implementing the functions specified in one Figure 1 process or multiple processes.
Claims
1. An embedded device upgrade method based on a mobile storage device, characterized in that, It includes the following steps: Detect whether a removable storage device is connected through the communication interface. If it is detected that there is a connection, determine whether there is a system upgrade file in the removable storage device; If not, skip the upgrade step; When it is detected that there is a system upgrade file in the removable storage device, use a hashing algorithm to calculate the version verification value of the current startup partition and compare it with the version verification value in the upgrade file. If the two are inconsistent, perform an upgrade operation on the backup partition; If they are consistent, skip the upgrade step; The current startup partition and the backup partition are two system partitions divided from the local storage space; If the backup partition is successfully upgraded, set the startup priority of the backup partition to be higher than that of the current startup partition, set the number of bootable times of the backup partition to a preset value, and save the relevant parameters to the local storage, and then perform a device restart operation; If the backup partition upgrade fails, record the upgrade log to the removable storage device, and then execute the version synchronization process to restore the backup partition; After the device restarts and enters the bootloader stage to initialize the hardware, select the partition with the higher startup priority from the two system partitions as the startup partition based on the startup priority, subtract 1 from the number of bootable times of this partition and save it to the local storage; if the number of bootable times of the partition with the higher startup priority is 0, select to boot from the other partition; Read and load the system file of the currently selected startup partition. If the system starts successfully, set the startup priority of the current partition to be higher than that of the other partition, and set the number of bootable times of the current partition to a preset value; If the system fails to start, trigger a device restart until the number of bootable times of the current startup partition is reduced to 0, and the system switches to the other partition to start; After the system starts successfully, perform a version synchronization operation.
2. The method according to claim 1, wherein The local storage space of the embedded device is divided into a bootloader partition, a startup parameter partition, a first system partition, a second system partition, and a user partition. The bootloader partition is used to store the firmware for booting the operating system and is used to initialize the hardware when the device is powered on; The startup parameter partition is used to store the startup parameters of the two system partitions, including the startup priority and the number of bootable times; The first system partition and the second system partition are two mutually backup system partitions and are used to store the operating system or firmware of the embedded device; The user partition is used to store user-mode programs.
3. The method according to claim 1, wherein The version synchronization operation is specifically: check the number of bootable times of the other partition. If it is 0, copy the current partition to the other partition; if it is not 0, calculate the verification values of the current partition and the other partition. If the two are inconsistent, after the current partition has been running stably for a specified period of time, copy the current partition to the other partition.
4. The method according to claim 1, characterized in that, Use a hashing algorithm to calculate the version verification value of the current startup partition, including: using the MD5 algorithm or the SHA-1 algorithm to calculate the version verification value of the current startup partition.
5. The method according to claim 1, characterized in that Set the number of bootable times of the backup partition to a preset value, including: set the number of bootable times of the backup partition to 2; set the number of bootable times of the current partition to a preset value, including: set the number of bootable times of the current partition to 2.
6. The method according to claim 1, wherein After the device is successfully started, it further includes performing a detection on a removable storage device, and when a system upgrade file is detected in the removable storage device, comparing the version verification values.
7. An embedded device upgrade system based on a mobile storage device, characterized in that, It includes: A removable storage device detection module, configured to detect whether a removable storage device is connected through a communication interface. If a connection is detected, it determines whether a system upgrade file exists in the removable storage device. If not, it skips the upgrade steps; A version verification module, configured to when a system upgrade file is detected in the removable storage device, calculate the version verification value of the current startup partition using a hashing algorithm and compare it with the version verification value in the upgrade file. If the two are inconsistent, it triggers the backup partition upgrade module; If they are consistent, it skips the upgrade steps; The current startup partition and the backup partition are two system partitions divided from the local storage space; A backup partition upgrade module, configured to perform an upgrade operation on the backup partition. If the backup partition upgrade is successful, it passes the result to the startup settings module. If the backup partition upgrade fails, it records the upgrade log to the removable storage device, and then triggers the version synchronization and recovery module; A startup settings module, configured to when the backup partition upgrade is successful, set the startup priority of the backup partition to be higher than that of the current startup partition, set the number of bootable times of the backup partition to a preset value, and save the relevant parameters to the local storage, and then trigger the device restart module; A device restart module, configured to perform a device restart operation to make the device enter the bootloader stage; A startup partition selection module, configured to after the device restarts and enters the bootloader stage and initializes the hardware, select the partition with the higher startup priority from the two system partitions as the startup partition, decrement the number of bootable times of this partition by 1 and save it to the local storage; if the number of bootable times of the partition with the higher startup priority is 0, it selects to boot from the other partition; A system file loading module, configured to read and load the system files of the currently selected startup partition. If the system starts successfully, it passes the result to the startup priority reset module; If the system startup fails, it triggers the device restart module until the number of bootable times of the current startup partition is decremented to 0 and the system switches to boot from the other partition; A startup priority reset module, configured to after the system starts successfully, set the startup priority of the current partition to be higher than that of the other partition, and set the number of bootable times of the current partition to a preset value; A version synchronization and recovery module, configured to when the backup partition upgrade fails, perform a version synchronization process to recover the backup partition; And after the system starts successfully, perform a version synchronization operation.
8. An embedded device, characterized in that, It includes: A processor; A memory; And a computer program, which is stored in the memory and is configured to be executed by the processor. When the computer program is executed by the processor, it implements the steps of the embedded device upgrade method based on a removable storage device according to any one of claims 1-6.
9. A 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 steps of the embedded device upgrade method based on a removable storage device according to any one of claims 1-6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method for upgrading an embedded device based on a removable storage device as described in any one of claims 1-6.
Citation Information
Patent Citations
High-reliability automobile OTA upgrading method and system based on A / B system
CN115291905A
USB upgrading method of embedded system, embedded device and storage medium
CN117873513A