Methods for upgrading firmware, electronic devices and storage media

By merging upgrade packages and using a dual-system upgrade engine, the problem of abnormal firmware upgrades for non-A/B partitions in the A/B system was solved, enabling reliable upgrades even when dependencies exist, and ensuring that the system can boot normally after the upgrade.

CN119960784BActive Publication Date: 2026-03-10FUZHOU ROCKCHIP SEMICON
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-05
Publication Date
2026-03-10

AI Technical Summary

Technical Problem

Existing technologies have issues with upgrade anomalies caused by dependencies when upgrading firmware for non-A/B partitions in A/B systems. This makes it incompatible with firmware for both A/B and non-A/B partitions, resulting in system boot failure.

Method used

The upgrade package is merged and upgraded using a dual-system upgrade engine. After the upgrade is completed, the system is restarted. By mounting and restoring firmware from non-A/B partitions, the reliability of firmware upgrades can still be guaranteed even when there is a dependency relationship between A/B partitions and non-A/B partitions.

Benefits of technology

When there is a dependency relationship between A/B partitions and non-A/B partitions, the reliability of firmware upgrades is ensured, avoiding system boot failures due to incompatibility and improving the security and reliability of the upgrade process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119960784B_ABST
    Figure CN119960784B_ABST
Patent Text Reader

Abstract

This invention discloses a method, electronic device, and storage medium for upgrading firmware. The method includes, in the bootloader firmware, if the current boot slot is equal to the previous slot in the upgrade metadata, and the firmware in the non-A / B partition is different from the non-A / B partition firmware under the previous non-A / B firmware path in the data partition corresponding to the upgrade metadata, then the partition corresponding to the data partition name of the upgrade metadata is mounted, and the firmware in the non-A / B partition is restored to the previous non-A / B partition firmware based on the data partition. The upgrade metadata in the boot communication partition is cleared from a preset location, and the Android system is booted normally. Therefore, even when there is a dependency relationship between the A / B partition firmware and the non-A / B partition firmware, the reliability of the firmware upgrade can still be guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] There are two main methods for firmware OTA upgrades in Android systems: recovery upgrade and A / B upgrade.

[0003] The recovery upgrade method in Android systems is also known as the non-A / B upgrade method. When using this method, it requires that all firmware files to be upgraded in the Android system have only one corresponding partition. For example, boot.img firmware corresponds to a unique boot partition, system.img firmware corresponds to a unique system partition, and uboot.img firmware corresponds to a unique uboot partition. During the upgrade, the corresponding firmware is upgraded to the corresponding partition, such as upgrading boot.img firmware to the boot partition.

[0004] When using the A / B upgrade method in Android, all firmware files to be upgraded must have two partitions, A and B, represented by the suffixes _a and _b. For example, boot.img firmware requires two partitions, boot_a and boot_b, and uboot.img firmware requires two partitions, uboot_a and uboot_b. All firmware files in partition A of the A / B system form the A slot (a slot) system, and all firmware files in partition B of the A / B system form the B slot (b slot) system. During an A / B upgrade, if the device is currently running in slot A, the firmware to be upgraded is moved to slot B, and vice versa. This A / B slot method ensures the reliability of firmware upgrades within the Android system.

[0005] The current Android system's recovery upgrade method and A / B upgrade method are incompatible. This means that if using the A / B upgrade method, all firmware files to be upgraded in the Android system must have two partitions, A and B, with the suffixes _a and _b. However, in some scenarios, to save space, it's necessary to use A / B partitions for critical partitions in the Android system, while using non-critical or space-consuming partitions in a different format. Examples include resource partitions and parameter configuration partitions in some products. When performing OTA upgrades on such systems, using the Android system's A / B upgrade method will not be able to upgrade firmware with non-A / B partitions.

[0006] Existing methods for supporting the upgrade of non-A / B (dual system) firmware in A / B systems all require that there be no dependency between the A / B partition firmware and the non-A / B partition firmware. If there is a dependency, it will lead to upgrade anomalies. Summary of the Invention

[0007] This invention provides a method, electronic device, and storage medium for upgrading firmware, which can ensure the reliability of firmware upgrades even when there is a dependency coupling relationship between A / B partition firmware and non-A / B partition firmware.

[0008] In one aspect of the present invention, a method for upgrading firmware is provided. The method includes: obtaining a merged upgrade package, the merged upgrade package including a dual-system firmware upgrade package and a non-dual-system firmware upgrade sub-package compressed into one upgrade package; constructing upgrade metadata based on information associated with the non-dual-system firmware upgrade sub-package, and writing the upgrade metadata into a preset location in a boot communication partition; performing a dual-system upgrade using a dual-system upgrade engine based on the dual-system firmware upgrade package, and restarting the system after the upgrade is completed, booting the upgraded bootloader firmware; in the bootloader firmware, if the current boot slot is equal to the pre-upgrade slot of the upgrade metadata, and the firmware in the non-dual-system partition is different from the non-dual-system partition firmware under the pre-upgrade non-dual-system firmware path of the upgrade metadata in the data partition corresponding to the data partition name of the upgrade metadata, then mounting the partition corresponding to the data partition name of the upgrade metadata, using the mounted partition as the data partition, and restoring the firmware in the non-dual-system partition to the non-dual-system partition firmware corresponding to the pre-upgrade firmware based on the data partition; and clearing the upgrade metadata in the preset location in the boot communication partition, and booting the Android system normally according to a preset process.

[0009] 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 executable program to cause the electronic device to perform the aforementioned method for upgrading firmware.

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

