Firmware upgrading method and electronic equipment

By backing up and updating the partition table during firmware upgrade, the problem of the inability to retain encrypted user data partitions and upgrades in the prior art is solved, and data security and device stability in unexpected situations are achieved.

CN119179505AActive Publication Date: 2024-12-24FUZHOU ROCKCHIP SEMICON
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202411306806.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-19
Publication Date
2024-12-24
Estimated Expiration
2044-09-19

AI Technical Summary

Technical Problem

The prior art cannot retain data in the encrypted user data partition during the firmware upgrade process and cannot guarantee the complete reliability of the upgrade process, especially when an unexpected device may cause the device to become bricked.

Method used

By reading the upgrade instruction information in the device's boot bootloader firmware, determining the command line parameters based on the partition table and the preset backup partition size, backing up the boot communication partition, metadata partition, boot bootloader firmware partition and recovery mode firmware partition, And update it to the backup partition table to ensure that the address space of the data after the upgrade remains unchanged and that the backup partition will not be damaged in unexpected circumstances.

Benefits of technology

It realizes the data in the encrypted user data partition retained after the upgrade, and prevents the device from becoming bricked when an unexpected device occurs, improving the reliability of firmware upgrades.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119179505A_ABST
    Figure CN119179505A_ABST
Patent Text Reader

Abstract

The invention relates to a firmware upgrading method and electronic equipment. The method comprises the following steps: backing up data including a metadata partition according to a first preset upgrading instruction and a second preset upgrading instruction, and when address spaces of the metadata partition in a current partition table and a new partition table are different, updating the metadata partition in the current partition table; the metadata partition firmware in the metadata partition backup area is written into the address space where the metadata partition in the new partition table is located according to a third preset upgrading instruction, and even if the address space of the metadata partition where the user data partition encryption key is stored is changed before and after upgrading, the metadata partition firmware in the metadata partition backup area is written into the new partition table. According to the method, data in the user data partition can be reserved after upgrading, data in the backup partition cannot be damaged even if accidental power failure occurs in the backup and upgrading process, and it is ensured that equipment cannot become brick when an accident occurs at any time in the upgrading process, so that the reliability of firmware upgrading is improved, and the user experience is improved. And after upgrading, the encrypted data in the user data partition are still reserved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of embedded devices, and in particular to a method for upgrading firmware and an electronic device. Background Art

[0002] Existing solutions that support upgrading the firmware partition table over the air interface (Over-The-Air, OTA) usually cannot retain the data in the user data partition and cannot guarantee complete reliability during the upgrade process, that is, an accident at some point in the upgrade process will cause the device to become bricked. Although some solutions can ensure that an accident at any time during the upgrade process will not cause the device to become bricked and can also retain the data in the user data partition, they require that the data in the user data partition must be unencrypted. In many scenarios with high security requirements, the user data partition of the device (such as data) is usually encrypted. Summary of the invention

[0003] The present invention provides a method for upgrading firmware and an electronic device, which can improve the reliability of firmware upgrading and still retain the data in the encrypted user data partition after upgrading.

[0004] In one aspect of the present invention, a method for upgrading firmware is provided. The method includes: in the boot program firmware of the device, reading the upgrade instruction information in the first preset position for storing the upgrade instruction in the boot communication partition; in the first stage corresponding to the upgrade instruction information and the first preset upgrade instruction, determining the command line parameters based on the partition start address of the storage area of ​​the firmware to be upgraded, the size of the preset temporary partition, the initial size of the data to be backed up, the header size of the data to be backed up, and the start address of the preset encrypted user data partition, and passing the command line parameters to the recovery mode firmware, the data to be backed up includes the boot communication partition, the metadata partition, the boot program firmware partition, and the recovery mode firmware partition; in the second stage corresponding to the upgrade instruction information and the second preset upgrade instruction, after backing up the data to be backed up and the temporary partition, updating the current partition table so that the boot program firmware in the current partition table is The program firmware partition, the recovery mode firmware partition, the metadata partition, the temporary partition and the boot communication partition point to the corresponding backup partitions respectively, and the updated current partition table is upgraded to the address space where the main partition table and the backup partition table are located in the storage medium; in the third stage corresponding to the upgrade instruction information and the third preset upgrade instruction, the boot program firmware partition and the recovery mode firmware partition are upgraded, and when the address space of the metadata partition in the current partition table and the new partition table is different, the metadata partition firmware in the metadata partition backup area is written to the address space where the metadata partition is located in the new partition table; and in the fourth stage corresponding to the upgrade instruction information and the fourth preset upgrade instruction, other firmware except the boot program firmware and the recovery mode firmware are upgraded.

[0005] In another aspect of the present invention, an electronic device is provided, comprising 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.

[0006] According to the present invention, data including metadata partitions are backed up according to the first preset upgrade instruction and the second preset upgrade instruction. When the address spaces of the metadata partitions in the current partition table and the new partition table are different, the metadata partition firmware in the metadata partition backup area is written to the address space of the metadata partition in the new partition table according to the third preset upgrade instruction. In this way, even if the address space of the metadata partition where the user data partition encryption key is stored changes before and after the upgrade, the data in the user data partition can be retained after the upgrade. Moreover, since the boot communication partition, metadata partition, boot program firmware partition, recovery mode firmware partition and temporary storage partition have been backed up, even if an unexpected power outage occurs during the upgrade process, the data in the backup partition will not be destroyed, ensuring that any accident (such as power outage) at any time during the upgrade process will not cause the device to become bricked, thereby improving the reliability of the firmware upgrade, and the data in the encrypted user data partition is still retained after the upgrade. BRIEF DESCRIPTION OF THE DRAWINGS

[0007] Figure 1 A flowchart of the method for upgrading firmware according to an embodiment of the present invention;

[0008] Figure 2 A schematic diagram of a flow chart of a method for upgrading firmware according to an embodiment of the present invention;

[0009] 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

[0010] In order to explain the technical content, achieved objectives and effects of the present invention in detail, the following is an explanation in combination with the implementation modes and the accompanying drawings.

[0011] In the existing technology, although it can ensure that any accidents at any time during the upgrade process will not cause the device to become bricked and the data in the user data partition can be retained, it is required that the data in the user data partition must be unencrypted. In many scenarios with high security requirements, the user data partition of the device is usually encrypted. In this case, the existing technology cannot retain the data in the user data partition after the upgrade, and cannot guarantee complete reliability during the upgrade process.

[0012] 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, data including metadata partitions are backed up according to a first preset upgrade instruction and a second preset upgrade instruction, and when the address space of the metadata partition in the current partition table and the new partition table is different, the metadata partition firmware in the metadata partition backup area is written to the address space where the metadata partition is located in the new partition table according to a third preset upgrade instruction. In this way, even if the address space of the metadata partition where the user data partition encryption key is stored changes before and after the upgrade, the data in the user data partition can be retained after the upgrade, and because the boot communication partition, metadata partition, boot program firmware partition, recovery mode firmware partition and temporary partition have been backed up, during the upgrade process, even if an unexpected power outage occurs, the data in the backup partition will not be destroyed, ensuring that any accident (such as power outage) at any time during the upgrade process will not cause the device to become bricked, thereby improving the reliability of the firmware upgrade, and the data in the encrypted user data partition is still retained after the upgrade.

[0013] Hereinafter, the technical solution according to the present disclosure will be described with reference to specific embodiments and in conjunction with the accompanying drawings.

[0014] 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 110.

[0015] In step 102, in the boot program firmware of the device, the upgrade instruction information in the first preset location for storing the upgrade instruction in the boot communication partition is read.

[0016] In step 104, in the first stage where the upgrade instruction information corresponds to the first preset upgrade instruction, command line parameters are determined based on the partition start address of the firmware storage area to be upgraded, the size of the preset temporary partition, the initial size of the data to be backed up, the header size of the data to be backed up, and the start address of the preset encrypted user data partition, and the command line parameters are passed to the recovery mode firmware, and the data to be backed up includes a boot communication partition, a metadata partition, a boot program firmware partition, and a recovery mode firmware partition.

[0017] In some embodiments, a firmware partition table is obtained from the address space of a device storage partition table, and the firmware partition table is used as the current partition table; the first partition after the preset partition list in the current partition table is used as a firmware storage area to be upgraded, the firmware storage area to be upgraded is not a preset encrypted user data partition, and the preset partition list includes the boot program firmware partition, the recovery mode firmware partition, the boot communication partition, the metadata partition and the temporary partition; the partition start address of the firmware storage area to be upgraded is written into a command line parameter; the size of the preset temporary partition is obtained from the current partition table, and the size of the preset temporary partition is written into the command line parameter; the size of the boot communication partition, the size of the metadata partition, the size of the boot program firmware partition, the size of the temporary ... The method comprises the following steps: obtaining the size of the boot communication partition, the size of the metadata partition, the size of the boot program firmware partition and the size of the recovery mode firmware partition, and adding the size of the boot communication partition, the size of the metadata partition, the size of the boot program firmware partition and the size of the recovery mode firmware partition to obtain the initial size of the data to be backed up; writing the initial size of the data to be backed up into the command line parameter; adding a boot communication partition backup header of a preset size, a metadata partition backup header of a preset size, a boot program firmware partition backup header of a preset size and a recovery mode firmware partition backup header of a preset size to obtain the header size of the data to be backed up, and writing the header size of the data to be backed up into the command line parameter; and obtaining the starting address of the preset encrypted user data partition from the current partition table, and writing the starting address of the preset encrypted user data partition into the command line parameter.

[0018] In this way, the partition starting address of the firmware storage area to be upgraded, the size of the preset temporary partition, the initial size of the data to be backed up, the header size of the data to be backed up and the starting address of the preset encrypted user data partition are written into the command line parameters for subsequent data backup.

[0019] In step 106, in the second stage corresponding to the upgrade instruction information and the second preset upgrade instruction, after backing up the data to be backed up and the temporary partition, the current partition table is updated so that the boot program firmware partition, the recovery mode firmware partition, the metadata partition, the temporary partition and the boot communication partition in the current partition table point to the corresponding backup partitions respectively, and the updated current partition table is upgraded to the address space where the main partition table and the address space where the backup partition table are located in the storage medium.

[0020] In some embodiments, a firmware partition table is obtained from the address space of the device storage partition table, and the firmware partition table is used as the current partition table; a partition table file is obtained from the firmware storage area to be upgraded as a new partition table according to the metadata of the firmware storage area to be upgraded; an initial value of a mark indicating that the current partition table has pointed to a backup area is set to false; it is determined whether the backup of all backup areas including the boot program firmware partition backup area, the recovery mode firmware partition backup area, the metadata partition backup area, the temporary storage partition backup area and the boot communication partition backup area has been completed, and whether the boot program firmware partition, the recovery mode firmware partition, the metadata partition, the temporary storage partition and the boot communication partition in the current partition table have respectively pointed to corresponding backup partitions; if so, then Set the flag that the current partition table has pointed to the backup area to true; determine whether the flag that the current partition table has pointed to the backup area is true; if true, write the third preset upgrade instruction into the first preset position of the boot communication partition; and if not true, after backing up the boot program firmware partition, the recovery mode firmware partition, the metadata partition, the temporary partition and the boot communication partition, update the current partition table so that the boot program firmware partition, the recovery mode firmware partition, the metadata partition, the temporary partition and the boot communication partition in the current partition table point to the corresponding backup partitions respectively, and upgrade the updated current partition table to the address space where the main partition table and the address space where the backup partition table are located in the storage medium.

[0021] In this way, it is simpler and more effective to determine whether the backup is completed by marking that the current partition table has pointed to the backup area. Since the encryption key of the encrypted user data partition is stored in the metadata area, after the boot program firmware partition, recovery mode firmware partition, metadata partition, temporary partition and boot communication partition are backed up, the current partition table is updated so that the boot program firmware partition, recovery mode firmware partition, metadata partition, temporary partition and boot communication partition in the current partition table point to the corresponding backup partitions respectively. When the address space of the metadata area changes before and after the upgrade (such as the partition start address of the metadata area changes), the data in the encrypted user data partition can still be retained after the upgrade.

