Method, electronic device and storage medium for upgrading firmware

By backing up the bootloader firmware and boot communication partition, and using the upgrade instruction information of the boot communication partition to perform OTA upgrades based on partition table changes, the problems of relying on external storage and multiple reboots in existing technologies are solved, achieving efficient and reliable firmware upgrades.

CN118567680BActive Publication Date: 2026-04-14FUZHOU ROCKCHIP SEMICON
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-31
Publication Date
2026-04-14

AI Technical Summary

Technical Problem

Existing OTA upgrade solutions require external storage when the partition table changes, and are prone to device failure due to power outages, resulting in the erasure of user data partition contents and the need for multiple restarts.

Method used

By backing up the bootloader firmware and boot communication partition, and using the upgrade instruction information in the preset location of the boot communication partition for upgrades, OTA upgrades with changes in the partition table are supported, avoiding reliance on external storage and multiple reboots.

Benefits of technology

It improves the efficiency and reliability of firmware upgrades, ensuring that devices do not become bricked and user data is not lost during the upgrade process, and eliminating the need for multiple reboots.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118567680B_ABST
    Figure CN118567680B_ABST
Patent Text Reader

Abstract

The present application relates to a method for upgrading firmware, an electronic device and a storage medium. The method comprises: 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 starting boot program firmware and 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, upgrading the partition table and the starting 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 into the first preset position; according to the upgrade instruction information corresponding to the third preset upgrade instruction, upgrading other firmware based on the firmware upgrade package information in the second preset position of the boot communication partition. In the event of an accident during the upgrade, the starting boot program firmware can be used to continue the upgrade, and multiple restart processes are not required, thereby improving the efficiency and reliability of the firmware upgrade.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of embedded device technology, and in particular to methods for upgrading firmware, electronic devices, and storage media. Background Technology

[0002] When upgrading firmware via Over-The-Air (OTA), it is generally required that the firmware partition table remain unchanged before and after the upgrade. However, in some scenarios, due to an unreasonable initial partition table design, it is necessary to make certain changes to the firmware partition table. In this case, there is a need for a way to upgrade the firmware with the changed partition table to the device via OTA even when the device partition table has changed.

[0003] Existing firmware upgrade solutions that support OTA upgrades that change the partition table typically suffer from one or more of the following problems: The upgrade process relies on external storage (such as an SD card or USB flash drive). If an unexpected event occurs during the upgrade process (such as a power outage), the device may become unusable, unable to boot normally and continue the upgrade. The user data partition, which contains read / write access and saves user data, is reformatted, and its contents are erased after the upgrade. Multiple reboots are required during the upgrade process. Summary of the Invention

[0004] This invention provides a method for upgrading firmware, an electronic device, and a storage medium that can improve the efficiency and reliability of firmware upgrades.

[0005] In one aspect of the present invention, a method for upgrading firmware is provided. The method includes: backing up a bootloader firmware and a boot communication partition based on upgrade instruction information corresponding to a first preset upgrade instruction in a first preset location of the boot communication partition, and writing a second preset upgrade instruction into the first preset location; upgrading a partition table and the bootloader firmware based on firmware upgrade package information in a second preset location of the boot communication partition, based on the upgrade instruction information corresponding to the second preset upgrade instruction in the first preset location of the boot communication partition, and writing a third preset upgrade instruction into the first preset location; and upgrading other firmware besides the bootloader firmware based on the firmware upgrade package information in the second preset location of the boot communication partition, based on the upgrade instruction information corresponding to the third preset upgrade instruction in the first preset location of the boot communication partition.

[0006] In another aspect of the invention, an electronic device is provided. The electronic device includes a memory configured to store an executable program; and a processor configured to execute the program to perform the aforementioned method for upgrading firmware.

[0007] In another aspect of the invention, a computer-readable medium is provided. This medium stores a computer program that is executed by a processor to implement the aforementioned method for upgrading firmware.

[0008] According to the present invention, the bootloader firmware and the boot communication partition are backed up based on the upgrade instruction information corresponding to the first preset upgrade instruction in the first preset position of the boot communication partition. Based on the upgrade instruction information corresponding to the second preset upgrade instruction, the partition table and the bootloader firmware are upgraded using the firmware upgrade package information in the second preset position of the boot communication partition. Furthermore, based on the upgrade instruction information corresponding to the third preset upgrade instruction, other firmware is upgraded using the firmware upgrade package information in the second preset position of the boot communication partition. By backing up the bootloader firmware and the boot communication partition, OTA upgrades of firmware with changed partition tables can be supported without relying on external storage. Moreover, even if an accident occurs during the upgrade, the backed-up bootloader firmware can be used to continue the upgrade, preventing the device from becoming unusable and eliminating the need for multiple reboots, thereby improving the efficiency and reliability of firmware upgrades. Attached Figure Description

[0009] Figure 1 This is a flowchart illustrating the steps of a firmware upgrade method according to an embodiment of the present invention.

[0010] Figure 2 This is a flowchart illustrating a method for upgrading firmware according to an embodiment of the present invention;

[0011] Figure 3 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. Detailed Implementation