[0011] According to the present invention, a dual-system upgrade engine is used to perform a dual-system upgrade based on the acquired dual-system firmware upgrade package. After the upgrade is completed, the system is restarted, and the upgraded bootloader firmware is booted. In the bootloader firmware, if the current boot slot is equal to the slot before the upgrade in the upgrade metadata, and the firmware in the non-dual-system partition is different from the non-dual-system partition firmware under the path of the non-dual-system firmware before the upgrade in the data partition corresponding to the data partition name in the upgrade metadata, then the partition corresponding to the data partition name in the upgrade metadata is mounted, the mounted partition is used as the data partition, and the firmware in the non-dual-system partition is restored to the non-dual-system partition firmware corresponding to the one before the upgrade based on the data partition, and the bootloader is cleared. The upgrade metadata in the preset location in the communication partition guides the Android system to boot normally according to the preset process. If an accident occurs during the upgrade of A / B firmware, the upgrade can be restarted as needed after entering the Android system. If an accident occurs during the upgrade of non-A / B firmware, the bootloader firmware itself can always boot after the system is powered on again. Therefore, the upgrade of non-A / B firmware can continue after power-on, avoiding the situation where the upgraded A / B firmware cannot boot due to incompatibility with the old non-A / B firmware. Thus, even when there is a dependency relationship between A / B partition firmware and non-A / B partition firmware, the reliability of firmware upgrade can still be guaranteed. Attached Figure Description

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

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

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

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

[0016] In existing technologies, methods for upgrading non-A / B (dual-system) firmware within an A / B system all require that there be no dependency between the A / B partition firmware and the non-A / B partition firmware. If a dependency exists, it will lead to upgrade anomalies.

[0017] To address at least the aforementioned technical problems, this disclosure provides a method for upgrading firmware. According to this disclosure, a dual-system upgrade engine is used to perform a dual-system upgrade based on the acquired dual-system firmware upgrade package. After the upgrade is complete, the system is restarted, and the upgraded bootloader firmware is initiated. In the bootloader firmware, if the current boot slot is equal to the slot before the upgrade in the upgrade metadata, and the firmware in the non-dual-system partition is different from the non-dual-system partition firmware under the path of the non-dual-system firmware before the upgrade in the data partition corresponding to the data partition name in the upgrade metadata, then the partition corresponding to the data partition name in the upgrade metadata is mounted, the mounted partition is used as the data partition, and the firmware in the non-dual-system partition is restored to the non-dual-system partition firmware before the upgrade based on the data partition. The upgrade metadata in the preset location in the boot communication partition is cleared, and the Android system is booted normally according to the preset process. In this way, if an accident occurs during the A / B firmware upgrade process, the upgrade can be restarted as needed after entering the Android system. If an accident occurs during the upgrade of non-A / B firmware, the bootloader firmware can always start after the system is powered on again. Therefore, the upgrade of non-A / B firmware can continue after power-on, avoiding the situation where the upgraded A / B firmware cannot start due to incompatibility with the old non-A / B firmware. Thus, the reliability of firmware upgrade can still be guaranteed when there is a dependency relationship between A / B partition firmware and non-A / B partition firmware.

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

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

[0020] In step 102, a merged upgrade package is obtained, which includes a dual-system firmware upgrade package and a non-dual-system firmware upgrade sub-package that have been compressed into one upgrade package.

[0021] In step 104, upgrade metadata is constructed based on the information associated with the non-dual system firmware upgrade subpackage, and the upgrade metadata is written to a preset location in the boot communication partition.

[0022] In some embodiments, prior to step 102, the method 100 may further include: determining the magic number, the digital digest algorithm type, the slot before the upgrade, the data partition name, the data partition file system type, the non-dual-system firmware path before the upgrade, and the non-dual-system firmware path to be upgraded; determining the list of non-dual-system partition image information before the upgrade and the list of non-dual-system partition image information to be upgraded based on the obtained non-dual-system firmware upgrade sub-package; and calculating the metadata digital digest value according to the digital digest algorithm type.

[0023] In some embodiments, the upgrade metadata is generated based on the magic number, the digital digest algorithm type, the pre-upgrade slot, the data partition name, the data partition file system type, the pre-upgrade non-dual system firmware path, the pre-upgrade non-dual system partition image information list, the non-dual system firmware path to be upgraded, the non-dual system partition image information list to be upgraded, and the metadata digital digest value.

[0024] In some embodiments, prior to step 102, the method 100 may further include: naming the non-dual-system firmware upgrade sub-package containing all non-dual-system partition firmware image files to be upgraded according to a preset name; and compressing the Android standard dual-system upgrade package and the non-dual-system firmware upgrade sub-package to obtain the upgrade package to be upgraded, and naming the upgrade package to be upgraded using the name of the Android standard dual-system upgrade package. In this way, because the upgrade package is encapsulated, it cannot be seamlessly integrated into the existing A / B upgrade process, but it can be compatible with the existing interaction protocol between the A / B upgrade client and the upgrade server. Therefore, the A / B upgrade client can seamlessly obtain the upgrade package to be upgraded without modifying the interaction protocol between the client and the server.

[0025] In some embodiments, prior to step 102, the method 100 may further include: obtaining an upgrade package to be upgraded with a name corresponding to a standard dual-system upgrade package; if the upgrade package to be upgraded does not contain a non-dual-system firmware upgrade sub-package with a preset name, then using a dual-system upgrade engine to perform a dual-system upgrade based on the upgrade package to be upgraded, and restarting the system after the upgrade is completed to boot the upgraded bootloader firmware; and if the upgrade package to be upgraded contains a non-dual-system firmware upgrade sub-package with a preset name, then unpacking the upgrade package to be upgraded to obtain the dual-system firmware upgrade package and the non-dual-system firmware upgrade sub-package.

[0026] In this way, there is no need to reserve a partition; instead, the existing read / write partitions in the Android system are used directly, saving storage space and improving storage space utilization.

[0027] In step 106, the dual-system upgrade engine is used to perform a dual-system upgrade based on the dual-system firmware upgrade package, and the system is restarted after the upgrade is completed to boot the upgraded bootloader firmware.