[0022] In some embodiments, the starting address and partition size of the recovery mode firmware partition are obtained from the new partition table as the starting address and partition size of the new recovery mode firmware; the free area metadata is read from the third preset position of the boot communication partition, and it is determined whether the magic number in the free area metadata is the preset magic number; if not, the firmware upgrade process is exited; if so, it is determined whether the address obtained by adding the starting address of the new recovery mode firmware and the partition size of the new recovery mode firmware is greater than the free area starting address in the free area metadata; if greater, the firmware upgrade process is exited; if not, the boot program firmware partition is backed up to the boot program firmware partition backup area , and write the boot program firmware partition backup area meta information at the fourth preset position of the boot communication partition in the current partition table; back up the recovery mode firmware partition to the recovery mode firmware partition backup area, and write the recovery mode firmware partition backup area meta information at the fifth preset position of the boot communication partition in the current partition table; determine whether the address space of the metadata partition in the current partition table and the new partition table is the same; if different, back up the metadata partition to the metadata partition backup area, and write the metadata partition backup area meta information at the sixth preset position of the boot communication partition in the current partition table; determine whether the address space of the temporary partition in the current partition table and the new partition table is the same; if not If the addresses of the boot communication partitions in the current partition table and the new partition table are the same, the temporary partition is backed up to the temporary partition backup area, and the temporary partition backup area meta-information is written in the seventh preset position of the boot communication partition in the current partition table; it is determined whether the address space of the boot communication partition in the current partition table and the new partition table is the same; if they are different, the boot communication partition is backed up to the boot communication partition backup area, and the boot communication partition backup area meta-information is written in the eighth preset position of the boot communication partition in the current partition table, and at the same time, the boot communication partition backup area meta-information is written in the preset position for storing the boot communication partition backup area meta-information in the boot communication partition firmware in the boot communication partition backup area; the boot program firmware partition in the current partition table is backed up to the temporary partition backup area, and the boot communication partition backup area meta-information is written in the eighth preset position of the boot communication partition in the current partition table; The starting address of the recovery mode firmware partition in the current partition table is set to the starting address of the boot program firmware in the boot program firmware partition backup header; the starting address of the recovery mode firmware partition in the current partition table is set to the starting address of the recovery mode firmware in the recovery mode firmware partition backup header; when the address space of the metadata partition in the current partition table and the new partition table is different, the starting address of the metadata partition in the current partition table is set to the starting address of the metadata partition firmware in the metadata partition backup header; when the address space of the temporary partition in the current partition table and the new partition table is different, the starting address of the temporary partition in the current partition table is set to the starting address of the temporary partition firmware in the temporary partition backup header;When the address spaces of the boot communication partition in the current partition table and the new partition table are different, the starting address of the boot communication partition in the current partition table is set to the boot communication partition firmware starting address in the boot communication partition backup header; the updated free area meta-information is written into the third preset position of the boot communication partition in the updated current partition table, and the updated current partition table is upgraded to the address space where the main partition table and the backup partition table are located in the storage medium; and the third preset upgrade instruction is written into the first preset position of the boot communication partition. ;

[0023] In this way, since the boot program firmware partition, recovery mode firmware partition, metadata partition, temporary partition and boot communication partition in the current partition table have respectively pointed to the corresponding backup partitions, and the firmware storage area to be upgraded and all the backup partitions are all located after the boot program firmware partition, recovery mode firmware partition, boot communication partition, metadata partition and temporary partition in the new and old partition tables, in the subsequent upgrade process, even if an unexpected power outage occurs, the data in the backup partition will not be destroyed, and the upgrade can be continued after power-on, thereby improving the reliability of the firmware upgrade.

[0024] In step 108, in the third stage where the upgrade instruction information corresponds to the third preset upgrade instruction, the boot program firmware partition and the recovery mode firmware partition are upgraded, and when the address space of the metadata partition in the current partition table and the new partition table is different, the metadata partition firmware in the metadata partition backup area is written to the address space where the metadata partition is located in the new partition table.

[0025] In some embodiments, a firmware partition table is obtained from the address space of a device storage partition table, and the firmware partition table is used as the current partition table; a partition table file is obtained from the firmware storage area to be upgraded as a new partition table according to the metadata of the firmware storage area to be upgraded; if the current partition table and the new partition table are different, boot program firmware image file data is obtained from the firmware storage area to be upgraded according to the metadata of the firmware storage area to be upgraded, and the boot program firmware image file data is written into the address space where the boot program firmware partition is located in the new partition table; recovery mode firmware image file data is obtained from the firmware storage area to be upgraded according to the metadata of the firmware storage area to be upgraded, and the recovery mode firmware image file data is written into the address space where the recovery mode firmware partition is located in the new partition table; when the address spaces of the metadata partition in the current partition table and the new partition table are different, the metadata partition firmware in the metadata partition backup area is written into the address space where the metadata partition is located in the new partition table; when the address spaces of the temporary partition in the current partition table and the new partition table are different, the metadata partition firmware in the metadata partition backup area is written into the address space where the metadata partition is located in the new partition table; When the address spaces of the boot communication partition in the current partition table and the new partition table are different, determine whether the size of the temporary partition in the new partition table is greater than or equal to the size of the temporary partition in the current partition table; if so, write the temporary partition firmware in the temporary partition backup area into the address space where the temporary partition is located in the new partition table; when the address spaces of the boot communication partition in the current partition table and the new partition table are different, write all the boot communication partition data in the current partition table into the address space where the boot communication partition is located in the new partition table; upgrade the new partition table to the address space where the main partition table and the backup partition table are located in the storage medium, and use the new partition table as the current partition table; if the current partition table and the new partition table are the same, determine whether there is legal block list description file backup area metadata in the boot communication partition of the current partition table, and whether there is legal block list description file backup header in the block list description file backup area; if both exist, write the fifth preset upgrade instruction into the first preset position of the boot communication partition; and if both do not exist, write the fourth preset upgrade instruction into the first preset position of the boot communication partition.

[0026] In this way, when the boot program firmware partition and the recovery mode firmware partition are upgraded, when the address space of the metadata partition in the current partition table and the new partition table is different, the metadata partition firmware in the metadata partition backup area is written to the address space where the metadata partition is located in the new partition table, thereby retaining the data in the encrypted user data partition after the upgrade.

[0027] In step 110, in the fourth stage where the upgrade instruction information corresponds to a fourth preset upgrade instruction, other firmware except the boot program firmware and the recovery mode firmware are upgraded.

[0028] In some embodiments, a firmware partition table is obtained from the address space of the device storage partition table, and the firmware partition table is used as the current partition table; metadata of the firmware storage area to be upgraded is read from the ninth preset position in the boot communication partition of the current partition table, and it is determined whether the magic number in the metadata of the firmware storage area to be upgraded is the preset magic number; if not, the firmware upgrade process is exited; if so, an upgrade image header of a preset size is read from the starting address of the firmware storage area to be upgraded in the metadata of the firmware storage area to be upgraded; it is determined whether the magic number in the upgrade image header is the preset magic number; if not, a sixth preset upgrade instruction is written into the first preset position of the boot communication partition; if it is the preset magic number, the firmware image file data and the recovery mode except for the boot program are obtained from the firmware storage area to be upgraded in sequence according to the metadata of the firmware storage area to be upgraded The method further comprises the steps of: storing other firmware image file data other than the firmware image file data, and saving all the other firmware image file data to the reserved space of the dynamic random access memory; writing the other firmware image file data in the reserved space to the address space where the corresponding firmware partition is located in the new partition table; clearing the firmware storage area metadata to be upgraded, the free area metadata, the block list description file backup area metadata, the boot program firmware partition backup area metadata, the recovery mode firmware partition backup area metadata, the metadata partition backup area metadata, the temporary partition backup area metadata and the boot communication partition backup area metadata in the boot communication partition of the current partition table; clearing the upgrade instruction information in the first preset position of the current partition table; writing a preset upgrade completion mark in the second preset position in the boot communication partition of the current partition table; and restarting the device to enter the upgraded system.

[0029] In this way, after upgrading the boot program firmware and the recovery mode firmware, other firmware are upgraded and the firmware upgrade is successfully completed. In this process, the data in the storage area of ​​the firmware to be upgraded may be damaged. When the data is damaged and an unexpected power outage occurs, the sixth preset upgrade instruction is written into the first preset position of the boot communication partition, so that in the recovery mode firmware, all files in the firmware upgrade package stored in the encrypted user data partition are read out and saved to the storage area of ​​the firmware to be upgraded according to the preset storage structure, and then the fourth preset upgrade instruction is re-executed to ensure that the device will not become bricked and can be restarted and continued to upgrade at the unexpected stage.

[0030] In some embodiments, the method 100 may further include: if the upgrade instruction information in the first preset position of the boot communication partition corresponds to the fifth preset upgrade instruction, loading and booting the recovery mode firmware, and running the recovery mode firmware.

[0031] In some embodiments, the method 100 may also include: if the upgrade instruction information in the first preset position of the boot communication partition corresponds to the sixth preset upgrade instruction, obtaining the firmware partition table from the address space of the device storage partition table, and using the firmware partition table as the current partition table; using the first partition after the preset partition list in the current partition table as the firmware storage area to be upgraded, the firmware storage area to be upgraded is not a preset encrypted user data partition, and the preset partition list includes the boot program firmware partition, the recovery mode firmware partition, the boot communication partition, the metadata partition and the temporary partition; writing the partition start address of the firmware storage area to be upgraded into the command line parameter; loading and booting the recovery mode firmware, and passing the command line parameter to the recovery mode firmware; and running the recovery mode firmware.

[0032] In this way, the first partition after the preset partition list in the current partition table is used as the storage area for the firmware to be upgraded. Even if an unexpected power outage occurs, the data in the backup partition will not be destroyed, thereby ensuring that the device will not be bricked if an accident occurs during the upgrade process and can continue to be upgraded, thereby improving the reliability of the upgrade.

[0033] In some embodiments, the upgrade instruction information in the first preset position of the boot communication partition is read; it is determined whether the upgrade instruction information is the first preset upgrade instruction, the fifth preset upgrade instruction or the sixth preset upgrade instruction; if not, the firmware upgrade process is exited; if so, the upgrade instruction information is used as the current upgrade instruction; if the current upgrade instruction is the first preset upgrade instruction, the temporary storage partition is mounted, and the firmware upgrade package under the preset path of the preset encrypted user data partition is read according to the block list description file under the preset path of the temporary storage partition; all files in the firmware upgrade package are read, and all files are saved to the firmware storage area to be upgraded according to the preset storage structure; if the new temporary storage partition is If the storage partition is smaller than the old temporary storage partition, the block list description file under the preset path of the temporary storage partition is backed up to the block list description file backup area, and the block list description file backup area meta information is constructed at the same time, and the block list description file backup area meta information is written to the tenth preset position of the boot communication partition; the firmware storage area meta information to be upgraded is constructed, and the firmware storage area meta information to be upgraded is written to the ninth preset position of the boot communication partition; the free area meta information is constructed, and the free area meta information is written to the third preset position of the boot communication partition; the second preset upgrade instruction is written to the first preset position of the boot communication partition, and the device is restarted; if the current upgrade instruction is the fifth preset upgrade instruction, the current The method further comprises the steps of: formatting the temporary partition before mounting the temporary partition and then mounting the temporary partition; reading the block list description file backup area meta information from the tenth preset position of the boot communication partition, and determining whether the magic number in the block list description file backup area meta information is the preset block list description file backup area meta information magic number; if so, reading a block list description file backup header of a preset size from the starting address of the block list description file backup area in the block list description file backup area meta information; if the magic number in the block list description file backup header is the preset magic number, creating a new empty block list description file under the preset path of the temporary partition, and reading a large block list description file from the block list description file starting address in the block list description file backup header. The method comprises the steps of: saving data smaller than the size of the block list description file in the block list description file backup header to the empty block list description file; writing a fourth preset upgrade instruction at the first preset position of the boot communication partition, and restarting the device; if the current upgrade instruction is the sixth preset upgrade instruction, obtaining the partition start address of the firmware storage area to be upgraded from the command line parameter as the start address of the firmware storage area to be upgraded, and mounting the temporary partition; reading the firmware upgrade package under the preset path of the preset encrypted user data partition according to the block list description file under the preset path of the temporary partition, and reading all files in the firmware upgrade package; saving all the files to the firmware storage area to be upgraded according to the preset storage structure;Construct the firmware storage area meta information to be upgraded, and write the firmware storage area meta information to the ninth preset position of the boot communication partition; and write the fourth preset upgrade instruction to the first preset position of the boot communication partition, and restart the device. In this way, the recovery mode firmware can run smoothly. ;

[0034] In some embodiments, before step 102, the method 100 may further include: constructing a firmware upgrade package, wherein the firmware upgrade package includes all firmware image files to be upgraded including a boot program firmware image file and a recovery mode firmware image file and a partition table file with a preset name.

