Method for upgrading firmware, electronic device
By storing firmware storage and upgrade metadata in the main storage medium, the complexity and reliability issues caused by boot communication partition backup are resolved, achieving reliability and security that firmware upgrades can still be completed after power failure.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-25
- Publication Date
- 2026-03-17
AI Technical Summary
Existing firmware upgrade methods are complex and error-prone when backing up the boot communication partition, and cannot guarantee the completion of the upgrade after a power outage during the upgrade process, resulting in decreased reliability.
By storing firmware storage and upgrade metadata in the main storage medium, the reliance on the boot communication partition is avoided. By utilizing the information stored simultaneously in the main storage medium and the boot communication partition, it is ensured that there is always legitimate firmware storage and upgrade metadata during the upgrade process, enabling mutual data recovery and continuing the upgrade process even after power failure.
It reduces the complexity and error rate of the upgrade process, improves the reliability of firmware upgrades, and ensures that upgrades can still be completed even after a power outage at any time.
Smart Images

Figure CN120950101B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of embedded technology, and more particularly to methods for upgrading firmware and electronic devices. Background Technology
[0002] Some existing firmware upgrade methods require backing up the boot communication partition during the upgrade process. Since the boot communication partition is readable and writable during the upgrade process, backing up the boot communication partition usually makes the upgrade process more complicated and prone to errors. If a power failure occurs at any time during the upgrade process, it cannot be guaranteed that the upgrade can continue after power is restored, resulting in a decrease in the reliability of the firmware upgrade. Summary of the Invention
[0003] This invention provides a method and electronic device for upgrading firmware, which can effectively improve the reliability of firmware upgrades.
[0004] In one aspect of the present invention, a method for upgrading firmware is provided. The method includes: obtaining a firmware upgrade package; writing a first-stage upgrade instruction and an upgrade package path to a boot communication partition; and restarting the device; in the bootloader firmware, reading data of a preset size equal to the firmware storage and upgrade metadata from the starting address of the firmware storage and upgrade metadata in the main storage medium as firmware storage and upgrade metadata; if the firmware storage and upgrade metadata is determined to be invalid, reading the first-stage upgrade instruction from the boot communication partition to boot the device into upgrade mode firmware; if the firmware storage and upgrade metadata is determined to be valid, using the upgrade instruction in the basic information of the firmware storage and upgrade metadata as a second-stage upgrade instruction, and reading it from the boot communication partition. The firmware storage and upgrade metadata is read from a preset location in the partition. Based on the basic information of the firmware storage and upgrade metadata in the boot communication partition, the data in the firmware storage area is written to the firmware storage area redirection base address. The firmware storage and upgrade metadata is updated to use the upgrade instruction in the basic information of the firmware storage and upgrade metadata as the third-stage upgrade instruction. The updated firmware storage and upgrade metadata is written to the boot communication partition and the main storage medium. The current upgrade instruction is set as the third-stage upgrade instruction, and the set current upgrade instruction is written to the boot communication partition to perform firmware upgrade based on the third-stage upgrade instruction.
[0005] In another aspect of the invention, an electronic device is provided. The electronic device includes a memory configured to store an executable program; and a processor configured to execute the program to perform the aforementioned method for upgrading firmware.
[0006] According to the technical solution of the present invention, data of a preset size for firmware storage and upgrade metadata is read from the starting address of the firmware storage and upgrade metadata in the main storage medium as firmware storage and upgrade metadata. If the firmware storage and upgrade metadata is invalid, a first-stage upgrade instruction is read from the boot communication partition to guide the device into upgrade mode firmware. If the firmware storage and upgrade metadata is valid, the upgrade instruction in the basic information of the firmware storage and upgrade metadata is used as the second-stage upgrade instruction. The firmware storage and upgrade metadata is read from a preset position in the boot communication partition. Based on the basic information of the firmware storage and upgrade metadata in the boot communication partition, the data in the firmware storage area is written to the firmware storage area redirection base address, and the firmware storage and upgrade metadata is updated to use the upgrade instruction in the basic information of the firmware storage and upgrade metadata as the third-stage upgrade instruction. The updated firmware storage and upgrade metadata is written to the boot communication partition and the main storage medium. The current upgrade instruction is set as the third-stage upgrade instruction, and the set current upgrade instruction is written to the boot communication partition to perform firmware upgrade based on the third-stage upgrade instruction. This method eliminates the need to back up the boot communication partition. By storing firmware storage and upgrade metadata in the main storage medium, it avoids dependence on the boot communication partition during the upgrade process, reducing the complexity and error rate of the upgrade process. Furthermore, by simultaneously storing firmware storage and upgrade metadata in both the main storage medium and the boot communication partition, it ensures that valid firmware storage and upgrade metadata are always available during the upgrade process. If firmware storage and upgrade metadata in one location are corrupted, they can be mutually recovered, preventing the loss of firmware storage and upgrade metadata due to power failure at any point during the upgrade process. Additionally, by storing upgrade commands in both the firmware storage and upgrade metadata and the boot communication partition, upgrade commands in the corrupted boot communication partition can be recovered using upgrade commands in the firmware storage and upgrade metadata, and vice versa. This ensures that valid upgrade command information is always available during the upgrade process, and that the upgrade can continue after power is restored even if a power failure occurs at any point during the upgrade process, thereby effectively improving the reliability of firmware upgrades. Attached Figure Description
[0007] Figure 1 This is a flowchart illustrating the steps of a firmware upgrade method according to an embodiment of the present invention.
[0008] Figure 2 This is a flowchart illustrating a method for upgrading firmware according to an embodiment of the present invention;
[0009] Figure 3 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. Detailed Implementation
[0010] To explain in detail the technical content, objectives, and effects of the present invention, the following description is provided in conjunction with the embodiments and accompanying drawings.
[0011] In existing technologies, firmware upgrade methods that support arbitrary partition table changes typically rely on external storage media (such as USB flash drives or SD cards). Firmware upgrade methods that do not rely on external storage media and support arbitrary partition table changes usually require multiple upgrades and cannot guarantee complete reliability during the upgrade process. Some firmware upgrade methods that do not rely on external storage media can ensure reliable upgrades when the partition table changes, but they usually require that the address space of the default user data partition cannot change in the new partition table. Other firmware upgrade methods can support arbitrary partition table changes without relying on external storage media, but these methods all require backing up the boot communication partition during the upgrade process and usually only support a certain default upgrade package format. Since the boot communication partition is readable and writable during the upgrade process, backing up the boot communication partition usually makes the upgrade process more complex and error-prone. If a power outage occurs at any point during the upgrade process, it cannot be guaranteed that the upgrade will continue after power is restored, leading to a decrease in the reliability of the firmware upgrade.
[0012] To address at least the aforementioned technical problems, this disclosure provides a method for upgrading firmware. According to embodiments of this disclosure, data of a preset size for firmware storage and upgrade metadata is read from the starting address of the firmware storage and upgrade metadata in the main storage medium as firmware storage and upgrade metadata. If the firmware storage and upgrade metadata is invalid, a first-stage upgrade instruction is read from the boot communication partition to guide the device into upgrade mode firmware. If the firmware storage and upgrade metadata is valid, the upgrade instruction in the basic information of the firmware storage and upgrade metadata is used as a second-stage upgrade instruction. The firmware storage and upgrade metadata is read from a preset location in the boot communication partition. Based on the basic information of the firmware storage and upgrade metadata in the boot communication partition, data in the firmware storage area is written to the firmware storage area redirection base address, and the firmware storage and upgrade metadata is updated to use the upgrade instruction in the basic information of the firmware storage and upgrade metadata as a third-stage upgrade instruction. The updated firmware storage and upgrade metadata is written to the boot communication partition and the main storage medium. The current upgrade instruction is set as the third-stage upgrade instruction, and the set current upgrade instruction is written to the boot communication partition to perform a firmware upgrade based on the third-stage upgrade instruction. This method eliminates the need to back up the boot communication partition. By storing firmware storage and upgrade metadata in the main storage medium, it avoids dependence on the boot communication partition during the upgrade process, reducing the complexity and error rate of the upgrade process. Furthermore, by simultaneously storing firmware storage and upgrade metadata in both the main storage medium and the boot communication partition, it ensures that valid firmware storage and upgrade metadata are always available during the upgrade process. If firmware storage and upgrade metadata in one location are corrupted, they can be mutually recovered, preventing the loss of firmware storage and upgrade metadata due to power failure at any point during the upgrade process. Additionally, by storing upgrade commands in both the firmware storage and upgrade metadata and the boot communication partition, upgrade commands in the corrupted boot communication partition can be recovered using upgrade commands in the firmware storage and upgrade metadata, and vice versa. This ensures that valid upgrade command information is always available during the upgrade process, and that the upgrade can continue after power is restored even if a power failure occurs at any point during the upgrade process, thereby effectively improving the reliability of firmware upgrades.
[0013] This disclosure requires that the last partition in the partition table is a preset user data partition. Upgrade mode firmware refers to firmware that contains the firmware upgrade engine and performs the actual upgrade, such as recovery firmware. Dependent firmware of upgrade mode firmware refers to firmware required to boot before the upgrade mode firmware boots during device startup, as well as firmware that the upgrade mode firmware depends on during its operation. The upgrade mode firmware dependent firmware list is a firmware list consisting of all dependent firmware of the upgrade mode firmware. The upgrade mode firmware dependent firmware list includes the bootloader firmware. The boot communication partition is a raw partition used for communication between the system, the bootloader firmware, and the upgrade mode firmware. The block list description file partition is a non-encrypted partition, such as a cache partition, used to store a block list description file (such as block.map) of the firmware upgrade package.
[0014] In the following, the technical solutions according to this disclosure will be described with reference to specific embodiments and in conjunction with the accompanying drawings.
[0015] Figure 1 This is a flowchart illustrating a method 100 for upgrading firmware according to an embodiment of the present disclosure. (Refer to...) Figure 1 The method 100 includes the following steps 102 to 110.
[0016] In step 102, the firmware upgrade package is obtained, the first-stage upgrade instruction and upgrade package path are written to the boot communication partition, and the device is restarted.
[0017] In some embodiments, the client obtains a firmware upgrade package and saves it to a preset firmware upgrade package path in a preset user data partition. The validity of the firmware upgrade package is determined. If valid, the validity of the preset user data partition is determined. If not encrypted, the upgrade package path is set to the preset firmware upgrade package path in the preset user data partition. If encrypted, a preset decryption service is used to generate a block list occupied by the firmware upgrade package file, and the block data in the block list is decrypted. Simultaneously, the decrypted data is rewritten to the corresponding blocks, and the corresponding block list is saved to a preset block list description file path in a preset block list description file partition. The upgrade package path is then set to the preset block list description file path in the preset block list description file partition.
[0018] In this way, if the preset user data partition is not encrypted, the upgrade package path is set to the preset firmware upgrade package path of the preset user data partition. If it is encrypted, the block data in the block list is decrypted, and the decrypted data is rewritten to the corresponding block. The corresponding block list is saved to the preset block list description file path of the preset block list description file partition, and the upgrade package path is set to the preset block list description file path of the preset block list description file partition. This method can support both encrypted and unencrypted preset user data partitions, improving the flexibility of firmware upgrades.
[0019] In step 104, in the bootloader firmware, data of a preset size for firmware storage and upgrade metadata is read from the starting address of the firmware storage and upgrade metadata in the main storage medium and used as firmware storage and upgrade metadata.
[0020] In step 106, if it is determined that the firmware storage and upgrade metadata is invalid, the first-stage upgrade instruction is read from the boot communication partition to guide the device into upgrade mode firmware.
[0021] In step 108, if the firmware storage and upgrade metadata is deemed valid, the upgrade instruction in the basic information of the firmware storage and upgrade metadata is used as the second-stage upgrade instruction. The firmware storage and upgrade metadata is read from a preset location in the boot communication partition. Based on the basic information of the firmware storage and upgrade metadata in the boot communication partition, the data in the firmware storage area is written to the firmware storage area redirection base address. The firmware storage and upgrade metadata is then updated so that the upgrade instruction in the basic information of the firmware storage and upgrade metadata is used as the third-stage upgrade instruction. The updated firmware storage and upgrade metadata is then written to the boot communication partition and the main storage medium.
[0022] In some embodiments, it is determined whether the firmware storage and upgrade metadata is valid. If valid, the address space of the firmware storage area is determined according to the starting address and length of the firmware storage area in the basic information of the firmware storage and upgrade metadata. The data in the address space of the firmware storage area is written to the firmware storage area redirection base address in the basic information of the firmware storage and upgrade metadata, wherein the size of the written data is the length of the firmware storage area in the basic information of the firmware storage and upgrade metadata.
[0023] In this way, when the firmware storage and upgrade metadata read from the boot communication partition is valid, the data in the address space of the firmware storage area is written to the firmware storage area redirection base address in the basic information of the firmware storage and upgrade metadata, thus realizing the transfer of firmware storage area data. This ensures that even if there is an unexpected power failure during the subsequent upgrade process, the corresponding data can be obtained from the firmware storage area redirection base address after power is restored to complete the upgrade smoothly.
[0024] In some embodiments, the upgrade instruction in the basic information of the firmware storage and upgrade meta-information is set as the third-stage upgrade instruction. A digital digest of the basic information of the firmware storage and upgrade meta-information is calculated according to the digital digest algorithm type of the firmware storage and upgrade meta-information, and the digital digest of the basic information is saved to the basic information digest value of the firmware storage and upgrade meta-information. A digital digest of the data in the firmware storage and upgrade meta-information, consisting of the basic information digest value, basic information, mass-produced firmware package storage information, Android format upgrade package storage information, upgrade mode firmware and upgrade mode dependent firmware list storage information, image file upgrade package system firmware storage information, and upgrade mode firmware and upgrade mode dependent firmware list backup information, is calculated according to the digital digest algorithm type of the firmware storage and upgrade meta-information, and the digital digest of the data is saved to the meta-information digital digest of the firmware storage and upgrade meta-information. The firmware storage and upgrade meta-information is written into the boot communication partition. The size of the main storage medium is obtained, and the preset storage medium tail reserved size and the preset size of the firmware storage and upgrade meta-information are subtracted from the main storage medium size to obtain the starting address of the firmware storage and upgrade meta-information in the main storage medium. In addition, the firmware storage and upgrade metadata is written to the starting address of the firmware storage and upgrade metadata in the main storage medium.
[0025] In this way, the firmware storage and upgrade metadata are updated and written to the boot communication partition. The starting address of the firmware storage and upgrade metadata in the main storage medium is obtained by subtracting the preset size reserved at the end of the main storage medium and the preset size of the firmware storage and upgrade metadata from the size of the main storage medium. The updated firmware storage and upgrade metadata is also written to the preset position at the end of the main storage medium. By storing the firmware storage and upgrade metadata in both the main storage medium and the boot communication partition, it is possible to ensure that there is always valid firmware storage and upgrade metadata during the upgrade process without relying on external storage media or backing up the boot communication partition. Even if a power outage occurs at any time during the upgrade process and the power is restored, the upgrade can still be completed using the firmware storage and upgrade metadata.
[0026] In step 110, the current upgrade instruction is set to the third-stage upgrade instruction, and the set current upgrade instruction is written to the boot communication partition to perform firmware upgrade based on the third-stage upgrade instruction.
[0027] In some embodiments, the method 100 may further include: if the current upgrade instruction is the third-stage upgrade instruction, then reading the firmware storage and upgrade metadata from the main storage medium and determining whether the read firmware storage and upgrade metadata is valid. If the read firmware storage and upgrade metadata is invalid, then reading the firmware storage and upgrade metadata from the boot communication partition as backup firmware storage and upgrade metadata, and using the backup firmware storage and upgrade metadata to update the firmware storage and upgrade metadata in the main storage medium. Reading the upgrade instruction from the boot communication partition and determining whether the read upgrade instruction is consistent with the upgrade instruction in the basic information of the firmware storage and upgrade metadata. If inconsistent, writing the upgrade instruction in the basic information of the firmware storage and upgrade metadata into the boot communication partition. Obtaining the current partition table from the address space where the partition table is located in the main storage medium. Performing a validity check on each backup firmware item in the backup firmware item list of the upgrade mode firmware and upgrade mode dependent firmware list backup information of the firmware storage and upgrade metadata based on the current partition table. If the validity check results are all valid, the current partition table is modified based on the firmware storage and upgrade metadata to obtain a modified current partition table. The modified current partition table is written into the address space of the partition table in the main storage medium. The firmware storage and upgrade metadata is updated, and the updated firmware storage and upgrade metadata is written into the boot communication partition. The current upgrade instruction is set to the fourth-stage upgrade instruction, and the set current upgrade instruction is written into the boot communication partition. Furthermore, the updated firmware storage and upgrade metadata is written into the main storage medium.
[0028] In this way, during the third-stage upgrade process, the validity of the firmware storage and upgrade metadata read from the main storage medium is determined. If it is invalid, the firmware storage and upgrade metadata is read from the boot communication partition as backup firmware storage and upgrade metadata, and the firmware storage and upgrade metadata in the main storage medium is updated using the backup firmware storage and upgrade metadata. This ensures the security and reliability of the firmware storage and upgrade metadata, thereby improving the security of firmware upgrades. Furthermore, based on the current partition table, the validity of each backup firmware item in the backup firmware item list of the upgrade mode firmware and upgrade mode dependent firmware list backup information is checked. If the validity check result is valid, the current partition table is modified based on the firmware storage and upgrade metadata, and the modified current partition table is written into the address space where the partition table resides in the main storage medium, achieving a secure and reliable upgrade operation on the modified current partition table.
[0029] In some embodiments, the method 100 may further include: if the current upgrade instruction is a fourth-stage upgrade instruction, reading the firmware storage and upgrade metadata from the main storage medium and determining whether the read firmware storage and upgrade metadata is valid. If valid, writing the firmware storage and upgrade metadata into the boot communication partition. If invalid, reading the firmware storage and upgrade metadata from the boot communication partition as backup firmware storage and upgrade metadata, and updating the firmware storage and upgrade metadata in the main storage medium using the backup firmware storage and upgrade metadata. Reading the upgrade instruction from the boot communication partition and determining whether the read upgrade instruction is consistent with the upgrade instruction in the basic information of the firmware storage and upgrade metadata. If inconsistent, writing the upgrade instruction in the basic information of the firmware storage and upgrade metadata into the boot communication partition. Obtaining the upgrade package type of the firmware upgrade package based on the firmware storage and upgrade metadata, wherein the upgrade package type is a mass-produced firmware upgrade package type, an image file upgrade package type, or an Android format upgrade package type. Upgrading the partition table to be upgraded based on the firmware storage and upgrade metadata according to the upgrade package type to obtain a new partition table. The firmware storage and upgrade metadata is updated, and the updated firmware storage and upgrade metadata is written to the boot communication partition of the new partition table. The current upgrade instruction is set to the fifth-stage upgrade instruction, and the set current upgrade instruction is written to the boot communication partition of the new partition table. Furthermore, the updated firmware storage and upgrade metadata is written to the main storage medium.
[0030] In this way, during the fourth-stage upgrade process, the upgrade package type of the firmware upgrade package is obtained based on the firmware storage and upgrade metadata. The upgrade package type can be a mass-produced firmware upgrade package type, an image file upgrade package type, or an Android format upgrade package type. Based on the upgrade package type, the partition table to be upgraded is upgraded according to the firmware storage and upgrade metadata to obtain a new partition table. This method can support multiple upgrade package types and improve the universality of firmware upgrades.
[0031] In some embodiments, the method 100 may further include: if the current upgrade instruction is a fifth-stage upgrade instruction, then reading firmware storage and upgrade metadata from the main storage medium and determining whether the read firmware storage and upgrade metadata is valid. If invalid, then reading the firmware storage and upgrade metadata from the boot communication partition as backup firmware storage and upgrade metadata, and using the backup firmware storage and upgrade metadata to update the firmware storage and upgrade metadata in the main storage medium. Reading the upgrade instruction from the boot communication partition and determining whether the read upgrade instruction is consistent with the upgrade instruction in the basic information of the firmware storage and upgrade metadata. If inconsistent, writing the upgrade instruction in the basic information of the firmware storage and upgrade metadata into the boot communication partition. Determining whether the upgrade package type of the firmware upgrade package in the basic information of the firmware storage and upgrade metadata is an Android format upgrade package type. If the upgrade package type is an Android format upgrade package type, then obtaining Android format upgrade package data based on the firmware storage and upgrade metadata, and transferring the Android format upgrade package data to the Android upgrade package redirection address based on the firmware storage and upgrade metadata. The firmware storage and upgrade metadata is updated, and the updated firmware storage and upgrade metadata is written to the boot communication partition. The current upgrade command is set to the sixth-stage upgrade command, and the set current upgrade command is written to the boot communication partition. In addition, the updated firmware storage and upgrade metadata is written to the main storage medium.
[0032] In this way, if the firmware upgrade package type in the basic information of firmware storage and upgrade metadata is an Android format upgrade package, then the Android format upgrade package data is obtained based on the firmware storage and upgrade metadata, and the Android format upgrade package data is transferred to the Android upgrade package redirection address based on the firmware storage and upgrade metadata. This supports Android format upgrade packages, can be seamlessly integrated with the existing Android upgrade process, does not require additional upgrade process writing, improves the universality of firmware upgrades, reduces the complexity of firmware upgrades, and transfers Android format upgrade package data to avoid data corruption and inability to continue the upgrade process in the event of an unexpected power outage, thus improving the reliability of firmware upgrades.
[0033] In some embodiments, the method 100 may further include setting the upgrade instruction in the basic information of the firmware storage and upgrade metadata as a seventh-stage upgrade instruction. If the current upgrade instruction is the seventh-stage upgrade instruction, the firmware storage and upgrade metadata is read from the main storage medium. The validity of the read firmware storage and upgrade metadata is determined. If the read firmware storage and upgrade metadata is invalid, the firmware storage and upgrade metadata is read from the boot communication partition as backup firmware storage and upgrade metadata, and the backup firmware storage and upgrade metadata is used to update the firmware storage and upgrade metadata in the main storage medium. An upgrade instruction is read from the boot communication partition, and it is determined whether the read upgrade instruction is consistent with the upgrade instruction in the basic information of the firmware storage and upgrade metadata. If they are inconsistent, the upgrade instruction in the basic information of the firmware storage and upgrade metadata is written into the boot communication partition. The upgrade package type of the firmware upgrade package is obtained based on the firmware storage and upgrade metadata. If the upgrade package type is a mass-production firmware upgrade package type or an image file upgrade package type, then the partition table to be upgraded is upgraded based on the firmware storage and upgrade metadata according to the mass-production firmware upgrade package type or the image file upgrade package type, resulting in a new partition table. The firmware storage and upgrade metadata are updated, and the updated firmware storage and upgrade metadata are written to the boot communication partition. The current upgrade instruction is set as a preset post-upgrade processing instruction, and the set current upgrade instruction is written to the boot communication partition. In addition, the updated firmware storage and upgrade metadata are written to the main storage medium.
[0034] In this way, if the upgrade package type is a mass production firmware upgrade package type or an image file upgrade package type, the partition table to be upgraded is upgraded based on the firmware storage and upgrade metadata according to the mass production firmware upgrade package type or image file upgrade package type, and a new partition table is obtained. This method can support multiple types of upgrade packages and improve the flexibility of firmware upgrades.
[0035] In some embodiments, the method 100 may further include controlling the device to run upgrade mode firmware if the current upgrade instruction is a first-stage upgrade instruction, a sixth-stage upgrade instruction, an eighth-stage upgrade instruction, or a preset post-upgrade processing instruction. In the upgrade mode firmware, an upgrade instruction is read from the boot communication partition, and it is determined whether the read upgrade instruction is a first-stage upgrade instruction, a sixth-stage upgrade instruction, an eighth-stage upgrade instruction, or a preset post-upgrade processing instruction. If so, the read upgrade instruction is used as the current upgrade instruction. If the current upgrade instruction is a first-stage upgrade instruction, the firmware storage and upgrade metadata are constructed based on the firmware upgrade package. Data in the firmware upgrade package is stored in the target address space based on the firmware storage and upgrade metadata. The upgrade mode firmware and each dependent firmware in the upgrade mode firmware dependent firmware list in the firmware storage and upgrade metadata are stored in the target backup address space. The upgrade instruction in the basic information of the firmware storage and upgrade metadata is set to the second-stage upgrade instruction. The firmware storage and upgrade metadata are updated. In addition, the updated firmware storage and upgrade metadata and the second-stage upgrade instruction are written into the boot communication partition, and the device is restarted.
[0036] In this way, if the current upgrade command is a first-stage upgrade command, firmware storage and upgrade metadata are constructed based on the firmware upgrade package. Data from the firmware upgrade package is then stored in the target address space based on this metadata. Each dependent firmware in the upgrade mode firmware and its dependent firmware list from the firmware storage and upgrade metadata is stored in the target backup address space, achieving data backup and ensuring that even if an error occurs during the upgrade process, safe and reliable data can still be stored to complete the upgrade. Furthermore, the upgrade command is stored in the firmware storage and upgrade information and the boot communication partition. If an unexpected event occurs at any point during the upgrade process, the upgrade can always resume from the most recent upgrade stage after power-on, improving upgrade reliability.
[0037] In some embodiments, the method 100 may further include, if the current upgrade instruction is the sixth-stage upgrade instruction, erasing and formatting each partition in a preset readable and writable partition list with a file system, each partition including a preset user data partition and a block list description file partition. The firmware storage and upgrade metadata is read from the boot communication partition as backup firmware storage and upgrade metadata. The validity of the backup firmware storage and upgrade metadata is determined. If valid, Android format upgrade package data is obtained based on the backup firmware storage and upgrade metadata. An Android format upgrade package file is created under a preset firmware upgrade package path in the preset user data partition, and the Android format upgrade package data is written to the Android format upgrade package file. The backup firmware storage and upgrade metadata is updated, and the updated backup firmware storage and upgrade metadata is written to the boot communication partition. Furthermore, the current upgrade instruction is set to the eighth-stage upgrade instruction, and the set current upgrade instruction is written to the boot communication partition.
[0038] In some embodiments, the method 100 may further include determining whether the Android format upgrade package file exists in the preset firmware upgrade package path of the preset user data partition if the current upgrade instruction is the eighth stage upgrade instruction. If it does not exist, the firmware storage and upgrade metadata and the upgrade instruction in the boot communication partition are cleared, and the device is restarted. If it exists, the Android system firmware is upgraded using a standard Android firmware upgrade engine based on the Android format upgrade package file in the preset firmware upgrade package path of the preset user data partition. During the upgrade process, the upgrade mode firmware and the dependent firmware in the upgrade mode dependent firmware list are not upgraded. After the upgrade is completed, the preset user data partition is formatted. In addition, the firmware storage and upgrade metadata and the upgrade instruction in the boot communication partition are cleared, and the device is restarted.
[0039] In this way, if the upgrade package type is an Android format upgrade package, in the sixth stage of the upgrade, the Android format upgrade package data is obtained based on the backup firmware storage and upgrade metadata. An Android format upgrade package file is created under the preset firmware upgrade package path of the preset user data partition, and the Android format upgrade package data is written to the Android format upgrade package file. Based on the Android format upgrade package file under the preset firmware upgrade package path of the preset user data partition, the standard Android firmware upgrade engine is used to upgrade the Android system firmware. During the upgrade process, the upgrade mode firmware and the dependent firmware in the upgrade mode dependent firmware list are not upgraded. The firmware upgrade can be performed smoothly even when any partition in the partition table (including the preset user data partition) changes.
[0040] In some embodiments, the method 100 may further include erasing and formatting each partition in a preset readable and writable partition list having a file system if the current upgrade instruction is the preset post-upgrade processing instruction, each partition including a preset user data partition and a block list description file partition. Additionally, the firmware storage and upgrade metadata and the upgrade instruction in the boot communication partition are cleared, and the device is restarted.
[0041] In this way, if the current upgrade command is the preset post-upgrade processing command, it means that the upgrade has been completed. Each partition in the preset readable and writable partition list with the file system is erased and formatted. Firmware storage and upgrade metadata and upgrade commands in the boot communication partition are cleared to avoid repeated upgrades and to prepare for the next firmware upgrade.
[0042] The following will describe, through examples, the application scenarios of the firmware upgrade method and device according to embodiments of the present invention.
[0043] Figure 2 This is a flowchart illustrating a method for upgrading firmware according to an embodiment of the present invention. Figure 2 As shown, the method includes steps 201 to 215.
[0044] In step 201, the firmware upgrade package is obtained and saved to the preset firmware upgrade package path in the preset user data partition.
[0045] In this embodiment, the firmware upgrade package type is a mass-produced firmware upgrade package, an image file upgrade package, or an Android format upgrade package.
[0046] A mass-production firmware upgrade package is an upgrade package containing a single mass-production firmware file. This single mass-production firmware file is a unified firmware file generated according to a preset storage format, containing all the firmware and firmware partition table required at the device's factory. The firmware partition table can be obtained from this single mass-production firmware file in the preset storage format within the firmware upgrade package, or the corresponding firmware data can be obtained from the single mass-production firmware file in the preset storage format based on the partition name. An image file upgrade package is an upgrade package consisting of 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 a prefix to their names. For example, the prefix "super" in the firmware image file "super.img" indicates that the partition name corresponding to the image file is "super," and the prefix "boot_a.img" in the firmware image file "boot_a" indicates that the partition name corresponding to the image file is "boot_a." Android format upgrade packages are standard Android upgrade packages supported by the Android system recovery upgrade mode. The firmware in these packages is divided into two categories: one is upgrade mode firmware (such as Android recovery firmware) and a list of firmware dependencies for upgrade mode firmware. This firmware is included in the Android format upgrade package as a firmware image file. The firmware image file uses the partition name corresponding to the image file as a prefix, and the firmware partition table is included in the Android format upgrade package as a partition table file with a preset name. The other category consists of other firmware files besides upgrade mode firmware and the list of firmware dependencies for upgrade mode firmware. This includes Android Open Source Project (AOSP) system firmware such as system, vendor, odm, and system_ext. These firmware files are stored in the upgrade package according to the Android format and consist of Android format upgrade files. For example, the system firmware consists of three upgrade files: system.new.dat.br, system.patch.dat, and system.transfer.list.
[0047] In step 202, it is determined whether the firmware upgrade package is valid. If it is invalid, the firmware upgrade package under the preset firmware upgrade package path of the preset user data partition is deleted, and the firmware upgrade process is exited. If it is valid, step 203 is executed.
[0048] In step 203, it is determined whether the preset user data partition is encrypted. If it is not encrypted, the upgrade package path is set to the preset firmware upgrade package path of the preset user data partition. If it is encrypted, the preset decryption service (such as uncrypt under Android) is used to generate a block list occupied by the firmware upgrade package file, and the block data in the block list is decrypted. At the same time, the decrypted data is rewritten to the corresponding block, and the corresponding block list is saved to the preset block list description file path of the preset block list description file partition (such as / cache / recovery / block.map). The upgrade package path is set to the preset block list description file path of the preset block list description file partition.
[0049] In step 204, the first-stage upgrade instruction is written in the first preset location of the boot communication partition, the upgrade package path is written in the second preset location of the boot communication partition, and the device is restarted.
[0050] Each time the device is restarted, the device automatically runs the bootloader firmware.
[0051] In step 205, firmware storage and upgrade metadata is read from the main storage medium in the bootloader firmware.
[0052] In some embodiments, the actual capacity of the main storage medium is obtained as the size of the main storage medium. The size of the main storage medium is subtracted by the preset size reserved at the end of the storage medium and the preset size of the firmware storage and upgrade metadata, and the result is used as the starting address of the firmware storage and upgrade metadata. Data of the preset size of the firmware storage and upgrade metadata is read from the starting address of the firmware storage and upgrade metadata of the main storage medium as the firmware storage and upgrade metadata.
[0053] In this embodiment, the firmware storage and upgrade metadata includes magic number, digital digest algorithm type, metadata digital digest, basic information digest value, basic information, mass production firmware package storage information, Android format upgrade package storage information, upgrade mode firmware and upgrade mode dependent firmware list storage information, image file upgrade package system firmware storage information, and upgrade mode firmware and upgrade mode dependent firmware list backup information.
[0054] In this embodiment, the basic information includes upgrade instructions, user data partition encryption marker, upgrade package type, firmware storage area start address, firmware storage area length, firmware storage area redirection base address, mass-produced firmware package storage information digest value, Android format upgrade package storage information digest value, upgrade mode firmware and upgrade mode dependent firmware list storage information digest value, image file upgrade package system firmware storage information digest value, and upgrade mode firmware and upgrade mode dependent firmware list backup information digest.
[0055] The storage information for mass-produced firmware packages includes the starting offset address of the mass-produced firmware file storage area, the size of the mass-produced firmware file, and the digital digest value of the mass-produced firmware file. The storage information for Android format upgrade packages includes the starting offset address of the upgrade package storage area, the Android upgrade package redirection address, the upgrade package size, and the digital digest value of the upgrade package.
[0056] The upgrade mode firmware and upgrade mode dependent firmware list storage information includes the total size of upgrade mode related firmware data, the starting offset address of the upgrade mode related firmware storage area, the offset address of the partition table storage area, the size of the partition table, the digital digest value of the partition table data, the number of firmware items, and the firmware item list. Each firmware item in the firmware item list consists of the firmware partition name, firmware data offset address, firmware data size, and firmware data digital digest value.
[0057] The system firmware storage information of the image file upgrade package includes the total size of the system firmware data, the starting offset address of the system firmware storage area, the number of system firmware items, and the system firmware item list. Each system firmware item in the system firmware item list consists of the system firmware partition name, the system firmware data offset address, the system firmware data size, and the system firmware data digital digest value.
[0058] The backup information for upgrade mode firmware and upgrade mode dependent firmware list includes the total size of backup firmware data, the starting offset address of backup firmware area, the number of backup firmware items, and the list of backup firmware items. Each backup firmware item in the backup firmware item list consists of the backup firmware partition name, backup firmware data offset address, backup firmware data size, and backup firmware data digital digest value.
[0059] In step 206, it is determined whether the read firmware storage and upgrade metadata is valid. If it is valid, the upgrade instruction in the firmware storage and upgrade metadata is used as the current upgrade instruction. If it is invalid, the upgrade instruction read from the boot communication partition is used as the current upgrade instruction. Specifically, it includes the following steps (1) to (3).
[0060] (1) Determine whether the magic number of firmware storage and upgrade metadata is the preset magic number of firmware storage and upgrade metadata. If not, proceed to step (2). If yes, calculate the digital digest of the data in firmware storage and upgrade metadata composed of basic information digest value, basic information, mass production firmware package storage information, Android format upgrade package storage information, upgrade mode firmware and upgrade mode dependent firmware list storage information, image file upgrade package system firmware storage information and upgrade mode firmware and upgrade mode dependent firmware list backup information according to the digital digest algorithm type of firmware storage and upgrade metadata. Determine whether the calculated digital digest is the same as the metadata digital digest of firmware storage and upgrade metadata. If not, proceed to step (2). If yes, proceed to step (3).
[0061] (2) Read the upgrade instruction from the first preset position in the boot communication partition, and use the read upgrade instruction as the current upgrade instruction, and then execute step 207.
[0062] (3) Calculate the digital digest of the basic information of the firmware storage and upgrade metadata according to the digital digest algorithm type of the firmware storage and upgrade metadata, and determine whether the calculated digital digest is consistent with the basic information digest value of the firmware storage and upgrade metadata. If it is consistent, the upgrade instruction in the basic information of the firmware storage and upgrade metadata is used as the current upgrade instruction, and then step 207 is executed. If it is inconsistent, step (2) is executed.
[0063] In step 207, it is determined whether the current upgrade instruction is a first-stage upgrade instruction. If yes, the device is controlled to run the upgrade mode firmware; otherwise, step 208 is executed.
[0064] In step 208, it is determined whether the current upgrade instruction is a second-stage upgrade instruction. If so, the firmware is upgraded based on the second-stage upgrade instruction. If not, step 209 is executed.
[0065] In this embodiment, firmware upgrade is performed based on the second-stage upgrade instruction, specifically including the following steps (1) to (2).
[0066] (1) Based on the firmware storage and upgrade metadata in the boot communication partition, transfer the data in the firmware storage area to the firmware storage area redirection base address, update the firmware storage and upgrade metadata, and write the updated firmware storage and upgrade metadata into the boot communication partition and the main storage medium. Specifically, this includes the following steps (1-1) to (1-8).
[0067] (1-1) Read firmware storage and upgrade metadata from the third preset location of the boot communication partition.
[0068] (1-2) Determine whether the read firmware storage and upgrade metadata is valid. If it is invalid, exit the firmware upgrade process. If it is valid, determine the address space of the firmware storage area based on the starting address and length of the firmware storage area in the basic information of the firmware storage and upgrade metadata, and write the data in the address space of the firmware storage area to the firmware storage area redirection base address in the basic information of the firmware storage and upgrade metadata.
[0069] Specifically, it determines whether the magic number of firmware storage and upgrade metadata is the preset magic number of firmware storage and upgrade metadata. If not, the firmware upgrade process is exited. If so, the digital digest of the basic information of firmware storage and upgrade metadata is calculated according to the digital digest algorithm type of firmware storage and upgrade metadata. It then determines whether the calculated digital digest is consistent with the basic information digest value of firmware storage and upgrade metadata. If not, the firmware upgrade process is exited. If they are consistent, the address space formed by the starting address of the firmware storage area and the length of the firmware storage area in the basic information of firmware storage and upgrade metadata is used as the address space of the firmware storage area. The data in the address space of the firmware storage area is written to the firmware storage area redirection base address in the basic information of firmware storage and upgrade metadata. The size of the written data is the length of the firmware storage area in the basic information of firmware storage and upgrade metadata.
[0070] (1-3) Set the upgrade instruction in the basic information of firmware storage and upgrade metadata to the third-stage upgrade instruction.
[0071] (1-4) Calculate the digital digest of the basic information of firmware storage and upgrade metadata according to the digital digest algorithm type of firmware storage and upgrade metadata, and save the digital digest of the basic information to the basic information digest value of firmware storage and upgrade metadata.
[0072] (1-5) Based on the digital digest algorithm type of firmware storage and upgrade metadata, calculate the digital digest of the data in firmware storage and upgrade metadata, which consists of basic information digest value, basic information, mass production firmware package storage information, Android format upgrade package storage information, upgrade mode firmware and upgrade mode dependent firmware list storage information, image file upgrade package system firmware storage information, and upgrade mode firmware and upgrade mode dependent firmware list backup information, and save the digital digest of the data to the metadata digital digest of firmware storage and upgrade metadata.
[0073] (1-6) Write firmware storage and upgrade metadata into the boot communication partition.
[0074] (1-7) Obtain the size of the main storage medium, subtract the preset size of the storage medium tail and the preset size of firmware storage and upgrade metadata from the size of the main storage medium to obtain the starting address of firmware storage and upgrade metadata in the main storage medium.
[0075] (1-8) Write the firmware storage and upgrade metadata to the starting address of the firmware storage and upgrade metadata in the main storage medium.
[0076] (2) After setting the current upgrade command to the third stage upgrade command, write the set current upgrade command to the boot communication partition and perform firmware upgrade based on the third stage upgrade command.
[0077] In step 209, it is determined whether the current upgrade instruction is a third-stage upgrade instruction. If so, the firmware is upgraded based on the third-stage upgrade instruction. If not, step 210 is executed.
[0078] In this embodiment, firmware upgrade is performed based on the third-stage upgrade instruction, specifically including the following steps (1) to (9).
[0079] (1) Read firmware storage and upgrade metadata from the main storage medium.
[0080] In some embodiments, the actual capacity of the main storage medium is obtained as the size of the main storage medium. The size of the main storage medium is subtracted by the preset size reserved at the end of the storage medium and the preset size of the firmware storage and upgrade metadata, and the result is used as the starting address of the firmware storage and upgrade metadata. Data of the preset size of the firmware storage and upgrade metadata is read from the starting address of the firmware storage and upgrade metadata of the main storage medium as the firmware storage and upgrade metadata.
[0081] (2) Determine whether the read firmware storage and upgrade metadata is valid. If it is valid, proceed to step (3). If it is invalid, read the firmware storage and upgrade metadata from the boot communication partition as backup firmware storage and upgrade metadata, and use the backup firmware storage and upgrade metadata to update the firmware storage and upgrade metadata in the main storage medium, and then proceed to step (3).
[0082] In some embodiments, it is determined whether the magic number of the firmware storage and upgrade metadata is the preset magic number of the firmware storage and upgrade metadata. If not, the firmware storage and upgrade metadata is read from the third preset location of the boot communication partition as backup firmware storage and upgrade metadata, and the backup firmware storage and upgrade metadata is used to update the firmware storage and upgrade metadata in the main storage medium. Then, step (3) is executed. If yes, the firmware storage and upgrade metadata is calculated according to the digital digest algorithm type of the firmware storage and upgrade metadata, which consists of the basic information digest value, basic information, mass production firmware package storage information, Android format upgrade package storage information, and upgrade metadata. The system stores information of the mode firmware and upgrade mode dependent firmware list, the system firmware of the image file upgrade package, and the backup information of the upgrade mode firmware and upgrade mode dependent firmware list. The system stores information of the ...
[0083] In this embodiment, firmware storage and upgrade metadata is read from the third preset location of the boot communication partition as backup firmware storage and upgrade metadata, and the backup firmware storage and upgrade metadata is used to update the firmware storage and upgrade metadata in the main storage medium. Specifically:
[0084] Read firmware storage and upgrade metadata from the third preset location of the boot communication partition as backup firmware storage and upgrade metadata; determine whether the magic number of the backup firmware storage and upgrade metadata is the same as the preset firmware storage and upgrade metadata magic number. If not, exit the firmware upgrade process. If yes, calculate the digital digest of the data in the backup firmware storage and upgrade metadata according to the digital digest algorithm type. The data consists of the basic information digest value, basic information, mass-produced firmware package storage information, Android format upgrade package storage information, upgrade mode firmware and upgrade mode dependent firmware list storage information, image file upgrade package system firmware storage information, and upgrade mode firmware and upgrade mode dependent firmware list backup information. Determine whether the calculated digital digest is the same as the metadata digital digest of the backup firmware storage and upgrade metadata. If they are different, exit the firmware upgrade process. If they are the same, write the backup firmware storage and upgrade metadata to the starting address of the firmware storage and upgrade metadata in the main storage medium. The size of the written data is the preset size of the firmware storage and upgrade metadata.
[0085] (3) Read the upgrade instruction from the boot communication partition and determine whether the read upgrade instruction is consistent with the upgrade instruction in the basic information of firmware storage and upgrade meta information. If they are consistent, execute step (4). If they are inconsistent, write the upgrade instruction in the basic information of firmware storage and upgrade meta information into the boot communication partition.
[0086] In some embodiments, a digital digest of the basic information of the firmware storage and upgrade metadata is calculated according to the digital digest algorithm type of the firmware storage and upgrade metadata. It is determined whether the calculated digital digest is consistent with the digest value of the basic information of the firmware storage and upgrade metadata. If they are inconsistent, the firmware upgrade process is exited. If they are consistent, the upgrade instruction is read from the first preset position of the boot communication partition. It is determined whether the read upgrade instruction is consistent with the upgrade instruction in the basic information of the firmware storage and upgrade metadata. If yes, step (4) is executed. If no, the upgrade instruction in the basic information of the firmware storage and upgrade metadata is written into the first preset position of the boot communication partition. A digital digest of the upgrade mode firmware and the upgrade mode dependent firmware list backup information of the firmware storage and upgrade metadata is calculated according to the digital digest algorithm type of the firmware storage and upgrade metadata. It is determined whether the calculated digital digest is the same as the digest value of the upgrade mode firmware and the upgrade mode dependent firmware list backup information in the basic information of the firmware storage and upgrade metadata. If they are different, the firmware upgrade process is exited. If they are the same, step (4) is executed.
[0087] (4) Obtain the current partition table from the address space where the partition table is located in the main storage medium.
[0088] (5) Based on the current partition table, perform a legality check on each backup firmware item in the backup firmware item list of the firmware storage and upgrade meta information upgrade mode firmware and upgrade mode dependent firmware list backup information. If the legality check result is not all legal, exit the firmware upgrade process. If the legality check result is all legal, modify the current partition table based on the firmware storage and upgrade meta information to obtain the modified current partition table. Specifically, it includes the following steps (5-1) to (5-4).
[0089] (5-1) Based on the number of backup firmware items in the backup firmware list of the upgrade mode firmware and upgrade mode dependent firmware list of the firmware storage and upgrade meta-information, sequentially traverse the backup firmware item list of the upgrade mode firmware and upgrade mode dependent firmware list of the firmware storage and upgrade meta-information; for each backup firmware item in the backup firmware item list, firstly, according to the backup firmware partition name of the corresponding backup firmware item, read the firmware data in the address space determined by the starting address and partition size of the corresponding partition in the current partition table into the temporary firmware data storage area, then calculate the digital digest of the temporary firmware data in the temporary firmware data storage area according to the digital digest algorithm type of the firmware storage and upgrade meta-information, and determine whether the calculated digital digest is consistent with the digital digest value of the backup firmware data of the corresponding backup firmware item. If they are inconsistent, exit the firmware upgrade process; if they are consistent, check the next backup firmware item in the backup firmware item list, until all backup firmware items have been checked.
[0090] (5-2) If the result of the validity check of the firmware data corresponding to all backup firmware items in the backup firmware item list is valid, then proceed to step (5-3); otherwise, exit the firmware upgrade process.
[0091] (5-3) Based on the partition name of the partition corresponding to the upgrade mode firmware, find the corresponding upgrade mode backup firmware item from the backup firmware item list of the upgrade mode firmware and upgrade mode dependent firmware list backup information in the firmware storage and upgrade meta information; set the starting address of the partition corresponding to the upgrade mode firmware in the current partition table to: the firmware storage area redirection base address in the basic information of firmware storage and upgrade meta information + the backup firmware data offset address of the upgrade mode backup firmware item; set the partition size of the partition corresponding to the upgrade mode firmware in the current partition table to the backup firmware data size of the upgrade mode backup firmware item.
[0092] (5-4) For each dependent firmware in the upgrade mode dependent firmware list, firstly, based on the partition name of the partition corresponding to the dependent firmware, find the corresponding dependent firmware backup firmware item from the backup firmware item list of the upgrade mode firmware and upgrade mode dependent firmware list backup information in the firmware storage and upgrade meta information. Then, set the starting address of the partition corresponding to the dependent firmware in the current partition table to: the firmware storage area redirection base address in the basic information of firmware storage and upgrade meta information + the backup firmware data offset address of the corresponding dependent firmware backup firmware item; set the partition size of the partition corresponding to the dependent firmware in the current partition table to the backup firmware data size of the corresponding dependent firmware backup firmware item, and obtain the modified current partition table.
[0093] (6) Write the modified current partition table into the address space where the partition table is located in the main storage medium to complete the upgrade operation of the modified current partition table.
[0094] (7) Update the firmware storage and upgrade metadata and write the updated firmware storage and upgrade metadata to the boot communication partition.
[0095] In some embodiments, the upgrade instruction in the basic information of the firmware storage and upgrade meta-information is set to the fourth-stage upgrade instruction; a digital digest of the basic information of the firmware storage and upgrade meta-information is calculated according to the digital digest algorithm type of the firmware storage and upgrade meta-information, and the calculated digital digest is saved to the basic information digest value of the firmware storage and upgrade meta-information; a digital digest of the data composed of the basic information digest value, basic information, mass-produced firmware package storage information, Android format upgrade package storage information, upgrade mode firmware and upgrade mode dependent firmware list storage information, image file upgrade package system firmware storage information, and upgrade mode firmware and upgrade mode dependent firmware list backup information in the firmware storage and upgrade meta-information is calculated according to the digital digest algorithm type of the firmware storage and upgrade meta-information, and the calculated digital digest is saved to the meta-information digital digest of the firmware storage and upgrade meta-information to obtain the updated firmware storage and upgrade meta-information; the updated firmware storage and upgrade meta-information is written to the third preset position of the boot communication partition.
[0096] (8) Set the current upgrade instruction to the fourth stage upgrade instruction and write the set current upgrade instruction to the first preset location of the boot communication partition.
[0097] (9) Write the updated firmware storage and upgrade metadata to the main storage medium.
[0098] In some embodiments, the actual capacity of the main storage medium is obtained as the size of the main storage medium. The size of the main storage medium is subtracted by the preset size reserved at the end of the storage medium and the preset size of the firmware storage and upgrade metadata as the starting address of the firmware storage and upgrade metadata. The updated firmware storage and upgrade metadata is written to the starting address of the firmware storage and upgrade metadata, and the size of the written data is the preset size of the firmware storage and upgrade metadata.
[0099] In step 210, it is determined whether the current upgrade instruction is a fourth-stage upgrade instruction. If it is, the firmware is upgraded based on the fourth-stage upgrade instruction. If not, step 211 is executed.
[0100] In this embodiment, firmware upgrade is performed based on the fourth-stage upgrade instruction, specifically including the following steps (1) to (8).
[0101] (1) Read firmware storage and upgrade metadata from the main storage medium.
[0102] (2) Determine whether the read firmware storage and upgrade metadata is valid. If it is valid, write the firmware storage and upgrade metadata into the third preset position of the boot communication partition. If it is invalid, read the firmware storage and upgrade metadata from the third preset position of the boot communication partition as backup firmware storage and upgrade metadata, and use the backup firmware storage and upgrade metadata to update the firmware storage and upgrade metadata in the main storage medium. Specifically, this includes the following steps (2-1) to (2-2).
[0103] (2-1) Determine whether the magic number of firmware storage and upgrade metadata is the preset magic number of firmware storage and upgrade metadata. If not, execute (2-2). If yes, calculate the digital digest of the data in firmware storage and upgrade metadata composed of basic information digest value, basic information, mass production firmware package storage information, Android format upgrade package storage information, upgrade mode firmware and upgrade mode dependent firmware list storage information, image file upgrade package system firmware storage information, and upgrade mode firmware and upgrade mode dependent firmware list backup information according to the digital digest algorithm type of firmware storage and upgrade metadata. Determine whether the calculated digital digest is the same as the metadata digital digest of firmware storage and upgrade metadata. If not, execute (2-2). If they are the same, write firmware storage and upgrade metadata into the third preset position of the boot communication partition.
[0104] (2-2) Read the firmware storage and upgrade metadata from the third preset location of the boot communication partition as backup firmware storage and upgrade metadata, and determine whether the magic number of the backup firmware storage and upgrade metadata is the same as the magic number of the preset firmware storage and upgrade metadata. If not, exit the firmware upgrade process. If yes, calculate the digital digest of the data in the backup firmware storage and upgrade metadata, which consists of the basic information digest value, basic information, mass production firmware package storage information, Android format upgrade package storage information, upgrade mode firmware and upgrade mode dependent firmware list storage information, image file upgrade package system firmware storage information, and upgrade mode firmware and upgrade mode dependent firmware list backup information, according to the digital digest algorithm type of the backup firmware storage and upgrade metadata. Determine whether the calculated digital digest is the same as the metadata digital digest of the backup firmware storage and upgrade metadata. If they are different, exit the firmware upgrade process. If they are the same, execute the following steps (a) to (b).
[0105] (a) Calculate the digital digest of the basic information of the backup firmware storage and upgrade metadata according to the digital digest algorithm type. Determine whether the calculated digital digest is consistent with the digest value of the basic information of the backup firmware storage and upgrade metadata. If they are inconsistent, exit the firmware upgrade process. If they are consistent, determine whether the upgrade instruction of the basic information of the backup firmware storage and upgrade metadata is the fourth stage upgrade instruction. If not, proceed to step (b). If yes, write the backup firmware storage and upgrade metadata to the starting address of the firmware storage and upgrade metadata in the main storage medium. The size of the written data is the preset size of the firmware storage and upgrade metadata.
[0106] (b) Set the upgrade instruction in the basic information of the backup firmware storage and upgrade meta-information to the fourth-stage upgrade instruction (d). Calculate the digital digest of the basic information of the backup firmware storage and upgrade meta-information according to the digital digest algorithm type of the backup firmware storage and upgrade meta-information, and save the calculated digital digest to the basic information digest value of the backup firmware storage and upgrade meta-information. Calculate the digital digest of the data composed of the basic information digest value, basic information, mass-produced firmware package storage information, Android format upgrade package storage information, upgrade mode firmware and upgrade mode dependent firmware list storage information, image file upgrade package system firmware storage information, and upgrade mode firmware and upgrade mode dependent firmware list backup information in the backup firmware storage and upgrade meta-information according to the digital digest algorithm type of the backup firmware storage and upgrade meta-information, and save the calculated digital digest to the meta-information digital digest of the backup firmware storage and upgrade meta-information. Write the backup firmware storage and upgrade meta-information to the starting address of the firmware storage and upgrade meta-information in the main storage medium, with the written data size being the preset size of the firmware storage and upgrade meta-information. Simultaneously, write the backup firmware storage and upgrade meta-information at the third preset position of the boot communication segment.
[0107] (3) Read the upgrade instruction from the boot communication partition and determine whether the read upgrade instruction is consistent with the upgrade instruction in the basic information of firmware storage and upgrade meta information. If they are consistent, execute step (4). If they are inconsistent, write the upgrade instruction in the basic information of firmware storage and upgrade meta information into the boot communication partition.
[0108] In some embodiments, a digital digest of the basic information of the firmware storage and upgrade metadata is calculated according to the digital digest algorithm type of the firmware storage and upgrade metadata, and it is determined whether the calculated digital digest is consistent with the basic information digest value of the firmware storage and upgrade metadata. If they are inconsistent, the firmware upgrade process is exited. If they are consistent, the upgrade instruction is read from the first preset position of the boot communication partition, and it is determined whether the read upgrade instruction is consistent with the upgrade instruction of the basic information of the firmware storage and upgrade metadata. If they are consistent, step (4) is executed. If they are inconsistent, the upgrade instruction of the basic information of the firmware storage and upgrade metadata is written into the first preset position of the boot communication partition.
[0109] (4) Obtain the upgrade package type of the firmware upgrade package based on firmware storage and upgrade metadata.
[0110] In some embodiments, the upgrade package type of the firmware upgrade package is obtained based on the upgrade package type in the basic information of the firmware storage and upgrade metadata.
[0111] (5) Based on the firmware storage and upgrade metadata, upgrade the partition table to be upgraded according to the upgrade package type to obtain a new partition table, specifically including the following steps (5-1) to (5-14).
[0112] (5-1) If the upgrade package type is a mass production firmware upgrade package type, then execute steps (5-2) to (5-7). If the upgrade package type is an image file upgrade package type or an Android format upgrade package type, then execute steps (5-8) to (5-14).
[0113] (5-2) Calculate the digital digest of the mass production firmware package storage information of the firmware storage and upgrade meta information according to the digital digest algorithm type of the firmware storage and upgrade meta information, and determine whether the calculated digital digest is consistent with the mass production firmware package storage information digest value in the basic information of the firmware storage and upgrade meta information. If they are inconsistent, exit the firmware upgrade process. If they are consistent, proceed to step (5-3).
[0114] (5-3) The starting offset address of the mass-produced firmware file storage area in the basic information of firmware storage and upgrade meta-information is added to the starting address of the mass-produced firmware file storage area in the mass-produced firmware package storage information of firmware storage and upgrade meta-information as the starting address of a single mass-produced firmware file, and the size of the mass-produced firmware file in the mass-produced firmware package storage information of firmware storage and upgrade meta-information is used as the size of a single mass-produced firmware file.
[0115] (5-4) Calculate the digital digest of the data in the address space consisting of the starting address of a single mass-produced firmware file and the size of a single mass-produced firmware file. Determine whether the calculated digital digest is consistent with the digital digest value of the mass-produced firmware file in the mass-produced firmware package storage information of firmware storage and upgrade meta information. If they are inconsistent, exit the firmware upgrade process. If they are consistent, proceed to step (5-5).
[0116] (5-5) The data in the address space consisting of the starting address of the single mass-produced firmware file and the size of the single mass-produced firmware file is called the single mass-produced firmware file data; the partition table to be upgraded is obtained from the single mass-produced firmware file data in the preset storage format as the new partition table; the upgrade mode firmware data is obtained from the single mass-produced firmware file data in the preset storage format according to the partition name corresponding to the upgrade mode firmware, and the obtained upgrade mode firmware data is written to the partition starting address of the partition corresponding to the upgrade mode firmware in the new partition table. The size of the written data is the minimum value between the size of the obtained upgrade mode firmware data and the partition size of the partition corresponding to the upgrade mode firmware in the new partition table.
[0117] (5-6) For each dependent firmware in the firmware dependency list of the upgrade mode firmware, firstly, obtain the corresponding dependent firmware data from the single mass production firmware file data in the preset storage format according to the partition name corresponding to the corresponding dependent firmware; then write the obtained corresponding dependent firmware data to the partition start address of the partition corresponding to the corresponding dependent firmware in the new partition table, and the size of the written data is the minimum value between the obtained corresponding dependent firmware data size and the partition size of the partition corresponding to the corresponding dependent firmware in the new partition table.
[0118] (5-7) Write the new partition table into the address space where the partition table is located in the main storage medium to complete the upgrade operation of the new partition table.
[0119] (5-8) Calculate the digital digest of the upgrade mode firmware and the list of upgrade mode dependent firmware in the firmware storage and upgrade meta information according to the digital digest algorithm type. Determine whether the calculated digital digest is consistent with the digest value of the upgrade mode firmware and the list of upgrade mode dependent firmware in the basic information of the firmware storage and upgrade meta information. If they are inconsistent, exit the firmware upgrade process. If they are consistent, proceed to step (5-9).
[0120] (5-9) Add the firmware storage area redirection base address in the basic information of firmware storage and upgrade meta-information to the partition table storage area offset address in the upgrade mode firmware and upgrade mode dependent firmware list storage information of firmware storage and upgrade meta-information as the starting address of the new partition table, and use the partition table size in the upgrade mode firmware and upgrade mode dependent firmware list storage information of firmware storage and upgrade meta-information as the size of the new partition table; calculate the digital digest of the data in the address space formed by the starting address of the new partition table and the size of the new partition table, and determine whether the calculated digital digest is consistent with the partition table data digital digest value in the upgrade mode firmware and upgrade mode dependent firmware list storage information of firmware storage and upgrade meta-information. If they are inconsistent, exit the firmware upgrade process; if they are consistent, proceed to step (5-10).
[0121] (5-10) The data in the address space consisting of the starting address of the new partition table and the size of the new partition table is called the new partition table.
[0122] (5-11) Based on the number of firmware items in the firmware storage and upgrade meta-information's upgrade mode firmware and upgrade mode dependent firmware list storage information, sequentially traverse the firmware item lists in the firmware storage and upgrade meta-information's upgrade mode firmware and upgrade mode dependent firmware list storage information; for each firmware item in the firmware item list, add the firmware data offset address of the corresponding firmware item to the firmware storage area redirection base address in the basic information of the firmware storage and upgrade meta-information as the firmware data start address of the corresponding firmware item, and read the corresponding firmware data in the address space determined by the firmware data start address of the corresponding firmware item and the firmware data size of the corresponding firmware item into the temporary firmware data storage area; calculate the digital digest of the temporary firmware data in the temporary firmware data storage area according to the digital digest algorithm type of the firmware storage and upgrade meta-information, and determine whether the calculated digital digest is consistent with the firmware data digital digest value of the corresponding firmware item. If they are inconsistent, exit the firmware upgrade process; if they are consistent, check the next firmware item in the firmware item list until all firmware items have been checked; if all firmware data corresponding to all firmware items in the firmware item list are valid, execute step (5-12); otherwise, exit the firmware upgrade process.
[0123] (5-12) Based on the partition name corresponding to the upgrade mode firmware, obtain the corresponding upgrade mode firmware item from the firmware item list of the upgrade mode firmware and upgrade mode dependent firmware list storage information in the firmware storage and upgrade meta information (that is, find the firmware item whose firmware partition name is the same as the partition name corresponding to the upgrade mode firmware from the firmware item list as the upgrade mode firmware item). Add the firmware data offset address of the upgrade mode firmware item to the firmware storage area redirection base address in the basic information of firmware storage and upgrade meta information as the firmware data start address of the upgrade mode firmware item. Obtain the upgrade mode firmware data from the address space determined by the firmware data start address of the upgrade mode firmware item and the firmware data size of the upgrade mode firmware item, and write the obtained upgrade mode firmware data to the partition start address of the partition corresponding to the upgrade mode firmware in the new partition table. The size of the written data is the minimum value between the obtained upgrade mode firmware data size and the partition size of the partition corresponding to the upgrade mode firmware in the new partition table.
[0124] (5-13) For each dependent firmware item in the firmware item list of the firmware storage and upgrade meta-information, excluding the upgrade mode firmware item, firstly, the firmware data offset address of the corresponding dependent firmware item is added to the firmware storage area redirection base address in the basic information of firmware storage and upgrade meta-information as the firmware data starting address of the corresponding dependent firmware item. The corresponding dependent firmware data is obtained from the address space determined by the firmware data starting address of the corresponding dependent firmware item and the firmware data size of the corresponding dependent firmware item. Then, the obtained corresponding dependent firmware data is written to the partition starting address of the partition corresponding to the corresponding dependent firmware in the new partition table. The size of the written data is the minimum value between the obtained corresponding dependent firmware data size and the partition size of the partition corresponding to the corresponding dependent firmware in the new partition table.
[0125] (5-14) Write the new partition table into the address space where the partition table is located in the main storage medium to complete the upgrade operation of the new partition table.
[0126] (6) Update the firmware storage and upgrade metadata and write the updated firmware storage and upgrade metadata into the boot communication partition of the new partition table.
[0127] In some embodiments, the upgrade instruction in the basic information of the firmware storage and upgrade meta-information is set to the fifth-stage upgrade instruction; a digital digest of the basic information of the firmware storage and upgrade meta-information is calculated according to the digital digest algorithm type of the firmware storage and upgrade meta-information, and the calculated digital digest is saved to the basic information digest value of the firmware storage and upgrade meta-information; a digital digest of the data composed of the basic information digest value, basic information, mass-produced firmware package storage information, Android format upgrade package storage information, upgrade mode firmware and upgrade mode dependent firmware list storage information, image file upgrade package system firmware storage information, and upgrade mode firmware and upgrade mode dependent firmware list backup information in the firmware storage and upgrade meta-information digital digest is calculated according to the digital digest algorithm type of the firmware storage and upgrade meta-information, and the calculated digital digest is saved to the meta-information digital digest of the firmware storage and upgrade meta-information; the updated firmware storage and upgrade meta-information is written to the third preset position of the boot communication segment of the new partition table.
[0128] (7) Set the current upgrade instruction to the fifth stage upgrade instruction and write the set current upgrade instruction to the first preset position of the boot communication partition of the new partition table.
[0129] (8) Write the updated firmware storage and upgrade metadata to the main storage medium.
[0130] In some embodiments, the actual capacity of the main storage medium is obtained as the main storage medium size, and the main storage medium size is subtracted by the preset storage medium tail size and the preset size of firmware storage and upgrade metadata information as the starting address of firmware storage and upgrade metadata information; the firmware storage and upgrade metadata information is written to the starting address of firmware storage and upgrade metadata information, and the written data size is the preset size of firmware storage and upgrade metadata information; the new partition table is used as the current partition table.
[0131] In step 211, it is determined whether the current upgrade instruction is a fifth-stage upgrade instruction. If so, the firmware is upgraded based on the fifth-stage upgrade instruction. If not, step 212 is executed.
[0132] In some embodiments, firmware upgrades are performed based on the fifth-stage upgrade instructions, specifically including the following steps (1) to (10).
[0133] (1) Read firmware storage and upgrade metadata from the main storage medium.
[0134] (2) Determine whether the read firmware storage and upgrade metadata is valid. If it is valid, proceed to step (3). If it is invalid, read the firmware storage and upgrade metadata from the boot communication partition as backup firmware storage and upgrade metadata, and use the backup firmware storage and upgrade metadata to update the firmware storage and upgrade metadata in the main storage medium.
[0135] The specific processing method of step (2) is similar to step (2) in step 209, and will not be repeated here.
[0136] (3) Read the upgrade instruction from the boot communication partition and determine whether the read upgrade instruction is consistent with the upgrade instruction in the basic information of firmware storage and upgrade meta information. If they are consistent, execute step (4). If they are inconsistent, write the upgrade instruction in the basic information of firmware storage and upgrade meta information into the boot communication partition.
[0137] In some embodiments, a digital digest of the basic information of the firmware storage and upgrade metadata is calculated according to the digital digest algorithm type of the firmware storage and upgrade metadata. It is determined whether the calculated digital digest is consistent with the basic information digest value of the firmware storage and upgrade metadata. If not, the firmware upgrade process is exited. If yes, the upgrade instruction is read from the first preset position of the boot communication partition, and it is determined whether the read upgrade instruction is consistent with the upgrade instruction of the basic information of the firmware storage and upgrade metadata. If they are consistent, step (4) is executed. If they are inconsistent, the upgrade instruction of the basic information of the firmware storage and upgrade metadata is written into the first preset position of the boot communication partition.
[0138] (4) Determine whether the firmware upgrade package type in the basic information of firmware storage and upgrade metadata is an Android format upgrade package type.
[0139] (5) If the upgrade package type is not an Android format upgrade package type, then execute steps (7) to (10).
[0140] (6) If the upgrade package type is an Android format upgrade package type, the Android format upgrade package data is obtained based on the firmware storage and upgrade metadata, and the Android format upgrade package data is transferred to the Android upgrade package redirection address based on the firmware storage and upgrade metadata, specifically including the following steps (6-1) to (6-10).
[0141] (6-1) Calculate the digital digest of the Android format upgrade package storage information of the firmware storage and upgrade metadata according to the digital digest algorithm type. Determine whether the calculated digital digest is consistent with the Android format upgrade package storage information digest value in the basic information of the firmware storage and upgrade metadata. If they are inconsistent, exit the firmware upgrade process. If they are consistent, proceed to step (6-2).
[0142] (6-2) The starting address of the Android format upgrade package is obtained by adding the firmware storage area redirection base address in the basic information of firmware storage and upgrade meta information to the start offset address of the upgrade package storage area in the Android format upgrade package storage information of firmware storage and upgrade meta information. The size of the Android format upgrade package is obtained by taking the upgrade package size in the Android format upgrade package storage information of firmware storage and upgrade meta information.
[0143] (6-3) Calculate the digital digest of the data in the address space consisting of the starting address of the Android format upgrade package and the size of the Android format upgrade package. Determine whether the calculated digital digest is consistent with the upgrade package digital digest value in the Android format upgrade package storage information of the firmware storage and upgrade meta information. If they are inconsistent, exit the firmware upgrade process. If they are consistent, the data in the address space consisting of the starting address of the Android format upgrade package and the size of the Android format upgrade package is called Android format upgrade package data.
[0144] (6-4) Obtain the current partition table from the address space where the partition table is located in the main storage medium.
[0145] (6-5) Check the current partition table to see if there is a partition whose size is greater than or equal to the size of the Android format upgrade package and whose name is not the default user data partition, boot communication partition, partition corresponding to the upgrade mode firmware, or partition corresponding to all dependent firmware in the upgrade mode dependent firmware list. If it exists, use the starting address of the partition as the Android upgrade package redirection address in the Android format upgrade package storage information of firmware storage and upgrade metadata. If it does not exist, exit the firmware upgrade process.
[0146] (6-6) Write the data in the address space formed by the starting address of the Android format upgrade package and the size of the Android format upgrade package into the Android format upgrade package redirection address in the firmware storage and upgrade meta information of the Android format upgrade package storage information. The size of the data written is the size of the Android format upgrade package.
[0147] (6-7) Calculate the digital digest of the Android format upgrade package storage information of the firmware storage and upgrade meta-information according to the digital digest algorithm type of the firmware storage and upgrade meta-information, and save the calculated digital digest to the Android format upgrade package storage information digest value in the basic information; set the upgrade instruction in the basic information of the firmware storage and upgrade meta-information to the sixth stage upgrade instruction; calculate the digital digest of the basic information of the firmware storage and upgrade meta-information according to the digital digest algorithm type of the firmware storage and upgrade meta-information, and save the calculated digital digest to the basic information digest value of the firmware storage and upgrade meta-information; calculate the digital digest of the data composed of the basic information digest value, basic information, mass production firmware package storage information, Android format upgrade package storage information, upgrade mode firmware and upgrade mode dependent firmware list storage information, image file upgrade package system firmware storage information y, and upgrade mode firmware and upgrade mode dependent firmware list backup information in the firmware storage and upgrade meta-information digital digest according to the digital digest algorithm type of the firmware storage and upgrade meta-information, and save the calculated digital digest to the meta-information digital digest of the firmware storage and upgrade meta-information.
[0148] (6-8) Write firmware storage and upgrade metadata in the third preset position of the boot communication partition.
[0149] (6-9) Set the current upgrade command to the sixth stage upgrade command and write the current upgrade command to the first preset location of the boot communication partition.
[0150] (6-10) Obtain the actual capacity of the main storage medium as the main storage medium size, subtract the preset storage medium tail size and the preset size of firmware storage and upgrade metadata from the main storage medium size to obtain the starting address of firmware storage and upgrade metadata, write the firmware storage and upgrade metadata to the starting address of firmware storage and upgrade metadata, and write the data size to the preset size of firmware storage and upgrade metadata, and then execute step 212.
[0151] (7) Set the upgrade instruction in the basic information of firmware storage and upgrade meta-information to the seventh stage upgrade instruction; calculate the digital digest of the basic information of firmware storage and upgrade meta-information according to the digital digest algorithm type of firmware storage and upgrade meta-information, and save the calculated digital digest to the basic information digest value of firmware storage and upgrade meta-information; calculate the digital digest of the data composed of basic information digest value, basic information, mass production firmware package storage information, Android format upgrade package storage information, upgrade mode firmware and upgrade mode dependent firmware list storage information, image file upgrade package system firmware storage information and upgrade mode firmware and upgrade mode dependent firmware list backup information in firmware storage and upgrade meta-information according to the digital digest algorithm type of firmware storage and upgrade meta-information, and save the calculated digital digest to the meta-information digital digest of firmware storage and upgrade meta-information to obtain the updated firmware storage and upgrade meta-information.
[0152] (8) Write the updated firmware storage and upgrade metadata to the third preset position of the boot communication partition.
[0153] (9) Set the current upgrade instruction to the seventh stage upgrade instruction and write the current upgrade instruction to the first preset position in the boot communication partition.
[0154] (10) Obtain the actual capacity of the main storage medium as the main storage medium size, subtract the preset storage medium tail size and the preset size of firmware storage and upgrade metadata from the main storage medium size as the starting address of firmware storage and upgrade metadata, write the firmware storage and upgrade metadata to the starting address of firmware storage and upgrade metadata, and write the data size as the preset size of firmware storage and upgrade metadata, and execute step 213.
[0155] In step 212, determine whether the current upgrade command is a sixth-stage upgrade command. If yes, control the device to run the upgrade mode firmware; otherwise, execute step 213.
[0156] In step 213, determine whether the current upgrade instruction is a seventh-stage upgrade instruction. If yes, perform firmware upgrade based on the seventh-stage upgrade instruction; otherwise, proceed to step 214.
[0157] In some implementations, firmware upgrades are performed based on the seventh-stage upgrade instructions, specifically including the following steps (1) to (8).
[0158] (1) Read firmware storage and upgrade metadata from the main storage medium.
[0159] (2) Determine whether the read firmware storage and upgrade metadata is valid. If the read firmware storage and upgrade metadata is valid, proceed to step (3). If the read firmware storage and upgrade metadata is invalid, read the firmware storage and upgrade metadata from the boot communication partition as backup firmware storage and upgrade metadata, and use the backup firmware storage and upgrade metadata to update the firmware storage and upgrade metadata in the main storage medium, and then proceed to step (3).
[0160] (3) Read the upgrade instruction from the boot communication partition and determine whether the read upgrade instruction is consistent with the upgrade instruction in the basic information of firmware storage and upgrade meta information. If they are consistent, execute step (4). If they are inconsistent, write the upgrade instruction in the basic information of firmware storage and upgrade meta information into the first preset position of the boot communication partition, and then execute step (4).
[0161] In some embodiments, a digital digest of the basic information of the firmware storage and upgrade metadata is calculated according to the digital digest algorithm type of the firmware storage and upgrade metadata. It is determined whether the calculated digital digest is consistent with the basic information digest value of the firmware storage and upgrade metadata. If not, the firmware upgrade process is exited. If so, the upgrade instruction is read from the first preset position of the boot communication partition, and it is determined whether the read upgrade instruction is consistent with the upgrade instruction of the basic information of the firmware storage and upgrade metadata. If not, the upgrade instruction of the basic information of the firmware storage and upgrade metadata is written into the first preset position of the boot communication partition, and then step (4) is executed.
[0162] (4) Obtain the upgrade package type of the firmware upgrade package based on firmware storage and upgrade metadata.
[0163] (5) If the upgrade package type is a mass production firmware upgrade package type or an image file upgrade package type, then upgrade the partition table to be upgraded based on the firmware storage and upgrade metadata according to the mass production firmware upgrade package type or the image file upgrade package type to obtain a new partition table, specifically including the following steps (5-1) to (5-2).
[0164] (5-1) If the upgrade package type is a mass production firmware upgrade package type, then perform the following steps (a) to (c).
[0165] (a) Calculate the digital digest of the mass production firmware package storage information of the firmware storage and upgrade metadata according to the digital digest algorithm type of the firmware storage and upgrade metadata, and determine whether the calculated digital digest is consistent with the mass production firmware package storage information digest value in the basic information of the firmware storage and upgrade metadata. If they are inconsistent, exit the firmware upgrade process. If they are consistent, proceed to step (b).
[0166] (b) Take the firmware storage area redirection base address in the basic information of firmware storage and upgrade meta-information, plus the starting offset address of the mass-produced firmware file storage area in the mass-produced firmware package storage information of firmware storage and upgrade meta-information, as the starting address of a single mass-produced firmware file, and take the size of the mass-produced firmware file in the mass-produced firmware package storage information of firmware storage and upgrade meta-information as the size of a single mass-produced firmware file; calculate the digital digest of the data in the address space formed by the starting address of the single mass-produced firmware file and the size of the single mass-produced firmware file, and determine whether the calculated digital digest is consistent with the digital digest value of the mass-produced firmware file in the mass-produced firmware package storage information of firmware storage and upgrade meta-information. If they are inconsistent, exit the firmware upgrade process; if they are consistent, proceed to step (c).
[0167] (c) The data in the address space consisting of the starting address of the single mass-produced firmware file and the size of the single mass-produced firmware file is called the single mass-produced firmware file data; the partition table to be upgraded is obtained from the single mass-produced firmware file data in the preset storage format as the new partition table; for each firmware partition in the new partition table other than the partition corresponding to the upgrade mode firmware and the partition corresponding to each dependent firmware in the firmware dependent list of the upgrade mode firmware, the corresponding firmware data is first obtained from the single mass-produced firmware file data in the preset storage format according to the partition name of the corresponding firmware partition; then the obtained corresponding firmware data is written to the partition starting address of the corresponding firmware partition in the new partition table, and the size of the written data is the minimum value between the obtained corresponding firmware data size and the partition size of the corresponding firmware partition in the new partition table.
[0168] (5-2) If the upgrade package type is an image file upgrade package type, then perform the following steps (A) to (C).
[0169] (A) Calculate the digital digest of the firmware storage and upgrade meta information image file upgrade package system firmware storage information according to the digital digest algorithm type of firmware storage and upgrade meta information. Determine whether the calculated digital digest is consistent with the image file upgrade package system firmware storage information digest value in the basic information of firmware storage and upgrade meta information. If they are inconsistent, exit the firmware upgrade process. If not, proceed to step (B).
[0170] (B) Based on the number of system firmware items in the system firmware storage information of the image file upgrade package of firmware storage and upgrade meta-information, sequentially traverse the system firmware item list of the system firmware storage information of the image file upgrade package of firmware storage and upgrade meta-information; for each system firmware item in the system firmware item list, add the system firmware data offset address of the corresponding system firmware item to the firmware storage area redirection base address in the basic information of firmware storage and upgrade meta-information as the firmware data start address of the corresponding system firmware item, and read the corresponding firmware data in the address space determined by the firmware data start address of the corresponding system firmware item and the system firmware data size of the corresponding system firmware item into the temporary firmware data storage area; then calculate the digital digest of the temporary firmware data in the temporary firmware data storage area according to the digital digest algorithm type of firmware storage and upgrade meta-information, and determine whether the calculated digital digest is consistent with the system firmware data digital digest value of the corresponding system firmware item. If they are inconsistent, exit the firmware upgrade process; if they are consistent, check the next system firmware item in the system firmware item list until all system firmware items have been checked; if the check result of the firmware data corresponding to all system firmware items in the system firmware item list is all valid, then execute step (C); otherwise, exit the firmware upgrade process.
[0171] (C) Obtain the partition table from the address space where the partition table is located in the main storage medium; based on the number of system firmware items in the system firmware storage information of the image file upgrade package of firmware storage and upgrade meta-information, for each system firmware item in the system firmware item list of the image file upgrade package of firmware storage and upgrade meta-information, first add the system firmware data offset address of the corresponding system firmware item to the firmware storage area redirection base address in the basic information of firmware storage and upgrade meta-information as the firmware data start address of the corresponding system firmware item; obtain the corresponding firmware data from the address space determined by the firmware data start address of the corresponding system firmware item and the system firmware data size of the corresponding system firmware item; then write the obtained corresponding firmware data to the partition start address of the partition corresponding to the corresponding firmware in the partition table, and the size of the written data is the minimum value between the obtained corresponding firmware data size and the partition size of the partition corresponding to the corresponding firmware in the partition table.
[0172] (6) Update the firmware storage and upgrade metadata and write the updated firmware storage and upgrade metadata to the third preset location of the boot communication partition.
[0173] In some embodiments, the upgrade instruction in the basic information of the firmware storage and upgrade metadata is set to a preset post-upgrade processing instruction; a digital digest of the basic information of the firmware storage and upgrade metadata is calculated according to the digital digest algorithm type of the firmware storage and upgrade metadata, and the calculated digital digest is saved to the basic information digest value of the firmware storage and upgrade metadata; a digital digest of the data composed of the basic information digest value, basic information, mass-produced firmware package storage information, Android format upgrade package storage information, upgrade mode firmware and upgrade mode dependent firmware list storage information, image file upgrade package system firmware storage information, and upgrade mode firmware and upgrade mode dependent firmware list backup information in the firmware storage and upgrade metadata is calculated according to the digital digest algorithm type of the firmware storage and upgrade metadata, and the calculated digital digest is saved to the metadata digital digest of the firmware storage and upgrade metadata to obtain the updated firmware storage and upgrade metadata; the updated firmware storage and upgrade metadata is written to the third preset position of the boot communication segment.
[0174] (7) Set the current upgrade instruction to the preset post-upgrade processing instruction and write the set current upgrade instruction to the first boot communication partition.
[0175] (8) Write the updated firmware storage and upgrade metadata to the main storage medium.
[0176] In step 214, determine whether the current upgrade instruction is the eighth stage upgrade instruction. If yes, control the device to run the upgrade mode firmware; otherwise, proceed to step 215.
[0177] In step 215, it is determined whether the current upgrade instruction is a preset post-upgrade processing instruction. If yes, the device is controlled to run the upgrade mode firmware; otherwise, the firmware upgrade process is exited.
[0178] In some embodiments, in the upgrade mode firmware, an upgrade instruction is read from the first preset location of the boot communication partition, and it is determined whether the read upgrade instruction is a first-stage upgrade instruction, a sixth-stage upgrade instruction, an eighth-stage upgrade instruction, or a preset post-upgrade processing instruction. If not, firmware storage and upgrade metadata are read from the third preset location of the boot communication partition as backup firmware storage and upgrade metadata, and the upgrade instruction in the basic information of the backup firmware storage and upgrade metadata is used as the current upgrade instruction. If yes, the read upgrade instruction is used as the current upgrade instruction.
[0179] If the current upgrade instruction is the first-stage upgrade instruction, then execute the following steps (1) to (6).
[0180] (1) Construct firmware storage and upgrade metadata based on firmware upgrade package, specifically including the following steps (a) to (i).
[0181] (a) Set the magic number of firmware storage and upgrade metadata to the preset magic number of firmware storage and upgrade metadata, and set the digital digest algorithm type of firmware storage and upgrade metadata to the preset digital digest algorithm.
[0182] (b) Read the upgrade package path from the second preset position of the boot communication segment, and determine whether the upgrade package path is the preset block list description file path of the preset block list description file partition. If yes, set the user data partition encryption flag in the basic information of firmware storage and upgrade metadata to true. If no, set the user data partition encryption flag in the basic information of firmware storage and upgrade metadata to false.
[0183] (c) Determine whether the upgrade package under the upgrade package path is valid. If it is invalid, exit the firmware upgrade process. If it is valid, determine whether the upgrade package contains a single mass-produced firmware file with a preset storage format. If yes, set the upgrade package type in the basic information of firmware storage and upgrade metadata to the mass-produced firmware upgrade package type. If no, determine whether the upgrade package contains an Android format upgrade file. If yes, set the upgrade package type in the basic information of firmware storage and upgrade metadata to the Android format upgrade package type. Otherwise, set the upgrade package type in the basic information of firmware storage and upgrade metadata to the image file upgrade package type.
[0184] (d) Obtain the current firmware partition table from the address space where the partition table is located in the main storage medium, and use the starting address of the preset user data partition in the current firmware partition table as the starting address of the old user data area; determine whether the user data partition encryption flag in the basic information of firmware storage and upgrade metadata is true. If so, use the starting address of the first physical partition after the boot communication partition, block list description file partition, partition corresponding to the upgrade mode firmware, and all partitions corresponding to the upgrade mode dependent firmware list in the current partition table as the starting address of the data to be stored. If not, use the starting address of the first physical partition after the boot communication partition, partition corresponding to the upgrade mode firmware, and all partitions corresponding to the upgrade mode dependent firmware list in the current partition table as the starting address of the data to be stored; set the starting address of the firmware storage area in the basic information of firmware storage and upgrade metadata as the starting address of the data to be stored; add the partition size of the partition corresponding to the upgrade mode firmware in the current partition table and the partition size of all partitions corresponding to the upgrade mode dependent firmware list to obtain the total size of the partition to be backed up; set the total size of the backup firmware data in the backup information of the upgrade mode firmware and upgrade mode dependent firmware list in firmware storage and upgrade metadata as the total size of the partition to be backed up.
[0185] (e) If the upgrade package type in the basic information of firmware storage and upgrade metadata is the mass production firmware upgrade package type, then execute steps (e-1) to (e-8).
[0186] (e-1) Calculate the size of a single mass-produced firmware file in the upgrade package; determine whether "the size of a single mass-produced firmware file plus the total size of backup firmware data in the backup information of the upgrade mode firmware and upgrade mode dependent firmware list" is greater than "the starting address of the old user data area minus the starting address of the firmware storage area in the basic information of firmware storage and upgrade meta information". If yes, there is insufficient space, and the firmware upgrade process is exited; otherwise, proceed to step (e-2).
[0187] (e-2) Set the starting offset address of the mass production firmware file storage area in the mass production firmware package storage information of firmware storage and upgrade meta information to 0, set the size of the mass production firmware file in the mass production firmware package storage information to the size of a single mass production firmware file, calculate the digital digest of a single mass production firmware file in the upgrade package according to the digital digest algorithm type of firmware storage and upgrade meta information, and save the calculated digital digest to the digital digest value of the mass production firmware file in the mass production firmware package storage information.
[0188] (e-3) Set the firmware storage and upgrade metadata upgrade mode. The starting offset address of the backup firmware area in the firmware and upgrade mode dependent firmware list backup information is the size of a single mass-produced firmware file.
[0189] (e-4) Set the length of the firmware storage area in the basic information of firmware storage and upgrade metadata to the size of a single mass-produced firmware file plus the total size of the backup firmware data in the backup information of the upgrade mode firmware and upgrade mode dependent firmware list.
[0190] (e-5) Obtain the firmware partition table from the single mass-produced firmware file in the upgrade package as the new partition table, and use the starting address of the preset user data partition in the new partition table as the starting address of the new user data area.
[0191] (e-6) Take the maximum value between "the starting address of the firmware storage area in the basic information of firmware storage and upgrade metadata plus the length of the firmware storage area in the basic information of firmware storage and upgrade metadata" and the starting address of the new user data area as the redirection address and save it to the redirection base address of the firmware storage area in the basic information of firmware storage and upgrade metadata.
[0192] (e-7) Obtain the actual capacity of the main storage medium as the main storage medium size, and subtract the preset storage medium tail size and the preset size of firmware storage and upgrade metadata from the main storage medium size to obtain the starting address of firmware storage and upgrade metadata.
[0193] (e-8) Determine whether the starting address of the firmware storage and upgrade metadata minus the redirection base address of the firmware storage area in the basic information of the firmware storage and upgrade metadata is greater than the length of the firmware storage area in the basic information of the firmware storage and upgrade metadata. If not, the redirection space is insufficient, and the firmware upgrade process is terminated.
[0194] (f) If the upgrade package type in the basic information of firmware storage and upgrade metadata is an image file upgrade package type, then execute steps (f-1) to (f-9).
[0195] (f-1) Calculate the sum of the sizes of all files in the upgrade package as the total size of the upgrade package firmware data; calculate the sum of the sizes of the partition table file, the upgrade mode firmware image file, and the firmware image file corresponding to each dependent firmware in the upgrade mode firmware dependent firmware list as the total size of the upgrade package upgrade mode related firmware; determine whether "the total size of the upgrade package firmware data plus the total size of the backup firmware data in the backup information of the upgrade mode firmware and upgrade mode dependent firmware list" is greater than "the starting address of the old user data area minus the starting address of the firmware storage area in the basic information of firmware storage and upgrade meta information". If yes, there is insufficient space, and the firmware upgrade process is exited; otherwise, proceed to step (f-2).
[0196] (f-2) Set the starting offset address of the storage area for upgrade mode-related firmware in the firmware storage and upgrade meta-information storage information to 0; set the total size of upgrade mode-related firmware data in the firmware storage and upgrade meta-information storage information to the total size of upgrade mode-related firmware in the upgrade package; set the offset address of the partition table storage area in the firmware storage and upgrade meta-information storage information to the starting offset address of the storage area for upgrade mode-related firmware in the firmware storage and upgrade meta-information storage information; calculate the size of the partition table file in the upgrade package, and set the size of the partition table in the firmware storage and upgrade meta-information storage information to the calculated partition table size; calculate the digital digest of the partition table file in the upgrade package according to the digital digest algorithm type of firmware storage and upgrade meta-information, and save the calculated digital digest to the partition table data digital digest value in the firmware storage and upgrade meta-information storage information.
[0197] (f-3) Set the number of firmware items in the upgrade mode firmware and upgrade mode dependent firmware list storage information to the sum of the number of upgrade mode firmware image files in the upgrade package and the number of firmware image files corresponding to each dependent firmware in the upgrade mode firmware dependent firmware list; set the partition name of the first firmware item in the firmware item list in the upgrade mode firmware and upgrade mode dependent firmware list storage information to the partition name corresponding to the upgrade mode firmware; set the firmware data offset address of the first firmware item to "the partition table storage area offset address in the upgrade mode firmware and upgrade mode dependent firmware list storage information plus the partition table size in the upgrade mode firmware and upgrade mode dependent firmware list storage information"; set the firmware data size of the first firmware item to the size of the upgrade mode firmware image file in the upgrade package, based on the digital digest algorithm class of firmware storage and upgrade metadata. The system calculates a digital digest of the firmware image file in the upgrade mode of the upgrade package and saves the calculated digital digest to the firmware data digital digest value of the first firmware item. Starting from the second firmware item in the firmware item list, the system sequentially sets the information of each dependent firmware in the firmware dependency list of the upgrade mode firmware. Specifically, the partition name of the firmware item is set to the partition name corresponding to the dependent firmware, the firmware data offset address of the firmware item is set to the sum of the firmware data offset address and the firmware data size of the previous firmware item, and the firmware data size of the firmware item is set to the size of the firmware image file corresponding to the corresponding dependent firmware in the upgrade package. The system calculates a digital digest of the firmware image file corresponding to the corresponding dependent firmware in the upgrade package according to the digital digest algorithm type of firmware storage and upgrade metadata, and saves the calculated digital digest to the firmware data digital digest value of the firmware item.
[0198] (f-4) Set the starting offset address of the system firmware storage area of the image file upgrade package system firmware storage information to "the starting offset address of the upgrade mode related firmware storage area in the upgrade mode firmware and upgrade mode dependent firmware list storage information plus the total size of the upgrade mode firmware and upgrade mode dependent firmware list storage information"; set the total size of the system firmware data of the image file upgrade package system firmware storage information to "the total size of the upgrade package firmware data minus the total size of the upgrade package upgrade mode related firmware".
[0199] (f-5) Set the number of system firmware items in the system firmware storage information of the image file upgrade package to: the sum of the number of all other files in the upgrade package except for the partition table file, the upgrade mode firmware image file, and the firmware image file corresponding to each dependent firmware in the upgrade mode firmware dependency firmware list (i.e., the total number of files in the upgrade package minus the number of firmware items in the upgrade mode firmware and upgrade mode dependent firmware list storage information minus one); according to the number of system firmware items, set the information of each system firmware in the system firmware item list of the image file upgrade package system firmware storage information in a preset order, wherein the system firmware partition name of the system firmware item is set to the partition name corresponding to the system firmware; if the current system firmware item is a system firmware If the first system firmware item in the item list is set, the system firmware data offset address of the system firmware item is set to the starting offset address of the system firmware storage area of the system firmware storage information in the image file upgrade package; otherwise, the system firmware data offset address of the system firmware item is set to the sum of the system firmware data offset address of the previous system firmware item and the system firmware data size of the previous system firmware item. The system firmware data size of the system firmware item is set to the size of the firmware image file corresponding to the corresponding system firmware in the upgrade package. The digital digest of the firmware image file corresponding to the corresponding system firmware in the upgrade package is calculated according to the digital digest algorithm type of firmware storage and upgrade metadata, and the calculated digital digest is saved to the system firmware data digital digest value of the system firmware item.
[0200] (f-6) Set the starting offset address of the backup firmware area in the backup information of the upgrade mode firmware and upgrade mode dependent firmware list to the total size of the upgrade package firmware data.
[0201] (f-7) Set the length of the firmware storage area in the basic information of firmware storage and upgrade metadata to "the total size of the upgrade package firmware data plus the total size of the backup firmware data in the backup information of the upgrade mode firmware and the upgrade mode dependent firmware list".
[0202] (f-8) Obtain the partition table file from the upgrade package as the new partition table, and use the starting address of the preset user data partition in the new partition table as the starting address of the new user data area; use the maximum value between "the starting address of the firmware storage area in the basic information of firmware storage and upgrade meta-information plus the length of the firmware storage area in the basic information of firmware storage and upgrade meta-information" and the starting address of the new user data area as the redirection address, and save it to the firmware storage area redirection base address in the basic information of firmware storage and upgrade meta-information.
[0203] (f-9) Obtain the actual capacity of the main storage medium as the main storage medium size. Subtract the preset storage medium tail size and the preset size of firmware storage and upgrade metadata from the main storage medium size to obtain the starting address of firmware storage and upgrade metadata. Check whether "the starting address of firmware storage and upgrade metadata minus the firmware storage area redirection base address in the basic information of firmware storage and upgrade metadata" is greater than the firmware storage area length in the basic information of firmware storage and upgrade metadata. If not, the redirection space is insufficient, and the firmware upgrade process is exited.
[0204] (g) If the upgrade package type in the basic information of firmware storage and upgrade metadata is Android format upgrade package type, then execute steps (g-1) to (g-9).
[0205] (g-1) Calculate the sum of the sizes of the partition table file, the upgrade mode firmware image file, and the firmware image file corresponding to each dependent firmware in the upgrade mode firmware dependency firmware list in the upgrade package, as the total size of the firmware related to the Android upgrade package upgrade mode; determine whether the user data partition encryption flag in the basic information of firmware storage and upgrade metadata is true. If the user data partition encryption flag is true, create a preset temporary system upgrade package directory under the preset unencrypted partition (such as cache). If the directory is not empty, delete all files in the directory. Then extract all other files in the upgrade package except for the partition table file, the upgrade mode firmware image file, and the firmware image file corresponding to each dependent firmware in the upgrade mode firmware dependency firmware list, and store them in the preset temporary system upgrade package directory of the preset unencrypted partition. The file directory structure in the temporary system upgrade package directory remains consistent with the original upgrade package. Finally, package all files in the temporary system upgrade package directory into an Android format system firmware package (such as update_system.zip), and calculate the size of the Android format system firmware package as the size of the Android temporary system firmware package. If the user data partition encryption flag is not true, calculate the total size of the entire upgrade package as the total size of the Android upgrade package.
[0206] (g-2) Determine whether the user data partition encryption flag in the basic information of firmware storage and upgrade metadata is true. If yes, set the upgrade package storage size to the size of the Android temporary system firmware package. If no, set the upgrade package storage size to the total size of the Android upgrade package.
[0207] (g-3) Determine whether "the total size of the upgrade package storage plus the total size of the firmware related to the Android upgrade package upgrade mode plus the total size of the backup firmware data in the backup information of the upgrade mode firmware and the upgrade mode dependent firmware list" is greater than "the starting address of the old user data area minus the starting address of the firmware storage area in the basic information of firmware storage and upgrade meta information". If yes, then there is insufficient space and the firmware upgrade process is exited. If no, then proceed to step (g-4).
[0208] (g-4) Set the starting offset address of the storage area for upgrade mode-related firmware in the upgrade mode firmware and upgrade mode dependent firmware list storage information to 0; set the total size of upgrade mode-related firmware data in the upgrade mode firmware and upgrade mode dependent firmware list storage information to the total size of upgrade mode-related firmware in the Android upgrade package; set the offset address of the partition table storage area in the upgrade mode firmware and upgrade mode dependent firmware list storage information to the starting offset address of the storage area for upgrade mode-related firmware in the upgrade mode firmware and upgrade mode dependent firmware list storage information; calculate the size of the partition table file in the upgrade package, and set the size of the partition table in the upgrade mode firmware and upgrade mode dependent firmware list storage information to the calculated partition table size; calculate the digital digest of the partition table file in the upgrade package according to the digital digest algorithm type of firmware storage and upgrade meta information, and save the calculated digital digest to the partition table data digital digest value in the upgrade mode firmware and upgrade mode dependent firmware list storage information.
[0209] (g-5) Set the number of firmware items in the upgrade mode firmware and upgrade mode dependent firmware list storage information to the sum of the number of upgrade mode firmware image files in the upgrade package and the number of firmware image files corresponding to each dependent firmware in the upgrade mode firmware dependent firmware list; set the partition name of the first firmware item in the firmware item list in the upgrade mode firmware and upgrade mode dependent firmware list storage information to the partition name corresponding to the upgrade mode firmware; set the firmware data offset address of the first firmware item in the firmware item list to "the partition table storage area offset address in the upgrade mode firmware and upgrade mode dependent firmware list storage information plus the partition table size in the upgrade mode firmware and upgrade mode dependent firmware list storage information"; set the firmware data size of the first firmware item in the firmware item list to the size of the upgrade mode firmware image file in the upgrade package, based on the digital extraction of firmware storage and upgrade metadata. The algorithm type calculates the digital digest of the upgrade mode firmware image file in the upgrade package and saves the calculated digital digest to the firmware data digital digest value of the first firmware item in the firmware item list. Starting from the second firmware item in the firmware item list, the information of each dependent firmware in the upgrade mode firmware dependent firmware list is set sequentially. The partition name of the firmware item is set to the partition name corresponding to the dependent firmware. The firmware data offset address of the firmware item is set to the sum of the firmware data offset address and the firmware data size of the previous firmware item. The firmware data size of the firmware item is set to the size of the firmware image file corresponding to the corresponding dependent firmware in the upgrade package. The digital digest of the firmware image file corresponding to the corresponding dependent firmware in the upgrade package is calculated according to the digital digest algorithm type of firmware storage and upgrade meta information, and the calculated digital digest is saved to the firmware data digital digest value of the firmware item.
[0210] (g-6) Set the starting offset address of the upgrade package storage area of the Android format upgrade package storage information to "the starting offset address of the upgrade mode related firmware storage area in the upgrade mode firmware and upgrade mode dependent firmware list storage information plus the total size of the upgrade mode related firmware data in the upgrade mode firmware and upgrade mode dependent firmware list storage information"; set the upgrade package size of the Android format upgrade package storage information to the upgrade package storage size; determine whether the user data partition encryption flag in the basic information of firmware storage and upgrade meta information is true. If so, calculate the digital digest of the Android format system firmware package in the preset temporary system upgrade package directory of the preset unencrypted partition according to the digital digest algorithm type of firmware storage and upgrade meta information, and save the calculated digital digest to the upgrade package digital digest value of the Android format upgrade package storage information. If not, calculate the digital digest of the upgrade package according to the digital digest algorithm type of firmware storage and upgrade meta information, and save the calculated digital digest to the upgrade package digital digest value of the Android format upgrade package storage information.
[0211] (g-7) Set the starting offset address of the backup firmware area in the backup information of the upgrade mode firmware and upgrade mode dependent firmware list to "upgrade package storage size plus total size of Android upgrade package upgrade mode related firmware"; set the length of the firmware storage area in the basic information of firmware storage and upgrade metadata to "upgrade package storage size plus total size of Android upgrade package upgrade mode related firmware and total size of backup firmware data in the backup information of upgrade mode firmware and upgrade mode dependent firmware list".
[0212] (g-8) Obtain the partition table file from the upgrade package as the new partition table, and use the starting address of the preset user data partition in the new partition table as the starting address of the new user data area; use the maximum value between "the starting address of the firmware storage area in the basic information of firmware storage and upgrade meta-information plus the length of the firmware storage area in the basic information of firmware storage and upgrade meta-information" and the starting address of the new user data area as the redirection address, and save it to the firmware storage area redirection base address in the basic information of firmware storage and upgrade meta-information.
[0213] (g-9) Obtain the actual capacity of the main storage medium as the main storage medium size. Subtract the preset storage medium tail size and the preset size of firmware storage and upgrade metadata from the main storage medium size to obtain the starting address of firmware storage and upgrade metadata. Determine whether "the starting address of firmware storage and upgrade metadata minus the firmware storage area redirection base address in the basic information of firmware storage and upgrade metadata" is greater than the firmware storage area length in the basic information of firmware storage and upgrade metadata. If not, the redirection space is insufficient, and the firmware upgrade process is exited.
[0214] (h) Calculate the number of dependent firmware for the upgrade mode firmware in the current firmware partition table; set the number of backup firmware entries in the upgrade mode firmware and upgrade mode dependent firmware list backup information to the number of dependent firmware plus one; set the backup firmware partition name of the first backup firmware entry in the backup firmware entry list of the upgrade mode firmware and upgrade mode dependent firmware list backup information to the partition name corresponding to the upgrade mode firmware; set the backup firmware data offset address of the first backup firmware entry in the backup firmware entry list to the starting offset address of the backup firmware area in the upgrade mode firmware and upgrade mode dependent firmware list backup information; set the backup firmware data size of the first backup firmware entry in the backup firmware entry list to the partition size of the partition corresponding to the upgrade mode firmware in the current firmware partition table; and calculate the digital digest of the current upgrade mode firmware data based on the starting address and partition size of the partition corresponding to the upgrade mode firmware in the current firmware partition table, according to the digital digest algorithm type of firmware storage and upgrade metadata. The algorithm first calculates a digital digest and saves it to the backup firmware data digital digest value of the first backup firmware item in the backup firmware item list. Starting from the second backup firmware item in the backup firmware item list, it sequentially sets the information of each dependent firmware in the upgrade mode firmware dependent firmware list. Specifically, it sets the backup firmware partition name of the backup firmware item to the partition name corresponding to the dependent firmware, sets the backup firmware data offset address of the backup firmware item to the sum of the backup firmware data offset address and the backup firmware data size of the previous backup firmware item, and sets the backup firmware data size of the backup firmware item to the partition size corresponding to the dependent firmware in the current firmware partition table. Based on the digital digest algorithm type of firmware storage and upgrade metadata, it calculates the corresponding dependent firmware data determined by the starting address and partition size of the corresponding dependent firmware in the current firmware partition table, and saves the calculated digital digest to the backup firmware data digital digest value of the backup firmware item.
[0215] (i) Calculate the digital digest of the mass-produced firmware package storage information of the firmware storage and upgrade metadata based on the digital digest algorithm type of the firmware storage and upgrade metadata, and save the calculated digital digest to the mass-produced firmware package storage information digest value in the basic information; calculate the digital digest of the Android format upgrade package storage information of the firmware storage and upgrade metadata based on the digital digest algorithm type of the firmware storage and upgrade metadata, and save the calculated digital digest to the Android format upgrade package storage information digest value in the basic information; calculate the digital digest of the upgrade mode firmware and upgrade mode dependent firmware list storage information of the firmware storage and upgrade metadata based on the digital digest algorithm type of the firmware storage and upgrade metadata, and save the calculated digital digest to the mass-produced firmware package storage information digest value in the basic information. The digital digest is saved to the digest value of the upgrade mode firmware and upgrade mode dependent firmware list storage information in the basic information; the digital digest of the image file upgrade package system firmware storage information of the firmware storage and upgrade meta information is calculated according to the digital digest algorithm type of the firmware storage and upgrade meta information, and the calculated digital digest is saved to the digest value of the image file upgrade package system firmware storage information in the basic information; the digital digest of the upgrade mode firmware and upgrade mode dependent firmware list backup information of the firmware storage and upgrade meta information is calculated according to the digital digest algorithm type of the firmware storage and upgrade meta information, and the calculated digital digest is saved to the digest value of the upgrade mode firmware and upgrade mode dependent firmware list backup information in the basic information.
[0216] (2) Data in the firmware upgrade package is stored in the target address space based on firmware storage and upgrade metadata. Specifically, this includes the following steps (2-1) to (2-4).
[0217] (2-1) If the upgrade package type in the basic information of firmware storage and upgrade metadata is the mass production firmware upgrade package type, then execute step (2-2); if the upgrade package type in the basic information of firmware storage and upgrade metadata is the image file upgrade package type, then execute step (2-3); if the upgrade package type in the basic information of firmware storage and upgrade metadata is the Android format upgrade package type, then execute step (2-4).
[0218] (2-2) Save the single mass-production firmware file in the upgrade package to the address space determined by the mass-production firmware package storage information of firmware storage and upgrade metadata. Specifically:
[0219] In some embodiments, a single mass-produced firmware file in the upgrade package is written to the address "the starting address of the firmware storage area in the basic information of firmware storage and upgrade meta-information plus the starting offset address of the mass-produced firmware file storage area of the mass-produced firmware package storage information of firmware storage and upgrade meta-information", and the size of the written data is the size of the mass-produced firmware file of the mass-produced firmware package storage information of firmware storage and upgrade meta-information.
[0220] (2-3) Save the partition table file, the upgrade mode firmware image file, and the firmware image file corresponding to each dependent firmware in the upgrade mode firmware dependent firmware list in the upgrade package to the address space determined by the firmware storage and upgrade meta-information storage information of the upgrade mode firmware and upgrade mode dependent firmware list; save all other files in the upgrade package except the partition table file, the upgrade mode firmware image file, and the firmware image file corresponding to each dependent firmware in the upgrade mode firmware dependent firmware list to the address space determined by the firmware storage and upgrade meta-information image file upgrade package system firmware storage information.
[0221] In some implementations, the partition table file in the upgrade package is written to the address of "the starting address of the firmware storage area in the basic information of firmware storage and upgrade meta information plus the offset address of the partition table storage area of the upgrade mode firmware and upgrade mode dependent firmware list storage information of firmware storage and upgrade meta information", and the size of the written data is the size of the partition table of the upgrade mode firmware and upgrade mode dependent firmware list storage information of firmware storage and upgrade meta information.
[0222] Based on the number of firmware items in the firmware storage and upgrade meta-information's upgrade mode firmware and upgrade mode dependent firmware list storage information, the firmware item lists in the firmware storage and upgrade meta-information's upgrade mode firmware and upgrade mode dependent firmware list storage information are traversed sequentially. According to the partition name of the firmware item, the corresponding upgrade mode firmware image file in the upgrade package and the firmware image file corresponding to each dependent firmware in the upgrade mode firmware dependent firmware list are written to "the starting address of the firmware storage area in the basic information of firmware storage and upgrade meta-information plus the firmware data offset address of the corresponding firmware item in the firmware item list of firmware storage and upgrade meta-information's upgrade mode firmware and upgrade mode dependent firmware list storage information". The size of the written data is the firmware data size of the corresponding firmware item.
[0223] Based on the number of system firmware items in the system firmware storage information of the image file upgrade package of firmware storage and upgrade meta information, the system firmware item list of the system firmware storage information of the image file upgrade package of firmware storage and upgrade meta information is traversed sequentially. According to the system firmware partition name of the system firmware item, the corresponding system firmware image file in the upgrade package is written to the address of "the starting address of the firmware storage area in the basic information of firmware storage and upgrade meta information plus the system firmware data offset address of the corresponding system firmware item in the system firmware item list of the image file upgrade package of firmware storage and upgrade meta information". The size of the written data is the system firmware data size of the corresponding system firmware item.
[0224] (2-4) Save the partition table file in the upgrade package, the upgrade mode firmware image file, and the firmware image file corresponding to each dependent firmware in the upgrade mode firmware dependent firmware list to the address space determined by the upgrade mode firmware and upgrade mode dependent firmware list storage information of firmware storage and upgrade meta information; determine whether the user data partition encryption flag in the basic information of firmware storage and upgrade meta information is true. If it is true, save the Android format system firmware package in the preset temporary system upgrade package directory of the preset unencrypted partition to the address space determined by the Android format upgrade package storage information. If not, save the upgrade package to the address space determined by the Android format upgrade package storage information.
[0225] In some embodiments, the partition table file in the upgrade package is written to "the starting address of the firmware storage area in the basic information of firmware storage and upgrade meta information plus the offset address of the partition table storage area of the upgrade mode firmware and upgrade mode dependent firmware list storage information of firmware storage and upgrade meta information", and the size of the written data is the size of the partition table of the upgrade mode firmware and upgrade mode dependent firmware list storage information of firmware storage and upgrade meta information.
[0226] Based on the number of firmware items in the firmware storage and upgrade meta-information's upgrade mode firmware and upgrade mode dependent firmware list storage information, the firmware item lists in the firmware storage and upgrade meta-information's upgrade mode firmware and upgrade mode dependent firmware list storage information are traversed sequentially. According to the partition name of the firmware item, the corresponding upgrade mode firmware image file in the upgrade package and the firmware image file corresponding to each dependent firmware in the upgrade mode firmware dependent firmware list are written to "the starting address of the firmware storage area in the basic information of firmware storage and upgrade meta-information plus the firmware data offset address of the corresponding firmware item in the firmware item list of firmware storage and upgrade meta-information's upgrade mode firmware and upgrade mode dependent firmware list storage information". The size of the written data is the firmware data size of the corresponding firmware item.
[0227] Determine if the user data partition encryption flag in the basic information of firmware storage and upgrade metadata is true. If true, write the Android format system firmware package from the preset temporary system upgrade package directory of the preset unencrypted partition to the address "the starting address of the firmware storage area in the basic information of firmware storage and upgrade metadata plus the starting offset address of the upgrade package storage area of the Android format upgrade package storage information in firmware storage and upgrade metadata". The size of the written data is the size of the upgrade package in the Android format upgrade package storage information of firmware storage and upgrade metadata. If false, write the upgrade package to the address "the starting address of the firmware storage area in the basic information of firmware storage and upgrade metadata plus the starting offset address of the upgrade package storage area of the Android format upgrade package storage information in firmware storage and upgrade metadata". The size of the written data is the size of the upgrade package in the Android format upgrade package storage information of firmware storage and upgrade metadata.
[0228] (3) Store each of the upgrade mode firmware and the upgrade mode firmware dependent firmware list in the firmware storage and upgrade meta information into the target backup address space.
[0229] In some embodiments, based on the number of backup firmware items in the backup firmware list of the upgrade mode firmware and upgrade mode dependent firmware list in the firmware storage and upgrade meta-information, the backup firmware item list of the upgrade mode firmware and upgrade mode dependent firmware list in the firmware storage and upgrade meta-information is traversed sequentially. Based on the backup firmware partition name of the backup firmware item, the corresponding firmware data determined by the starting address and partition size of the corresponding partition in the current partition table is written to "the starting address of the firmware storage area in the basic information of the firmware storage and upgrade meta-information plus the offset address of the backup firmware data of the corresponding backup firmware item in the backup firmware item list of the upgrade mode firmware and upgrade mode dependent firmware list in the firmware storage and upgrade meta-information", and the size of the written data is the size of the backup firmware data of the corresponding backup firmware item.
[0230] (4) Set the upgrade command in the basic information of firmware storage and upgrade metadata to the second-stage upgrade command.
[0231] (5) Update the firmware storage and upgrade metadata.
[0232] In some embodiments, a digital digest of the basic information of the firmware storage and upgrade metadata is calculated according to the digital digest algorithm type of the firmware storage and upgrade metadata, and the calculated digital digest is saved to the basic information digest value of the firmware storage and upgrade metadata; a digital digest of the data composed of the basic information digest value, basic information, mass-produced firmware package storage information, Android format upgrade package storage information, upgrade mode firmware and upgrade mode dependent firmware list storage information, image file upgrade package system firmware storage information, and upgrade mode firmware and upgrade mode dependent firmware list backup information in the firmware storage and upgrade metadata is calculated according to the digital digest algorithm type of the firmware storage and upgrade metadata, and the calculated digital digest is saved to the metadata digital digest of the firmware storage and upgrade metadata.
[0233] (6) Write the updated firmware storage and upgrade metadata in the third preset position of the boot communication partition, write the second-stage upgrade instruction in the first preset position of the boot communication partition, and restart the device.
[0234] If the current upgrade instruction is the sixth stage upgrade instruction, then execute the following steps (1) to (6).
[0235] (1) Erase and format each partition in the preset list of readable and writable partitions with a file system, each partition including a preset user data partition and a block list description file partition.
[0236] (2) Read firmware storage and upgrade metadata from the third preset location of the boot communication partition as backup firmware storage and upgrade metadata.
[0237] (3) Determine whether the backup firmware storage and upgrade metadata are valid. If they are invalid, exit the firmware upgrade process. If they are valid, obtain the Android format upgrade package data based on the backup firmware storage and upgrade metadata.
[0238] In some implementations, it is determined whether the magic number of the backup firmware storage and upgrade metadata is the preset magic number of the firmware storage and upgrade metadata. If not, the firmware upgrade process is exited. If so, the digital digest of the data in the backup firmware storage and upgrade metadata, which consists of the basic information digest value, basic information, mass-produced firmware package storage information, Android format upgrade package storage information, upgrade mode firmware and upgrade mode dependent firmware list storage information, image file upgrade package system firmware storage information, and upgrade mode firmware and upgrade mode dependent firmware list backup information, is calculated according to the digital digest algorithm type of the backup firmware storage and upgrade metadata.
[0239] The system determines whether the calculated digital digest is the same as the digital digest of the metadata of the backup firmware storage and upgrade metadata. If they are different, the firmware upgrade process is terminated. If they are the same, the system calculates the digital digest of the Android format upgrade package storage information of the backup firmware storage and upgrade metadata according to the algorithm type of the digital digest of the backup firmware storage and upgrade metadata. The system then determines whether the calculated digital digest is consistent with the Android format upgrade package storage information digest value in the basic information of the backup firmware storage and upgrade metadata. If they are inconsistent, the firmware upgrade process is terminated. If they are consistent, the system uses the Android upgrade package redirection address in the Android format upgrade package storage information of the backup firmware storage and upgrade metadata as the starting address of the Android format upgrade package, and uses the upgrade package size in the Android format upgrade package storage information of the backup firmware storage and upgrade metadata as the size of the Android format upgrade package.
[0240] Calculate the digital digest of the data in the address space consisting of the starting address and the size of the Android format upgrade package. Determine whether the calculated digital digest is consistent with the upgrade package digital digest value in the Android format upgrade package storage information of the backup firmware storage and upgrade metadata. If they are inconsistent, exit the firmware upgrade process. Otherwise, the data in the address space consisting of the starting address and the size of the Android format upgrade package is called the Android format upgrade package data.
[0241] (4) Create an Android format upgrade package file in the preset firmware upgrade package path of the preset user data partition, and write the Android format upgrade package data into the Android format upgrade package file.
[0242] (5) Update the backup firmware storage and upgrade metadata, and write the updated backup firmware storage and upgrade metadata to the third preset location of the boot communication partition.
[0243] In some implementations, the upgrade instruction in the basic information of the backup firmware storage and upgrade metadata is set to the eighth-stage upgrade instruction; a digital digest of the basic information of the backup firmware storage and upgrade metadata is calculated according to the digital digest algorithm type of the backup firmware storage and upgrade metadata, and the calculated digital digest is saved to the basic information digest value of the backup firmware storage and upgrade metadata; a digital digest of the data composed of the basic information digest value, basic information, mass-produced firmware package storage information, Android format upgrade package storage information, upgrade mode firmware and upgrade mode dependent firmware list storage information, image file upgrade package system firmware storage information, and upgrade mode firmware and upgrade mode dependent firmware list backup information in the backup firmware storage and upgrade metadata is calculated according to the digital digest algorithm type of the backup firmware storage and upgrade metadata, and the calculated digital digest is saved to the metadata digital digest of the backup firmware storage and upgrade metadata; the updated backup firmware storage and upgrade metadata is written to the third preset position of the boot communication partition.
[0244] (6) Set the current upgrade instruction to the eighth stage upgrade instruction and write the set current upgrade instruction to the first preset location of the boot communication partition.
[0245] If the current upgrade instruction is the eighth stage upgrade instruction, then execute the following steps (1) to (4).
[0246] (1) Determine whether there is an Android format upgrade package file under the preset firmware upgrade package path of the preset user data partition. If not, clear the firmware storage and upgrade metadata in the third preset location of the boot communication partition and the upgrade instructions in the first preset location, and restart the device. If it exists, execute step (2).
[0247] (2) Based on the Android format upgrade package file under the preset firmware upgrade package path of the preset user data partition, use the standard Android firmware upgrade engine to upgrade the Android system firmware. During the upgrade process, the firmware in the upgrade mode and the dependent firmware in the upgrade mode dependent firmware list will not be upgraded.
[0248] (3) After the upgrade is completed, format the preset user data partition.
[0249] (4) Clear the firmware storage and upgrade metadata in the third preset location of the boot communication partition and the upgrade instructions in the first preset location, and restart the device.
[0250] If the current upgrade instruction is a preset post-upgrade processing instruction, then execute the following steps (1) to (2).
[0251] (1) Erase and format each partition in the preset list of readable and writable partitions with a file system, each partition including a preset user data partition and a block list description file partition.
[0252] (2) Clear the firmware storage and upgrade metadata in the third preset location of the boot communication partition and the upgrade instructions in the first preset location, and restart the device.
[0253] The firmware upgrade method described above in this invention can be applied to scenarios where some functions that require partition changes need to be added after the product has been shipped. In addition, many types of products do not usually have external storage configured by default to save costs. At the same time, some types of products are deployed in places that are not easily accessible to people, such as high places or dangerous isolation areas. The firmware upgrade method described above in this invention can also be applied when upgrading the firmware of these products.
[0254] According to another aspect of the invention, Figure 3 This is a schematic diagram illustrating an electronic device 300 according to an embodiment of the present invention. (Refer to...) Figure 3 The electronic device 300 includes a memory 302 and a processor 304. The memory 302 is configured to store a computer program that can run on the processor 304. When the processor 304 executes the computer program, it implements the various steps of the firmware upgrade method as described above.
[0255] In summary, in the firmware upgrade method and electronic device provided by the present invention, data of a preset size equal to the firmware storage and upgrade metadata is read from the starting address of the firmware storage and upgrade metadata in the main storage medium as firmware storage and upgrade metadata. If the firmware storage and upgrade metadata is invalid, a first-stage upgrade instruction is read from the boot communication partition to guide the device into firmware upgrade mode. If the firmware storage and upgrade metadata is valid, the upgrade instruction in the basic information of the firmware storage and upgrade metadata is used as the second-stage upgrade instruction. The firmware storage and upgrade metadata is read from a preset position in the boot communication partition. Based on the basic information of the firmware storage and upgrade metadata in the boot communication partition, the data in the firmware storage area is written to the firmware storage area redirection base address, and the firmware storage and upgrade metadata is updated to use the upgrade instruction in the basic information of the firmware storage and upgrade metadata as the third-stage upgrade instruction. The updated firmware storage and upgrade metadata is written to the boot communication partition and the main storage medium. The current upgrade instruction is set as the third-stage upgrade instruction, and the set current upgrade instruction is written to the boot communication partition to perform firmware upgrade based on the third-stage upgrade instruction. This method eliminates the need to back up the boot communication partition. By storing firmware storage and upgrade metadata in the main storage medium, it avoids dependence on the boot communication partition during the upgrade process, reducing the complexity and error rate of the upgrade process. Furthermore, by simultaneously storing firmware storage and upgrade metadata in both the main storage medium and the boot communication partition, it ensures that valid firmware storage and upgrade metadata are always available during the upgrade process. If firmware storage and upgrade metadata in one location are corrupted, they can be mutually recovered, preventing the loss of firmware storage and upgrade metadata due to power failure at any point during the upgrade process. Additionally, by storing upgrade commands in both the firmware storage and upgrade metadata and the boot communication partition, upgrade commands in the corrupted boot communication partition can be recovered using upgrade commands in the firmware storage and upgrade metadata, and vice versa. This ensures that valid upgrade command information is always available during the upgrade process, and that the upgrade can continue after power is restored even if a power failure occurs at any point during the upgrade process, thereby effectively improving the reliability of firmware upgrades. In addition, if the preset user data partition is not encrypted, the upgrade package path is set to the preset firmware upgrade package path of the preset user data partition. If it is encrypted, the block data in the block list is decrypted, and the decrypted data is rewritten to the corresponding block. The corresponding block list is saved to the preset block list description file path of the preset block list description file partition, and the upgrade package path is set to the preset block list description file path of the preset block list description file partition. This can support both encrypted and unencrypted preset user data partitions, improving the flexibility of firmware upgrades.Furthermore, the upgrade package type of the firmware upgrade package is obtained based on firmware storage and upgrade metadata. The upgrade package type can be mass-produced firmware upgrade package type, image file upgrade package type, or Android format upgrade package type. Based on the upgrade package type, the partition table to be upgraded is upgraded according to firmware storage and upgrade metadata to obtain a new partition table. This can support multiple upgrade package types and improve the universality of firmware upgrades.
[0256] The above description is merely an embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent modifications made based on the content of the present invention specification and drawings, or direct or indirect applications in related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. A method of upgrading firmware, characterized by, The method comprises: obtaining a firmware upgrade package, writing first-stage upgrade instructions and an upgrade package path in a boot communication partition, and restarting the device; in the starting boot program firmware, reading data with a preset size of firmware storage and upgrade meta information from a starting address of the firmware storage and upgrade meta information of a main storage medium as the firmware storage and upgrade meta information; if it is judged that the firmware storage and upgrade meta information is not legal, reading the first-stage upgrade instructions from the boot communication partition to guide the device to enter an upgrade mode firmware; if it is judged that the firmware storage and upgrade meta information is legal, taking the upgrade instructions in the basic information of the firmware storage and upgrade meta information as second-stage upgrade instructions, reading the firmware storage and upgrade meta information from a preset position of the boot communication partition, determining an address space of the firmware storage area according to the firmware storage area starting address and the firmware storage area length in the basic information of the firmware storage and upgrade meta information, and writing data in the address space of the firmware storage area into the firmware storage area redirection base address in the basic information of the firmware storage and upgrade meta information, wherein the writing data size is the firmware storage area length in the basic information of the firmware storage and upgrade meta information, and updating the firmware storage and upgrade meta information to take the upgrade instructions in the basic information of the firmware storage and upgrade meta information as third-stage upgrade instructions, and writing the updated firmware storage and upgrade meta information into the boot communication partition and the main storage medium; and setting a current upgrade instruction as the third-stage upgrade instruction, and writing the set current upgrade instruction into the boot communication partition to perform firmware upgrade based on the third-stage upgrade instruction.
2. The method of claim 1, wherein, The updating of the firmware storage and upgrade meta information to take the upgrade instructions in the basic information of the firmware storage and upgrade meta information as third-stage upgrade instructions, and the writing of the updated firmware storage and upgrade meta information into the boot communication partition and the main storage medium comprises: setting the upgrade instructions in the basic information of the firmware storage and upgrade meta information as the third-stage upgrade instructions; calculating a digital digest of the basic information of the firmware storage and upgrade meta information according to a digital digest algorithm type of the firmware storage and upgrade meta information, and saving the digital digest of the basic information to a basic information digest value of the firmware storage and upgrade meta information; calculating a digital digest of data composed of the basic information digest value, the basic information, the mass production firmware package storage information, the Android format upgrade package storage information, the upgrade mode firmware and the upgrade mode dependent firmware list storage information, the mirror file upgrade package system firmware storage information, and the upgrade mode firmware and the upgrade mode dependent firmware list backup information in the firmware storage and upgrade meta information according to the digital digest algorithm type of the firmware storage and upgrade meta information, and saving the digital digest of the data to a meta information digital digest of the firmware storage and upgrade meta information; writing the firmware storage and upgrade meta information in the boot communication partition; obtaining a main storage medium size of the main storage medium, subtracting a preset storage medium tail reserved size and a firmware storage and upgrade meta information preset size from the main storage medium size to obtain a start address of the firmware storage and upgrade meta information in the main storage medium; and writing the firmware storage and upgrade meta information into the start address of the firmware storage and upgrade meta information in the main storage medium.
3. The method of claim 1, wherein, The firmware upgrade package includes: The client obtains the firmware upgrade package and saves the firmware upgrade package to a preset firmware upgrade package path of a preset user data partition; determining whether the firmware upgrade package is legal; if not encrypted, setting an upgrade package path to be the preset firmware upgrade package path of the preset user data partition; and if encrypted, generating a block list occupied by the firmware upgrade package file using a preset decryption service, decrypting block data in the block list, re-writing the decrypted data into the corresponding block, saving the corresponding block list to a preset block list description file path of a preset block list description file partition, and setting the upgrade package path to be the preset block list description file path of the preset block list description file partition. Further comprising:
4. The method of claim 1, wherein, if the current upgrade instruction is the third stage upgrade instruction, reading the firmware storage and upgrade meta information from the main storage medium; determining whether the read firmware storage and upgrade meta information is legal; if the read firmware storage and upgrade meta information is not legal, reading the firmware storage and upgrade meta information from the boot communication partition as backup firmware storage and upgrade meta information, and updating the firmware storage and upgrade meta information in the main storage medium using the backup firmware storage and upgrade meta information; reading an upgrade instruction from the boot communication partition and determining whether the read upgrade instruction is consistent with the upgrade instruction in the basic information of the firmware storage and upgrade meta information; if not consistent, writing the upgrade instruction in the basic information of the firmware storage and upgrade meta information into the boot communication partition; obtaining a current partition table from an address space where the partition table in the main storage medium is located; based on the current partition table, performing legality checking on each backup firmware item in the backup firmware item list in the upgrade mode firmware and the upgrade mode dependent firmware list backup information of the firmware storage and upgrade meta information; if the result of the legality checking is that all are legal, modifying the current partition table based on the firmware storage and upgrade meta information to obtain a modified current partition table; writing the modified current partition table into the address space where the partition table in the main storage medium is located; updating the firmware storage and upgrade meta information, and writing the updated firmware storage and upgrade meta information into the boot communication partition; setting the current upgrade instruction to be a fourth stage upgrade instruction, and writing the set current upgrade instruction into the boot communication partition; and writing the updated firmware storage and upgrade meta information into the main storage medium. Further comprising: 5. The method of claim 4, wherein, If the current upgrade instruction is a fourth-stage upgrade instruction, reading the firmware storage and upgrade meta-information from the main storage medium; determining whether the read firmware storage and upgrade meta-information is legal; if legal, writing the firmware storage and upgrade meta-information in the boot communication partition; if not legal, reading the firmware storage and upgrade meta-information from the boot communication partition as backup firmware storage and upgrade meta-information, and using the backup firmware storage and upgrade meta-information to update the firmware storage and upgrade meta-information in the main storage medium; reading an upgrade instruction from the boot communication partition, and determining whether the read upgrade instruction is consistent with the upgrade instruction in the basic information of the firmware storage and upgrade meta-information; if not consistent, writing the upgrade instruction in the basic information of the firmware storage and upgrade meta-information into the boot communication partition; based on the firmware storage and upgrade meta-information, obtaining an upgrade package type of the firmware upgrade package, the upgrade package type being a mass production firmware upgrade package type, an image file upgrade package type, or an Android format upgrade package type; based on the firmware storage and upgrade meta-information, upgrading a partition table to be upgraded according to the upgrade package type, to obtain a new partition table; updating the firmware storage and upgrade meta-information, and writing the updated firmware storage and upgrade meta-information into the boot communication partition of the new partition table; setting the current upgrade instruction as a fifth-stage upgrade instruction, and writing the set current upgrade instruction into the boot communication partition of the new partition table; and writing the updated firmware storage and upgrade meta-information into the main storage medium. Further comprising:
6. The method of claim 5, wherein, if the current upgrade instruction is a fifth-stage upgrade instruction, reading firmware storage and upgrade meta-information from the main storage medium; determining whether the read firmware storage and upgrade meta-information is legal; if not legal, reading the firmware storage and upgrade meta-information from the boot communication partition as backup firmware storage and upgrade meta-information, and using the backup firmware storage and upgrade meta-information to update the firmware storage and upgrade meta-information in the main storage medium; reading an upgrade instruction from the boot communication partition, and determining whether the read upgrade instruction is consistent with the upgrade instruction in the basic information of the firmware storage and upgrade meta-information; if not consistent, writing the upgrade instruction in the basic information of the firmware storage and upgrade meta-information into the boot communication partition; determining whether the upgrade package type of the firmware upgrade package in the basic information of the firmware storage and upgrade meta-information is an Android format upgrade package type; if the upgrade package type is an Android format upgrade package type, obtaining Android format upgrade package data based on the firmware storage and upgrade meta-information, and transferring the Android format upgrade package data to an Android upgrade package redirection address based on the firmware storage and upgrade meta-information; updating the firmware storage and upgrade meta-information, and writing the updated firmware storage and upgrade meta-information into the boot communication partition; setting the current upgrade instruction as a sixth stage upgrade instruction, and writing the set current upgrade instruction into the boot communication partition; and writing the updated firmware storage and upgrade meta information into the main storage medium.
7. The method of claim 6, wherein, Further comprising: setting the upgrade instruction in the basic information of the firmware storage and upgrade meta information as a seventh stage upgrade instruction; if the current upgrade instruction is the seventh stage upgrade instruction, reading firmware storage and upgrade meta information from the main storage medium; judging whether the read firmware storage and upgrade meta information is legal; if the read firmware storage and upgrade meta information is illegal, reading the firmware storage and upgrade meta information from the boot communication partition as backup firmware storage and upgrade meta information, and updating the firmware storage and upgrade meta information in the main storage medium using the backup firmware storage and upgrade meta information; reading an upgrade instruction from the boot communication partition, and judging whether the read upgrade instruction is consistent with the upgrade instruction in the basic information of the firmware storage and upgrade meta information; if not, writing the upgrade instruction in the basic information of the firmware storage and upgrade meta information into the boot communication partition; obtaining an upgrade package type of the firmware upgrade package based on the firmware storage and upgrade meta information; if the upgrade package type is a mass production firmware upgrade package type or an image file upgrade package type, upgrading a partition table to be upgraded based on the firmware storage and upgrade meta information according to the mass production firmware upgrade package type or the image file upgrade package type, to obtain a new partition table; updating the firmware storage and upgrade meta information, and writing the updated firmware storage and upgrade meta information into the boot communication partition; setting the current upgrade instruction as a preset post-upgrade processing instruction, and writing the set current upgrade instruction into the boot communication partition; and writing the updated firmware storage and upgrade meta information into the main storage medium.
8. The method of claim 4, wherein, Further comprising: if the current upgrade instruction is a first stage upgrade instruction, a sixth stage upgrade instruction, an eighth stage upgrade instruction or a preset post-upgrade processing instruction, controlling the device to run an upgrade mode firmware; in the upgrade mode firmware, reading an upgrade instruction from the boot communication partition, and judging whether the read upgrade instruction is the first stage upgrade instruction, the sixth stage upgrade instruction, the eighth stage upgrade instruction or the preset post-upgrade processing instruction, if so, taking the read upgrade instruction as the current upgrade instruction; if the current upgrade instruction is the first stage upgrade instruction, constructing the firmware storage and upgrade meta information according to the firmware upgrade package; storing data in the firmware upgrade package to a target address space based on the firmware storage and upgrade meta information; storing an upgrade mode firmware in the firmware storage and upgrade meta information and each dependent firmware in a dependent firmware list of the upgrade mode firmware to a target backup address space; setting the upgrade instruction in the basic information of the firmware storage and upgrade meta information as the second stage upgrade instruction; updating the firmware storage and upgrade meta information; and write the updated firmware storage and upgrade meta information and the second stage upgrade instruction in the boot communication partition, and restart the device.
9. The method of claim 8, wherein, Further comprising: if the current upgrade instruction is the sixth stage upgrade instruction, erase and format each partition in a preset list of readable and writable partitions with a file system, the each partition including a preset user data partition and a block list description file partition; read the firmware storage and upgrade meta information from the boot communication partition as backup firmware storage and upgrade meta information; determine whether the backup firmware storage and upgrade meta information is legal; if legal, obtain Android format upgrade package data based on the backup firmware storage and upgrade meta information; create an Android format upgrade package file under a preset firmware upgrade package path of the preset user data partition, and write the Android format upgrade package data into the Android format upgrade package file; update the backup firmware storage and upgrade meta information, and write the updated backup firmware storage and upgrade meta information into the boot communication partition; and set the current upgrade instruction as an eighth stage upgrade instruction, and write the set current upgrade instruction into the boot communication partition.
10. The method of claim 9, wherein, Further comprising: if the current upgrade instruction is the eighth stage upgrade instruction, determine whether the Android format upgrade package file exists under the preset firmware upgrade package path of the preset user data partition; if not, clear the firmware storage and upgrade meta information and the upgrade instruction in the boot communication partition, and restart the device; if yes, use a standard Android firmware upgrade engine to upgrade the Android system firmware according to the Android format upgrade package file under the preset firmware upgrade package path of the preset user data partition, and no upgrade is performed on the upgrade mode firmware and the dependent firmware in the upgrade mode dependent firmware list during the upgrade; after the upgrade, format the preset user data partition; and clear the firmware storage and upgrade meta information and the upgrade instruction in the boot communication partition, and restart the device.
11. The method of claim 8, wherein, Further comprising: if the current upgrade instruction is the preset post-upgrade processing instruction, erase and format each partition in a preset list of readable and writable partitions with a file system, the each partition including a preset user data partition and a block list description file partition; and clear the firmware storage and upgrade meta information and the upgrade instruction in the boot communication partition, and restart the device.
12. An electronic device, comprising: comprising: a memory configured to store an executable program; and a processor configured to execute the program to perform the method according to any one of claims 1 to 11.
Citation Information
Patent Citations
Firmware upgrading method, electronic equipment and storage medium
CN118567680A
Firmware upgrading method and electronic equipment
CN120671116A