[0012] To explain in detail the technical content, objectives, and effects of the present invention, the following description is provided in conjunction with the embodiments and accompanying drawings.

[0013] Existing firmware upgrade solutions that support OTA (Over-The-Air) partition table changes typically suffer from one or more problems. For example, the upgrade process relies on external storage (such as an SD card or USB flash drive). If an unexpected event occurs during the upgrade process (such as a power outage), the device may become unusable, unable to boot normally and continue the upgrade. The user data partition, which contains read / write access and stores user data, may be reformatted, and its contents erased after the upgrade. Multiple reboots may be required during the upgrade process.

[0014] To address at least the aforementioned technical problems, this disclosure provides a method for upgrading firmware. According to embodiments of this disclosure, the bootloader firmware and the boot communication partition are backed up based on upgrade instruction information corresponding to a first preset upgrade instruction in a first preset location of the boot communication partition. Based on upgrade instruction information corresponding to a second preset upgrade instruction, the partition table and the bootloader firmware are upgraded using firmware upgrade package information in the second preset location of the boot communication partition. Furthermore, based on upgrade instruction information corresponding to a third preset upgrade instruction, other firmware is upgraded using firmware upgrade package information in the second preset location of the boot communication partition. In this manner, by backing up the bootloader firmware and the boot communication partition, OTA upgrades of firmware with changed partition tables can be supported without relying on external storage. Moreover, even if unexpected events occur during the upgrade, the backed-up bootloader firmware can be used to continue the upgrade, preventing device bricking and eliminating the need for multiple reboots, thereby improving the efficiency and reliability of firmware upgrades.

[0015] In the following, the technical solutions according to this disclosure will be described with reference to specific embodiments and in conjunction with the accompanying drawings.

[0016] Figure 1 This is a flowchart illustrating a method 100 for upgrading firmware according to an embodiment of the present disclosure. (Refer to...) Figure 1 The method 100 includes the following steps 102 to 106.

[0017] In step 102, based on the upgrade instruction information corresponding to the first preset upgrade instruction in the first preset location of the boot communication partition, the bootloader firmware and the boot communication partition are backed up, and the second preset upgrade instruction is written to the first preset location. In this way, the backup operation of the bootloader firmware and the boot communication partition is completed by determining whether a first preset upgrade instruction exists.

[0018] In some embodiments, the bootloader firmware is backed up so that the starting address of the bootloader firmware partition in the current partition table points to the address where the backed-up bootloader firmware is located. When the boot communication partition in the new partition table changes, the boot communication partition is backed up synchronously so that the starting address of the boot communication partition in the current partition table points to the address where the backed-up boot communication partition is located.

[0019] In this way, if an accident (such as a power outage) occurs during the upgrade of the bootloader firmware itself, the backup bootloader firmware will not be damaged. After power is restored, the bootloader firmware can continue to be booted from the backup bootloader firmware partition to continue the upgrade, thereby improving the efficiency and reliability of firmware upgrades.

[0020] In step 104, based on 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 bootloader firmware are upgraded according to 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 reside.

[0022] In some embodiments, the partition table file to be upgraded is obtained from the unzipped folder path of the firmware upgrade package information as a new partition table. The starting address and length of the bootloader firmware 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 starting address of the bootloader firmware partition in the current partition table is modified to the starting address of the bootloader backup firmware in the bootloader firmware backup information. If valid information exists in the boot communication partition backup information, 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, 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. The bootloader firmware image file to be upgraded is obtained from the unzipped folder path of the firmware upgrade package, and the bootloader firmware image file to be upgraded is upgraded to the address space of the bootloader firmware partition in the new partition table. If valid information exists in the boot communication partition backup information, then all data in the address space consisting of the starting address and size of the boot communication partition backup partition in the boot communication partition backup information is copied to the address space of the boot communication partition in the new partition table. Furthermore, the new partition table is upgraded to the address space of the main firmware partition table in the boot storage medium, and the new partition table is upgraded to the address space of the backup partition table in the boot storage medium, and then used as the current partition table.

[0023] In this way, the entire upgrade process does not require multiple restarts, and if the device is unexpectedly powered on and upgraded again, it can continue the upgrade from the previous unfinished stage, improving the efficiency of firmware upgrades. At the same time, the upgrade process does not destroy the data in the preset user data partition, ensuring that the content in the user data partition remains unchanged after the upgrade.

[0024] In step 106, based on the upgrade instruction information corresponding to the third preset upgrade instruction in the first preset position of the boot communication partition, the firmware other than the bootloader 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, excluding the bootloader 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 upgraded to the address space of the corresponding firmware partition in the new partition table.

[0026] In this way, after upgrading the partition table and bootloader firmware, other firmware can be upgraded, thus successfully completing the firmware upgrade.

[0027] In some embodiments, prior to step 102, the method 100 may further include: obtaining a firmware upgrade package to be upgraded, the firmware upgrade package to be upgraded including 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 bootloader firmware.

[0028] In some embodiments, a backup completion flag is determined based on the bootloader 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 bootloader firmware and boot communication partition are not backed up. If the backup completion flag is false, the bootloader firmware and boot communication partition are backed up. In this way, by determining the backup completion flag based on the bootloader 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, and considering that any node in the backup process may experience unexpected power loss, multiple factors are combined to ensure that the backup is truly completed, thereby ensuring the reliability of the upgrade.