[0035] In some embodiments, before step 102, the method 100 may further include: saving the firmware upgrade package to be upgraded to a preset path of the user data partition; generating a block list occupied by the firmware upgrade package, decrypting the block data in the block list, rewriting the decrypted block data into the corresponding block, and saving the corresponding block list into a block list description file under the preset path of the temporary storage partition; and writing the first preset upgrade instruction into the first preset position in the boot communication partition, and then restarting the device.

[0036] In some embodiments, the method 100 may also include: in the recovery mode firmware, reading the upgrade instruction information in the first preset position in the boot communication partition; if the upgrade instruction information corresponds to the first preset upgrade instruction, mounting the temporary storage partition; reading the firmware upgrade package under the preset path of the encrypted user data partition according to the block list description file under the preset path of the temporary storage partition, and saving all files read from the firmware upgrade package to the firmware storage area to be upgraded according to the preset storage structure; constructing the firmware storage area metadata and writing it to the ninth preset position in the boot communication partition, and constructing the free area metadata and writing it to the third preset position in the boot communication partition; and writing the second preset upgrade instruction to the first preset position in the boot communication partition, and then restarting the device.

[0037] In some embodiments, the method 100 may further include: if the current partition table already points to the backup partition, setting the current upgrade instruction to the third preset upgrade instruction; and writing the third preset upgrade instruction into the first preset position in the boot communication partition of the current partition table.

[0038] In some embodiments, the method 100 may also include: loading the boot recovery mode firmware and passing the command line parameters to the recovery mode firmware; formatting the current temporary partition and creating an empty block list description file under the preset path of the temporary partition; starting from the block list description file start address in the block list description file backup header, reading data of a size equal to the block list description file size in the block list description file backup header and saving it to the newly created block list description file under the preset path of the temporary partition; and writing the fourth preset upgrade instruction at the first preset position in the boot communication partition, and then restarting the device.

[0039] In some embodiments, the method 100 may also include: loading the boot recovery mode firmware and passing command line parameters to the recovery mode firmware; reading the firmware upgrade package under the preset path of the encrypted user data partition according to the block list description file under the preset path of the temporary partition, and saving all files read from the firmware upgrade package to the firmware storage area to be upgraded according to the preset storage structure; constructing the firmware storage area metadata to be upgraded and writing it to the ninth preset position in the boot communication partition; and writing the fourth preset upgrade instruction to the first preset position in the boot communication partition, and then restarting the device.

[0040] In some embodiments, the method 100 may further include: if there is no valid block list description file backup area metadata and block list description file backup area, setting the current upgrade instruction to the fourth preset upgrade instruction; and writing the fourth preset upgrade instruction to the first preset position in the boot communication partition of the current partition table.

[0041] In some embodiments, before step 102, the method 100 may further include: determining whether there is a preset upgrade completion mark at the second preset position of the boot communication partition; if so, outputting upgrade success information, deleting the firmware upgrade package under the preset path of the preset encrypted user data partition, and clearing the upgrade completion mark in the second preset position of the boot communication partition; if not, periodically determining whether there is a new firmware upgrade package to be upgraded; if so, obtaining the firmware upgrade package to be upgraded, and saving the firmware upgrade package to be upgraded to the preset path of the preset encrypted user data partition; and conducting a validity check on the firmware upgrade package to be upgraded. Check; if the legitimacy check is illegal, delete the firmware upgrade package under the preset path of the preset encrypted user data partition and exit the firmware upgrade process; if the legitimacy check is legal, generate a block list occupied by the firmware upgrade package under the preset path of the preset encrypted user data partition through a preset decryption service, decrypt the block data in the block list to obtain the decrypted data; rewrite the decrypted data into the corresponding block, and save the corresponding block list into the block list description file under the preset path of the temporary partition; and write the first preset upgrade instruction into the first preset position of the boot communication partition, and restart the device.

[0042] In this way, determining whether to enter the upgrade process by presetting the upgrade completion mark is more reliable, and the legitimacy of the firmware upgrade package to be upgraded is first checked to ensure the security of the firmware upgrade package, thereby ensuring the reliability of the firmware upgrade.

[0043] 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.

[0044] 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 213.

[0045] In some embodiments, the preset encrypted user data partition remains unchanged when the firmware partition table changes, that is, the starting address and length of the preset encrypted user data partition in the new and old partition tables remain unchanged. In addition, the address space of the boot program firmware partition, the boot communication partition, and the recovery mode firmware partition in the firmware partition table is located before the address space of various system firmware partitions (such as super or system) and the preset encrypted user data partition, and the preset encrypted user data partition is the last partition in the firmware partition table. In addition, the length of the boot communication partition in the new partition table must be greater than or equal to the length of the boot communication partition in the old partition table, and the length of the metadata partition in the new partition table must be greater than or equal to the length of the metadata partition in the old partition table.

[0046] In step 201, a firmware upgrade package is constructed, which includes all firmware image files to be upgraded including a boot program firmware image file and a recovery mode firmware image file and a partition table file with a preset name.

[0047] All firmware image files use 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.

[0048] The device contains readable and writable partitions including a preset boot communication partition, a temporary partition, a metadata partition, and an encrypted user data partition, and there are two partition tables in the device, namely the primary partition table and the backup partition table. The preset boot communication partition (such as misc) is a raw partition used for communication between the system firmware, the boot program firmware, and the upgrade mode firmware. The preset temporary partition (such as cache) is a user-readable and writable non-encrypted file system partition used to store files generated during system operation. The preset metadata partition (such as metadata) is a user-readable and writable non-encrypted file system partition used to store encryption keys for the user data area. The preset encrypted user data partition (such as data) is a user-readable and writable encrypted file system partition used to store user data.

[0049] In step 202, it is determined whether there is a preset upgrade completion mark at the second preset position of the boot communication partition. If so, step 203 is executed; if not, step 204 is executed.

[0050] In step 203, the upgrade success information is output, the firmware upgrade package under the preset path of the preset encrypted user data partition is deleted, and the upgrade completion mark in the second preset position of the boot communication partition is cleared.

[0051] In step 204, it is regularly determined whether there is a new firmware upgrade package to be upgraded. If so, the firmware upgrade package to be upgraded is obtained and saved to a preset path of a preset encrypted user data partition. A legitimacy check is performed on the firmware upgrade package to be upgraded. If the legitimacy check is illegal, the firmware upgrade package under the preset path of the preset encrypted user data partition is deleted and the firmware upgrade process is exited. If the legitimacy check is legal, step 205 is executed.

[0052] In step 205, a block list occupied by the firmware upgrade package under a preset path of a preset encrypted user data partition is generated through a preset decryption service (such as uncrypt under Android), and the block data in the block list is decrypted to obtain decrypted data.

[0053] In step 206, the decrypted data is rewritten into the corresponding block, and the corresponding block list is saved in a block list description file in a preset path of the temporary partition (eg, / cache / recovery / block.map in the cache partition).

[0054] In step 207, a first preset upgrade instruction is written into a first preset location of the boot communication partition, and the device is restarted.

[0055] In step 208, if the upgrade instruction information in the first preset position of the boot communication partition corresponds to the first preset upgrade instruction, the command line parameters are determined based on the partition start address of the firmware storage area to be upgraded, the size of the preset temporary partition, the initial size of the data to be backed up, the header size of the data to be backed up and the start address of the preset encrypted user data partition, and the command line parameters are passed to the recovery mode firmware. The data to be backed up includes the boot communication partition, the metadata partition, the boot program firmware partition and the recovery mode firmware partition, specifically including the following (1) to (9).

[0056] (1) Obtain the firmware partition table from the address space of the device storage partition table, and use the firmware partition table as the current partition table.

[0057] Specifically, the primary partition table is read from the address space where the primary partition table is located, and the legality of the primary partition table is verified. If the verification result of the primary partition table is legal, the primary partition table is used as the current partition table. If the verification result of the primary partition table is illegal, the backup partition table is read from the address space of the backup partition table, and the legality of the backup partition table is verified. If the verification result of the backup partition table is legal, the backup partition table is used as the current partition table.

[0058] (2) The first partition after the preset partition list in the current partition table is used as the firmware storage area to be upgraded (such as a super partition). The firmware storage area to be upgraded is not the preset encrypted user data partition. The preset partition list includes a boot program firmware partition, a recovery mode firmware partition, a boot communication partition, a metadata partition, and a temporary storage partition.

[0059] (3) Write the partition start address of the firmware storage area to be upgraded into the command line parameter.

[0060] (4) Obtain the size of the preset temporary partition from the current partition table, and write the size of the preset temporary partition into the command line parameter.

[0061] (5) Obtain the size of the boot communication partition, the size of the metadata partition, the size of the boot program firmware partition, and the size of the recovery mode firmware partition from the current partition table respectively, and add the size of the boot communication partition, the size of the metadata partition, the size of the boot program firmware partition, and the size of the recovery mode firmware partition to obtain the initial size of the data to be backed up.

[0062] (6) Write the initial size of the data to be backed up into the command line parameter.

[0063] (7) A preset size of the boot communication partition backup header, a preset size of the metadata partition backup header, a preset size of the boot program firmware partition backup header, and a preset size of the recovery mode firmware partition backup header are added together to obtain the header size of the data to be backed up, and the header size of the data to be backed up is written into the command line parameter.

[0064] (8) Obtain the starting address of the preset encrypted user data partition from the current partition table, and write the starting address of the preset encrypted user data partition into the command line parameter.

[0065] (9) Load and boot the recovery mode firmware, pass the command line parameters to the recovery mode firmware, and run the recovery mode firmware.

[0066] In step 209, if the upgrade instruction information in the first preset position of the boot communication partition corresponds to the second preset upgrade instruction, then after backing up the backup data and the temporary partition, the current partition table is updated so that the boot program firmware partition, recovery mode firmware partition, metadata partition, temporary partition and boot communication partition in the current partition table point to the corresponding backup partitions respectively, and the updated current partition table is upgraded to the address space where the main partition table and the address space where the backup partition table are located in the storage medium, specifically including the following (1) to (19).

[0067] (1) Obtain a firmware partition table from the address space of the device storage partition table, and use the firmware partition table as the current partition table.

[0068] (2) Obtain a partition table file from the firmware storage area to be upgraded as a new partition table according to the metadata of the firmware storage area to be upgraded.

[0069] Specifically, the firmware storage area to be upgraded meta information is read from the ninth preset position of the boot communication partition, and the magic number in the firmware storage area to be upgraded meta information is checked to be the preset magic number. If it is not the preset magic number, the firmware upgrade process is exited; if it is the preset magic number, the upgrade image header of the preset size is read from the starting address of the firmware storage area to be upgraded in the firmware storage area to be upgraded meta information; check whether the magic number in the upgrade image header is the preset magic number; if not, the firmware upgrade process is exited; if so, the partition table image file item is searched from the image file item list in the upgrade image header, and the starting address of the firmware storage area to be upgraded is added to the offset address of the image file in the partition table image file item in the firmware storage area to be upgraded to obtain a final address; and data with a length equal to the size of the image file in the partition table image file item is read from the final address as a new partition table.

[0070] (3) The initial value of the flag (such as pt_bak_flag) indicating that the current partition table points to the backup area is set to false.

[0071] (4) Determine whether the backup of all backup areas including the boot program firmware partition backup area, the recovery mode firmware partition backup area, the metadata partition backup area, the temporary partition backup area and the boot communication partition backup area has been completed, and whether the boot program firmware partition, the recovery mode firmware partition, the metadata partition, the temporary partition and the boot communication partition in the current partition table have all pointed to the corresponding backup partitions respectively. If so, set the flag that the current partition table has pointed to the backup area to true, specifically including the following (a) to (o).

[0072] (a) Read the boot program firmware partition backup area metadata from the fourth preset position of the boot communication partition in the current partition table, and check whether the magic number in the boot program firmware partition backup area metadata is a preset magic number. If not, execute (5). If yes, read the boot program firmware partition backup header of a preset size from the starting address of the boot program firmware partition backup area in the boot program firmware partition backup area metadata.

[0073] (b) Check whether the magic number in the boot program firmware partition backup header is a preset magic number. If not, execute (5). If it is the preset magic number, check whether the starting address of the boot program firmware partition in the current partition table is the same as the boot program firmware starting address in the boot program firmware partition backup header. If not, execute (5). If they are the same, read the recovery mode firmware partition backup area metadata from the fifth preset position of the boot communication partition in the current partition table.

[0074] (c) Check whether the magic number in the recovery mode firmware partition backup area metadata is a preset magic number. If not, execute (5). If so, read the recovery mode firmware partition backup header of the preset size from the starting address of the recovery mode firmware partition backup area in the recovery mode firmware partition backup area metadata.