[0028] In step 108, in the bootloader firmware, if the current boot slot is equal to the pre-upgrade slot of the upgrade metadata, and the firmware in the non-dual system partition is different from the non-dual system partition firmware under the pre-upgrade non-dual system firmware path of the upgrade metadata in the data partition corresponding to the data partition name of the upgrade metadata, then the partition corresponding to the data partition name of the upgrade metadata is mounted, the mounted partition is used as the data partition, and the firmware in the non-dual system partition is restored to the non-dual system partition firmware corresponding to the pre-upgrade firmware based on the data partition.

[0029] In some embodiments, the partition corresponding to the data partition name of the upgrade meta information is mounted in read-only mode according to the data partition file system type of the upgrade meta information, and the mounted partition is used as a data partition.

[0030] In some embodiments, the validity of all non-dual-system partition firmware image files under the previous non-dual-system firmware path in the upgrade metadata of the data partition is verified. If all non-dual-system partition firmware image files are valid, then all non-dual-system partition firmware image files under the previous non-dual-system firmware path in the upgrade metadata of the data partition are written to the corresponding non-dual-system partition. In this way, a safe and reliable firmware upgrade for non-A / B partitions is achieved.

[0031] In step 110, the upgrade metadata in the preset location of the boot communication partition is cleared, and the Android system is booted normally according to the preset process.

[0032] In this way, if the upgrade completes normally, but the upgraded A / B firmware itself has problems—meaning the firmware slot after the upgrade cannot be set to a successful boot flag by the Android A / B upgrade engine—then after the system restarts a preset number of times, the bootloader firmware, according to the Android A / B upgrade specification, will switch the current boot slot back to the pre-upgrade slot, using the old A / B firmware. At this point, the current boot slot is equal to the pre-upgrade slot in the upgrade metadata, and the firmware in the non-A / B partition is different from the non-A / B partition firmware corresponding to the pre-upgrade non-A / B firmware path in the data partition corresponding to the upgrade metadata's data partition name. Then, based on the data partition file system type of the upgrade metadata, the partition corresponding to the upgrade metadata's data partition name is mounted in read-only mode, and the mounted partition... The partition is called the data partition. All non-A / B partition firmware image files under the non-A / B firmware path before the upgrade, which contains upgrade metadata in the data partition, are written to the corresponding non-A / B partition. This restores the firmware in the non-A / B partition to the non-A / B partition firmware corresponding to the slot before the upgrade, thereby ensuring compatibility between A / B firmware and non-A / B firmware. This avoids the situation where the system cannot boot due to incompatibility between the old A / B firmware and the new non-A / B firmware before the upgrade. Finally, the upgrade metadata in the preset location in the boot communication partition is cleared, and the device is normally booted into the Android system before the upgrade according to the preset process. After entering the Android system, the upgrade can be restarted as needed. Thus, even when there is a dependency relationship between A / B partition firmware and non-A / B partition firmware, the reliability of firmware upgrade can still be guaranteed.

[0033] In some embodiments, the method 100 may further include: if the current boot slot is equal to the pre-upgrade slot of the upgrade metadata, and the firmware in the non-dual system partition is the same as the non-dual system partition firmware under the pre-upgrade non-dual system firmware path of the upgrade metadata in the data partition corresponding to the data partition name of the upgrade metadata, then clear the upgrade metadata in the preset position in the boot communication partition, and boot the Android system normally according to the preset process.

[0034] In this way, if an accident occurs during the A / B firmware upgrade process (such as a power outage), the A / B upgrade engine in the Android system will not set the system to boot from the upgraded slot because the A / B upgrade is not completed. When the system is powered on again, in the bootloader firmware, the current boot slot is equal to the slot before the upgrade in the upgrade metadata information, and the firmware in the non-A / B partition is the same as the non-A / B partition firmware under the path of the non-A / B firmware before the upgrade in the data partition corresponding to the data partition name of the upgrade metadata information. At this time, the upgrade metadata in the preset position in the boot communication partition is cleared, and then the Android system is booted normally according to the preset process. After entering the Android system, the upgrade can be restarted as needed, thus ensuring that the upgrade can always be completed smoothly.

[0035] In some embodiments, prior to step 108, the method 100 may further include: checking the legality of the upgrade metadata in a preset location of the boot communication partition; and if the check result is illegal, booting the Android system normally according to a preset process. This ensures the security of the upgrade process.

[0036] In some embodiments, prior to step 108, the method 100 may further include: reading Android dual-system upgrade boot control information from the boot communication partition; and obtaining the current boot slot from the Android dual-system upgrade boot control information.

[0037] In some embodiments, the method 100 may further include: if the current boot slot is not equal to the pre-upgrade slot of the upgrade metadata, and the current boot slot has been set with a successful boot flag, then clear the non-dual system partition upgrade completion flag and the upgrade metadata in the preset position of the boot communication partition, and boot the Android system normally according to the preset process.

[0038] In some embodiments, the method 100 may further include: if the current boot slot is not equal to the pre-upgrade slot of the upgrade metadata, and the current boot slot has not set a successful boot flag, then read the non-dual-system partition upgrade completion flag from the boot communication partition; if the non-dual-system partition upgrade completion flag is a preset non-dual-system partition upgrade completion magic number, then boot the Android system normally according to a preset process; if the non-dual-system partition upgrade completion flag is not a preset non-dual-system partition upgrade completion magic number, then mount the partition corresponding to the data partition name of the upgrade metadata, use the mounted partition as a data partition, and upgrade the non-dual-system partition firmware based on the data partition; and write the preset non-dual-system partition upgrade completion magic number into the boot communication partition, and boot the Android system normally according to a preset process.

[0039] In some embodiments, the validity of all non-dual system partition firmware image files under the non-dual system firmware path to be upgraded in the upgrade metadata of the data partition is verified; and if all non-dual system partition firmware image files are valid, then all non-dual system partition firmware image files under the non-dual system firmware path to be upgraded in the upgrade metadata of the data partition are written to the corresponding non-dual system partition.