[0029] In some embodiments, the bootloader 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 magic number of the backup information in the bootloader firmware backup information is the same as a preset magic number of the backup information. If they are different, the backup completion flag is set to false. If they are the same, it is determined whether the starting address of the bootloader firmware partition in the current partition table is the same as the starting address of the bootloader backup firmware in the bootloader firmware backup information. If not, the backup completion flag is set to false. If yes, the partition table file to be upgraded is obtained from the unzipped folder path of the firmware upgrade package 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 flag is set to false. If they are not the same, the boot communication partition change flag is set to true. If the boot communication partition change flag is false, the backup completion flag is set to true. If the boot communication partition change flag 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 the value is less than the preset value, an error message is displayed, and the firmware upgrade process is exited. If the value is not less than the preset value, the backup information of the boot communication partition in the fourth preset position of the boot communication partition in the current partition table is read, and it is determined whether the magic number of the backup information in the boot communication partition backup information is the same as the preset magic number of the backup information. If not, the backup completion flag is set to false. If yes, 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 flag is set to true. If they are not the same, the backup completion flag is set to false. In this way, the backup completion flag can be used to intuitively determine whether the backup operation of the boot program firmware and the boot communication partition is complete.

[0030] In some embodiments, the total length of the data to be backed up is calculated. Among the firmware partitions following the bootloader firmware partition and the boot communication partition in the new partition table, a firmware partition with a length greater than the total length of the data to be backed up is selected as the backup partition. Simultaneously, the starting address and size of the backup partition in the new partition table are obtained. Based on the starting address and size of the bootloader firmware partition in the current partition table, all contents of the bootloader firmware partition in the corresponding address space are copied to the address space starting at the starting address of the backup partition. If the boot communication partition change flag is true, the boot communication partition backup starting address is set to the starting address of the backup partition plus the size of the bootloader firmware partition in the current partition table. Based on the starting address and size of the boot communication partition in the current partition table, all contents of the boot communication partition in the corresponding address space are copied to the address space starting at the backup starting address of the boot communication partition. Bootloader firmware backup information is constructed and saved to the third preset position of the boot communication partition in the current partition table. If the boot communication partition change flag is true, the bootloader 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 simultaneously. The boot communication partition backup information is saved to the fourth preset position in the boot communication partition of 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 start address of the bootloader firmware partition in the current partition table is modified to the start address of the bootloader backup firmware in the bootloader firmware backup information. If the boot communication partition change flag is true, the start address of the boot communication partition in the current partition table is modified to the start 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 also 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 bootloader firmware and boot communication partition, and pointing the starting address of the bootloader firmware partition in the current partition table to the address of the backed-up bootloader 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, the modified partition table is then upgraded to the address space of the main firmware partition table and the backup partition table. This method can support OTA upgrades of firmware with partition table changes without the need for external storage, and ensures that no unexpected event occurs during the upgrade process, preventing the device from becoming unusable. The device can continue upgrading after power-on, thereby improving the reliability of the upgrade.

[0032] In some embodiments, before step 102, the method 100 may further include: determining whether a preset upgrade completion marker exists in the fifth preset location of the boot communication partition; if it exists, deleting the upgraded firmware upgrade package and clearing the preset upgrade completion marker in the fifth preset location of the boot communication partition; if it does not exist, determining whether a firmware upgrade package to be upgraded exists; if it does, storing the firmware upgrade package to be upgraded in a preset path of the preset user data partition and performing a validity check on the firmware upgrade package to be upgraded; if the validity check fails, exiting the firmware upgrade process; if the validity check succeeds, creating a new empty folder in the preset path of the preset user data partition; decompressing all files in the firmware upgrade package to be upgraded into the empty folder and constructing firmware upgrade package information; writing the firmware upgrade package information in the second preset location of the boot communication partition; and writing a first preset upgrade instruction in the first preset location of the boot communication partition and restarting the device.

[0033] In some embodiments, firmware upgrade package information is read from the fifth preset location of the boot communication partition as upgraded firmware upgrade package information, and the entire decompressed folder is deleted according to the partition name and path of the firmware upgrade package decompressed folder in the upgraded firmware upgrade package information. A message indicating successful firmware upgrade and whether the firmware upgrade package has been deleted is output. If a confirmation to delete the firmware upgrade package is received from the user, 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 marker at the fifth preset location of the boot communication partition is cleared.

[0034] In this way, the firmware upgrade package to be upgraded is stored in a preset path of the preset user data partition. The address space of the preset user data partition remains unchanged in the new partition table, ensuring that the firmware upgrade package will not be corrupted, thereby improving the reliability of firmware upgrades.