[0075] (d) Check whether the magic number in the recovery mode firmware partition backup header is the preset magic number. If not, execute (5). If it is the preset magic number, check whether the starting address of the recovery mode firmware partition in the current partition table is the same as the recovery mode firmware starting address in the recovery mode firmware partition backup header. If not, execute (5). If they are the same, check whether the address space of the metadata partition in the current partition table is exactly the same as the address space of the metadata partition in the new partition table. If so, execute the following step (h). If not, execute (e).

[0076] (e) Read the metadata partition backup area meta information from the sixth preset position of the boot communication partition in the current partition table, and check whether the magic number in the metadata partition backup area meta information is the preset magic number. If not, execute the following (5). If yes, execute (f).

[0077] (f) Read the metadata partition backup header of a preset size from the starting address of the metadata partition backup area in the metadata partition backup area meta-information, and check whether the magic number of the metadata partition backup header is the preset magic number. If not, execute (5); if yes, execute (g).

[0078] (g) Check whether the starting address of the metadata partition in the current partition table is the same as the starting address of the metadata partition firmware in the metadata partition backup header. If not, execute (5); if so, execute (h).

[0079] (h) Check whether the address space of the temporary partition in the current partition table is exactly the same as the address space of the temporary partition in the new partition table. If so, execute (l); if not, execute (i).

[0080] (i) Read the temporary partition backup area meta information from the seventh preset position of the boot communication partition in the current partition table, and check whether the magic number in the temporary partition backup area meta information is the preset magic number. If not, execute (5); if so, execute (j).

[0081] (j) Read a temporary partition backup header of a preset size from the starting address of the temporary partition backup area in the temporary partition backup area meta-information, and check whether the magic number of the temporary partition backup header is a preset magic number. If not, execute (5); if so, execute (k).

[0082] (k) Check whether the starting address of the temporary partition in the current partition table is the same as the starting address of the temporary partition firmware in the temporary partition backup header. If not, execute (5); if so, execute (l).

[0083] (l) Check whether the address space of the boot communication partition in the current partition table is exactly the same as the address space of the boot communication partition in the new partition table. If so, set the flag that the current partition table points to the backup area to true and execute (5). If not, execute (m).

[0084] (m) Read the boot communication partition backup area meta information from the eighth preset position of the boot communication partition in the current partition table, and check whether the magic number of the boot communication partition backup area meta information is the preset magic number. If not, execute (5); if so, execute (n).

[0085] (n) Read a boot communication partition backup header of a preset size from the starting address of the boot communication partition backup area of ​​the boot communication partition backup area meta-information, and check whether the magic number of the boot communication partition backup header is a preset magic number. If not, execute (5); if so, execute (o).

[0086] (o) Check 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 firmware in the boot communication partition backup header. If not, execute (5). If so, set the flag that the current partition table has pointed to the backup area to true and execute (5).

[0087] The same address space of two partitions means that the starting address and partition size of the corresponding partitions are the same.

[0088] (5) Determine whether the flag indicating that the current partition table has pointed to the backup area is true. If so, write the third preset upgrade instruction into the first preset position of the boot communication partition. If not, execute (6).

[0089] (6) Obtain the starting address and partition size of the recovery mode firmware partition from the new partition table as the starting address and partition size of the new recovery mode firmware.

[0090] (7) Read the free area meta information from the third preset position of the boot communication partition, and determine whether the magic number in the free area meta information is a preset magic number. If not, exit the firmware upgrade process. If yes, execute (8).

[0091] (8) Determine whether the address obtained by adding the starting address of the new recovery mode firmware and the partition size of the new recovery mode firmware is greater than the starting address of the free area in the free area metadata. If so, exit the firmware upgrade process. If not, back up the boot program firmware partition to the boot program firmware partition backup area, and write the boot program firmware partition backup area metadata to the fourth preset position of the boot communication partition in the current partition table, specifically including the following (a) to (d).

[0092] (a) The magic number in the boot program firmware partition backup header is set to the preset boot program firmware partition backup magic number; the boot program firmware starting address in the boot program firmware partition backup header is set to "the free area starting address in the free area metadata + the size of the boot program firmware partition backup header"; the boot program firmware size in the boot program firmware partition backup header is set to the partition size of the boot program firmware partition in the current partition table.

[0093] (b) obtaining the starting address and partition size of the boot program firmware partition in the current partition table as the starting address of the current boot program firmware and the current boot program firmware partition size; reading the data of the current boot program firmware partition size from the starting address of the current boot program firmware, and writing the read data to the starting address of the boot program firmware in the boot program firmware partition backup header, the written data size being the boot program firmware size in the boot program firmware partition backup header; writing the boot program firmware partition backup header to the starting address of the free area in the free area meta-information, the written data size being the size of the boot program firmware partition backup header.

[0094] (c) constructing the boot program firmware partition backup area meta information, and writing the boot program firmware partition backup area meta information into the boot communication partition in the current partition table for storing the boot program firmware partition backup area meta information in a preset location.

[0095] Specifically, the magic number in the boot program firmware partition backup area metadata is set to the preset boot program firmware partition backup area metadata magic number; the starting address of the boot program firmware partition backup area in the boot program firmware partition backup area metadata is set to the free area starting address in the free area metadata; the constructed boot program firmware partition backup area metadata is written to the fourth preset position of the boot communication partition in the current partition table.

[0096] (d) The starting address of the free area in the free area meta-information is updated to: the starting address of the original free area + the size of the boot program firmware partition backup header + the size of the boot program firmware in the boot program firmware partition backup header; the length of the free area in the free area meta-information is updated to: the original length of the free area - the size of the boot program firmware partition backup header - the size of the boot program firmware in the boot program firmware partition backup header.

[0097] Among them, the boot program firmware partition backup area is composed of a boot program firmware partition backup header of a preset size and the boot program firmware; the boot program firmware partition backup header of a preset size is composed of a preset magic number, a boot program firmware starting address and a boot program firmware size; the boot program firmware partition backup area metadata is composed of a preset magic number and a starting address of the boot program firmware partition backup area.

[0098] (9) Backing up the recovery mode firmware partition to the recovery mode firmware partition backup area, and writing the recovery mode firmware partition backup area meta information in the fifth preset position of the boot communication partition in the current partition table, specifically including the following (a) to (d).

[0099] (a) Set the magic number in the recovery mode firmware partition backup header to the preset recovery mode firmware partition backup magic number; set the recovery mode firmware starting address in the recovery mode firmware partition backup header to "the free area starting address in the free area metadata + the size of the recovery mode firmware partition backup header"; set the recovery mode firmware size in the recovery mode firmware partition backup header to the partition size of the recovery mode firmware partition in the current partition table.

[0100] (b) Obtain the starting address and partition size of the recovery mode firmware partition in the current partition table as the starting address of the current recovery mode firmware and the current recovery mode firmware partition size; read the data of the current recovery mode firmware partition size from the starting address of the current recovery mode firmware, and write the read data to the starting address of the recovery mode firmware in the recovery mode firmware partition backup header, and the written data size is the recovery mode firmware size in the recovery mode firmware partition backup header; write the recovery mode firmware partition backup header to the starting address of the free area in the free area meta-information, and the written data size is the size of the recovery mode firmware partition backup header.

[0101] (c) Constructing recovery mode firmware partition backup area meta information, and writing the recovery mode firmware partition backup area meta information into the boot communication partition in the current partition table for storing the recovery mode firmware partition backup area meta information in a preset location.

[0102] Specifically, the magic number in the recovery mode firmware partition backup area meta-information is set to the preset recovery mode firmware partition backup area meta-information magic number; the starting address of the recovery mode firmware partition backup area in the recovery mode firmware partition backup area meta-information is set to the free area starting address in the free area meta-information; and the constructed recovery mode firmware partition backup area meta-information is written to the fifth preset position of the boot communication partition in the current partition table.

[0103] (d) Update the starting address of the free area in the free area meta-information to: the original starting address of the free area + the size of the recovery mode firmware partition backup header + the size of the recovery mode firmware in the recovery mode firmware partition backup header; update the length of the free area in the free area meta-information to: the original length of the free area - the size of the recovery mode firmware partition backup header - the size of the recovery mode firmware in the recovery mode firmware partition backup header.

[0104] The recovery mode firmware partition backup area consists of a recovery mode firmware partition backup header of a preset size and the recovery mode firmware. The recovery mode firmware partition backup header of a preset size consists of a preset magic number, a recovery mode firmware start address, and a recovery mode firmware size. The recovery mode firmware partition backup area meta information consists of a preset magic number and a start address of the recovery mode firmware partition backup area.

[0105] (10) Determine whether the address space of the metadata partition in the current partition table and the new partition table is the same. If different, back up the metadata partition to the metadata partition backup area, and write the metadata partition backup area meta information to the sixth preset position of the boot communication partition in the current partition table, specifically including the following (a) to (e).

[0106] (a) Determine whether the address space of the metadata partition in the current partition table and the new partition table is the same. If so, execute (11); if not, execute (b).

[0107] (b) The magic number in the metadata partition backup header is set to the preset metadata partition backup magic number; the metadata partition firmware starting address in the metadata partition backup header is set to "the free area starting address in the free area meta information + the size of the metadata partition backup header"; the metadata partition firmware size in the metadata partition backup header is set to the partition size of the metadata partition in the current partition table.

[0108] (c) Obtain the starting address and partition size of the metadata partition in the current partition table as the starting address and current metadata partition size of the current metadata partition; read the data of the current metadata partition size from the starting address of the current metadata partition, and write the read data to the starting address of the metadata partition firmware in the metadata partition backup header, and the written data size is the metadata partition firmware size in the metadata partition backup header; write the metadata partition backup header to the starting address of the free area in the free area meta information, and the written data size is the size of the metadata partition backup header.

[0109] (d) constructing metadata partition backup area meta information, and writing the metadata partition backup area meta information to the sixth preset position of the boot communication partition in the current partition table.

[0110] Specifically, the magic number in the metadata partition backup area meta-information is set to the preset metadata partition backup area meta-information magic number; the starting address of the metadata partition backup area in the metadata partition backup area meta-information is set to the free area starting address in the free area meta-information; and the constructed metadata partition backup area meta-information is written to the sixth preset position of the boot communication partition in the current partition table.

[0111] (e) The starting address of the free area in the free area meta-information is updated to: the starting address of the original free area + the size of the metadata partition backup header + the size of the metadata partition firmware in the metadata partition backup header; the length of the free area in the free area meta-information is updated to: the original length of the free area - the size of the metadata partition backup header - the size of the metadata partition firmware in the metadata partition backup header.

[0112] The metadata partition backup area meta information is composed of a preset magic number and the start address of the metadata partition backup area.

[0113] (11) Determine whether the address space of the temporary partition in the current partition table and the new partition table is the same. If different, back up the temporary partition to the temporary partition backup area, and write the temporary partition backup area meta information to the seventh preset position of the boot communication partition in the current partition table, specifically including the following (a) to (e).

[0114] (a) Check whether the address space of the temporary partition in the current partition table and the new partition table is the same. If they are the same, execute the following step (12); if they are different, execute (b).

[0115] (b) The magic number in the temporary partition backup header is set to the preset temporary partition backup magic number; the temporary partition firmware starting address in the temporary partition backup header is set to "the free area starting address in the free area metadata + the size of the temporary partition backup header"; the temporary partition firmware size in the temporary partition backup header is set to the partition size of the temporary partition in the current partition table.

[0116] (c) obtaining the starting address and partition size of the temporary partition in the current partition table as the starting address and current temporary partition size of the current temporary partition; reading the data of the current temporary partition size from the starting address of the current temporary partition, and writing the read data to the starting address of the temporary partition firmware in the temporary partition backup header, the written data size being the temporary partition firmware size in the temporary partition backup header; writing the temporary partition backup header to the starting address of the free area in the free area meta-information, the written data size being the size of the temporary partition backup header.

[0117] (d) constructing temporary partition backup area meta information, and writing the temporary partition backup area meta information into the seventh preset position of the boot communication partition in the current partition table.

[0118] Specifically, the magic number in the temporary partition backup area meta-information is set to the preset magic number of the temporary partition backup area meta-information; the starting address of the temporary partition backup area in the temporary partition backup area meta-information is set to the starting address of the free area in the free area meta-information; and the constructed temporary partition backup area meta-information is written to the seventh preset position of the boot communication partition in the current partition table.

[0119] (e) The starting address of the free area in the free area meta-information is updated to: the starting address of the original free area + the size of the temporary partition backup header + the size of the temporary partition firmware in the temporary partition backup header; the length of the free area in the free area meta-information is updated to: the length of the original free area - the size of the temporary partition backup header - the size of the temporary partition firmware in the temporary partition backup header.

