Over-the-air upgrade method and system for compressed firmware
By dividing the firmware into multiple partitions and compressing and differentially processing them on a partition-by-partition basis to generate differential upgrade files, the problems of large file sizes for compressed firmware differential upgrade files and excessive storage space consumption for power-down protection are solved, thus achieving efficient firmware upgrades and data protection.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2025-09-11
- Publication Date
- 2026-04-30
AI Technical Summary
In existing technologies, the differential upgrade files of compressed firmware are large in size, and the power-loss protection mechanism occupies a lot of storage space, which cannot effectively reduce the amount of backup space occupied.
The firmware is divided into multiple partitions, each containing one or more functional modules. The firmware is compressed and differentially processed on a partition-by-partition basis to generate differential upgrade files. During the upgrade, the compressed partitions are backed up and replaced, and relevant information is recorded to optimize the differential results.
It achieves optimal file size for differential upgrades, reduces the storage space requirements for power-loss protection, and ensures data integrity during firmware upgrades.
Smart Images

Figure CN2025120734_30042026_PF_FP_ABST
Abstract
Description
An over-the-air (OTA) upgrade method and system for compressed firmware Technical Field
[0001] This application relates to a method for firmware over-the-air (FOTA) upgrade of electronic devices. Background Technology
[0002] Firmware over-the-air (OTA) updates for electronic devices typically use differential methods. The advantage of differential update files is their small size, requiring less storage space on non-volatile memory (NDRAM). Some electronic devices with limited NDRAM capacity further compress the firmware to reduce NDRAM usage. However, differential updates with compressed firmware are less effective. The differential results for compressed firmware are usually much larger than those for uncompressed firmware, failing to accurately reflect the data changes. For example, a 3-byte difference between new and old firmware might result in a 1KB differential update file, while a difference between compressed new and compressed old firmware could generate a 1242KB file.
[0003] When electronic devices replace old firmware with new firmware, a power-loss protection mechanism is needed, which means backing up either the old or new firmware. Currently, the entire firmware (whether compressed or uncompressed) is backed up, which consumes a significant amount of non-volatile memory storage space. Technical issues
[0004] The technical problem this application aims to solve is how to perform over-the-air upgrades of compressed firmware using a differential method, thereby reducing the size of the differential upgrade file while implementing a power-loss protection mechanism and significantly reducing the amount of backup space required. Technical solutions
[0005] To address the aforementioned technical problems, this application proposes an over-the-air (OTA) firmware upgrade method, comprising the following steps: Step S1: During the firmware compilation stage, the firmware of the electronic device is divided into multiple partitions, each containing one or more functional modules; each partition has a substantially similar size after compression. Step S2: The firmware of the electronic device is compressed on a partition-by-partition basis to obtain compressed firmware; the compressed partitions are called compressed partitions, and relevant information of the compressed partitions is recorded during compression. All relevant information of the compressed partitions is stored in the header of the compressed firmware of the electronic device in the form of a load data table. Step S3: An upgrade file table is generated; the load data table of the new compressed firmware and the load data table of the old compressed firmware are differentially analyzed to obtain differential data of the load data table; the decompressed data of each partition in the new firmware and the decompressed data of the corresponding partition in the old firmware are differentially analyzed to obtain differential data of each partition; the above three parts are sequentially assembled into differential upgrade files of the new and old compressed firmware. Step S4: After the electronic device obtains the differential upgrade files of the new and old compressed firmware, it first upgrades the load data table, and then upgrades the firmware on a partition-by-partition basis.
[0006] Furthermore, in step S2, the relevant information of the compressed partition includes the running address and size of the uncompressed data in the compressed partition in the memory of the electronic device, the storage address and size of the compressed data in the non-volatile memory of the electronic device, and the checksum of the compressed data.
[0007] Furthermore, in step S3, the upgrade file table records which compressed partitions need to be upgraded and which compressed partitions do not need to be upgraded; if the functional modules in a certain compressed partition in the new and old compressed firmware remain unchanged, then the partition will not generate differential data; only if the functional modules in a certain compressed partition in the new and old compressed firmware change will the partition generate differential data.
[0008] Furthermore, in step S3, if the new compressed firmware adds functional modules compared to the old compressed firmware, then the new compressed firmware adds a new compressed partition to store the added functional modules.
[0009] Further, in step S4, the upgrade loading data table specifically includes the following sub-steps: Step S410: Back up the loading data table of the old compressed firmware. Step S411: Restore the loading data table of the new compressed firmware based on the loading data table of the old compressed firmware and the differential data of the loading data table. Step S412: Replace the loading data table of the old compressed firmware with the loading data table of the new compressed firmware. Step S413: Delete the backed-up loading data table of the old compressed firmware.
[0010] Further, step S4, specifically the firmware upgrade per compressed partition, includes the following sub-steps: Step S420: Parse the upgrade file table in the differential upgrade file to determine which compressed partitions need to be upgraded and which do not. Step S421: Back up the data of the old compressed partitions. Step S422: Decompress the data of the old compressed partitions to obtain the data of that partition in the old firmware. Step S423: Restore the data of that partition in the new firmware based on the data of that partition in the old firmware and the differential data of that partition. Step S424: Compress the data of that partition in the new firmware to obtain the data of the new compressed partition. Step S425: Replace the data of the old compressed partition with the data of the new compressed partition. Step S426: Delete the backed-up data of the old compressed partition. Repeat steps S421 to S426 until the upgrade operation of all compressed partitions that need to be upgraded is completed.
[0011] Further, step S4, specifically the firmware upgrade per compressed partition, includes the following sub-steps: Step S430: Parse the upgrade file table in the differential upgrade file to determine which compressed partitions need to be upgraded and which do not. Step S431: Decompress the data of the old compressed partition to obtain the data of that partition in the old firmware. Step S432: Restore the data of that partition in the new firmware based on the data of that partition in the old firmware and the differential data of that partition. Step S433: Compress the data of that partition in the new firmware to obtain the data of the new compressed partition. Step S434: Back up the data of the new compressed partition. Step S435: Replace the data of the old compressed partition with the data of the new compressed partition. Step S436: Delete the backed-up data of the new compressed partition. Repeat steps S431 to S436 until the upgrade operation of all compressed partitions that need to be upgraded is completed.
[0012] Further, in step S4, the firmware upgrade based on compressed partitions specifically includes the following sub-steps: Step S440: Parse the upgrade file table in the differential upgrade file to determine which compressed partitions need to be upgraded and which do not. Simultaneously, determine if the compressed partitions requiring upgrade have increased in size and whether there are other compressed partitions following them. If the size of the compressed partition M requiring upgrade has increased, and there is another compressed partition N following M, proceed to step S441. Step S441: Back up the data of the old compressed partition M, and simultaneously back up the data of the first partition of the old compressed partition N based on the size difference Δ between the new and old compressed partitions M; partition N is the partition immediately following partition M; Δ > 0. Step S442: Decompress the data of the old compressed partition M to obtain the data of partition M in the old firmware. Step S443: Reconstruct the data of partition M in the new firmware based on the data of partition M in the old firmware and the differential data of partition M. Step S444: Compress the data of partition M in the new firmware to obtain the data of the new compressed partition M. Step S445: Replace the data in the old compressed partition M with the data in the new compressed partition M; this process will also overwrite the data of the beginning of the old compressed partition N by a size Δ. Step S446: Determine if compressed partition N needs to be upgraded. If not, proceed to step S447; if so, combine the remaining data of the old compressed partition N after removing the beginning Δ size with the backed-up data of the beginning Δ size of the old compressed partition N to form the complete data of the old compressed partition N. Then proceed to step S440, changing the compressed partition M mentioned in step S440 to N, and the mentioned compressed partition N to the next compressed partition of N. Step S447: Offset all data after the new compressed partition M by a size Δ; at this point, the data after the new compressed partition M consists of: the remaining data of the old compressed partition N after removing the beginning Δ size, and the data of each of the old compressed partitions after the old compressed partition N; after this step, a free space of size Δ is formed after the new compressed partition M and before all the offset data. Step S448: Fill the free space of size Δ with the first Δ-sized data from the backed-up old compressed partition N; at this point, the data in the old compressed partition N is complete. Step S449: Delete the data from the backed-up old compressed partition M and the first Δ-sized data from the old compressed partition N. Repeat steps S441 to S449 until the upgrade operation for all compressed partitions requiring upgrade is completed.
[0013] Further, in step S4, the firmware upgrade based on compressed partitions specifically includes the following sub-steps: Step S450: Parse the upgrade file table in the differential upgrade file to determine which compressed partitions need to be upgraded and which do not; simultaneously determine whether the compressed partitions that need to be upgraded have increased in size, and whether there are other compressed partitions following the compressed partitions that need to be upgraded; if it is found that the size of the compressed partition M that needs to be upgraded has increased, and there is another compressed partition N following the compressed partition M, then proceed to step S451. Step S451: Decompress the data of the old compressed partition M to obtain the data of partition M in the old firmware. Step S452: Restore the data of partition M in the new firmware based on the data of partition M in the old firmware and the differential data of partition M. Step S453: Compress the data of partition M in the new firmware to obtain the data of the new compressed partition M. Step S454: Back up the data of the new compressed partition M, and simultaneously back up the data of the first Δ-sized part of the old compressed partition N based on the size difference Δ between the new and old compressed partitions M; partition N is the partition immediately following partition M; Δ > 0. Step S455: Replace the data in the old compressed partition M with the data in the new compressed partition M; during this process, the data at the beginning of the old compressed partition N (by a factor of Δ) will also be overwritten, making the data in the old compressed partition N incomplete. Step S456: Determine if compressed partition N needs to be upgraded. If not, proceed to step S457; if so, combine the remaining data after removing the beginning of the Δ from the old compressed partition N with the data at the beginning of the backed-up old compressed partition N to form the complete data of the old compressed partition N. Then proceed to step S450, changing the compressed partition M mentioned in step S450 to N, and the mentioned compressed partition N to the next compressed partition of N. Step S457: Offset all data after the new compressed partition M by a factor of Δ; thus creating a free space of a factor of Δ after the new compressed partition M and before all the offset data. Step S458: Fill the free space of the factor of Δ with the data at the beginning of the backed-up old compressed partition N; at this point, the data in the old compressed partition N is complete. Step S459: Delete the data in the newly compressed partition M (backed up) and the first few bytes of data (Δ size) in the old compressed partition N. Repeat steps S451 to S459 until the upgrade operation for all compressed partitions that need to be upgraded is complete.
[0014] This application also proposes an over-the-air firmware upgrade system, including a partitioning unit, a partition compression unit, a partition differential unit, and a partition upgrade unit. The partitioning unit is used to divide the firmware of an electronic device into multiple partitions during the firmware compilation stage, each partition containing one or more functional modules; each partition has a substantially similar size after compression. The partition compression unit is used to compress the firmware of the electronic device on a partition-by-partition basis to obtain compressed firmware; the compressed partitions are called compressed partitions, and relevant information of the compressed partitions is recorded during compression; all relevant information of the compressed partitions is stored in the header of the compressed firmware of the electronic device in the form of a load data table. The partition differential unit is used to generate an upgrade file table; it also differentially divides the load data table of the new compressed firmware and the load data table of the old compressed firmware to obtain differential data of the load data table; it also differentially divides the decompressed data of each partition in the new firmware and the decompressed data of the corresponding partition in the old firmware to obtain differential data of each partition; and it assembles the above three parts sequentially into differential upgrade files of the new and old compressed firmware. The partition upgrade unit is used by the electronic device to first upgrade the loading data table after obtaining the differential upgrade files of the new and old compressed firmware, and then upgrade the firmware in units of compressed partitions. Beneficial effects
[0015] The technical effect achieved by this application is that by compressing firmware in units of partitions, generating differential data in units of partitions, and upgrading firmware in units of compressed partitions, the differential effect is optimized, while the storage space occupied by power-off protection during the upgrade process is small. Attached Figure Description
[0016] Figure 1 is a flowchart illustrating the over-the-air (OTA) firmware upgrade method proposed in this application.
[0017] Figure 2 is a schematic diagram showing the relationship between firmware, partitions, and functional modules of an electronic device.
[0018] Figure 3 is a schematic diagram showing the relationship between firmware, partitions, compressed firmware, and compressed partitions in an electronic device.
[0019] Figure 4 is a schematic diagram of the changes between the new and old compressed firmware and the assembly of differential upgrade files.
[0020] Figure 5 is a schematic diagram of the changes between the new and old compressed firmware and the assembly of differential upgrade files.
[0021] Figure 6 is a schematic diagram of the specific process of upgrading and loading the data table in step S4.
[0022] Figure 7 is a schematic diagram of the specific process of upgrading the firmware in step S4 by unit of compressed partition.
[0023] Figure 8 is a schematic diagram of the specific process of upgrading the firmware in step S4 by unit of compressed partition.
[0024] Figure 9 is a schematic diagram of the specific process of upgrading firmware in step S4 by unit of compressed partition.
[0025] Figure 10 is a schematic diagram of the fourth example of upgrading firmware by compressed partition in step S4.
[0026] Figure 11 is a schematic diagram of the structure of the over-the-air firmware upgrade system proposed in this application.
[0027] The diagram shows the following labels: Partition division unit 1, partition compression unit 2, partition differential unit 3, and partition upgrade unit 4. Embodiments of the present invention
[0028] Please refer to Figure 1. The over-the-air firmware upgrade method proposed in this application includes the following steps.
[0029] Step S1: During the firmware compilation stage, the firmware of the compiled electronic device is divided into functional modules, and all functional modules are stored in multiple partitions. The size of each partition meets the following condition: each partition has a basically the same size after compression (within a small difference), for example, the change is within 10%, or further limited to within 5% or 3%. In this way, the firmware of the electronic device is divided into multiple partitions, and each partition contains one or more functional modules. The sum of all partitions is the complete firmware of the electronic device. As an example, as shown in Figure 2, the complete firmware of an electronic device is divided into 5 partitions, and each partition stores one or more functional modules.
[0030] This step involves partitioning the firmware during compilation, assigning functional modules to each partition. The advantages of this partitioning and module storage are as follows: First, this application will subsequently generate differential upgrade files on a partition-by-partition basis. If the functional modules in a partition remain unchanged, that partition will not contain differential data. Second, this application will subsequently perform firmware upgrades and power-loss protection on a partition-by-partition basis, backing up compressed partition data. To minimize backup space and conserve storage resources, as many partitions as possible are needed. However, since the sizes of various functional modules may differ, partitioning each module individually is unreasonable. This application places multiple small functional modules in one partition and large functional modules in a separate partition, ensuring that the compressed size of each partition is roughly the same, thus saving backup space. Third, if a new functional module needs to be added, it is achieved by adding a new partition and storing the new functional module in the new partition. The new partition is added to the end of the old firmware and will not affect the original partitions. The differential upgrade file for the new partition is the data of the new partition, achieving optimal differential performance.
[0031] Step S2: Compress the firmware of the electronic device in units of partitions to obtain compressed firmware. Specifically, each partition is compressed, and the compressed partition is called a compressed partition. During compression, relevant information of the compressed partition is recorded, including the running address (physical address) and size of the uncompressed data in the compressed partition in the electronic device's memory, the storage address and size of the compressed data in the electronic device's non-volatile memory, and the checksum of the compressed data. All compressed partitions are concatenated to form a complete compressed firmware of the electronic device. The relevant information of all compressed partitions is stored in the header of the complete compressed firmware of the electronic device in the form of a load table. The load table is used during system startup to decompress and load the data of the compressed partitions one by one into the physical addresses for execution.
[0032] As an example, as shown in Figure 3, the uncompressed firmware of an electronic device is processed through step S2 to obtain compressed firmware. The compressed firmware consists of a header loading data table and subsequent compressed partitions. The uncompressed firmware and the compressed firmware are mutually corresponding; each partition in the uncompressed firmware corresponds one-to-one with each compressed partition in the compressed firmware.
[0033] Step S3: Generate an upgrade file table, which records which compressed partitions of the electronic device need to be upgraded and which do not compared to the old compressed firmware. Parse the loading data tables of the new and old compressed firmware of the electronic device, and perform differential analysis on the loading data tables of the new and old compressed firmware to obtain the differential data of the loading data table. Decompress each compressed partition that needs to be upgraded in the new compressed firmware and the corresponding compressed partition in the old compressed firmware to obtain the decompressed data of each partition that needs to be upgraded in the new firmware and the corresponding decompressed data of the corresponding partition in the old firmware. Perform differential analysis on the decompressed data of each partition that needs to be upgraded in the new firmware and the corresponding decompressed data of the corresponding partition in the old firmware to obtain the differential data of each partition that needs to be upgraded. Assemble the upgrade file table, the differential data of the loading data table, and the differential data of all partitions that need to be upgraded sequentially into a complete differential upgrade file of the new and old compressed firmware.
[0034] As a first example, as shown in Figure 4, if only functional module A in a certain compressed partition changes in the new and old compressed firmware, then the differential upgrade files of the new and old compressed firmware will only contain the differential data of the upgrade file table, the load data table, and functional module A. The differential data of functional module A is also the differential data of the partition where functional module A is located.
[0035] As a second example, as shown in Figure 5, if the new compressed firmware only adds one functional module X compared to the old compressed firmware, then the new compressed firmware adds a new compressed partition to store the new functional module X. The differential upgrade files of the new and old compressed firmware only contain the upgrade file table, the differential data of the load data table, and the data of the new functional module X. The data of the new functional module X is the differential data of the new partition where the new functional module X is located.
[0036] As shown in Figures 4 and 5, if the functional modules in a certain compressed partition remain unchanged between the new and old compressed firmware, then that partition does not need to be upgraded and therefore no differential data will be generated. Only when the functional modules in a certain compressed partition change between the new and old compressed firmware will that partition need to be upgraded and differential data will be generated.
[0037] Step S4: After the electronic device obtains the differential upgrade files of the new and old compressed firmware, it first upgrades the load data table, that is, it upgrades the load data table from the old compressed firmware to the load data table of the new compressed firmware. Then, it upgrades the firmware on a per-compressed-partition basis (equivalent to upgrading on a per-partition basis), that is, it upgrades a specific compressed partition of the old compressed firmware (hereinafter referred to as the old compressed partition) to the corresponding compressed partition of the new compressed firmware (hereinafter referred to as the new compressed partition). When upgrading the firmware on a per-compressed-partition basis, a backup is also performed on a per-partition basis to achieve power loss protection.
[0038] As an example, as shown in Figure 6, the upgrade loading data table specifically includes the following sub-steps.
[0039] Step S410: Back up the loading data table of the old compressed firmware.
[0040] Step S411: Reconstruct the loading data table of the new compressed firmware based on the loading data table of the old compressed firmware and the differential data of the loading data table.
[0041] Step S412: Replace the loading data table of the old compressed firmware with the loading data table of the new compressed firmware.
[0042] Step S413: Delete the load data table of the backed-up old compressed firmware.
[0043] As a first example, as shown in Figure 7, the firmware upgrade based on compressed partitions specifically includes the following sub-steps.
[0044] Step S420: Parse the upgrade file table in the differential upgrade file to determine which compressed partitions need to be upgraded and which compressed partitions do not need to be upgraded.
[0045] Step S421: Back up the data of the old compressed partition (i.e., a compressed partition in the old compressed firmware that needs to be upgraded).
[0046] Step S422: Decompress the data in the old compressed partition to obtain the data of that partition in the old firmware.
[0047] Step S423: Restore the data of the partition in the new firmware based on the data of the partition in the old firmware and the differential data of the partition.
[0048] Step S424: Compress the data of the partition in the new firmware to obtain the data of the new compressed partition (i.e., the compressed partition in the new compressed firmware).
[0049] Step S425: Replace the data in the old compressed partition with the data in the new compressed partition.
[0050] Step S426: Delete the data from the backed-up old compressed partition.
[0051] Repeat steps S421 to S426 until all compressed partitions requiring upgrades are completed. During this process, even if the electronic device experiences a power outage or restart, because the old compressed partition has been backed up, the electronic device can still obtain the data from the old compressed partition after a power outage or restart, generate the data of the new compressed partition based on the differential data of that partition, and replace and overwrite the data of the old compressed partition. This achieves power outage protection during the firmware upgrade process.
[0052] As a second example, as shown in Figure 8, the firmware upgrade based on compressed partitions specifically includes the following sub-steps.
[0053] Step S430: Parse the upgrade file table in the differential upgrade file to determine which compressed partitions need to be upgraded and which compressed partitions do not need to be upgraded.
[0054] Step S431: Decompress the data in the old compressed partition (i.e., a compressed partition in the old compressed firmware that needs to be upgraded) to obtain the data of that partition in the old firmware.
[0055] Step S432: Restore the data of the partition in the new firmware based on the data of the partition in the old firmware and the differential data of the partition.
[0056] Step S433: Compress the data of the partition in the new firmware to obtain the data of the new compressed partition (i.e., the compressed partition in the new compressed firmware).
[0057] Step S434: Back up the data in the new compressed partition.
[0058] Step S435: Replace the data in the old compressed partition with the data in the new compressed partition.
[0059] Step S436: Delete the data from the newly compressed partition that was backed up.
[0060] Repeat steps S431 to S436 until all compressed partitions requiring upgrades are completed. During this process, even if the electronic device experiences a power outage or restart, the data in the new compressed partition can still be obtained after a power outage or restart because the new compressed partition has been backed up. This allows the electronic device to directly replace and overwrite the data in the old compressed partition, thus achieving power outage protection during the firmware upgrade process.
[0061] The two examples shown in Figures 7 and 8 demonstrate that electronic devices without batteries or with low battery power can undergo firmware upgrades anytime, anywhere, without worrying about the device becoming damaged due to firmware upgrades, even in the event of an unexpected shutdown or restart.
[0062] In step S4, when upgrading firmware by compressed partition, a special case arises: the new compressed partition may be larger than the old one. In this case, replacing the data in the old compressed partition with the data in the new one will partially replace the data in subsequent old compressed partitions, preventing them from upgrading properly and causing the entire firmware upgrade to fail. Therefore, this application, when upgrading a compressed partition, pre-determines whether it will overwrite the data in subsequent old compressed partitions. If so, the overwritten data in subsequent old compressed partitions is backed up along with the old compressed partition (or the new compressed partition).
[0063] Assume that the compressed partition M in the new and old compressed firmware has changed, and the new compressed partition M is larger than the old compressed partition M, with compressed partition N immediately following compressed partition M. Let Δ represent the difference between the data size of the new compressed partition M and the data size of the old compressed partition M, where Δ > 0.
[0064] As a third example, as shown in Figure 9, the firmware upgrade based on compressed partitions specifically includes the following sub-steps.
[0065] Step S440: Parse the upgrade file table in the differential upgrade file to determine which compressed partitions need to be upgraded and which do not. Simultaneously, check if the compressed partitions that need upgrading have increased in size and whether there are other compressed partitions following them. If the compressed partition M that needs upgrading has increased in size and there is another compressed partition N following it, proceed to step S441. If the compressed partition M that needs upgrading has increased in size but there are no other compressed partitions following it, proceed to step S421 as shown in Figure 7. If the compressed partition M that needs upgrading has not increased in size, also proceed to step S421 as shown in Figure 7.
[0066] Step S441: Back up the data of the old compressed partition M, and simultaneously back up the data of the old compressed partition N, which is Δ in size, based on the size difference Δ between the new and old compressed partitions M. Partition N is the partition immediately following partition M. Δ > 0.
[0067] Step S442: Decompress the data in the old compressed partition M to obtain the data in partition M in the old firmware.
[0068] Step S443: Reconstruct the data of partition M in the new firmware based on the data of partition M in the old firmware and the differential data of partition M.
[0069] Step S444: Compress the data in partition M in the new firmware to obtain the data of the newly compressed partition M.
[0070] Step S445: Replace the data in the old compressed partition M with the data in the new compressed partition M. This process also overwrites the first Δ-sized data in the old compressed partition N, making the data in the old compressed partition N incomplete.
[0071] Step S446: Determine whether compressed partition N needs to be upgraded. If not, proceed to step S447. If so, combine the remaining data after removing the first Δ size from the old compressed partition N with the first Δ size data from the backup of the old compressed partition N to form the complete data of the old compressed partition N. Then proceed to step S440, change the compressed partition M mentioned in step S440 to N, and change the mentioned compressed partition N to the next compressed partition of N.
[0072] Step S447: Offset all data after the new compressed partition M by a value of Δ. At this point, the data after the new compressed partition M consists of: the remaining data from the old compressed partition N after removing the first Δ values, and the data from all the old compressed partitions following the old compressed partition N. After this step is completed, a free space of Δ size is formed after the new compressed partition M and before all the offset data.
[0073] Step S448: Fill the free space of size Δ with the first Δ-sized data from the backed-up old compressed partition N. At this point, the data in the old compressed partition N is complete.
[0074] Step S449: Delete the data in the backed-up old compressed partition M and the data with the first Δ size in the old compressed partition N.
[0075] As a fourth example, as shown in Figure 10, the firmware upgrade based on compressed partitions specifically includes the following sub-steps.
[0076] Step S450: Parse the upgrade file table in the differential upgrade file to determine which compressed partitions need to be upgraded and which do not. Simultaneously, determine if the compressed partition requiring upgrade has increased in size and whether there are other compressed partitions following it. If the compressed partition M requiring upgrade has increased in size and there is another compressed partition N following it, proceed to step S451. If the compressed partition M requiring upgrade has increased in size but there are no other compressed partitions following it, proceed to step S431 as shown in Figure 8. If the compressed partition M requiring upgrade has not increased in size, also proceed to step S431 as shown in Figure 8.
[0077] Step S451: Decompress the data of the old compressed partition M to obtain the data of partition M in the old firmware.
[0078] Step S452: Reconstruct the data of partition M in the new firmware based on the data of partition M in the old firmware and the differential data of partition M.
[0079] Step S453: Compress the data of partition M in the new firmware to obtain the data of the new compressed partition M.
[0080] Step S454: Back up the data of the new compressed partition M, and simultaneously back up the data of the old compressed partition N, which is Δ in size, based on the size difference Δ between the new and old compressed partitions M. Partition N is the partition immediately following partition M. Δ > 0.
[0081] Step S455: Replace the data in the old compressed partition M with the data in the new compressed partition M. This process also overwrites the first Δ-sized data in the old compressed partition N, making the data in the old compressed partition N incomplete.
[0082] Step S456: Determine whether compressed partition N needs to be upgraded. If not, proceed to step S457. If so, combine the remaining data after removing the first Δ size from the old compressed partition N with the first Δ size data from the backup of the old compressed partition N to form the complete data of the old compressed partition N. Then proceed to step S450, change the compressed partition M mentioned in step S450 to N, and change the mentioned compressed partition N to the next compressed partition of N.
[0083] Step S457: Offset all data after the new compressed partition M backward by a value of Δ. This creates a free space of value Δ after the new compressed partition M and before all the data to be offset.
[0084] Step S458: Fill the free space of size Δ with the first Δ-sized data from the backed-up old compressed partition N. At this point, the data in the old compressed partition N is complete.
[0085] Step S459: Delete the data in the newly compressed partition M and the data with the first Δ size in the old compressed partition N.
[0086] The two examples given in Figures 9 and 10 effectively address the problem of how to upgrade a compressed partition when the size of the new compressed partition is larger than that of the old compressed partition.
[0087] Please refer to Figure 11. The over-the-air firmware upgrade system proposed in this application includes a partitioning unit 1, a partition compression unit 2, a partition differential unit 3, and a partition upgrade unit 4. The system shown in Figure 11 corresponds to the method shown in Figure 1.
[0088] The partitioning unit 1 is used to divide the firmware of an electronic device into multiple partitions during the firmware compilation stage. Each partition contains one or more functional modules. Each partition has a substantially the same size after compression.
[0089] The partition compression unit 2 is used to compress the firmware of the electronic device on a partition-by-partition basis to obtain compressed firmware. During compression, relevant information about the compressed partitions is recorded, including the memory address and size of the uncompressed data in the compressed partition, the storage address and size of the compressed data in the non-volatile memory of the electronic device, and the checksum of the compressed data. All relevant information about the compressed partitions is stored in the header of the complete compressed firmware of the electronic device in the form of a load data table. The header of the complete compressed firmware of the electronic device also contains an upgrade file table, which records which compressed partitions need to be upgraded and which do not.
[0090] The partition differential unit 3 is used to generate an upgrade file table, recording which compressed partitions need to be upgraded and which do not; it is also used to differentially analyze the loading data table of the new compressed firmware and the loading data table of the old compressed firmware to obtain differential data of the loading data table; it is also used to differentially analyze the decompressed data of each partition in the new firmware and the decompressed data of the corresponding partition in the old firmware to obtain differential data of each partition. The upgrade file table, the differential data of the loading data table, and the differential data of all partitions are sequentially assembled into a complete differential upgrade file of the new and old compressed firmware.
[0091] The partition upgrade unit 4 is used to first upgrade the loading data table, that is, to upgrade the loading data table of the old compressed firmware to the loading data table of the new compressed firmware; and then upgrade the firmware by compressed partition, that is, to upgrade a certain compressed partition of the old compressed firmware to the corresponding compressed partition of the new compressed firmware.
[0092] Compared with the prior art, the over-the-air firmware upgrade method proposed in this application has the following technical innovations and beneficial effects.
[0093] First, this application compresses the firmware of the electronic device and stores it in the non-volatile memory of the electronic device, thereby reducing the storage space of the firmware.
[0094] Second, this application divides the firmware of the electronic device into multiple partitions according to functional modules, and compresses the firmware on a partition-by-partition basis. Regardless of whether a functional module is changed or added, it will only affect the data in one partition and will not change or affect the data in other partitions, thus achieving the purpose of isolation.
[0095] Third, this application generates differential data between uncompressed new and old partitions on a partition-by-partition basis, resulting in efficient differential results and reducing the size of the differential upgrade files for the new and old compressed firmware. For example, if the new firmware differs from the old firmware by only 3 bytes, the generated differential upgrade file is only 1KB in size, accurately reflecting the data changes of the functional modules.
[0096] Fourth, this application upgrades firmware on a per-compressed-partition basis. Each upgrade's power-loss protection only requires backing up the data of one compressed partition, reducing the backup space requirements for power-loss protection. Regarding the special case where upgrading one compressed partition might corrupt the data of a subsequent compressed partition, this application effectively solves this technical challenge by predicting in advance whether the new compressed partition will corrupt the older compressed partitions. If corruption is likely, the corrupted portion is backed up along with the existing data.
[0097] The above are merely preferred embodiments of this application and are not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A method for over-the-air upgrade of compressed firmware, characterized by, The method comprises the following steps; Step S1: dividing firmware of an electronic device into multiple partitions in a compiling firmware stage, each partition containing one or more functional modules; each partition having substantially the same size after compression; Step S2: compressing the firmware of the electronic device in units of the partitions to obtain compressed firmware of the electronic device; The compressed partition is referred to as a compressed partition, and relevant information of the compressed partition is recorded during compression, and the relevant information of all compressed partitions is stored in a header of the compressed firmware of the electronic device in the form of a loading data table; Step S3: generating an upgrade file table; differentiating the loading data table of the new compressed firmware from the loading data table of the old compressed firmware to obtain differential data of the loading data table; differentiating decompressed data of each partition in the new firmware from decompressed data of a corresponding partition in the old firmware to obtain differential data of each partition; The above three parts are sequentially assembled into a differential upgrade file of the new and old compressed firmware; Step S4: after the electronic device obtains the differential upgrade file of the new and old compressed firmware, the loading data table is upgraded first, and then the firmware is upgraded in units of the compressed partitions.
2. The method of over-the-air upgrade of a compressed firmware according to claim 1, characterized in that, In the step S2, the relevant information of the compressed partition includes a running address and a size of non-compressed data in the compressed partition in a memory of the electronic device, a storage address and a size of compressed data in a non-volatile memory of the electronic device, and a check value of the compressed data.
3. The method of over-the-air upgrade of a compressed firmware according to claim 1, characterized in that, In the step S3, the upgrade file table records which compressed partitions need to be upgraded and which compressed partitions do not need to be upgraded; if a functional module in a certain compressed partition in the new and old compressed firmware has no change, the partition does not generate differential data; only if the functional module in the certain compressed partition in the new and old compressed firmware has a change, the partition generates differential data.
4. The method of over-the-air upgrade of a compressed firmware according to claim 1, characterized in that, In the step S3, if the new compressed firmware increases a functional module compared with the old compressed firmware, a new compressed partition of the new compressed firmware is used to store the added functional module.
5. The method of over-the-air upgrade of a compressed firmware according to claim 1, characterized in that, In the step S4, the upgrade loading data table specifically comprises the following sub-steps; Step S410: backing up the loading data table of the old compressed firmware; Step S411: restoring the loading data table of the new compressed firmware according to the loading data table of the old compressed firmware and the differential data of the loading data table; Step S412: replacing the loading data table of the old compressed firmware with the loading data table of the new compressed firmware; Step S413: deleting the backed-up loading data table of the old compressed firmware.
6. The method of over-the-air upgrade of a compressed firmware according to claim 2, characterized in that, In the step S4, the firmware is upgraded in units of the compressed partitions, specifically comprising the following sub-steps; Step S420: analyzing the upgrade file table in the differential upgrade file to determine which compressed partitions need to be upgraded and which compressed partitions do not need to be upgraded; Step S421: backing up data of the old compressed partition; Step S422: decompressing the data of the old compressed partition to obtain data of the partition in the old firmware; Step S423: restoring data of the partition in the new firmware according to the data of the partition in the old firmware and the differential data of the partition; Step S424: compressing the data of the partition in the new firmware to obtain data of the new compressed partition; Step S425: replacing the data of the old compressed partition with the data of the new compressed partition; Step S426: deleting the backup data of the old compressed partition; Repeat steps S421 to S426 until the upgrade operation of all compressed partitions that need to be upgraded is completed.
7. The method of over-the-air upgrade of a compressed firmware according to claim 2, characterized in that, The step S4, the unit of compressed partition to upgrade firmware specifically includes the following sub-steps; Step S430: parsing the upgrade file table in the differential upgrade file to determine which compressed partition needs to be upgraded and which compressed partition does not need to be upgraded; Step S431: decompressing the data of the old compressed partition to obtain the data of the partition in the old firmware; Step S432: restoring the data of the partition in the new firmware according to the data of the partition in the old firmware and the differential data of the partition; Step S433: compressing the data of the partition in the new firmware to obtain the data of the new compressed partition; Step S434: backing up the data of the new compressed partition; Step S435: replacing the data of the old compressed partition with the data of the new compressed partition; Step S436: deleting the backup data of the new compressed partition; Repeat steps S431 to S436 until the upgrade operation of all compressed partitions that need to be upgraded is completed.
8. The method of over-the-air upgrade of a compressed firmware according to claim 2, characterized in that, The step S4, the unit of compressed partition to upgrade firmware specifically includes the following sub-steps; Step S440: parsing the upgrade file table in the differential upgrade file to determine which compressed partition needs to be upgraded and which compressed partition does not need to be upgraded, and judging whether the compressed partition that needs to be upgraded is larger and whether there are other compressed partitions after the compressed partition that needs to be upgraded; If it is found that the volume of the compressed partition M that needs to be upgraded is larger, and there is a compressed partition N after the compressed partition M, then step S441 is entered; Step S441: backing up the data of the old compressed partition M, and backing up the data of the old compressed partition N in front of the Δ size according to the volume difference Δ between the new and old compressed partitions M; Partition N is a partition immediately after partition M; Δ>0; Step S442: decompressing the data of the old compressed partition M to obtain the data of partition M in the old firmware; Step S443: restoring the data of partition M in the new firmware according to the data of partition M in the old firmware and the differential data of partition M; Step S444: compressing the data of partition M in the new firmware to obtain the data of the new compressed partition M; Step S445: replacing the data of the old compressed partition M with the data of the new compressed partition M; in this process, the data of the old compressed partition N in front of the Δ size will also be overwritten; Step S446: judging whether the compressed partition N needs to be upgraded, if not, then step S447 is entered; if yes, then the data of the old compressed partition N after removing the data in front of the Δ size is combined with the backup data of the old compressed partition N in front of the Δ size to obtain the complete data of the old compressed partition N, and then step S440 is entered, in which the mentioned compressed partition M is changed to N, and the mentioned compressed partition N is changed to the next compressed partition of N; Step S447: Shift all data after the new compressed partition M backward by Δ size; at this time, the data after the new compressed partition M is the data of the old compressed partition N after removing the front Δ size, and the data of each old compressed partition after the old compressed partition N; After this step is performed, an idle space of Δ size is formed before all the data after the new compressed partition M is shifted; Step S448: Fill the front Δ size of the data of the backup old compressed partition N into the idle space of Δ size; at this time, the data of the old compressed partition N becomes complete; Step S449: Delete the data of the backup old compressed partition M and the front Δ size of the data of the old compressed partition N; Repeat steps S441 to S449 until the upgrade operation of all compressed partitions that need to be upgraded is completed.
9. The method of over-the-air upgrade of a compressed firmware according to claim 2, characterized in that, In the step S4, the upgrading the firmware in the compressed partition unit specifically includes the following sub-steps; Step S450: Analyze the upgrade file table in the differential upgrade file to determine which compressed partitions need to be upgraded and which compressed partitions do not need to be upgraded; at the same time, determine whether the compressed partition that needs to be upgraded is larger and whether there is another compressed partition after the compressed partition that needs to be upgraded; If it is found that the volume of the compressed partition M that needs to be upgraded is larger, and there is a compressed partition N after the compressed partition M, then enter step S451; Step S451: Decompress the data of the old compressed partition M to obtain the data of the partition M in the old firmware; Step S452: Restore the data of the partition M in the new firmware according to the data of the partition M in the old firmware and the differential data of the partition M; Step S453: Compress the data of the partition M in the new firmware to obtain the data of the new compressed partition M; Step S454: Backup the data of the new compressed partition M, and backup the front Δ size of the data of the old compressed partition N according to the volume difference Δ between the new and old compressed partitions M; The partition N is a partition immediately after the partition M; Δ>0; Step S455: Replace the data of the old compressed partition M with the data of the new compressed partition M; in this process, the front Δ size of the data of the old compressed partition N is also overwritten, which makes the data of the old compressed partition N incomplete; Step S456: Determine whether the compressed partition N needs to be upgraded, and if not, enter step S457; If yes, combine the data of the old compressed partition N after removing the front Δ size and the backup front Δ size of the data of the old compressed partition N to form the complete data of the old compressed partition N, and then enter step S450, change the mentioned compressed partition M in step S450 to N, and change the mentioned compressed partition N to the next compressed partition of N; Step S457: Shift all data after the new compressed partition M backward by Δ size; thereby forming an idle space of Δ size before all the data after the new compressed partition M is shifted; Step S458: Fill the front Δ size of the data of the backup old compressed partition N into the idle spaces of Δ size; at this time, the data of the old compressed partition N becomes complete; Step S459: deleting the data of the backup new compressed partition M and the data of the front Δ size of the old compressed partition N; Repeat steps S451 to S459 until the upgrade operation of all compressed partitions that need to be upgraded is completed.
10. An over-the-air upgrade system for compressing firmware, characterized by, The partition division unit, the partition compression unit, the partition difference unit, and the partition upgrade unit are included. The partition division unit is configured to divide the firmware of the electronic device into a plurality of partitions during a firmware compiling stage, each of the partitions containing one or more functional modules; Each of the partitions has substantially the same size after compression; The partition compression unit is configured to compress the firmware of the electronic device in units of the partitions to obtain compressed firmware of the electronic device; The compressed partition is referred to as a compressed partition after compression, and relevant information of the compressed partition is recorded during compression; The relevant information of all the compressed partitions is stored in the header of the compressed firmware of the electronic device in the form of a loading data table; The partition difference unit is configured to generate an upgrade file table, and to further perform a difference between the loading data table of the new compressed firmware and the loading data table of the old compressed firmware to obtain difference data of the loading data table, and to further perform a difference between the decompressed data of each partition in the new firmware and the decompressed data of the corresponding partition in the old firmware to obtain difference data of each partition; The three parts are further sequentially assembled into a difference upgrade file of the new and old compressed firmware; The partition upgrade unit is configured to, after the electronic device obtains the difference upgrade file of the new and old compressed firmware, first upgrade the loading data table, and then upgrade the firmware in units of the compressed partitions.
Citation Information
Patent Citations
Over-the-air firmware differential upgrading method and device for electronic equipment
CN110874239A
Differential packet generation method, differential packet generation equipment and upgrading method
CN113721967A
Method and system for realizing incremental upgrading of intelligent electric meter
CN115712447A
Over-the-air upgrading method and system for compressed firmware
CN119556962A
Method of updating firmware and device for using the method
US20200233659A1