[0035] In some embodiments, before step 102, the method 100 may further include: reading 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; if the main firmware partition table is valid, then using the main firmware partition table as the current partition table; if the main firmware partition table is invalid, then reading the backup partition table from the boot storage medium and determining whether the backup partition table is valid; if it is valid, then using the backup partition table as the current partition table; if not, then exiting the firmware upgrade process; determining whether the current partition table has a partition with the same partition name as the firmware upgrade package decompression folder partition in the firmware upgrade package information; if it does not exist, then exiting the firmware upgrade process. Upgrade process: If it exists, then according to the partition name of the unzipped folder of the firmware upgrade package in the firmware upgrade package information, mount the partition where the unzipped folder of the firmware upgrade package is located according to the file system type specified by the file system type of the unzipped folder of the firmware upgrade package information; if the mounting result fails, then exit the firmware upgrade process; if the mounting result is successful, then verify all files under the path of the unzipped folder of the firmware upgrade package according to the verification information of the unzipped folder of the firmware upgrade package in the firmware upgrade package information; if the verification result of all files is all passed, then proceed with the firmware upgrade; and if the verification result of all files is not all passed, then exit the firmware upgrade process.

[0036] In this way, files in the unzipped folder of the firmware upgrade package can only be accessed after mounting, ensuring a smooth upgrade. The files in the unzipped folder are also verified to ensure the reliability of the firmware file to be upgraded, preventing the upgrade of tampered or corrupted firmware, thereby improving the reliability of firmware upgrades.

[0037] In some embodiments, after step 106, the method 100 may further include: clearing the bootloader firmware backup information in the third preset location, the boot communication partition backup information in the fourth preset location, and the upgrade instruction information in the first preset location of the boot communication partition of the current partition table; simultaneously writing a preset upgrade completion flag in the fifth preset location of the boot communication partition of the current partition table; and restarting the device to enter the upgraded system. In this way, various information is cleared while a preset upgrade completion flag is written in the fifth preset location of the boot communication partition of the current partition table, preparing for the next upgrade.

[0038] The following will describe, through examples, the application scenarios of the firmware upgrade method and device according to embodiments of the present invention.

[0039] Figure 2 This is a flowchart illustrating a method for upgrading firmware according to an embodiment of the present invention. Figure 2 As shown, the method includes steps 201 to 220.

[0040] In some embodiments, the address spaces of the bootloader firmware partition and the boot communication partition in the partition table are located before the address spaces of various system firmware partitions (such as super or system) and preset user data partitions (such as data partitions); 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 is constructed, which includes all firmware image files and a partition table file with preset names.

[0042] In this context, the firmware image file uses the partition name corresponding to the image file as a prefix to its name. For example, the prefix "uboot" in the firmware image file uboot.img is the uboot partition name, meaning the image file name corresponding to the uboot partition is uboot.img.

[0043] In step 202, determine whether there is a preset upgrade completion mark in the fifth preset position of the boot communication partition. If there is, proceed to step 203; otherwise, proceed to step 204.

[0044] In step 203, the upgraded firmware upgrade package is deleted and the preset upgrade completion mark in the fifth preset position of the boot communication partition is cleared, specifically including the following (1) to (4).

[0045] (1) Read the firmware upgrade package information from the fifth preset position of the boot communication partition as the upgraded firmware upgrade package information, and delete the entire decompressed folder according to the firmware upgrade package decompressed folder partition name and firmware upgrade package decompressed folder path in the upgraded firmware upgrade package information.

[0046] (2) Output information indicating whether the firmware upgrade was successful and whether the firmware upgrade package was deleted.

[0047] (3) If the user sends a confirmation message to delete the firmware upgrade package, then delete the upgraded firmware upgrade package according to the original path of the firmware upgrade package in the upgraded firmware upgrade package information.

[0048] (4) Clear the preset upgrade completion mark in the fifth preset position of the boot communication partition.

[0049] In step 204, determine whether there is a firmware upgrade package to be upgraded. If so, proceed to step 205.

[0050] In step 205, the firmware upgrade package to be upgraded is stored in the preset path of the preset user data partition (such as / data / ota / update.zip), and the validity of the firmware upgrade package to be upgraded is verified. If the validity verification result is unsuccessful, the firmware upgrade process is exited. If the validity verification result is successful, step 206 is executed.

[0051] In step 206, create a new empty folder (e.g., / data / ota / update_files) under the preset path of the preset user data partition.

[0052] In step 207, all files in the firmware upgrade package to be upgraded are extracted to an empty folder, and the 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 extracted folder, the file system type of the extracted folder, the path of the extracted folder, and verification information for the extracted files. The verification information includes the digital digest algorithm type and a list of verification units, where each verification unit consists of a filename and a digital digest value.

[0054] The firmware upgrade package information is constructed, specifically including the following (1) to (6).

[0055] (1) Use the path of the firmware upgrade package to be upgraded (e.g., / data / ota / update.zip) as the original path of the firmware upgrade package in the firmware upgrade package information.

[0056] (2) Use the name of the partition where the firmware upgrade package is extracted (e.g., data) as the partition name of the firmware upgrade package extraction folder in the firmware upgrade package information.

[0057] (3) Use the file system type (e.g., ext4) of the partition where the firmware upgrade package decompression folder is located as the file system type of the firmware upgrade package decompression folder partition in the firmware upgrade package information.

[0058] (4) Use the path of the firmware upgrade package unzipped folder in the corresponding partition as the firmware upgrade package unzipped folder path in the firmware upgrade package information.