[0120] The temporary partition backup area consists of a temporary partition backup header of a preset size and a temporary partition firmware. The temporary partition backup header of a preset size consists of a preset magic number, a temporary partition firmware start address, and a temporary partition firmware size. The temporary partition backup area meta information consists of a preset magic number and a start address of the temporary partition backup area.

[0121] (12) Determine whether the address space of the boot communication partition in the current partition table and the new partition table is the same. If different, back up the boot communication partition to the boot communication partition backup area, and write the boot communication partition backup area meta-information at the eighth preset position of the boot communication partition in the current partition table. At the same time, write the boot communication partition backup area meta-information at the preset position used to store the boot communication partition backup area meta-information in the boot communication partition firmware in the boot communication partition backup area, specifically including the following (a) to (e).

[0122] (a) Check whether the address space of the boot communication partition in the current partition table and the new partition table is the same. If they are the same, execute (13); if they are different, execute (b).

[0123] (b) Setting the magic number in the boot communication partition backup header to the preset boot communication partition backup magic number; setting the boot communication partition firmware starting address in the boot communication partition backup header to "the free area starting address in the free area metadata + the size of the boot communication partition backup header"; setting the boot communication partition firmware size in the boot communication partition backup header to the partition size of the boot communication partition in the current partition table.

[0124] (c) Obtain the starting address and partition size of the boot communication partition in the current partition table as the starting address and current boot communication partition size of the current boot communication partition; read the data of the current boot communication partition size from the starting address of the current boot communication partition, and write the read data to the starting address of the boot communication partition firmware in the boot communication partition backup header, and the written data size is the boot communication partition firmware size in the boot communication partition backup header; write the boot communication partition backup header to the free area starting address in the free area meta-information, and the written data size is the size of the boot communication partition backup header.

[0125] (d) Constructing the boot communication partition backup area meta-information, and writing the boot communication partition backup area meta-information to the eighth preset position of the boot communication partition in the current partition table, and at the same time writing the constructed boot communication partition backup area meta-information to the preset position used to save the boot communication partition backup area meta-information in the boot communication partition firmware in the boot communication partition backup area.

[0126] Specifically, the magic number in the boot communication partition backup area meta-information is set to the preset boot communication partition backup area meta-information magic number; the starting address of the boot communication partition backup area in the boot communication partition backup area meta-information is set to the free area starting address in the free area meta-information; the constructed boot communication partition backup area meta-information is written to the eighth preset position of the boot communication partition in the current partition table, and the constructed boot communication partition backup area meta-information is written to the preset position for storing the boot communication partition backup area meta-information in the boot communication partition firmware in the boot communication partition backup area.

[0127] (e) Update the starting address of the free area in the free area meta-information to: the original starting address of the free area + the size of the boot communication partition backup header + the size of the boot communication partition firmware in the boot communication partition backup header; update the length of the free area in the free area meta-information to: the original length of the free area - the size of the boot communication partition backup header - the size of the boot communication partition firmware in the boot communication partition backup header.

[0128] The boot communication partition backup area is composed of a boot communication partition backup header of a preset size and a boot communication partition firmware. The boot communication partition backup header of a preset size is composed of a preset magic number, a boot communication partition firmware start address and a boot communication partition firmware size. The boot communication partition backup area meta information is composed of a preset magic number and a start address of the boot communication partition backup area.

[0129] (13) The starting address of the boot program firmware partition in the current partition table is set to the boot program firmware starting address in the boot program firmware partition backup header.

[0130] (14) The starting address of the recovery mode firmware partition in the current partition table is set to the recovery mode firmware starting address in the recovery mode firmware partition backup header.

[0131] (15) When the address spaces of the metadata partition in the current partition table and the new partition table are different, the start address of the metadata partition in the current partition table is set to the metadata partition firmware start address in the metadata partition backup header.

[0132] (16) When the address spaces of the temporary partition in the current partition table and the new partition table are different, the starting address of the temporary partition in the current partition table is set to the starting address of the temporary partition firmware in the temporary partition backup header.

[0133] (17) When the address space of the boot communication partition in the current partition table and the new partition table is different, the starting address of the boot communication partition in the current partition table is set to the boot communication partition firmware starting address in the boot communication partition backup header.

[0134] (18) The updated free area metadata is written into the third preset position of the boot communication partition in the updated current partition table, and the updated current partition table is upgraded to the address space where the primary partition table and the backup partition table are located in the storage medium.

[0135] (19) Writing the third preset upgrade instruction into the first preset location of the boot communication partition.

[0136] In step 210, if the upgrade instruction information in the first preset position of the boot communication partition corresponds to the third preset upgrade instruction, the boot program firmware partition and the recovery mode firmware partition are upgraded, and when the address space of the metadata partition in the current partition table and the new partition table is different, the metadata partition firmware in the metadata partition backup area is written to the address space where the metadata partition is located in the new partition table, specifically including the following (1) to (10).

[0137] (1) Obtain the firmware partition table from the address space of the device storage partition table, and use the firmware partition table as the current partition table.

[0138] (2) Obtain a partition table file from the firmware storage area to be upgraded as a new partition table according to the metadata of the firmware storage area to be upgraded.

[0139] (3) If the current partition table and the new partition table are different, execute (4) to (10); if the current partition table and the new partition table are the same, execute (10).

[0140] (4) Obtain boot program firmware image file data from the firmware storage area to be upgraded according to the metadata of the firmware storage area to be upgraded, and write the boot program firmware image file data into the address space where the boot program firmware partition is located in the new partition table.

[0141] Specifically, the firmware storage area meta information to be upgraded is read from the ninth preset position of the boot communication partition of the current partition table, and it is checked whether the magic number in the firmware storage area meta information to be upgraded is the preset magic number. If not, the firmware upgrade process is exited; if so, an upgrade image header of a preset size is read from the starting address of the firmware storage area to be upgraded in the firmware storage area meta information to be upgraded; it is checked whether the magic number in the upgrade image header is the preset magic number. If not, the firmware upgrade process is exited; if it is the preset magic number, the boot program firmware image file item is searched from the image file item list in the upgrade image header, and data with a length of the image file size in the boot program firmware image file item is read from "the starting address of the firmware storage area to be upgraded in the firmware storage area meta information to be upgraded + the offset address of the image file in the boot program firmware image file item in the firmware storage area to be upgraded" as the boot program firmware image file data; the boot program firmware image file data is written to the address space where the boot program firmware partition is located in the new partition table.

[0142] (5) The recovery mode firmware image file data is obtained from the firmware storage area to be upgraded according to the metadata of the firmware storage area to be upgraded, and the recovery mode firmware image file data is written into the address space where the recovery mode firmware partition is located in the new partition table.

[0143] Specifically, metadata of the firmware storage area to be upgraded is read from the ninth preset position of the boot communication partition of the current partition table, and it is checked whether the magic number in the metadata of the firmware storage area to be upgraded is the preset magic number. If not, the firmware upgrade process is exited. If so, an upgrade image header of a preset size is read from the starting address of the firmware storage area to be upgraded in the metadata of the firmware storage area to be upgraded, and it is checked whether the magic number in the upgrade image header is the preset magic number. If not, the firmware upgrade process is exited. If it is the preset magic number, the recovery mode firmware image file item is searched from the image file item list in the upgrade image header, and data with a length equal to the size of the image file in the recovery mode firmware image file item is read from "the starting address of the firmware storage area to be upgraded in the metadata of the firmware storage area to be upgraded + the offset address of the image file in the recovery mode firmware image file item in the firmware storage area to be upgraded" as the recovery mode firmware image file data; the recovery mode firmware image file data is written to the address space where the recovery mode firmware partition is located in the new partition table.

[0144] (6) When the address spaces of the metadata partition in the current partition table and the new partition table are different, the metadata partition firmware in the metadata partition backup area is written to the address space where the metadata partition is located in the new partition table.

[0145] Specifically, it is determined whether the address spaces of the metadata partition in the current partition table and the new partition table are the same. If they are different, the metadata partition backup area meta information is read from the sixth preset position in the boot communication partition of the current partition table, and it is checked whether the magic number in the metadata partition backup area meta information is the preset magic number. If it is not the preset magic number, the firmware upgrade process is exited. If it is the preset magic number, a metadata partition backup header of a preset size is read from the starting address of the metadata partition backup area in the metadata partition backup area meta information; it is checked whether the magic number in the metadata partition backup header is the preset magic number. If not, the firmware upgrade process is exited. If so, data with a length equal to the size of the metadata partition firmware in the metadata partition backup header is read from the starting address of the metadata partition firmware in the metadata partition backup header as the metadata partition firmware; and the metadata partition firmware is written to the address space where the metadata partition is located in the new partition table.

[0146] (7) When the address spaces of the temporary partition in the current partition table and the new partition table are different, determine whether the size of the temporary partition in the new partition table is greater than or equal to the size of the temporary partition in the current partition table. If so, write the temporary partition firmware in the temporary partition backup area to the address space of the temporary partition in the new partition table.

[0147] Specifically, determine whether the address spaces of the temporary partition in the current partition table and the new partition table are the same. If not, check whether the temporary partition size in the new partition table is greater than or equal to the temporary partition size in the current partition table. If so, read the temporary partition backup area meta-information from the seventh preset position of the boot communication partition of the current partition table; check whether the magic number in the temporary partition backup area meta-information is the preset magic number. If not, exit the firmware upgrade process. If so, read the temporary partition backup header of the preset size from the starting address of the temporary partition backup area in the temporary partition backup area meta-information; check whether the magic number in the temporary partition backup header is the preset magic number. If not, exit the firmware upgrade process. If so, read data with a length equal to the size of the temporary partition firmware in the temporary partition backup header from the starting address of the temporary partition firmware in the temporary partition backup header as the temporary partition firmware; write the temporary partition firmware to the address space where the temporary partition is located in the new partition table.

[0148] (8) When the address space of the boot communication partition in the current partition table and the new partition table is different, all the boot communication partition data in the current partition table are written to the address space where the boot communication partition is located in the new partition table.

[0149] (9) The new partition table is upgraded to the address space where the primary partition table and the backup partition table are located in the storage medium, and the new partition table is used as the current partition table.

[0150] (10) Determine whether there is legal block list description file backup area metadata in the boot communication partition of the current partition table, and whether there is legal block list description file backup header in the block list description file backup area. If both exist, write the fifth preset upgrade instruction into the first preset position of the boot communication partition. If both do not exist, write the fourth preset upgrade instruction into the first preset position of the boot communication partition, which specifically includes the following (a) to (b).

[0151] (a) Reading the block list description file backup area meta information from the tenth preset position of the boot communication partition of the current partition table, and checking whether the magic number in the block list description file backup area meta information is the preset magic number, if not, writing the fourth preset upgrade instruction to the first preset position of the boot communication partition, if yes, reading the block list description file backup header of the preset size from the starting address of the block list description file backup area in the block list description file backup area meta information.

[0152] (b) Check whether the magic number in the block list description file backup header is the preset magic number. If not, write the fourth preset upgrade instruction into the first preset position of the boot communication partition. If not, write the fifth preset upgrade instruction into the first preset position of the boot communication partition.

[0153] In step 211, if the upgrade instruction information in the first preset position of the boot communication partition corresponds to the fifth preset upgrade instruction, the boot recovery mode firmware is loaded and the recovery mode firmware is run.

[0154] In some embodiments, running the recovery mode firmware may specifically include the following (1) to (5).

[0155] (1) reading the upgrade instruction information in the first preset position of the guide communication partition;

[0156] (2) Determine whether the upgrade instruction information is the first preset upgrade instruction, the fifth preset upgrade instruction or the sixth preset upgrade instruction. If not, exit the firmware upgrade process. If so, use the upgrade instruction information as the current upgrade instruction.

[0157] (3) If the current upgrade instruction is the first preset upgrade instruction, mount the temporary storage partition, and read the firmware upgrade package under the preset path of the preset encrypted user data partition according to the block list description file under the preset path of the temporary storage partition; read all files in the firmware upgrade package, and save all files to the firmware storage area to be upgraded according to the preset storage structure; if the new temporary storage partition is smaller than the old temporary storage partition, back up the block list description file under the preset path of the temporary storage partition to the block list description file backup area, and at the same time construct the block list description file backup area metadata, and write the block list description file backup area metadata to the tenth preset position of the boot communication partition; construct the firmware storage area metadata, and write the firmware storage area metadata to the ninth preset position of the boot communication partition; construct the free area metadata, and write the free area metadata to the third preset position of the boot communication partition; write the second preset upgrade instruction at the first preset position of the boot communication partition, and restart the device, specifically including the following (a) to (p).