[0040] In this way, if an accident occurs during the upgrade of non-A / B firmware (such as a power outage), since the bootloader firmware itself is A / B and has already been upgraded by the Android A / B upgrade engine before upgrading the non-A / B firmware, and since the bootloader firmware starts upgrading the non-A / B partition firmware before accessing its contents, there is no bootloader firmware crashing due to the dependency between the bootloader firmware and the non-A / B partition firmware. After the system is powered on again, the bootloader firmware can always start, thus continuing the non-A / B firmware upgrade. Only after the non-A / B firmware upgrade is completed will the bootloader firmware normally boot the device into the upgraded Android system according to the preset process, thereby ensuring compatibility between A / B firmware and non-A / B firmware. This avoids situations where the upgraded A / B firmware cannot boot due to incompatibility with the old non-A / B firmware, improving the reliability of the upgrade process.

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

[0042] Figure 2 This is a flowchart illustrating a method for upgrading firmware according to an embodiment of the present invention, including steps 201 to 215.

[0043] In step 201, the non-A / B firmware upgrade subpackage containing all non-A / B partition firmware image files to be upgraded is named according to a preset name (e.g., non_A / B_update.zip).

[0044] In some embodiments, each non-A / B partition firmware image file to be upgraded in the non-A / B firmware upgrade subpackage uses the non-A / B partition name corresponding to the firmware image file as the prefix of the firmware image file name. For example, the prefix "resource" in the non-A / B partition firmware image file resource.img to be upgraded is the partition name resource corresponding to the non-A / B partition firmware image file to be upgraded.

[0045] In step 202, the Android standard A / B upgrade package (such as RK3588_A / B_update_V1.0.zip) and the non-A / B firmware upgrade sub-package (such as non_A / B_update.zip) are compressed to obtain the upgrade package to be upgraded, and the upgrade package to be upgraded is named using the name of the Android standard A / B upgrade package.

[0046] For example, if the standard Android A / B upgrade package is named RK3588_A / B_update_V1.0.zip, then the corresponding upgrade package to be upgraded will also be named RK3588_A / B_update_V1.0.zip.

[0047] In step 203, obtain the upgrade package to be upgraded with a name corresponding to the standard dual-system upgrade package; determine whether the upgrade package to be upgraded contains a non-A / B firmware upgrade sub-package with a preset name. If not, proceed to step 204; if yes, proceed to steps 205 to 207.

[0048] In step 204, the A / B upgrade engine is used to perform an A / B upgrade based on the upgrade package to be upgraded. After the upgrade is completed, the system is restarted and the upgraded bootloader firmware is used.

[0049] In step 205, the upgrade package to be upgraded is unpacked to obtain the A / B firmware upgrade package and the non-A / B firmware upgrade sub-package.

[0050] In step 206, upgrade meta-information is constructed based on the information associated with the non-A / B firmware upgrade sub-package, and the upgrade meta-information is written to a preset location in the boot communication partition, specifically including the following steps (1) to (5).

[0051] (1) Determine the magic number, digital digest algorithm type, pre-upgrade slot, data partition name, data partition file system type, pre-upgrade non-A / B firmware path, and the non-A / B firmware path to be upgraded.

[0052] Specifically, the magic number is set to the preset magic number of the upgrade metadata; the digital digest algorithm type is set to the preset digital digest algorithm; the A / B slot information in the Android system before the upgrade is obtained and used as the slot before the upgrade; the data partition name is set to the preset readable and writable unencrypted data partition name (such as cache) in the Android system; the data partition file system type is set to the file system type of the partition corresponding to the data partition name in the upgrade metadata; the non-A / B firmware path before the upgrade is set to the preset non-A / B firmware path before the upgrade; and the non-A / B firmware path to be upgraded is set to the preset non-A / B firmware path to be upgraded.

[0053] (2) Based on the obtained non-A / B firmware upgrade sub-package, determine the list of non-A / B partition image information before upgrade and the list of non-A / B partition image information to be upgraded, specifically including the following steps (2-1) to (2-5).

[0054] (2-1) Check if the non-A / B firmware path before the upgrade exists in the data partition corresponding to the data partition name of the upgrade metadata. If it does not exist, create the directory structure corresponding to the path; otherwise, delete all files under the path.

[0055] (2-2) For each non-A / B firmware partition among all non-A / B firmware partitions to be upgraded, perform the following steps (a) to (c).

[0056] (a) Using the partition name of the non-A / B firmware partition as a prefix, create an empty firmware image file with the partition name of the non-A / B firmware partition as a prefix in the non-A / B firmware path before the upgrade metadata, and use it as the current non-A / B partition firmware image file.

[0057] (b) Determine the corresponding non-A / B partition block device node based on the partition name of the non-A / B firmware partition, read all the contents of the determined corresponding non-A / B partition block device node as the corresponding non-A / B partition image data, and write the read non-A / B partition image data into the current non-A / B partition firmware image file.

[0058] (c) Obtain the unused non-A / B partition image information items from the list of non-A / B partition image information before the upgrade in the order of upgrade metadata as the current non-A / B partition image information items; set the image name of the current non-A / B partition image information item to the partition name of the non-A / B firmware partition; calculate the digital digest of the current non-A / B partition firmware image file according to the digital digest algorithm type of the upgrade metadata, and save the calculated digital digest to the image digest value of the current non-A / B partition image information item.

[0059] (2-3) Check if the path of the non-A / B firmware to be upgraded exists in the data partition corresponding to the data partition name of the upgrade metadata. If it does not exist, create the directory structure corresponding to the path; otherwise, delete all files under the path.

[0060] (2-4) Unzip the non-A / B firmware upgrade subpackage and save all the non-A / B partition firmware image files to be upgraded in the non-A / B firmware path of the upgrade metadata.

[0061] (2-5) Traverse all non-A / B partition firmware image files to be upgraded under the non-A / B firmware path to be upgraded in the data partition corresponding to the data partition name of the upgrade metadata. For each non-A / B partition firmware image file traversed, perform the following steps (a) to (c).