[0059] For example, when the firmware upgrade package decompression folder is located at the path ota / update_files under the data partition, the firmware upgrade package decompression folder path here is ota / update_files.

[0060] (5) Set the digital digest algorithm type of the firmware upgrade package decompression file verification information in the firmware upgrade package information to the preset digital digest algorithm type.

[0061] (6) Calculate the corresponding digital digest value for each file in the firmware upgrade package decompression folder path according to the digital digest algorithm type in the firmware upgrade package decompression file verification information, and save the corresponding file name and the calculated digital digest value 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, firmware upgrade package information is written to the second preset location of the boot communication partition.

[0063] In step 209, a first preset upgrade instruction is written to the first preset location of the boot communication partition, and the device is restarted.

[0064] In step 210, read 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.

[0065] In step 211, if the main firmware partition table is valid, then the main firmware partition table is used as the current partition table.

[0066] In step 212, if the main firmware partition table is invalid, the backup partition table is read from the boot storage medium, and it is determined whether the backup partition table is valid. If it is valid, the backup partition table is used as the current partition table; otherwise, the firmware upgrade process is exited.

[0067] In step 213, determine whether there is a partition in the current partition table with the same partition name as the firmware upgrade package decompression folder in the firmware upgrade package information. If it does not exist, exit the firmware upgrade process. If it exists, proceed to step 214.

[0068] In step 214, according to the partition name of the unzipped folder of the firmware upgrade package in the firmware upgrade package information, the partition where the unzipped folder of the firmware upgrade package is located is mounted according to the file system type specified by the file system type of the unzipped folder of the firmware upgrade package in the firmware upgrade package information. If the mounting result fails, the firmware upgrade process is exited. If the mounting result is successful, step 215 is executed.

[0069] In step 215, all files under the firmware upgrade package decompression folder path are verified according to the firmware upgrade package decompression file verification information in the firmware upgrade package information. If the verification result of all files is all passed, then the firmware upgrade is performed and step 216 is executed. If the verification result of all files is not all passed, then the firmware upgrade process is exited, specifically including the following (1) to (2).

[0070] (1) Obtain the firmware upgrade package decompression file verification information from the firmware upgrade package information as the firmware upgrade package decompression file verification information.

[0071] (2) Traverse each file in the firmware upgrade package unzipped folder path in the firmware upgrade package information. For each file, search for the corresponding verification unit in the verification unit list in the firmware upgrade package unzipped file verification information according to the corresponding file name. That is, search for the verification unit whose file name is the same as the file name of the verification unit in the verification unit list. If no corresponding verification unit is found, exit the firmware upgrade process. If a corresponding verification unit is found, calculate the digital digest of the corresponding file according to the digital digest algorithm type specified in the firmware upgrade package unzipped file verification information, and compare it with the digital digest value of the corresponding verification unit in the verification unit list in the firmware upgrade package unzipped file verification information. If the comparison result is different, exit the firmware upgrade process. If the comparison result is the same, continue to verify other files in the firmware upgrade package unzipped folder path. 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, then the boot program firmware and the boot communication partition are backed up, and the second preset upgrade instruction is written to the first preset location.

[0073] Among them, the bootloader firmware and boot communication partition are backed up, specifically including the following (1) to (3).

[0074] (1) Determine the backup completion mark based on the bootloader 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 loader firmware backup information in the third preset location of the boot communication partition in the current partition table.

[0076] The bootloader firmware backup information includes the backup information magic number, the starting address of the bootloader backup firmware, and the size of the bootloader backup firmware.

[0077] (1-2) Determine whether the magic number of the backup information in the bootloader firmware backup information is the same as the preset magic number of the backup information. If they are different, set the backup completion mark to false. If they are the same, execute (1-3).

[0078] (1-3) Determine whether the starting address of the bootloader firmware partition in the current partition table is the same as the starting address of the bootloader backup firmware in the bootloader firmware backup information. If not, set the backup completion flag to false. If yes, execute (1-4).

[0079] (1-4) Obtain the partition table file to be upgraded from the unzipped 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, then set the backup completion flag to true.

[0081] (1-6) If the boot communication partition change flag is true, then 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, then prompt an error and exit the firmware upgrade process. If it is not less, then execute (1-7).

[0082] (1-7) Read the backup information of the boot communication partition in the fourth preset position of the boot communication partition in the current partition table, and determine whether the magic number of the backup information in the backup information is the same as the preset magic number of the backup information. If not, set the backup completion mark to false. If yes, execute (1-8).

[0083] The boot communication partition backup information includes the backup information magic number, the starting address of the boot communication partition backup partition, and the 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 flag to true. If they are not the same, set the backup completion flag to false.

[0085] (2) If the backup completion mark is true, the bootloader firmware and boot communication partition will not be backed up.

[0086] (3) If the backup completion is marked as false, the bootloader firmware and 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 flag is false, the total length of the data to be backed up is set to the size of the boot loader firmware partition in the current partition table; if the boot communication partition change flag is true, the total length of the data to be backed up is set to the size of the boot loader firmware partition in the current partition table plus the size of the boot communication partition in the current partition table.