[0158] (a) obtaining a partition start address of a storage area for firmware to be upgraded from a command line parameter as the start address of the storage area for firmware to be upgraded, obtaining a temporary partition size from a command line parameter as the old temporary partition size, obtaining an initial size of data to be backed up from a command line parameter as the initial size of data to be backed up, obtaining a header size of data to be backed up from a command line parameter as the header size of data to be backed up, and obtaining a start address of an encrypted user data partition from a command line parameter as the start address of a user data partition.

[0159] (b) constructing an upgrade image header of a preset size; the upgrade image header includes a preset magic number and an image file item list of a preset size; each image file item in the image file item list includes an image file partition name, an offset address of the image file in the firmware storage area to be upgraded, and an image file size.

[0160] (c) Set the magic number of the upgrade image header to the preset magic number.

[0161] (d) Mount the temporary partition, and read the firmware upgrade package under the preset path of the preset encrypted user data partition according to the block list description file under the preset path of the temporary partition, and calculate the sum of the sizes of all files in the firmware upgrade package as the total size of the files to be upgraded; read the partition table file with a preset name in the firmware upgrade package file under the preset path of the preset encrypted user data partition according to the block list description file under the preset path of the temporary partition, and obtain the first partition after the preset partition list from the partition table file with the preset name as the comparison partition; determine whether the starting address of the comparison partition is greater than the starting address of the firmware storage area to be upgraded, and if so, update the starting address of the firmware storage area to be upgraded to the starting address of the comparison partition, and use "user data partition starting address - firmware storage area starting address to be upgraded" as the available space size; if the size of the new temporary partition is greater than or equal to the size of the old temporary partition, determine "the starting address of the preset size". Whether "upgrade image header + total size of files to be upgraded + initial size of data to be backed up + header size of data to be backed up + temporary partition backup header of preset size + old temporary partition size" is greater than the size of available space; if so, exit the firmware upgrade process and clear the upgrade instruction information in the first preset position of the boot communication partition; if the new temporary partition size is smaller than the old temporary partition size, the size of the block list description file under the preset path of the temporary partition is used as the block list description file size, and judge whether "preset size upgrade image header + total size of files to be upgraded + initial size of data to be backed up + header size of data to be backed up + temporary partition backup header of preset size + old temporary partition size + block list description file backup header of preset size + block list description file size" is greater than the size of available space; if so, exit the firmware upgrade process and clear the upgrade instruction information in the first preset position of the boot communication partition.

[0162] (e) reading a partition table file with a preset name in a firmware upgrade package file under a preset path of a preset encrypted user data partition according to a block list description file (such as / cache / recovery / block.map) under a preset path of a temporary partition; using the first image file item in the image file item list of the upgrade image header as the partition table image file item, and using the preset name of the partition table file as the image file partition name of the partition table image file item, using the size of the upgrade image header as the offset address of the image file of the partition table image file item in the firmware storage area to be upgraded, and using the size of the partition table file as the image file size of the partition table image file item; writing the partition table file with the preset name to the offset address of the image file of the partition table image file item in the firmware storage area to be upgraded, and the data write size is the image file size of the partition table image file item.

[0163] (f) traversing each firmware image file to be upgraded in the firmware upgrade package under the preset path of the preset encrypted user data partition in a preset order according to the block list description file under the preset path of the temporary partition; for each firmware image file to be upgraded that is read, updating the corresponding image file item in the image file item list of the upgrade image header in a sequential order starting from the second image file item in the image file item list of the upgrade image header, and at the same time writing the corresponding firmware image file to be upgraded to the offset address of the image file of the corresponding image file item in the firmware storage area to be upgraded, and the data write size is the size of the corresponding image file.

[0164] Specifically, for each firmware image file to be upgraded that is read: the corresponding image file item in the image file item list in the upgrade image header is used as the current image file item; the file name prefix of the firmware image file to be upgraded is obtained as the image file partition name of the current image file item; the size of the firmware image file to be upgraded is obtained as the image file size as the image file size of the current image file item; the "offset address of the image file in the firmware to be upgraded storage area + the image file size" of the previous image file item of the current image file item is used as the offset address of the image file of the current image file item in the firmware to be upgraded storage area; the corresponding firmware image file to be upgraded is written to the offset address of the image file of the current image file item in the firmware to be upgraded storage area, and the data write size is the image file size of the current image file item.

[0165] (g) Writing the upgrade image header of a preset size to the starting address of the firmware storage area to be upgraded.

[0166] (h) Obtain a partition table file with a preset name in the firmware upgrade package file under the preset path of the preset encrypted user data partition, and obtain the size of the temporary partition from the partition table file as the new temporary partition size; use "the starting address of the firmware storage area to be upgraded + the upgrade image header of the preset size + the total size of the file to be upgraded" as the starting address of the free area; use "the starting address of the user data partition - the starting address of the free area" as the length of the free area.

[0167] (i) If the new scratch partition size is greater than or equal to the old scratch partition size, execute (n); otherwise, execute (j) to (p).

[0168] (j) The magic number in the block list description file backup header is set to the preset block list description file backup magic number; the block list description file start address in the block list description file backup header is set to "the free area start address + the size of the block list description file backup header"; the block list description file size in the block list description file backup header is set to the calculated size of the block list description file under the preset path of the temporary partition.

[0169] (k) writing the block list description file under the preset path of the temporary partition to the starting address of the block list description file in the backup header of the block list description file, and the written data size is the size of the block list description file in the backup header of the block list description file; writing the backup header of the block list description file to the starting address of the free area, and the written data size is the size of the backup header of the block list description file.

[0170] (l) Constructing the block list description file backup area meta information, and writing the block list description file backup area meta information to the tenth preset position of the boot communication partition.

[0171] Specifically, the magic number in the block list description file backup area meta-information is set to the preset block list description file backup area meta-information magic number; the starting address of the block list description file backup area in the block list description file backup area meta-information is set to the starting address of the free area; and the constructed block list description file backup area meta-information is written to the tenth preset position of the boot communication partition.

[0172] (m) Update the starting address of the free area to: the starting address of the original free area + the size of the backup header of the block list description file + the size of the block list description file; update the length of the free area to: the length of the original free area - the size of the backup header of the block list description file - the size of the block list description file.

[0173] The block list description file backup area consists of a block list description file backup header of a preset size and a block list description file. The block list description file backup header of a preset size consists of a preset magic number, a block list description file start address, and a block list description file size. The block list description file backup area meta information consists of a preset magic number and a start address of the block list description file backup area.

[0174] (n) constructing metadata of the storage area of ​​the firmware to be upgraded, and writing the metadata of the storage area of ​​the firmware to be upgraded into a ninth preset position of the boot communication partition, wherein the metadata of the storage area of ​​the firmware to be upgraded is composed of a preset magic number and a starting address of the storage area of ​​the firmware to be upgraded.

[0175] Specifically, the magic number in the metadata of the firmware storage area to be upgraded is set as the preset magic number of the metadata of the firmware storage area to be upgraded; the starting address of the firmware storage area to be upgraded in the metadata of the firmware storage area to be upgraded is set as the starting address of the firmware storage area to be upgraded; and the constructed metadata of the firmware storage area to be upgraded is written to the ninth preset position of the boot communication partition.

[0176] (o) constructing free area meta information, and writing the free area meta information into a third preset position of the boot communication partition; the free area meta information includes a preset magic number, a free area start address and a free area length.

[0177] Specifically, the magic number in the free area meta-information is set to be the preset free area meta-information magic number; the free area start address and free area length in the free area meta-information are set to be the free area start address and free area length calculated above, respectively.

[0178] (p) Writing a second preset upgrade instruction into the first preset position of the boot communication partition and restarting the device.

[0179] (4) If the current upgrade instruction is the fifth preset upgrade instruction, the current temporary partition is formatted and then mounted; the block list description file backup area metadata is read from the tenth preset position of the boot communication partition, and it is determined whether the magic number in the block list description file backup area metadata is the preset block list description file backup area metadata magic number; if so, a block list description file backup header of a preset size is read from the starting address of the block list description file backup area in the block list description file backup area metadata; if the magic number in the block list description file backup header is the preset magic number, a new empty block list description file is created under the preset path of the temporary partition, and starting from the block list description file starting address in the block list description file backup header, data of a size equal to the block list description file size in the block list description file backup header is read and saved to the empty block list description file; the fourth preset upgrade instruction is written to the first preset position of the boot communication partition, and the device is restarted, specifically including the following (a) to (c).

[0180] (a) After formatting the current temporary partition, mount the temporary partition; read the block list description file backup area metadata from the tenth preset position of the boot communication partition, and determine whether the magic number in the block list description file backup area metadata is the preset block list description file backup area metadata magic number, if not, exit the firmware upgrade process, if so, execute (b).

[0181] (b) Reading a block list description file backup header of a preset size from the starting address of the block list description file backup area in the block list description file backup area metadata, and determining whether the magic number in the block list description file backup header is a preset magic number; if not, exiting the firmware upgrade process; if yes, executing (c).

[0182] (c) Create a new empty block list description file (such as / cache / recovery / block.map) under the preset path of the temporary partition, and start from the block list description file start address in the block list description file backup header, read data with a size of the block list description file size in the block list description file backup header and save it to the empty block list description file; write the fourth preset upgrade instruction at the first preset position of the boot communication partition, and restart the device.

[0183] (5) If the current upgrade instruction is the sixth preset upgrade instruction, the partition starting address of the firmware storage area to be upgraded is obtained from the command line parameters as the starting address of the firmware storage area to be upgraded, and the temporary storage partition is mounted; the firmware upgrade package under the preset path of the preset encrypted user data partition is read according to the block list description file under the preset path of the temporary storage partition, and all files in the firmware upgrade package are read; all files are saved to the firmware storage area to be upgraded according to the preset storage structure; metadata of the firmware storage area to be upgraded is constructed, and the metadata of the firmware storage area to be upgraded is written to the ninth preset position of the boot communication partition; the fourth preset upgrade instruction is written to the first preset position of the boot communication partition, and the device is restarted, specifically including the following (a) to (g).

[0184] (a) Obtaining the partition start address of the firmware storage area to be upgraded from the command line parameters as the start address of the firmware storage area to be upgraded.

[0185] (b) Build an upgrade image header of a preset size.

[0186] (c) Set the magic number of the upgrade image header to the preset magic number.

[0187] (d) Mounting the temporary partition, and reading the partition table file with a preset name in the firmware upgrade package under the preset path of the preset encrypted user data partition according to the block list description file under the preset path of the temporary partition; using the first image file item in the image file item list of the upgrade image header as the partition table image file item; using the preset name of the partition table file as the image file partition name of the partition table image file item; using the size of the upgrade image header as the offset address of the image file of the partition table image file item in the firmware storage area to be upgraded; using the size of the partition table file as the image file size of the partition table image file item; writing the partition table file with the preset name to the offset address of the image file of the partition table image file item in the firmware storage area to be upgraded, and the data write size is the image file size of the partition table image file item.

[0188] (e) traversing each firmware image file to be upgraded in the firmware upgrade package under the preset path of the preset encrypted user data partition in a preset order according to the block list description file under the preset path of the temporary partition; for each firmware image file to be upgraded that is read, updating the corresponding image file item in the image file item list of the upgrade image header in a sequential order starting from the second image file item in the image file item list of the upgrade image header, and at the same time writing the corresponding firmware image file to be upgraded to the offset address of the image file of the corresponding image file item in the firmware storage area to be upgraded, and the data write size is the size of the corresponding image file.

[0189] Specifically, for each firmware image file to be upgraded that is read: the corresponding image file item in the image file item list of the upgrade image header is used as the current image file item; the file name prefix of the firmware image file to be upgraded is obtained as the image file partition name of the current image file item; the size of the firmware image file to be upgraded is obtained as the image file size as the image file size of the current image file item; the "offset address of the image file in the firmware to be upgraded storage area + the image file size" of the previous image file item of the current image file item is used as the offset address of the image file of the current image file item in the firmware to be upgraded storage area; the corresponding firmware image file to be upgraded is written to the offset address of the image file of the current image file item in the firmware to be upgraded storage area, and the data write size is the image file size of the current image file item; the upgrade image header of the preset size is written to the starting address of the firmware storage area to be upgraded.

[0190] (f) constructing the metadata of the storage area of ​​the firmware to be upgraded, and writing the metadata of the storage area of ​​the firmware to be upgraded to the ninth preset position of the boot communication partition.