[0062] (a) The unused non-A / B partition image information item in the list of non-A / B partition image information to be upgraded is obtained in sequence as the current non-A / B partition image information item.

[0063] (b) Save the prefix of the filename of the corresponding non-A / B partition firmware image file as the partition name of the corresponding non-A / B partition to the image name of the current non-A / B partition image information item.

[0064] (c) Calculate the digital digest value of the corresponding non-A / B partition firmware image file according to the digital digest algorithm type of the upgrade meta information, and save the calculated digital digest value to the image digest value of the current non-A / B partition image information item.

[0065] (3) Calculate the metadata digital digest value according to the digital digest algorithm type.

[0066] Specifically, based on the digital digest algorithm type, a digital digest value is calculated for the data in the address space consisting of the pre-upgrade slot, data partition name, data partition file system type, pre-upgrade non-A / B firmware path, pre-upgrade non-A / B partition image information list, non-A / B firmware path to be upgraded, and non-A / B partition image information list to be upgraded, and the calculated digital digest value is used as the metadata digital digest value.

[0067] (4) Generate upgrade metadata based on the magic number, digital digest algorithm type, previous slot, data partition name, data partition file system type, previous non-A / B firmware path, previous non-A / B partition image information list, to-be-upgraded non-A / B firmware path, to-be-upgraded non-A / B partition image information list, and metadata digital digest value. Both the previous and to-be-upgraded non-A / B partition image information lists are composed of non-A / B partition image information items, each consisting of an image name and an image digest value.

[0068] (5) Write the upgrade metadata to the preset location in the boot communication partition.

[0069] In step 207, the A / B upgrade engine is used to perform an A / B upgrade based on the A / B firmware upgrade package. After the upgrade is completed, the system is restarted and the upgraded bootloader firmware is used.

[0070] In step 208, the validity of the upgrade metadata in the preset location of the boot communication partition is checked. If the check result is invalid, the Android system is booted normally according to the preset process. If the check result is valid, step 209 is executed.

[0071] In some embodiments, the validity of upgrade metadata in a preset location of the boot communication partition is checked, specifically including the following steps (1) to (2).

[0072] (1) Read the upgrade metadata from the preset location of the boot communication partition, and determine whether the magic number of the upgrade metadata is the preset magic number of the upgrade metadata. If not, determine that the check result is illegal; otherwise, proceed to step (2).

[0073] (2) Calculate the digital digest value of the data in the address space composed of the pre-upgrade slot, data partition name, data partition file system type, pre-upgrade non-A / B firmware path, pre-upgrade non-A / B partition image information list, non-A / B firmware path to be upgraded, and non-A / B partition image information list to be upgraded in the upgrade meta information according to the digital digest algorithm type of the upgrade meta information. Compare the calculated digital digest value with the meta information digital digest value of the upgrade meta information. If they are inconsistent, the check result is determined to be illegal; otherwise, the check result is determined to be legal.

[0074] In step 209, read the Android A / B upgrade boot control information from the boot communication partition, and obtain the current boot slot from the Android A / B upgrade boot control information.

[0075] In step 210, in the bootloader firmware, it is determined whether the current boot slot is equal to the pre-upgrade slot in the upgrade metadata. If so, it is checked whether the firmware in the non-A / B partition is the same as the firmware in the non-A / B partition under the pre-upgrade non-A / B firmware path in the data partition corresponding to the data partition name of the upgrade metadata. If they are the same, it means that the recovery has been completed, and step 211 is executed. If they are not the same, steps 212 to 213 are executed. If not, it is checked whether the current boot slot has been set with a successful boot flag (such as successful) according to the Android A / B upgrade boot control information. If so, step 214 is executed. If not, step 215 is executed.

[0076] In step 211, the upgrade metadata in the preset location of the boot communication partition is cleared, and the Android system is booted normally according to the preset process.

[0077] In step 212, the partition corresponding to the data partition name of the upgrade metadata is mounted in read-only mode according to the data partition file system type of the upgrade metadata. The mounted partition is used as the data partition, and the firmware in the non-A / B partition is restored to the non-A / B partition firmware corresponding to the one before the upgrade based on the data partition.

[0078] In some embodiments, the firmware in the non-A / B partition is restored to the firmware of the non-A / B partition before the upgrade based on the data partition, specifically as follows:

[0079] Verify the validity of all non-A / B partition firmware image files under the non-A / B firmware path in the upgrade metadata of the data partition. If all non-A / B partition firmware image files are valid, write all non-A / B partition firmware image files under the non-A / B firmware path in the upgrade metadata of the data partition to the corresponding non-A / B partition.

[0080] In step 213, the upgrade metadata in the preset location of the boot communication partition is cleared, and the Android system is booted normally according to the preset process.

[0081] In some embodiments, it is checked whether the firmware in the non-A / B partition is the same as the firmware in the non-A / B partition under the non-A / B firmware path before the upgrade in the data partition corresponding to the data partition name of the upgrade metadata. If they are the same, it means that the recovery has been completed, and step 211 is executed. If they are not the same, steps 212 to 213 are executed, specifically including the following steps (a) to (d).

[0082] (a) Set the recovery completion flag to "completed".

[0083] (b) Traverse the list of non-A / B partition image information before the upgrade in the upgrade metadata. For the non-A / B partition image information items traversed, perform the following steps (b-1) to (b-2).

[0084] (b-1) Read all the data in the partition corresponding to the image name of the non-A / B partition image information item as the corresponding non-A / B partition image data. Calculate the digital digest value of the non-A / B partition image data according to the digital digest algorithm type of the upgrade meta information. Compare the calculated digital digest value with the image digest value of the non-A / B partition image information item. If they are inconsistent, set the recovery completion mark to incomplete and execute step (c). Otherwise, execute step (b-2).

[0085] (b-2) If the corresponding non-A / B partition image information item is the last item in the non-A / B partition image information list, then execute step (c); otherwise, continue to traverse the next item in the non-A / B partition image information list.

