Firmware upgrading method and electronic equipment
By reading and storing upgrade instruction information in the bootloader firmware, calculating and constructing upgrade metadata, the unreliable OTA upgrade problem of partition table changes under user data partition encryption is solved, and safe and reliable firmware upgrades are achieved.
Patent Information
- Application Number
- CN202510695435.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-28
- Publication Date
- 2025-09-19
AI Technical Summary
Existing OTA upgrade methods cannot achieve safe and reliable upgrades with arbitrary changes to the partition table when the user data partition is encrypted, and multiple upgrades are unreliable.
In the bootloader firmware, the upgrade instruction information is read from the boot communication partition, the base address of the data storage area of the firmware to be upgraded is calculated based on the current partition table and the metadata of the firmware to be upgraded, the upgrade metadata is constructed, and the firmware upgrade package is stored in the encrypted user data partition to ensure that the upgrade can be reliably restored in the event of an unexpected power outage.
It achieves safe and reliable upgrade of firmware with arbitrary partition table changes when the user data partition is encrypted, ensures that the upgrade can be correctly re-executed after an unexpected power outage, and avoids the uncertainty of multiple upgrades.
Smart Images

Figure CN120671116A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of embedded technology, and in particular to a method for upgrading firmware and an electronic device. Background Art
[0002] Existing over-the-air (OTA) upgrade methods, which don't rely on external storage media and support arbitrary changes to the partition table address space, require multiple upgrades and often can't guarantee complete reliability. They also require the default user data partition to be unencrypted, which is often the case in security-critical environments. Once the user data partition is encrypted, the bootloader firmware cannot access the encrypted data in the corresponding partition, making the upgrade impossible. Summary of the Invention
[0003] The present invention provides a method for upgrading firmware and an electronic device, which can safely and reliably upgrade firmware with arbitrarily changed partition tables when user data partitions are encrypted.
[0004] In one aspect of the present invention, a method for upgrading firmware is provided. The method comprises: reading upgrade instruction information from a first preset location of a boot communication partition in boot program firmware; if the upgrade instruction information includes a first-stage upgrade instruction, calculating a base address of a data storage area of a firmware to be upgraded according to a current partition table and firmware metadata to be upgraded, and constructing upgrade metadata based on the base address of the data storage area of the firmware to be upgraded; storing a partition table file with a preset name and all firmware image files to be upgraded in a firmware upgrade package under a preset firmware upgrade package path of an encrypted preset user data partition to an address space determined by the base address of the data storage area of the firmware to be upgraded according to a block list description file; writing the upgrade metadata to a second preset location of the boot communication partition of the current partition table; if the upgrade instruction information includes a second-stage upgrade instruction, determining an end address of a data storage space of the firmware to be upgraded and a base address for data movement of the firmware to be upgraded according to a boot communication partition address space change flag read from the upgrade metadata; and if the storage space meets a preset requirement, copying data in the address space determined by the end address of the data storage space of the firmware to be upgraded to the base address for data movement of the firmware to be upgraded, modifying the upgrade metadata, and writing the modified upgrade metadata to the second preset location of the boot communication partition.
[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, in the first stage upgrade, the base address of the firmware data storage area to be upgraded is calculated according to the current partition table and the firmware meta information to be upgraded, and the upgrade meta information is constructed based on it. According to the block list description file, the partition table file with the preset name in the firmware upgrade package under the preset firmware upgrade package path of the encrypted preset user data partition and all the firmware image files to be upgraded are stored in the address space determined by the base address of the firmware data storage area to be upgraded. In the second stage upgrade, the end address of the firmware data storage space to be upgraded and the base address of the firmware data to be upgraded are determined according to the boot communication partition address space change mark of the upgrade meta information read. If the storage space meets the preset requirements, the address space determined by the end address of the firmware data storage space to be upgraded is cleared. The data in between is copied to the data moving base address of the firmware to be upgraded, and the modified upgrade metadata is written into the second preset location of the boot communication partition. In this way, if an accident occurs during the first stage upgrade or the second stage upgrade (such as power failure), the address space determined by the base address of the data storage area of the firmware to be upgraded will not damage the encrypted preset user data partition, the boot program firmware partition, the boot communication partition, the block list description file partition, the recovery mode firmware partition and the physical partition of the dependent firmware list of the recovery mode firmware, and the second stage upgrade will not damage the boot program firmware, so the corresponding upgrade can always be correctly re-executed after power is turned on again, thereby safely and reliably upgrading the firmware with arbitrarily changed partition tables when the user data partition is encrypted. BRIEF DESCRIPTION OF THE DRAWINGS
[0007] Figure 1 A flowchart of the method for upgrading firmware according to an embodiment of the present invention; Figure 2 A flowchart of a method for upgrading firmware according to an embodiment of the present invention; Figure 3 FIG. 1 is a schematic structural diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0008] To illustrate the technical content, achieved objectives and effects of the present invention in detail, the following description is given in conjunction with the embodiments and accompanying drawings.
[0009] In the existing technology, there are two firmware upgrade methods that do not rely on external storage media and can support arbitrary changes in the partition table address space. One of them requires multiple upgrades and usually cannot guarantee the complete reliability of the entire upgrade process. The other requires that the preset user data partition is unencrypted. Once the user data partition is encrypted, the encrypted data in the corresponding partition cannot be accessed in the boot program firmware, and the upgrade cannot be achieved.
[0010] In order to solve at least the above-mentioned technical problems, the present disclosure provides a method for upgrading firmware. According to an embodiment of the present disclosure, in the first stage of upgrading, the base address of the data storage area of the firmware to be upgraded is calculated based on the current partition table and the metadata of the firmware to be upgraded, and the upgrade metadata is constructed based on the base address. According to the block list description file, the partition table file with the preset name and all the firmware image files to be upgraded in the firmware upgrade package under the preset firmware upgrade package path of the encrypted preset user data partition are stored in the address space determined by the base address of the data storage area of the firmware to be upgraded. In the second stage of upgrading, the end address of the data storage space of the firmware to be upgraded and the base address of the data movement of the firmware to be upgraded are determined based on the boot communication partition address space change mark of the upgrade metadata. If the storage space meets the preset requirements, the data in the address space determined by the end address of the data storage space of the firmware to be upgraded is copied to the base address of the data movement of the firmware to be upgraded, and the modified upgrade metadata is written to the second preset position of the boot communication partition. In this way, if an accident occurs during the first-stage upgrade or the second-stage upgrade (such as power failure), since the address space determined by the base address of the firmware data storage area to be upgraded will not damage the encrypted preset user data partition, boot program firmware partition, boot communication partition, block list description file partition, recovery mode firmware partition and the physical partition of the recovery mode firmware's dependent firmware list, and the second-stage upgrade will not damage the boot program firmware, the corresponding upgrade can always be correctly re-executed after power is restored, thereby safely and reliably upgrading the firmware with arbitrarily changed partition tables when the user data partition is encrypted.
[0011] The disclosed embodiment requires that the address space of the boot program firmware partition and the boot communication partition in the partition table be located before the address space of various system firmware partitions (such as super or system) and the encrypted preset user data partition (such as data). At the same time, it requires that the encrypted preset user data partition be the last partition in the partition table, and the length of the boot communication partition in the new partition table cannot be less than the length of the boot communication partition in the old partition table. The boot communication partition is a bare partition used for communication between the system, the boot program firmware, and the recovery mode firmware. The preset non-encrypted partition where the block list description file (such as block.map) of the firmware upgrade package is saved is called the block list description file partition. The dependent firmware of the recovery mode firmware refers to the firmware that needs to be booted before the recovery mode firmware is booted during the device startup process, as well as the firmware that the recovery mode firmware depends on during operation. The dependent firmware list of the recovery mode firmware is a list composed of all the dependent firmware of the recovery mode firmware.
[0012] According to the disclosed embodiment, since the user data partition containing the firmware upgrade package is encrypted, the base address of the data storage area for the firmware to be upgraded is first calculated in the recovery mode phase 1 upgrade instruction based on the current partition table and the metadata of the firmware to be upgraded. The upgrade metadata is then constructed and the legitimacy of the address space determined by the upgrade metadata is checked. Finally, based on the block list description file, the partition table file with a preset name and all the firmware image files to be upgraded in the firmware upgrade package under the preset firmware upgrade package path of the encrypted user data partition are stored in the address space determined by the base address of the data storage area for the firmware to be upgraded. If an unexpected event (such as a power outage) occurs during the phase 1 upgrade instruction process, the address space determined by the base address of the firmware data storage area to be upgraded will not damage the preset user data partition, bootloader firmware partition, boot communication partition, block list description file partition, recovery mode firmware partition, and the physical partitions of the recovery mode firmware's dependent firmware list. Therefore, the phase 1 upgrade instruction can always be correctly re-executed after powering on. Since the phase 2 upgrade instruction does not damage the bootloader firmware, if an unexpected event (such as a power outage) occurs during the execution of the phase 2 upgrade instruction, the phase 2 upgrade instruction can always be resumed after powering on. At the start of the stage 3 upgrade, the bootloader firmware partition in the current partition table is ensured to point to the bootloader backup firmware. This ensures that if an unexpected situation occurs while the bootloader firmware itself is being upgraded, the backup firmware can always be booted from it, thus ensuring upgrade reliability. Because the upgrade instructions in the other stages do not damage the bootloader firmware, if an unexpected situation occurs (such as a power outage), the corresponding upgrade instructions can always be executed after powering back on.
[0013] Hereinafter, the technical solutions according to the present disclosure will be described with reference to specific embodiments and in conjunction with the accompanying drawings.
[0014] Figure 1 FIG. 1 is a flow chart illustrating 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 112.
[0015] In step 102, upgrade instruction information is read from a first preset location of the boot communication partition in the boot program firmware.
[0016] In some embodiments, before step 102, the method 100 may further include: saving the block list corresponding to the firmware upgrade package in the form of the block list description file to a preset block list description file path of the block list description file partition; constructing the firmware meta-information to be upgraded based on the firmware upgrade package; writing the firmware meta-information to be upgraded at a third preset position of the boot communication partition, and writing the first stage upgrade instruction at the first preset position of the boot communication partition; and restarting the device.
[0017] In this way, the metadata of the firmware to be upgraded is written into the boot communication partition, ensuring that the upgrade process is traceable and avoiding upgrade failures due to power outages or unexpected interruptions.
[0018] In step 104, if the upgrade instruction information includes the first stage upgrade instruction, the base address of the firmware data storage area to be upgraded is calculated according to the current partition table and the firmware metadata to be upgraded, and the upgrade metadata is constructed based on the base address of the firmware data storage area to be upgraded.
[0019] In some embodiments, the device is booted into recovery mode. In the recovery mode, the base address of the data storage area of the firmware to be upgraded is calculated based on the current partition table and the metadata of the firmware to be upgraded. The current startup storage medium size is calculated based on the storage medium block device node, and the starting address of the encrypted preset user data partition in the new partition table to be upgraded and the tail reserved size of the startup storage medium are calculated based on the partition table file with the preset name in the firmware upgrade package. In addition, based on the base address of the data storage area of the firmware to be upgraded, the upgrade metadata including the magic number, the digital digest algorithm type, the digital digest of the first data metadata, the first data metadata, the digital digest of the second data metadata, the second data metadata, the digital digest of the third data metadata, the third data metadata, the digital digest of the fourth data metadata and the fourth data metadata is constructed.
[0020] In this way, the base address of the data storage area of the firmware to be upgraded is calculated according to the current partition table and the metadata of the firmware to be upgraded, ensuring that the upgrade data is written to the correct physical storage location, which is helpful for subsequent sequential upgrades.
[0021] In some embodiments, the current partition table is obtained from the address space where the device partition table resides, and the firmware to be upgraded meta-information is read from a third preset location of the boot communication partition of the current partition table. A check is performed to determine whether the magic number in the firmware to be upgraded meta-information is the preset magic number for the firmware to be upgraded meta-information. If not, the firmware upgrade process is exited. If so, a digital digest of the firmware image information to be upgraded in the firmware to be upgraded meta-information is calculated based on the digital digest algorithm type in the firmware to be upgraded meta-information, and the calculated digital digest is compared with the digital digest of the firmware image information to be upgraded in the firmware to be upgraded meta-information. If the comparison result is different, the firmware upgrade process is exited. If the comparison result is the same, the total size of the firmware data in the firmware upgrade package, including the partition table file and all firmware image files to be upgraded, is calculated based on the firmware image information to be upgraded in the firmware to be upgraded meta-information. A check is performed to determine whether there is a partition in the current partition table whose size is greater than or equal to the total firmware data size and whose partition name is not an encrypted preset user data partition, a bootloader firmware partition, a boot communication partition, a block list description file partition, a recovery mode firmware partition, or a physical partition of the recovery mode firmware's dependent firmware list. If it exists, the starting address of the physical partition is used as the base address of the firmware data storage area to be upgraded. If it does not exist, the first physical partition after the boot program firmware partition, boot communication partition, block list description file partition, recovery mode firmware partition, and the dependent firmware list of the recovery mode firmware in the current partition table is used as a candidate physical partition, and it is determined whether the difference between the starting address of the encrypted preset user data partition and the starting address of the candidate physical partition is greater than or equal to the total size of the firmware data. If it is greater than or equal to, the starting address of the candidate physical partition is used as the base address of the firmware data storage area to be upgraded. If it is less than, the firmware upgrade process is exited.
[0022] In this way, by verifying the legitimacy of the firmware metadata to be upgraded, the security of the upgrade is ensured. When determining the base address of the firmware data storage area to be upgraded, a non-critical partition of sufficient size is searched to store the upgrade data, thus avoiding overwriting of critical data in operation and ensuring the reliability of the upgrade.
[0023] In some embodiments, based on the block list description file under the preset block list description file path in the block list description file partition, a partition table file with a preset name in the firmware upgrade package is obtained from the preset firmware upgrade package path of the encrypted preset user data partition as the new partition table to be upgraded. The starting address of the encrypted preset user data partition is obtained from the new partition table as the base address of the new user data partition. If the partition table type corresponding to the new partition table is a globally unique identifier partition table, the reserved size at the end of the boot storage medium is set to the preset reserved partition table size. If the partition table type corresponding to the new partition table is not a globally unique identifier partition table, the reserved size at the end of the boot storage medium is set to 0.
[0024] In this way, by calculating the reserved tail space, it is ensured that when the main partition table is damaged, the system can still be restored from the backup, reducing the risk of the device being unable to boot (becoming bricked) due to an upgrade failure. In addition, after executing the first-stage upgrade instruction, the partition table file with the preset name in the firmware upgrade package under the preset firmware upgrade package path of the encrypted user data partition and all the firmware image files to be upgraded can be stored in the address space determined by the base address of the firmware data storage area to be upgraded, thereby no longer relying on the file system of the user data partition to obtain the data in the firmware upgrade package. The boot program firmware can directly access the firmware to be upgraded in the address space determined by the base address of the firmware data storage area to be upgraded, and no longer needs to be accessed through the file system, which means that the boot program firmware is not required to support the file system.
[0025] In step 106, according to the block list description file, the partition table file with the preset name in the firmware upgrade package under the preset firmware upgrade package path of the encrypted preset user data partition and all the firmware image files to be upgraded are stored in the address space determined by the base address of the firmware data storage area to be upgraded.
[0026] In some embodiments, the legality of the address space determined by the upgrade meta-information is checked; if the result of the check is illegal, the firmware upgrade process is exited. If the result of the check is legal, the new partition table to be upgraded is stored in the partition table address space determined by the first data meta-information and the second data meta-information in the upgrade meta-information. The boot program firmware to be upgraded is stored in the boot program firmware address space determined by the first data meta-information and the second data meta-information in the upgrade meta-information. In addition, the other firmware to be upgraded except the new partition table to be upgraded and the boot program firmware to be upgraded is stored in the corresponding firmware address space to be upgraded determined by the first data meta-information and the third data meta-information in the upgrade meta-information.
[0027] In this way, the address space determined by the base address of the firmware data storage area to be upgraded will not destroy the encrypted preset user data partition, boot program firmware partition, boot communication partition, block list description file partition, recovery mode firmware partition and the physical partition of the recovery mode firmware's dependent firmware list. Therefore, even if an accident occurs during the first stage upgrade process, the first stage upgrade instructions can always be correctly re-executed after power is restored, thereby achieving reliable firmware upgrade.
[0028] In step 108, the upgrade meta-information is written into a second preset location of the boot communication partition of the current partition table.
[0029] In some embodiments, the current boot program firmware data determined by the boot program firmware partition in the current partition table is stored in the boot program backup firmware address space determined by the first data meta-information and the fourth data meta-information in the upgrade meta-information. If the boot communication partition address space change flag of the first data meta-information in the upgrade meta-information is true, the constructed upgrade meta-information is written to the preset location for storing the upgrade meta-information in the boot communication backup partition address space determined by the first data meta-information and the fourth data meta-information in the upgrade meta-information, and the second-stage upgrade instruction is written to the preset location for storing the upgrade instruction in the boot communication backup partition address space. In addition, the constructed upgrade meta-information is written to the second preset location of the boot communication partition in the current partition table.
[0030] In some embodiments, after step 108, the method 100 may further include: writing the second-stage upgrade instruction into the first preset location of the boot communication partition of the current partition table; and restarting the device.
[0031] In this way, if the boot communication partition address space change mark of the first data meta-information in the upgrade meta-information is true, the constructed upgrade meta-information is written into the preset position for storing the upgrade meta-information in the boot communication backup partition address space determined according to the first data meta-information and the fourth data meta-information in the upgrade meta-information, and the second-stage upgrade instruction is written into the preset position for storing the upgrade instruction in the boot communication backup partition address space, and the constructed upgrade meta-information is written into the second preset position of the boot communication partition of the current partition table, so that the upgrade can be successfully completed when the partition table changes arbitrarily.
[0032] In step 110, if the upgrade instruction information includes a second-stage upgrade instruction, the end address of the storage space of the firmware data to be upgraded and the base address of the firmware data to be upgraded are determined according to the boot communication partition address space change flag read from the upgrade meta-information.
[0033] In some embodiments, the current partition table is obtained from the address space where the device partition table resides, and the upgrade metadata is read from the second preset location of the boot communication partition in the current partition table. A check is performed to determine whether the magic number of the upgrade metadata is the preset upgrade metadata magic number. If not, the firmware upgrade process is exited. If so, a digital digest of the first data metadata of the upgrade metadata is calculated based on the digital digest algorithm type of the upgrade metadata, and the calculated digital digest is checked to determine whether it is identical to the digital digest of the first data metadata of the upgrade metadata. If not, the firmware upgrade process is exited. If they are identical, a digital digest of the fourth data metadata of the upgrade metadata is calculated based on the digital digest algorithm type of the upgrade metadata, and the calculated digital digest is checked to determine whether it is identical to the digital digest of the fourth data metadata of the upgrade metadata. If the calculated digital digest is different from the digital digest of the fourth data metadata of the upgrade metadata, the firmware upgrade process is exited. If the calculated digital digest is identical to the digital digest of the fourth data metadata of the upgrade metadata, a determination is made as to whether the boot communication partition address space change flag of the first data metadata of the upgrade metadata is false. If the value is false, the end address of the data storage space for the firmware to be upgraded is determined based on the boot program backup firmware starting address and the boot program backup firmware size in the fourth data meta information of the upgrade meta information. If the value is true, the end address of the data storage space for the firmware to be upgraded is determined based on the boot communication backup partition starting address and the boot communication backup partition size in the fourth data meta information of the upgrade meta information. In addition, the maximum value of the end address of the data storage space for the firmware to be upgraded and the start address of the new user data partition in the first data meta information of the upgrade meta information is used as the base address for moving the data for the firmware to be upgraded.
[0034] In this way, the read upgrade metadata is verified for legitimacy, ensuring the security of the upgrade. By accurately calculating the end address of the firmware data storage space to be upgraded and the base address of the firmware data to be upgraded, it can be compatible with partition table changes, thereby improving the reliability of the firmware upgrade.
[0035] In step 112, if the storage space meets the preset requirements, the data in the address space determined by the end address of the firmware data storage space to be upgraded is copied to the base address of the firmware data movement to be upgraded, and the upgrade meta information is modified, and the modified upgrade meta information is written to the second preset location of the boot communication partition.
[0036] In some embodiments, the storage medium capacity size of the first data meta information of the upgrade meta information is subtracted from the storage medium tail reserved size of the first data meta information and the data move base address of the firmware to be upgraded to obtain a first result. The data storage area base address of the first data meta information of the upgrade meta information is subtracted from the end address of the data storage space of the firmware to be upgraded to obtain a second result. It is determined whether the first result is greater than or equal to the second result. If not, the firmware upgrade process is exited. If so, the data in the address space determined by the data storage area base address of the first data meta information of the upgrade meta information and the end address of the data storage space of the firmware to be upgraded is copied to the data move base address of the firmware to be upgraded. The data storage area base address of the first data meta information of the upgrade meta information is set as the data move base address of the firmware to be upgraded, and the digital summary of the first data meta information of the upgrade meta information is calculated according to the digital summary algorithm type of the upgrade meta information, and the calculated digital summary is saved to the digital summary of the first data meta information of the upgrade meta information to modify the upgrade meta information. If the boot communication partition address space change flag in the first data meta-information of the upgrade meta-information is true, the modified upgrade meta-information is written to the preset location for storing upgrade meta-information in the boot communication backup partition address space determined based on the first and fourth data meta-information in the upgrade meta-information, and the third-stage upgrade instructions are written to the preset location for storing upgrade instructions in the boot communication backup partition address space. Furthermore, the modified upgrade meta-information is written to the second preset location of the boot communication partition in the current partition table.
[0037] In some embodiments, after step 112, the method 100 may further include: writing the third stage upgrade instruction into the first preset location of the boot communication partition of the current partition table.
[0038] In this way, by comparing the first and second results, the device ensures that there is sufficient space to complete the data migration, preventing upgrade interruptions or data corruption due to insufficient storage. The data in the address space determined by the data storage area base address of the first data metadata of the upgrade metadata and the end address of the data storage space of the firmware to be upgraded are copied to the data migration base address of the firmware to be upgraded, ensuring data integrity during the upgrade process. Furthermore, if the address of the boot communication partition changes, the modified upgrade metadata is synchronously written to the address space of the boot communication backup partition, ensuring that the system can resume the upgrade process from the backup partition even in the event of an unexpected power outage.
[0039] In some embodiments, the method 100 may further include: if the upgrade instruction information includes a third-stage upgrade instruction, modifying the current partition table according to the read upgrade metadata; writing the modified current partition table into the address space where the device partition table is located to complete the upgrade of the modified current partition table; and using the modified current partition table as the current partition table, and writing the fourth-stage upgrade instruction into the first preset position of the boot communication partition of the current partition table.
[0040] In some embodiments, the current partition table is obtained from the address space where the device partition table is located, and the upgrade meta-information is read from the second preset position of the boot communication partition of the current partition table. Check whether the magic number of the upgrade meta-information is the preset upgrade meta-information magic number. If not, exit the firmware upgrade process. If yes, calculate the digital summary of the first data meta-information of the upgrade meta-information according to the digital summary algorithm type of the upgrade meta-information, and check whether the calculated digital summary is the same as the digital summary of the first data meta-information of the upgrade meta-information. If not, exit the firmware upgrade process. If they are the same, calculate the digital summary of the fourth data meta-information of the upgrade meta-information according to the digital summary algorithm type of the upgrade meta-information, and check whether the calculated digital summary is the same as the digital summary of the fourth data meta-information of the upgrade meta-information. If the calculated digital summary is different from the digital summary of the fourth data meta-information of the upgrade meta-information, exit the firmware upgrade process. If the calculated digital digest is the same as the digital digest of the fourth data meta-information of the upgrade meta-information, then according to the digital digest algorithm type of the upgrade meta-information, calculate the digital digest of the data in the address space determined by the data storage area base address of the first data meta-information of the upgrade meta-information, the boot program backup firmware starting address of the fourth data meta-information of the upgrade meta-information and the boot program backup firmware size of the fourth data meta-information of the upgrade meta-information, and check whether the calculated digital digest is the same as the boot program backup firmware digital digest value of the fourth data meta-information of the upgrade meta-information. If it is different from the boot program backup firmware digital digest value of the fourth data meta-information of the upgrade meta-information, exit the firmware upgrade process. If it is the same as the boot program backup firmware digital digest value of the fourth data meta-information of the upgrade meta-information, modify the current partition table according to the upgrade meta-information.
[0041] In this way, after reading the upgrade meta information, the upgrade meta information is first verified for validity to ensure that the boot program firmware partition of the current partition table points to the boot program backup firmware. Only after the validity verification is passed is the current partition table modified according to the upgrade meta information to improve the security of the upgrade and ensure that when the boot program firmware itself is upgraded, if an accident occurs, the boot program backup firmware can always be booted from the boot program backup firmware, thereby ensuring the reliability of the upgrade.
[0042] In some embodiments, the method 100 may further include: if the upgrade instruction information includes a fourth-stage upgrade instruction, modifying the current partition table according to the read upgrade metadata; writing the modified current partition table into the address space where the device partition table is located to complete the upgrade of the modified current partition table; using the modified current partition table as the current partition table; obtaining a new partition table to be upgraded from the partition table address space determined by the first data metadata and the second data metadata in the upgrade metadata; calculating the digital digest of the new partition table to be upgraded according to the digital digest algorithm type of the upgrade metadata, and checking whether the calculated digital digest is the same as the digital digest value of the partition table to be upgraded of the second data metadata of the upgrade metadata; if the calculated digital digest is different from the digital digest value of the partition table to be upgraded of the second data metadata of the upgrade metadata, exiting the firmware upgrade process; if the calculated digital digest is the same as the digital digest value of the partition table to be upgraded of the second data metadata of the upgrade metadata, obtaining the digital digest from the first data metadata and the second data metadata in the upgrade metadata. Obtain the boot program firmware data to be upgraded from the address space of the boot program firmware to be upgraded determined by the metadata; calculate the digital digest of the boot program firmware data to be upgraded according to the digital digest algorithm type of the upgrade metadata, and check whether the calculated digital digest is the same as the digital digest value of the boot program firmware to be upgraded in the second data metadata of the upgrade metadata; if it is different from the digital digest value of the boot program firmware to be upgraded in the second data metadata of the upgrade metadata, exit the firmware upgrade process; if it is the same as the digital digest value of the boot program firmware to be upgraded in the second data metadata of the upgrade metadata, write the boot program firmware data to be upgraded into the address space corresponding to the boot program firmware partition of the new partition table; write the new partition table to be upgraded into the address space where the device partition table is located to complete the upgrade of the new partition table; use the new partition table as the current partition table; and write the fifth-stage upgrade instruction into the first preset position of the boot communication partition of the current partition table.
[0043] In this way, the partition table and bootloader upgrade are performed as independent stages in the fourth upgrade stage. Even if a failure occurs, the upgrade can be quickly rolled back, ensuring the reliability of the upgrade.
[0044] In some embodiments, the method 100 may further include: if the upgrade instruction information includes a fifth-stage upgrade instruction, then, based on the number of firmware items to be upgraded in the third data metadata of the upgrade metadata, sequentially traversing each firmware item to be upgraded in the list of firmware items to be upgraded in the third data metadata of the upgrade metadata; for each firmware item to be upgraded traversed, reading data of a length equal to the size of the firmware to be upgraded of the firmware item to be upgraded as the firmware data to be upgraded based on the data storage area base address of the first data metadata of the upgrade metadata and the firmware offset address to be upgraded of the firmware item to be upgraded; and reading data of a length equal to the size of the firmware to be upgraded of the firmware item to be upgraded according to the data storage area base address of the first data metadata of the upgrade metadata and the firmware offset address to be upgraded of the firmware item to be upgraded according to the data storage area base address of the first data metadata of the upgrade metadata and the firmware offset address to be upgraded of the firmware item to be upgraded; and reading data of a length equal to the size of the firmware ... The digital digest algorithm type calculates the digital digest of the firmware to be upgraded data, and checks whether the calculated digital digest is the same as the digital digest value of the firmware to be upgraded of the firmware item to be upgraded; if the calculated digital digest is different from the digital digest value of the firmware to be upgraded of the firmware item to be upgraded, the firmware upgrade process is exited; if the calculated digital digest is the same as the digital digest value of the firmware to be upgraded of the firmware item to be upgraded, the firmware to be upgraded data is written into the address space corresponding to the firmware to be upgraded partition name of the firmware to be upgraded item in the new partition table; and all readable and writable partition erase instructions are written into the first preset position of the boot communication partition of the current partition table.
[0045] In this way, the firmware data is verified item by item to ensure the integrity and security of the firmware upgrade. The upgrade of each firmware item is completed independently. In the event of an accident, the corresponding upgrade can be continued after power is restored, achieving more reliable firmware upgrades. In addition, through the staged upgrade method, breakpoint upgrades can be reliably achieved when the address space of all partitions in the new partition table changes (including adding partitions, deleting partitions, changing partition sizes, etc.), and even when user data partitions change.
[0046] In some embodiments, the method 100 may further include: if the upgrade instruction information includes instructions for erasing all readable and writable partitions, mounting the corresponding file system for each readable and writable partition in the preset readable and writable partition list with a file system, and determining whether the mounting is successful; if the mounting is successful, no operation is performed; if the mounting fails, erasing the corresponding readable and writable partition and formatting the readable and writable partition; erasing each readable and writable partition in the preset readable and writable partition list without a file system; erasing the upgrade instruction information in the first preset position of the boot communication partition and the upgrade meta information in the second preset position; and restarting the device to enter the upgraded system.
[0047] In this way, after the upgrade is completed, temporary data can be cleaned up in a timely manner to prevent residual files from occupying storage space or interfering with the operation of the new system.
[0048] 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.
[0049] Figure 2 FIG. 1 is a flow chart illustrating 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 237.
[0050] In step 201, the block list corresponding to the firmware upgrade package is saved in the form of a block list description file to a preset block list description file path of a block list description file partition.
[0051] In some embodiments, a firmware upgrade package to be upgraded is obtained and saved to a preset firmware upgrade package path of an encrypted preset user data partition. A validity check is performed on the firmware upgrade package under the preset firmware upgrade package path. If the validity check is illegal, the corresponding firmware upgrade package is deleted and the firmware upgrade process is exited. If the validity check is legal, a block list occupied by the firmware upgrade package is generated through a preset decryption service (such as uncrypt under Android), and the block data in the block list is decrypted, and the decrypted data is rewritten into the corresponding block. The block list corresponding to the firmware upgrade package is saved in the form of a block list description file (such as block.map) to the preset block list description file path of the block list description file partition (such as / cache / recovery / block.map under the cache partition).
[0052] In this embodiment, the firmware upgrade package includes a partition table file with a preset name and all the firmware image files to be upgraded. The firmware image files to be upgraded use the partition name corresponding to the image file as the prefix of the firmware image file name. For example, the prefix "super" in the firmware image file super.img indicates that the partition name corresponding to the image file is super.
[0053] In step 202, metadata of the firmware to be upgraded is constructed according to the firmware upgrade package, which specifically includes the following (1) to (4).
[0054] (1) Set the magic number to the preset magic number of the firmware metadata to be upgraded, and set the digital digest algorithm type to the preset digital digest algorithm type.
[0055] (2) Build the firmware image information to be upgraded, including the following details.
[0056] (2-1) Calculate the number of partition table files with preset names and all firmware image files to be upgraded in the firmware upgrade package, and save the number of firmware images to be upgraded in the firmware image information to be upgraded.
[0057] (2-2) According to the number of firmware images to be upgraded in the firmware image information to be upgraded, the firmware upgrade package is traversed in sequence. For the partition table file and each firmware image file to be upgraded in the firmware upgrade package, the firmware image item to be upgraded of the corresponding file is calculated, and the corresponding firmware image items to be upgraded are sequentially saved in the firmware image item list to be upgraded in the firmware image information to be upgraded.
[0058] In some embodiments, the prefix of the corresponding file is extracted and saved to the partition name of the firmware to be upgraded of the corresponding firmware image item to be upgraded. If the file is a partition table file, the preset name of the partition table file is saved to the partition name of the firmware to be upgraded of the corresponding firmware image item to be upgraded. The size of the corresponding file is calculated and saved to the firmware to be upgraded size of the corresponding firmware image item to be upgraded. A digital digest of the corresponding file is calculated based on the digital digest algorithm type of the firmware to be upgraded meta-information and saved to the firmware to be upgraded digital digest value of the corresponding firmware image item to be upgraded.
[0059] In this embodiment, the firmware image information to be upgraded includes the number of firmware images to be upgraded and a list of firmware image items to be upgraded of a preset size. Each firmware image item to be upgraded in the list of firmware image items to be upgraded consists of a firmware partition name to be upgraded, a firmware size to be upgraded, and a digital summary value of the firmware to be upgraded.
[0060] (3) Calculate the digital summary of the firmware image information to be upgraded according to the digital summary algorithm type of the firmware meta-information to be upgraded, and obtain the digital summary of the firmware image information to be upgraded.
[0061] (4) Generate the firmware metadata to be upgraded based on the magic number, the digital summary algorithm type, the firmware image information to be upgraded, and the digital summary of the firmware image information to be upgraded.
[0062] In step 203, the to-be-upgraded firmware meta-information is written into the third preset location of the boot communication partition, and the first stage upgrade instruction is written into the first preset location of the boot communication partition.
[0063] In step 204, the device is restarted.
[0064] In step 205, the upgrade instruction information is read from a first preset location of the boot communication partition in the boot program firmware.
[0065] In step 206, if the upgrade instruction information includes the first stage upgrade instruction, the base address of the data storage area of the firmware to be upgraded is calculated according to the current partition table and the metadata of the firmware to be upgraded, and the upgrade metadata is constructed based on the base address of the data storage area of the firmware to be upgraded, which specifically includes the following (1) to (4).
[0066] (1) Boot the device into recovery mode.
[0067] (2) In the recovery mode, the base address of the data storage area of the firmware to be upgraded is calculated according to the current partition table and the metadata of the firmware to be upgraded, which specifically includes the following (2-1) to (2-9).
[0068] (2-1) Obtain the current partition table from the address space where the device partition table is located, and read the firmware meta-information to be upgraded from the third preset location of the boot communication partition of the current partition table.
[0069] (2-2) Check whether the magic number in the firmware to be upgraded meta-information is the preset magic number of the firmware to be upgraded meta-information. If not, exit the firmware upgrade process. If so, calculate the digital digest of the firmware to be upgraded image information of the firmware to be upgraded meta-information according to the digital digest algorithm type in the firmware to be upgraded meta-information, and compare the calculated digital digest with the digital digest of the firmware to be upgraded image information in the firmware to be upgraded meta-information.
[0070] (2-3) If the comparison result is different, exit the firmware upgrade process.
[0071] (2-4) If the comparison result is the same, the total size of the firmware data in the firmware upgrade package, including the partition table file and all the firmware image files to be upgraded, is calculated based on the firmware image information to be upgraded in the firmware meta information to be upgraded.
[0072] In some embodiments, the total size of the firmware data is obtained by adding the sizes of the first several firmware images to be upgraded in the list of firmware images to be upgraded in the firmware image information to be upgraded.
[0073] (2-5) Check whether there is a partition in the current partition table whose size is greater than or equal to the total size of the firmware data, and whose partition name is not the encrypted preset user data partition, boot program firmware partition, boot communication partition, block list description file partition, recovery mode firmware partition, and physical partition of the recovery mode firmware's dependent firmware list.
[0074] (2-6) If it exists, the starting address of the physical partition is used as the base address of the firmware data storage area to be upgraded.
[0075] (2-7) If it does not exist, the first physical partition after the boot program firmware partition, boot communication partition, block list description file partition, recovery mode firmware partition and the dependent firmware list of the recovery mode firmware in the current partition table is used as a candidate physical partition, and it is determined whether the difference between the starting address of the encrypted preset user data partition and the starting address of the candidate physical partition is greater than or equal to the total size of the firmware data.
[0076] In some embodiments, the difference between the start address of the encrypted preset user data partition and the start address of the candidate physical partition is the start address of the encrypted preset user data partition minus the start address of the candidate physical partition.
[0077] (2-8) If it is greater than or equal to, the starting address of the candidate physical partition is used as the base address of the firmware data storage area to be upgraded.
[0078] (2-9) If it is less than, exit the firmware upgrade process.
[0079] (3) Calculate the current boot storage medium size based on the storage medium block device node, and calculate the starting address of the encrypted preset user data partition and the tail reserved size of the boot storage medium in the new partition table to be upgraded based on the partition table file with the preset name in the firmware upgrade package, including the following (3-1) to (3-5).
[0080] (3-1) Calculate the current startup storage medium size based on the storage medium block device node.
[0081] In some embodiments, the size of the storage medium block device node file (such as / dev / mmcblk0 of eMMC) is used as the current boot device storage medium size.
[0082] (3-2) According to the block list description file under the preset block list description file path in the block list description file partition, obtain the partition table file with the preset name in the firmware upgrade package from the preset firmware upgrade package path of the encrypted preset user data partition as the new partition table to be upgraded.
[0083] (3-3) Obtain the starting address of the encrypted preset user data partition from the new partition table as the base address of the new user data partition.
[0084] (3-4) If the partition table type corresponding to the new partition table is a globally unique identifier partition table (GUID Partition Table, GPT), the reserved size at the end of the boot storage medium is set to the preset reserved partition table size.
[0085] (3-5) If the partition table type corresponding to the new partition table is not a globally unique identifier partition table, set the reserved size at the end of the boot storage medium to 0.
[0086] (4) Based on the base address of the firmware data storage area to be upgraded, upgrade meta information including a magic number, a digital digest algorithm type, a first data meta information digital digest, a first data meta information, a second data meta information digital digest, a second data meta information, a third data meta information digital digest, a third data meta information, a fourth data meta information digital digest and a fourth data meta information is constructed, specifically including the following (4-1) to (4-6).
[0087] (4-1) The preset magic number of the upgrade meta-information is set as the magic number of the upgrade meta-information, and the digital digest algorithm type of the firmware meta-information to be upgraded is set as the digital digest algorithm type of the upgrade meta-information.
[0088] (4-2) Construct the first data meta-information of the upgrade meta-information, the first data meta-information includes the base address of the data storage area, the capacity of the storage medium, the reserved size at the end of the storage medium, the starting address of the new user data partition and the boot communication partition address space change mark, specifically including the following (4-2-1) to (4-2-2).
[0089] (4-2-1) The base address of the data storage area of the firmware to be upgraded is set to the base address of the data storage area of the first data meta-information, the size of the current startup storage medium is set to the storage medium capacity size of the first data meta-information, the reserved size at the end of the startup storage medium is set to the reserved size at the end of the storage medium of the first data meta-information, and the base address of the new user data partition is set to the starting address of the new user data partition of the first data meta-information.
[0090] (4-2-2) Determine whether the starting address and partition size of the boot communication partition in the current partition table and the new partition to be upgraded are the same. If so, set the boot communication partition address space change flag of the first data meta information to false; otherwise, set the boot communication partition address space change flag of the first data meta information to true.
[0091] (4-3) Construct the second data metadata of the upgrade metadata, the second data metadata includes the offset address of the partition table to be upgraded, the size of the partition table to be upgraded, the digital summary value of the partition table to be upgraded, the offset address of the boot program firmware to be upgraded, the size of the boot program firmware to be upgraded and the digital summary value of the boot program firmware to be upgraded, specifically including the following (4-3-1) to (4-3-3).
[0092] (4-3-1) According to the preset name of the partition table file, the firmware image item to be upgraded corresponding to the partition table to be upgraded is searched from the firmware image information to be upgraded in the firmware meta information to be upgraded as the partition table image item to be upgraded; according to the partition name corresponding to the boot program firmware to be upgraded, the firmware image item to be upgraded corresponding to the boot program firmware to be upgraded is searched from the firmware image information to be upgraded in the firmware meta information to be upgraded as the boot program firmware image item to be upgraded.
[0093] (4-3-2) The offset address of the partition table to be upgraded in the second data meta information is set to 0, the size of the partition table to be upgraded in the second data meta information is set to the size of the firmware to be upgraded in the partition table mirror item to be upgraded, and the digital digest value of the partition table to be upgraded in the second data meta information is set to the digital digest value of the firmware to be upgraded in the partition table mirror item to be upgraded.
[0094] (4-3-3) The offset address of the boot program firmware to be upgraded in the second data meta information is set to: the offset address of the partition table to be upgraded in the second data meta information + the size of the partition table to be upgraded in the second data meta information; the size of the boot program firmware to be upgraded in the second data meta information is set to the size of the firmware to be upgraded in the boot program firmware image item; and the digital digest value of the boot program firmware to be upgraded in the second data meta information is set to the digital digest value of the firmware to be upgraded in the boot program firmware image item.
[0095] (4-4) Constructing the third data metadata of the upgrade metadata, the third data metadata includes the number of firmware items to be upgraded and a list of firmware items to be upgraded of a preset size, each firmware item to be upgraded in the list of firmware items to be upgraded consists of a partition name of the firmware to be upgraded, an offset address of the firmware to be upgraded, a size of the firmware to be upgraded, and a digital summary value of the firmware to be upgraded, specifically including the following (4-4-1) to (4-4-2).
[0096] (4-4-1) The number of firmware items to be upgraded in the third data metadata is set to: the number of firmware images to be upgraded in the firmware image information to be upgraded in the firmware metadata - 2.
[0097] (4-4-2) Sequentially traverse all other firmware image items to be upgraded except the partition table image item to be upgraded and the boot loader firmware image item to be upgraded from the firmware image information to be upgraded in the firmware meta-information to be upgraded. For each firmware image item to be upgraded traversed, construct a corresponding firmware item to be upgraded according to the corresponding firmware image item to be upgraded, and sequentially save them in the firmware item list to be upgraded in the third data meta-information.
[0098] In some embodiments, the name of the firmware partition to be upgraded of the firmware item to be upgraded is set to the name of the firmware partition to be upgraded of the corresponding firmware image item to be upgraded. The size of the firmware to be upgraded of the firmware item to be upgraded is set to the size of the firmware to be upgraded of the corresponding firmware image item to be upgraded. In addition, the digital summary value of the firmware to be upgraded of the firmware item to be upgraded is set to the digital summary value of the firmware to be upgraded of the corresponding firmware image item to be upgraded.
[0099] The previous firmware item to be upgraded is referred to as the previous firmware item to be upgraded. If the firmware item to be upgraded is the first firmware item to be upgraded in the list of firmware items to be upgraded in the third data metadata, the firmware offset address to be upgraded of the firmware item to be upgraded is set to: the offset address of the boot program firmware to be upgraded in the second data metadata of the upgrade metadata + the size of the boot program firmware to be upgraded in the second data metadata of the upgrade metadata. Otherwise, the firmware offset address to be upgraded of the firmware item to be upgraded is set to: the offset address of the previous firmware item to be upgraded + the size of the previous firmware item to be upgraded.
[0100] (4-5) Construct the fourth data metadata of the upgrade metadata, the fourth data metadata includes the boot program backup firmware starting address, boot program backup firmware size, boot program backup firmware digital summary value, boot communication backup partition starting address and boot communication backup partition size, specifically including the following (4-5-1) to (4-5-5).
[0101] (4-5-1) According to the number of firmware items to be upgraded in the third data metadata of the upgrade metadata, the last firmware item to be upgraded is found from the list of firmware items to be upgraded in the third data metadata, and the list is used as the last firmware item to be upgraded.
[0102] (4-5-2) The starting address of the boot program backup firmware of the fourth data element information is set to: the offset address of the firmware to be upgraded of the tail firmware to be upgraded item + the size of the firmware to be upgraded of the tail firmware to be upgraded item.
[0103] (4-5-3) The boot program backup firmware size of the fourth data meta-information is set to the size of the boot program firmware partition in the current partition table.
[0104] (4-5-4) Calculate the digital digest of the data in the address space determined by the starting address and partition size of the boot program firmware partition in the current partition table according to the digital digest algorithm type of the upgrade metadata, and save the calculated digital digest to the boot program backup firmware digital digest value of the fourth data metadata.
[0105] (4-5-5) If the boot communication partition address space change flag of the first data meta-information of the upgrade meta-information is false, then the boot communication backup partition starting address and the boot communication backup partition size of the fourth data meta-information are set to 0; otherwise, the boot communication backup partition starting address of the fourth data meta-information is set to: the boot program backup firmware starting address of the fourth data meta-information + the boot program backup firmware size of the fourth data meta-information, and the boot communication backup partition size of the fourth data meta-information is set to the size of the boot communication partition in the current partition table.
[0106] (4-6) Calculate the digital digest of the first data meta-information of the upgraded meta-information according to the digital digest algorithm type of the upgraded meta-information as the digital digest of the first data meta-information; calculate the digital digest of the second data meta-information of the upgraded meta-information according to the digital digest algorithm type of the upgraded meta-information as the digital digest of the second data meta-information; calculate the digital digest of the third data meta-information of the upgraded meta-information according to the digital digest algorithm type of the upgraded meta-information as the digital digest of the third data meta-information; calculate the digital digest of the fourth data meta-information of the upgraded meta-information according to the digital digest algorithm type of the upgraded meta-information as the digital digest of the fourth data meta-information.
[0107] In step 207, according to the block list description file, the partition table file with the preset name in the firmware upgrade package under the preset firmware upgrade package path of the encrypted preset user data partition and all the firmware image files to be upgraded are stored in the address space determined by the base address of the firmware data storage area to be upgraded, which specifically includes the following (1) to (5).
[0108] (1) Check the legitimacy of the address space determined by the upgrade metadata.
[0109] In some embodiments, if the boot communication partition address space change flag of the first data meta-information of the upgrade meta-information is false, the "boot program backup firmware starting address of the fourth data meta-information + the boot program backup firmware size of the fourth data meta-information" of the upgrade meta-information is used as the end address of the data storage space of the firmware to be upgraded. Otherwise, the "boot communication backup partition starting address of the fourth data meta-information + the boot communication backup partition size of the fourth data meta-information" of the upgrade meta-information is used as the end address of the data storage space of the firmware to be upgraded. The maximum value of the end address of the data storage space of the firmware to be upgraded and the start address of the new user data partition of the first data meta-information is selected as the base address for data movement of the firmware to be upgraded. It is determined whether the value of "storage medium capacity of the first data meta-information - storage medium tail reserved size of the first data meta-information - base address for data movement of the firmware to be upgraded" is greater than or equal to the value of "end address of the data storage space of the firmware to be upgraded - base address of the data storage area of the first data meta-information". If not, the check result is determined to be illegal. If so, the check result is determined to be legal.
[0110] (2) If the check result is illegal, exit the firmware upgrade process.
[0111] (3) If the result of the check is legal, the new partition table to be upgraded is stored in the partition table address space determined by the first data meta information and the second data meta information in the upgrade meta information.
[0112] In some embodiments, based on the block list description file at a preset block list description file path in the block list description file partition, a partition table file with a preset name in the firmware upgrade package is obtained from the preset firmware upgrade package path of the encrypted preset user data partition as the new partition table to be upgraded. The new partition table to be upgraded is written to the address "data storage area base address of the first data metadata of the upgrade metadata + offset address of the partition table to be upgraded of the second data metadata of the upgrade metadata", and the size of the written data is the size of the partition table to be upgraded of the second data metadata of the upgrade metadata.
[0113] (4) The boot program firmware to be upgraded is stored in the boot program firmware address space determined by the first data meta information and the second data meta information in the upgrade meta information.
[0114] In some embodiments, based on the block list description file at the preset block list description file path in the block list description file partition, a boot program firmware image file in the firmware upgrade package is obtained from the preset firmware upgrade package path in the encrypted preset user data partition as the boot program firmware to be upgraded. The boot program firmware to be upgraded is written to the address "data storage area base address of the first data meta information of the upgrade meta information + boot program firmware offset address of the second data meta information of the upgrade meta information", and the written data size is the size of the boot program firmware to be upgraded in the second data meta information of the upgrade meta information.
[0115] (5) The firmware to be upgraded, except for the new partition table to be upgraded and the boot program firmware to be upgraded, is stored in the corresponding firmware to be upgraded address space determined by the first data metadata and the third data metadata in the upgrade metadata.
[0116] In some embodiments, based on the block list description file under the preset block list description file path in the block list description file partition, other firmware image files to be upgraded in the firmware upgrade package, excluding the partition table file and the bootloader firmware image file, are sequentially obtained from the preset firmware upgrade package path of the encrypted preset user data partition. The prefix of the obtained firmware image files to be upgraded is used as the partition name to be upgraded. The obtained firmware image files to be upgraded are used as the firmware data to be upgraded. The firmware item to be upgraded whose firmware partition name to be upgraded is consistent with the partition name to be upgraded is searched in the list of firmware items to be upgraded in the third data metadata of the upgrade metadata. The firmware data to be upgraded is written to "the data storage area base address of the first data metadata of the upgrade metadata + the firmware offset address to be upgraded of the firmware item to be upgraded", and the written data size is the firmware size to be upgraded of the firmware item to be upgraded.
[0117] In step 208, the upgrade meta information is written into the second preset location of the boot communication partition of the current partition table, which specifically includes the following (1) to (3).
[0118] (1) The current boot program firmware data determined by the boot program firmware partition in the current partition table is stored in the boot program backup firmware address space determined by the first data meta information and the fourth data meta information in the upgrade meta information.
[0119] In some embodiments, the data in the address space determined by the starting address and partition size of the boot program firmware partition in the current partition table is written to the "data storage area base address of the first data meta-information of the upgrade meta-information + the boot program backup firmware starting address of the fourth data meta-information of the upgrade meta-information", and the written data size is the boot program backup firmware size of the fourth data meta-information of the upgrade meta-information.
[0120] (2) If the boot communication partition address space change flag of the first data meta-information in the upgrade meta-information is true, the constructed upgrade meta-information is written into the preset location for storing the upgrade meta-information in the boot communication backup partition address space determined by the first data meta-information and the fourth data meta-information in the upgrade meta-information, and the second-stage upgrade instruction is written into the preset location for storing the upgrade instruction in the boot communication backup partition address space.
[0121] In some embodiments, if the boot communication partition address space change mark of the first data meta-information in the upgrade meta-information is true, then the "data storage area base address of the first data meta-information of the upgrade meta-information + the boot communication backup partition starting address of the fourth data meta-information of the upgrade meta-information" is used as the boot communication backup partition base address. Based on the base address, the preset position for saving the upgrade meta-information is offset, the constructed upgrade meta-information is written into the preset position, and the second stage upgrade instruction is also written into the preset position for saving the upgrade instruction.
[0122] (3) Write the constructed upgrade meta information into the second preset location of the boot communication partition of the current partition table.
[0123] In step 209, the second stage upgrade instruction is written into the first preset location of the boot communication partition of the current partition table.
[0124] In step 210, the device is restarted.
[0125] In step 211, if the upgrade instruction information includes the second-stage upgrade instruction, the end address of the storage space of the firmware data to be upgraded and the base address of the firmware data to be upgraded are determined according to the boot communication partition address space change mark of the read upgrade meta-information, specifically including the following (1) to (11).
[0126] (1) Obtain the current partition table from the address space where the device partition table is located, and read the upgrade meta information from the second preset location of the boot communication partition of the current partition table.
[0127] (2) Check whether the magic number of the upgrade meta information is the preset magic number of the upgrade meta information.
[0128] (3) If not, exit the firmware upgrade process.
[0129] (4) If yes, calculate the digital digest of the first data metadata of the upgrade metadata according to the digital digest algorithm type of the upgrade metadata, and check whether the calculated digital digest is the same as the digital digest of the first data metadata of the upgrade metadata.
[0130] (5) If they are not the same, exit the firmware upgrade process.
[0131] (6) If they are the same, calculate the digital summary of the fourth data metadata of the upgrade metadata according to the digital summary algorithm type of the upgrade metadata, and check whether the calculated digital summary is the same as the digital summary of the fourth data metadata of the upgrade metadata.
[0132] (7) If the digital summary of the fourth data metadata is different from the digital summary of the upgrade metadata, the firmware upgrade process is exited.
[0133] (8) If the digital digest of the fourth data meta-information of the upgrade meta-information is the same, determine whether the boot communication partition address space change flag of the first data meta-information of the upgrade meta-information is false.
[0134] (9) If the answer is false, the end address of the storage space of the firmware data to be upgraded is determined based on the starting address of the boot program backup firmware of the fourth data meta information of the upgrade meta information and the size of the boot program backup firmware of the fourth data meta information.
[0135] In some embodiments, the "starting address of the boot program backup firmware of the fourth data meta information + the size of the boot program backup firmware of the fourth data meta information" of the upgrade meta information is used as the end address of the storage space of the firmware data to be upgraded.
[0136] (10) If true, the end address of the firmware data storage space to be upgraded is determined according to the boot communication backup partition start address of the fourth data meta information of the upgrade meta information and the boot communication backup partition size of the fourth data meta information.
[0137] In some embodiments, "the boot communication backup partition starting address of the fourth data meta information+the boot communication backup partition size of the fourth data meta information" of the upgrade meta information is used as the end address of the storage space of the firmware data to be upgraded.
[0138] (11) The maximum value of the end address of the data storage space of the firmware to be upgraded and the starting address of the new user data partition of the first data metadata of the upgrade metadata is used as the base address for moving the data of the firmware to be upgraded.
[0139] In step 212, if the storage space meets the preset requirements, the data in the address space determined by the end address of the data storage space of the firmware to be upgraded is copied to the data moving base address of the firmware to be upgraded, and the upgrade meta information is modified, and the modified upgrade meta information is written into the second preset location of the boot communication partition, specifically including the following (1) to (8).
[0140] (1) Subtract the storage medium capacity of the first data meta-information of the upgrade meta-information from the storage medium tail reserved size of the first data meta-information and the base address of the firmware data to be upgraded to obtain a first result.
[0141] (2) Subtract the data storage area base address of the first data metadata of the upgrade metadata from the end address of the data storage space of the firmware to be upgraded to obtain a second result.
[0142] (3) Determine whether the first result is greater than or equal to the second result.
[0143] (4) If not, exit the firmware upgrade process.
[0144] (5) If yes, copy the data in the address space determined by the data storage area base address of the first data metadata of the upgrade metadata and the end address of the data storage space of the firmware to be upgraded to the data movement base address of the firmware to be upgraded.
[0145] In this embodiment, the length of the copied data is "the end address of the data storage space of the firmware to be upgraded minus the base address of the data storage area of the first data metadata of the upgrade metadata".
[0146] (6) Setting the data storage area base address of the first data meta-information of the upgrade meta-information as the data movement base address of the firmware to be upgraded, calculating the digital digest of the first data meta-information of the upgrade meta-information according to the digital digest algorithm type of the upgrade meta-information, and saving the calculated digital digest to the digital digest of the first data meta-information of the upgrade meta-information to modify the upgrade meta-information.
[0147] (7) If the boot communication partition address space change flag of the first data meta-information of the upgrade meta-information is true, the modified upgrade meta-information is written into the preset location for storing the upgrade meta-information in the boot communication backup partition address space determined according to the first data meta-information and the fourth data meta-information in the upgrade meta-information, and the third stage upgrade instruction is written into the preset location for storing the upgrade instruction in the boot communication backup partition address space.
[0148] (8) The modified upgrade meta information is written into the second preset location of the boot communication partition of the current partition table.
[0149] In step 213, the third stage upgrade instruction is written into the first preset location of the boot communication partition of the current partition table.
[0150] In step 214, if the upgrade instruction information includes the third-stage upgrade instruction, the current partition table is modified according to the read upgrade meta-information, specifically including the following (1) to (10).
[0151] (1) Obtain the current partition table from the address space where the device partition table is located, and read the upgrade meta information from the second preset location of the boot communication partition of the current partition table.
[0152] (2) Check whether the magic number of the upgrade meta information is the preset magic number of the upgrade meta information.
[0153] (3) If no, exit the firmware upgrade process.
[0154] (4) If yes, calculate the digital digest of the first data metadata of the upgrade metadata according to the digital digest algorithm type of the upgrade metadata, and check whether the calculated digital digest is the same as the digital digest of the first data metadata of the upgrade metadata.
[0155] (5) If they are not the same, exit the firmware upgrade process.
[0156] (6) If they are the same, calculate the digital summary of the fourth data metadata of the upgrade metadata according to the digital summary algorithm type of the upgrade metadata, and check whether the calculated digital summary is the same as the digital summary of the fourth data metadata of the upgrade metadata.
[0157] (7) If the digital summary of the fourth data metadata is different from the digital summary of the upgrade metadata, the firmware upgrade process is exited.
[0158] (8) If the digital summary is the same as the digital summary of the fourth data meta-information of the upgrade meta-information, then according to the digital summary algorithm type of the upgrade meta-information, calculate the digital summary of the data in the address space determined by the base address of the data storage area of the first data meta-information of the upgrade meta-information, the starting address of the boot program backup firmware of the fourth data meta-information of the upgrade meta-information, and the size of the boot program backup firmware of the fourth data meta-information of the upgrade meta-information, and check whether the calculated digital summary is the same as the digital summary value of the boot program backup firmware of the fourth data meta-information of the upgrade meta-information.
[0159] In some embodiments, the digital summary of the data in the address space determined by "the data storage area base address of the first data meta-information of the upgrade meta-information + the boot program backup firmware starting address of the fourth data meta-information of the upgrade meta-information" and "the boot program backup firmware size of the fourth data meta-information of the upgrade meta-information" is calculated according to the digital summary algorithm type of the upgrade meta-information, and it is checked whether the calculated digital summary is the same as the boot program backup firmware digital summary value of the fourth data meta-information of the upgrade meta-information.
[0160] (9) If the digital summary value of the boot program backup firmware is different from the digital summary value of the fourth data metadata of the upgrade metadata, the firmware upgrade process is exited.
[0161] (10) If the digital summary value of the boot program backup firmware is the same as the digital summary value of the fourth data metadata of the upgrade metadata, the current partition table is modified according to the upgrade metadata.
[0162] In some embodiments, the starting address of the boot program firmware partition of the current partition table is set to "the data storage area base address of the first data meta information of the upgrade meta information + the boot program backup firmware starting address of the fourth data meta information of the upgrade meta information", and the partition size of the boot program firmware partition of the current partition table is set to "the boot program backup firmware size of the fourth data meta information of the upgrade meta information". If the boot communication partition address space change flag of the first data meta information of the upgrade meta information is true, the starting address of the boot communication partition of the current partition table is set to "the data storage area base address of the first data meta information of the upgrade meta information + the boot communication backup partition starting address of the fourth data meta information of the upgrade meta information", and the partition size of the boot communication partition of the current partition table is set to "the boot communication backup partition size of the fourth data meta information of the upgrade meta information".
[0163] In step 215, the modified current partition table is written into the address space where the device partition table is located, completing the update of the modified current partition table.
[0164] In step 216, the modified current partition table is used as the current partition table, and the fourth stage upgrade instruction is written into the first preset position of the boot communication partition of the current partition table.
[0165] In step 217, if the upgrade instruction information includes the fourth-stage upgrade instruction, the current partition table is modified according to the read upgrade meta-information, which is specifically as follows.
[0166] (1) Obtain the current partition table from the address space where the device partition table is located, read the upgrade meta information from the second preset location of the boot communication partition of the current partition table, and check whether the magic number of the upgrade meta information is the preset upgrade meta information magic number.
[0167] (2) If not, exit the firmware upgrade process.
[0168] (3) If yes, calculate the digital digest of the first data metadata of the upgrade metadata according to the digital digest algorithm type of the upgrade metadata, and check whether the calculated digital digest is the same as the digital digest of the first data metadata of the upgrade metadata.
[0169] (4) If the digital summary of the first data metadata is different from the digital summary of the upgrade metadata, the firmware upgrade process is exited.
[0170] (5) If the digital summary of the second data meta-information of the upgraded meta-information is the same as the digital summary of the first data meta-information of the upgraded meta-information, the digital summary of the second data meta-information of the upgraded meta-information is calculated according to the digital summary algorithm type of the upgraded meta-information, and the digital summary of the second data meta-information of the upgraded meta-information is checked to see whether the calculated digital summary is the same as the digital summary of the second data meta-information of the upgraded meta-information.
[0171] (6) If the digital summary of the second data metadata is different from the digital summary of the upgrade metadata, the firmware upgrade process is exited.
[0172] (7) If the digital summary of the fourth data meta-information of the upgraded meta-information is the same as the digital summary of the second data meta-information of the upgraded meta-information, the digital summary of the fourth data meta-information of the upgraded meta-information is calculated according to the digital summary algorithm type of the upgraded meta-information, and the digital summary of the fourth data meta-information of the upgraded meta-information is checked to see whether the calculated digital summary is the same as the digital summary of the fourth data meta-information of the upgraded meta-information.
[0173] (8) If the digital summary of the fourth data metadata is different from the digital summary of the upgrade metadata, the firmware upgrade process is exited.
[0174] (9) If it is the same as the digital summary of the fourth data metadata of the upgrade metadata, check whether the starting address of the boot program firmware partition of the current partition table is the same as "the data storage area base address of the first data metadata of the upgrade metadata + the boot program backup firmware starting address of the fourth data metadata of the upgrade metadata". If so, execute step 220; otherwise, execute (10).
[0175] (10) The starting address of the boot program firmware partition of the current partition table is set to "the data storage area base address of the first data meta-information of the upgrade meta-information + the boot program backup firmware starting address of the fourth data meta-information of the upgrade meta-information", and the partition size of the boot program firmware partition of the current partition table is set to "the boot program backup firmware size of the fourth data meta-information of the upgrade meta-information". If the boot communication partition address space change flag of the first data meta-information of the upgrade meta-information is true, the starting address of the boot communication partition of the current partition table is set to "the data storage area base address of the first data meta-information of the upgrade meta-information + the boot communication backup partition starting address of the fourth data meta-information of the upgrade meta-information", and the partition size of the boot communication partition of the current partition table is set to "the boot communication backup partition size of the fourth data meta-information of the upgrade meta-information".
[0176] In step 218, the modified current partition table is written into the address space where the device partition table is located, completing the update of the modified current partition table.
[0177] In step 219, the modified current partition table is used as the current partition table.
[0178] In step 220, a new partition table to be upgraded is obtained from the partition table address space determined by the first data meta information and the second data meta information in the upgrade meta information.
[0179] In some embodiments, data having a length equal to the size of the partition table to be upgraded of the second data meta information of the upgrade meta information is read from the "data storage area base address of the first data meta information of the upgrade meta information + the offset address of the partition table to be upgraded of the second data meta information of the upgrade meta information" as the new partition table to be upgraded.
[0180] In step 221, a digital digest of the new partition table to be upgraded is calculated according to the digital digest algorithm type of the upgrade meta-information, and a check is made to see whether the calculated digital digest is the same as the digital digest value of the partition table to be upgraded in the second data meta-information of the upgrade meta-information.
[0181] In step 222, if the digital summary value of the partition table to be upgraded is different from the digital summary value of the second data metadata of the upgrade metadata, the firmware upgrade process is exited.
[0182] In step 223, if the digital summary value of the partition table to be upgraded is the same as that of the second data metadata of the upgrade metadata, the boot program firmware data to be upgraded is obtained from the boot program firmware address space to be upgraded determined by the first data metadata and the second data metadata in the upgrade metadata.
[0183] In some embodiments, data having a length equal to the size of the boot program firmware to be upgraded of the second data meta information of the upgrade meta information is read from the "data storage area base address of the first data meta information of the upgrade meta information + the offset address of the boot program firmware to be upgraded of the second data meta information of the upgrade meta information" as the boot program firmware data to be upgraded.
[0184] In step 224, a digital digest of the boot program firmware data to be upgraded is calculated according to the digital digest algorithm type of the upgrade meta information, and a check is made to see whether the calculated digital digest is the same as the digital digest value of the boot program firmware to be upgraded in the second data meta information of the upgrade meta information.
[0185] In step 225, if the digital digest value of the boot program firmware to be upgraded is different from the digital digest value of the second data metadata of the upgrade metadata, the firmware upgrade process is exited.
[0186] In step 226, if the digital digest value of the boot program firmware to be upgraded is the same as the digital digest value of the second data metadata of the upgrade metadata, the boot program firmware to be upgraded data is written into the address space corresponding to the boot program firmware partition of the new partition table.
[0187] In this embodiment, the size of the written data is the size of the boot program firmware to be upgraded of the second data metadata of the upgrade metadata.
[0188] In step 227, the new partition table to be upgraded is written into the address space where the device partition table is located, thereby completing the upgrade of the new partition table.
[0189] In step 228, the new partition table is used as the current partition table.
[0190] In step 229, the fifth stage upgrade instruction is written into the first preset location of the boot communication partition of the current partition table.
[0191] In step 230, if the upgrade instruction information includes the fifth-stage upgrade instruction, then, based on the number of firmware items to be upgraded in the third data metadata of the upgrade metadata, each firmware item to be upgraded in the list of firmware items to be upgraded in the third data metadata of the upgrade metadata is sequentially traversed; For each firmware item to be upgraded that is traversed, data having a length equal to the size of the firmware to be upgraded of the firmware item to be upgraded is read as the firmware data to be upgraded based on the data storage area base address of the first data metadata of the upgrade metadata and the firmware offset address of the firmware item to be upgraded. A digital digest of the firmware data to be upgraded is calculated based on the digital digest algorithm type of the upgrade metadata, and a check is made to see whether the calculated digital digest is the same as the digital digest value of the firmware to be upgraded of the firmware item to be upgraded. If they are different, the firmware upgrade process is exited. If they are the same, the firmware data to be upgraded is written into the address space corresponding to the firmware partition name of the firmware item to be upgraded in the new partition table, specifically including the following (1) to (7).
[0192] (1) Obtain the current partition table from the address space where the device partition table is located, read the upgrade meta information from the second preset location of the boot communication partition of the current partition table, and check whether the magic number of the upgrade meta information is the preset upgrade meta information magic number.
[0193] (2) If not, exit the firmware upgrade process.
[0194] (3) If yes, calculate the digital digest of the first data metadata of the upgrade metadata according to the digital digest algorithm type of the upgrade metadata, and check whether the calculated digital digest is the same as the digital digest of the first data metadata of the upgrade metadata.
[0195] (4) If the digital summary of the first data metadata is different from the digital summary of the upgrade metadata, the firmware upgrade process is exited.
[0196] (5) If the digital summary of the third data metadata of the upgraded meta-information is the same as the digital summary of the first data metadata of the upgraded meta-information, the digital summary of the third data metadata of the upgraded meta-information is calculated according to the digital summary algorithm type of the upgraded meta-information, and the digital summary of the calculated digital summary is checked to see whether it is the same as the digital summary of the third data metadata of the upgraded meta-information.
[0197] (6) If the digital summary of the third data metadata is different from the digital summary of the upgrade metadata, the firmware upgrade process is exited.
[0198] (7) If the digital summary of the third data metadata of the upgrade metadata is the same as the digital summary of the third data metadata of the upgrade metadata, then traverse each firmware item to be upgraded in the list of firmware items to be upgraded in the third data metadata of the upgrade metadata in turn according to the number of firmware items to be upgraded in the third data metadata of the upgrade metadata; For each firmware item to be upgraded that is traversed, data equal to the size of the firmware to be upgraded in the firmware item to be upgraded is read from the address "data storage area base address of the first data metadata of the upgrade metadata + firmware offset address of the firmware item to be upgraded" as the firmware data to be upgraded. A digital digest of the firmware data to be upgraded is calculated based on the digital digest algorithm type of the upgrade metadata, and a check is performed to determine whether the calculated digital digest is identical to the digital digest value of the firmware item to be upgraded. If they are different, the firmware upgrade process is exited. If they are identical, the firmware data to be upgraded is written to the address space corresponding to the firmware partition name of the firmware item to be upgraded in the new partition table.
[0199] In step 231, all readable and writable partition erasing instructions are written into the first preset location of the boot communication partition of the current partition table.
[0200] In step 232, if the upgrade instruction information includes instructions for erasing all readable and writable partitions, a corresponding file system is mounted on each readable and writable partition in the preset readable and writable partition list having a file system, and it is determined whether the mounting is successful.
[0201] In step 233, if the mounting is successful, no operation is performed.
[0202] In step 234, if the mounting fails, the corresponding readable and writable partition is erased and the readable and writable partition is formatted.
[0203] In step 235, each readable and writable partition in the preset readable and writable partition list without a file system is erased.
[0204] In step 236, the upgrade instruction information in the first preset location of the boot communication partition and the upgrade meta information in the second preset location are erased.
[0205] In step 237, the device is restarted to enter the upgraded system.
[0206] According to yet another aspect of the present invention, Figure 3 Schematic diagram of 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.
[0207] In summary, the method and electronic device for upgrading firmware provided by the present invention, in the first stage of upgrading, calculates the base address of the data storage area of the firmware to be upgraded according to the current partition table and the metadata of the firmware to be upgraded, and constructs the upgrade metadata based on it, and according to the block list description file, stores the partition table file with the preset name and all the firmware image files to be upgraded in the firmware upgrade package under the preset firmware upgrade package path of the encrypted preset user data partition into the address space determined by the base address of the data storage area of the firmware to be upgraded, and in the second stage of upgrading, determines the end address of the data storage space of the firmware to be upgraded and the base address of the firmware data to be upgraded according to the boot communication partition address space change mark of the upgrade metadata read, and if the storage space meets the preset requirements, the end address of the data storage space of the firmware to be upgraded is moved to the end address of the data storage space of the firmware to be upgraded. The data in the address space determined by the address is copied to the data move base address of the firmware to be upgraded, and the modified upgrade metadata is written to the second preset location of the boot communication partition. Therefore, if an unexpected event (such as a power outage) occurs during the first or second phase upgrade, the address space determined by the base address of the firmware data storage area to be upgraded will not damage the encrypted preset user data partition, boot program firmware partition, boot communication partition, block list description file partition, recovery mode firmware partition, and the physical partition of the recovery mode firmware's dependent firmware list, and the second phase upgrade will not damage the boot program firmware. Therefore, the corresponding upgrade can always be correctly re-executed after power is restored. This allows for secure and reliable upgrades of firmware with any partition table changes, even when the user data partition is encrypted. Furthermore, item-by-item firmware data verification ensures the integrity and security of the firmware upgrade. Each firmware item is upgraded independently, and if an unexpected event occurs, the corresponding upgrade can be resumed after power is restored, achieving a more reliable firmware upgrade. Furthermore, through the phased upgrade approach, even when the address spaces of all partitions in the new partition table change, even when the user data partition changes, breakpoint upgrades can be reliably implemented.
[0208] 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 description 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: Reading upgrade instruction information from a first preset location of the boot communication partition in the boot program firmware; If the upgrade instruction information includes the first-stage upgrade instruction, calculating the base address of the data storage area of the firmware to be upgraded according to the current partition table and the metadata of the firmware to be upgraded, and constructing the upgrade metadata based on the base address of the data storage area of the firmware to be upgraded; According to the block list description file, the partition table file with a preset name in the firmware upgrade package under the preset firmware upgrade package path of the encrypted preset user data partition and all the firmware image files to be upgraded are stored in the address space determined by the base address of the firmware data storage area to be upgraded; Writing the upgrade meta information into a second preset location of the boot communication partition of the current partition table; If the upgrade instruction information includes a second-stage upgrade instruction, determining the end address of the storage space of the firmware data to be upgraded and the base address of the firmware data to be upgraded according to the boot communication partition address space change flag read from the upgrade meta information; as well as If the storage space meets the preset requirements, the data in the address space determined by the end address of the firmware data storage space to be upgraded is copied to the firmware data movement base address to be upgraded, and the upgrade meta information is modified, and the modified upgrade meta information is written into the second preset position of the boot communication partition.
2. The method according to claim 1, characterized in that Before reading the upgrade instruction information from the first preset location of the boot communication partition in the boot program firmware, the method further includes: Saving the block list corresponding to the firmware upgrade package in the form of the block list description file to a preset block list description file path of the block list description file partition; Constructing the firmware to be upgraded meta information according to the firmware upgrade package; Writing the to-be-upgraded firmware meta-information into the third preset location of the boot communication partition, and writing the first-stage upgrade instruction into the first preset location of the boot communication partition; and Restart the device.
3. The method according to claim 1, characterized in that Calculating the base address of the data storage area of the firmware to be upgraded according to the current partition table and the metadata of the firmware to be upgraded, and constructing the upgrade metadata based on the base address of the data storage area of the firmware to be upgraded includes: Boot the device into recovery mode; In the recovery mode, calculating a base address of a data storage area of the firmware to be upgraded according to the current partition table and the metadata of the firmware to be upgraded; Calculating the current startup storage medium size according to the storage medium block device node, and calculating the starting address of the encrypted preset user data partition in the new partition table to be upgraded and the tail reserved size of the startup storage medium according to the partition table file with a preset name in the firmware upgrade package; and Based on the base address of the firmware data storage area to be upgraded, the upgrade meta-information including a magic number, a digital digest algorithm type, a first data meta-information digital digest, a first data meta-information, a second data meta-information digital digest, a second data meta-information, a third data meta-information digital digest, a third data meta-information, a fourth data meta-information digital digest and a fourth data meta-information is constructed.
4. The method according to claim 3, characterized in that Calculating the base address of the data storage area for the firmware to be upgraded based on the current partition table and the metadata of the firmware to be upgraded includes: Acquire the current partition table from the address space where the device partition table is located, and read the firmware meta-information to be upgraded from a third preset location of the boot communication partition of the current partition table; Checking whether the magic number in the firmware to be upgraded meta information is the preset magic number of the firmware to be upgraded meta information; If not, exit the firmware upgrade process; If so, calculating a digital digest of the firmware image information to be upgraded of the firmware meta information according to the digital digest algorithm type in the firmware meta information to be upgraded, and comparing the calculated digital digest with the digital digest of the firmware image information to be upgraded in the firmware meta information to be upgraded; If the comparison result is different, exit the firmware upgrade process; If the comparison result is the same, calculating the total size of the firmware data in the firmware upgrade package including the partition table file and all the firmware image files to be upgraded according to the firmware image information to be upgraded in the firmware meta information to be upgraded; Searching the current partition table for a partition whose size is greater than or equal to the total size of the firmware data and whose name is not an encrypted preset user data partition, a boot program firmware partition, a boot communication partition, a block list description file partition, a recovery mode firmware partition, or a physical partition of a recovery mode firmware dependent firmware list; If it exists, the starting address of the physical partition is used as the base address of the firmware data storage area to be upgraded; If it does not exist, then taking the first physical partition after the boot program firmware partition, the boot communication partition, the block list description file partition, the recovery mode firmware partition, and the dependent firmware list of the recovery mode firmware in the current partition table as a candidate physical partition, and determining whether the difference between the start address of the encrypted preset user data partition and the start address of the candidate physical partition is greater than or equal to the total size of the firmware data; If it is greater than or equal to, the starting address of the candidate physical partition is used as the base address of the firmware data storage area to be upgraded; and If it is less, exit the firmware upgrade process.
5. The method according to claim 3, characterized in that Calculating the starting address of the encrypted preset user data partition and the tail reserved size of the boot storage medium in the new partition table to be upgraded according to the partition table file with the preset name in the firmware upgrade package includes: According to the block list description file under the preset block list description file path in the block list description file partition, obtaining the partition table file with the preset name in the firmware upgrade package from the preset firmware upgrade package path of the encrypted preset user data partition as the new partition table to be upgraded; Obtaining the starting address of the encrypted preset user data partition from the new partition table as the base address of the new user data partition; If the partition table type corresponding to the new partition table is a globally unique identifier partition table, setting the reserved size at the end of the boot storage medium to a preset reserved partition table size; and If the partition table type corresponding to the new partition table is not a globally unique identifier partition table, the tail reserved size of the startup storage medium is set to 0.
6. The method according to claim 3, characterized in that According to the block list description file, storing the partition table file with a preset name in the firmware upgrade package under the preset firmware upgrade package path of the encrypted preset user data partition and all the firmware image files to be upgraded in the address space determined by the base address of the firmware data storage area to be upgraded includes: Checking the legitimacy of the address space determined by the upgrade meta-information; If the result of the check is illegal, then exit the firmware upgrade process; If the result of the check is legal, the new partition table to be upgraded is stored in the partition table address space determined by the first data meta information and the second data meta information in the upgrade meta information; storing the boot program firmware to be upgraded in the boot program firmware address space determined by the first data meta information and the second data meta information in the upgrade meta information; and The other firmware to be upgraded except the new partition table to be upgraded and the boot program firmware to be upgraded are stored in the corresponding firmware to be upgraded address space determined by the first data meta information and the third data meta information in the upgrade meta information.
7. The method according to claim 1, characterized in that Writing the upgrade meta-information into the second preset location of the boot communication partition of the current partition table includes: Storing the current boot program firmware data determined by the boot program firmware partition in the current partition table into the boot program backup firmware address space determined by the first data meta information and the fourth data meta information in the upgrade meta information; If the boot communication partition address space change flag of the first data meta-information in the upgrade meta-information is true, writing the constructed upgrade meta-information into a preset location for storing upgrade meta-information in the boot communication backup partition address space determined according to the first data meta-information and the fourth data meta-information in the upgrade meta-information, and writing a second-stage upgrade instruction into a preset location for storing upgrade instructions in the boot communication backup partition address space; and The constructed upgrade meta-information is written into the second preset location of the boot communication partition of the current partition table.
8. The method according to claim 7, characterized in that After writing the constructed upgrade meta information into the second preset location of the boot communication partition of the current partition table, the method further includes: Writing the second stage upgrade instruction into the first preset location of the boot communication partition of the current partition table; and Restart the device.
9. The method according to claim 1, characterized in that Determining the end address of the storage space of the firmware data to be upgraded and the base address of the data movement of the firmware data to be upgraded according to the boot communication partition address space change mark of the upgrade meta information read includes: Acquire the current partition table from the address space where the device partition table is located, and read the upgrade meta information from the second preset location of the boot communication partition in the current partition table; Checking whether the magic number of the upgrade meta information is the preset upgrade meta information magic number; If not, exit the firmware upgrade process; If so, calculating the digital digest of the first data metadata of the upgrade metadata according to the digital digest algorithm type of the upgrade metadata, and checking whether the calculated digital digest is the same as the digital digest of the first data metadata of the upgrade metadata; If they are not the same, exit the firmware upgrade process; If they are the same, calculating the digital digest of the fourth data metadata of the upgrade metadata according to the digital digest algorithm type of the upgrade metadata, and checking whether the calculated digital digest is the same as the digital digest of the fourth data metadata of the upgrade metadata; If the calculated digital digest is different from the digital digest of the fourth data metadata of the upgrade metadata, exit the firmware upgrade process; If the calculated digital digest is the same as the digital digest of the fourth data meta information of the upgrade meta information, determining whether the boot communication partition address space change flag of the first data meta information of the upgrade meta information is false; If the answer is false, determining the end address of the firmware data storage space to be upgraded according to the boot program backup firmware start address of the fourth data meta information of the upgrade meta information and the boot program backup firmware size of the fourth data meta information; If true, determining the end address of the firmware data storage space to be upgraded according to the boot communication backup partition start address of the fourth data meta information of the upgrade meta information and the boot communication backup partition size of the fourth data meta information; and The maximum value of the end address of the data storage space of the firmware to be upgraded and the starting address of the new user data partition of the first data meta information of the upgrade meta information is used as the base address for moving the data of the firmware to be upgraded.
10. The method according to claim 1, characterized in that If the storage space meets the preset requirement, copying the data in the address space determined by the end address of the data storage space of the firmware to be upgraded to the data move base address of the firmware to be upgraded, modifying the upgrade meta information, and writing the modified upgrade meta information into the second preset location of the boot communication partition includes: Subtract the storage medium tail reserved size of the first data meta information and the base address of the firmware data to be upgraded from the storage medium capacity of the first data meta information of the upgrade meta information to obtain a first result; Subtract the data storage area base address of the first data metadata of the upgrade metadata from the end address of the data storage space of the firmware to be upgraded to obtain a second result; Determining whether the first result is greater than or equal to the second result; If not, exit the firmware upgrade process; If so, copying the data in the address space determined by the data storage area base address of the first data meta-information of the upgrade meta-information and the end address of the data storage space of the firmware to be upgraded to the data movement base address of the firmware to be upgraded; Setting the data storage area base address of the first data meta information of the upgrade meta information as the data movement base address of the firmware to be upgraded, calculating the digital digest of the first data meta information of the upgrade meta information according to the digital digest algorithm type of the upgrade meta information, and saving the calculated digital digest to the digital digest of the first data meta information of the upgrade meta information, so as to modify the upgrade meta information; If the boot communication partition address space change flag of the first data meta-information of the upgrade meta-information is true, writing the modified upgrade meta-information into the preset location for storing the upgrade meta-information in the boot communication backup partition address space determined according to the first data meta-information and the fourth data meta-information in the upgrade meta-information, and writing the third stage upgrade instruction into the preset location for storing the upgrade instruction in the boot communication backup partition address space; and The modified upgrade meta information is written into the second preset location of the boot communication partition of the current partition table.
11. The method according to claim 10, characterized in that After writing the modified upgrade meta information into the second preset location of the boot communication partition of the current partition table, the method further includes: The third stage upgrade instruction is written into the first preset location of the boot communication partition of the current partition table.
12. The method according to claim 1, characterized in that Also includes: If the upgrade instruction information includes a third-stage upgrade instruction, modifying the current partition table according to the read upgrade meta-information; Write the modified current partition table into the address space where the device partition table is located, completing the upgrade of the modified current partition table; as well as The modified current partition table is used as the current partition table, and the fourth stage upgrade instruction is written into the first preset position of the boot communication partition of the current partition table.
13. The method according to claim 12, characterized in that Modifying the current partition table according to the read upgrade meta information includes: Acquire the current partition table from the address space where the device partition table is located, and read the upgrade meta information from the second preset location of the boot communication partition in the current partition table; Checking whether the magic number of the upgrade meta information is the preset upgrade meta information magic number; If no, exit the firmware upgrade process; If yes, calculating the digital digest of the first data metadata of the upgrade metadata according to the digital digest algorithm type of the upgrade metadata, and checking whether the calculated digital digest is the same as the digital digest of the first data metadata of the upgrade metadata; If they are not the same, exit the firmware upgrade process; If they are the same, calculating the digital digest of the fourth data metadata of the upgrade metadata according to the digital digest algorithm type of the upgrade metadata, and checking whether the calculated digital digest is the same as the digital digest of the fourth data metadata of the upgrade metadata; If the digital summary of the fourth data metadata of the upgrade metadata is different from the digital summary of the fourth data metadata of the upgrade metadata, then exit the firmware upgrade process; If the digital digest of the first data meta information of the upgrade meta information is the same as the digital digest of the fourth data meta information of the upgrade meta information, then, based on the digital digest algorithm type of the upgrade meta information, calculating a digital digest of data in an address space determined based on the data storage area base address of the first data meta information of the upgrade meta information, the boot program backup firmware start address of the fourth data meta information of the upgrade meta information, and the boot program backup firmware size of the fourth data meta information of the upgrade meta information, and checking whether the calculated digital digest is the same as the digital digest value of the boot program backup firmware of the fourth data meta information of the upgrade meta information; If the calculated digital digest is different from the boot program backup firmware digital digest value of the fourth data metadata of the upgrade metadata, exit the firmware upgrade process; and If the calculated digital digest is the same as the digital digest value of the boot program backup firmware of the fourth data metadata of the upgrade metadata, the current partition table is modified according to the upgrade metadata.
14. The method according to claim 1, wherein Also includes: If the upgrade instruction information includes a fourth-stage upgrade instruction, modifying the current partition table according to the read upgrade meta-information; Write the modified current partition table into the address space where the device partition table is located, completing the upgrade of the modified current partition table; Use the modified current partition table as the current partition table; Acquire a new partition table to be upgraded from the partition table address space determined by the first data meta information and the second data meta information in the upgrade meta information; Calculating a digital digest of the new partition table to be upgraded according to the digital digest algorithm type of the upgrade meta-information, and checking whether the calculated digital digest is the same as the digital digest value of the partition table to be upgraded in the second data meta-information of the upgrade meta-information; If the digital summary value of the partition table to be upgraded is different from the digital summary value of the second data metadata of the upgrade metadata, then exit the firmware upgrade process; If the digital summary value of the partition table to be upgraded is the same as the digital summary value of the partition table to be upgraded of the second data meta information of the upgrade meta information, obtaining the boot program firmware data to be upgraded from the boot program firmware address space to be upgraded determined by the first data meta information and the second data meta information in the upgrade meta information; Calculating a digital digest of the boot program firmware data to be upgraded according to the digital digest algorithm type of the upgrade meta information, and checking whether the calculated digital digest is the same as the digital digest value of the boot program firmware to be upgraded in the second data meta information of the upgrade meta information; If the digital summary value of the boot program firmware to be upgraded is different from the digital summary value of the second data metadata of the upgrade metadata, then exit the firmware upgrade process; If the digital digest value of the boot program firmware to be upgraded is the same as the digital digest value of the second data metadata of the upgrade metadata, writing the boot program firmware data to be upgraded into the address space corresponding to the boot program firmware partition of the new partition table; Writing the new partition table to be upgraded into the address space where the device partition table is located to complete the upgrade of the new partition table; Using the new partition table as the current partition table; as well as The fifth stage upgrade instruction is written into the first preset location of the boot communication partition of the current partition table.
15. The method according to claim 1, wherein Also includes: If the upgrade instruction information includes a fifth-stage upgrade instruction, then, based on the number of firmware items to be upgraded read from the third data metadata of the upgrade metadata, sequentially traverse each firmware item to be upgraded in the list of firmware items to be upgraded in the third data metadata of the upgrade metadata; For each firmware item to be upgraded that is traversed, reading data having a length equal to the size of the firmware to be upgraded of the firmware item to be upgraded as the firmware data to be upgraded according to the data storage area base address of the first data metadata of the upgrade metadata and the firmware offset address to be upgraded of the firmware item to be upgraded; Calculating a digital digest of the firmware data to be upgraded according to the digital digest algorithm type of the upgrade meta information, and checking whether the calculated digital digest is the same as the digital digest value of the firmware item to be upgraded; If the calculated digital digest is different from the digital digest value of the firmware item to be upgraded, then exit the firmware upgrade process; If the calculated digital digest is the same as the digital digest value of the firmware to be upgraded of the firmware to be upgraded item, then writing the firmware to be upgraded data into the address space corresponding to the firmware to be upgraded partition name of the firmware to be upgraded item in the new partition table; as well as All readable and writable partition erasing instructions are written into a first preset location of the boot communication partition of the current partition table.
16. The method according to claim 1, wherein Also includes: If the upgrade instruction information includes an instruction to erase all readable and writable partitions, then mounting a corresponding file system on each readable and writable partition in a preset readable and writable partition list having a file system, and determining whether the mounting is successful; If the mount is successful, no operation is performed; If the mounting fails, erasing the corresponding readable and writable partition and formatting the readable and writable partition; Erase each readable and writable partition in the preset readable and writable partition list without a file system; Erasing the upgrade instruction information in the first preset location of the boot communication partition and the upgrade meta information in the second preset location; as well as Restart the device to enter the upgraded system.
17. 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 16.
Citation Information
Cited By
Firmware upgrading method and electronic equipment
CN120950101A
Method for upgrading firmware, electronic device
CN120950101B
Equipment upgrading method, equipment upgrading device and computer storage medium
CN121233147A