[0191] Specifically, the magic number in the metadata of the firmware storage area to be upgraded is set as the preset magic number of the metadata of the firmware storage area to be upgraded; the starting address of the firmware storage area to be upgraded in the metadata of the firmware storage area to be upgraded is set as the starting address of the firmware storage area to be upgraded; and the constructed metadata of the firmware storage area to be upgraded is written to the ninth preset position of the boot communication partition.

[0192] (g) Writing a fourth preset upgrade instruction into the first preset position of the boot communication partition and restarting the device.

[0193] In step 212, if the upgrade instruction information in the first preset position of the boot communication partition corresponds to the fourth preset upgrade instruction, then the other firmware except the boot program firmware and the recovery mode firmware are upgraded, specifically including the following (1) to (8).

[0194] (1) Obtain the firmware partition table from the address space of the device storage partition table, and use the firmware partition table as the current partition table.

[0195] (2) Read the metadata of the firmware storage area to be upgraded from the ninth preset position in the boot communication partition of the current partition table, and determine whether the magic number in the metadata of the firmware storage area to be upgraded is the preset magic number. If not, exit the firmware upgrade process. If yes, read the upgrade image header of the preset size from the starting address of the firmware storage area to be upgraded in the metadata of the firmware storage area to be upgraded.

[0196] (3) Determine whether the magic number in the upgrade image header is a preset magic number. If not, write the sixth preset upgrade instruction into the first preset position of the boot communication partition. If it is the preset magic number, obtain other firmware image file data except the boot program firmware image file data and the recovery mode firmware image file data from the firmware storage area to be upgraded in sequence according to the metadata of the firmware storage area to be upgraded, and save all other firmware image file data into the reserved space of the dynamic random access memory.

[0197] Specifically, the other firmware image file items except the partition table image file item, the boot program firmware image file item and the recovery mode firmware image file item are searched in turn from the image file item list in the upgrade image header. For each firmware image file item to be processed, from "the starting address of the firmware storage area to be upgraded in the metadata of the firmware storage area to be upgraded + the offset address of the image file in the firmware image file item to be processed in the firmware storage area to be upgraded", data with a length equal to the size of the image file in the firmware image file item to be processed is read as the firmware image file data to be processed into the reserved space of the dynamic random access memory.

[0198] (4) Write the other firmware image file data in the reserved space into the address space where the corresponding firmware partition is located in the new partition table.

[0199] Specifically, the firmware image file data to be processed in the reserved space is written into the address space where the corresponding firmware partition is located in the new partition table.

[0200] (5) Clear the metadata of the firmware storage area to be upgraded, the free area metadata, the block list description file backup area metadata, the boot program firmware partition backup area metadata, the recovery mode firmware partition backup area metadata, the metadata partition backup area metadata, the temporary partition backup area metadata and the boot communication partition backup area metadata in the boot communication partition of the current partition table.

[0201] (6) Clear the upgrade instruction information in the first preset position of the current partition table.

[0202] (7) Writing a preset upgrade completion mark at a second preset position in the boot communication partition of the current partition table.

[0203] (8) Restart the device to enter the upgraded system.

[0204] In step 213, if the upgrade instruction information in the first preset position of the boot communication partition corresponds to the sixth preset upgrade instruction, the firmware partition table is obtained from the address space of the device storage partition table, and the firmware partition table is used as the current partition table; the first partition after the preset partition list in the current partition table is used as the firmware storage area to be upgraded, the firmware storage area to be upgraded is not the preset encrypted user data partition, and the preset partition list includes the boot program firmware partition, the recovery mode firmware partition, the boot communication partition, the metadata partition and the temporary partition; the partition starting address of the firmware storage area to be upgraded is written into the command line parameter; the boot recovery mode firmware is loaded, and the command line parameters are passed to the recovery mode firmware; and the recovery mode firmware is run.

[0205] 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.

[0206] In summary, the method for upgrading firmware and the electronic device provided by the present invention back up data including the metadata partition according to the first preset upgrade instruction and the second preset upgrade instruction. When the address space of the metadata partition in the current partition table and the new partition table is different, the metadata partition firmware in the metadata partition backup area is written into the address space where the metadata partition is located in the new partition table according to the third preset upgrade instruction. In this way, even if the address space of the metadata partition where the user data partition encryption key is stored changes before and after the upgrade, the data in the user data partition can be retained after the upgrade. Moreover, since the boot communication partition, the metadata partition, the boot program firmware partition, the recovery mode firmware partition and the temporary storage partition have been backed up, during the upgrade process, even if there is a change in the address space of the metadata partition where the user data partition encryption key is stored before and after the upgrade, the data in the user data partition can be retained. Accidental power failure will not destroy the data in the backup partition, ensuring that any accident at any time during the upgrade process will not cause the device to become bricked, thereby improving the reliability of firmware upgrades, and the data in the encrypted user data partition is still retained after the upgrade; in addition, since the boot program firmware partition, recovery mode firmware partition, metadata partition, temporary partition and boot communication partition in the current partition table have already pointed to the corresponding backup partitions respectively, and the firmware storage area to be upgraded and all backup partitions are all located after the boot program firmware partition, recovery mode firmware partition, boot communication partition, metadata partition and temporary partition in the new and old partition tables, in the subsequent upgrade process, even if an accidental power failure occurs, the data in the backup partition will not be destroyed, and the upgrade can be continued after power-on.

[0207] 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: In the boot program firmware of the device, read the upgrade instruction information in the first preset location for storing the upgrade instruction in the boot communication partition; In a first stage in which the upgrade instruction information corresponds to a first preset upgrade instruction, command line parameters are determined based on a partition start address of a storage area of ​​the firmware to be upgraded, a size of a preset temporary storage partition, an initial size of data to be backed up, a header size of data to be backed up, and a start address of a preset encrypted user data partition, and the command line parameters are passed to the recovery mode firmware, wherein the data to be backed up includes a boot communication partition, a metadata partition, a boot program firmware partition, and a recovery mode firmware partition; In the second stage corresponding to the upgrade instruction information and the second preset upgrade instruction, after backing up the data to be backed up and the temporary partition, updating the current partition table so that the boot program firmware partition, the recovery mode firmware partition, the metadata partition, the temporary partition and the boot communication partition in the current partition table respectively point to the corresponding backup partitions, and upgrading the updated current partition table to the address space where the primary partition table and the address space where the backup partition table are located in the storage medium; In the third stage where the upgrade instruction information corresponds to the third preset upgrade instruction, the boot program firmware partition and the recovery mode firmware partition are upgraded, and when the address spaces of the metadata partition in the current partition table and the new partition table are different, the metadata partition firmware in the metadata partition backup area is written into the address space where the metadata partition is located in the new partition table; as well as In the fourth stage where the upgrade instruction information corresponds to a fourth preset upgrade instruction, other firmware except the boot program firmware and the recovery mode firmware are upgraded.

2. The method according to claim 1, characterized in that Also includes: Save the firmware upgrade package to be upgraded to the preset path of the user data partition; Generate a block list occupied by the firmware upgrade package, decrypt the block data in the block list, rewrite the decrypted block data into the corresponding block, and save the corresponding block list into a block list description file under a preset path of the temporary storage partition; as well as The first preset upgrade instruction is written into the first preset position in the boot communication partition, and then the device is restarted.

3. The method according to claim 2, characterized in that Also includes: In the recovery mode firmware, reading the upgrade instruction information in the first preset location in the boot communication partition; If the upgrade instruction information corresponds to the first preset upgrade instruction, mounting the temporary storage partition; Reading a firmware upgrade package under a preset path of an encrypted user data partition according to a block list description file under a preset path of the temporary storage partition, and saving all files read from the firmware upgrade package to a firmware storage area to be upgraded according to a preset storage structure; Constructing metadata of the firmware storage area to be upgraded and writing it to a ninth preset position in the boot communication partition, and constructing metadata of the free area and writing it to a third preset position in the boot communication partition; as well as The second preset upgrade instruction is written into the first preset position in the boot communication partition, and then the device is restarted.

4. The method according to claim 3, characterized in that Also includes: If the current partition table already points to the backup partition, setting the current upgrade instruction to the third preset upgrade instruction; as well as The third preset upgrade instruction is written into the first preset position in the boot communication partition of the current partition table.

5. The method according to claim 4, characterized in that Also includes: Loading boot recovery mode firmware and passing command line parameters to the recovery mode firmware; Format the current temporary partition and create a new empty block list description file in the preset path of the temporary partition; Starting from the block list description file start address in the block list description file backup header, read data of a size equal to the block list description file size in the block list description file backup header and save it to a newly created block list description file under a preset path of the temporary storage partition; as well as The fourth preset upgrade instruction is written into the first preset position in the boot communication partition, and then the device is restarted.

6. The method according to claim 4, characterized in that Also includes: Loading boot recovery mode firmware and passing command line parameters to the recovery mode firmware; Reading a firmware upgrade package under a preset path of an encrypted user data partition according to a block list description file under a preset path of the temporary storage partition, and saving all files read from the firmware upgrade package to a firmware storage area to be upgraded according to a preset storage structure; Constructing metadata of the firmware storage area to be upgraded and writing it to a ninth preset position in the boot communication partition; as well as The fourth preset upgrade instruction is written into the first preset position in the boot communication partition, and then the device is restarted.

7. The method according to claim 4, characterized in that Also includes: If there is no legal block list description file backup area meta information and block list description file backup area, setting the current upgrade instruction to the fourth preset upgrade instruction; as well as The fourth preset upgrade instruction is written into the first preset position in the boot communication partition of the current partition table.

8. The method according to claim 1, characterized in that: Also includes: A firmware upgrade package is constructed, wherein the firmware upgrade package includes all firmware image files to be upgraded including a boot program firmware image file and a recovery mode firmware image file and a partition table file with a preset name.

9. The method according to claim 1, characterized in that: Also includes: Determine whether there is a preset upgrade completion mark at the second preset position of the guide communication partition; If it exists, output upgrade success information, delete the firmware upgrade package under the preset path of the preset encrypted user data partition, and clear the upgrade completion mark in the second preset position of the boot communication partition; If not, periodically determine whether there is a new firmware upgrade package to be upgraded; If yes, then obtaining the firmware upgrade package to be upgraded, and saving the firmware upgrade package to be upgraded to a preset path of the preset encrypted user data partition; Performing a validity check on the firmware upgrade package to be upgraded; If the legality check is illegal, the firmware upgrade package under the preset path of the preset encrypted user data partition is deleted, and the firmware upgrade process is exited; If the legality check is legal, a block list occupied by the firmware upgrade package under the preset path of the preset encrypted user data partition is generated through a preset decryption service, and the block data in the block list is decrypted to obtain the decrypted data; Rewriting the decrypted data into the corresponding block, and saving the corresponding block list into the block list description file under the preset path of the temporary partition; as well as The first preset upgrade instruction is written into the first preset position of the boot communication partition, and the device is restarted.

10. The method according to claim 1, characterized in that Determining the command line parameters based on the partition start address of the firmware storage area to be upgraded, the size of the preset temporary partition, the initial size of the data to be backed up, the header size of the data to be backed up, and the start address of the preset encrypted user data partition includes: Obtaining a firmware partition table from the address space of the device storage partition table, and using the firmware partition table as the current partition table; The first partition after the preset partition list in the current partition table is used as a firmware storage area to be upgraded, wherein the firmware storage area to be upgraded is not a preset encrypted user data partition, and the preset partition list includes the boot program firmware partition, the recovery mode firmware partition, the boot communication partition, the metadata partition, and the temporary storage partition; Writing the partition start address of the firmware storage area to be upgraded into the command line parameter; Obtaining a preset temporary partition size from the current partition table, and writing the preset temporary partition size into the command line parameter; Acquire the size of the boot communication partition, the size of the metadata partition, the size of the boot program firmware partition, and the size of the recovery mode firmware partition from the current partition table respectively, and add the size of the boot communication partition, the size of the metadata partition, the size of the boot program firmware partition, and the size of the recovery mode firmware partition to obtain the initial size of the data to be backed up; Writing the initial size of the data to be backed up into the command line parameter; Adding a preset size of a boot communication partition backup header, a preset size of a metadata partition backup header, a preset size of a boot program firmware partition backup header, and a preset size of a recovery mode firmware partition backup header to obtain a header size of the data to be backed up, and writing the header size of the data to be backed up into the command line parameter; and The starting address of the preset encrypted user data partition is obtained from the current partition table, and the starting address of the preset encrypted user data partition is written into the command line parameter.