[0086] (c) Determine whether the recovery completion mark is complete. If so, clear the upgrade metadata in the preset location of the boot communication partition and boot the Android system normally according to the preset process. Otherwise, proceed to step (d).

[0087] (d) Mount the partition corresponding to the data partition name of the upgrade meta information in read-only mode according to the data partition file system type of the upgrade meta information, and use the mounted partition as the data partition; verify the validity of all non-A / B partition firmware image files under the non-A / B firmware path of the upgrade meta information in the data partition. If all non-A / B partition firmware image files are valid, write all non-A / B partition firmware image files under the non-A / B firmware path of the upgrade meta information in the data partition to the corresponding non-A / B partition, and clear the upgrade meta information in the preset position in the boot communication partition. Boot the Android system normally according to the preset process, specifically including the following steps (d-1) to (d-3).

[0088] (d-1) Mount the partition corresponding to the data partition name in the upgrade metadata in read-only mode according to the data partition file system type of the upgrade metadata, and use the mounted partition as the data partition.

[0089] (d-2) Verify the validity of all non-A / B partition firmware image files under the non-A / B firmware path before the upgrade in the data partition. If all non-A / B partition firmware image files are valid, proceed to step (d-3); otherwise, prompt an error message and exit the firmware upgrade process.

[0090] Specifically, iterate through all non-A / B partition firmware image files under the non-A / B firmware path before the upgrade in the data partition. For each non-A / B partition firmware image file traversed, perform the following steps (d-2-1) to (d-2-3).

[0091] (d-2-1) Determine the partition name of the non-A / B partition corresponding to the firmware image file based on the file name prefix of the corresponding non-A / B partition firmware image file.

[0092] (d-2-2) Find the non-A / B partition image information item whose image name is the same as the partition name of the determined non-A / B partition from the non-A / B partition image information list before the upgrade of the upgrade meta information. This item is called the non-A / B partition image information item to be restored.

[0093] (d-2-3) Calculate the digital digest value of the corresponding non-A / B partition firmware image file according to the digital digest algorithm type of the upgrade meta information, and compare the calculated digital digest value with the image digest value of the current non-A / B partition image information item to be restored. If the comparison results are different, an error message is displayed and the firmware upgrade process is exited. If the comparison results are the same, if the non-A / B partition firmware image file is the last non-A / B partition firmware image file under the non-A / B firmware path before the upgrade in the data partition, then step (d-3) is executed; otherwise, continue to traverse the next non-A / B partition firmware image file under the non-A / B firmware path before the upgrade in the data partition.

[0094] (d-3) Traverse all non-A / B partition firmware image files under the non-A / B firmware path before the upgrade in the data partition. For each non-A / B partition firmware image file found, perform the following steps (d-3-1) to (d-3-3).

[0095] (d-3-1) Determine the partition name of the non-A / B partition corresponding to the firmware image file based on the file name prefix of the corresponding non-A / B partition firmware image file. This partition name is called the non-A / B partition to be recovered.

[0096] (d-3-2) Read all the data in the corresponding non-A / B partition firmware image file as image file data, and write the read image file data to the non-A / B partition to be restored.

[0097] (d-3-3) If the non-A / B partition firmware image file is the last non-A / B partition firmware image file under the non-A / B firmware path before the upgrade in the data partition upgrade metadata, then clear the upgrade metadata in the preset position in the boot communication partition and boot the Android system normally according to the preset process; otherwise, continue to traverse the next non-A / B partition firmware image file under the non-A / B firmware path before the upgrade in the data partition upgrade metadata.

[0098] In step 214, the upgrade completion marker and upgrade metadata of the non-A / B partition in the preset position in the boot communication partition are cleared, and the Android system is booted normally according to the preset process.

[0099] In step 215, the upgrade completion marker for the non-A / B partition is read from the boot communication partition. If the upgrade completion marker for the non-A / B partition is a preset magic number, the Android system is booted normally according to the preset process. If the upgrade completion marker for the non-A / B partition is not a preset magic number, the partition corresponding to the data partition name of the upgrade metadata is mounted, the mounted partition is used as the data partition, and the firmware of the non-A / B partition is upgraded based on the data partition. The preset magic number for the upgrade completion of the non-A / B partition is written into the boot communication partition, and the Android system is booted normally according to the preset process.

[0100] In some embodiments, firmware upgrades for non-A / B partitions are performed based on data partitions, specifically as follows:

[0101] Verify the validity of all non-A / B partition firmware image files under the non-A / B firmware path to be upgraded in the data partition upgrade metadata; if all non-A / B partition firmware image files are valid, write all non-A / B partition firmware image files under the non-A / B firmware path to be upgraded in the data partition upgrade metadata to the corresponding non-A / B partition.

[0102] In some embodiments, the system queries whether the current boot slot has been set with a successful boot flag (such as "successful") based on the Android A / B upgrade boot control information. If yes, step 214 is executed; otherwise, step 215 is executed, which specifically includes the following steps (a) to (c).

[0103] (a) Query whether the current boot slot has been set with a successful boot flag according to the Android A / B upgrade boot control information. If so, clear the non-A / B partition upgrade completion flag and upgrade metadata in the preset position of the boot communication partition, and boot the Android system normally according to the preset process. Otherwise, proceed to step (b).

[0104] (b) Read the non-A / B partition upgrade completion flag from the boot communication partition, and determine whether the read non-A / B partition upgrade completion flag is the preset non-A / B partition upgrade completion magic number. If so, boot the Android system normally according to the preset process; otherwise, proceed to step (c).

[0105] (c) Mount the partition corresponding to the data partition name of the upgrade metadata in read-only mode according to the data partition file system type of the upgrade metadata. Use the mounted partition as the data partition and verify the validity of all non-A / B partition firmware image files under the non-A / B firmware path to be upgraded in the upgrade metadata in the data partition. If all non-A / B partition firmware image files are valid, write all non-A / B partition firmware image files under the non-A / B firmware path to be upgraded in the upgrade metadata in the data partition to the corresponding non-A / B partition. Write the preset non-A / B partition upgrade completion magic number in the boot communication partition and boot the Android system normally according to the preset process. Specifically, it includes the following steps (c-1) to (c-3).

