Over-the-air upgrading method and system for compressed firmware
By dividing the firmware into multiple partitions and compressing and differentiating in units of partitions, the problem of excessive volume of compressed firmware differential upgrade files is solved, and the storage space occupied by power-down protection is effectively reduced during the firmware upgrade process.
Patent Information
- Application Number
- CN202411494863.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-24
- Publication Date
- 2025-03-04
AI Technical Summary
When the prior art performs differential upgrade of compressed firmware, the differential result is too large, and the power-down protection mechanism occupies a lot of storage space, which cannot effectively reduce the use of backup space.
The firmware is divided into multiple partitions. Each partition has basically the same size after compression. It adopts compression and differential methods in partitions to generate differential upgrade files, and firmware upgrades in compressed partitions to achieve power-down protection.
Through compression and differential in units of partitions, the volume of differential upgrade files is reduced, and the difference effect is optimized. At the same time, during the upgrade process, the storage space occupied by power-down protection is greatly reduced.
Smart Images

Figure CN119556962A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to a method for firmware over-the-air (FOTA, Firmware Over-the-Air, also known as over-the-air firmware upgrade) of an electronic device. Background Art
[0002] The firmware of electronic devices is generally upgraded over the air using a differential method, which has the advantage that the differential upgrade file is small in size and occupies less storage space in the non-volatile memory. The capacity of the non-volatile memory of some electronic devices is limited, and the firmware is compressed and stored to further reduce the storage space occupied by the non-volatile memory. However, the effect of using differential upgrades on compressed firmware is not good. The differential results of compressed firmware are usually much larger than those of uncompressed firmware, and cannot truly reflect the data changes of the firmware. For example, the new firmware and the old firmware only have 3 bytes of change, and the generated differential upgrade file is only 1KB in size; while the differential upgrade file generated by the compressed new firmware and the compressed old firmware is 1242KB in size.
[0003] When replacing old firmware with new firmware, electronic devices need to implement a power-off protection mechanism, that is, back up the old firmware or the new firmware. Currently, the entire firmware (whether compressed firmware or uncompressed firmware) is backed up, which will take up more storage space of non-volatile memory. Summary of the invention
[0004] The technical problem to be solved by the present application is how to perform an over-the-air upgrade of compressed firmware using a differential method, thereby reducing the differential upgrade file size while implementing a power-off protection mechanism and significantly reducing the backup space occupied.
[0005] To solve the above technical problems, the present application proposes an over-the-air upgrade method for compressed firmware, comprising the following steps. Step S1: In the firmware compilation stage, the firmware of the electronic device is divided into multiple partitions, each partition contains one or more functional modules; each partition has substantially the same size after compression. Step S2: The firmware of the electronic device is compressed in units of partitions to obtain the compressed firmware of the electronic device; the compressed partition is called a compressed partition, and the relevant information of the compressed partition is recorded during compression, and the relevant information of all compressed partitions is stored in the header of the compressed firmware of the electronic device in the form of a loading data table. Step S3: Generate an upgrade file table; differentiate 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; differentiate the decompressed data of each partition in the new firmware from the decompressed data of the corresponding partition in the old firmware to obtain differential data of each partition; assemble the above three parts in sequence 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 loading data table, and then upgrades the firmware in units of compressed partitions.
[0006] Furthermore, in step S2, the relevant information of the compressed partition includes the running address and size of the non-compressed 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 check value 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 compressed partition in the new and old compressed firmware are unchanged, the partition does not generate differential data; only if the functional modules in a compressed partition in the new and old compressed firmware are changed, the partition will generate differential data.
[0008] Furthermore, in step S3, if the new compressed firmware has an additional functional module compared to the old compressed firmware, the new compressed firmware adds a new compressed partition to store the additional functional module.
[0009] Further, in the step S4, the upgrading 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, in the step S4, the firmware upgrade in units of compressed partitions specifically 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 compressed partitions do not need to be upgraded. Step S421: Back up the data of the old compressed partition. Step S422: Decompress the data of the old compressed partition to obtain the data of the partition in the old firmware. 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. Step S424: Compress the data of the 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, in the step S4, the firmware upgrade in units of compressed partitions specifically 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 compressed partitions do not need to be upgraded. Step S431: Decompress the data of the old compressed partition to obtain the data of the partition in the old firmware. 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. Step S433: Compress the data of the 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 in units of 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 compressed partitions do not need to be upgraded, and at the same time determine whether the compressed partition to be upgraded has become larger, and whether there are other compressed partitions behind the compressed partition to be upgraded; if it is found that the volume of the compressed partition M to be upgraded has become larger, and there is a compressed partition N behind the compressed partition M, then enter step S441. Step S441: Back up the data of the old compressed partition M, and at the same time back up the data of the front Δ size of the old compressed partition N according to the volume difference Δ between the new and old compressed partitions M; partition N is a partition immediately behind 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: Restore 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: 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 of the old compressed partition M with the data of the new compressed partition M; in this process, the data of the front Δ size of the old compressed partition N will also be overwritten. Step S446: Determine whether the compressed partition N needs to be upgraded. If not, proceed to step S447; if it is needed, combine the remaining data after the old compressed partition N removes the front Δ size and the backed-up data of the front Δ size of the old compressed partition N into the complete data of the old compressed partition N, and then proceed to step S440, change the compressed partition M mentioned in step S440 to N, and change the compressed partition N mentioned to the next compressed partition of N. Step S447: Shift all the data after the new compressed partition M backward by Δ size; at this time, the data after the new compressed partition M is: the remaining data after the old compressed partition N removes the front Δ size, and the data of each old compressed partition after 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 data to be shifted. Step S448: Fill the free space of the backup old compressed partition N with the data of the size Δ at the front; at this time, the data of the old compressed partition N becomes complete. Step S449: Delete the backup data of the old compressed partition M and the data of the size Δ at the front 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.
[0013] Furthermore, in step S4, the firmware upgrade in units of 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 compressed partitions do not need to be upgraded; at the same time, determine whether the compressed partition to be upgraded has become larger, and whether there are other compressed partitions behind the compressed partition to be upgraded; if it is found that the volume of the compressed partition M to be upgraded has become larger, and there is a compressed partition N behind 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 based on 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: Back up the data of the new compressed partition M, and at the same time, back up the data of the front Δ size of the old compressed partition N based on the volume difference Δ between the new and old compressed partitions M; partition N is a partition immediately behind partition M; Δ>0. Step S455: Replace the data of the old compressed partition M with the data of the new compressed partition M; in the process, the data of the front Δ size of the old compressed partition N will also be overwritten, which makes the data of the old compressed partition N incomplete. Step S456: Determine whether the compressed partition N needs to be upgraded. If not, proceed to step S457; if it is needed, combine the remaining data of the old compressed partition N after removing the front Δ size and the backed-up data of the front Δ size of the old compressed partition N into the complete data of the old compressed partition N, and then proceed to step S450, change the compressed partition M mentioned in step S450 to N, and change the compressed partition N mentioned to the next compressed partition of N. Step S457: Shift all the data after the new compressed partition M backward by Δ size; thereby forming a free space of Δ size after the new compressed partition M and before all the data to be shifted. Step S458: Fill the backed-up data of the front Δ size of the old compressed partition N into the free space of Δ size; at this time, the data of the old compressed partition N becomes complete. Step S459: Delete the backed-up data of the 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 the compressed partitions that need to be upgraded is completed.
[0014] The present application also proposes an over-the-air upgrade system for compressed firmware, including a partition division unit, a partition compression unit, a partition difference unit, and a partition upgrade unit. The partition division unit is used to divide the firmware of the electronic device into multiple partitions during the firmware compilation stage, each partition contains one or more functional modules; each partition has substantially the same size after compression. The partition compression unit is used to compress the firmware of the electronic device in units of partitions to obtain the compressed firmware of the electronic device; the compressed partition is called a compressed partition, and the relevant information of the compressed partition is recorded during compression; the relevant information of all 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 used to generate an upgrade file table; the loading data table of the new compressed firmware and the loading data table of the old compressed firmware are also differentiated to obtain differential data of the loading 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 also differentiated to obtain differential data of each partition; the above three parts are also assembled in sequence into differential upgrade files of the new and old compressed firmware;. The partition upgrade unit is used for upgrading the loading data table first and then upgrading the firmware in units of compressed partitions after the electronic device obtains the differential upgrade file of the new and old compressed firmware.
[0015] The technical effect achieved by the present application is: by compressing the firmware in units of partitions, generating differential data in units of partitions, and upgrading the firmware in units of compressed partitions, the optimal differential effect is achieved, and at the same time, the storage space occupied by power-off protection during the upgrade process is small. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 It is a flowchart of the over-the-air upgrade method of compressed firmware proposed in this application.
[0017] Figure 2 It is a schematic diagram of the relationship between the firmware, partitions, and functional modules of an electronic device.
[0018] Figure 3 It is a schematic diagram of the relationship between the firmware, partitions, compressed firmware, and compressed partitions of electronic devices.
[0019] Figure 4 It is a schematic diagram of the changes between the new and old compressed firmware and the assembly of differential upgrade files.
[0020] Figure 5 This is a schematic diagram of the changes between the new and old compressed firmware and the assembly of the differential upgrade file.
[0021] Figure 6 It is a specific flow chart of upgrading and loading the data table in step S4.
[0022] Figure 7This is a specific flowchart of the first example of upgrading the firmware in units of compressed partitions in step S4.
[0023] Figure 8 This is a specific flowchart of the second example of upgrading the firmware in units of compressed partitions in step S4.
[0024] Fig. 9 This is a specific flowchart of the third example of upgrading the firmware in units of compressed partitions in step S4.
[0025] Fig.10 This is a specific flowchart of the fourth example of upgrading the firmware in units of compressed partitions in step S4.
[0026] Fig.11 It is a structural diagram of the over-the-air upgrade system of compressed firmware proposed in this application.
[0027] Explanation of the reference numerals in the figure: partition division unit 1, partition compression unit 2, partition difference unit 3, partition upgrade unit 4. DETAILED DESCRIPTION
[0028] See also Figure 1 The method for over-the-air upgrading of compressed firmware proposed in this application includes the following steps.
[0029] Step S1: During the firmware compilation stage, the firmware of the electronic device compiled is divided according to the functional modules, and all the functional modules are stored in multiple partitions. The size of each partition satisfies: each partition has substantially the same size after compression (with little difference), for example, the variation range 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, each of which contains one or more functional modules. The sum of all partitions is the complete firmware of the electronic device. As an example, Figure 2 As shown, the complete firmware of an electronic device is divided into five partitions, each of which stores one or more functional modules.
[0030] In this step, a certain number of partitions are divided when the firmware is compiled, and the functional modules are assigned to the partitions. The benefits of this partitioning and storing functional modules are as follows. First, this application will subsequently generate differential upgrade files in units of partitions. If the functional modules in a partition do not change, then there is no differential data for the partition. Second, this application will subsequently perform firmware upgrades and power-off protection in units of partitions, and the compressed partition data is backed up. In order to make the backup space as small as possible and save storage resources, the partitions need to be as many as possible. However, since the sizes of each functional module may be different, it is unreasonable to divide the partitions separately for each functional module. This application places multiple small functional modules in one partition, and large functional modules are placed separately in a partition, so that the compressed size of each partition is basically the same, thereby saving backup space. Third, if a new functional module is 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 at the end of the old firmware and will not affect the original partition. The differential upgrade file of the new partition is the data of the new partition, which meets the optimal differential effect.
[0031] Step S2: compress the firmware of the electronic device in units of partitions to obtain the compressed firmware of the electronic device. Specifically, each partition is compressed, and the compressed partition is called a compressed partition. During compression, the relevant information of the compressed partition is recorded, including the running address (running physical address) and size of the non-compressed 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, the check value of the compressed data, etc. All compressed partitions are spliced together to form a complete compressed firmware of the electronic device, and the relevant information of all compressed partitions is stored in the form of a load data table (loadtable) in the header of the complete compressed firmware of the electronic device. The load data table is used when the system is started, and the data of the compressed partition is decompressed and loaded into the physical address one by one for operation by parsing the load data table.
[0032] As an example, Figure 3 As shown, after step S2, the uncompressed firmware of an electronic device obtains the compressed firmware, which is composed of the loading data table at the head and the subsequent compressed partitions. The uncompressed firmware corresponds to the compressed firmware, and each partition in the uncompressed firmware corresponds one-to-one to each compressed partition in the compressed firmware.
[0033] Step S3: Generate an upgrade file table, which records which compressed partitions of the new compressed firmware of the electronic device need to be upgraded and which compressed partitions do not need to be upgraded compared with the old compressed firmware. Parse the loading data table of the new compressed firmware of the electronic device and the loading data table of the old compressed firmware, and differentiate 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. 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 decompressed data of the corresponding partition in the old firmware. Differentiate the decompressed data of each partition that needs to be upgraded in the new firmware and the 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 into a complete differential upgrade file of the new and old compressed firmware in sequence.
[0034] As a first example, Figure 4 As shown, if only the function module A in a certain compressed partition has changed between the new and old compressed firmware, the differential upgrade file of the new and old compressed firmware only includes the upgrade file table, the differential data of the loading data table, and the differential data of the function module A. The differential data of the function module A is also the differential data of the partition where the function module A is located.
[0035] As a second example, Figure 5 As shown, if the new compressed firmware only adds one functional module X compared to the old compressed firmware, then the new compressed firmware adds a compressed partition to store the newly added functional module X, and the differential upgrade file between the new and old compressed firmware only contains the upgrade file table, differential data of the loading data table, and data of the newly added functional module X. The data of the newly added functional module X is the differential data of the newly added partition where the newly added functional module X is located.
[0036] Depend on Figure 4 , Figure 5 It can be seen that if the function modules in a certain compressed partition in the new and old compressed firmware are unchanged, the partition does not need to be upgraded and no differential data is generated. Only if the function modules in a certain compressed partition in the new and old compressed firmware are changed, the partition needs to be upgraded to generate differential data.
[0037] Step S4: After the electronic device obtains the differential upgrade file of the new and old compressed firmware, it first upgrades the loading data table, that is, upgrades from the loading data table of the old compressed firmware to the loading data table of the new compressed firmware. Then, the firmware is upgraded in units of compressed partitions (equivalent to units of partitions), that is, from a certain 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 in units of compressed partitions, backup is also performed in units of compressed partitions to achieve power-off protection.
[0038] As an example, Figure 6 As shown, the upgrading and loading of the data table specifically includes the following sub-steps.
[0039] Step S410: backing up the loading data table of the old compressed firmware.
[0040] 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.
[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 backed-up loading data table of the old compressed firmware.
[0043] As a first example, Figure 7 As shown, the firmware upgrade in units of compressed partitions specifically includes the following sub-steps.
[0044] Step S420: parsing 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: backing up the data of the old compressed partition (ie, a compressed partition in the old compressed firmware that needs to be upgraded).
[0046] Step S422: decompress the data of the old compressed partition to obtain the data of the partition in the old firmware.
[0047] Step S423: restore 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.
[0048] Step S424: compress the data of the partition in the new firmware to obtain the data of the new compressed partition (ie, the compressed partition in the new compressed firmware).
[0049] Step S425: Replace the data of the old compressed partition with the data of the new compressed partition.
[0050] Step S426: Delete the backed-up data of the old compressed partition.
[0051] Repeat steps S421 to S426 until the upgrade operation of all compressed partitions that need to be upgraded is completed. In this process, even if the electronic device loses power or restarts, since the old compressed partition is backed up, the electronic device can still obtain the data of the old compressed partition after power failure or restart, and generate the data of the new compressed partition according to the differential data of the partition, and complete the replacement and overwriting of the data of the old compressed partition, that is, the power failure protection during the firmware upgrade process is realized.
[0052] As a second example, Figure 8 As shown, the firmware upgrade in units of compressed partitions specifically includes the following sub-steps.
[0053] Step S430: parsing 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 of the old compressed partition (ie, a compressed partition in the old compressed firmware that needs to be upgraded) to obtain the data of the partition in the old firmware.
[0055] Step S432: restore 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.
[0056] Step S433: compress the data of the partition in the new firmware to obtain the data of the new compressed partition (ie, the compressed partition in the new compressed firmware).
[0057] Step S434: Back up the data of the new compressed partition.
[0058] Step S435: Replace the data of the old compressed partition with the data of the new compressed partition.
[0059] Step S436: Delete the backed-up data of the new compressed partition.
[0060] Repeat steps S431 to S436 until the upgrade operation of all compressed partitions to be upgraded is completed. In this process, even if the electronic device loses power or restarts, since the new compressed partition is backed up, the electronic device can still obtain the data of the new compressed partition after power failure or restart, and directly replace and overwrite the data of the old compressed partition, that is, power failure protection is achieved during the firmware upgrade process.
[0061] Figure 7 and Figure 8The two examples given allow electronic devices without batteries or with low batteries to perform firmware upgrades anytime and anywhere. Even if an unexpected shutdown or restart occurs, there is no need to worry about the device being damaged due to the firmware upgrade.
[0062] There is a special situation when upgrading the firmware in units of compressed partitions in step S4. It may happen that the volume of the new compressed partition is larger than the volume of the old compressed partition. At this time, when the data of the old compressed partition is replaced by the data of the new compressed partition, the data of the old compressed partition behind will be partially replaced, resulting in that the old compressed partition behind cannot be upgraded normally, and the entire firmware upgrade will fail. For this reason, when upgrading a certain compressed partition, the present application determines in advance whether the data of the old compressed partition behind will be overwritten. If so, the overwritten data of the old compressed partition behind will be backed up together when backing up the old compressed partition (or backing up the new compressed partition).
[0063] Assume that the compressed partition M in the new and old compressed firmware changes, and the new compressed partition M becomes larger than the old compressed partition M, and the compressed partition N follows the compressed partition M. Δ represents the difference between the data size of the new compressed partition M and the data size of the old compressed partition M, Δ>0.
[0064] As a third example, Fig. 9 As shown, the firmware upgrade in units of 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, and determine whether the compressed partition that needs to be upgraded has become larger, and whether there are other compressed partitions behind the compressed partition that needs to be upgraded. If it is found that the size of the compressed partition M that needs to be upgraded has become larger, and there is a compressed partition N behind the compressed partition M, then go to step S441. If it is found that the size of the compressed partition M that needs to be upgraded has become larger, but there are no other compressed partitions behind the compressed partition M, then go to Figure 7 If it is found that the size of the compressed partition M to be upgraded has not increased, the process also proceeds to step S421. Figure 7 Step S421 shown.
[0066] Step S441: back up the data of the old compressed partition M, and at the same time back up the data of the front Δ size of the old compressed partition N according to the volume difference Δ between the new and old compressed partitions M. Partition N is a partition immediately behind partition M. Δ>0.
[0067] Step S442: decompress the data of the old compressed partition M to obtain the data of the partition M in the old firmware.
[0068] Step S443: restore 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.
[0069] Step S444: compress the data of partition M in the new firmware to obtain the data of new compressed partition M.
[0070] Step S445: Replace the data of the old compressed partition M with the data of the new compressed partition M. In this process, the data of the front Δ size of the old compressed partition N will also be overwritten, which makes the data of the old compressed partition N incomplete.
[0071] Step S446: Determine whether the compressed partition N needs to be upgraded. If not, proceed to step S447. If necessary, combine the remaining data after removing the first Δ size from the old compressed partition N and the first Δ size data of the backed-up old compressed partition N into the complete data of the old compressed partition N, and then proceed to step S440, change the compressed partition M mentioned in step S440 to N, and change the compressed partition N mentioned to the next compressed partition of N.
[0072] Step S447: All data after the new compressed partition M are shifted backward by the size Δ. At this time, the data after the new compressed partition M is: the data remaining after the old compressed partition N is removed from the front Δ size, and the data of each old compressed partition after the old compressed partition N. After this step is completed, a free space of the size Δ is formed after the new compressed partition M and before all the data to be shifted.
[0073] Step S448: Fill the free space of the size Δ with the front data of the backed-up old compressed partition N. At this point, the data of the old compressed partition N becomes complete.
[0074] Step S449: Delete the backed-up data of the old compressed partition M and the data of the previous size Δ of the old compressed partition N.
[0075] As a fourth example, Fig.10 As shown, the firmware upgrade in units of 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. At the same time, determine whether the compressed partition that needs to be upgraded has become larger, and whether there are other compressed partitions behind the compressed partition that needs 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 a compressed partition N behind the compressed partition M, then go to step S451. If it is found that the size of the compressed partition M that needs to be upgraded has increased, but there are no other compressed partitions behind the compressed partition M, then go to Figure 8If it is found that the size of the compressed partition M to be upgraded has not increased, the process also proceeds to step S431. Figure 8 Step S431 shown.
[0077] Step S451: decompress the data of the old compressed partition M to obtain the data of the partition M in the old firmware.
[0078] Step S452: restore 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.
[0079] Step S453: compress the data of partition M in the new firmware to obtain the data of new compressed partition M.
[0080] Step S454: back up the data of the new compressed partition M, and at the same time back up the data of the previous Δ size of the old compressed partition N according to the volume difference Δ between the new and old compressed partitions M. Partition N is a partition immediately behind partition M. Δ>0.
[0081] Step S455: Replace the data of the old compressed partition M with the data of the new compressed partition M. In this process, the data of the front Δ size of the old compressed partition N will also be overwritten, which makes the data of the old compressed partition N incomplete.
[0082] Step S456: Determine whether the compressed partition N needs to be upgraded. If not, proceed to step S457. If necessary, combine the remaining data after removing the first Δ size from the old compressed partition N and the first Δ size data of the backed-up old compressed partition N into the complete data of the old compressed partition N, and then proceed to step S450, change the compressed partition M mentioned in step S450 to N, and change the compressed partition N mentioned to the next compressed partition of N.
[0083] Step S457: All data after the newly compressed partition M are shifted backward by the size Δ, so that a free space of the size Δ is formed after the newly compressed partition M and before all the data to be shifted.
[0084] Step S458: fill the free space of the size Δ with the front data of the backed-up old compressed partition N. At this time, the data of the old compressed partition N becomes complete.
[0085] Step S459: Delete the backed-up data of the new compressed partition M and the data of the first Δ size of the old compressed partition N.
[0086] Fig. 9 and Fig.10 The two examples given better solve the problem of how to upgrade a compressed partition when the volume of the new compressed partition is larger than the volume of the old compressed partition.
[0087] See also Fig.11 The compressed firmware over-the-air upgrade system proposed in this application includes a partition division unit 1, a partition compression unit 2, a partition difference unit 3, and a partition upgrade unit 4. Fig.11 The system shown corresponds to Figure 1 The method shown.
[0088] The partition division unit 1 is used to divide the firmware of the electronic device into multiple partitions during the firmware compilation stage, each partition contains one or more functional modules; each partition has substantially the same size after compression.
[0089] The partition compression unit 2 is used to compress the firmware of the electronic device in units of partitions to obtain the compressed firmware of the electronic device. During compression, the relevant information of the compressed partition is recorded, including the running address and size of the non-compressed 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, the check value of the compressed data, etc. The relevant information of all compressed partitions is stored in the form of a loading data table in the header of the complete compressed firmware of the electronic device. There is also an upgrade file table in the header of the complete compressed firmware of the electronic device, which records which compressed partitions need to be upgraded and which compressed partitions do not need to be upgraded.
[0090] The partition difference unit 3 is used to generate an upgrade file table to record which compressed partitions need to be upgraded and which compressed partitions do not need to be upgraded; it is also used to differentiate 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 differentiate 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, upgrade from the loading data table of the old compressed firmware to the loading data table of the new compressed firmware; then upgrade the firmware in units of compressed partitions, that is, upgrade from a compressed partition of the old compressed firmware to the corresponding compressed partition of the new compressed firmware.
[0092] Compared with the prior art, the method for over-the-air upgrading of compressed firmware proposed in this application has the following technical innovations and beneficial effects.
[0093] First, the present 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, the present application divides the firmware of the electronic device into multiple partitions according to the functional modules, and compresses the firmware in partitions. No matter 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, the present application generates differential data between the new and old uncompressed partitions in units of partitions, obtains efficient differential results, and reduces the size of the differential upgrade file of the new and old compressed firmware. For example, the new firmware and the old firmware only have 3 bytes of change, and the generated differential upgrade file is only 1KB in size, which truly reflects the data changes of the functional modules.
[0096] Fourth, the present application upgrades the firmware in units of compressed partitions, and each upgraded power-off protection only needs to back up the data of one compressed partition, which reduces the backup space requirements for power-off protection. In view of the special situation that the data of the subsequent compressed partition will be destroyed when a compressed partition is upgraded, the present application effectively solves this technical difficulty by judging in advance whether the new compressed partition will destroy the subsequent old compressed partition, and backing up the destroyed part together when it will be destroyed.
[0097] The above are only preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should all be included in the protection scope of the present application.
Claims
1. A method for over-the-air upgrading of compressed firmware, characterized in that: The method comprises the following steps: Step S1: in the firmware compiling stage, the firmware of the electronic device is divided into a plurality of partitions, each partition including one or more functional modules; each partition has substantially the same size after compression; Step S2: compressing the firmware of the electronic device in units of partitions to obtain compressed firmware of the electronic device; The compressed partition is called a compressed partition. The relevant information of the compressed partition is recorded during compression. All the relevant information of the compressed partition is stored in the header of the compressed firmware of the electronic device in the form of a loaded data table. Step S3: Generate an upgrade file table; differentiate 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; differentiate the decompressed data of each partition in the new firmware from the decompressed data of the corresponding partition in the old firmware to obtain differential data of each partition; Assemble the above three parts in sequence into the 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, it first upgrades the loading data table and then upgrades the firmware in units of compressed partitions.
2. The method for over-the-air upgrading of compressed firmware according to claim 1, characterized in that: In step S2, the relevant information of the compressed partition includes the running address and size of the non-compressed 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 check value of the compressed data.
3. The method for upgrading compressed firmware over the air according to claim 1, characterized in that: 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 compressed partition in the new and old compressed firmware are unchanged, the partition does not generate differential data; only if the functional modules in a compressed partition in the new and old compressed firmware are changed, the partition will generate differential data.
4. The method for over-the-air upgrading of compressed firmware according to claim 1, characterized in that: In step S3, if the new compressed firmware has an additional functional module compared to the old compressed firmware, the new compressed firmware adds a new compressed partition to store the additional functional module.
5. The method for over-the-air upgrading of compressed firmware according to claim 1, characterized in that: In step S4, the upgrading and loading of the data table specifically includes 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: Delete the backed-up loading data table of the old compressed firmware.
6. The method for over-the-air upgrading of compressed firmware according to claim 2, characterized in that: In the step S4, the firmware upgrade in units of compressed partitions specifically includes the following sub-steps: Step S420: parsing 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 the data of the old compressed partition; Step S422: decompress the data of the old compressed partition to obtain the data of the partition in the old firmware; Step S423: restore 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 S424: compress the data of the partition in the new firmware to obtain data of a new compressed partition; Step S425: replace the data of the old compressed partition with the data of the new compressed partition; Step S426: deleting the backed-up data of the old compressed partition; Repeat step S421 to step S426 until the upgrade operation of all compressed partitions that need to be upgraded is completed.
7. The method for over-the-air upgrading of compressed firmware according to claim 2, characterized in that: In the step S4, the firmware upgrade in units of compressed partitions specifically includes the following sub-steps: Step S430: parsing 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 S431: decompress 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: compress the data of the partition in the new firmware to obtain data of a new compressed partition; Step S434: backing 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: deleting the backed-up data of the new compressed partition; Repeat step S431 to step S436 until the upgrade operation of all compressed partitions that need to be upgraded is completed.
8. The method for upgrading compressed firmware over the air according to claim 2, characterized in that: In the step S4, the firmware upgrade in units of compressed partitions specifically includes the following sub-steps: Step S440: parsing 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, and determining whether the compressed partitions that need to be upgraded have become larger and whether there are other compressed partitions behind the compressed partitions that need to be upgraded; If it is found that the size of the compressed partition M to be upgraded becomes larger, and there is a compressed partition N behind the compressed partition M, then go to step S441; Step S441: back up the data of the old compressed partition M, and at the same time back up the data of the front Δ size of the old compressed partition N according to the volume difference Δ between the new and old compressed partitions M; Partition N is a partition immediately following partition M; Δ>0; Step S442: decompress the data of the old compressed partition M to obtain the data of the partition M in the old firmware; Step S443: restore 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 the partition M in the new firmware to obtain the data of the new compressed partition M; Step S445: replace the data of the old compressed partition M with the data of the new compressed partition M; in this process, the data of the size Δ at the front of the old compressed partition N will also be overwritten; Step S446: Determine whether the compressed partition N needs to be upgraded. If not, proceed to step S447; if it needs to be upgraded, combine the remaining data after removing the front Δ size of the old compressed partition N and the backed-up front Δ size of the old compressed partition N into 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 compressed partition N mentioned to the next compressed partition of N; Step S447: all data after the new compressed partition M is shifted backward by the size Δ; at this time, the data after the new compressed partition M is: the remaining data after the old compressed partition N is removed by the size Δ at the front, and the data of each old compressed partition after the old compressed partition N; After this step is completed, a free space of size Δ is formed after the newly compressed partition M and before all the data to be offset; Step S448: fill the front Δ-sized data of the backed-up old compressed partition N into the free space of the Δ-sized data; at this time, the data of the old compressed partition N becomes complete; Step S449: deleting the backed-up data of the old compressed partition M and the data of the front Δ size of the old compressed partition N; Repeat step S441 to step S449 until the upgrade operation of all compressed partitions that need to be upgraded is completed.
9. The method for upgrading compressed firmware over the air according to claim 2, wherein: In the step S4, the firmware upgrade in units of compressed partitions specifically includes the following sub-steps: Step S450: parsing 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, determining whether the compressed partition to be upgraded becomes larger and whether there are other compressed partitions behind the compressed partition to be upgraded; If it is found that the size of the compressed partition M to be upgraded becomes larger, and there is a compressed partition N behind the compressed partition M, then go to 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 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 S453: compress the data of the 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 at the same time back up the data of the front Δ size of the old compressed partition N according to the volume difference Δ between the new and old compressed partitions M; Partition N is a partition immediately following 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 data of the front Δ size of the old compressed partition N will also be overwritten, which makes the data of the old compressed partition N incomplete; Step S456: Determine whether the compressed partition N needs to be upgraded, if not, proceed to step S457; If necessary, the remaining data after removing the front Δ size from the old compressed partition N and the backed-up data of the front Δ size of the old compressed partition N are combined into the complete data of the old compressed partition N, and then the process goes to step S450, the compressed partition M mentioned in step S450 is changed to N, and the compressed partition N mentioned is changed to the next compressed partition of N; Step S457: all data after the newly compressed partition M is shifted backward by a size of Δ, so that a free space of a size of Δ is formed after the newly compressed partition M and before all data to be shifted; Step S458: fill the front Δ-sized data of the backed-up old compressed partition N into the free space of the Δ-sized data; at this time, the data of the old compressed partition N becomes complete; Step S459: deleting the backed-up data of the new compressed partition M and the data of the front Δ size of the old compressed partition N; Repeat step S451 to step S459 until the upgrade operation of all compressed partitions that need to be upgraded is completed.
10. An over-the-air upgrade system for compressed firmware, characterized in that: It includes a partition division unit, a partition compression unit, a partition difference unit, and a partition upgrade unit; The partition division unit is used to divide the firmware of the electronic device into multiple partitions during the firmware compilation stage, each partition containing one or more functional modules; Each partition has essentially the same size after compression; The partition compression unit is used to compress the firmware of the electronic device in units of partitions to obtain compressed firmware of the electronic device; After the partition is compressed, it is called a compressed partition. During compression, the relevant information of the compressed partition is recorded; All the relevant information of the compressed partition 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 used to generate an upgrade file table; also to differentiate 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; and also to differentiate the decompressed data of each partition in the new firmware from the decompressed data of the corresponding partition in the old firmware to obtain differential data of each partition; The above three parts are assembled into differential upgrade files of new and old compressed firmware in sequence; The partition upgrade unit is used for upgrading the loading data table first and then upgrading the firmware in units of compressed partitions after the electronic device obtains the differential upgrade file of the new and old compressed firmware.
Citation Information
Cited By
Over-the-air upgrade method and system for compressed firmware
WO2026086473A1