[0089] (3-2) In the new partition table, find the firmware partition whose partition length is greater than the total length of the data to be backed up (such as the super partition or boot partition) in the firmware partition after the boot loader firmware partition and the boot communication partition, and use it as the backup partition. At the same time, obtain the starting address and size of the backup partition in the new partition table.

[0090] (3-3) Based on the starting address and size of the bootloader firmware partition in the current partition table, copy all the contents of the bootloader firmware partition in the corresponding address space 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, then set the boot communication partition backup start address to the start address of the backup partition plus the size of the boot loader firmware partition in the current partition table.

[0092] (3-5) Based on the starting address and size of the boot communication partition in the current partition table, copy all the contents of the boot communication partition in the corresponding address space to the address space starting from the backup starting address of the boot communication partition.

[0093] (3-6) Construct bootloader firmware backup information and save the bootloader firmware backup information to the third preset location of the boot communication partition in the current partition table.

[0094] Specifically, the process of constructing bootloader firmware backup information involves setting the magic number of backup information in the bootloader firmware backup information to a preset magic number, setting the starting address of the bootloader backup firmware in the bootloader firmware backup information to the starting address of the backup partition, and setting the size of the bootloader backup firmware in the bootloader firmware backup information to the size of the bootloader 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 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.

[0096] Specifically, the process of constructing the boot communication partition backup information involves setting the backup information magic number in the boot communication partition backup information to a preset backup information magic number, setting the starting address of the boot communication partition backup partition in the boot communication partition backup information to the boot communication partition backup starting address, and setting the size of the boot communication partition backup partition in the boot communication partition backup information to the size of the boot communication partition in the current partition table.

[0097] (3-8) Save the backup information of the boot communication partition 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 backup start address of the boot communication partition.

[0098] (3-9) Modify the starting address of the bootloader firmware partition in the current partition table to the starting address of the bootloader backup firmware in the bootloader firmware backup information.

[0099] (3-10) If the boot communication partition change flag is true, then 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.

[0100] (3-11) 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.