[0106] (c-1) Mount the partition corresponding to the data partition name in the upgrade metadata in read-only mode according to the data partition file system type of the upgrade metadata, and use the mounted partition as the data partition.

[0107] (c-2) Verify the validity of all non-A / B partition firmware image files under the non-A / B firmware path to be upgraded in the data partition upgrade metadata. If all non-A / B partition firmware image files are valid, proceed to step (c-3); otherwise, prompt an error message and exit the firmware upgrade process.

[0108] Specifically, iterate through all non-A / B partition firmware image files under the non-A / B firmware path to be upgraded in the data partition upgrade metadata. For the non-A / B partition firmware image files that have been traversed, perform the following steps (c-2-1) to (c-2-3).

[0109] (c-2-1) Determine the partition name of the non-A / B partition corresponding to the firmware image file based on the file name prefix of the corresponding non-A / B partition firmware image file.

[0110] (c-2-2) Find the non-A / B partition image information item whose image name is the same as the partition name of the determined non-A / B partition from the list of non-A / B partition image information items to be upgraded in the upgrade meta information. This item is called the current non-A / B partition image information item to be upgraded.

[0111] (c-2-3) Calculate the digital digest value of the corresponding non-A / B partition firmware image file according to the digital digest algorithm type of the upgrade metadata, and compare the calculated digital digest value with the image digest value of the current non-A / B partition image information item to be upgraded. If the comparison results are different, an error message is displayed and the firmware upgrade process is exited. If the comparison results are the same, if the non-A / B partition firmware image file is the last non-A / B partition firmware image file under the non-A / B firmware path to be upgraded in the upgrade metadata of the data partition, then step (c-3) is executed; otherwise, continue to traverse the next non-A / B partition firmware image file under the non-A / B firmware path to be upgraded in the upgrade metadata of the data partition.

[0112] (c-3) Traverse all non-A / B partition firmware image files under the non-A / B firmware path to be upgraded in the data partition upgrade metadata. For the traversed non-A / B partition firmware image files, perform the following steps (c-3-1) to (c-3-3).

[0113] (c-3-1) Determine the partition name of the non-A / B partition corresponding to the non-A / B partition firmware image file based on the file name prefix of the corresponding non-A / B partition firmware image file. This partition name is called the non-A / B partition to be upgraded.

[0114] (c-3-2) Read all the data in the corresponding non-A / B partition firmware image file as image file data, and write the read image file data to the non-A / B partition to be upgraded.

[0115] (c-3-3) If the non-A / B partition firmware image file is the last non-A / B partition firmware image file under the upgrade meta-information of the data partition, then write the preset non-A / B partition upgrade completion magic number to the preset position corresponding to the preset non-A / B partition upgrade completion mark in the boot communication partition, and boot the Android system normally according to the preset process; otherwise, continue to traverse the next non-A / B partition firmware image file under the upgrade meta-information of the data partition.

[0116] According to another aspect of the invention, Figure 3 This is a schematic diagram illustrating a device 300 for upgrading firmware according to an embodiment of the present invention. (Refer to...) Figure 3 The electronic device 300 includes a memory 302, a processor 304, and an executable program stored in the memory and executable on the processor. When the processor executes the executable program, it causes the electronic device to perform the steps of the firmware upgrade method described above.

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

[0118] In summary, the firmware upgrade method, electronic device, and storage medium provided by this invention utilize a dual-system upgrade engine to perform a dual-system upgrade based on the acquired dual-system firmware upgrade package. After the upgrade is completed, the system is restarted, and the upgraded bootloader firmware is booted. In the bootloader firmware, if the current boot slot is equal to the slot before the upgrade in the upgrade metadata, and the firmware in the non-dual-system partition is different from the non-dual-system partition firmware under the path of the non-dual-system firmware before the upgrade in the data partition corresponding to the data partition name in the upgrade metadata, then the partition corresponding to the data partition name in the upgrade metadata is mounted, the mounted partition is used as the data partition, and the firmware in the non-dual-system partition is restored to the non-dual-system partition firmware before the upgrade based on the data partition. The upgrade metadata in the preset position in the boot communication partition is cleared. The system boots the Android system normally according to the preset process. If an unexpected event occurs during the A / B firmware upgrade process, the upgrade can be restarted as needed after entering the Android system. If an unexpected event occurs during the upgrade of non-A / B firmware, the bootloader firmware itself can always boot after the system is powered on again. Therefore, the upgrade of non-A / B firmware can continue after power-on, avoiding the situation where the upgraded A / B firmware cannot boot due to incompatibility with the old non-A / B firmware. Thus, even when there is a dependency relationship between A / B partition firmware and non-A / B partition firmware, the reliability of firmware upgrade can still be guaranteed. In addition, there is no need to reserve partitions, but to directly use the existing read and write partitions in the Android system, saving storage space and improving storage space utilization.

