CN116700739A - Differential upgrading method and device, electronic equipment and readable storage medium - Google Patents

Differential upgrading method and device, electronic equipment and readable storage medium Download PDF

Info

Publication number
CN116700739A
CN116700739A CN202211154066.7A CN202211154066A CN116700739A CN 116700739 A CN116700739 A CN 116700739A CN 202211154066 A CN202211154066 A CN 202211154066A CN 116700739 A CN116700739 A CN 116700739A
Authority
CN
China
Prior art keywords
data
data block
command
upgrade
differential
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211154066.7A
Other languages
Chinese (zh)
Inventor
陈彦桦
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Honor Device Co Ltd
Original Assignee
Honor Device Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Honor Device Co Ltd filed Critical Honor Device Co Ltd
Priority to CN202211154066.7A priority Critical patent/CN116700739A/en
Publication of CN116700739A publication Critical patent/CN116700739A/en
Pending legal-status Critical Current

Links

Abstract

The application relates to the technical field of firmware upgrading, and provides a differential upgrading method, a differential upgrading device, electronic equipment and a readable storage medium, wherein the method comprises the following steps: sequentially reading data block identifiers representing the data block restoration sequence in the differential upgrade package, determining a restoration command corresponding to the data block identifiers, acquiring first upgrade data and/or second upgrade data according to the restoration command, and covering a data area to be upgraded in the old image through the first upgrade data and/or the second upgrade data. Compared with the existing differential upgrading flow, the application performs block restoration on the old image according to a certain restoration sequence, so that the memory occupation of each restoration operation does not exceed the size of the current restored data block, the memory use of the thin equipment in the firmware upgrading process is ensured to be controllable, and the memory resource occupation of the thin equipment is reduced.

Description

