Firmware upgrading method, electronic equipment and storage medium
By backing up the bootloader firmware and partition table in the boot communication partition, it solves the problem of device bricking and external storage dependency during OTA upgrade, improves the efficiency and reliability of firmware upgrade, and ensures data integrity during the upgrade process.
Patent Information
- Application Number
- CN202410696891.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-31
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2044-05-31
AI Technical Summary
The existing OTA firmware upgrade solution can easily cause the device to become bricked and unable to start normally when the partition table changes. It also requires external storage and multiple restarts, affecting upgrade efficiency and reliability.
By backing up the bootloader firmware and partition table in the boot communication partition, the backup information is used to continue the upgrade during the upgrade process, avoiding external storage and multiple restarts, ensuring the reliability and efficiency of the upgrade process.
It realizes OTA upgrade when the partition table changes without external storage, avoids device bricking, improves the efficiency and reliability of firmware upgrade, and ensures that the user data partition content remains unchanged.
Smart Images

Figure CN118567680A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of embedded devices, and in particular to a method for upgrading firmware, an electronic device and a storage medium. Background Art
[0002] When upgrading the firmware via Over-The-Air (OTA), it is usually required that the firmware partition table cannot change before and after the upgrade. However, in some scenarios, due to the unreasonable initial partition table design, the firmware partition table needs to be changed to a certain extent. At this time, a method is needed to upgrade the firmware with the changed partition table to the device through OTA when the device partition table changes.
[0003] Existing firmware upgrade solutions that support OTA upgrade partition table changes usually have one or more of the following problems. The upgrade process requires external storage (such as an SD card or USB flash drive). When an unexpected event occurs during the upgrade process (such as a power outage), the device may become a brick and cannot be started normally and continue to upgrade. The user data partition that can read, write and save user data is reformatted, and the content inside is erased after the upgrade. Multiple restarts are required during the upgrade process. Summary of the invention
[0004] The present invention provides a method for upgrading firmware, an electronic device and a storage medium, which can improve the efficiency and reliability of firmware upgrading.
[0005] In one aspect of the present invention, a method for upgrading firmware is provided. The method includes: according to the upgrade instruction information corresponding to the first preset upgrade instruction in the first preset position of the boot communication partition, backing up the boot program firmware and the boot communication partition, and writing the second preset upgrade instruction to the first preset position; according to the upgrade instruction information corresponding to the second preset upgrade instruction in the first preset position of the boot communication partition, upgrading the partition table and the boot program firmware based on the firmware upgrade package information in the second preset position of the boot communication partition, and writing the third preset upgrade instruction to the first preset position; according to the upgrade instruction information corresponding to the third preset upgrade instruction in the first preset position of the boot communication partition, upgrading other firmware except the boot program firmware based on the firmware upgrade package information in the second preset position of the boot communication partition.
[0006] In another aspect of the present invention, an electronic device is provided, which includes a memory configured to store an executable program and a processor configured to execute the program to perform the above-mentioned method for upgrading firmware.
[0007] In another aspect of the present invention, a computer readable medium is provided, wherein a computer program is stored on the medium, and the computer program is executed by a processor to implement the above-mentioned method for upgrading firmware.
[0008] According to the present invention, according to the upgrade instruction information corresponding to the first preset upgrade instruction in the first preset position of the boot communication partition, the boot program firmware and the boot communication partition are backed up, according to the upgrade instruction information corresponding to the second preset upgrade instruction, the partition table and the boot program firmware are upgraded based on the firmware upgrade package information in the second preset position of the boot communication partition, and according to the upgrade instruction information corresponding to the third preset upgrade instruction, other firmware is upgraded based on the firmware upgrade package information in the second preset position of the boot communication partition. By backing up the boot program firmware and the boot communication partition, it is possible to support OTA upgrade of firmware with changes in the partition table without relying on external storage. In addition, even if an accident occurs during the upgrade, the backup boot program firmware can be used to continue the upgrade to avoid bricking the device and without the need to restart the process multiple times, thereby improving the efficiency and reliability of the firmware upgrade. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] Figure 1 A flowchart of the method for upgrading firmware according to an embodiment of the present invention;
[0010] Figure 2 A schematic diagram of a flow chart of a method for upgrading firmware according to an embodiment of the present invention;
[0011] Figure 3 FIG. 4 is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0012] In order to explain the technical content, achieved objectives and effects of the present invention in detail, the following is an explanation in conjunction with the implementation modes and the accompanying drawings.
[0013] In the prior art, firmware upgrade solutions that support OTA upgrade partition table changes usually have one or more problems. For example, the upgrade process needs to rely on external storage (such as SD card or USB flash drive). When an accident occurs during the upgrade process (such as power failure), the device may become bricked and cannot be started normally and continue to upgrade. The user data partition that can read, write and save user data is reformatted, and the content inside is erased after the upgrade. Multiple restarts are required during the upgrade process.
[0014] In order to solve at least the above technical problems, the present disclosure provides a method for upgrading firmware. According to an embodiment of the present disclosure, according to the upgrade instruction information corresponding to the first preset upgrade instruction in the first preset position of the boot communication partition, the boot program firmware and the boot communication partition are backed up, according to the upgrade instruction information corresponding to the second preset upgrade instruction, the partition table and the boot program firmware are upgraded based on the firmware upgrade package information in the second preset position of the boot communication partition, and according to the upgrade instruction information corresponding to the third preset upgrade instruction, other firmware is upgraded based on the firmware upgrade package information in the second preset position of the boot communication partition. In this way, by backing up the boot program firmware and the boot communication partition, it is possible to support OTA upgrade of firmware with changes in the partition table without relying on external storage. In addition, even if an accident occurs during the upgrade, the backup boot program firmware can be used to continue the upgrade to avoid bricking the device, and there is no need to restart the process multiple times, thereby improving the efficiency and reliability of the firmware upgrade.
[0015] Hereinafter, the technical solution according to the present disclosure will be described with reference to specific embodiments and in conjunction with the accompanying drawings.
[0016] Figure 1 1 is a flowchart showing a method 100 for upgrading firmware according to an embodiment of the present disclosure. Figure 1 The method 100 includes the following steps 102 to 106.
[0017] In step 102, according to the upgrade instruction information corresponding to the first preset upgrade instruction in the first preset position of the boot communication partition, the boot program firmware and the boot communication partition are backed up, and the second preset upgrade instruction is written into the first preset position. In this way, the backup operation of the boot program firmware and the boot communication partition is completed by judging whether the first preset upgrade instruction exists.
[0018] In some embodiments, the boot program firmware is backed up to point the starting address of the boot program firmware partition in the current partition table to the address where the backed-up boot program firmware is located. When the boot communication partition in the new partition table changes, the boot communication partition is backed up synchronously to point the starting address of the boot communication partition in the current partition table to the address where the backed-up boot communication partition is located.
[0019] In this way, if an accident (such as power failure) occurs when the boot program firmware is upgrading the boot program firmware itself, since the backup boot program firmware will not be damaged, the boot program firmware can be booted from the backup boot program firmware partition after power-on and continue to be upgraded, thereby improving the efficiency and reliability of firmware upgrading.
[0020] In step 104, according to the upgrade instruction information corresponding to the second preset upgrade instruction in the first preset position of the boot communication partition, the partition table and the boot program firmware are upgraded based on the firmware upgrade package information in the second preset position of the boot communication partition, and the third preset upgrade instruction is written into the first preset position.
[0021] In some embodiments, upgrading the partition table includes upgrading the modified partition table to the address space where the main firmware partition table and the backup partition table are located.
[0022] In some embodiments, the partition table file to be upgraded is obtained from the path of the folder where the firmware upgrade package is decompressed in the firmware upgrade package information as a new partition table. Compare whether the starting address and length of the boot program firmware partition in the current partition table and the new partition table are the same. If they are the same, modify the starting address of the boot program firmware partition in the current partition table to the starting address of the boot program backup firmware in the boot program firmware backup information. If there is valid information in the boot communication partition backup information, modify the starting address of the boot communication partition in the current partition table to the starting address of the boot communication partition backup partition in the boot communication partition backup information, and upgrade the current partition table to the address space where the main firmware partition table is located in the boot storage medium, and upgrade the current partition table to the address space where the backup partition table is located in the boot storage medium. Obtain the boot program firmware image file to be upgraded from the path of the folder where the firmware upgrade package is decompressed, and upgrade the boot program firmware image file to be upgraded to the address space of the boot program firmware partition in the new partition table. If there is valid information in the boot communication partition backup information, all data in the address space consisting of the boot communication partition backup partition start address and the boot communication partition backup partition size in the boot communication partition backup information are copied to the address space of the boot communication partition in the new partition table. In addition, the new partition table is updated to the address space where the main firmware partition table in the boot storage medium is located, the new partition table is updated to the address space where the backup partition table in the boot storage medium is located, and the new partition table is used as the current partition table.
[0023] In this way, the entire upgrade process does not require multiple restarts, and when the device is accidentally powered on again for upgrading, it can continue upgrading from the last unfinished upgrade stage, improving the efficiency of firmware upgrades. At the same time, the data in the preset user data partition is not destroyed during the upgrade process, ensuring that the content in the user data partition remains unchanged after the upgrade.
[0024] In step 106, according to the upgrade instruction information corresponding to the third preset upgrade instruction in the first preset position of the boot communication partition, other firmware except the boot program firmware is upgraded based on the firmware upgrade package information in the second preset position of the boot communication partition.
[0025] In some embodiments, other firmware image files except the boot program firmware image file are obtained in sequence from the firmware upgrade package decompression folder path in the firmware upgrade package information, and the other firmware image files are upgraded to the address space of the corresponding firmware partition in the new partition table respectively.
[0026] In this way, after upgrading the partition table and the bootloader firmware, other firmware can be upgraded to successfully complete the firmware upgrade.
[0027] In some embodiments, before step 102, the method 100 may also include: obtaining a firmware upgrade package to be upgraded, wherein the firmware upgrade package to be upgraded includes a firmware image file and a partition table file with a preset name; decompressing all files of the firmware upgrade package to be upgraded to a preset path of a preset user data partition; and mounting the user data partition in the boot program firmware.
[0028] In some embodiments, the backup completion mark is determined based on the boot program firmware backup information, whether the address space of the boot communication partition changes in the new partition table, and the boot communication partition backup information. If the backup completion mark is true, the boot program firmware and the boot communication partition are not backed up. If the backup completion mark is false, the boot program firmware and the boot communication partition are backed up. In this way, the backup completion mark is determined based on the boot program firmware backup information, whether the address space of the boot communication partition changes in the new partition table, and the boot communication partition backup information, based on the consideration that any node in the backup process may experience an unexpected power failure, by combining multiple factors, it is ensured that the backup is truly completed, thereby ensuring the reliability of the upgrade.
[0029] In some embodiments, the boot program firmware backup information in the third preset position of the boot communication partition in the current partition table is read. It is determined whether the backup information magic number in the boot program firmware backup information is the same as the preset backup information magic number. If not, the backup completion mark is set to false. If the same, it is determined whether the starting address of the boot program firmware partition in the current partition table is the same as the starting address of the boot program backup firmware in the boot program firmware backup information. If not, the backup completion mark is set to false. If so, the partition table file to be upgraded is obtained from the firmware upgrade package decompression folder path in the firmware upgrade package as a new partition table, and the starting address and length of the boot communication partition in the current partition table and the new partition table are compared to see if they are the same. If they are the same, the boot communication partition change mark is set to false. If they are not the same, the boot communication partition change mark is set to true. If the boot communication partition change mark is false, the backup completion mark is set to true. If the boot communication partition change mark is true, it is determined whether the length of the boot communication partition in the new partition table is less than the length of the boot communication partition in the current partition table. If it is less than, an error message is displayed and the firmware upgrade process is exited. If it is not less than, the boot communication partition backup information in the fourth preset position of the boot communication partition in the current partition table is read, and it is determined whether the backup information magic number in the boot communication partition backup information is the same as the preset backup information magic number. If not, the backup completion mark is set to false. If so, it is determined whether the starting address of the boot communication partition in the current partition table is the same as the starting address of the boot communication partition backup partition in the boot communication partition backup information. If they are the same, the backup completion mark is set to true. If they are not the same, the backup completion mark is set to false. In this way, the backup completion mark can be used to intuitively determine whether the backup operation of the boot program firmware and the boot communication partition is completed.
[0030] In some embodiments, the total length of the data to be backed up is calculated. In the boot program firmware partition in the new partition table and the firmware partition after the boot communication partition, a firmware partition whose partition length is greater than the total length of the data to be backed up is searched as a backup partition, and the starting address and size of the backup partition in the new partition table are obtained at the same time. According to the starting address and size of the boot program firmware partition in the current partition table, all the contents in the boot program firmware partition of the corresponding address space are copied to the address space starting from the starting address of the backup partition. If the boot communication partition change mark is true, the boot communication partition backup starting address is set to the starting address of the backup partition plus the size of the boot program firmware partition in the current partition table. According to the starting address and size of the boot communication partition in the current partition table, all the contents in the boot communication partition of the corresponding address space are copied to the address space starting from the backup starting address of the boot communication partition. Boot program firmware backup information is constructed, and the boot program firmware backup information is saved to the third preset position of the boot communication partition in the current partition table. If the boot communication partition change mark is true, the boot program firmware backup information is saved to the third preset position in the backup boot communication partition address space starting from the boot communication partition backup start address, and the boot communication partition backup information is constructed at the same time. The boot communication partition backup information is saved to the fourth preset position in the boot communication partition in the current partition table and the fourth preset position in the backup boot communication partition address space starting from the boot communication partition backup start address. The starting address of the boot program firmware partition in the current partition table is modified to the starting address of the boot program backup firmware in the boot program firmware backup information. If the boot communication partition change mark is true, the starting address of the boot communication partition in the current partition table is modified to the starting address of the boot communication partition backup partition in the boot communication partition backup information. The current partition table is upgraded to the address space where the main firmware partition table is located in the boot storage medium, and the current partition table is upgraded to the address space where the backup partition table is located in the boot storage medium.
[0031] In this way, by backing up the boot program firmware and the boot communication partition, and pointing the starting address of the boot program firmware partition in the current partition table to the address of the backup boot program firmware, and pointing the starting address of the boot communication partition in the current partition table to the address of the backed-up boot communication partition, and then upgrading the modified partition table to the address space where the main firmware partition table and the backup partition table are located, it is possible to support OTA upgrade of the firmware with partition table changes without the need for external storage, and ensure that any accidents at any time during the upgrade process will not cause the device to become bricked, and the device can continue to upgrade after powering on again, thereby improving the reliability of the upgrade.
[0032] In some embodiments, before step 102, the method 100 may also include: determining whether there is a preset upgrade completion mark at the fifth preset position of the boot communication partition; if so, deleting the upgraded firmware upgrade package, and clearing the preset upgrade completion mark at the fifth preset position of the boot communication partition; if not, determining whether there is a firmware upgrade package to be upgraded; if so, storing the firmware upgrade package to be upgraded to a preset path of a preset user data partition, and performing a legitimacy check on the firmware upgrade package to be upgraded; if the result of the legitimacy check is failure, exiting the firmware upgrade process; if the result of the legitimacy check is success, creating a new empty folder under the preset path of the preset user data partition; decompressing all files in the firmware upgrade package to be upgraded to the empty folder, and constructing firmware upgrade package information; writing the firmware upgrade package information in the second preset position of the boot communication partition; and writing the first preset upgrade instruction in the first preset position of the boot communication partition, and restarting the device.
[0033] In some embodiments, the firmware upgrade package information is read from the fifth preset position of the boot communication partition as the upgraded firmware upgrade package information, and the entire decompressed folder is deleted according to the partition name of the firmware upgrade package decompressed folder and the path of the firmware upgrade package decompressed folder in the upgraded firmware upgrade package information. The firmware upgrade is successful and the firmware upgrade package information is output. If the user receives the confirmation to delete the firmware upgrade package information, the upgraded firmware upgrade package is deleted according to the original path of the firmware upgrade package in the upgraded firmware upgrade package information. The preset upgrade completion mark of the fifth preset position of the boot communication partition is cleared.
[0034] In this way, the firmware upgrade package to be upgraded is stored in the preset path of the preset user data partition, and the address space of the preset user data partition is unchanged in the new partition table, ensuring that the firmware upgrade package will not be damaged, thereby improving the reliability of the firmware upgrade.
[0035] In some embodiments, before step 102, the method 100 may further include: reading the firmware upgrade package information in the second preset position of the boot communication partition and the main firmware partition table in the boot storage medium; if the main firmware partition table is legal, using the main firmware partition table as the current partition table; if the main firmware partition table is illegal, reading the backup partition table from the boot storage medium, and judging whether the backup partition table is legal, if so, using the backup partition table as the current partition table, if not, exiting the firmware upgrade process; judging whether the current partition table has a partition with the same name as the partition of the firmware upgrade package decompression folder in the firmware upgrade package information; if not, exiting the firmware upgrade process. upgrade process; if it exists, then according to the partition name of the firmware upgrade package decompression folder in the firmware upgrade package information, the partition where the firmware upgrade package decompression folder is located is mounted according to the file system specified by the partition file system type of the firmware upgrade package decompression folder in the firmware upgrade package information; if the result of the mounting is failure, the firmware upgrade process is exited; if the result of the mounting is success, all files under the path of the firmware upgrade package decompression folder are verified according to the firmware upgrade package decompression file verification information in the firmware upgrade package information; if the verification results of all the files are all passed, the firmware upgrade is performed; and if the verification results of all the files are not all passed, the firmware upgrade process is exited.
[0036] In this way, the files in the unzipped folder path of the firmware upgrade package can be accessed only after mounting, ensuring a smooth upgrade. The reliability of the firmware files to be upgraded is also ensured by verifying the files in the unzipped folder path, avoiding upgrading tampered or damaged firmware, thereby improving the reliability of firmware upgrades.
[0037] In some embodiments, after step 106, the method 100 may further include: clearing the boot program firmware backup information in the third preset position of the boot communication partition of the current partition table, the boot communication partition backup information in the fourth preset position, and the upgrade instruction information in the first preset position, and writing a preset upgrade completion mark in the fifth preset position of the boot communication partition of the current partition table; restarting the device to enter the upgraded system. In this way, each piece of information is cleared and a preset upgrade completion mark is written in the fifth preset position of the boot communication partition of the current partition table to prepare for the next upgrade.
[0038] Hereinafter, application scenarios of the method and device for upgrading firmware according to embodiments of the present invention will be described by way of examples.
[0039] Figure 2 1 is a flow chart showing a method for upgrading firmware according to an embodiment of the present invention. Figure 2 As shown, the method includes the following steps 201 to 220.
[0040] In some embodiments, the address space of the boot program firmware partition and the boot communication partition in the partition table is located before the address space of various system firmware partitions (such as super or system) and the preset user data partition (such as data partition); and the address space of the preset user data partition in the new and old partition tables cannot change, that is, the starting address and length of the preset user data partition cannot change; at the same time, the length of the boot communication partition in the new partition table cannot be less than the length of the boot communication partition in the old partition table.
[0041] In step 201, a firmware upgrade package including all firmware image files and partition table files with preset names is constructed.
[0042] The firmware image file uses the partition name corresponding to the image file as the prefix of the firmware image file name. For example, the prefix "uboot" of the firmware image file uboot.img is the uboot partition name, that is, the image file name corresponding to the uboot partition is uboot.img.
[0043] In step 202, it is determined whether there is a preset upgrade completion mark at the fifth preset position of the guide communication partition. If so, step 203 is executed; if not, step 204 is executed.
[0044] In step 203, the upgraded firmware upgrade package is deleted, and the preset upgrade completion mark at the fifth preset position of the boot communication partition is cleared, which specifically includes the following (1) to (4).
[0045] (1) Reading the firmware upgrade package information from the fifth preset position of the boot communication partition as the upgraded firmware upgrade package information, and deleting the entire decompressed folder according to the partition name of the firmware upgrade package decompressed folder and the path of the firmware upgrade package decompressed folder in the upgraded firmware upgrade package information.
[0046] (2) Output information on whether the firmware upgrade is successful and whether to delete the firmware upgrade package.
[0047] (3) If the firmware upgrade package deletion confirmation information sent by the user is received, the upgraded firmware upgrade package is deleted according to the original path of the firmware upgrade package in the upgraded firmware upgrade package information.
[0048] (4) Clear the preset upgrade completion flag of the fifth preset position of the boot communication partition.
[0049] In step 204 , it is determined whether there is a firmware upgrade package to be upgraded. If so, step 205 is executed.
[0050] In step 205, the firmware upgrade package to be upgraded is stored in a preset path of the preset user data partition (such as / data / ota / update.zip), and the firmware upgrade package to be upgraded is verified for legitimacy. If the result of the legitimacy verification is failure, the firmware upgrade process is exited. If the result of the legitimacy verification is success, step 206 is executed.
[0051] In step 206, a new empty folder (eg, / data / ota / update_files) is created under a preset path of the preset user data partition.
[0052] In step 207, all files in the firmware upgrade package to be upgraded are decompressed into an empty folder, and firmware upgrade package information is constructed.
[0053] The firmware upgrade package information includes the original path of the firmware upgrade package, the partition name of the folder where the firmware upgrade package is decompressed, the partition file system type of the folder where the firmware upgrade package is decompressed, the path of the folder where the firmware upgrade package is decompressed, and the verification information of the decompressed file of the firmware upgrade package. The verification information of the decompressed file of the firmware upgrade package includes the digital summary algorithm type and the verification unit list, and the verification unit consists of the file name and the digital summary value.
[0054] Constructing the firmware upgrade package information specifically includes the following (1) to (6).
[0055] (1) The path where the firmware upgrade package to be upgraded is located (such as / data / ota / update.zip) as the original path of the firmware upgrade package in the firmware upgrade package information.
[0056] (2) The name of the partition where the folder where the firmware upgrade package is decompressed is located (such as data) is used as the partition name of the folder where the firmware upgrade package is decompressed in the firmware upgrade package information.
[0057] (3) The file system type of the partition where the folder where the firmware upgrade package is decompressed is located (such as ext4) is used as the file system type of the partition where the folder where the firmware upgrade package is decompressed is located in the firmware upgrade package information.
[0058] (4) The path of the folder where the firmware upgrade package is decompressed in the corresponding partition is used as the path of the folder where the firmware upgrade package is decompressed in the firmware upgrade package information.
[0059] For example, when the decompressed folder of the firmware upgrade package is located in the ota / update_files path under the data partition, the decompressed folder path of the firmware upgrade package here is ota / update_files.
[0060] (5) Setting the digital digest algorithm type of the firmware upgrade package decompression file verification information in the firmware upgrade package information to a preset digital digest algorithm type.
[0061] (6) For each file in the folder path of the firmware upgrade package decompression, a corresponding digital summary value is calculated according to the digital summary algorithm type in the firmware upgrade package decompression file verification information, and the corresponding file name and the calculated digital summary value are saved to the corresponding verification unit in the verification unit list in the firmware upgrade package decompression file verification information in the firmware upgrade package information.
[0062] In step 208, the firmware upgrade package information is written into the second preset location of the boot communication partition.
[0063] In step 209, a first preset upgrade instruction is written into a first preset location of the boot communication partition, and the device is restarted.
[0064] In step 210, the firmware upgrade package information in the second preset location of the boot communication partition and the main firmware partition table in the boot storage medium are read.
[0065] In step 211, if the main firmware partition table is legal, the main firmware partition table is used as the current partition table.
[0066] In step 212, if the main firmware partition table is not legal, the backup partition table is read from the boot storage medium, and it is determined whether the backup partition table is legal. If so, the backup partition table is used as the current partition table. If not, the firmware upgrade process is exited.
[0067] In step 213, it is determined whether the current partition table has a partition with the same name as the partition in the folder where the firmware upgrade package is decompressed in the firmware upgrade package information. If not, the firmware upgrade process is exited. If so, step 214 is executed.
[0068] In step 214, according to the partition name of the decompressed folder of the firmware upgrade package in the firmware upgrade package information, the partition where the decompressed folder of the firmware upgrade package is located is mounted according to the file system specified by the partition file system type of the decompressed folder of the firmware upgrade package in the firmware upgrade package information. If the result of the mounting is failure, the firmware upgrade process is exited. If the result of the mounting is success, step 215 is executed.
[0069] In step 215, all files under the folder path of the firmware upgrade package decompression are verified according to the firmware upgrade package decompression file verification information in the firmware upgrade package information. If the verification results of all files are all passed, the firmware upgrade is performed and step 216 is executed. If the verification results of all files are not all passed, the firmware upgrade process is exited, which specifically includes the following (1) to (2).
[0070] (1) Obtaining the firmware upgrade package decompression file verification information in the firmware upgrade package information as the firmware upgrade package decompression file verification information.
[0071] (2) traverse each file under the path of the firmware upgrade package decompression folder in the firmware upgrade package information. For each file, search for the corresponding verification unit from the verification unit list in the verification information of the firmware upgrade package decompression file according to the corresponding file name, that is, search for the verification unit whose corresponding file name is the same as the file name of the verification unit from the verification unit list. If the corresponding verification unit is not found, exit the firmware upgrade process. If the corresponding verification unit is found, calculate the digital summary of the corresponding file according to the digital summary algorithm specified by the digital summary algorithm type in the verification information of the firmware upgrade package decompression file, and compare it with the digital summary value of the corresponding verification unit in the verification unit list in the verification information of the firmware upgrade package decompression file. If the comparison result is different, exit the firmware upgrade process. If the comparison result is the same, continue to verify other files under the path of the firmware upgrade package decompression folder. When all files to be verified are successfully verified, execute step 216.
[0072] In step 216, if the upgrade instruction information in the first preset location of the boot communication partition is the first preset upgrade instruction, the boot program firmware and the boot communication partition are backed up, and the second preset upgrade instruction is written into the first preset location.
[0073] Among them, backing up the boot program firmware and the boot communication partition specifically includes the following (1) to (3).
[0074] (1) Determine the backup completion mark based on the boot program firmware backup information, whether the address space of the boot communication partition has changed in the new partition table, and the boot communication partition backup information, specifically including the following (1-1) to (1-8).
[0075] (1-1) Read the boot program firmware backup information in the third preset position of the boot communication partition in the current partition table.
[0076] The boot program firmware backup information includes a backup information magic number, a start address of the boot program backup firmware, and a size of the boot program backup firmware.
[0077] (1-2) Determine whether the backup information magic number in the boot program firmware backup information is the same as the preset backup information magic number. If not, set the backup completion mark to false. If the same, execute (1-3).
[0078] (1-3) Determine whether the starting address of the boot program firmware partition in the current partition table is the same as the starting address of the boot program backup firmware in the boot program firmware backup information. If not, set the backup completion mark to false. If so, execute (1-4).
[0079] (1-4) Obtain the partition table file to be upgraded from the decompressed folder path of the firmware upgrade package in the firmware upgrade package as the new partition table, and compare whether the starting address and length of the boot communication partition in the current partition table and the new partition table are the same. If they are the same, set the boot communication partition change flag to false; if they are not the same, set the boot communication partition change flag to true.
[0080] (1-5) If the boot communication partition change flag is false, set the backup completion flag to true.
[0081] (1-6) If the boot communication partition change flag is true, determine whether the length of the boot communication partition in the new partition table is less than the length of the boot communication partition in the current partition table. If it is less, an error message is displayed and the firmware upgrade process is exited. If it is not less, execute (1-7).
[0082] (1-7) Read the boot communication partition backup information in the fourth preset position of the boot communication partition in the current partition table, and determine whether the backup information magic number in the boot communication partition backup information is the same as the preset backup information magic number. If not, set the backup completion mark to false. If so, execute (1-8).
[0083] The boot communication partition backup information includes a backup information magic number, a start address of the boot communication partition backup partition, and a size of the boot communication partition backup partition.
[0084] (1-8) Determine whether the starting address of the boot communication partition in the current partition table is the same as the starting address of the boot communication partition backup partition in the boot communication partition backup information. If they are the same, set the backup completion mark to true; if they are not the same, set the backup completion mark to false.
[0085] (2) If the backup completion flag is true, the bootloader firmware and boot communication partition are not backed up.
[0086] (3) If the backup completion mark is false, the boot program firmware and the boot communication partition are backed up, specifically including the following (3-1) to (3-11).
[0087] (3-1) Calculate the total length of the data to be backed up.
[0088] Specifically, if the boot communication partition change mark is false, the total length of the data to be backed up is set to the boot program firmware partition size in the current partition table. If the boot communication partition change mark is true, the total length of the data to be backed up is set to the boot program firmware partition size in the current partition table plus the boot communication partition size in the current partition table.
[0089] (3-2) Search for a firmware partition (such as a super partition or a boot partition) whose partition length is greater than the total length of the data to be backed up in the firmware partition after the boot program firmware partition and the boot communication partition in the new partition table as a backup partition, and obtain the starting address and size of the backup partition in the new partition table;
[0090] (3-3) According to the starting address and size of the boot program firmware partition in the current partition table, all the contents in the boot program firmware partition in the corresponding address space are copied to the address space starting from the starting address of the backup partition.
[0091] (3-4) If the boot communication partition change flag is true, the boot communication partition backup start address is set to the start address of the backup partition plus the size of the boot program firmware partition in the current partition table.
[0092] (3-5) According to the starting address and size of the boot communication partition in the current partition table, all the contents in the boot communication partition of the corresponding address space are copied to the address space starting from the boot communication partition backup starting address.
[0093] (3-6) Constructing boot program firmware backup information, and saving the boot program firmware backup information to a third preset location of the boot communication partition in the current partition table.
[0094] Among them, the boot program firmware backup information is constructed, specifically, the backup information magic number in the boot program firmware backup information is set to the preset backup information magic number, the starting address of the boot program backup firmware in the boot program firmware backup information is set to the starting address of the backup partition, and the size of the boot program backup firmware in the boot program firmware backup information is set to the size of the boot program firmware partition in the current partition table.
[0095] (3-7) If the boot communication partition change flag is true, the boot program firmware backup information is saved to a third preset position in the backup boot communication partition address space starting from the boot communication partition backup start address, and the boot communication partition backup information is constructed at the same time.
[0096] Among them, the boot communication partition backup information is constructed, specifically, the backup information magic number in the boot communication partition backup information is set to the preset backup information magic number, the starting address of the boot communication partition backup partition in the boot communication partition backup information is set to the boot communication partition backup starting address, and the size of the boot communication partition backup partition in the boot communication partition backup information is set to the size of the boot communication partition in the current partition table.
[0097] (3-8) The boot communication partition backup information is saved to a fourth preset position in the boot communication partition in the current partition table and a fourth preset position in the backup boot communication partition address space starting from the boot communication partition backup start address.
[0098] (3-9) Modify the starting address of the boot program firmware partition in the current partition table to the starting address of the boot program backup firmware in the boot program firmware backup information.
[0099] (3-10) If the boot communication partition change flag is true, the starting address of the boot communication partition in the current partition table is modified to the starting address of the boot communication partition backup partition in the boot communication partition backup information.
[0100] (3-11) The current partition table is upgraded to the address space where the main firmware partition table is located in the boot storage medium, and the current partition table is upgraded to the address space where the backup partition table is located in the boot storage medium.
[0101] In step 217, if the upgrade instruction information in the first preset position of the boot communication partition is the second preset upgrade instruction, the partition table and the boot program firmware are upgraded based on the firmware upgrade package information in the second preset position of the boot communication partition, and the third preset upgrade instruction is written into the first preset position, specifically including the following (1) to (6).
[0102] (1) Obtain the partition table file to be upgraded from the decompressed folder path of the firmware upgrade package in the firmware upgrade package information as a new partition table.
[0103] (2) Compare the starting address and length of the boot program firmware partition in the current partition table and the new partition table to see if they are the same. If they are the same, execute (3); if they are not the same, execute (4).
[0104] (3) Modify the starting address of the boot program firmware partition in the current partition table to the starting address of the boot program backup firmware in the boot program firmware backup information; if there is valid information in the boot communication partition backup information, modify the starting address of the boot communication partition in the current partition table to the starting address of the boot communication partition backup partition in the boot communication partition backup information, and upgrade the current partition table to the address space where the main firmware partition table in the boot storage medium is located, and upgrade the current partition table to the address space where the backup partition table in the boot storage medium is located, specifically including the following (3-1) to (3-3).
[0105] (3-1) Read the boot program firmware backup information in the third preset position of the boot communication partition in the current partition table, and check whether the backup information magic number in the boot program firmware backup information is the same as the preset backup information magic number. If they are different, an error message is prompted and the firmware upgrade process is exited. If they are the same, the starting address of the boot program firmware partition in the current partition table is modified to the starting address of the boot program backup firmware in the boot program firmware backup information.
[0106] (3-2) Read the boot communication partition backup information in the fourth preset position of the boot communication partition in the current partition table, and check whether the backup information magic number in the boot communication partition backup information is the same as the preset backup information magic number. If they are the same, modify the starting address of the boot communication partition in the current partition table to the starting address of the boot communication partition backup partition in the boot communication partition backup information. If they are different, prompt an error and exit the firmware upgrade process.
[0107] (3-3) The current partition table is upgraded to the address space where the main firmware partition table is located in the boot storage medium, and the current partition table is upgraded to the address space where the backup partition table is located in the boot storage medium.
[0108] (4) Obtain the boot program firmware image file to be upgraded from the folder path where the firmware upgrade package is decompressed, and upgrade the boot program firmware image file to be upgraded to the address space of the boot program firmware partition in the new partition table.
[0109] (5) If there is valid information in the boot communication partition backup information, all the data in the address space consisting of the starting address of the boot communication partition backup partition and the size of the boot communication partition backup partition in the boot communication partition backup information are copied to the address space of the boot communication partition in the new partition table.
[0110] (6) The new partition table is upgraded to the address space where the main firmware partition table is located in the boot storage medium, the new partition table is upgraded to the address space where the backup partition table is located in the boot storage medium, and the new partition table is used as the current partition table.
[0111] In step 218, if the upgrade instruction information in the first preset position of the boot communication partition is the third preset upgrade instruction, then other firmware except the boot program firmware is upgraded based on the firmware upgrade package information in the second preset position of the boot communication partition.
[0112] Specifically, other firmware image files except the bootstrap firmware image file are sequentially obtained from the firmware upgrade package decompression folder path in the firmware upgrade package information, and other firmware image files are respectively upgraded to the address space where the corresponding firmware partition is located in the new partition table.
[0113] In step 219, the boot program firmware backup information in the third preset position of the boot communication partition of the current partition table, the boot communication partition backup information in the fourth preset position, and the upgrade instruction information in the first preset position are cleared, and a preset upgrade completion mark is written in the fifth preset position of the boot communication partition of the current partition table.
[0114] In step 220, the device is restarted to enter the upgraded system.
[0115] According to yet another aspect of the present invention, Figure 3 is a schematic diagram showing an electronic device 300 according to an embodiment of the present invention. Figure 3 , the electronic device 300 includes a memory 302 and a processor 304. The memory 302 is configured to store a computer program that can be run on the processor 304. When the processor 304 executes the computer program, each step of the method for upgrading firmware as described above is implemented.
[0116] According to another aspect of the present invention, a computer readable medium is provided, wherein a computer program is stored on the computer readable medium, and the computer program is executed by a processor to implement the method for upgrading firmware as described above.
[0117] In summary, the method for upgrading firmware, the electronic device and the storage medium provided by the present invention back up the boot program firmware and the boot communication partition according to the upgrade instruction information corresponding to the first preset upgrade instruction in the first preset position of the boot communication partition, upgrade the partition table and the boot program firmware based on the firmware upgrade package information in the second preset position of the boot communication partition according to the upgrade instruction information corresponding to the second preset upgrade instruction, and upgrade other firmware based on the firmware upgrade package information in the second preset position of the boot communication partition according to the upgrade instruction information corresponding to the third preset upgrade instruction. By backing up the boot program firmware and the boot communication partition, it is possible to support OTA upgrade of firmware with changed partition tables without relying on external storage. In addition, even if an accident occurs during the upgrade, the backup boot program firmware can be used to continue the upgrade to avoid bricking the device, and there is no need to restart the process multiple times, thereby improving the efficiency and reliability of the firmware upgrade. In addition, the firmware upgrade package to be upgraded is stored in the preset path of the preset user data partition, and the address space of the preset user data partition is unchanged in the new partition table, ensuring that the firmware upgrade package will not be destroyed, thereby improving the reliability of the firmware upgrade. In addition, the entire upgrade process does not require multiple restarts, and when the device is accidentally powered on again for upgrading, it can continue upgrading from the last unfinished upgrade stage, improving the efficiency of firmware upgrades. At the same time, the data in the preset user data partition is not destroyed during the upgrade process, ensuring that the content in the user data partition remains unchanged after the upgrade.
[0118] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent transformations made using the contents of the present invention's specification and drawings, or directly or indirectly applied in related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A method for upgrading firmware, characterized in that: include: Backing up the boot program firmware and the boot communication partition according to the upgrade instruction information corresponding to the first preset upgrade instruction in the first preset position of the boot communication partition, and writing the second preset upgrade instruction into the first preset position; According to the upgrade instruction information corresponding to the second preset upgrade instruction in the first preset position of the boot communication partition, the partition table and the boot program firmware are upgraded based on the firmware upgrade package information in the second preset position of the boot communication partition, and a third preset upgrade instruction is written into the first preset position; as well as According to the upgrade instruction information corresponding to the third preset upgrade instruction in the first preset position of the boot communication partition, other firmware except the boot program firmware is upgraded based on the firmware upgrade package information in the second preset position of the boot communication partition.
2. The method according to claim 1, characterized in that Backing up the bootloader firmware and boot communication partitions includes: Backing up the boot program firmware to point the start address of the boot program firmware partition in the current partition table to the address where the backup boot program firmware is located; and When the boot communication partition in the new partition table changes, the boot communication partition is backed up synchronously to point the starting address of the boot communication partition in the current partition table to the address of the boot communication partition after the backup. The upgrading of the partition table includes: upgrading the modified partition table to the address space where the main firmware partition table and the backup partition table are located.
3. The method according to claim 1, characterized in that Also includes: Obtaining a firmware upgrade package to be upgraded, wherein the firmware upgrade package to be upgraded includes a firmware image file and a partition table file with a preset name; Decompress all files of the firmware upgrade package to be upgraded to a preset path of a preset user data partition; as well as The user data partition is mounted in the bootloader firmware.
4. The method according to claim 1, characterized in that: Backing up the bootloader firmware and boot communication partitions includes: Determine a backup completion mark according to the boot program firmware backup information, whether the address space of the boot communication partition has changed in the new partition table, and the boot communication partition backup information; If the backup completion flag is true, the boot program firmware and the boot communication partition are not backed up; and If the backup completion flag is false, the boot program firmware and the boot communication partition are backed up.
5. The method according to claim 4, characterized in that The backup completion flag is determined based on the boot program firmware backup information, whether the address space of the boot communication partition has changed in the new partition table, and the boot communication partition backup information, including: Reading boot program firmware backup information in a third preset position of the boot communication partition in the current partition table; Determine whether the backup information magic number in the boot program firmware backup information is the same as the preset backup information magic number; If they are not the same, set the backup completion flag to false; If they are the same, determining whether the starting address of the boot program firmware partition in the current partition table is the same as the starting address of the boot program backup firmware in the boot program firmware backup information; If not, set the backup completion flag to false; If yes, obtain the partition table file to be upgraded from the firmware upgrade package decompression folder path in the firmware upgrade package as the new partition table, and compare whether the starting address and length of the boot communication partition in the current partition table and the new partition table are the same; If they are the same, set the boot communication partition change flag to false; If they are not the same, then set the boot communication partition change flag to true; If the boot communication partition change flag is false, setting the backup completion flag to true; If the boot communication partition change flag is true, determining whether the length of the boot communication partition in the new partition table is less than the length of the boot communication partition in the current partition table; If it is less than that, an error message will be displayed and the firmware upgrade process will be exited; If it is not less than, reading the boot communication partition backup information in the fourth preset position of the boot communication partition in the current partition table, and determining whether the backup information magic number in the boot communication partition backup information is the same as the preset backup information magic number; If not, set the backup completion flag to false; If yes, determining whether the starting address of the boot communication partition in the current partition table is the same as the starting address of the boot communication partition backup partition in the boot communication partition backup information; If they are the same, set the backup complete flag to true; and If not the same, set the backup complete flag to false.
6. The method according to claim 4, characterized in that Backing up the bootloader firmware and boot communication partitions includes: Calculate the total length of data to be backed up; Searching for a firmware partition whose partition length is greater than the total length of the data to be backed up in the boot program firmware partition and the firmware partition after the boot communication partition in the new partition table as a backup partition, and obtaining the starting address and size of the backup partition in the new partition table; According to the starting address and size of the boot program firmware partition in the current partition table, copy all the contents of the boot program firmware partition in the corresponding address space to the address space starting from the starting address of the backup partition; If the boot communication partition change flag is true, then setting the boot communication partition backup start address to the start address of the backup partition plus the size of the boot program firmware partition in the current partition table; According to the starting address and size of the boot communication partition in the current partition table, copy all the contents in the boot communication partition of the corresponding address space to the address space starting from the backup starting address of the boot communication partition; Constructing boot program firmware backup information, and saving the boot program firmware backup information to a third preset position of the boot communication partition in the current partition table; If the boot communication partition change flag is true, the boot program firmware backup information is saved to a third preset position in the backup boot communication partition address space starting from the boot communication partition backup start address, and the boot communication partition backup information is constructed at the same time; Saving the boot communication partition backup information to a fourth preset position in the boot communication partition in the current partition table and a fourth preset position in the backup boot communication partition address space starting from the boot communication partition backup start address; Modify the starting address of the boot program firmware partition in the current partition table to the starting address of the boot program backup firmware in the boot program firmware backup information; If the boot communication partition change flag is true, modifying the starting address of the boot communication partition in the current partition table to the starting address of the boot communication partition backup partition in the boot communication partition backup information; and The current partition table is upgraded to the address space where the main firmware partition table is located in the boot storage medium, and the current partition table is upgraded to the address space where the backup partition table is located in the boot storage medium.
7. The method according to claim 1, characterized in that Also includes: Determining whether there is a preset upgrade completion mark at the fifth preset position of the guide communication partition; If it exists, deleting the upgraded firmware upgrade package, and clearing the preset upgrade completion mark at the fifth preset position of the boot communication partition; If not, determine whether there is a firmware upgrade package to be upgraded; If yes, the firmware upgrade package to be upgraded is stored in a preset path of a preset user data partition, and a validity check is performed on the firmware upgrade package to be upgraded; If the result of the legality check is failure, then exit the firmware upgrade process; If the result of the legality check is successful, creating a new empty folder under the preset path of the preset user data partition; Decompress all files in the firmware upgrade package to be upgraded into the empty folder, and construct firmware upgrade package information; Writing the firmware upgrade package information into a second preset location of the boot communication partition; as well as A first preset upgrade instruction is written into a first preset position of the boot communication partition, and the device is restarted.
8. The method according to claim 7, characterized in that Deleting the upgraded firmware upgrade package and clearing the preset upgrade completion mark at the fifth preset position of the boot communication partition includes: Reading firmware upgrade package information from a fifth preset position of the boot communication partition as upgraded firmware upgrade package information, and deleting the entire decompressed folder according to the partition name of the firmware upgrade package decompressed folder and the path of the firmware upgrade package decompressed folder in the upgraded firmware upgrade package information; Output the information of successful firmware upgrade and whether to delete the firmware upgrade package; If the firmware upgrade package deletion confirmation information sent by the user is received, deleting the upgraded firmware upgrade package according to the original path of the firmware upgrade package in the upgraded firmware upgrade package information; and The preset upgrade completion mark at the fifth preset position of the guide communication partition is cleared.
9. The method according to claim 7, characterized in that: Also includes: Reading the firmware upgrade package information in the second preset position of the boot communication partition and the main firmware partition table in the boot storage medium; If the main firmware partition table is legal, use the main firmware partition table as the current partition table; If the main firmware partition table is not legal, read the backup partition table from the boot storage medium, and determine whether the backup partition table is legal. If so, use the backup partition table as the current partition table. If not, exit the firmware upgrade process. Determine whether the current partition table has a partition with the same name as the partition of the folder where the firmware upgrade package is decompressed in the firmware upgrade package information; If it does not exist, exit the firmware upgrade process; If it exists, then according to the partition name of the decompressed folder of the firmware upgrade package in the firmware upgrade package information, the partition where the decompressed folder of the firmware upgrade package is located is mounted according to the file system specified by the partition file system type of the decompressed folder of the firmware upgrade package in the firmware upgrade package information; If the result of the mounting is failure, then exit the firmware upgrade process; If the result of the mounting is successful, all files under the folder path of the firmware upgrade package decompression are verified according to the firmware upgrade package decompression file verification information in the firmware upgrade package information; If the verification results of all the files are all passed, then the firmware is upgraded; and If the verification results of all the files are not all passed, the firmware upgrade process is exited.
10. The method according to claim 1, characterized in that Upgrading the partition table and the boot program firmware based on the firmware upgrade package information in the second preset position of the boot communication partition includes: Obtaining a partition table file to be upgraded from the firmware upgrade package decompression folder path in the firmware upgrade package information as a new partition table; Compare the start address and length of the boot program firmware partition in the current partition table and the new partition table to see if they are the same; If they are the same, modifying the starting address of the boot program firmware partition in the current partition table to the starting address of the boot program backup firmware in the boot program firmware backup information; If there is valid information in the boot communication partition backup information, modify the starting address of the boot communication partition in the current partition table to the starting address of the boot communication partition backup partition in the boot communication partition backup information, and upgrade the current partition table to the address space where the main firmware partition table in the boot storage medium is located, and upgrade the current partition table to the address space where the backup partition table in the boot storage medium is located; Obtaining a boot program firmware image file to be upgraded from the decompressed folder path of the firmware upgrade package, and upgrading the boot program firmware image file to be upgraded to the address space of the boot program firmware partition in the new partition table; If there is valid information in the boot communication partition backup information, all data of the address space composed of the starting address of the boot communication partition backup partition and the size of the boot communication partition backup partition in the boot communication partition backup information are copied to the address space of the boot communication partition in the new partition table; and The new partition table is upgraded to the address space where the main firmware partition table is located in the boot storage medium, the new partition table is upgraded to the address space where the backup partition table is located in the boot storage medium, and the new partition table is used as the current partition table.
11. The method according to claim 1, characterized in that: Upgrading other firmware except the boot program firmware based on the firmware upgrade package information in the second preset position of the boot communication partition includes: The other firmware image files except the boot program firmware image file are sequentially obtained from the firmware upgrade package decompression folder path in the firmware upgrade package information, and the other firmware image files are respectively upgraded to the address space where the corresponding firmware partition is located in the new partition table.
12. The method according to claim 1, characterized in that After upgrading other firmware except the boot program firmware based on the firmware upgrade package information in the second preset position of the boot communication partition, the method further includes: Clear the boot program firmware backup information in the third preset position of the boot communication partition of the current partition table, the boot communication partition backup information in the fourth preset position, and the upgrade instruction information in the first preset position, and write a preset upgrade completion mark in the fifth preset position of the boot communication partition of the current partition table; Restart the device to enter the upgraded system.
13. An electronic device, characterized in that: include: a memory configured to store an executable program; as well as A processor configured to execute the program to perform the method according to any one of claims 1 to 12.
14. A computer readable medium having a computer program stored thereon, characterized in that: The computer program is executed to implement the method according to any one of claims 1 to 12.
Citation Information
Patent Citations
Firmware upgrading method and storage device
CN113791811A
Method for upgrading non-system firmware, electronic equipment and storage medium
CN115904438A
Data presetting method, electronic equipment and computer readable storage medium
CN116578307A
Firmware upgrading method, electronic equipment and storage medium
CN116974617A
Firmware upgrading method, electronic equipment and storage medium
CN117369847A
Cited By
Firmware upgrading method and electronic equipment
CN120950101A
Method for upgrading firmware, electronic device
CN120950101B
Equipment upgrading method, equipment upgrading device and computer storage medium
CN121233147A