[0119] 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 combined upgrade package, the combined upgrade package comprising a dual-system firmware upgrade package and a non-dual-system firmware upgrade sub-package compressed into one upgrade package; constructing upgrade meta-information based on information associated with the non-dual-system firmware upgrade sub-package, and writing the upgrade meta-information to a preset position of a boot communication partition, wherein the upgrade meta-information is generated according to a magic number, a digital digest algorithm type, a pre-upgrade slot, a data partition name, a data partition file system type, a pre-upgrade non-dual-system firmware path, a pre-upgrade non-dual-system partition image information list, a to-be-upgraded non-dual-system firmware path, a to-be-upgraded non-dual-system partition image information list, and a meta-information digital digest value; performing dual-system upgrade based on the dual-system firmware upgrade package by using a dual-system upgrade engine, and restarting the system after the upgrade is completed to guide the boot program firmware after the upgrade; in the boot program firmware, if the current boot slot is equal to the pre-upgrade slot of the upgrade meta-information, and the firmware in the non-dual-system partition is different from the non-dual-system partition firmware under the pre-upgrade non-dual-system firmware path of the upgrade meta-information in the data partition corresponding to the data partition name of the upgrade meta-information, then mounting the partition corresponding to the data partition name of the upgrade meta-information, taking the mounted partition as a data partition, and restoring the firmware in the non-dual-system partition to the pre-upgrade non-dual-system partition firmware based on the data partition; clearing the upgrade meta-information in the preset position of the boot communication partition, and normally booting the Android system according to a preset process; if the current boot slot is not equal to the pre-upgrade slot of the upgrade meta-information, and the current boot slot is not successfully set with a boot flag, then reading a non-dual-system partition upgrade completion flag from the boot communication partition; if the non-dual-system partition upgrade completion flag is a preset non-dual-system partition upgrade completion magic number, then normally booting the Android system according to a preset process; if the non-dual-system partition upgrade completion flag is not the preset non-dual-system partition upgrade completion magic number, then mounting the partition corresponding to the data partition name of the upgrade meta-information, taking the mounted partition as a data partition, and upgrading the non-dual-system partition firmware based on the data partition; and writing the preset non-dual-system partition upgrade completion magic number into the boot communication partition, and normally booting the Android system according to a preset process.

2. The method of claim 1, wherein, The method further comprises: if the current boot slot is equal to the pre-upgrade slot of the upgrade meta-information, and the firmware in the non-dual-system partition is the same as the non-dual-system partition firmware under the pre-upgrade non-dual-system firmware path of the upgrade meta-information in the data partition corresponding to the data partition name of the upgrade meta-information, then clearing the upgrade meta-information in the preset position of the boot communication partition, and normally booting the Android system according to a preset process.

3. The method of claim 1, wherein, The method further comprises: obtaining a to-be-upgraded upgrade package with a name corresponding to a standard dual-system upgrade package; If the non-dual-system firmware upgrade sub-package with the preset name is not included in the upgrade package to be upgraded, a dual-system upgrade engine performs dual-system upgrade based on the upgrade package to be upgraded, and restarts the system after the upgrade is completed to guide the starting of the boot program firmware after the upgrade; and If the non-dual-system firmware upgrade sub-package with the preset name is included in the upgrade package to be upgraded, the upgrade package to be upgraded is unpacked to obtain the dual-system firmware upgrade package and the non-dual-system firmware upgrade sub-package.

4. The method of claim 1, wherein, Further comprising: The non-dual-system firmware upgrade sub-package including all non-dual-system partition firmware image files to be upgraded is named according to a preset name; and The dual-system upgrade package of the Android standard and the non-dual-system firmware upgrade sub-package are compressed to obtain an upgrade package to be upgraded, and the upgrade package to be upgraded is named using the name of the dual-system upgrade package of the Android standard.

5. The method of claim 1, wherein, Further comprising: The magic number, the digital digest algorithm type, the slot before the upgrade, the data partition name, the data partition file system type, the non-dual-system firmware path before the upgrade, and the non-dual-system firmware path to be upgraded are determined; Based on the obtained non-dual-system firmware upgrade sub-package, a non-dual-system partition image information list before the upgrade and a non-dual-system partition image information list to be upgraded are determined; and The digital digest value of the meta information is calculated according to the digital digest algorithm type.

6. The method of claim 1, wherein, Further comprising: The legality of the upgrade meta information in the preset position of the boot communication partition is checked; and If the checking result is illegal, the Android system is normally guided to start according to a preset process.

7. The method of claim 1, wherein, The partition corresponding to the data partition name of the upgrade meta information is mounted, and the mounted partition is included as a data partition The partition corresponding to the data partition name of the upgrade meta information is mounted in a read-only mode according to the data partition file system type of the upgrade meta information, and the mounted partition is included as a data partition.

8. The method of claim 1, wherein, Based on the data partition, the firmware in the non-dual-system partition is restored to the non-dual-system partition firmware before the upgrade, including: The legality of all non-dual-system partition firmware image files under the non-dual-system firmware path before the upgrade of the upgrade meta information in the data partition is verified; and If all non-dual-system partition firmware image files are legal, all non-dual-system partition firmware image files under the non-dual-system firmware path before the upgrade of the upgrade meta information in the data partition are written into the corresponding non-dual-system partition.

9. The method of claim 1, wherein, Further comprising: If the current starting slot is not equal to the slot before the upgrade of the upgrade meta information, and the current starting slot has set a successful starting mark, the non-dual-system partition upgrade completion mark in the preset position of the boot communication partition and the upgrade meta information are cleared, and the Android system is normally guided to start according to a preset process.

10. The method of claim 1, wherein, Based on the data partition, the non-dual-system partition firmware is upgraded, including: The legality of all non-dual-system partition firmware image files under the non-dual-system firmware path to be upgraded of the upgrade meta information in the data partition is verified; and If all non-dual-system partition firmware image files are legal, all non-dual-system partition firmware image files under the non-dual-system firmware path to be upgraded of the upgrade meta information in the data partition are written into the corresponding non-dual-system partition.

11. The method of claim 1, wherein, Further comprising: reading Android dual-system upgrade start control information from the guide communication partition; and obtaining a current start slot from the Android dual-system upgrade start control information.

12. An electronic device, comprising: comprising: a memory configured to store an executable program; and a processor configured to execute the program so that the electronic device performs the method according to any one of claims 1 to 11.

13. A computer readable medium having stored thereon a computer program, characterized in that The computer program is executed by a processor to implement the method according to any one of claims 1 to 11.

Citation Information

Patent Citations

  • Version upgrade method and system

    CN106469069A

  • Vehicle, software upgrading method and device thereof, storage medium and vehicle-mounted controller

    CN117827238A