11. The method according to claim 1, characterized in that After backing up the data to be backed up and the temporary partition, updating the current partition table so that the boot program firmware partition, the recovery mode firmware partition, the metadata partition, the temporary partition and the boot communication partition in the current partition table respectively point to the corresponding backup partitions, and upgrading the updated current partition table to the address space where the main partition table and the address space where the backup partition table are located in the storage medium includes: Obtaining a firmware partition table from the address space of the device storage partition table, and using the firmware partition table as the current partition table; Acquire a partition table file from the firmware storage area to be upgraded as a new partition table according to the metadata of the firmware storage area to be upgraded; Set the initial value of the flag that the current partition table has pointed to the backup area to false; Determine whether the backup of all backup areas including the boot program firmware partition backup area, the recovery mode firmware partition backup area, the metadata partition backup area, the temporary storage partition backup area and the boot communication partition backup area has been completed, and whether the boot program firmware partition, the recovery mode firmware partition, the metadata partition, the temporary storage partition and the boot communication partition in the current partition table have respectively pointed to the corresponding backup partitions; If both are true, then setting the flag that the current partition table has pointed to the backup area to true; Determine whether the flag that the current partition table has pointed to the backup area is true; If true, writing a third preset upgrade instruction into the first preset location of the boot communication partition; and If it is not true, after backing up the boot program firmware partition, the recovery mode firmware partition, the metadata partition, the temporary partition and the boot communication partition, update the current partition table so that the boot program firmware partition, the recovery mode firmware partition, the metadata partition, the temporary partition and the boot communication partition in the current partition table point to the corresponding backup partitions respectively, and upgrade the updated current partition table to the address space where the main partition table and the address space where the backup partition table are located in the storage medium.

12. The method according to claim 11, characterized in that After backing up the boot program firmware partition, the recovery mode firmware partition, the metadata partition, the temporary storage partition, and the boot communication partition, updating the current partition table so that the boot program firmware partition, the recovery mode firmware partition, the metadata partition, the temporary storage partition, and the boot communication partition in the current partition table respectively point to the corresponding backup partitions, and upgrading the updated current partition table to the address space where the primary partition table and the address space where the backup partition table are located in the storage medium includes: Obtaining the starting address and partition size of the recovery mode firmware partition from the new partition table as the starting address and partition size of the new recovery mode firmware; Reading the free area meta information from the third preset position of the guided communication partition, and determining whether the magic number in the free area meta information is a preset magic number; If not, exit the firmware upgrade process; If yes, determining whether the address obtained by adding the starting address of the new recovery mode firmware and the partition size of the new recovery mode firmware is greater than the starting address of the free area in the free area meta information; If it is greater, then exit the firmware upgrade process; If not, backing up the boot program firmware partition to the boot program firmware partition backup area, and writing the boot program firmware partition backup area meta information in the fourth preset position of the boot communication partition in the current partition table; Backing up the recovery mode firmware partition to the recovery mode firmware partition backup area, and writing the recovery mode firmware partition backup area meta information in the fifth preset position of the boot communication partition in the current partition table; Determine whether the address space of the metadata partition in the current partition table and the new partition table is the same; If they are different, backing up the metadata partition to the metadata partition backup area, and writing metadata partition backup area meta information in the sixth preset position of the boot communication partition in the current partition table; Determine whether the address space of the temporary partition in the current partition table and the new partition table is the same; If they are different, backing up the temporary partition to the temporary partition backup area, and writing the temporary partition backup area meta information into the seventh preset position of the boot communication partition in the current partition table; Determine whether the address space of the boot communication partition in the current partition table and the new partition table is the same; If they are different, backing up the boot communication partition to the boot communication partition backup area, and writing the boot communication partition backup area meta information in the eighth preset position of the boot communication partition in the current partition table, and writing the boot communication partition backup area meta information in the preset position for storing the boot communication partition backup area meta information in the boot communication partition firmware in the boot communication partition backup area; Setting the starting address of the boot program firmware partition in the current partition table to the boot program firmware starting address in the boot program firmware partition backup header; Setting the starting address of the recovery mode firmware partition in the current partition table to the recovery mode firmware starting address in the recovery mode firmware partition backup header; When the address spaces of the metadata partition in the current partition table and the new partition table are different, setting the start address of the metadata partition in the current partition table to the metadata partition firmware start address in the metadata partition backup header; When the address spaces of the temporary partition in the current partition table and the new partition table are different, setting the starting address of the temporary partition in the current partition table to the starting address of the temporary partition firmware in the temporary partition backup header; When the address spaces of the boot communication partition in the current partition table and the new partition table are different, setting the starting address of the boot communication partition in the current partition table to the boot communication partition firmware starting address in the boot communication partition backup header; Writing the updated free area meta-information into the third preset position of the boot communication partition in the updated current partition table, and upgrading the updated current partition table to the address space where the primary partition table and the backup partition table are located in the storage medium; and Writing a third preset upgrade instruction into the first preset location of the boot communication partition.

13. The method according to claim 1, characterized in that The boot program firmware partition and the recovery mode firmware partition are upgraded, and when the address spaces of the metadata partition in the current partition table and the new partition table are different, the metadata partition firmware in the metadata partition backup area is written into the address space where the metadata partition is located in the new partition table, comprising: Obtaining a firmware partition table from the address space of the device storage partition table, and using the firmware partition table as the current partition table; Acquire a partition table file from the firmware storage area to be upgraded as a new partition table according to the metadata of the firmware storage area to be upgraded; If the current partition table and the new partition table are different, obtaining boot program firmware image file data from the firmware storage area to be upgraded according to the metadata of the firmware storage area to be upgraded, and writing the boot program firmware image file data into the address space where the boot program firmware partition is located in the new partition table; Acquire recovery mode firmware image file data from the firmware storage area to be upgraded according to the metadata of the firmware storage area to be upgraded, and write the recovery mode firmware image file data into the address space where the recovery mode firmware partition is located in the new partition table; When the address spaces of the metadata partition in the current partition table and the new partition table are different, writing the metadata partition firmware in the metadata partition backup area into the address space where the metadata partition is located in the new partition table; When the address spaces of the temporary partition in the current partition table and the new partition table are different, determining whether the size of the temporary partition in the new partition table is greater than or equal to the size of the temporary partition in the current partition table; If yes, then write the temporary partition firmware in the temporary partition backup area into the address space where the temporary partition is located in the new partition table; When the address spaces of the boot communication partition in the current partition table and the new partition table are different, all the boot communication partition data in the current partition table are written into the address space where the boot communication partition is located in the new partition table; Upgrading the new partition table to the address space where the primary partition table and the backup partition table are located in the storage medium, and using the new partition table as the current partition table; If the current partition table and the new partition table are the same, determining whether there is legal block list description file backup area meta information in the boot communication partition of the current partition table, and whether there is legal block list description file backup header in the block list description file backup area; If both exist, writing the fifth preset upgrade instruction into the first preset position of the guide communication partition; and If not all of them exist, then a fourth preset upgrade instruction is written into the first preset location of the boot communication partition.

14. The method according to claim 1, characterized in that Upgrading other firmware except the boot program firmware and the recovery mode firmware includes: Obtaining a firmware partition table from the address space of the device storage partition table, and using the firmware partition table as the current partition table; Reading the to-be-upgraded firmware storage area meta information from a ninth preset position in the boot communication partition of the current partition table, and determining whether the magic number in the to-be-upgraded firmware storage area meta information is a preset magic number; If not, exit the firmware upgrade process; If yes, read the upgrade image header of a preset size from the start address of the firmware storage area to be upgraded in the firmware storage area to be upgraded meta information; Determine whether the magic number in the upgrade image header is a preset magic number; If it is not the preset magic number, writing the sixth preset upgrade instruction into the first preset position of the guide communication partition; If it is a preset magic number, then other firmware image file data except the boot program firmware image file data and the recovery mode firmware image file data are obtained from the firmware storage area to be upgraded in sequence according to the metadata of the firmware storage area to be upgraded, and all the other firmware image file data are saved to the reserved space of the dynamic random access memory; Writing the other firmware image file data in the reserved space into the address space of the corresponding firmware partition in the new partition table; Clear the to-be-upgraded firmware storage area meta-information, free area meta-information, block list description file backup area meta-information, boot program firmware partition backup area meta-information, recovery mode firmware partition backup area meta-information, metadata partition backup area meta-information, temporary partition backup area meta-information and boot communication partition backup area meta-information in the boot communication partition of the current partition table; Clearing the upgrade instruction information in the first preset position of the current partition table; Writing a preset upgrade completion mark at a second preset position in the boot communication partition of the current partition table; and Restart the device to enter the upgraded system.

15. The method according to claim 1, characterized in that Also includes: If the upgrade instruction information in the first preset position of the boot communication partition corresponds to the fifth preset upgrade instruction, the recovery mode firmware is loaded and booted, and the recovery mode firmware is run.

16. The method according to claim 1, characterized in that Also includes: If the upgrade instruction information in the first preset position of the boot communication partition corresponds to the sixth preset upgrade instruction, obtaining a firmware partition table from the address space of the device storage partition table, and using the firmware partition table as the current partition table; The first partition after the preset partition list in the current partition table is used as a firmware storage area to be upgraded, wherein the firmware storage area to be upgraded is not a preset encrypted user data partition, and the preset partition list includes the boot program firmware partition, the recovery mode firmware partition, the boot communication partition, the metadata partition, and the temporary storage partition; Writing the partition start address of the firmware storage area to be upgraded into the command line parameter; Loading and booting the recovery mode firmware, and passing the command line parameters to the recovery mode firmware; as well as Run the recovery mode firmware.

17. The method according to claim 15 or 16, characterized in that Running the recovery mode firmware includes: Reading the upgrade instruction information in the first preset position of the guide communication partition; Determining whether the upgrade instruction information is the first preset upgrade instruction, the fifth preset upgrade instruction, or the sixth preset upgrade instruction; If not, exit the firmware upgrade process; If yes, the upgrade instruction information is used as the current upgrade instruction; If the current upgrade instruction is the first preset upgrade instruction, the temporary storage partition is mounted, and the firmware upgrade package under the preset path of the preset encrypted user data partition is read according to the block list description file under the preset path of the temporary storage partition; Read all files in the firmware upgrade package, and save all files to the firmware to be upgraded storage area according to a preset storage structure; If the new temporary storage partition is smaller than the old temporary storage partition, backing up the block list description file under the preset path of the temporary storage partition to the block list description file backup area, constructing the block list description file backup area meta information, and writing the block list description file backup area meta information to the tenth preset position of the boot communication partition; Constructing metadata of a storage area for firmware to be upgraded, and writing the metadata of the storage area for firmware to be upgraded into a ninth preset position of the boot communication partition; Constructing free area meta information, and writing the free area meta information into a third preset position of the guided communication partition; Writing a second preset upgrade instruction in the first preset position of the boot communication partition, and restarting the device; If the current upgrade instruction is the fifth preset upgrade instruction, formatting the current temporary partition and then mounting the temporary partition; Reading the block list description file backup area meta information from the tenth preset position of the boot communication partition, and determining whether the magic number in the block list description file backup area meta information is a preset block list description file backup area meta information magic number; If yes, then reading a block list description file backup header of a preset size from the starting address of the block list description file backup area in the block list description file backup area meta information; If the magic number in the block list description file backup header is a preset magic number, a new empty block list description file is created under the preset path of the temporary storage partition, and starting from the block list description file start address in the block list description file backup header, data with a size equal to the block list description file size in the block list description file backup header is read and saved to the empty block list description file; Writing a fourth preset upgrade instruction in the first preset position of the boot communication partition, and restarting the device; If the current upgrade instruction is the sixth preset upgrade instruction, obtaining the partition start address of the firmware storage area to be upgraded from the command line parameter as the start address of the firmware storage area to be upgraded, and mounting the temporary partition; Reading a firmware upgrade package under a preset path of a preset encrypted user data partition according to a block list description file under a preset path of the temporary storage partition, and reading all files in the firmware upgrade package; Saving all the files to the firmware storage area to be upgraded according to a preset storage structure; Constructing metadata of the firmware storage area to be upgraded, and writing the metadata of the firmware storage area to be upgraded into a ninth preset position of the boot communication partition; and A fourth preset upgrade instruction is written into the first preset position of the boot communication partition, and the device is restarted.

18. 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 17.

Citation Information

Patent Citations

  • Firmware upgrading method and terminal

    CN109634645A

  • Firmware upgrading system and method

    CN113885907A

  • Firmware upgrading method, electronic equipment and storage medium

    CN116974617A

  • Firmware upgrading method, electronic equipment and storage medium

    CN117369847A

  • Firmware security protection and upgrading method, system, equipment and medium

    CN118656841A