[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, then 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 path of the unzipped folder of the firmware upgrade package in the firmware upgrade package information as the new partition table.

[0103] (2) Compare the starting address and length of the boot 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 bootloader firmware partition in the current partition table to the starting address of the bootloader backup firmware in the bootloader 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, specifically including the following (3-1) to (3-3).

[0105] (3-1) Read the bootloader firmware backup information in the third preset position of the boot communication partition in the current partition table, and check whether the magic number of the backup information in the bootloader firmware backup information is the same as the preset magic number of the backup information. If they are different, an error message is displayed and the firmware upgrade process is exited. If they are the same, the starting address of the bootloader firmware partition in the current partition table is modified to the starting address of the bootloader backup firmware in the bootloader firmware backup information.

[0106] (3-2) Read the backup information of the boot communication partition in the fourth preset position of the boot communication partition in the current partition table, and check whether the magic number of the backup information in the backup information is the same as the preset magic number of the backup information. 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 in the backup information. If they are different, prompt an error and exit the firmware upgrade process.

[0107] (3-3) 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.

[0108] (4) Obtain the bootloader firmware image file to be upgraded from the unzipped folder path of the firmware upgrade package, and upgrade the bootloader firmware image file to be upgraded to the address space of the bootloader firmware partition in the new partition table.

[0109] (5) If there is valid information in the boot communication partition backup information, then copy 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 to the address space of the boot communication partition in the new partition table.

[0110] (6) Upgrade the new partition table to the address space where the main firmware partition table is located in the boot storage medium, upgrade the new partition table to the address space where the backup partition table is located in the boot storage medium, and use the new partition table as the current partition table.

[0111] In step 218, if the upgrade instruction information in the first preset location of the boot communication partition is the third preset upgrade instruction, then the firmware other than the bootloader firmware is upgraded based on the firmware upgrade package information in the second preset location of the boot communication partition.

[0112] Specifically, the firmware image files other than the bootloader 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 upgraded to the address space of the corresponding firmware partition in the new partition table.

[0113] In step 219, the boot loader firmware backup information in the third preset position, the boot communication partition backup information in the fourth preset position, and the upgrade instruction information in the first preset position of the boot communication partition of the current partition table are cleared. At the same time, 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, restart the device to enter the upgraded system.

[0115] According to another aspect of the invention, Figure 3 This is a schematic diagram illustrating an electronic device 300 according to an embodiment of the present invention. (Refer to...) 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 run on the processor 304. When the processor 304 executes the computer program, it implements the various steps of the firmware upgrade method as described above.

[0116] According to another aspect of the present invention, a computer-readable medium is provided. The computer-readable medium stores a computer program that is executed by a processor to implement the firmware upgrade method as described above.

[0117] In summary, the firmware upgrade method, electronic device, and storage medium provided by this invention back up the bootloader firmware and boot communication partition based on upgrade instruction information corresponding to the first preset upgrade instruction in the first preset location of the boot communication partition. Based on upgrade instruction information corresponding to the second preset upgrade instruction, the partition table and bootloader firmware are upgraded using firmware upgrade package information in the second preset location of the boot communication partition. Furthermore, based on upgrade instruction information corresponding to the third preset upgrade instruction, other firmware is upgraded using firmware upgrade package information in the second preset location of the boot communication partition. By backing up the bootloader firmware and boot communication partition, OTA upgrades of firmware whose partition table has changed can be supported without relying on external storage. Even if an accident occurs during the upgrade, the backed-up bootloader firmware can be used to continue the upgrade, preventing device bricking and eliminating the need for multiple reboots, thereby improving the efficiency and reliability of firmware upgrades. Moreover, storing the firmware upgrade package to be upgraded in a preset path of a preset user data partition ensures that the address space of the preset user data partition remains unchanged in the new partition table, guaranteeing that the firmware upgrade package will not be corrupted, thus improving the reliability of firmware upgrades. In addition, the entire upgrade process does not require multiple restarts, and if the device is unexpectedly powered on again for another upgrade, it can continue the upgrade from the previous unfinished stage, improving the efficiency of firmware upgrades. At the same time, the upgrade process does not destroy the data in the preset user data partition, ensuring that the content in the user data partition remains unchanged after the upgrade.

[0118] The above description is merely an embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent modifications made based on the content of the present invention specification and drawings, or direct or indirect applications in related technical fields, are similarly included within the patent protection scope of the present invention.

Claims

1. A method for upgrading firmware, characterized in that, include: Based on the upgrade instruction information corresponding to the first preset upgrade instruction in the first preset location 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 location. Based on 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 bootloader 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. as well as Based on the upgrade instruction information corresponding to the third preset upgrade instruction in the first preset position of the boot communication partition, the firmware other than the bootloader firmware is upgraded based on the firmware upgrade package information in the second preset position of the boot communication partition. The backup of the bootloader firmware and boot communication partition includes: determining a backup completion flag based on the bootloader 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, then the bootloader firmware and boot communication partition are not backed up; and if the backup completion flag is false, then the bootloader firmware and boot communication partition are backed up. The backup of the bootloader firmware and boot communication partition includes: Calculate the total length of the data to be backed up; In the new partition table, find the firmware partition whose partition length is greater than the total length of the data to be backed up in the boot loader firmware partition and the firmware partition after the boot communication partition, and use it as the backup partition. At the same time, obtain the starting address and size of the backup partition in the new partition table. Based on the starting address and size of the bootloader firmware partition in the current partition table, copy all the contents of the bootloader firmware partition in the corresponding address space to the address space starting at the starting address of the backup partition; If the boot communication partition change flag is true, then the boot communication partition backup start address is set to the start address of the backup partition plus the size of the bootloader firmware partition in the current partition table; Based on the starting address and size of the boot communication partition in the current partition table, copy all the contents of the boot communication partition in the corresponding address space to the address space starting from the backup starting address of the boot communication partition; Construct bootloader firmware backup information and save the bootloader firmware backup information to the third preset location of the boot communication partition in the current partition table; If the boot communication partition change flag is true, the boot boot 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. Save the boot communication partition backup information 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; Modify the starting address of the bootloader firmware partition in the current partition table to the starting address of the bootloader backup firmware in the bootloader firmware backup information; If the boot communication partition change flag is true, then 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 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.

2. The method according to claim 1, characterized in that, Backing up the bootloader firmware and boot communication partition includes: The bootloader firmware is backed up so that the starting address of the bootloader firmware partition in the current partition table is pointed to the address where the backed-up bootloader firmware is located; and When the boot communication partition in the new partition table changes, the boot communication partition is backed up synchronously so that the starting address of the boot communication partition in the current partition table is pointed to the address of the backed-up boot communication partition. Upgrading the partition table includes: upgrading the modified partition table to the address space where the main firmware partition table and backup partition table are located.

3. The method according to claim 1, characterized in that, Also includes: Obtain the firmware upgrade package to be upgraded, which includes a firmware image file and a partition table file with a preset name; Extract all files of the firmware upgrade package to be upgraded to the preset path of the 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, The backup completion markers are determined based on the bootloader 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: Read the bootloader firmware backup information from the third preset location of the boot communication partition in the current partition table; Determine whether the magic number of the backup information in the bootloader firmware backup information is the same as the preset magic number of the backup information; If they are different, set the backup completion flag to false; If they are the same, then determine whether the starting address of the bootloader firmware partition in the current partition table is the same as the starting address of the bootloader backup firmware in the bootloader firmware backup information. If not, set the backup completion flag to false; If so, the partition table file to be upgraded is obtained from the unzipped folder path of the firmware upgrade package in the firmware upgrade package as the 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 all are the same, then set the boot communication partition change flag to false; If they are not all the same, then set the boot communication partition change flag to true; If the boot communication partition change flag is false, then set the backup completion flag to true; If the boot communication partition change flag is true, then 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 the value is less than the specified value, an error message will be displayed, and the firmware upgrade process will be terminated. If it is not less than, then read the backup information of the boot communication partition in the fourth preset position of the boot communication partition in the current partition table, and determine whether the magic number of the backup information in the backup information is the same as the preset magic number of the backup information. If not, set the backup completion flag to false; If so, 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 complete flag to true; and If they are different, set the backup completion flag to false.

5. The method according to claim 1, characterized in that, Also includes: Determine if a preset upgrade completion marker exists in the fifth preset position of the boot communication partition; If it exists, delete the upgraded firmware upgrade package and clear the preset upgrade completion mark in the fifth preset position of the boot communication partition; If it does not exist, then determine whether there is a firmware upgrade package to be upgraded; If so, the firmware upgrade package to be upgraded is stored in a preset path of the preset user data partition, and the validity of the firmware upgrade package to be upgraded is verified. If the validity check fails, the firmware upgrade process will be terminated. If the validity check is successful, a new empty folder is created under the preset path of the preset user data partition; Extract all files from the firmware upgrade package to be upgraded to the empty folder and construct the firmware upgrade package information; The firmware upgrade package information is written into the second preset location of the boot communication partition; as well as Write a first preset upgrade command in the first preset location of the boot communication partition, and restart the device.

6. The method according to claim 5, characterized in that, Deleting the upgraded firmware upgrade package and clearing the preset upgrade completion marker in the fifth preset position of the boot communication partition includes: Read the firmware upgrade package information from the fifth preset position of the boot communication partition, use it as the upgraded firmware upgrade package information, and delete the entire decompressed folder according to the firmware upgrade package decompressed folder partition name and firmware upgrade package decompressed folder path in the upgraded firmware upgrade package information; Outputs information indicating whether the firmware upgrade was successful and whether the firmware upgrade package was deleted. If a confirmation message to delete the firmware upgrade package is received from the user, then the upgraded firmware upgrade package is deleted according to the original path of the firmware upgrade package in the upgraded firmware upgrade package information; and Clear the preset upgrade completion marker at the fifth preset position of the boot communication partition.

7. The method according to claim 5, characterized in that, Also includes: Read 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; If the main firmware partition table is valid, then the main firmware partition table will be used as the current partition table. If the main firmware partition table is invalid, the backup partition table is read from the boot storage medium, and it is determined whether the backup partition table is valid. If it is valid, the backup partition table is used as the current partition table; otherwise, the firmware upgrade process is exited. Determine whether the current partition table contains a partition with the same partition name as the unzipped folder of the firmware upgrade package in the firmware upgrade package information; If not, exit the firmware upgrade process; If it exists, then according to the partition name of the unzipped folder of the firmware upgrade package in the firmware upgrade package information, the partition where the unzipped folder of the firmware upgrade package is located is mounted according to the file system specified by the file system type of the unzipped folder of the firmware upgrade package in the firmware upgrade package information. If the mounting fails, the firmware upgrade process will be terminated. If the mounting result is successful, then all files under the firmware upgrade package decompression folder path are verified according to the firmware upgrade package decompression file verification information in the firmware upgrade package information; If all the files pass the verification, then proceed with the firmware upgrade; and If the verification results of all the files are not all passed, the firmware upgrade process will be terminated.

8. The method according to claim 1, characterized in that, Upgrading the partition table and the bootloader firmware based on the firmware upgrade package information in the second preset location of the boot communication partition includes: Obtain the partition table file to be upgraded from the unzipped folder path of the firmware upgrade package in the firmware upgrade package information as the new partition table; Compare the starting address and length of the bootloader firmware partition in the current partition table and the new partition table to see if they are the same; If all are the same, then modify the starting address of the bootloader firmware partition in the current partition table to the starting address of the bootloader backup firmware in the bootloader firmware backup information. If valid information exists in the boot communication partition backup information, then 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, 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. Obtain the bootloader firmware image file to be upgraded from the unzipped folder path of the firmware upgrade package, and upgrade the bootloader firmware image file to be upgraded to the address space of the bootloader firmware partition in the new partition table; If valid information exists in the boot communication partition backup information, then all data in the address space consisting of the starting address and size of the boot communication partition backup partition in the boot communication partition backup information will be 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.

9. The method according to claim 1, characterized in that, Upgrading firmware other than the bootloader firmware based on the firmware upgrade package information in the second preset location of the boot communication partition includes: From the firmware upgrade package decompression folder path in the firmware upgrade package information, obtain the other firmware image files except the bootloader firmware image file, and upgrade the other firmware image files to the address space of the corresponding firmware partition in the new partition table.

10. The method according to claim 1, characterized in that, After upgrading the firmware other than the bootloader firmware based on the firmware upgrade package information in the second preset location of the boot communication partition, the process further includes: Clear the bootloader firmware backup information in the third preset position, the boot communication partition backup information in the fourth preset position, and the upgrade instruction information in the first preset position of the boot communication partition of the current partition table. At the same time, write a preset upgrade completion mark in the fifth preset position of the boot communication partition of the current partition table. Reboot your device to access the upgraded system.

11. An electronic device, characterized in that, include: The memory is configured to store executable programs; as well as A processor is configured to execute the program to perform the method according to any one of claims 1 to 10.

12. 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 10.

Citation Information

Patent Citations

  • Firmware upgrading method, electronic equipment and storage medium

    CN116974617A

  • Firmware upgrading method, electronic equipment and storage medium

    CN117369847A