Differential upgrading method and device, electronic equipment and readable storage medium
Technical Field
The present application relates to the field of firmware upgrade technologies, and in particular, to a differential upgrade method, a differential upgrade device, an electronic device, and a readable storage medium.
Background
At present, the differential upgrading algorithm is very mature, and is mature to be applied to the scenes of system upgrading such as android and IOS, upgrading of mobile phone App and the like. However, for embedded devices (also called thin devices), the memory resources are extremely limited, and the differential algorithm applied to the rich device is not feasible in the embedded device.
The existing differential upgrading method for the thin equipment can realize firmware upgrading of the thin equipment, but the memory usage is uncontrollable in the firmware upgrading process, because the differential packet generated by the differential upgrading algorithm needs to be completely decompressed when being upgraded, so that the memory usage is uncontrolled and the occupation of memory resources is larger.
Disclosure of Invention
The application provides a differential upgrading method, a differential upgrading device, electronic equipment and a readable storage medium, and aims to ensure that memory usage of thin equipment in a firmware upgrading process is controllable and reduce occupation of memory resources of the thin equipment.
In a first aspect, the present application provides a differential upgrade method, the method comprising: sequentially reading data block identifiers representing the data block restoration sequence in the differential upgrade package, wherein the restoration sequence is determined in advance according to the dependence of the data blocks to be restored in the old mirror image; determining a restoring command corresponding to the data block identifier; acquiring first upgrade data and/or second upgrade data according to the restore command, wherein the first upgrade data is added data of a new image compared with the old image, and the second upgrade data is data obtained after restoring an original data block in the old image; and covering a data area to be upgraded in the old image by the first upgrade data and/or the second upgrade data.
According to the differential upgrading method provided by the application, the data block identifiers representing the data block restoration sequence in the differential upgrading packet are sequentially read, then the restoration command corresponding to the data block identifiers is determined, the first upgrading data and/or the second upgrading data are obtained according to the restoration command, and then the data area to be upgraded in the old image is covered by the first upgrading data and/or the second upgrading data. Compared with the existing differential upgrading flow, the application performs block restoration on the old image according to a certain restoration sequence, so that the memory occupation of each restoration operation does not exceed the size of the current restored data block, the memory use of the thin equipment in the firmware upgrading process is ensured to be controllable, and the memory resource occupation of the thin equipment is reduced.
In one possible implementation manner, the determining the restore command corresponding to the data block identifier includes: reading corresponding compressed data from the differential upgrade package according to the data block identifier; and determining a restore command according to the compressed data.
In another possible implementation manner, the determining a restore command according to the compressed data includes: decompressing the compressed data to obtain decompressed data; and reading a restore command from the decompressed data.
In another possible implementation manner, the acquiring the first upgrade data and/or the second upgrade data according to the restore command includes: reading a first type command in the restore command, and acquiring first upgrade data from the decompressed data according to the first type command; and/or reading a second class command in the restoring command, restoring the target original data block into second upgrading data in the old image according to the second class command, wherein the target original data block is determined in the old image according to the data block identification.
In another possible implementation manner, before the obtaining the first upgrade data and/or the second upgrade data according to the restore command, the method further includes: reading a third type command in the restore commands; and copying the corresponding target original data block in the old image to a backup area of the differential upgrade package for waiting to restore according to the third class command.
In another possible implementation manner, the copying the corresponding target original data block in the old image to the backup area of the differential upgrade package according to the third class command waits for restoration, including: determining a target original data block in the old image according to the third class command; acquiring first target data to be backed up in the target original data block, wherein the first target data is all or part of data in the target original data block; copying the first target data to a backup area of the differential upgrade package to wait for reduction.
In another possible implementation manner, the reading a second class command in the restore command, and restoring the target original data block to the second upgrade data in the old image according to the second class command includes: reading a second class command in the restore commands; determining a field range indicated by the second type command; and restoring the target original data block into second upgrading data according to the second type command in the old image according to the field range.
In another possible implementation manner, the restoring, according to the field range, the target original data block to the second upgrade data in the old image according to the second type command includes: determining second target data to be restored in the target original data block according to the field range, wherein the second target data is all or part of data in the target original data block; and restoring the second target data into second upgrading data according to the second class command in the old image.
In another possible implementation, the method further includes: determining an original data packet to which the current restored original data block belongs; judging whether a dependency relationship exists between the original data packet and the next original data packet to be restored; if not, after the original data packet is restored, releasing the backup area occupied by the original data packet.
In another possible implementation, the method further includes: in the process of restoring the target original data block into the second upgrading data, if the equipment is powered down, after the equipment is powered up, reading the target original data block from a backup area of the differential upgrading packet; and restoring the target original data block to the corresponding position of the old mirror image, and continuing restoring the target original data block.
In another possible implementation manner, before the obtaining the second upgrade data according to the restore command, the method includes: determining a target original data block corresponding to the data block identification in the old image and second upgrading data corresponding to the new image; acquiring a first checksum corresponding to the target original data block and a second checksum corresponding to the second upgrade data; and executing the step of acquiring second upgrading data according to the restoring command when the first checksum is matched with the second checksum.
In another possible implementation, the dependency is the number of bytes of data in each data block to be restored that is required by the new image.
In a second aspect, the present application provides a differential upgrade method, the method comprising: obtaining an initial differential upgrade package according to the difference data between the new image and the old image; splitting the new mirror image to obtain a plurality of data blocks, wherein the data blocks comprise first class data and/or second class data, and the second class data is obtained by converting original data in the old mirror image; for each data block containing the second class data, determining the dependence of the second class data on the corresponding original data block in the old image, and converting the original data block into a restore command; and updating the initial differential upgrade package according to the dependence degree and the reduction command to obtain a target differential upgrade package.
According to the differential upgrading method provided by the application, the initial differential upgrading packet is obtained according to the difference data between the new image and the old image; then splitting the new mirror image to obtain a plurality of data blocks; determining the dependence of the second class data on the corresponding original data block in the old mirror image and a restoring command for converting the original data block for each data block containing the second class data; and finally, updating the initial differential upgrade package according to the dependence degree and the reduction command to obtain a target differential upgrade package, so that the memory usage of the thin equipment in the firmware upgrade process according to the target differential upgrade package is controllable, and the occupation of memory resources of the thin equipment is reduced.
In a third aspect, the present application provides a differential upgrade apparatus, comprising: the device comprises a data reading module, a command acquisition module, a data reduction module and a differential upgrading module;
the data reading module is used for sequentially reading data block identifiers representing the data block restoration sequence in the differential upgrade package, and the restoration sequence is determined in advance according to the dependence of the data blocks to be restored in the old mirror image;
the command acquisition module is used for determining a restoring command corresponding to the data block identifier;
The data restoring module is configured to obtain first upgrade data and/or second upgrade data according to the restoring command, where the first upgrade data is data that is added by a new image compared with the old image, and the second upgrade data is data obtained by restoring an original data block in the old image;
the differential upgrading module is used for covering a data area to be upgraded in the old image through the first upgrading data and/or the second upgrading data.
In a fourth aspect, the present application provides a differential upgrade apparatus, including: the system comprises a mirror image comparison module, a mirror image splitting module, a dependency acquisition module and a differential packet updating module;
the image comparison module is used for obtaining an initial differential upgrade package according to the difference data between the new image and the old image;
the image splitting module is used for splitting a new image to obtain a plurality of data blocks, wherein the data blocks comprise first-class data and/or second-class data, and the second-class data is obtained by converting original data in the old image;
the dependency degree obtaining module is configured to determine, for each data block containing the second class data, a dependency degree of an original data block corresponding to the second class data in the old image, and a restore command for converting the original data block;
The differential packet updating module is used for updating the initial differential upgrade packet according to the dependence degree and the reduction command to obtain a target differential upgrade packet.
In a fifth aspect, the present application provides an electronic device, comprising:
one or more processors; a memory; and one or more computer programs, wherein the one or more computer programs are stored in the memory, the one or more computer programs comprising instructions that, when executed by the electronic device, cause the electronic device to perform the differential upgrade method as described in the first aspect or any of the possible implementations of the second aspect or the second aspect.
In a sixth aspect, the present application provides a computer readable storage medium having stored therein a computer program which, when executed by a processor, causes the processor to perform the differential upgrade method as described in the first aspect or any one of the possible implementations of the second aspect or the second aspect.
In a seventh aspect, the present application provides a chip, the chip including a processor and a data interface, the processor reading instructions stored on a memory through the data interface, performing any one of the first aspect or the possible implementation manner of the first aspect or the differential upgrading method of any one of the second aspect or the possible implementation manner of the second aspect.
Optionally, as a possible implementation manner, the chip may further include a memory, where the memory stores instructions, and the processor is configured to execute the instructions stored on the memory, where the instructions, when executed, are configured to perform the first aspect or any one of the possible implementation manners of the second aspect or the second aspect.
Drawings
Fig. 1 is a schematic diagram of a differential upgrading method according to an embodiment of the present application;
FIG. 2 is a schematic diagram of a BSDiff algorithm in the prior art;
fig. 3 is a schematic flow chart of a differential upgrading method according to an embodiment of the present application;
FIG. 4 is a schematic scene diagram of data block restoration provided by an embodiment of the present application;
FIG. 5 is a schematic scene diagram of still another data block restoration provided by an embodiment of the present application;
fig. 6 is a schematic structural diagram of a differential upgrade package according to an embodiment of the present application;
FIG. 7 is a schematic scene diagram of differential upgrade provided by an embodiment of the present application;
FIG. 8 is a schematic scene diagram of still another differential upgrade provided by an embodiment of the present application;
FIG. 9 is a schematic diagram of checksum state transition in a data block recovery process according to an embodiment of the present application;
fig. 10 is a schematic structural diagram of a differential upgrade apparatus provided by the present application;
fig. 11 is a schematic structural diagram of another differential upgrade apparatus provided by the present application.
Detailed Description
The terms first, second, third and the like in the description and in the claims and in the drawings are used for distinguishing between different objects and not for limiting the specified order.
In embodiments of the application, words such as "exemplary" or "such as" are used to mean serving as an example, instance, or illustration. Any embodiment or design described herein as "exemplary" or "e.g." in an embodiment should not be taken as preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "such as" is intended to present related concepts in a concrete fashion.
In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present application, the technical solutions in the embodiments of the present application are described in further detail below with reference to the accompanying drawings.
For clarity and conciseness in the description of the embodiments below, a brief introduction to related concepts or technologies is first given:
the internet of things (Internet of Things, ioT) refers to collecting any object or process needing to be monitored, connected and interacted in real time through various devices and technologies such as various information sensors, radio frequency identification technologies, global positioning systems, infrared sensors and laser scanners, collecting various needed information such as sound, light, heat, electricity, mechanics, chemistry, biology and positions, and realizing ubiquitous connection of objects and people through various possible network access, thereby realizing intelligent perception, identification and management of objects and processes. The internet of things is an information carrier based on the internet, a traditional telecommunication network and the like, and enables all common physical objects which can be independently addressed to form an interconnection network.
BSDiff is a delta update algorithm. Running the BSDiff algorithm on the server side can generate a patch package, and running the BSPatch algorithm (i.e. the restore algorithm) on the client side can synthesize the old image (old file) and the differential upgrade package (patch package) into a new image (new file). The core idea of the delta update algorithm is to construct new files with as little new content as possible, using as much as possible the existing content in old files. The common practice is to perform string matching on the old file and the new file or use a hash technique to extract the common part and package the rest part in the new file into a patch package. In the patch stage, the old file and the patch package can be updated to new files by two basic operations of copy and insert.
In order to better explain the technical scheme provided by the application, firstly, a terminal for generating a differential upgrade package (patch package) and a terminal for performing differential upgrade according to the differential upgrade package in the embodiment of the application are respectively described.
As shown in fig. 1, in this embodiment, the terminal that generates the differential upgrade package is a PC terminal, and the terminal that performs differential upgrade according to the differential upgrade package is an IoT thin device (IoT device for short). The PC side stores the current old firmware (old file) and the new firmware (new file) of the IoT device, generates a differential upgrade package by the old file and the new file through the BSDiff algorithm, and uploads the generated patch package to the server. When the IoT device needs to perform firmware version upgrade, the patch package is downloaded from the server, and differential upgrade is implemented according to the patch package and the old file in the current device, so that the old file of the IoT device is upgraded to a new file.
As shown in fig. 2, fig. 2 is a schematic diagram of a BSDiff algorithm in the prior art. In the execution process of the BSDiff algorithm, all the substrings in the old file are formed into a dictionary, the old file and the new file are compared to generate diff string and extra string, the diff string, the extra string and corresponding control words are combined together, and a patch package is formed after compression.
As can be seen from the above description of fig. 2, the lengths of diff and extra strings are not controllable, and if the initial patch packet (i.e., the differential upgrade packet generated directly from the difference data of the old and new images) is directly used, the entire diff or extra string needs to be decompressed out during the upgrade process, which results in uncontrolled memory usage of the IoT device, which is not feasible on a resource-constrained terminal device (i.e., a thin device). Furthermore, the BSDiff algorithm produces diff strings that are dependent on the old file, and each diff string is not sequentially dependent with respect to the old file. Therefore, for flash or memory limited scenarios, it is not feasible to restore the new image directly on the old image.
Based on the above problems, the present application proposes a differential upgrade method applied to a terminal, such as a PC, that generates a differential upgrade package. As shown in fig. 3, fig. 3 is a flow chart of a differential upgrading method according to an embodiment of the present application, where the differential upgrading method includes:
step S01: obtaining an initial differential upgrade package according to the difference data between the new image and the old image;
it should be noted that, in this embodiment, the PC side may compare the new image with the old image, further determine difference data between the new image and the old image, and then generate an initial differential upgrade packet based on the difference data.
It should be understood that the initial differential upgrade packet at least includes differential data for indicating that the old image obtains the new image, where the differential data may represent a difference between the new image and the old image, and the difference may also be represented on different types of data, for example, a first type of character string, that is, a character string that the new image is newly added compared to the old image, and such character string cannot be obtained according to the character string in the old image, that is, extra string. For another example, the second type of string, i.e., diffstring, may be converted into the data in the new image, i.e., the second type of data described below, under a restore command corresponding to such string. Illustratively, the original data "abcxef" in the old image may be converted or restored to the data "abcdef" in the new image under the second type string "000200" and its corresponding restore command (e.g., diff_o, oldbin from the old image oldimage).
It can be understood that if the type of the differential data carried in the initial differential upgrade package is the second type of character string, the part corresponding to the type of data in the initial differential upgrade package can be replaced by a restore command, so that the size of the initial differential upgrade package can be reduced, and the memory occupation in the differential upgrade process can be reduced. Illustratively, the restore command includes, but is not limited to:
1. And translating some original data in the old image to the appointed field position in the new image, wherein part or all data of the second class data in the new image is only data corresponding to some original data in the old image, and only the original data are required to be translated. For example, as shown in fig. 4, the original data OA in the old image (old file) is translated to the designated field position (i.e. the position corresponding to NA) in the new image (new file), and at this time, the second type of data NA in the new image is obtained by translating the original data OA in the old file.
2. Deleting the original data of some areas in the old image, wherein the acquisition of part or all of the data in the second class of data in the new image requires deleting part of the data in some original data in the old image, and then splicing the rest of the data. Illustratively, as shown in fig. 4, a part of the original data OB2 in the original data OB in the old image (old file) is deleted, at this time, a part or all of the data in the second class of data NB in the new image needs to be deleted from the part of the data OB2 in the original data OB in the old file, and then the remaining data OB1 and OB3 are spliced to obtain the data block NB.
3. And transforming some original data in the old image according to a designated path, wherein part or all of data in the second class of data in the new image is required to be changed or transformed according to some original data in the old image. For example, as shown in fig. 4, the original data OC in the old image (old file) is transformed according to a specified path, at this time, part or all of the second type data NC in the new image needs to be changed or converted according to the original data OC in the old file, for example, the original data OC "abcxef" is transformed into "abcdef", and then the "abcdef" is moved to a corresponding position in the new file, so as to obtain the second type data NC.
Step S02: splitting the new mirror image to obtain a plurality of data blocks, wherein the data blocks comprise first class data and/or second class data, and the second class data is obtained by converting original data in the old mirror image;
it should be noted that, in order to ensure that the memory occupation of the IoT device is controllable in the firmware upgrade process, the embodiment is implemented by adopting a packet block reduction manner, that is, when the IoT device performs firmware upgrade according to the target differential upgrade packet finally generated by the PC side, a plurality of data blocks in the packet are sequentially reduced according to the block unit, so that a new image is restored on the old image.
It should be emphasized that the first type of data may be data that is newly added by the new image relative to the old image, and that this portion of data cannot be obtained by converting the original data in the old image. For example, the first type of data may be the first type of character string, i.e., extra string. Correspondingly, the second type of data is data which can be obtained by converting the original data in the old image. For example, the second type of data may be converted from a second type of string, i.e. diffstring.
In particular, the PC may split the new image with equal length, or split the new image with different lengths, which is not limited in this embodiment. It should be understood that after splitting the new image, the obtained data block may include only the first type of data, only the second type of data, or both the first type of data and the second type of data.
In one possible implementation manner, the PC side may split the new image with equal length according to a preset byte length, so as to obtain a plurality of data blocks. In this embodiment, the preset byte length may be set according to actual needs. By way of example, 4KB, 8KB, etc. may be set, and the present embodiment is not particularly limited. The equal length split is to split the mirror image according to a certain byte length and address order (e.g. order from head address to tail address).
In another possible implementation manner, the PC side may first acquire a flash unit, and then determine the preset byte length according to the flash unit. It should be appreciated that for flash, data is written in whole page (whole block) fashion, while the flash erase unit in different IoT devices is different. Therefore, in this embodiment, by obtaining the flash unit of the IoT device to be upgraded and then determining the preset byte length according to the flash unit, it is ensured that the occupation of the memory is controllable when the block upgrade is performed based on the differential upgrade packet.
It should be noted that, when the preset byte length is set according to the flash erase unit, the preset byte length may be an integer multiple of the flash erase unit. For example, if the flash erase unit is 4KB, the preset byte length may be set to 4KB, 8KB, 12KB, etc.
Step S03: for each data block containing the second class data, determining the dependence of the second class data on the corresponding original data block in the old image, and converting the original data block into a restore command;
it will be appreciated that not all of the data blocks obtained after splitting the new image contain the second type of data described above. For such data blocks, the IoT device does not depend on the original data in the old image in the process of upgrading the new image according to the old image and the differential upgrade package, so that the data blocks only need to be restored in sequence according to the address positions of the data blocks in the new image after upgrading in the firmware upgrading process.
For the data blocks containing the second class data, since the second class data in the data blocks has corresponding original data in the old image, the original data has the original data blocks to which the original data belongs, and if the restoration sequence of the original data blocks is not considered, firmware upgrade cannot be performed. For example, as shown in fig. 5, if the original data blocks OA blocks in the old image are restored first, the original data OA2 in the OA blocks is covered, and when NB blocks (specifically NB 1) in the new image are assembled, the source of the old image is lost, and the restoration operation cannot be continued. Therefore, when the target differential upgrade package is generated, the restoration sequence of each original data block (such as an OA block and an OB block) in the old image needs to be considered, so as to ensure that the data blocks NA and NB in the new image are successfully obtained. In this embodiment, the restoration order of each original data block in the old image may be determined by its corresponding dependency.
The definition of the dependency of the present embodiment is described herein with reference to fig. 5.
As shown in fig. 5, the so-called dependency, i.e. the number of bytes required by a new image for a certain original data block in the old image. Specifically, for each data block (e.g., NA) of the new image that includes the second type data (e.g., NA 1), the PC side may determine the target original data OB1 corresponding to the second type data NA1 in the old image, obtain the byte number (e.g., 2 KB) of the target original data OB1, and then use the byte number (e.g., 2 KB) as the dependency of the original data block OB to which the original data OB1 belongs.
Illustratively, the dependency of the old image original data block OA in FIG. 5 is the size of the original data OA2 required by the second type of data NB1 of the NB blocks in the new image. Regarding the above-described degree of dependence, the present embodiment is also defined as follows: since the original data OC2 in the old mirrored original data block OC itself and the second class data NC2 block in the new mirrored data block NC are out of the address space of the same block, OC2 is not counted inside the dependency of the original data block OC, i.e. the dependency of the original data block OC block, i.e. the number of bytes of the original data OC1, is not the number of bytes of OC1 + the number of bytes of OC 2.
In addition, in this embodiment, the dependency of each original data block may change with the restoration state of the original data block before it. For example, in fig. 5, when the original data block OB block in the old image is restored, the corresponding NB block with the same address in the new image needs to use the original data OC1 in the OC block of the old image, when the OB block completes the restoration, only the original data OC2 remains in the OC block to wait for the restoration, but since OC2 and the NC2 block in the new image are in the same address space, according to the above definition, when the OB block is restored, the dependency of OC changes from the byte number (2 KB) occupied by OC1 to 0 byte, and then the restoration sequence of the OC block of the original data may also change with the decrease of the dependency.
Step S04: and updating the initial differential upgrade package according to the dependence degree and the reduction command to obtain a target differential upgrade package.
It will be appreciated that the dependency of the original data blocks, i.e. the order of restoration of each original data block in the determined old image, is determined.
It can be understood that the difference data in the initial differential upgrade package generated by the PC end is not marked according to the reduction sequence, and the reduction command corresponding to the first type character string and the second type character string in the difference data is not encapsulated into the initial differential upgrade package, so that in order to ensure smooth implementation of firmware upgrade, the initial differential upgrade package needs to be updated according to the dependency and the reduction command, and the target differential upgrade package is obtained.
In one possible implementation manner, the PC side may determine a restoration order of the data blocks to be restored in the old image according to the dependency, then generate a data block identifier of each data block to be restored according to the restoration order, and update the initial differential upgrade package according to the data block identifier and the restoration command, so as to obtain a target differential upgrade package.
Specifically, the PC side may first align the new and old images according to the file header address, and then block the aligned new and old images according to a preset byte length to obtain a plurality of data blocks; and then constructing a data packet every other data block with the same number according to the sequence from the head address to the tail address, then determining the corresponding original data packet in the old mirror image according to the address range covered by each data packet, and carrying out packet marking, such as 1 st, 2 nd and 3 th … … n groups, and finally determining the restoration sequence of each data block to be restored in each original data packet.
Regarding the generation of the data block identifier, the PC side may first obtain the dependency of the (original) data block to be restored in each original data packet in the old image (for example, the dependency of OA, OB, OC, OD blocks in the 1 st packet), then sort the dependencies of all the (original) data blocks to be restored in each original data packet in order from small to large, then use the original data block with the smallest dependency as the first data block waiting for restoration in the current original data packet according to the sorting result, and so on, and determine the actual restoration order of each (original) data block to be restored in the packet under the condition that the dependency of each original data block in the packet is fully considered to change with the restoration state of the previous original data block, and then generate the corresponding data block identifier according to the order. Illustratively, the representation of the data block identifier may be a block_id (x), where x represents the number of bytes occupied by the entire data block identifier block_id, and id may be an encoding or marking of the original data block in mirrored address order, e.g. 1, 2, 3 … … n. The original data block corresponding to the data block with id n is located at the end position of the file in the old image.
If in the target differential upgrade package, the reading sequence or the storage sequence of the original data blocks is as follows: block_4 (2), block_3 (2), block_1 (2), and block_2 (2), then the original data block currently waiting to be restored is indicated as the 4 th block in the old image, followed by the 3 rd, 1 st, and 2 nd blocks.
In addition, it should be noted that, the second upgrade data corresponding to some difference data (diff string) stored in the initial differential upgrade package may be converted from the original data in the old image, so that a portion of the difference data in the initial differential upgrade package may be replaced by a restore command for restoring the original data, thereby reducing the size of the initial differential upgrade package and reducing the memory occupation in the differential upgrade process.
In another possible implementation manner, in order to reduce the size of the initial differential upgrade packet as much as possible, the PC side may further compress the restore command to obtain compressed data, then associate the data block identifier with the compressed data, write the data block identifier into the initial differential upgrade packet, and divide a backup area in the initial differential packet to obtain the target differential upgrade packet.
In another possible implementation manner, in order to ensure that firmware upgrade can be performed smoothly after the IoT device is powered down, the present embodiment further sets an area for implementing power-down recovery, that is, a checksum (checksum) area, in the target differential upgrade packet, where data stored in the area is used to verify whether the old image is legal and power-down recovery. Therefore, after determining the data block identifier and the restore command of each (original) data block to be restored, the PC side also needs to calculate the checksum of the (original) data block to be restored and the checksum of the data block restored to the new mirrored data block, and then update both checksums into the initial differential upgrade package, so as to check whether the old mirrored data is legal and restore the power failure.
Of course, the target differential upgrade packet of the embodiment further includes information of the offset field of the old image and information of the length to be backed up. Therefore, in the process of updating the initial differential upgrade package, the PC side also needs to update the two kinds of information into the initial differential upgrade package according to the offset field of the current (original) data block to be restored and the length to be backed up.
The target differential upgrade package finally generated by the PC side of this embodiment will be described with reference to fig. 6.
As shown in fig. 6 (a), the target differential upgrade package includes a Patch area in which data required in the firmware upgrade process is stored according to the data structure of fig. 6 (b) (also referred to as a Patch package structure), and a backup area for temporarily storing data blocks to be backed up.
As shown in fig. 6 (b), the patch package structure is mainly divided into 4 parts: header, checksum, bck _cmd and block_cmd. The darker portions of the base color in FIG. 6 (b), such as bck_cmd (bck_pos, bck_len) and block_cmd, may be multi-set, with the specific number of sets depending on how many sets the image is partitioned (e.g., a new image of 128KB, partitioned into 32 blocks by 4KB, and 8 if there are four sets). In addition, other parts (block_id, old_checksum, new_checksum) with deeper base color can also have multiple groups, and the number of groups is equal to the number of blocks of max (new image size, old image size). (e.g., a new image of 128KB may be divided into 32 blocks by 4KB partition, an old image of 96KB may be divided into 24 blocks by 4KB partition), then the number of groups is max (32 blocks, 24 blocks) =32 blocks.
Note that, the block_cmd of fig. 6 (b) includes a section of compressed data (compression_data), and after the section of compressed data is decompressed, the specific format is as follows:
cmd_type cmd_content data
wherein, the cmd_type segment is a command type, corresponding to 00, 01 or 10, each command occupies 2 bits, and corresponds to 3 commands of diff_o (oldbin from oldimage), diff_b (oldbin from backup area), and extra, respectively. The cmd_content segment is the offset and length under the 3 commands described above; the data section length is 4KB, which is the set of diff string and extra string. In addition, brackets following each field in fig. 6 (b) represent how many bytes the field occupies. E.g., marked (OLD), the size of this field needs to be inferred from the OLD image size. If the OLD image size exceeds 0xFFFF bytes, then (OLD) represents 4 bytes, otherwise 2 bytes; for another example, labeled (BLOCK), an inference is made based on whether the chunk size exceeds 0xFFFF bytes.
As can be seen from the above embodiments, in the differential upgrade method provided in this embodiment, an initial differential upgrade packet is obtained according to difference data between a new image and an old image; then splitting the new mirror image to obtain a plurality of data blocks; determining the dependence of the second class data on the corresponding original data block in the old mirror image and a restoring command for converting the original data block for each data block containing the second class data; and finally, updating the initial differential upgrade package according to the dependency and the restoring command to obtain a target differential upgrade package, thereby ensuring that the memory usage of the thin equipment in the firmware upgrade process is controllable and reducing the occupation of memory resources of the thin equipment.
The differential method provided by the embodiment generates the (target) differential upgrade package at the PC end, and the application also provides another differential upgrade method which is applied to upgrading the firmware according to the (target) differential upgrade package after the (target) differential upgrade package is acquired by the IoT device, so as to upgrade the old image in the IoT device into the new image.
Based on the above differential upgrade method, the embodiment of the present application provides another differential upgrade method, which includes:
step S10: sequentially reading data block identifiers representing the data block restoration sequence in the differential upgrade package, wherein the restoration sequence can be determined in advance according to the dependence of the data blocks to be restored in the old mirror image;
it should be understood that, in the target differential upgrade package generated in the above embodiment, each block in the target differential upgrade package is updated, so that the data size in the differential upgrade becomes smaller, but at least, it is ensured that the terminal can complete normal firmware upgrade by using the target differential upgrade package.
It is understood that the data block identifier stored in the differential upgrade package is used to determine the data block that needs to be restored currently, and the restoration order (the reading order or the storage position) of the data block identifier in the differential upgrade package is also determined in advance according to the dependency of the data block to be restored in the old image.
In one possible implementation, the dependency is the number of bytes of data required for the new image in each data block to be restored. The determination method of the dependency degree in this embodiment may be referred to the first embodiment, and will not be described herein. According to the embodiment, the byte number is used as the dependency degree, so that the memory occupation in the firmware upgrading process can be fundamentally ensured to be controllable.
In particular, when the IoT device obtains the differential upgrade packet (i.e., the target differential upgrade packet) through the fota technology, the differential upgrade packet may be parsed, and then the data block identifiers, such as block_id, that characterize the data block reduction sequence are sequentially read from the parsed differential upgrade packet.
Step S20: determining a restoring command corresponding to the data block identifier;
in particular, when the IoT device reads the data block identifier, the IoT device may determine a restore command of the data block that needs to be restored currently according to the data block identifier. Of course, the above-mentioned restore command in this embodiment may include: a first type of command, a second type of command, and/or a third type of command. The first type of command is used for acquiring first upgrade data, the second type of command is used for restoring the original data block in the old image into second upgrade data, and the third type of command is used for backing up all or part of data in the original data block restoring process of the old image.
In one possible implementation, corresponding compressed data is read from a (target) differential upgrade package according to the data block identification; a restore command is then determined from the compressed data. It should be understood that, as shown in fig. 6 (b), the compressed data (compression_data) in the block_cmd area of the differential upgrade packet generated at the PC end stores a restore command. The IoT device may thus read corresponding compressed data from the differential upgrade package according to the data block identification, and then determine a restore command according to the compressed data.
In another possible implementation, the IoT device may also decompress the compressed data, obtain decompressed data, and then read the restore command from the decompressed data. After obtaining the compressed data, the IoT device may decompress it to obtain decompressed data (including cmd_type, cmd_content, and data), and then read the restore command from the data.
Step S30: acquiring first upgrade data and/or second upgrade data according to the restore command, wherein the first upgrade data is added data of a new image compared with the old image, and the second upgrade data is data obtained after restoring an original data block in the old image;
It should be understood that the data included in the new image data block generated by each restore operation may be all data (extra string) added by the new image compared to the old image, that is, the first upgrade data described above. It is also possible that all are restored from some of the original data blocks in the old image. It is also possible that part of the data is added to the new image compared with the old image, and the other part of the data is obtained after the original data block in the old image is restored. Thus, the IoT device, upon acquiring the restore command from the data block identification, may obtain the first upgrade data and/or the second upgrade data from the restore command and the (a series of data in the) differential upgrade package.
In one possible implementation, the IoT device may read a first type of command in the restore command and then obtain first upgrade data from the decompressed data according to the first type of command. It can be appreciated that, since the obtaining of the first upgrade data does not depend on the old image, after obtaining the first class command (extra), the IoT device may directly read the first upgrade data extra string from the data according to the command, and then write the extra string into the corresponding area in the old image according to the offset and the length corresponding to the first class command (extra) in the cmd_content, so as to obtain the first upgrade data.
In another possible implementation, the IoT device may also read a second type of command in the restore command and then restore the target original data block to the second upgrade data in the old image according to the second type of command, wherein the target original data block is determined in the old image according to the data block identification. It can be appreciated that, since the second upgrade data needs to be obtained by relying on the old image, after obtaining the second type command (diff_o), the IoT device can read the second type string diff from the data according to the command, and then restore the original data of the corresponding area in the old image to the second type string diff according to the offset and the length corresponding to the second type command (diff_o) in the cmd_content.
Specifically, the IoT device may read a second type command (diff_o) in the restore command, and then determine a field range indicated by the second type command according to cmd_content; and restoring the target original data block into second upgrading data according to the second type command in the old image according to the field range.
It should be appreciated that for a target original data block (i.e., an original data block that is currently in need of restoration), not all of the data in the block may be required for the new image. Therefore, in the firmware upgrading process, the IoT device may determine, according to the field range indicated by the second type of command, second target data to be restored in the target original data block, where the second target data is all or part of data in the target original data block; and then restoring the second target data into second upgrading data according to the second type command in the old image.
In another possible implementation, the IoT device may also read a third type of command in the restore command and then copy the corresponding target original data block in the old image to the backup area of the differential upgrade package for waiting to restore according to the third type of command.
It should be understood that, in order to ensure that the firmware upgrade is performed smoothly, some original data in the old image may not be used temporarily in the current restore operation, but if the data is covered in the current restore operation, the data block that depends on the data cannot be obtained smoothly, so the data may be copied to a backup area in the differential upgrade package (e.g., the backup area in fig. 6 (a)), and the restore may be performed continuously after the data is read from the backup area in waiting for the subsequent restore.
It should be appreciated that not all of the data in the block may be required by the new image for the target original data block, and thus the IoT device may first determine the target original data block in the old image according to the third type of command during the data block backup process; and then acquiring first target data to be backed up in the target original data block, wherein the first target data is all or part of data in the target original data block, and copying the first target data to a backup area of the differential upgrade package for waiting for restoration.
Step S40: and covering a data area to be upgraded in the old image by the first upgrade data and/or the second upgrade data.
It should be understood that the first upgrade data is obtained by a first type of character string (extra string) in the differential upgrade package, and the second upgrade data is obtained by restoring the original data block in the old image. After the IoT device obtains the first upgrade data and/or the second upgrade data, the data may be used to cover the corresponding data area to be upgraded in the old image until each data area to be upgraded in the old image completes the operations in steps S10 to S40, and the old image is upgraded into a new image, thereby completing the firmware upgrade.
The differential upgrade method provided in this embodiment is described herein with reference to fig. 7.
As shown in fig. 7, old_seed_num is the dependency, the 1 st, 2 nd, 3 rd and 4 th original data blocks in the Old image belong to one original data block group in the restoration process, and the dependency of the original data blocks 1, 2 nd, 3 rd and 4 in the Old image is 4b <1b <3d <2a+2d. The currently newly added gray node represents this time to restore the original data block.
Note that new_need_num in fig. 7 is the occupancy. In this embodiment, the occupancy is the number of bytes of a certain data block M in the new image that requires some original data block (or the original data contained therein) in the old image. After the data block M is restored (or after the data block M in the new image is constructed), the resources occupied by the data block M (the original data block in the old image) are released, so that the dependency of other original data blocks in the old image which have not been restored is reduced. Referring to fig. 5, for the data block NA in the new image, the occupation degree is the size of the original data OB1 in the original data block OB of the old image; the occupancy for the data block NB in the new image is the size of the original data OA2+ OC 1. Of course, the occupancy of the present embodiment is only presented to illustrate that the dependency of a certain data block in the new image on the original data block related to the new image in the old image changes after the construction is completed.
In the definition of the above-described degree of dependence and degree of occupancy, first, a data block having a smaller degree of dependence and a larger degree of occupancy should be restored. Because the blocks with smaller dependency are restored, the number of bytes to be backed up is also smaller; and the blocks with larger occupation degree are restored, and the released resources are more, so that the dependency degree of other original data blocks which are not restored in the old mirror image is reduced, and the reduction of the number of bytes needing backup is facilitated. In practice, it is found that if the ordering considers the occupancy, the size of the backup area is slightly increased instead, so that the order of restoration of the data blocks in this embodiment only considers one factor of the dependency as a preferred way.
Based on the above description, the process of fig. 7 (a) →fig. 7 (e) of the present embodiment is described as follows: since the dependency of the 4 th block in the old image is the smallest (4 b), the 4 th block is restored first, and the restoration (or construction) of the b block in the new image is dependent on the 4 th block, it is necessary to backup the dependency of the 4 th block to the backup area (i.e., copy the original data 4b in the 4 th block to the backup area), and then perform the restoration operation. When the 4 th block in the old image finishes the restoration, the d block of the data block with the same address in the new image also finishes the restoration, that is, the IoT device has constructed the d block in the new image according to the data (dependency) 2d in the 2 nd block and the data (dependency) 3d in the 3 rd block, the occupation degree corresponding to the d block is released, the dependencies of the 2 nd block and the 3 rd block in the old image are reduced together, as shown in fig. 7 (b), and the 1 st, 2 nd and 3 rd data blocks to be restored still remain at the moment, and the corresponding dependencies are 1b, 2a and 0 respectively. It goes without saying that the original data block to be restored is the 3 rd block and the data block corresponding to the 3 rd block in the new image is the c block, and the construction of the c block does not depend on the original data blocks in any old image, so that when the 3 rd block is restored, the restored states of the 1 st, 2 nd, 3 rd and 4 th blocks in the old image are as shown in fig. 7 (c), and only the 1 st and 2 nd blocks in the old image are left to wait for restoration, that is, the a block and the b block in the new image wait for construction. Since the dependency 1b is smaller than 2a, as shown in fig. 7 (d), the next restoration is 1 st block, but the restoration (or construction) of b block in the new image is again dependent on the data (dependency) 1b in 1 st block, the dependency 1b of 1 st block needs to be backed up to the backup area (i.e., the original data 1b in 1 st block is copied to the backup area), and then the restoration operation is performed. After the restoration operation of the 1 st block is performed, the restoration of the 2 nd block, that is, the construction of the new mirror image b block, can be completed according to the data (1 b and 4 b) in the backup area, so that the restoration of all the original data blocks in the original data packet in the old mirror image is completed, that is, the state shown in fig. 7 (e) is reached.
In another possible implementation, when performing packet block restoration, the IoT device may first determine an original data packet to which the currently restored original data block belongs; then judging whether a dependency relationship exists between the original data packet and the next original data packet to be restored; if not, after the original data packet is restored, releasing the backup area occupied by the original data packet. For example, as shown in fig. 8, there may be no dependencies between some data blocks and other data blocks (i.e., there is no dependency between data block a, b, c, d and data blocks 5, 6, 7, 8, and there is no dependency between data block e, f, g, h and data blocks 1, 2, 3, 4), and space in the spare area occupied by the group after the group upgrade to which these data blocks (1, 2, 3, 4, a, b, c, d) belong is released for use in the next group upgrade. According to the dependency relationship shown in FIG. 8, 1-4 blocks can be upgraded firstly, then 5-8 blocks can be upgraded, and the backup area used by the previous 1-4 blocks can be reused by 5-8 blocks, so that flash occupation in the upgrading process is reduced.
In another possible implementation manner, in order to verify whether the old image is legal during the firmware upgrade process and ensure recovery of the firmware upgrade after the IoT device is powered down, in the above embodiment, the PC side may first calculate the checksum of each block (including the new image and the old image) according to the restoration order when updating the initial differential upgrade package, and then package the checksum into the final generated target differential upgrade package. And when the firmware is upgraded, the IoT device sequentially checks the checksum of each data block to be restored on the old image of the device side, so as to determine whether the old image of the device side is legal and to which degree the old image is restored, so that the device side can restore continuously after power failure.
Referring to fig. 9, the state transition of the checksum shown in fig. 9 is a legal state transition, and the state transition without marking the path is an illegal state transition, which can be understood as a check failure and the need to stop the upgrade operation. Such a result may be caused by flash corruption, or mismatch of an old image and a differential upgrade package (patch package), or the like. Wherein the New state is several times, which represents how many blocks have been restored before, the restoration algorithm needs to continue to perform the restoration operation at the designated breakpoint. For the Unknown state in fig. 9, the present embodiment is explained as follows:
in one possible implementation, a restore algorithm running in an IoT device needs to backup the contents of a data block to a backup area before each data block is restored, and then perform a restore operation. If during restore, the IoT device suddenly fails when writing the old image, resulting in the corruption of the data for that block, the data in the backup area plays a significant role. Thus, if the IoT device is detecting that the state is Unknown, it is performing exactly this block power down on behalf of the previous restore operation. At this time, it is necessary to restore the contents of the backup area to the corresponding position of the old image and then continue the restore. Specifically, in the process of restoring the target original data block into the second upgrade data, if the device is powered down, the IoT device reads the target original data block from the backup area of the differential upgrade package after powering up the device; and then restoring the target original data block to the corresponding position of the old mirror image, and continuing restoring the target original data block.
It should be emphasized that, during each firmware upgrade, the Unknown state described above may only appear once, and then must be transferred to the Old state (or the Unknown state is the restore state corresponding to the last original data block waiting to be restored), otherwise, the mirror image is illegal.
As another possible implementation, the above-described restoration algorithm may employ a CRC32 algorithm. Since the output of CRC32 is 32-bit integer, collision will necessarily occur when the number of samples exceeds 2≡32, resulting in a situation that the lower probability of judging the recovery point error occurs in the power-down recovery scene. With the restoration algorithm, if the restoration point is wrong, the fatal problem that the file is restored to the brick can occur. To solve this problem, in this embodiment, during execution of the above restoration algorithm, if the checksum of the new image of the id block is consistent with the checksum of the old image of the id block, the IoT device records the block_id of the id block to flash after the restoration of the id block is completed. Then when checking the checksum every time power is applied, if the checksum of the new image of the id block is consistent with the checksum of the old image of the id block, and the block_id of the id block is restored before the recorded block_id, judging that the id block is the new block; and otherwise, judging the block as an old block.
Specifically, after analyzing the differential upgrade packet, the IoT device determines a target original data block corresponding to the data block identifier in the old image and second upgrade data corresponding to the new image; then, a first checksum corresponding to the target original data block (namely, the checksum of the old image of the id block) and a second checksum corresponding to the second upgrade data (namely, the checksum of the new image of the id block) are obtained; and when the first checksum is matched with the second checksum, executing the operation of acquiring the second upgrading data according to the restoring command, namely restoring the target original data block.
Fig. 10 shows a schematic structural diagram of a differential upgrade apparatus provided by the present application. The differential upgrade apparatus 10 provided by the present application includes: the device comprises a data reading module, a command acquisition module, a data reduction module and a differential upgrading module;
the data reading module 101 is configured to sequentially read data block identifiers that represent a restoration sequence of data blocks in the differential upgrade packet, where the restoration sequence is determined in advance according to a dependency of the data blocks to be restored in the old image;
the command obtaining module 102 is configured to determine a restore command corresponding to the data block identifier;
The data restoration module 103 is configured to obtain, according to the restoration command, first upgrade data and/or second upgrade data, where the first upgrade data is data that is added by a new image compared with the old image, and the second upgrade data is data obtained by restoring an original data block in the old image;
the differential upgrade module 104 is configured to cover a data area to be upgraded in the old image with the first upgrade data and/or the second upgrade data.
In one possible implementation, the dependency is the number of bytes of data in each data block to be restored that is required by the new image.
In a possible implementation manner, the command obtaining module 102 is further configured to read corresponding compressed data from the differential upgrade package according to the data block identifier; and determining a restore command according to the compressed data.
In a possible implementation manner, the command obtaining module 102 is further configured to decompress the compressed data to obtain decompressed data; and reading a restore command from the decompressed data.
In a possible implementation manner, the data restoring module 103 is further configured to read a first type of command in the restoring commands, and obtain first upgrade data from the decompressed data according to the first type of command;
And/or reading a second class command in the restoring command, restoring the target original data block into second upgrading data in the old image according to the second class command, wherein the target original data block is determined in the old image according to the data block identification.
In a possible implementation manner, the data reduction module 103 is further configured to read a third type of command in the reduction commands; and copying the corresponding target original data block in the old image to a backup area of the differential upgrade package for waiting to restore according to the third class command.
In a possible implementation manner, the data reduction module 103 is further configured to determine a target original data block in the old image according to the third class command; acquiring first target data to be backed up in the target original data block, wherein the first target data is all or part of data in the target original data block; copying the first target data to a backup area of the differential upgrade package to wait for reduction.
In a possible implementation manner, the data restoring module 103 is further configured to read a second type of command in the restoring commands; determining a field range indicated by the second type command; and restoring the target original data block into second upgrading data according to the second type command in the old image according to the field range.
In a possible implementation manner, the data restoration module 103 is further configured to determine, according to the field range, second target data that needs to be restored in the target original data block, where the second target data is all or part of data in the target original data block; and restoring the second target data into a second upgrading data root according to the second class command in the old mirror image to acquire first frame image data acquired by the TOF sensor in the target working mode. Correspondingly, the differential upgrade module 804 is further configured to perform differential upgrade based on the first frame image data.
In a possible implementation manner, the data restoration module 103 is further configured to determine an original data packet to which the current restored original data block belongs; judging whether a dependency relationship exists between the original data packet and the next original data packet to be restored; if not, after the original data packet is restored, releasing the backup area occupied by the original data packet.
In a possible implementation manner, the data reduction module 103 is further configured to, in a process of reducing the target original data block to the second upgrade data, if the device is powered down, read the target original data block from the backup area of the differential upgrade package after the device is powered up; and restoring the target original data block to the corresponding position of the old mirror image, and continuing restoring the target original data block.
In a possible implementation manner, the data restoration module 103 is further configured to determine that the data block identifies a corresponding target original data block in the old image and corresponding second upgrade data in the new image; acquiring a first checksum corresponding to the target original data block and a second checksum corresponding to the second upgrade data; and when the first checksum is matched with the second checksum, executing the operation of acquiring second upgrading data according to the restoring command.
Fig. 11 shows a schematic structural diagram of a differential upgrade apparatus provided by the present application. The differential upgrading device 11 provided by the application comprises: the system comprises a mirror image comparison module, a mirror image splitting module, a dependency acquisition module and a differential packet updating module;
the image comparison module 110 is configured to obtain an initial differential upgrade package according to difference data between the new image and the old image;
the image splitting module 111 is configured to split a new image to obtain a plurality of data blocks, where the data blocks include first class data and/or second class data, and the second class data is obtained by converting original data in the old image;
the dependency obtaining module 112 is configured to determine, for each data block containing the second class data, a dependency of an original data block corresponding to the second class data in the old image, and a restore command for converting the original data block;
The differential packet updating module 113 is configured to update the initial differential upgrade packet according to the dependency and the restore command, and obtain a target differential upgrade packet.
In a possible implementation manner, the image splitting module 111 is further configured to perform equal-length splitting on the new image according to a preset byte length, so as to obtain a plurality of data blocks.
In a possible implementation manner, the mirror splitting module 111 is further configured to obtain a flash unit, and determine the preset byte length according to the flash unit.
In a possible implementation manner, the dependency obtaining module 112 is further configured to determine, for each data block including the second class data, target original data corresponding to the second class data in the old image; acquiring the byte number of the target original data; determining an original data block to which the target original data belongs; taking the byte number as the dependency of the original data block
In a possible implementation manner, the differential packet updating module 113 is configured to determine a restoration order of the data blocks to be restored in the old image according to the dependency degree; generating a data block identifier of each data block to be restored according to the restoration sequence; and updating the initial differential upgrade package according to the data block identifier and the restore command to obtain a target differential upgrade package.
In a possible implementation manner, the differential packet updating module 113 is configured to compress the restore command to obtain compressed data; and writing the data block identifier and the compressed data into the initial differential upgrade package after being associated, and dividing a backup area in the initial differential package to obtain a target differential upgrade package.
It should be understood that the electronic device herein is embodied in the form of functional modules. The term "module" herein may be implemented in software and/or hardware, and is not specifically limited thereto. For example, a "module" may be a software program, a hardware circuit, or a combination of both that implements the functionality described above. The hardware circuitry may include application specific integrated circuits (application specific integrated circuit, ASICs), electronic circuits, processors (e.g., shared, proprietary, or group processors, etc.) and memory for executing one or more software or firmware programs, merged logic circuits, and/or other suitable components that support the described functions.
The present application also provides an electronic device including: one or more processors; a memory; and one or more computer programs, wherein the one or more computer programs are stored in the memory, the one or more computer programs comprising instructions that, when executed by the electronic device, cause the electronic device to perform the differential upgrade method as described in the first aspect or any of the possible implementations of the second aspect or the second aspect.
The application also provides a computer readable storage medium having a computer program stored therein, which when executed by a processor causes the processor to perform the differential upgrade method as described in the first aspect or any of the possible implementations of the second aspect or the second aspect.
The present application also provides a chip comprising a processor and a data interface, the processor reading instructions stored on a memory through the data interface, performing the differential upgrade method as described in any one of the above first aspect or the possible implementation manners of the first aspect or any one of the above second aspect or the possible implementation manners of the second aspect.
Optionally, the chip may further include a memory, where the memory stores instructions, and the processor is configured to execute the instructions stored on the memory, where the instructions, when executed, are configured to perform the method of differential upgrade as described in the first aspect or any one of the possible implementations of the second aspect or the second aspect.
The memory may be read-only memory (ROM), other types of static storage devices that can store static information and instructions, random access memory (random access memory, RAM) or other types of dynamic storage devices that can store information and instructions, electrically erasable programmable read-only memory (electrica llyerasable programmable read-only memory, EEPROM), compact disc read-only memory (compact disc read-only memory) or other optical disk storage, optical disk storage (including compact disc, laser disc, optical disc, digital versatile disc, blu-ray disc, etc.), magnetic disk storage media, or any other magnetic storage device that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer, etc.
In the embodiment of the application, "and/or" describes the association relation of the association objects, which means that three relations can exist, for example, a and/or B, and can mean that a exists alone, a exists together with B, and B exists alone. Wherein A, B may be singular or plural. The character "/" generally indicates that the context-dependent object is an "or" relationship. "at least one of the following" and the like means any combination of these items, including any combination of single or plural items. For example, at least one of a, b and c may represent: a, b, c, a-b, a-c, b-c, or a-b-c, wherein a, b, c may be single or plural.
Those of ordinary skill in the art will appreciate that the various elements and algorithm steps described in the embodiments disclosed herein can be implemented as a combination of electronic hardware, computer software, and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
It will be clear to those skilled in the art that, for convenience and brevity of description, specific working procedures of the above-described systems, apparatuses and units may refer to corresponding procedures in the foregoing method embodiments, and are not repeated herein.
In several embodiments provided by the present application, any of the functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a read-only memory (ROM), a random access memory (random access memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The foregoing is merely exemplary embodiments of the present application, and any person skilled in the art may easily conceive of changes or substitutions within the technical scope of the present application, which should be covered by the present application. The protection scope of the present application shall be subject to the protection scope of the claims.

Claims (22)

1. A method of differential upgrade, the method comprising:
sequentially reading data block identifiers representing the data block restoration sequence in the differential upgrade package, wherein the restoration sequence is determined in advance according to the dependence of the data blocks to be restored in the old mirror image;
determining a restoring command corresponding to the data block identifier;
acquiring first upgrade data and/or second upgrade data according to the restore command, wherein the first upgrade data is added data of a new image compared with the old image, and the second upgrade data is data obtained after restoring an original data block in the old image;
and covering a data area to be upgraded in the old image by the first upgrade data and/or the second upgrade data.
2. The differential upgrade method of claim 1, wherein the determining the restore command to which the data block identification corresponds comprises:
Reading corresponding compressed data from the differential upgrade package according to the data block identifier;
and determining a restore command according to the compressed data.
3. The differential upgrade method of claim 2, wherein said determining a restore command from said compressed data comprises:
decompressing the compressed data to obtain decompressed data;
and reading a restore command from the decompressed data.
4. The differential upgrade method of claim 3, wherein said obtaining the first upgrade data and/or the second upgrade data according to the restore command comprises:
reading a first type command in the restore command, and acquiring first upgrade data from the decompressed data according to the first type command;
and/or the number of the groups of groups,
and reading a second class command in the restoring command, restoring the target original data block into second upgrading data in the old image according to the second class command, and determining the target original data block in the old image according to the data block identification.
5. The differential upgrade method of claim 3, wherein before said obtaining the first upgrade data and/or the second upgrade data according to the restore command, further comprises:
Reading a third type command in the restore commands;
and copying the corresponding target original data block in the old image to a backup area of the differential upgrade package for waiting to restore according to the third class command.
6. The differential upgrade method of claim 5, wherein copying the corresponding target original data block in the old image to the backup area of the differential upgrade package for waiting for restore according to the third class command comprises:
determining a target original data block in the old image according to the third class command;
acquiring first target data to be backed up in the target original data block, wherein the first target data is all or part of data in the target original data block;
copying the first target data to a backup area of the differential upgrade package to wait for reduction.
7. The differential upgrade method of claim 4, wherein said reading a second class of commands in said restore commands and restoring the target original data block to the second upgrade data in said old image according to said second class of commands comprises:
reading a second class command in the restore commands;
determining a field range indicated by the second type command;
And restoring the target original data block into second upgrading data according to the second type command in the old image according to the field range.
8. The differential upgrade method of claim 7, wherein said restoring the target original data block in said old image according to said field range as said second class command to the second upgrade data comprises:
determining second target data to be restored in the target original data block according to the field range, wherein the second target data is all or part of data in the target original data block;
and restoring the second target data into second upgrading data according to the second class command in the old image.
9. The differential upgrade method of claim 4, wherein the method further comprises:
determining an original data packet to which the current restored original data block belongs;
judging whether a dependency relationship exists between the original data packet and the next original data packet to be restored;
if not, after the original data packet is restored, releasing the backup area occupied by the original data packet.
10. The differential upgrade method of claim 4, wherein the method further comprises:
In the process of restoring the target original data block into the second upgrading data, if the equipment is powered down, after the equipment is powered up, reading the target original data block from a backup area of the differential upgrading packet;
and restoring the target original data block to the corresponding position of the old mirror image, and continuing restoring the target original data block.
11. The differential upgrade method according to any one of claims 1 to 10, wherein before the second upgrade data is acquired according to the restore command, the differential upgrade method includes:
determining a target original data block corresponding to the data block identification in the old image and second upgrading data corresponding to the new image;
acquiring a first checksum corresponding to the target original data block and a second checksum corresponding to the second upgrade data;
and executing the step of acquiring second upgrading data according to the restoring command when the first checksum is matched with the second checksum.
12. A differential upgrade method as claimed in any one of claims 1 to 10, wherein said degree of dependence is the number of bytes of data required by said new image in each data block to be restored.
13. A method of differential upgrade, the method comprising:
obtaining an initial differential upgrade package according to the difference data between the new image and the old image;
splitting the new mirror image to obtain a plurality of data blocks, wherein the data blocks comprise first class data and/or second class data, and the second class data is obtained by converting original data in the old mirror image;
for each data block containing the second class data, determining the dependence of the second class data on the corresponding original data block in the old image, and converting the original data block into a restore command;
and updating the initial differential upgrade package according to the dependence degree and the reduction command to obtain a target differential upgrade package.
14. The differential upgrade method of claim 13, wherein splitting the new image to obtain a plurality of data blocks comprises:
and equally dividing the new mirror image according to the preset byte length to obtain a plurality of data blocks.
15. The differential upgrade method as claimed in claim 14, wherein the performing equal-length splitting on the new image according to a preset byte length includes, before obtaining a plurality of data blocks:
And obtaining a flash erasing unit, and determining the preset byte length according to the flash erasing unit.
16. The differential upgrade method of claim 13, wherein said determining, for each data block containing said second class data, the dependency of the corresponding original data block of said second class data in said old image comprises:
for each data block containing the second class data, determining target original data corresponding to the second class data in the old mirror image;
acquiring the byte number of the target original data;
determining an original data block to which the target original data belongs;
and taking the byte number as the dependency of the original data block.
17. The differential upgrade method of claim 13, wherein the updating the initial differential upgrade package according to the dependency and the restore command to obtain a target differential upgrade package comprises:
determining the restoration sequence of the data blocks to be restored in the old mirror image according to the dependency degree;
generating a data block identifier of each data block to be restored according to the restoration sequence;
and updating the initial differential upgrade package according to the data block identifier and the restore command to obtain a target differential upgrade package.
18. The differential upgrade method of claim 17, wherein the updating the initial differential upgrade package according to the data block identification and the restore command to obtain a target differential upgrade package comprises:
compressing the restore command to obtain compressed data;
and writing the data block identifier and the compressed data into the initial differential upgrade package after being associated, and dividing a backup area in the initial differential package to obtain a target differential upgrade package.
19. A differential upgrade apparatus, comprising: the device comprises a data reading module, a command acquisition module, a data reduction module and a differential upgrading module;
the data reading module is used for sequentially reading data block identifiers representing the data block restoration sequence in the differential upgrade package, and the restoration sequence is determined in advance according to the dependence of the data blocks to be restored in the old mirror image;
the command acquisition module is used for determining a restoring command corresponding to the data block identifier;
the data restoring module is configured to obtain first upgrade data and/or second upgrade data according to the restoring command, where the first upgrade data is data that is added by a new image compared with the old image, and the second upgrade data is data obtained by restoring an original data block in the old image;
The differential upgrading module is used for covering a data area to be upgraded in the old image through the first upgrading data and/or the second upgrading data.
20. A differential upgrade apparatus, comprising: the system comprises a mirror image comparison module, a mirror image splitting module, a dependency acquisition module and a differential packet updating module;
the image comparison module is used for obtaining an initial differential upgrade package according to the difference data between the new image and the old image;
the image splitting module is used for splitting a new image to obtain a plurality of data blocks, wherein the data blocks comprise first-class data and/or second-class data, and the second-class data is obtained by converting original data in the old image;
the dependency degree obtaining module is configured to determine, for each data block containing the second class data, a dependency degree of an original data block corresponding to the second class data in the old image, and a restore command for converting the original data block;
the differential packet updating module is used for updating the initial differential upgrade packet according to the dependence degree and the reduction command to obtain a target differential upgrade packet.
21. An electronic device, comprising: one or more processors; a memory; and one or more computer programs, wherein the one or more computer programs are stored in the memory, the one or more computer programs comprising instructions, which when executed by the electronic device, cause the electronic device to perform the differential upgrade method of any of claims 1-12 or 13-18.
22. A computer readable storage medium, wherein a computer program is stored in the computer readable storage medium, which when executed by a processor causes the processor to perform the differential upgrade method of any one of claims 1 to 12 or 13 to 18.
CN202211154066.7A 2022-09-21 2022-09-21 Differential upgrading method and device, electronic equipment and readable storage medium Pending CN116700739A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211154066.7A CN116700739A (en) 2022-09-21 2022-09-21 Differential upgrading method and device, electronic equipment and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211154066.7A CN116700739A (en) 2022-09-21 2022-09-21 Differential upgrading method and device, electronic equipment and readable storage medium

Publications (1)

Publication Number Publication Date
CN116700739A true CN116700739A (en) 2023-09-05

Family

ID=87834487

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211154066.7A Pending CN116700739A (en) 2022-09-21 2022-09-21 Differential upgrading method and device, electronic equipment and readable storage medium

Country Status (1)

Country Link
CN (1) CN116700739A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111104149A (en) * 2018-10-25 2020-05-05 华为技术有限公司 Firmware upgrading method and device and terminal
CN111240722A (en) * 2020-01-07 2020-06-05 翱捷科技(上海)有限公司 Method for upgrading firmware over the air, and terminal, server and system applied by same
CN113094077A (en) * 2019-12-23 2021-07-09 深圳Tcl数字技术有限公司 System differential upgrading method and device, intelligent terminal and storage medium
CN113721967A (en) * 2021-08-30 2021-11-30 苏州磐联集成电路科技股份有限公司 Differential packet generation method, differential packet generation device, and upgrade method
WO2022048511A1 (en) * 2020-09-02 2022-03-10 上海飞奥燃气设备有限公司 Differential upgrade method for intelligent gas meter firmware

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111104149A (en) * 2018-10-25 2020-05-05 华为技术有限公司 Firmware upgrading method and device and terminal
CN113094077A (en) * 2019-12-23 2021-07-09 深圳Tcl数字技术有限公司 System differential upgrading method and device, intelligent terminal and storage medium
CN111240722A (en) * 2020-01-07 2020-06-05 翱捷科技(上海)有限公司 Method for upgrading firmware over the air, and terminal, server and system applied by same
WO2022048511A1 (en) * 2020-09-02 2022-03-10 上海飞奥燃气设备有限公司 Differential upgrade method for intelligent gas meter firmware
CN113721967A (en) * 2021-08-30 2021-11-30 苏州磐联集成电路科技股份有限公司 Differential packet generation method, differential packet generation device, and upgrade method

Similar Documents

Publication Publication Date Title
JP4364790B2 (en) Byte-level file difference detection and update algorithm
US11531535B2 (en) Firmware upgrade method and apparatus, and terminal
US7661102B2 (en) Method for reducing binary image update package sizes
US8296535B2 (en) Generating incremental program updates
CN105009067B (en) Managing operations on units of stored data
US20060106888A1 (en) Data update system, differential data creating device and program for data update system, updated file restoring device and program
CN109710185B (en) Data processing method and device
KR20120063455A (en) Apparatus and method for updating firmware
CN111475195A (en) Firmware upgrading method, device and system
US9577666B2 (en) Method and system
WO2023221735A1 (en) Embedded device firmware updating method, embedded device, and development end device
CN113377401A (en) Method and tool for packaging version file of embedded device
US8413132B2 (en) Techniques for resolving read-after-write (RAW) conflicts using backup area
CN113468118B (en) File increment storage method, device and storage medium based on blockchain
WO2019041891A1 (en) Method and device for generating upgrade package
CN116700739A (en) Differential upgrading method and device, electronic equipment and readable storage medium
US20220350576A1 (en) Compression Of Firmware Updates
US11327741B2 (en) Information processing apparatus
CN114661298A (en) Automatic public method generation method, system, device and medium
CN113468144A (en) Database migration method and migration device thereof
CN117170722B (en) Address discontinuity firmware upgrading method, device and system
CN112433743B (en) File updating method and device, electronic equipment and storage medium
CN117170726A (en) Differential upgrading method of low resources and embedded equipment
CN108989813A (en) A kind of high efficiency of compression/decompression method, computer installation and storage medium
CN114065703A (en) File processing method and device, computer equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination