Restoration method of differential file and electronic device

By adaptively determining the number of parallel restore threads and reasonably allocating RAM memory areas, the restoration efficiency of differential files is improved, solving the problem of limited RAM in terminal devices, and is suitable for firmware upgrades of lightweight embedded devices.

CN117707588BActive Publication Date: 2025-10-17HONOR DEVICE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211101979.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-09
Publication Date
2025-10-17
Estimated Expiration
2042-09-09

AI Technical Summary

Technical Problem

When upgrading firmware using differential package upgrade, how can we improve the efficiency of restoring differential files, especially when the terminal device has limited RAM space?

Method used

The electronic device adaptively determines the number of parallel restoration threads according to the block size of the differential file and the RAM memory space size, and performs restoration processing in parallel through multiple threads, utilizing multiple RAM memory areas for data processing, including a security buffer to ensure data accuracy.

Benefits of technology

It improves the efficiency of restoring differential files and reduces RAM memory consumption, making it suitable for lightweight embedded devices with limited RAM resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117707588B_ABST
    Figure CN117707588B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a differential file restoration method and an electronic device. In the method, the differential file includes at least one group of data compression blocks, and each data compression block in each group is divided based on a preset block size before compression; when the electronic device restores the differential file, the parallel number k of restoration threads is first determined according to the block size and the RAM space size, and then the differential file is restored in parallel using k restoration threads, wherein each restoration thread uses a group of RAM spaces corresponding to the restoration thread to restore at least one group of data compression blocks. In this way, when the differential file is restored, the electronic device can adaptively determine the parallel number of restoration threads according to the RAM memory space used for differential file restoration, and improve the restoration efficiency of the differential file through parallel processing of multiple threads.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of smart terminal technology, and in particular to a differential file restoration method and electronic device. Background Art

[0002] In order to improve the functions of terminal devices, enhance device stability, and patch device defects or vulnerabilities (bugs), it is often necessary to upgrade the firmware of the terminal devices.

[0003] Currently, over-the-air (OTA) technology is commonly used to perform online firmware upgrades on terminal devices. OTA upgrade methods mainly include full package upgrades and differential package upgrades. To improve the efficiency of upgrade package transmission and firmware upgrades, terminal devices often use differential package upgrades, which only upgrades the different parts of the firmware.

[0004] When terminal devices use differential package upgrades for online firmware upgrades, they first need to restore the differential files. This operation requires RAM (Random Access Memory), and the RAM space available for differential file restoration varies from terminal device to terminal device. Therefore, when using differential package upgrades for firmware upgrades, improving the efficiency of differential file restoration is a challenge that needs to be addressed. Summary of the Invention

[0005] To address the above technical issues, embodiments of the present application provide a differential file restoration method and electronic device. In this method, the electronic device adaptively determines the number of parallel restoration threads based on the block size corresponding to the differential file and the size of the RAM memory space used for differential file restoration, and performs the restoration process in parallel using multiple threads, thereby improving the efficiency of differential file restoration.

[0006] In a first aspect, an embodiment of the present application provides a method for restoring a differential file. The method includes:

[0007] The electronic device obtains a differential file; wherein the differential file includes at least one set of data compression blocks, the set of data compression blocks including difference Diff data compression blocks and / or newly added Extra data compression blocks, and the data compression blocks are divided based on a preset block size before being compressed;

[0008] The electronic device determines the number k of parallel restoration threads according to the block size and the size of RAM space of the electronic device used for restoring the differential file, and allocates a set of RAM space for each restoration thread;

[0009] The electronic device uses k reduction threads to perform reduction processing on the differential file in parallel, wherein each reduction thread uses a corresponding set of RAM spaces to perform reduction processing on at least one set of data compression blocks, and writes the data obtained after reduction processing into a target file.

[0010] In this way, the electronic device adaptively determines the number of parallel reduction threads according to the block size corresponding to the differential file and the size of the RAM memory space used for reduction of the differential file, and performs reduction processing in parallel through multiple threads, thereby improving the reduction efficiency of the differential file.

[0011] According to a first aspect, the set of RAM spaces can include a first RAM memory area, a second RAM memory area, a third RAM memory area, and a fourth RAM memory area; wherein the sizes of the first RAM memory area and the second RAM memory area are the block size; the second RAM memory area and the fourth RAM memory area are safety buffer areas of the first RAM memory area and the third RAM memory area, respectively; each reduction thread shares a fifth RAM memory area, and the fifth RAM memory area is used to run a data compression algorithm.

[0012] In this way, the electronic device can implement data compression block reduction operations based on smaller RAM memory spaces. Moreover, by setting safety buffer areas for the first RAM memory area and the third RAM memory area, the accuracy of data processing is not affected even in the case of data compression.

[0013] According to the first aspect, or any one of the implementation manners of the first aspect, the electronic device determines the number of parallel reduction threads k according to the block size and the size of the RAM space used by the electronic device for reduction of the differential file, k = [(M-N1) / (zonesize+N2)]; wherein M is the size of the RAM space used by the electronic device for reduction of the differential file, N1 is the size of the fifth RAM memory area, zonesize is the block size, N2 is the size of the safety buffer area, and [] is the rounding operation.

[0014] According to a first aspect, or any possible implementation mode of the first aspect, the Diff data corresponding to the Diff data compression block is obtained based on the first operation; the restoring thread restores the set of data compression blocks, which can include: the restoring thread sequentially restores the Diff data compression block or the Extra data compression block in the set of data compression blocks according to the parsing order; when each Diff data compression block is parsed, the Diff data corresponding to the Diff data compression block is operated on the existing data based on the second operation to obtain the first target data, which is written into the target file; wherein the existing data is the data matched with the Diff data compression block in the existing file corresponding to the differential file, and the second operation is the inverse operation of the first operation; when each Extra data compression block is parsed, the Extra data compression block is decompressed to obtain the second target data, which is written into the target file.

[0015] For example, the first operation is subtraction, and the second operation is addition.

[0016] In this way, when the electronic device restores the differential file, each restoring thread can take the Diff data compression block or the Extra data compression block as an independent differential restoration processing unit, so that the RAM memory consumption of the terminal side is smaller, and the terminal side can realize the differential data restoration function through a smaller RAM memory space.

[0017] According to the first aspect, or any possible implementation mode of the first aspect, the electronic device can perform the second operation on the Diff data corresponding to the Diff data compression block and the existing data to obtain the first target data, which is written into the target file, which can include: the electronic device temporarily stores the Diff data compression block in the first RAM memory area; the electronic device performs data decompression processing on the Diff data compression block, and temporarily stores the obtained Diff data block in the third RAM memory area; the electronic device reads the existing data corresponding to the Diff data block from the existing file and temporarily stores it in the first RAM memory area; the electronic device performs the second operation on the data in the first RAM memory area and the data in the third RAM memory area, and temporarily stores the obtained first target data in the third RAM memory area; and the electronic device writes the first target data temporarily stored in the third RAM memory area into the target file.

[0018] According to the first aspect, or any one of the implementations of the first aspect, the electronic device decompresses the Extra data compression block to obtain second target data, and writes the second target data into the target file, which can include: the electronic device temporarily stores the Extra data compression block in the first RAM memory area; the electronic device decompresses the Extra data compression block to obtain second target data, and temporarily stores the second target data in the third RAM memory area; and the electronic device writes the second target data temporarily stored in the third RAM memory area into the target file.

[0019] According to the first aspect, or any one of the implementations of the first aspect, each restore thread uses a corresponding set of RAM space to restore at least one set of data compression blocks, which can include: the electronic device creates a linked list for each restore thread according to the number of sets of data compression blocks included in the differential file and the serial numbers of the sets of data compression blocks, so that the restore thread restores at least one set of data compression blocks according to the corresponding linked list; and in the linked list, the data part of a node is filled with the serial number of a set of data compression blocks and the first address in the target file where the restore data corresponding to the set of data compression blocks is written.

[0020] According to the first aspect, or any one of the implementations of the first aspect, the data structure of the differential file includes a header, a control block, and a set of data compression blocks described by the control block; the header is filled with the magic number and the block size of the differential file; the control block is filled with a first pointer offset and a second pointer offset; the first pointer offset is used to determine the data reading starting address corresponding to a set of data compression blocks in the existing file; and the second pointer offset is used to determine the data writing starting address corresponding to a set of data compression blocks in the target file.

[0021] According to the first aspect, or any one of the implementations of the first aspect, the electronic device determines each set of data compression blocks to be processed by each restore thread according to the remainder of the serial number of the data compression block divided by the number of parallel threads.

[0022] According to a first aspect, or any possible implementation mode of the first aspect, each restoring thread uses a set of RAM spaces corresponding to the restoring thread to restore at least one set of data compression blocks, which can include: each restoring thread creates a first sub-thread and a second sub-thread; the electronic device uses the set of RAM spaces corresponding to the restoring thread through the first sub-thread and the second sub-thread to sequentially restore Diff data compression blocks or Extra data compression blocks included in the set of data compression blocks; wherein when the second sub-thread executes to a target stage, the first sub-thread continues to restore the data compression blocks in the set of data compression blocks; when the first sub-thread executes to the target stage, the second sub-thread continues to restore the data compression blocks in the set of data compression blocks; wherein the target stage is to write the data temporarily stored in the third RAM memory area into the target file.

[0023] In this way, when each restoring thread restores the set of data compression blocks, the restoring process of the next data compression block does not need to start until the restoring process of the previous data compression block is completely finished, so that the first RAM memory area no longer exists waiting delay, the restoring time of the set of data compression blocks is reduced, and the processing efficiency of the restoring thread is improved.

[0024] In a second aspect, an embodiment of the present application provides an electronic device. The electronic device includes: one or more processors; a memory; and one or more computer programs, wherein the one or more computer programs are stored in the memory, and when the computer programs are executed by the one or more processors, the electronic device performs the restoring method of the differential file as in the first aspect and any possible implementation mode of the first aspect.

[0025] The second aspect and any possible implementation mode of the second aspect correspond to the first aspect and any possible implementation mode of the first aspect, respectively. The technical effects corresponding to the second aspect and any possible implementation mode of the second aspect can refer to the technical effects corresponding to the first aspect and any possible implementation mode of the first aspect described above, which will not be described here.

[0026] In a third aspect, an embodiment of the present application provides a computer readable storage medium. The computer readable storage medium includes a computer program, and when the computer program runs on the electronic device, the electronic device performs the restoring method of the differential file as in the first aspect and any possible implementation mode of the first aspect.

[0027] The third aspect and any possible implementation mode of the third aspect correspond to the first aspect and any possible implementation mode of the first aspect, respectively. The technical effects corresponding to the third aspect and any possible implementation mode of the third aspect can refer to the technical effects corresponding to the first aspect and any possible implementation mode of the first aspect described above, which will not be described here.

[0028] In a fourth aspect, an embodiment of the present application provides a computer program product, comprising a computer program, which when executed by a computer, causes the computer to perform the method for restoring a differential file according to the first aspect and any one of the implementation manners of the first aspect.

[0029] The fourth aspect and any one of the implementation manners of the fourth aspect correspond to the first aspect and any one of the implementation manners of the first aspect respectively. For details of the technical effects caused by the fourth aspect and any one of the implementation manners of the fourth aspect, reference can be made to the technical effects caused by the first aspect and any one of the implementation manners of the first aspect, which will not be described here.

[0030] In a fifth aspect, the present application provides a chip, comprising a processing circuit, a receiving pin and a sending pin. The receiving pin and the sending pin communicate with each other through an internal connection path. The processing circuit executes the method for restoring a differential file according to the first aspect and any one of the implementation manners of the first aspect, to control the receiving pin to receive a signal and to control the sending pin to send a signal.

[0031] The fifth aspect and any one of the implementation manners of the fifth aspect correspond to the first aspect and any one of the implementation manners of the first aspect respectively. For details of the technical effects caused by the fifth aspect and any one of the implementation manners of the fifth aspect, reference can be made to the technical effects caused by the first aspect and any one of the implementation manners of the first aspect, which will not be described here. BRIEF DESCRIPTION OF DRAWINGS

[0032] Figure 1 An application scenario schematic diagram is exemplarily shown;

[0033] Figure 2 A flowchart of restoring a firmware file is exemplarily shown;

[0034] Figure 3 A differential principle schematic diagram is exemplarily shown;

[0035] Figure 4 A data structure schematic diagram of a differential file is exemplarily shown;

[0036] Figure 5 A restoring principle schematic diagram is exemplarily shown;

[0037] Figure 6 A data restoring operation schematic diagram is exemplarily shown;

[0038] Figure 7 A differential file generation method schematic diagram is provided in the embodiment;

[0039] Figure 8A data structure example of a differential file provided for the embodiment;

[0040] Figure 9 A generation method of a differential file provided for the embodiment;

[0041] Figure 10 A data structure example of a differential file provided for the embodiment;

[0042] Figure 11a A generation method of a differential file provided for the embodiment;

[0043] Figure 11b A data block division method provided for the embodiment;

[0044] Figure 12 A restoration method of a differential file provided for the embodiment;

[0045] Figure 13 A restoration operation of a differential file provided for the embodiment;

[0046] Figure 14 A RAM space occupation diagram when data is restored based on Diff data compression blocks provided for the embodiment;

[0047] Figure 15 A RAM space occupation diagram when data is restored based on Extra data compression blocks provided for the embodiment;

[0048] Figure 16 A RAM space occupation diagram when data is restored based on Diff data compression blocks provided for the embodiment;

[0049] Figure 17 A RAM space occupation diagram when data is restored based on Extra data compression blocks provided for the embodiment;

[0050] Figure 18 A RAM space occupation diagram when data is restored based on Diff data compression blocks provided for the embodiment;

[0051] Figure 19 A RAM space occupation diagram when data is restored based on Extra data compression blocks provided for the embodiment;

[0052] Figure 20 A schematic diagram of an application scenario exemplarily shown;

[0053] Figure 21a A RAM space division diagram for restoring thread parallelism exemplarily shown;

[0054] Figure 21b A schematic diagram of RAM space division for restoring thread parallelism, shown by way of example;

[0055] Figure 22 A schematic diagram of differential data parallel restoration, shown by way of example;

[0056] Figure 23 A schematic diagram of a data structure of a differential file, provided by the present embodiment;

[0057] Figure 24a A schematic diagram of changes in the occupancy state of a RAM memory region when data is restored based on Diff data compression blocks, provided by the present embodiment;

[0058] Figure 24b A schematic diagram of changes in the occupancy state of a RAM memory region when data is restored based on Extra data compression blocks, provided by the present embodiment;

[0059] Figure 25 A schematic diagram of a processing flow of a restoration thread, provided by the present embodiment;

[0060] Figure 26a A schematic diagram of a processing flow of a first sub-thread in a restoration thread, provided by the present embodiment;

[0061] Figure 26b A schematic diagram of a processing flow of a second sub-thread in a restoration thread, provided by the present embodiment;

[0062] Figure 27a A schematic diagram of a duration of continuous data compression block restoration based on single-thread, provided by the present embodiment;

[0063] Figure 27b A schematic diagram of a duration of continuous data compression block restoration based on multi-thread, provided by the present embodiment;

[0064] Figure 28 A schematic diagram of a hardware structure of an electronic device, shown by way of example;

[0065] Figure 29 A schematic diagram of a software structure of an electronic device, shown by way of example;

[0066] Figure 30 A schematic diagram of a structure of an apparatus, shown by way of example. DETAILED DESCRIPTION

[0067] With reference to the drawings and the embodiments of the present application, the technical solutions in the embodiments of the present application will be described clearly and completely. Obviously, the described embodiments are some of the embodiments of the present application, but not all of the embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of the present application.

[0068] The term "and / or" used herein is merely used to describe an associated relationship with associated objects, and means that three relationships can exist, for example, A and / or B can mean that A exists alone, A and B exist together, and B exists alone.

[0069] The terms "first" and "second" and the like in the description and claims of the embodiments of the present application are used to distinguish different objects, and are not used to describe a specific order of the objects. For example, the first target object and the second target object are used to distinguish different target objects, and are not used to describe a specific order of the target objects.

[0070] In the embodiments of the present application, the words "exemplary" or "for example" are used to mean serving as an example, instance, or illustration. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be construed as being more preferred or advantageous than other embodiments or designs. In fact, the word "exemplary" or "for example" is used to present concepts in a concrete manner.

[0071] In the description of the embodiments of the present application, unless otherwise specified, "a plurality of" means two or more. For example, a plurality of processing units means two or more processing units; a plurality of systems means two or more systems.

[0072] When the terminal device performs online firmware upgrade, if the OTA differential package upgrade mode is used for firmware upgrade, the terminal device needs to have the capability of restoring the differential file, that is, generating the corresponding new version of the firmware file (hereinafter referred to as the new firmware file) according to the differential file and the existing firmware file (that is, the old version of the firmware file, hereinafter referred to as the old firmware file) corresponding to the differential file. Further, the terminal device can complete firmware upgrade according to the new version of the firmware file.

[0073] Figure 1 An application scenario is exemplarily shown, and an online firmware upgrade of a smart watch 100 is taken as an example for explanation and description. The smart watch 100 is a low-end smart terminal device (which can also be a lightweight embedded device) without independent networking function, and the smart watch 100 can communicate with a smart phone 200 through Bluetooth. Referring to Figure 1In the smart phone 200, an application APP corresponding to the smart watch 100 is installed, which is used to connect the smart watch 100 and the smart phone 200, download applications or files for the smart watch 100, and the like. Further, the smart watch 100 can communicate with the OTA server 300 through the application APP. For example, the smart watch 100 can periodically query the OTA server 300 through the application APP whether there is an upgrade differential package corresponding to the smart watch 100. If it is found that there is an upgrade differential package corresponding to the smart watch 100, the smart watch 100 can send an upgrade differential package download request to the OTA server 300 through the application APP to download the corresponding upgrade differential package through the smart phone 200 when the online upgrade condition (for example, the power state, the networking state, the Bluetooth state, and the like meet the preset condition) is met. The smart phone can send the downloaded upgrade differential package to the smart watch 100 through Bluetooth technology. Further, the smart watch 100 can restore the upgrade differential package and complete the firmware upgrade based on the new version of the firmware file obtained after the restoration.

[0074] With reference back to Figure 1 The upgrade differential package corresponding to the smart watch 100 can be made based on the differential data package making platform 400 and uploaded to the OTA server 300. In some implementations, the upgrade differential package can also be generated in the OTA server 300, which is not limited in the embodiment. Whether the upgrade differential package is made based on the differential data package making platform 400 or the OTA server 300, the upgrade differential package is generated based on the new and old firmware files and the corresponding differential algorithm.

[0075] In the application scenario as shown in Figure 1 The smart phone 200 is a smart terminal device with independent networking function, which is used as a relay device of the smart watch 100 and the OTA server 300.

[0076] In some implementations, if the smart watch 100 has independent networking capability, it can also directly communicate with the OTA server 300 to query the OTA server 300 whether there is an upgrade differential package corresponding to the smart watch 100, or download the corresponding upgrade differential package from the OTA server 300.

[0077] In Figure 1The application scenario shown is explained by taking the smart watch 100 as an example of a terminal device that has a firmware online upgrade requirement. The terminal device that has a firmware online upgrade requirement can also be a smart bracelet, a smart earphone, or other wearable devices, or any embedded node device in the Internet of Everything scenario (for example, a node device that collects temperature, humidity, and other information), and the present embodiment does not make a limitation. If the terminal device that has a firmware online upgrade requirement is a low-end device that does not have independent networking functionality, it needs to communicate with the OTA server through a relay device to download the upgrade differential package through the relay device. If the terminal device that has a firmware online upgrade requirement is a low-end device that has independent networking functionality, it can directly communicate with the OTA server to download the upgrade differential package.

[0078] Figure 2 An exemplary flowchart of firmware file differential restoration is shown.

[0079] As shown in Figure 2 On the server side (or tool side), the server performs differential processing on pairs of new firmware files and old firmware files according to a preset differential algorithm (for example, the BSDiff algorithm), to obtain a differential file (Patch file). In this way, the server can obtain multiple differential files corresponding to firmware upgrades. The number of differential files is related to the firmware to be upgraded, and the present embodiment does not make a limitation. Furthermore, the server can compress and package the multiple differential files to generate an upgrade differential package. The upgrade differential package can include multiple compressed differential files, and description files corresponding to the multiple differential files, and the like.

[0080] When the terminal needs to perform firmware upgrade, it requests the server to download the upgrade differential package. After the terminal receives the upgrade differential package, it decompresses the upgrade differential package to obtain the differential files. Taking one differential file as an example, the terminal restores the differential file according to the old firmware file matched with the differential file, to obtain the corresponding new firmware file. In this way, the terminal side can obtain multiple new firmware files, and can further perform firmware upgrade operations based on the multiple new firmware files.

[0081] Continuing to refer to Figure 2 In the firmware file differential restoration process, the file differential operation and the differential package compression operation are performed on the server side, and the differential package decompression operation and the differential file restoration operation are performed on the terminal side.

[0082] When the terminal is a lightweight embedded device (such as a wearable device), its RAM resource is limited, which seriously affects the efficiency of the differential package decompression and restoration process, and even can cause the problem of firmware upgrade failure due to the too large differential file. Therefore, if the memory consumption involved in the differential file restoration process can be smaller, it will be better suitable for the firmware upgrade scenario of lightweight embedded devices.

[0083] The following takes the BSDiff algorithm as an example to explain the basic principles of the differential restoration algorithm.

[0084] (I) Differential principle (Bsdiff principle)

[0085] Among them, the core idea of the differential principle is to use as much data in the old file as possible and add as little new data as possible to construct a new file.

[0086] Figure 3 An exemplary file differential process based on the Bsdiff principle is shown.

[0087] Referring to Figure 3 By comparing the old file data and the new file data, the longest similar substring (i.e. substring) in both is determined. For example, the data 01_new in the new file data is "1010101010101010101", and the data 01_old in the old file data is "1010101110101011101". The data 01_new in the new file data and the data 01_old in the old file data are a longest similar substring. For another example, the data 03_new in the new file data and the data 02_old in the old file data are another longest similar substring. For example, in the new file data, between the data 01_new and the data 03_new is the data 02_new, and there is no similar substring to the data 02_new in the old file data, so the data 02_new is the newly added data in the new file. Similarly, in the new file data, the data 04_new is also newly added data.

[0088] Therefore, according to the similar substrings in the new file data and the old file data, the difference data (Diff data) can be calculated, and the difference data and the newly added data (Extra data) together constitute the incremental update data (Patch data). For example, Figure 3As shown, the Diff data 01 in the Patch data can be obtained by subtracting the data 01_old in the old file from the data 01_new in the new file; the Diff data 02 in the Patch data can be obtained by subtracting the data 02_old in the old file from the data 03_new in the new file. Meanwhile, the data 02_new in the new file can be directly used as the Extra01 data in the Patch data, and the data 04_new in the new file can be directly used as the Extra02 data in the Patch data. In this way, all the Diff data and the Extra data can be obtained based on the new file data and the old file data, and the Patch data can be composed.

[0089] It should be noted that, in general, the Diff data and the Extra data in the Patch data obtained according to the BSDiff algorithm are in pairs, and each piece of Diff data is followed by a piece of Extra data. It can be understood that the Patch data includes at least one set of incremental update data, and each set of incremental update data generally includes Diff data and Extra data. In some special cases, the Diff data and the Extra data can not be in pairs, for example, the last set of incremental update data in the Patch data can only include Diff data or can only include Extra data.

[0090] It should be noted that the order and position offset of each Diff data and Extra data in the Patch data are consistent with the new file data. Therefore, the Diff data and the Extra data in the Patch data can be restored in sequence, and the new file data corresponding to the Patch data can be obtained.

[0091] It should be noted that, in the Patch data obtained according to the BSDiff algorithm,

[0092] After the Patch data is obtained based on the new file data and the old file data, the Patch data can be encoded to obtain a corresponding Patch file.

[0093] In Figure 3 an exemplary data structure of a Patch file is shown, which includes a total encoding header, encoding information corresponding to a set of Diff data and Extra data, and the Diff data and the Extra data. The encoding information corresponding to a set of Diff data and Extra data is used to describe the set of Diff data and Extra data, for example, to describe the byte length of the Diff data, the byte length of the Extra data, and the pointer offset for reading data in the old file.

[0094] Figure 4 An exemplary data structure of a Patch file is shown. As shown, the data structure of the Patch file includes a Header, a control block, a Diff block and an Extra block. Figure 4

[0095] The Header includes 8 bytes, which are used to fill a magic number. Here, the magic number is used to determine the file type.

[0096] Each control block includes 24 bytes, which are used to describe a group of Diff blocks and Extra blocks. That is, the data recorded in the control block can be used as the encoding information of the group of Diff blocks and Extra blocks described by the control block. The first 8 bytes of the control block are used to fill the byte length of the Diff block described by the control block; the middle 8 bytes of the control block are used to fill the byte length of the Extra block described by the control block; and the last 8 bytes of the control block are used to fill a pointer offset, which is used to determine the position of reading data (data used for addition operation with Diff data) in the old file.

[0097] For example, each control block can be represented by (x, y, z), where x is the byte length of the Diff block, which is used to indicate that x bytes are read from the old file and the Diff block for addition operation; y is the byte length of the Extra block, which is used to indicate that y bytes are read from the Extra block to be added to the new file; and z is the offset of the pointer of the old file, which is used to determine the position of the pointer for next reading of data from the old file, that is, to determine the offset of the pointer after the current reading of data from the old file. When the offset represented by z is based on the current position of the pointer, z can represent the direction of the offset by using positive and negative values, for example, a positive value represents forward offset, and a negative value represents backward offset.

[0098] The Diff block is used to record Diff data, that is, to record the difference between the old file and a longest similar substring in the new file.

[0099] The Extra block is used to record Extra data, that is, to record the new data in the new file.

[0100] Before the multiple Patch files are packaged, the Patch files can also be compressed.

[0101] In a possible implementation, the data structure is as shown. Figure 4 ​When the Patch file shown is compressed, a compression method by data block can be used, that is, each control block (control block 1 or control block 2 or control block n), each Diff block (Diff block 1 or Diff block 2 or Diff block n) and each Extra block (Extra block 1 or Extra block 2 or Extra block n) is compressed respectively.

[0102] In a possible implementation, the data structure is as shown in FIG. 4, and the Patch file is compressed by using a compression method by data block. Figure 4 When the Patch file shown is compressed, a compression method by data block can be used, that is, each control block (control block 1 or control block 2 or control block n), each Diff block (Diff block 1 or Diff block 2 or Diff block n) and each Extra block (Extra block 1 or Extra block 2 or Extra block n) is compressed respectively.

[0103] In a possible implementation, the data structure is as shown in FIG. 4, and the Patch file is compressed by using a compression method by data block. Figure 4 When the Patch file shown is compressed, a compression method by data block can be used, that is, each control block (control block 1 or control block 2 or control block n), each Diff block (Diff block 1 or Diff block 2 or Diff block n) and each Extra block (Extra block 1 or Extra block 2 or Extra block n) is compressed respectively.

[0104] In a possible implementation, the data structure is as shown in FIG. 4, and the Patch file is compressed by using a compression method by data block. Figure 4 When the Patch file shown is compressed, a compression method by data block can be used, that is, each control block (control block 1 or control block 2 or control block n), each Diff block (Diff block 1 or Diff block 2 or Diff block n) and each Extra block (Extra block 1 or Extra block 2 or Extra block n) is compressed respectively.

[0105] In this way, after the server respectively performs difference processing on each group of new firmware files and old firmware files to obtain a plurality of Patch files, the plurality of Patch files are compressed and packaged to obtain corresponding upgrade difference packages, so that the terminal can query and download the upgrade difference packages.

[0106] (ii) Restoration principle (bspatch principle)

[0107] Corresponding to the above-mentioned bsdiff principle, the BSDiff algorithm performs patch file restoration based on the bspatch principle. The bspatch principle can be understood as the inverse process of the bsdiff principle, that is, patch file restoration can be understood as the inverse process of patch file generation.

[0108] Figure 5 The file restoration process based on the bspatch principle is exemplified.

[0109] Reference Figure 5 , decode the Patch file data to obtain the corresponding Patch data. The process of decoding the Patch file data here can be understood as the inverse process of encoding the Patch data.

[0110] Among them, the data structure of the Patch file can be referred to above. Figure 4 The explanation of the above is omitted here. Therefore, in the Patch data obtained by decoding the Patch file, the Diff data and Extra data appear in pairs, with each block of Diff data followed by a block of Extra data. Moreover, the order of each pair of Diff data and Extra data in the Patch data is consistent with the new file data.

[0111] When a terminal receives a patch file, it parses the header and determines the file type based on the magic number in the header. It then decodes the data using the data structure corresponding to that file type. After decoding each block of Diff data or Extra data, the terminal restores the file based on that block.

[0112] Reference Figure 4 In a patch file, each control block describes a pair of diff and extra blocks. The terminal can retrieve the corresponding diff and extra data based on the content recorded in the control block, and restore the data in the new file based on the retrieved diff and extra data.

[0113] Taking the Diff01 data and the Extra01 data in the Patch data as examples, when restoring new file data, the Diff01 data is read, and data01_old data matching the Diff01 data in the old file is read, and the Diff01 data and the data01_old data are added to obtain data01_new which is written into the new file; the Extra01 data is read and directly written into the new file as data02_new. Similarly, the Diff02 data is read, and data02_old data matching the Diff02 data in the old file is read, and the Diff02 data and the data02_old data are added to obtain data03_new which is written into the new file; the Extra02 data is read and directly written into the new file as data04_new. In this way, all data in the new file can be obtained based on the Patch data in the Patch file and the related data in the old file.

[0114] The following takes (x, y, z) used in each control block as an example, and the following Figure 6 The process of restoring based on the Patch file is explained.

[0115] As shown in Figure 6 In the Patch file, the content filled in the control block1 is (x1, y1, z1), which is used to describe the Diff block1 and the Extra block1. The byte length of the Diff block1 is x1, and the byte length of the Extra block1 is x2.

[0116] The terminal parses (x1, y1, z1) filled in the control block1 in the Patch file. First, the terminal continues to read x1 length of Diff data in the Patch file, and reads x1 length of data in the old file, and adds the two pieces of x1 length data to obtain x1 length of new file data, which is written into the new file (or referred to as the target file). Then, the terminal continues to read y1 length of Extra data in the Patch file, which is directly written into the new file as y1 length of new file data.

[0117] For example, as shown in Figure 4In the shown file data structure, control block 0 can also be included after the header and before control block 1, in which (0, 0, z0) is filled. In control block 0, z0 is filled, which is used to determine the pointer offset for reading the x1-length data in the old file. Since the current position of the old file pointer is the start position of the old file, the old file pointer is offset by z0 from the start position of the old file, and the x1-length old file data matching the x1-length Diff data can be read in the old file.

[0118] Similarly, the terminal continues to parse the Patch file and reads (x2, y2, z2) filled in control block 2. First, the terminal continues to read the x2-length Diff data in the Patch file and the x2-length data in the old file, and performs addition operation on the two x2-length data to obtain the x2-length new file data, which is written into the new file. In which, the old file pointer is offset by z1 from the current position, and the x2-length old file data corresponding to the x2-length Diff data can be read in the old file. Then, the terminal continues to read the y2-length Extra data in the Patch file as the y2-length new file data and directly writes it into the new file.

[0119] In this way, the terminal can obtain a new file according to the Patch file and the old file, and complete the restoration process of the new file.

[0120] In this way, the terminal can obtain a new file according to the Patch file and the old file, and complete the restoration process of the new file.

[0121] However, in the Patch file obtained according to the BSDiff algorithm, since the Diff block is determined based on the longest similar substring of the new file and the old file, and the Extra block is determined based on the newly added data in the new file, the byte length of the Diff block and the Extra block is not fixed and unlimited, and the byte length is related to the difference between the new file and the old file, which can be tens of KB, or even hundreds or even tens of thousands of KB.

[0122] When the terminal restores the patch file, the required RAM memory space size is directly related to the byte length of the diff block or the extra block. The larger the byte length of the diff block or the extra block, the larger the required RAM memory space of the terminal when processing the diff block or the extra block. For example, the byte length of the diff block is 200 KB, and the terminal needs to allocate at least 200 KB of RAM memory space to process the diff block. When the RAM memory space of the terminal is limited, the terminal cannot or hardly meet the processing requirement of the diff block or the extra block. Therefore, the data structure of the patch file based on the BSDiff algorithm is extremely unfriendly to the firmware differential package upgrade scene of the lightweight embedded device.

[0123] To solve the above technical problems, so that the terminal RAM memory consumption involved in the differential file restoration process can be smaller, the embodiment provides a differential file generation method, which is applied to the server side. Wherein, the server mentioned here can be understood as any electronic device for generating a differential file.

[0124] Figure 7 An exemplary file differential flow based on the Bsdiff principle provided by the embodiment is shown.

[0125] As described above, by comparing the old file data and the new file data, the longest similar sub-strings (i.e. sub-strings) in the two are determined. For example, the data 01_new in the new file data is "1010101010101010101", and the data 01_old in the old file data is "1010101110101011101". The data 01_new in the new file data and the data 01_old in the old file data are a longest similar sub-string. For another example, the data 03_new in the new file data and the data 02_old in the old file data are another longest similar sub-string. For example, in the new file data, between the data 01_new and the data 03_new is the data 02_new, and there is no similar sub-string to the data 02_new in the old file data, so the data 02_new is newly added data in the new file. Similarly, in the new file data, the data 04_new is also newly added data.

[0126] Therefore, the difference data (Diff data) can be calculated according to the similar sub-strings in the new file data and the old file data, and the difference data and the newly added data (Extra data) together constitute the incremental update data (Patch data). For example, Figure 7As shown, the Diff data 01 in the Patch data can be obtained by subtracting the data 01_old in the old file from the data 01_new in the new file; the Diff data 02 in the Patch data can be obtained by subtracting the data 02_old in the old file from the data 03_new in the new file. Meanwhile, the data 02_new in the new file can be directly used as the Extra01 data in the Patch data, and the data 04_new in the new file can be directly used as the Extra02 data in the Patch data. In this way, all the Diff data and the Extra data can be obtained based on the new file data and the old file data, and the Patch data can be composed.

[0127] It should be noted that the Diff data and the Extra data in the Patch data obtained according to the BSDiff algorithm are in pairs, and each block of Diff data is followed by a block of Extra data. Moreover, the position offset of each pair of Diff data and Extra data in the Patch data is consistent with the new file data.

[0128] After obtaining the Patch data, the server side performs data blocking on each Diff data and Extra data in the Patch data according to the zone size of the Diff data and the Extra data. Each Diff data block and Extra data block is the minimum independent processing data unit when the terminal restores the differential file.

[0129] The zone size can be determined according to the RAM memory space on the terminal side, and specifically can be determined according to the size of the continuous RAM memory space available for the terminal to restore the differential file. The zone size can also be understood as the maximum processing byte number supported by the RAM memory space of the terminal when the Diff data is restored.

[0130] With reference to the foregoing description, the server side can obtain the Patch data according to the BSDiff algorithm, and then perform data blocking on each Diff data and Extra data in the Patch data according to the zone size of the Diff data and the Extra data. Figure 7For the Diff data 01 in the Patch data, the Diff data 01 is divided into n1 Diff data blocks according to the zonesize. In the n1 Diff data blocks, the data size (or byte length) of the first (n1-1) Diff data blocks is zonesize, and the data size of the last Diff data block is less than or equal to zonesize. The data ordering of the n1 Diff data blocks is the same as that of the Diff data 01. Similarly, for the Extra data 01 in the Patch data, the Extra data 01 is also divided into n2 Extra data blocks according to the zonesize. In the n1 Extra data blocks, the data size of the first (n2-1) Extra data blocks is zonesize, and the data size of the last Extra data block is less than or equal to zonesize. The data ordering of the n2 Extra data blocks is also the same as that of the Extra data 01.

[0131] For example, in the case that the RAM memory area for the terminal device to restore the differential file is not multiplexed, the continuous RAM memory space for the terminal device to restore the differential file can be divided into a first RAM memory area, a second RAM memory area, a third RAM memory area, and a fourth RAM memory area. The first RAM memory area, the second RAM memory area, and the third RAM memory area are collectively used for data storage operations involved in Diff data block restoration processing and data storage operations involved in Extra data block restoration processing, and the fourth RAM memory area is used for data decompression operations.

[0132] Suppose that the RAM memory space for the terminal device to restore the differential file is M, and the memory space required by the data compression algorithm for data decompression operations is N1 (i.e., the memory space of the fourth RAM memory area is N1), then the first RAM memory area, the second RAM memory area, and the third RAM memory area can each occupy the remaining RAM memory space, i.e., the memory space of the first RAM memory area, the second RAM memory area, and the third RAM memory area is (M-N1) / 3. At this time, the zonesize can be set to (M-N1) / 3. For example, when M is 200 KB and N1 is 20 KB, the RAM memory space is divided as follows: the first RAM memory area is 60 KB, the second RAM memory area is 60 KB, the third RAM memory area is 60 KB, and the fourth RAM memory area is 20 KB. At this time, zonesize = 60 KB, indicating that the terminal device can perform data restoration processing on 60 KB of Diff data or Extra data at a time.

[0133] For example, in the case that the terminal device uses the RAM memory region multiplexing for differential file restoration, the RAM memory can be sequentially divided into a first RAM memory region, a second RAM memory region, a third RAM memory region, a fourth RAM memory region and a fifth RAM memory region. The first RAM memory region and the third RAM memory region are used for data storage operations involved in the Diff data chunk restoration processing and the Extra data chunk restoration processing, and the fifth RAM memory region is used for data decompression operation. The second RAM memory region is located between the first RAM memory region and the third RAM memory region, and is a safety buffer region of the first RAM memory region. The fourth RAM memory region is located between the third RAM memory region and the fifth RAM memory region, and is a safety buffer region of the third RAM memory region.

[0134] Suppose that the RAM memory space used by the terminal device for differential file restoration is M, the memory space required by the data compression algorithm for data decompression operation is N1 (i.e. the memory space of the fifth RAM memory region is N1), and the memory space required by the safety buffer region is N2. The first RAM memory region and the third RAM memory region can each occupy half of the remaining space, i.e. the memory space of the first RAM memory region and the third RAM memory region is (M-N1-N2*2) / 2. At this time, zonesize can be set to (M-N1-N2*2) / 2. For example, when M is 200 KB, N1 is 16 KB, and N2 is 2 KB, the RAM memory space is divided as follows: the first RAM memory region is 90 KB, the second RAM memory region is 2 KB, the third RAM memory region is 90 KB, the fourth RAM memory region is 2 KB, and the fifth RAM memory region is 16 KB. At this time, zonesize = 90 KB, indicating that the terminal device can perform data restoration processing on 90 KB of Diff data or Extra data at a time.

[0135] In some special cases, the size of the compressed data is larger than that of the uncompressed data. Since the size of the Diff data chunk or the Extra data chunk before compression is the same as the size of the first RAM memory region and the third RAM memory region, once the size of the Diff data compression chunk or the Extra data compression chunk becomes larger, it will overflow the first RAM memory region or the third RAM memory region and affect the normal data restoration processing. Therefore, the safety buffer region can effectively avoid the problem of data restoration abnormality caused by the overflow of the RAM memory region due to the increase in the size of the Diff data compression chunk or the Extra data compression chunk.

[0136] As another example, in the case where the RAM memory area of ​​the terminal device is reused for differential file restoration, the continuous RAM memory space used by the terminal device for differential file restoration can be divided into a first RAM memory area, a third RAM memory area and a fifth RAM memory area, wherein the first RAM memory area and the third RAM memory area are jointly used for data storage operations involved in the Diff data block restoration processing, and for data storage operations involved in the Extra data block restoration processing, and the fifth RAM memory area is used for data decompression operations.

[0137] Assume that the RAM memory space used by the terminal device for differential file restoration is M, and the memory space required for the data compression algorithm to perform data decompression operations is N1 (that is, the memory space of the third RAM memory area is N1), then the first RAM memory area and the second RAM memory area can evenly divide the remaining space, that is, the memory space of the first RAM memory area and the second RAM memory area are both (M-N1) / 2. At this time, the zonesize can be set to (M-N1) / 2. For example, when M is 20KB and N1 is 16KB, the division of the RAM memory space is: 2KB for the first RAM memory area, 2KB for the second RAM memory area, and 16KB for the third RAM memory area. At this time, zonesize = 2KB, which means that the terminal device can perform data restoration processing on 2KB of Diff data or Extra data at a time.

[0138] In some extreme cases, if the continuous RAM memory space available for differential file restoration on the terminal device is extremely small, such as 20 KB, the safety buffer area may not be set.

[0139] How to restore data based on the various areas of RAM memory space applied for by the terminal will be explained in detail in the patch file restoration process described later and will not be repeated here.

[0140] After the Diff data and Extra data in the Patch data are divided into blocks and compressed, the divided and compressed Patch data can be encoded to obtain a corresponding Patch file.

[0141] In the embodiment, the data compression algorithm for compressing the Diff data blocks or the Extra data blocks adopts a data compression algorithm with low memory consumption and fast decompression speed, such as a lossless decompression algorithm like LZMA (Lempel-Ziv-Markov chain-Algorithm), miniLZO (Lempel-Ziv-Oberhumer), etc., so as to reduce the RAM memory space occupied by the terminal device when restoring the differential file data.

[0142] In the embodiment, the data compression algorithm for compressing the Diff data blocks or the Extra data blocks adopts a data compression algorithm with low memory consumption and fast decompression speed, such as a lossless decompression algorithm like LZMA (Lempel-Ziv-Markov chain-Algorithm), miniLZO (Lempel-Ziv-Oberhumer), etc., so as to reduce the RAM memory space occupied by the terminal device when restoring the differential file data. Figure 7 The data structure of the Patch file is exemplarily shown in the embodiment, which includes a total encoding header, encoding information corresponding to the plurality of Diff data compression blocks and the plurality of Extra data compression blocks, and the plurality of Diff data compression blocks and the plurality of Extra data compression blocks. The encoding information corresponding to the plurality of Diff data compression blocks and the plurality of Extra data compression blocks is used to describe the total byte length of the plurality of Diff data blocks before compression, the total byte length of the plurality of Extra data blocks before compression, the byte length of each Diff data block after compression, the byte length of each Extra data block after compression, and the pointer offset for reading the data corresponding to the Diff data compression block in the old file.

[0143] The total encoding header can include a zonesize field in addition to the magic number, and the value of the zonesize field is used to indicate the block size of the Diff data and the Extra data, which can be used by the terminal to combine the encoding information to perform data addressing when restoring the data. For example, the terminal can determine the offset of the old file pointer based on the value of the zonesize field to read the old file data corresponding to each Diff data compression block in the old file. For another example, the terminal can determine the number of Diff data blocks or the number of Extra data blocks based on the value of the zonesize field and the total byte length of the plurality of Diff data blocks before compression or the total byte length of the plurality of Extra data blocks before compression.

[0144] In another example, the zonesize field is not included in the total encoding header, but is set in each encoding information, which is not limited in the embodiment.

[0145] In another example, the number of Diff data compression blocks, the number of Extra data compression blocks, the byte length of each Diff data compression block before and after compression, and the byte length of each Extra data compression block before and after compression are set in each encoding information.

[0146] As to the data structure of the patch file, the embodiment does not limit the description information (or coding information) of the diff data compression blocks and the extra data compression blocks, as long as the terminal can perform data addressing in the patch file and the old file based on the corresponding description information, and restore the target file based on each diff data compression block and each extra data compression block.

[0147] Figure 8 An exemplary data structure of a patch file provided by the embodiment is shown. As shown in Figure 8 the data structure of the patch file includes a header (Header), a control block (zone), diff data, and extra data.

[0148] The Header includes 16 bytes, which are used to fill a magic number and a zone size.

[0149] Each zone includes 24 bytes, which are used to describe a plurality of diff data compression blocks and a plurality of extra data compression blocks. The plurality of diff data compression blocks and the plurality of extra data compression blocks correspond to a pair of diff data and extra data in the patch data obtained based on the BSDiff algorithm. The data recorded in the zone can be used as the coding information of the plurality of diff data compression blocks and the plurality of extra data compression blocks described by the zone. The first 8 bytes of the zone can record the total byte length of the diff data corresponding to the plurality of diff data compression blocks before compression, and the description information (such as the byte length after compression) of each diff data compression block; the middle 8 bytes of the zone can record the total byte length of the extra data corresponding to the plurality of extra data compression blocks before compression, and the description information (such as the byte length after compression) of each extra data compression block; and the last 8 bytes of the zone are used to fill a pointer offset, which is used to determine the position of reading data (i.e., data used for addition operation with the diff data block) in the old file.

[0150] In an optional implementation, the pointer offset filled in the last 8 bytes of the zone can be an offset determined based on the current position of the pointer, and the offset direction is identified by the positive or negative of the offset.

[0151] In another optional implementation, the pointer offset filled in the last 8 bytes of the zone can be an offset determined based on the starting position of the file.

[0152] The diff data includes one or more diff data compression blocks, and each diff data compression block is used to record the data after compression of the diff data block.

[0153] The one or more extra data compression blocks in the extra data include one or more extra data compression blocks, each of which records the data of the extra data block after compression.

[0154] In this way, in the patch file, each diff data compression block or extra data compression block can be an independently processable data unit when the terminal restores the data, thereby reducing the RAM memory consumption when the terminal restores the data.

[0155] In an optional implementation, when the patch file is generated based on the patch data, each diff data block and extra data block can also be compressed, and block encoding information can be added to each data compression block. The block encoding information can be the block header of the data compression block, and the corresponding diff compression data or extra compression data can be the block data of the data compression block.

[0156] Taking the diff data 01 and the extra data 01 in the patch data as an example, Figure 9 An exemplary data structure of a patch file is shown. As shown in Figure 9 For the diff data 01 in the patch data, the diff data 01 is divided into n1 diff data blocks according to the zone size, and each diff data block is compressed to obtain a corresponding diff data compression block. In the patch file, the encoding information for describing each diff data compression block is filled before each diff data compression block. For example, the encoding information of the diff data compression block can include but is not limited to the data size (csize) before compression and the data size (usize) after compression of the diff data block.

[0157] Similarly, continuing to refer to Figure 9 For the extra data 01 in the patch data, the extra data 01 is divided into n2 extra data blocks according to the zone size, and each extra data block is compressed to obtain a corresponding extra data compression block. In the patch file, the encoding information for describing each extra data compression block is filled before each extra data compression block. For example, the encoding information of the extra data compression block can include but is not limited to the data size (csize) before compression and the data size (usize) after compression of the extra data block.

[0158] The same is true for other Diff data and Extra data in the Patch data, which will not be described here. Thus, for each Diff data compression block and each Extra data compression block, the terminal can parse the corresponding block encoding information and treat it as an independently processable data unit to perform data restoration operations. How to restore the target file using the Diff data compression block or the Extra data compression block as a data processing unit will be described in detail in the subsequent restoration process of the Patch file, which will not be described here.

[0159] It should be noted that, with reference to Figure 9 , the encoding information 01 is used to describe the Diff data 01 and the Extra data 01, that is, to describe the total data size of the Diff data compression block 1-n1 before compression, the total data size of the Extra data compression block 1-n2 before compression, and the pointer offset for reading the old file data corresponding to the Diff data 02 in the old file.

[0160] Figure 10 An exemplary data structure of a Patch file provided by the present embodiment is shown. As Figure 10 shown, the data structure of the Patch file includes a header (Header), a control block (zone), Diff data, and Extra data.

[0161] The Header includes 16 bytes, which are used to fill the magic number and zone size.

[0162] Each zone includes 24 bytes, which are used to describe a plurality of Diff block compression data and a plurality of Extra block compression data. The plurality of Diff block compression data before block compression is the Diff data, and the plurality of Extra block compression data before block compression is the Extra data, which correspond to a pair of Diff data and Extra data in the Patch data. The data recorded in the zone can be used as the encoding information of the plurality of Diff block compression data and the plurality of Extra block compression data it describes. The first 8 bytes of the zone can record the total byte length of the Diff data before block compression of the plurality of Diff block compression data; the middle 8 bytes of the zone can record the total byte length of the Extra data before block compression of the plurality of Extra compression data; and the last 8 bytes of the zone are used to fill the pointer offset, which is used to determine the position of the data (used for addition operation with the Diff data block) in the old file.

[0163] Exemplarily, each zone can be represented by (x, y, z), where x is the total byte length of the Diff data before the plurality of Diff chunk compressed data described by the zone is chunk compressed; y is the total byte length of the Extra data before the plurality of Extra chunk compressed data described by the zone is chunk compressed; and z is the offset of the old file pointer, used to determine the pointer position of the old file data corresponding to the first Diff chunk data described by the zone from the old file. The pointer offset can be an offset determined based on the current position of the pointer, and the offset direction can be identified by the positive or negative of the offset, or the offset can be an offset determined based on the start position of the file, which is not limited in the embodiment.

[0164] In an alternative example, each zone can also be compressed individually, and the compressed zone is referred to as a control compression block. The control compression block can include a block header and block data, where the block data is used to record the compressed data corresponding to the content of the zone, and the block header is used to record the compression description information corresponding to the control compression block. The compression description information can include the data size of the compressed zone (or the data size of the control compression block), and the compression description information can include but is not limited to the data size before compression (csize) and the data size after compression (usize).

[0165] The Diff data includes one or more data compression chunks, and each data compression chunk includes a block header and block data, where the block data is used to record the compressed data of the Diff data chunk, and the block header is used to record the compression description information corresponding to the compressed data of the Diff data chunk. The compression description information can include but is not limited to the data size before compression (csize) and the data size after compression (usize). The compression description information can only include the data size after compression (usize) of the Diff data compression chunk, i.e., only the data size of the Diff data compression chunk.

[0166] The Extra data includes one or more Extra data compression chunks, and each Extra data compression chunk includes a block header and block data, where the block data is used to record the compressed data of the Extra data chunk, and the block header is used to record the compression description information corresponding to the compressed data of the Extra data chunk. The compression description information can include but is not limited to the data size before compression (csize) and the data size after compression (usize). The compression description information can only include the data size after compression (usize) of the Extra data compression chunk, i.e., only the data size of the Extra data compression chunk.

[0167] In this way, each Diff data compression block or Extra data compression block in the Patch file can be an independently processable data unit when the terminal restores data, thereby reducing the RAM memory consumption when the terminal restores data.

[0168] It should be noted that the Patch file provided by the embodiments of the present application is only an exemplary expression, and is not limited thereto.

[0169] In an example, based on the data structure of the Patch file described above, the Header can further include a data compression block maximum length (LengthMAX) field in addition to the zonesize field. The value of the LengthMAX field is used to indicate the maximum data size of each data compression block (including Diff data compression blocks and Extra data compression blocks).

[0170] If each zone is also compressed separately, the value of the LengthMAX field is used to indicate the maximum data size of each data compression block (including control compression blocks, Diff data compression blocks, and Extra data compression blocks).

[0171] When the terminal parses the Patch file, the value of the LengthMAX field can be used to determine whether the received Patch file is incorrect. For example, if the size of a Diff data compression block or an Extra data compression block in the Patch file exceeds the value of the LengthMAX field, the terminal can determine that the Patch file is incorrect.

[0172] In another example, based on the data structure of the Patch file described above, the Header can further include a target file data total length (NewfileLength) field in addition to the zonesize field. The value of the NewfileLength field is used to indicate the total data length of the target file obtained based on the Patch file.

[0173] When the terminal restores the target file based on the Patch file, the value of the NewfileLength field can be used to determine whether the restored target file is correct. For example, if the data length of the target file obtained based on the Patch file is less than or greater than the value of the NewfileLength field, the terminal can determine that the restored target file is incorrect.

[0174] In another example, based on the data structure of the Patch file described above, the data structure of the Patch file can further include a tail portion. The tail portion can include a check field. The value of the check field is used to indicate the hash value of the target file obtained based on the Patch file.

[0175] When restoring a target file based on a patch file, the terminal can also determine whether the restored target file is correct based on the value of the checksum field. For example, if the hash value of the target file restored based on the patch file differs from the value of the checksum field, the terminal can determine that the restored target file is incorrect.

[0176] The above explanation uses the generation of a single patch file as an example. Similarly, corresponding patch files can be generated based on other pairs of old and new firmware files, thereby obtaining individual patch files corresponding to differential upgrade packages. When a terminal requests a download of the differential upgrade package from the server, the server can package these patch files to generate the corresponding differential upgrade package and send the differential upgrade package to the terminal via the wireless network.

[0177] In the differential file generation method provided in this embodiment, the Patch data obtained based on the BSDiff algorithm is re-encoded, and the Diff data and Extra data are compressed in blocks based on the zonesize, so that the size of the minimum data processing unit when the Patch file is restored can be controlled. Among them, the zonesize can be flexibly set according to the RAM memory space of the lightweight embedded device, which can be better suitable for the firmware upgrade scenario of the lightweight embedded device.

[0178] Considering that when the terminal side performs differential file restoration, the RAM memory space applied for may include a safety buffer area, this embodiment further provides a method for dividing the Diff data and Extra data into blocks based on zonesize.

[0179] Figure 11a The file difference process based on the Bsdiff principle provided by this embodiment is exemplarily shown.

[0180] in, Figure 11a and Figure 7 The file difference process shown is the same, the difference lies in the way the Diff data blocks and Extra data blocks are divided. For any details not explained here, please refer to the above and will not be repeated here.

[0181] Reference Figure 11aTaking Diff data 01 in the Patch data as an example, it is divided into n1 Diff data blocks according to zonesize. Among these n1 Diff data blocks, the data size (or byte length) of the first (n1-1) Diff data blocks is zonesize, and the data size of the last Diff data block may be larger than zonesize. Among them, the data sorting of these n1 Diff data blocks is the same as that of Diff data 01. Similarly, for Extra data 01 in the Patch data, it is also divided into n2 Extra data blocks according to zonesize. Among these n1 Extra data blocks, the data size of the first (n2-1) Extra data blocks is zonesize, and the data size of the last Extra data block may be larger than zonessize. Among them, the data sorting of these n2 Extra data blocks is also the same as that of Extra data 01.

[0182] Continue to refer to Figure 11b In (1), continuing to take Diff data 01 as an example, it is divided into (n1+1) Diff data blocks according to zonesize. In these (n1+1) Diff data blocks, the data size of the first n1 Diff data blocks is zonesize, and the data size of the (n1+1)th Diff data block is much smaller than zonesize. Exemplarily, the data size of the (n1+1)th Diff data block is smaller than a preset ratio of the data size of the security buffer area. For example, the data size of the (n1+1)th Diff data block is smaller than 50% of the data size of the security buffer area. The security buffer area refers to the security buffer area divided in the RAM memory space applied for when the terminal side performs differential file restoration.

[0183] Continue to refer to Figure 11b In (1), when the data size of the (n1+1)th Diff data block is smaller than the preset ratio of the data size of the safety buffer area, the division of the Diff data blocks can be adjusted. That is, the (n1+1)th Diff data block can be used to merge with the n1th Diff data block and serve as the final n1th Diff data block. At this time, among these n1 Diff data blocks, the data size of the first (n1-1) Diff data blocks is zonesize, and the data size of the last Diff data block is larger than zonesize.

[0184] When the data size of the (n1+1)th Diff data block is not less than the preset ratio of the data size of the safety buffer area, the division of the Diff data block is not adjusted.Figure 7 , no more details.

[0185] Take Extra data 01 as an example, the same is true. Figure 11b As shown in (2), the Extra data 01 can be divided into (n2+1) Extra data blocks according to the zonesize. Among these (n2+1) Extra data blocks, the data size of the first n2 Extra data blocks is the zonesize, and the data size of the (n2+1)th Extra data block is much smaller than the zonesize. Exemplarily, the data size of the (n2+1)th Extra data block is smaller than a preset ratio of the data size of the safety buffer area. For example, the data size of the (n2+1)th Extra data block is smaller than 50% of the data size of the safety buffer area.

[0186] Continue to refer to Figure 11b In (2), when the data size of the (n2+1)th Extra data block is smaller than the preset ratio of the data size of the safety buffer area, the division of the Extra data blocks can be adjusted. That is, the (n2+1)th Extra data block can be used to merge with the n2th Extra data block and serve as the final n2th Extra data block. At this time, among these n2 Extra data blocks, the data size of the first (n2-1) Extra data blocks is zonesize, and the data size of the last Extra data block is larger than zonesize.

[0187] When the data size of the (n2+1)th Extra data block is not less than the preset ratio of the data size of the safety buffer area, the division of the Extra data block is not adjusted. Figure 7 , no more details.

[0188] It can be understood that, for any Diff data or Extra data, when the data blocks are divided according to the zonesize, whether the size of the last data block is greater than the zonesize is related to the length of the Diff data or Extra data.

[0189] For details about the data structure of the differential file and the generation process that are not fully explained here, please refer to the previous article and will not be repeated here.

[0190] When the terminal side performs data restoration operation based on the Patch file, the terminal can calculate whether there exists a Diff data block with byte length greater than zonesize and the byte length of each Diff data block based on the total byte length of the Diff data corresponding to the plurality of Diff data compressed blocks recorded in the zone before compression, the value of zonesize, and the data size of the security buffer applied.

[0191] In an alternative embodiment, a flag field can also be set in the header of the Patch file, and the value of the flag field is used to indicate whether there exists a data block (including Diff data block and Extra data block) with byte length greater than zonesize.

[0192] When the terminal side performs data restoration operation based on the Patch file, the terminal can calculate whether there exists a Diff data block with byte length greater than zonesize and the byte length of each Diff data block based on the total byte length of the Diff data corresponding to the plurality of Diff data compressed blocks recorded in the zone before compression, the value of zonesize, and the data size of the security buffer applied.

[0193] Corresponding to the generation method of the differential file provided in the present embodiment, the present embodiment also provides a restoration method of the differential file, which is applied to the terminal side. Wherein the terminal mentioned here can be understood as any electronic device that needs to perform restoration operation on the differential file, such as smart phone, smart watch, smart bracelet, etc., and further such as any Internet of Things node device.

[0194] Figure 12 An exemplary flow of the target file restoration based on the Patch file provided in the present embodiment is shown.

[0195] Referring to Figure 12 The Patch file is decoded to obtain the corresponding Patch data. The process of decoding the Patch file data here can be understood as the inverse process of data encoding of the Patch data.

[0196] Referring to Figure 12The data structure of the patch file includes a total encoding header, encoding information corresponding to the plurality of Diff data compression blocks and the plurality of Extra data compression blocks, and the plurality of Diff data compression blocks and the plurality of Extra data compression blocks. The encoding information corresponding to the plurality of Diff data compression blocks and the plurality of Extra data compression blocks is used to describe the plurality of Diff data compression blocks and the plurality of Extra data compression blocks, so that the terminal can perform data addressing according to the encoding information. The data structure of the patch file can be referred to the above description of the data structure of the patch file, and will not be described here again. Figure 8

[0197] When the terminal obtains the patch file, the header of the patch file is parsed, and after the file type and the data block size are obtained according to the magic number and the zone size recorded in the header, the RAM memory space can be applied for the differential file restoration processing according to the data block size, and the data decoding operation is performed according to the data structure corresponding to the file type.

[0198] The terminal restores the target file according to the Diff data block or the Extra data block after each Diff data block or Extra data block is decompressed.

[0199] Continuing to refer to Figure 12 In the patch data obtained by decoding the patch file, the Diff data and the Extra data appear in pairs, and each block of Diff data is followed by a block of Extra data. Moreover, the order of each pair of Diff data and Extra data in the patch data is consistent with the new file data. Each block of Diff data includes a plurality of decompressed Diff data blocks, and each block of Extra data includes a plurality of decompressed Extra data blocks. When the terminal restores the target file based on the patch data, the data restoration operation is performed based on each Diff data block or Extra data block.

[0200] Referring to Figure 8 In the patch file, each zone is used to describe a plurality of Diff data compression blocks and a plurality of Extra data compression blocks. Therefore, the terminal can obtain each Diff data compression block and Extra data compression block according to the content recorded in the zone, perform decompression operation, and obtain the data in the new file by restoration processing based on the decompressed Diff data block and Extra data block.

[0201] Continuing to refer to Figure 12 ​For example, the terminal performs data restoration based on each Diff data compression block (corresponding to Diff data 01) and each Extra data compression block (corresponding to Extra data 01) described by the encoding information 01. The terminal first decompresses the Diff data 01 compression block 1 to obtain the Diff data 01 block 1, and the byte length of the Diff data 01 block 1 is equal to zonesize. When the terminal performs data restoration based on the Diff data 01 block 1, the terminal reads the Diff data of the Diff data 01 block 1 and reads the old file data (byte length equal to zonesize) matching the Diff data 01 block 1 in the old file, and performs XOR operation on the Diff data of the Diff data 01 block 1 and the matching old file data to obtain the new file data (byte length equal to zonesize) corresponding to the Diff data 01 block 1, and writes the new file data into the new file. Similarly, the terminal continues to decompress the Diff data 01 compression block 2, and performs data restoration based on the decompressed Diff data 01 block 2, until the Diff data 01 compression block n1 is restored. The byte length of the Diff data 01 block obtained by decompressing the Diff data 01 compression block n1 is less than or equal to zonesize.

[0202] Next, the terminal continues to decompress the Extra data 01 compression block 1 to obtain the Extra data 01 block 1, and the byte length of the Extra data 01 block 1 is equal to zonesize. When the terminal performs data restoration based on the Extra data 01 block 1, the terminal reads the Extra data of the Extra data 01 block 1 and directly writes the Extra data into the new file. Similarly, the terminal continues to decompress the Extra data 01 compression block 2, and performs data restoration based on the decompressed Extra data 01 block 2, until the Extra data 01 compression block n2 is restored. The byte length of the Extra data 02 block obtained by decompressing the Extra data 01 compression block n2 is less than or equal to zonesize.

[0203] At this point, the terminal completes the restoration of the target file based on the Diff data 01 and the Extra data 01. The operation of the terminal to restore the target file based on other Diff data and Extra data is the same, and the same applies to the terminal. Based on each Diff data compression block and each Extra data compression block in the patch file, and the related data in the old file, the terminal can obtain all the data in the new file.

[0204] The following uses (x, y, z) for each zone as an example, combined with Figure 13Explain the restoration process based on patch files.

[0205] In this example, z represents the pointer offset from the beginning of the file.

[0206] like Figure 13 As shown, in the Patch file, the content filled in zone1 is (x1, y1, z1), which is used to describe Diff data 01 compressed block 1, Diff data 01 compressed block 2, Extra data 01 compressed block 1 and Extra data 01 compressed block 2. Among them, the total byte length of the Diff data obtained after the Diff data 01 compressed block 1 and the Diff data 01 compressed block 2 are decompressed is x1, the character length of the Diff data 01 block 1 obtained after the Diff data 01 compressed block 1 is decompressed is m (assuming zonesize = m), and the byte length of the Diff data 01 block 2 obtained after the Diff data 01 compressed block 2 is decompressed is x1-m (x1-m≤m); the total byte length of the Extra data obtained after the Extra data 01 compressed block 1 and the Extra data 01 compressed block 2 are decompressed is y1, the character length of the Extra data 01 block 1 obtained after the Extra data 01 compressed block 1 is decompressed is m, and the character length of the Extra data 01 block 2 obtained after the Extra data 01 compressed block 2 is decompressed is y1-m (y1-m≤m).

[0207] The terminal parses (x1, y1, z1) filled in zone1 in the patch file. First, the terminal continues to read Diff data 01 compressed block 1 in the patch file, decompresses the Diff data 01 compressed block 1 to obtain Diff data of m length, reads data of m length in the old file, and adds the two pieces of data of m length to obtain new file data of m length, which is written into the new file (or referred to as the target file). Wherein, the terminal can read the m length of the old file data corresponding to the m length of the Diff data (Diff data 01 compressed block 1) in the old file by offsetting the old file pointer from the starting position of the file by z1. Then, the terminal continues to read Diff data 01 compressed block 2 in the patch file, decompresses the Diff data 01 compressed block 2 to obtain Diff data of (x1-m) length, and continues to read data of (x1-m) length in the old file, and adds the two pieces of data of (x1-m) length to obtain new file data of (x1-m) length, which is written into the new file. Wherein, after the terminal reads the m length of the old file data corresponding to the m length of the Diff data in the old file, the old file pointer continues to offset by m, and at this time the terminal can continue to read the (x1-m) length of the old data corresponding to the (x1-m) length of the Diff data in the old file based on the current position of the pointer.

[0208] At this point, each Diff data 01 compressed block described in zone1 has been processed.

[0209] The terminal continues to read Extra data 01 compressed block 1 in the patch file, decompresses the Extra data 01 compressed block 1 to obtain Extra data of m length, and directly writes it into the new file. The terminal continues to read Extra data 01 compressed block 2 in the patch file, decompresses the Extra data 01 compressed block 2 to obtain Extra data of (y1-m) length, and directly writes it into the new file.

[0210] At this point, each Extra data 01 compressed block described in zone1 has also been processed.

[0211] Next, the terminal continues to read (x2, y2, z2) filled in zone2 in the patch file. In the patch file, zone2 is used to describe Diff data 02 compressed block 1 and other Diff data 02 compressed block 2, and each Extra data 02 compressed block. The terminal continues Diff data 02 compressed block 1 in the patch file, decompresses Diff data 02 compressed block 1 to obtain m-length Diff data, reads m-length data in the old file, and performs addition operation on the two m-length data to obtain m-length new file data, and continues to write in the new file (or referred to as target file). In order to enable the terminal to read m-length old file data corresponding to the m-length Diff data (Diff data 02 compressed block 1) in the old file, it is necessary to re-determine the old file pointer based on the old file starting position and z2. That is, after the old file pointer is offset from the file starting position by z2, the terminal can read m-length old file data corresponding to the m-length Diff data (Diff data 01 compressed block 1) in the old file.

[0212] Similarly, the terminal continues to perform data restoration processing on the Diff data 02 compressed block and the Extra data 02 compressed block described by zone2.

[0213] Similarly, when the terminal completes the data restoration processing on all Diff data compressed blocks and Extra data compressed blocks described by zones, the restoration process of the new file can be completed.

[0214] The following respectively explains and describes the RAM memory occupation when the terminal performs data restoration based on the Diff data compressed block and the Extra data compressed block.

[0215] It should be noted that when the terminal device performs differential file restoration, it can apply for continuous RAM memory space, or it can apply for non-continuous RAM memory space, and the embodiment does not limit this.

[0216] When the terminal device applies for non-continuous RAM memory space, if the RAM memory area is reused, two RAM memory areas with the same size as zone size can be applied, and a RAM memory area (the size is related to the data compression algorithm) for running the data compression algorithm can be applied. When the terminal device applies for non-continuous RAM memory space, if the RAM memory area is not reused, three RAM memory areas with the same size as zone size can be applied, and a RAM memory area (the size is related to the data compression algorithm) for running the data compression algorithm can be applied.

[0217] In an alternative embodiment, if the RAM memory region is multiplexed, two RAM memory regions with a size of (zone size+N2) can be applied, and a RAM memory region (the size is related to the data compression algorithm) for running the data compression algorithm can be applied. N2 is the data size of the security buffer region.

[0218] Similarly, if the RAM memory region is not multiplexed, three RAM memory regions with a size of (zone size+N2) can be applied, and a RAM memory region (the size is related to the data compression algorithm) for running the data compression algorithm can be applied. N2 is the data size of the security buffer region.

[0219] Since the discontinuous RAM memory space is applied, RAM memory fragmentation is easily generated, and RAM space is wasted. Therefore, in the present embodiment, the terminal device applies a continuous RAM memory space as an example for explanation and description.

[0220] When the terminal device obtains the patch file, the header of the patch file is parsed, and the value of the data block size (zone size) is obtained. Then, a continuous RAM memory space based on the value of the zone size can be applied for the differential data restoration operation.

[0221] In a possible embodiment, the RAM memory region is not multiplexed, and the terminal device applies a continuous RAM memory space for the patch restoration operation. The size of the RAM memory space is 3*zone size+N1 (bytes), wherein N1 bytes is the size of the RAM memory space required for running the data compression algorithm. The terminal device can divide the RAM memory space into four RAM memory regions, i.e., a first RAM memory region 201, a second RAM memory region 202, a third RAM memory region 203, and a fourth RAM memory region 204, as shown in FIG. 2A and FIG. 2B. Figure 14 and Figure 15 The size of the first RAM memory region 201, the second RAM memory region 202, and the third RAM memory region 203 is equal, and is zone size (bytes). The size of the fourth RAM memory region 204 is N1 bytes.

[0222] For example, the data compression algorithm used for data compression of the Diff data compression patch or the Extra data compression patch can be LZMA. Assuming that the minimum RAM memory space required for supporting the operation of LZMA is 16 KB, N1 can be set as 16. Assuming that the zone size is 60 KB, the terminal can apply for a continuous block of M bytes of RAM memory space for the patch restoration operation in the present embodiment, M = 60*3 + 16 = 196 KB.

[0223] The first RAM memory area 201, the second RAM memory area 202, and the third RAM memory area 203 are collectively used for data storage operations related to the Diff data patch restoration process, including but not limited to storing the Diff data compression patch, storing the decompressed Diff data patch, and storing the new file data patch obtained after the addition operation, and are also used for data storage operations related to the Extra data patch restoration process, including but not limited to storing the Extra data compression patch, storing the decompressed Extra data patch; the fourth RAM memory area 204 is used for data decompression operations.

[0224] For example, the data compression algorithm used for data compression of the Diff data compression patch or the Extra data compression patch can be LZMA. Assuming that the minimum RAM memory space required for supporting the operation of LZMA is 16 KB, N1 can be set as 16. Assuming that the zone size is 60 KB, the terminal can apply for a continuous block of M bytes of RAM memory space for the patch restoration operation in the present embodiment, M = 60*3 + 16 = 196 KB. Figure 14At T0, the terminal applies for the first RAM memory area 201, the second RAM memory area 202, the third RAM memory area 203 and the fourth RAM memory area 204. At T1, the terminal reads the Diff data 01 compressed block 1 from the patch file, and writes the Diff data 01 compressed block 1 into the first RAM memory area 201. Next, the terminal decompresses the Diff data 01 compressed block 1 in the first RAM memory area 201 by calling the data compression algorithm, and the RAM memory area used by the decompression process of the data compression algorithm is the fourth RAM memory area 204, and the decompressed data is written into the second RAM memory area 202. At T2, the decompression of the Diff data 01 compressed block 1 is completed, and the second RAM memory area 202 temporarily stores the Diff data 01 block 1 (byte length is zonesize). Next, the terminal reads the Old data 01 block 1 (byte length is zonesize) corresponding to the Diff data 01 block 1 in the running state image file (equivalent to the old file before upgrading) and temporarily stores it in the third RAM memory area 203, as shown at T3. At T3, the terminal reads the Old data 01 block 1 in the third RAM memory area 203, and reads the Diff data 01 block 1 in the second RAM memory area 202, and performs addition operation. Among them, the terminal can add the Diff data 01 block 1 and the Old data 01 block 1 to make the New data 01 block 1 obtained by the addition operation can be written in the second RAM memory area 202, and the Diff data 01 block 1 temporarily stored in the second RAM memory area 202 is overwritten. Further, at T4, the terminal can read the New data 01 block 1 in the second RAM memory area 202 and write it into the static state image file (or a newly created file). Among them, the static state image file can be understood as a backup of the running state image file.

[0225] It should be noted that the data temporarily stored in a certain RAM memory area can be overwritten or cleared, and this is not limited in comparison to the present embodiment. For example, when reading Old data 01 block 1 in the third RAM memory area 203 and reading Diff data 01 block 1 in the second RAM memory area 202, and performing an addition operation, the operation result can be directly written into the first RAM memory area 201, overwriting the Diff data 01 compressed block 1 temporarily stored therein. For another example, after decompressing the Diff data 01 compressed block 1 temporarily stored in the first RAM memory area 201, the data temporarily stored in the first RAM memory area 201 can be cleared, and then, when reading Old data 01 block 1 in the third RAM memory area 203 and reading Diff data 01 block 1 in the second RAM memory area 202, and performing an addition operation, the operation result can be directly written into the first RAM memory area 201.

[0226] At this point, the terminal completes the data restoration operation based on Diff Data 01 compressed block 1. Similarly, the terminal can continue the data restoration operation based on Diff Data 01 compressed block 2. If Diff Data 01 compressed block 2 is the last compressed block of Diff Data 01, the byte length of Diff Data 01 block 2 obtained by decompressing it is less than or equal to zonesize.

[0227] When the terminal completes the data restoration operation based on the various Diff data 01 compression blocks included in the Diff data 01 , the terminal may continue to perform the data restoration operation based on the various Extra data 01 compression blocks included in the Extra data 01 .

[0228] For example, refer to Figure 15 At time T5, the terminal reads Extra data 01 compressed block 1 in the Patch file and writes Extra data 01 compressed block 1 into the first RAM memory area 201. Next, the terminal calls the data compression algorithm to decompress Extra data 01 compressed block 1 in the first RAM memory area 201. The RAM memory area used by the data compression algorithm to perform the decompression process is the fourth RAM memory area 204, and the decompressed data is written into the second RAM memory area 202. At time T6, the decompression of Extra data 01 compressed block 1 is completed, and Extra data 01 block 1 (byte length is zonesize) is temporarily stored in the second RAM memory area 202. Furthermore, at time T6, the terminal can read Extra data 01 block 1 in the second RAM memory area 202 and continue to write it into the static image file. At this time, the data in the static image file is restored to New data 01 block 3.

[0229] At this point, the terminal completes the data restoration operation based on the Extra data 01 compressed block 1. Similarly, the terminal can continue the data restoration operation based on the Extra data 01 compressed block 2. If the Extra data 01 compressed block 2 is the last compressed block of the Extra data 01, the byte length of the Extra data 01 block 2 obtained by decompressing the Extra data 01 compressed block 2 is less than or equal to zonesize. Similarly, when the data in the static state image file is full, the terminal completes the data restoration operation based on the patch file.

[0230] In this embodiment, a security buffer can also be provided for the RAM memory area, which is not limited in the present embodiment. For example, the terminal applies for a continuous block of RAM memory space for the patch restoration operation, and the size of the RAM memory space is 3*zonesize+3*N2+N1 (bytes). N2 bytes is the size of the RAM memory space occupied by the security buffer. This embodiment is not described herein.

[0231] In another possible embodiment, the RAM memory area is multiplexed, and the terminal applies for a continuous block of RAM memory space for the patch restoration operation, and the size of the RAM memory space is 2*zonesize+2*N2+N1 (bytes). N1 bytes is the size of the RAM memory space required for running the data compression algorithm, and N2 bytes is the size of the RAM memory space occupied by the security buffer. The terminal can divide the RAM memory space into five RAM memory areas, i.e., a first RAM memory area 301, a second RAM memory area 302, a third RAM memory area 303, a fourth RAM memory area 304, and a fifth RAM memory area 305, as shown in FIGS. 3 and 4. Figure 16 and Figure 17 The size of the first RAM memory area 301 and the third RAM memory area 303 is equal, and is zonesize (bytes). The size of the fifth RAM memory area 305 is N1 bytes. The second RAM memory area 302 is located between the first RAM memory area 301 and the third RAM memory area 303, and is a security buffer area of the first RAM memory area 301. The fourth RAM memory area 304 is located between the third RAM memory area 303 and the fifth RAM memory area 305, and is a security buffer area of the third RAM memory area 304. The size of the second RAM memory area 302 and the fourth RAM memory area 304 is equal, and is N2 bytes.

[0232] For example, the data compression algorithm used for data compression of the Diff data compression patch or the Extra data compression patch can be LZMA. Assuming that the minimum RAM memory space required for supporting the operation of LZMA is 16 KB, N1 can be set as 16. Assuming that the zone size is 90 KB and N2 is 2 KB, the terminal can apply for a continuous block of M bytes of RAM memory space for the patch restoration operation in the present embodiment, M = 90*2+2*2+16 = 200 KB.

[0233] The first RAM memory area 301 and the third RAM memory area 303 are used for data storage operations involved in the Diff data patch restoration process, including but not limited to storage of the Diff data compression patch, storage of the decompressed Diff data patch, storage of the new file data patch obtained after the addition operation, and data storage operations involved in the Extra data patch restoration process, including but not limited to storage of the Extra data compression patch, storage of the decompressed Extra data patch. The fifth RAM memory area 304 is used for data decompression operation.

[0234] For example, the data compression algorithm used for data compression of the Diff data compression patch or the Extra data compression patch can be LZMA. Assuming that the minimum RAM memory space required for supporting the operation of LZMA is 16 KB, N1 can be set as 16. Assuming that the zone size is 90 KB and N2 is 2 KB, the terminal can apply for a continuous block of M bytes of RAM memory space for the patch restoration operation in the present embodiment, M = 90*2+2*2+16 = 200 KB. Figure 16At T0, the terminal applies for the first RAM memory area 301, the second RAM memory area 302, the third RAM memory area 303, the fourth RAM memory area 304 and the fifth RAM memory area 305. At T1, the terminal reads the Diff data 01 compressed block 1 in the patch file, writes the Diff data 01 compressed block 1 into the first RAM memory area 301. Next, the terminal decompresses the Diff data 01 compressed block 1 in the first RAM memory area 301 by calling the data compression algorithm, the RAM memory area used by the data compression algorithm for decompression is the fifth RAM memory area 304, and the decompressed data is written into the third RAM memory area 303. At T2, the decompression of the Diff data 01 compressed block 1 is completed, and the third RAM memory area 303 temporarily stores the Diff data 01 block 1 (byte length is zonesize). Next, the terminal reads the Old data 01 block 1 (byte length is zonesize) corresponding to the Diff data 01 block 1 in the running state image file (equivalent to the old file before upgrading) and temporarily stores it in the first RAM memory area 301, covering the Diff data 01 compressed block 1, as shown at T3. Referring back to T3, the terminal reads the Old data 01 block 1 in the first RAM memory area 301 and the Diff data 01 block 1 in the third RAM memory area 303 and performs addition operation. Among them, the terminal can add the Diff data 01 block 1 and the Old data 01 block 1 to obtain the New data 01 block 1, which can be written in the third RAM memory area 303 to overwrite the Diff data 01 block 1 temporarily stored in the third RAM memory area 303. Further, at T4, the terminal can read the New data 01 block 1 in the third RAM memory area 303 and write it into the static state image file.

[0235] Among them, the New data 01 block 1 obtained by addition operation can also be written in the first RAM memory area 301 to overwrite the Old data 01 block 1 temporarily stored in the first RAM memory area 301. Further, the terminal can read the New data 01 block 1 in the first RAM memory area 301 and write it into the static state image file.

[0236] At this point, the terminal completes the data restoration operation based on the Diff data 01 compressed block 1. Similarly, the terminal can continue the data restoration operation based on the Diff data 01 compressed block 2. Among them, if the Diff data 01 compressed block 2 is the last compressed block of the Diff data 01, the byte length of the Diff data 01 block 2 obtained by decompression is less than or equal to zonesize.

[0237] When the terminal completes the data restoration operation based on each Diff data 01 compressed block included in the Diff data 01, it can continue the data restoration operation based on each Extra data 01 compressed block included in the Extra data 01.

[0238] For example, referring to Figure 17 At T5, the terminal reads the Extra data 01 compressed block 1 in the patch file and writes the Extra data 01 compressed block 1 into the first RAM memory area 301. Next, the terminal calls the data compression algorithm to decompress the Extra data 01 compressed block 1 in the first RAM memory area 301, and the RAM memory area used by the data compression algorithm to perform the decompression process is the fifth RAM memory area 305, and the decompressed data is written into the third RAM memory area 303. At T6, the Extra data 01 compressed block 1 is decompressed, and the third RAM memory area 303 temporarily stores the Extra data 01 block 1 (byte length zonesize). Further, at T6, the terminal can read the Extra data 01 block 1 in the third RAM memory area 303 and continue to write it into the static state image file. At this time, the data in the static state image file is restored to the New data 01 block 3.

[0239] At this point, the terminal completes the data restoration operation based on the Extra data 01 compressed block 1. Similarly, the terminal can continue the data restoration operation based on the Extra data 01 compressed block 2. If the Extra data 01 compressed block 2 is the last compressed block of the Extra data 01, the Extra data 01 block 2 obtained by decompressing it has a byte length less than or equal to zonesize. Similarly, when the data in the static state image file is full, the terminal completes the data restoration operation based on the patch file.

[0240] The terminal applies the second RAM memory area 302 as a safety buffer for the first RAM memory area 301, which can prevent data overflow in the first RAM memory area 301 from causing data processing errors. Similarly, the terminal applies the fourth RAM memory area 304 as a safety buffer for the third RAM memory area 303, which can prevent data overflow in the third RAM memory area 303 from causing data processing errors.

[0241] It should be noted that, if the size of a certain Diff data compression block or Extra data compression block is greater than the size of the Diff data block or the size of the Extra data compression block before compression, when the data compression block is temporarily stored in the first RAM memory area or the third RAM memory area, data may overflow into the second RAM memory area or the fourth RAM memory area. At this time, when the terminal device performs data decompression processing on the data compression block, the data overflowed into the second RAM memory area or the fourth RAM memory area also needs to be decompressed to ensure the correctness of the decompressed Diff data block or Extra data block.

[0242] When the terminal device applies for a certain determined value of continuous RAM memory space for differential data restoration, compared with the case where the RAM memory areas are not multiplexed, the RAM memory area multiplexing can improve the data restoration processing efficiency.

[0243] When the terminal device can allocate a very small amount of RAM memory space for differential data restoration processing, the terminal device can also not divide the second RAM memory area 302 and the fourth RAM memory area 304 as the safety buffer area in the applied RAM memory space. When the terminal device does not divide the second RAM memory area 302 and the fourth RAM memory area 304 as the safety buffer area in the applied RAM memory space, the RAM memory occupation condition when the terminal device performs data restoration based on the Diff data compression block and the Extra data compression block is similar, and will not be described here.

[0244] For example, the data compression algorithm used for data compression of the Diff data compression block or the Extra data compression block can use LZMA. Taking the minimum RAM memory space required to support the operation of LZMA as 16 KB as an example, N1 can be set as 16. Assuming that zonesize = 2 KB, in this embodiment, the terminal device can apply for a continuous block of M bytes of RAM memory space for patch restoration operation, M = 2*2 + 16 = 20 KB.

[0245] In this way, when the terminal device performs data restoration operation based on the Diff data compression block or the Extra data compression block, the decompression operation and the data storage operation are performed in the specified RAM memory area, the RAM memory space is fully and effectively utilized, the differential restoration operation consumes less RAM memory, and the lightweight device with small RAM space can also have differential restoration capability.

[0246] Corresponding to Figure 11a-Figure 11bThe data block division mode shown, the terminal for patch file data restoration, the application for patch restoration operation RAM memory space includes a security buffer. Among them, the data size of the security buffer is N2 bytes.

[0247] For example, the terminal application RAM memory space can be continuous, can refer to Figure 16 Also shown, the terminal application RAM memory space can also be non-continuous, for example, to apply three blocks of size (zone size + N2) RAM memory area, and a block of RAM memory area for running data compression algorithm (size related to data compression algorithm). This embodiment is not limited.

[0248] When the terminal based on a certain zone description Diff data compression block or Extra data compression block for data restoration operation, can be based on the zone in the record more than one Diff data compression block before compression corresponding Diff data total byte length, zone size, and the value of the application of the data size of the security buffer, calculate whether there is byte length greater than the Diff data block size.

[0249] If there is no byte length greater than the Diff data block size, the terminal based on multiple Diff data compression block for data restoration process can refer to the foregoing, hereinafter will not be repeated.

[0250] Assuming that the last Diff data compression block (such as Diff data 01 compression block n1) described by a certain zone before compression Diff data block byte length greater than zone size, the following to the terminal based on Diff data 01 compression block n1 data restoration process flow explanation.

[0251] Referring to Figure 18At T1, the terminal reads the Diff data 01 compressed chunk n1 from the patch file, and writes the Diff data 01 compressed chunk n1 into the first RAM memory area 301. Next, the terminal decompresses the Diff data 01 compressed chunk n1 in the first RAM memory area 301 by calling the data compression algorithm, and the RAM memory area used by the data compression algorithm for decompression is the fifth RAM memory area 304, and the decompressed data is written into the third RAM memory area 303. At T2, the decompression of the Diff data 01 compressed chunk n1 is completed, and the decompressed Diff data 01 chunk n1 is temporarily stored in the third RAM memory area 303. Since the byte length of the Diff data 01 chunk n1 before compression is greater than zonesize, the Diff data 01 chunk n1 not only fills the third RAM memory area 303, but also writes part of the data into the fourth RAM memory area 304. Next, the terminal reads the Old data 01 chunk n1 (byte length greater than zonesize) corresponding to the Diff data 01 chunk n1 from the running state image file (equivalent to the old file before upgrading), and temporarily stores it in the first RAM memory area 301. Among them, the Old data 01 chunk n1 not only fills the first RAM memory area 301, but also writes part of the data into the second RAM memory area 302, as shown at T3. Continuing to refer to T3, the terminal reads the Old data 01 chunk n1 in the first RAM memory area 301 and the second RAM memory area 302, and reads the Diff data 01 chunk n1 in the third RAM memory area 303 and the fourth RAM memory area 304, and performs addition operation. Among them, the terminal can perform addition operation on the Diff data 01 chunk n1 and the Old data 01 chunk n1, so that the New data 01 chunk n1 obtained by the addition operation can be written in the third RAM memory area 303 and the fourth RAM memory area 304. Further, at T4, the terminal can read the New data 01 chunk n1 in the third RAM memory area 303 and the fourth RAM memory area 304 and write it into the static state image file.

[0252] Suppose the last Extra data compressed chunk described in a zone (such as the Extra data 01 compressed chunk n2) has a byte length of the Extra data chunk before compression greater than zonesize, the following explains the terminal data restoration process based on the Extra data 01 compressed chunk n2.

[0253] For example, referring to Figure 19At T5, the terminal reads the Extra data 01 compressed block n2 from the patch file, and writes the Extra data 01 compressed block n2 into the first RAM memory area 301. Next, the terminal decompresses the Extra data 01 compressed block n2 in the first RAM memory area 301 by calling the data compression algorithm, and the RAM memory area used by the data compression algorithm for decompression is the fifth RAM memory area 305, and the decompressed data is written into the third RAM memory area 303. At T6, the decompression of the Extra data 01 compressed block n2 is completed, and the decompressed Extra data 01 block n2 is temporarily stored in the third RAM memory area 303. Since the byte length of the Extra data 01 block n2 before compression is greater than zonesize, the Extra data 01 block n2 not only fills the third RAM memory area 303, but also writes some data into the fourth RAM memory area 304. Further, at T6, the terminal can read the Extra data 01 block n2 from the third RAM memory area 303 and the fourth RAM memory area 304 and continue to write into the static state image file. At this time, the data in the static state image file is restored to the New data 01 block n2.

[0254] In an example, if the terminal parses the value of the flag field in the header of the patch file, and determines that there is a data block (including a Diff data block and an Extra data block) with a byte length greater than zonesize, the terminal can perform data restoration processing according to the processing flow shown in FIGS. 10 and 11. Figure 17 and 18

[0255] In this way, when the size of a certain data block is slightly greater than zonesize, the terminal can also complete the corresponding data restoration operation with the help of the safe buffer area.

[0256] In an example, in the data structure of the patch file, in addition to filling the zonesize field in the header, the patch file can also fill a data compression block maximum byte length (LengthMAX) field, and the value of the field is used to indicate the maximum data size of each data compression block (including a Diff data compression block and an Extra data compression block).

[0257] In this case, when the terminal parses the patch file, it can determine whether the received patch file is incorrect based on the value of the LengthMAX field. For example, if the size of a certain Diff data compression block or Extra data compression block in the patch file exceeds the value of the LengthMAX field, the terminal can determine that the patch file is incorrect, and then no longer perform data restoration operations based on the patch file. ​

[0258] In yet another example, in the data structure of the Patch file, in addition to filling the zone size field in the Header, a target file data total length (NewfileLength) field can also be filled, and the value of this field is used to indicate the total data length of the target file obtained based on the Patch file.

[0259] In this case, when the terminal performs target file restoration based on the Patch file, it can determine whether the obtained target file is correct based on the value of the NewfileLength field. For example, if the data length of the target file obtained based on the Patch file is less than or greater than the value of the NewfileLength field, the terminal can determine that the obtained target file is incorrect, and then no longer perform firmware upgrade based on the target file.

[0260] In another example, the data structure of the Patch file can also include a check field, and the value of this field is used to indicate the hash value of the target file obtained based on the Patch file.

[0261] When the terminal performs target file restoration based on the Patch file, it can also determine whether the obtained target file is correct based on the value of the check field. For example, if the hash value of the target file obtained based on the Patch file is different from the value of the check field, the terminal can determine that the obtained target file is incorrect, and then no longer perform firmware upgrade based on the target file.

[0262] In this way, in the embodiments of the present application, the Patch data is split into difference restoration unit data with controllable size, and the data size is related to the RAM space size of the terminal, so that the terminal device only needs to process one piece of difference restoration unit data at a time, and thus the lightweight device with limited RAM space also has difference restoration capability.

[0263] The above is explained and described based on a group of image files (including running state image files and static state running files), and other static state image files can also be filled with data based on other Patch files, so as to obtain all image files corresponding to the upgrade package. At this time, the terminal can perform firmware upgrade based on these image files. The explanation of the terminal performing firmware upgrade based on these image files can refer to the existing technology, and will not be described here.

[0264] It should be noted that in the foregoing embodiment of the method for generating a differential file, the Diff data server is generated based on a subtraction operation as an example. Correspondingly, in the foregoing embodiment of the method for restoring a differential file, the terminal restores the Diff data based on an addition operation as an example. Wherein, the Diff data can also be generated by the server based on other operations, which is temporarily referred to as the Diff data is generated by the server based on a first operation. Correspondingly, the terminal can restore the Diff data based on a second operation, and the second operation is the inverse operation of the first operation. This embodiment does not limit the first operation and the second operation.

[0265] It should be noted that in the foregoing embodiment of the method for generating a differential file and the method for restoring a differential file, the firmware file is taken as an example for explanation. Wherein, the method for generating a differential file and the method for restoring a differential file provided in this embodiment can also be applied to differential restoration processing of other file types, such as patch files, APK (Android application package) and the like.

[0266] In addition, the method for restoring a differential file provided in this embodiment is not only applicable to lightweight electronic devices with small RAM memory space (for example, less than a first preset threshold), but also applicable to other electronic devices with small RAM memory space (for example, less than a second preset threshold) that can be used for differential file restoration.

[0267] That is, when the RAM memory space of the electronic device is not small, but the RAM memory space allocated for differential file restoration is small, the electronic device can execute the method for restoring a differential file provided in this embodiment to use the small RAM memory space to realize the differential file restoration function.

[0268] Figure 20 An exemplary application scenario is shown. As shown in FIG. 1, Figure 20 As shown in FIG. 1 (1), when the user plays a game using the mobile phone, a dialog box 700 pops up on the interface. Wherein, the content in the dialog box 700 shows “xx patch is detected at present, do you want to download and update immediately”. If the user agrees, the “yes” option 701 can be clicked. In response to the user's operation, the dialog box disappears, as shown in FIG. 1 (2). Figure 20 The user continues to play the game using the mobile phone. At the same time, the mobile phone executes the operation of downloading the xx patch, restoring the differential file based on the downloaded xx patch, and performing hot update based on the restored patch file.

[0269] In this application scenario, although the RAM memory space of the mobile phone is not small, the RAM memory space allocated by the mobile phone for performing the differential file restoration operation is limited so as not to affect the experience of the user using the mobile phone. At this time, if the mobile phone executes the differential file restoration method provided by the present application, the differential data restoration function can be realized through a smaller RAM memory space, and the user's experience will not be affected.

[0270] In some other application scenarios, it is assumed that the user has enabled the APK automatic update function of the mobile phone. At the same time that the user uses the mobile phone, the mobile phone may perform APK differential package downloading and differential restoration operations in the background. Although the RAM memory space of the mobile phone is not small, in order not to affect the user's experience, the RAM memory space allocated by the mobile phone for performing the differential file restoration operation is usually small. At this time, if the mobile phone executes the differential file restoration method provided by the present application, the differential data restoration function can be realized through a smaller RAM memory space, and the user's experience will not be affected.

[0271] However, in actual applications, there are usually multiple versions of the same terminal device, and the multiple versions of the terminal device may all have the demand for firmware upgrade. The hardware configurations of the terminal devices of different versions are not necessarily the same (usually the high and low configurations of hardware resources). If a separate upgrade differential package is developed for each version of the terminal device, the number of versions of the upgrade differential package will undoubtedly increase, and the manual maintenance cost will also increase. Therefore, in order to reduce the number of versions of the upgrade differential package, the same upgrade differential package can be developed for multiple versions of the terminal device to meet the scene demand of one package for multiple versions and realize the unification of the upgrade differential package of different versions of the terminal device.

[0272] When the differential file in the upgrade differential package is generated based on the foregoing scheme, if the RAM memory space allocated by the terminal device for performing the differential file restoration is large, how to improve the efficiency of the differential file restoration is a problem to be solved.

[0273] In order to solve the above problems, the present application also provides a differential file restoration method. In this method, the terminal device can adaptively perform the restoration of the differential file according to the RAM memory space for differential file restoration, so as to improve the restoration efficiency of the differential file.

[0274] In the foregoing description, reference is made to Figure 13The compressed blocks in the patch file, including the Diff data compressed blocks and the Extra data compressed blocks, are processed in series. When the terminal device allocates a large amount of RAM memory space for the restoration of the differential file, the restoration of the compressed blocks can be performed in parallel, thereby improving the restoration efficiency of the differential file. The parallelization of the restoration of the compressed blocks is related to the size of the RAM memory space allocated by the terminal device for the restoration of the differential file.

[0275] As described above, with reference to Figure 16 and Figure 17 , the terminal device can perform the restoration of one compressed block (Diff data compressed block or Extra data compressed block) based on the first RAM memory region 301, the second RAM memory region 302, the third RAM memory region 303, the fourth RAM memory region 304, and the fifth RAM memory region 305. The first RAM memory region 301 and the third RAM memory region 303 have the same size, which is zonesize (bytes). The fifth RAM memory region 305 has a size of N1 bytes, which is used for data decompression. The second RAM memory region 302 is a safety buffer region of the first RAM memory region 301, and the fourth RAM memory region 304 is a safety buffer region of the third RAM memory region 304, both of which have a size of N2 bytes.

[0276] In this way, in addition to providing the fifth RAM memory region for data decompression, a set of RAM space (i.e., the first RAM memory region 301, the second RAM memory region 302, the third RAM memory region 303, and the fourth RAM memory region 304) can perform the restoration of one compressed block. Therefore, in addition to the fifth RAM memory region, as long as the terminal device can provide multiple sets of RAM space, the parallelization of the restoration of multiple compressed blocks can be achieved, thereby improving the restoration efficiency of the differential file.

[0277] For example, with reference to Figure 21a , the first set of RAM space is used for the first restoration thread to perform the restoration of a compressed block (Diff data compressed block or Extra data compressed block), and the second set of RAM space is used for the second restoration thread to perform the restoration of a compressed block (Diff data compressed block or Extra data compressed block). The first restoration thread and the second restoration thread are parallel. In this way, when the terminal device can provide multiple sets of RAM space, the terminal device can perform the restoration of Diff data compressed blocks or Extra data compressed blocks through multiple parallel restoration threads.

[0278] In an alternative embodiment, the RAM space for the terminal device to perform the differential file restoration process is a static array, and a group of RAM space corresponding to each restoration thread can be divided in the static array, so that each restoration thread performs the restoration process on the compressed patch (Diff data compressed patch or Extra data compressed patch) based on the corresponding group of RAM space.

[0279] For example, as shown in FIG. 3, the static array is divided into a plurality of groups of RAM space (including the first RAM memory area 301, the second RAM memory area 302, the third RAM memory area 303, the fourth RAM memory area 304, and the fifth RAM memory area 305) in sequence, and each group of RAM space corresponds to one restoration thread. Figure 21a For example, as shown in FIG. 3, the static array is divided into a plurality of groups of RAM space (including the first RAM memory area 301, the second RAM memory area 302, the third RAM memory area 303, the fourth RAM memory area 304, and the fifth RAM memory area 305) in sequence, and each group of RAM space corresponds to one restoration thread.

[0280] Figure 21b For example, as shown in FIG. 3, the static array is divided into a plurality of groups of RAM space (including the first RAM memory area 301, the second RAM memory area 302, the third RAM memory area 303, the fourth RAM memory area 304, and the fifth RAM memory area 305) in sequence, and each group of RAM space corresponds to one restoration thread.

[0281] It should be noted that the above-mentioned division of the RAM space is only an example, and the present embodiment is not limited thereto. As long as each restoration thread corresponds to a group of RAM space (including the first RAM memory area 301, the second RAM memory area 302, the third RAM memory area 303, and the fourth RAM memory area 304), the parallelization of the compressed patch restoration can be achieved.

[0282] In the present embodiment, in the restoration process of the Patch data, each group of incremental update data can be used as a unit for the restoration thread to independently perform the restoration operation. One group of incremental update data is the incremental update data described by one control block (zone). Generally, one group of incremental update data includes a Diff data patch and an Extra data patch, and the number of Diff data patches and Extra data patches is one or more. In a special case, one group of incremental update data only includes a Diff data patch or an Extra data patch.

[0283] For example, the terminal device creates a first restoration thread and a second restoration thread in parallel for the restoration of the Patch data. As shown in FIG. 4, the first restoration thread and the second restoration thread are created in parallel, and each of the first restoration thread and the second restoration thread is used to restore the Patch data. Figure 22 ​As shown, the first reduction thread is used to restore the compressed patch described by zone1, the second reduction thread is used to restore the compressed patch described by zone2, the first reduction thread is used to restore the compressed patch described by zone3, the second reduction thread is used to restore the compressed patch described by zone4, and so on. In this way, the terminal device can restore the Patch data based on two parallel reduction threads, thereby improving the restoration efficiency of the Patch data.

[0284] In the process of restoring the compressed patch described by each zone by each reduction thread, the Diff data patches and the Extra data patches described by the zone are sequentially restored in order. The operation of sequentially restoring the Diff data patches and the Extra data patches by the reduction thread can be referred to the foregoing, and will not be described here.

[0285] In order to realize the parallelization of the Patch data restoration, the data structure of the Patch file is adaptively adjusted in this embodiment. Figure 23 An exemplary data structure of a Patch file provided by this embodiment is shown. As shown in Figure 23 The data structure of the Patch file includes a header (Header), a control block (zone), Diff data, and Extra data. The description of the Diff data and the Extra data can be referred to the foregoing, which is the same as the data structure of the Patch file shown in Figure 8 .

[0286] Different from the data structure of the Patch file shown in Figure 8 , in the data structure of the Patch file shown in Figure 23 , the total number of the control blocks (zones) is also included in the header (Header).

[0287] Different from the data structure of the Patch file shown in Figure 8 , in the data structure of the Patch file shown in Figure 23 , each zone not only includes the first pointer offset for reading data in the old file, but also includes the second pointer offset for writing data in the new file. The first pointer offset is the pointer offset determined based on the starting position of the old file, and the second pointer offset is the pointer offset determined based on the starting position of the new file. Moreover, the total byte length of the compressed Diff data patches and the compressed Extra data patches described by the zone is also included in each zone, for example, the total byte length of the compressed Diff data patches and the total byte length of the compressed Extra data patches.

[0288] In the present embodiment, the first pointer offset is used to read the old data corresponding to the first Diff data chunk described by the zone in the old file, i.e. to read the old data used to add the first Diff data chunk described by the zone in the old file. The second pointer offset is used to determine the first address in the new file to write the restored data corresponding to the zone. In this way, when multiple restore threads process the data chunks described by the zones in parallel, the first address in the new file to write the restored data corresponding to the zone can be determined based on the second pointer offset in the zone.

[0289] In the present embodiment, the total length of the compressed bytes of the Diff data chunks and the total length of the compressed bytes of the Extra data chunks described by a zone can be used by the restore threads to calculate the address offset of the next zone in the patch file. That is, the total length of the compressed bytes can be used by the restore threads to skip the data compression chunks described by the zone when reading data in the patch file, so as to read the data filled in the next zone. That is, based on the total length of the compressed bytes of the Diff data chunks and the total length of the compressed bytes of the Extra data chunks described by each zone, the restore threads can read the data compression chunks described by the zone which needs to be processed. For example, if a restore thread needs to process the restoration of the data compression chunks described by zone 2, the total length of the compressed bytes of the Diff data chunks and the total length of the compressed bytes of the Extra data chunks described by zone 1 can be used to determine the total length of the compressed bytes of the Diff data chunks and the total length of the compressed bytes of the Extra data chunks described by zone 1, and then the restore thread can skip the Diff data chunks and the Extra data chunks when reading data in the patch file, and then the data filled in zone 2 can be read. Similarly, if the restore thread needs to process the restoration of the data compression chunks described by zone 4, the same is true, and will not be described here.

[0290] For example, referring to FIG. 6, the total length of the compressed bytes of the Diff data chunks and the total length of the compressed bytes of the Extra data chunks described by zone 1 is 1000 bytes, and the total length of the compressed bytes of the Diff data chunks and the total length of the compressed bytes of the Extra data chunks described by zone 2 is 2000 bytes. When the restore thread needs to process the restoration of the data compression chunks described by zone 2, the total length of the compressed bytes of the Diff data chunks and the total length of the compressed bytes of the Extra data chunks described by zone 1 can be used to determine the total length of the compressed bytes of the Diff data chunks and the total length of the compressed bytes of the Extra data chunks described by zone 1, and then the restore thread can skip the Diff data chunks and the Extra data chunks when reading data in the patch file, and then the data filled in zone 2 can be read. Figure 23each zone includes 32 bytes for describing a plurality of Diff data compression blocks and a plurality of Extra data compression blocks. The plurality of Diff data compression blocks and the plurality of Extra data compression blocks correspond to a pair of Diff data and Extra data in the Patch data obtained based on the BSDiff algorithm. The data recorded in the zone can be used as the encoding information of the plurality of Diff data compression blocks and the plurality of Extra data compression blocks described by the zone. The first 8 bytes of the zone can record the total byte length of the Diff data corresponding to the plurality of Diff data compression blocks before and after compression, and the Diff data compression block description information (such as the byte length after compression); the second 8 bytes of the zone can record the total byte length of the Extra data corresponding to the plurality of Extra data compression blocks before and after compression, and the Extra data compression block description information (such as the byte length after compression); the third 8 bytes of the zone are used to fill the first pointer offset, and the first pointer offset is used to determine the position of reading data (that is, the data used for addition operation with the Diff data block) in the old file; and the fourth 8 bytes of the zone are used to fill the second pointer offset, and the second pointer offset is used to determine the position of writing data (that is, the data obtained by the restoration operation) in the new file.

[0291] In another optional embodiment, each zone includes 32 bytes for describing a plurality of Diff data compression blocks and a plurality of Extra data compression blocks. The first 8 bytes of the zone can record the total byte length of the Diff data corresponding to the plurality of Diff data compression blocks before and after compression; the second 8 bytes of the zone can record the total byte length of the Extra data corresponding to the plurality of Extra data compression blocks before and after compression; the third 8 bytes of the zone are used to fill the first pointer offset, and the first pointer offset is used to determine the position of reading data (that is, the data used for addition operation with the Diff data block) in the old file; and the fourth 8 bytes of the zone are used to fill the second pointer offset, and the second pointer offset is used to determine the position of writing data (that is, the data obtained by the restoration operation) in the new file. The zone structure can also be applied to the data structure of the Patch file as shown in Figure 10 The zone structure can also be applied to the data structure of the Patch file as shown in

[0292] The first pointer offset and the second pointer offset are not limited in the order of filling in the zone.

[0293] Exemplarily, the restoring thread can also determine the number of the zone based on the order of reading the zone in the patch file, and determine whether the data compression blocks described by the zone need to be processed by the restoring thread based on the number of the zone.

[0294] Exemplarily, the number of the zone can also be filled in each zone, so that each restoring thread can determine whether the data compression blocks described by the zone need to be processed by the restoring thread based on the number of the zone read.

[0295] In an optional embodiment, assuming that k restoring threads process the restoring of the patch file in parallel, the determination of whether the data compression blocks described by a zone need to be processed by the restoring thread can be based on the remainder of the number of the zone divided by the number of the restoring threads.

[0296] Assuming that the number of the zone is counted from 1. For the zone numbered x: if x%k=1, the data compression blocks described by the zone are processed by the restoring thread 1; if x%k=2, the data compression blocks described by the zone are processed by the restoring thread 2; if x%k=n, 0

[0297] Assuming that the number of the zone is counted from 0. For the zone numbered x: if x%k=0, the data compression blocks described by the zone are processed by the restoring thread 1; if x%k=1, the data compression blocks described by the zone are processed by the restoring thread 2; if x%k=n, 0

[0298] In another optional embodiment, assuming that the number of the zones is x, the x zones can be evenly divided into k parts, the data compression blocks described by the zones corresponding to the first part are processed by the restoring thread 1, the data compression blocks described by the zones corresponding to the second part are processed by the restoring thread 2, and so on.

[0299] In this way, the number of the zone corresponding to each restoring thread can be determined. The number of the zone corresponding to a restoring thread means that the data compression blocks described by the zone need to be processed by the restoring thread.

[0300] In the embodiment, the reduction thread number remainder result can be used to create a reduction operation execution chain table for each of the parallel k reduction threads according to the zone number. In each reduction operation execution chain table, the data filled in each node is the zone number and the address offset of the zone in the patch file. The address offset of the zone in the patch file can refer to the address offset relative to the start position of the file. It should be noted that the address offset of each zone in the patch file can be calculated according to the zone number and the total byte length of the data compression block described by each zone. For example, the address offset of zone2 relative to the start position of the file is the sum of the address offset of zone1 relative to the start position of the file and the total byte length of the data compression block described by zone1, the address offset of zone3 relative to the start position of the file is the sum of the address offset of zone2 relative to the start position of the file and the total byte length of the data compression block described by zone2, and so on.

[0301] Further, each reduction thread can read the corresponding zone in the patch file based on the data of each node in the corresponding reduction operation execution chain table, and perform data restoration processing on the data compression block described by the zone.

[0302] FIG. 24 shows a difference file restoration method provided by an embodiment of the application. As shown in FIG. 24, the flow of the difference file restoration method specifically includes:

[0303] S501, the electronic device parses the patch file to obtain the block size zonesize and the total number of control blocks x.

[0304] For example, the block size zonesize and the total number of control blocks x can be carried in the header of the patch file.

[0305] After the electronic device obtains the patch file, the header of the patch file is parsed, and after the file type is known according to the magic number recorded in the header, the zonesize and the total number of control blocks x can be read in the header.

[0306] S502, the electronic device determines whether the electronic device supports the difference file restoration processing according to the RAM space size M used for difference restoration and the zonesize, and if so, performs S503, and if not, performs error processing.

[0307] The electronic device can calculate the minimum RAM space required for restoring the Patch file according to the zone size. If the RAM space size M used by the electronic device for differential restoration is smaller than the minimum RAM space required for the restoration operation, the electronic device can determine that it cannot support the restoration processing of the differential file and perform error processing.

[0308] If the RAM space size M used by the electronic device for differential restoration is greater than or equal to the minimum RAM space required for the restoration operation, the electronic device can determine that it can support the restoration processing of the differential file.

[0309] As described above, the minimum RAM space required for the restoration operation of the Patch file is (zonesize+N2)*2+N1. Wherein, N1 is the size of the RAM memory space required for running the data compression algorithm, and N2 is the size of the RAM memory space occupied by the security buffer. For example, N2=2KB, and N1=16KB.

[0310] If the RAM space size M used by the electronic device for differential restoration is greater than or equal to ((zonesize+N2)*2+N1, the electronic device can determine that it can support the restoration processing of the differential file.

[0311] It should be noted that the RAM space used by the electronic device for differential restoration mentioned here is continuous, for example, implemented by a static array. If the RAM space used by the electronic device for differential restoration is dynamically allocated and non-continuous, the electronic device needs to apply for two RAM memory regions with a size of (zonesize+N2) and one RAM memory region with a size of N1, so that the electronic device can support the restoration processing of the differential file.

[0312] S503, the electronic device determines the parallel number k of the restoration threads according to M and zonesize.

[0313] When the RAM space size M used by the electronic device for differential restoration is large, the electronic device can complete the restoration operation of the Patch file through several parallel restoration threads to improve the restoration efficiency of the Patch file.

[0314] When the RAM space M used by the electronic device for differential restoration is a continuous RAM space (such as a static array), the parallel number k of the restoration threads is [(M-N1) / (zonesize+N2)]. Wherein, [] represents the rounding operation. If the parallel number k≥2, the electronic device can perform the restoration processing of the data compression blocks in the Patch file through k parallel restoration threads.

[0315] When the electronic device is used for differential restoration of non-continuous RAM space, the electronic device can dynamically apply for RAM space, if a 2k(k≥2) block size of (zone size+N2) RAM memory area and a block size of N1 RAM memory area can be applied, the electronic device can restore the data compression block in the patch file through k restoration threads in parallel.

[0316] S504, the electronic device determines whether k is greater than or equal to 2, if not, S505 is executed, if yes, S506 is executed.

[0317] Wherein, when k is not greater than or equal to 2, it has been determined that the electronic device supports differential file restoration processing before, so k=1, the electronic device executes the differential file restoration processing through single thread.

[0318] S505, the electronic device executes the differential file restoration processing through single thread.

[0319] When the electronic device executes the differential file restoration processing through single thread, the data compression blocks described in each zone of the patch file are processed in series, which can be referred to the related description in the foregoing, and will not be repeated here.

[0320] S506, the electronic device creates k restoration threads.

[0321] The electronic device creates a corresponding number of restoration threads according to the determined parallel number k, to realize the parallel restoration processing of the data compression blocks described in different zones of the patch file.

[0322] S507, the electronic device divides a group of RAM space corresponding to each restoration thread, and creates a restoration operation chain table corresponding to each restoration thread according to the total number of control blocks x.

[0323] For example, assuming that the parallel number k=2, the electronic device creates a first restoration thread and a second restoration thread for parallel restoration processing of the data compression blocks described in different zones of the patch file.

[0324] For each restoration thread, the electronic device needs to divide a group of RAM space corresponding to it, including the first RAM space area 301, the second RAM space area 302, the third RAM space area 303, and the fourth RAM space area 304, which can be referred to the related description in the foregoing, and will not be repeated here. Figure 21a Or Figure 21b .

[0325] For each restore thread, the electronic device also needs to create a restore operation chain table corresponding thereto. As described above, the zone number corresponding to each restore thread can be determined according to the remainder of the zone number and the number k of restore threads. Then, after the electronic device determines the address offset of each zone in the Patch file, the restore operation chain table corresponding to each restore thread can be created. In the restore operation chain table, the data (data) part of each node is filled with the zone number and the address offset of the zone corresponding to the number in the Patch file.

[0326] For example, the zone numbers corresponding to the first restore thread are zone1, zone3, zone5, etc. In the restore operation list corresponding thereto, the data (data) part of the first node is filled with zone1 and the address offset 1 of zone1 in the Patch file, and the link (next) part is filled with the pointer of the second node. The data (data) part of the second node is filled with zone3 and the address offset 3 of zone3 in the Patch file, and the link (next) part is filled with the pointer of the third node. The data (data) part of the third node is filled with zone5 and the address offset 5 of zone5 in the Patch file, and the link (next) part is filled with the pointer of the fourth node, and so on.

[0327] S508, each restore thread of the electronic device reads the corresponding data compression blocks in the Patch file according to the data in each node in the corresponding restore operation chain table, and restores the data compression blocks using a corresponding set of RAM space.

[0328] For a node in the restore operation chain table, the restore thread sequentially restores each data compression block (including Diff data compression block and / or Extra data compression block) described by the node. The process of restoring each Diff data compression block or Extra data compression block using a corresponding set of RAM space by the restore thread can be referred to the previous description and will not be repeated here.

[0329] For example, the first restore thread sequentially processes each data compression block described by zone1, zone3, zone5, etc. using the first set of RAM space, and the second restore thread sequentially processes each data compression block described by zone2, zone4, zone6, etc. using the second set of RAM space.

[0330] For example, zone1 describes 3 Diff data compression blocks and 4 Extra data compression blocks, and then the first restoring thread processes the 3 Diff data compression blocks and the 4 Extra data compression blocks in the first set of RAM space one by one, and then continues to process the data compression blocks described in zone3, and so on.

[0331] It should be noted that when the first restoring thread restores the data compression blocks described in zone1, the new data after restoration is written to the position corresponding to the second pointer offset in zone1 in the new file.

[0332] For example, zone2 describes 5 Diff data compression blocks and 2 Extra data compression blocks, and then the second restoring thread processes the 5 Diff data compression blocks and the 2 Extra data compression blocks in the second set of RAM space one by one, and then continues to process the data compression blocks described in zone4, and so on.

[0333] It should be noted that when the second restoring thread restores the data compression blocks described in zone2, the new data after restoration is written to the position corresponding to the second pointer offset in zone2 in the new file.

[0334] That is, when each restoring thread restores the data compression blocks described in a zone, the new data after restoration is written to the position corresponding to the second pointer offset in the zone in the new file.

[0335] S509, when each restoring thread completes the corresponding data compression block restoration operation according to the restoration operation chain table, the electronic device verifies the obtained target file.

[0336] Since the number of data compression blocks described in each zone is not the same, the time length of the data restoration operation performed by each restoring thread is also not the same. After each restoring thread completes the corresponding data compression block restoration operation according to the restoration operation chain table, all data compression blocks in the Patch file are restored.

[0337] At this time, the electronic device can determine whether the restored target file is correct based on the value of the verification field in the Patch file. For example, assuming that the hash value of the target file obtained by data restoration based on the Patch file is the same as the value of the verification field, the terminal can determine that the restored target file is correct, otherwise it can be determined that the restored target file is incorrect.

[0338] As described above, any one of the restoration threads can be roughly divided into the following stages when restoring the Diff data blocks: a stage of reading the Diff data compression blocks in the Patch file (referred to as the first stage), a stage of decompressing the Diff data compression blocks (referred to as the second stage), a stage of reading the data corresponding to the Diff data compression blocks in the old file (referred to as the fourth stage), a stage of synthesizing new data according to the old data and the Diff data blocks (referred to as the fourth stage), and a stage of writing data in the new file (referreded to as the fifth stage).

[0339] Any one of the restoration threads uses a set of RAM spaces corresponding thereto (i.e., the first, second, third and fourth RAM memory areas) to complete the restoration operation for each Diff data compression block.

[0340] The following describes the available states of the first and third RAM memory areas in the above stages. Figure 16 and Figure 24a The initial value of the available states of the first and third RAM memory areas is available. It is assumed that state = 0 indicates that the RAM memory area is available, and state = 1 indicates that the RAM memory area is unavailable.

[0341] In the first stage, the restoration thread writes the Diff data compression blocks read in the Patch file into the first RAM memory area, and the state of the first RAM memory area changes from 0 to 1.

[0342] In the second stage, the restoration thread performs a decompression operation on the Diff data compression blocks in the first RAM memory area, writes the Diff data blocks obtained after decompression into the third RAM memory area, the state of the third RAM memory area changes from 0 to 1, and the state of the first RAM memory area changes from 1 to 0.

[0343] In the third stage, the restoration thread reads the old data (or source data) corresponding to the Diff data compression blocks in the third RAM memory area in the static partition (i.e., the old file), writes the old data into the first RAM memory area (overwriting the Diff data compression blocks), and the state of the first RAM memory area changes from 0 to 1.

[0344] In the fourth stage, the restoration thread reads the old data in the first RAM memory region and the Diff data in the third RAM memory region to synthesize new target data, and writes the synthesized target data into the third RAM memory region. In this stage, the restoration thread changes the state of the third RAM memory region from 1 to 0, and applies for holding the object lock corresponding to the third RAM memory region to protect the data in the third RAM memory region. After the restoration thread finishes the data synthesis operation, the object lock corresponding to the third RAM memory region is released, and the state of the first RAM memory region is changed from 1 to 0, and the state of the third RAM memory region is changed from 0 to 1.

[0345] In the fifth stage, the restoration thread writes the synthesized new data in the third RAM memory region into a new file, i.e., falls into the target static partition, and changes the state of the third RAM memory region from 1 to 0 after the execution is completed.

[0346] Through the analysis of the above process, it can be known that the restoration thread writes the synthesized new data in the third RAM memory region into a new file in the fifth stage. After the fifth stage ends, the restoration thread continues to process the next Diff data compression block or Extra data compression block, and the processing process involves the first stage described above. However, in the fifth stage, the first RAM memory region is in an available state (state = 0), and is not used by the restoration thread until the fifth stage ends. In this way, in the fifth stage, the first RAM memory region has a waiting delay, which affects the processing efficiency of the restoration thread to a certain extent.

[0347] Similarly, as described above, when any one of the restoration threads processes the Extra data block, it can be roughly divided into the following stages: the stage of reading the Extra data compression block in the Patch file (referred to as the first stage), the stage of decompressing the Extra data compression block (referred to as the second stage), and the stage of writing data into a new file (referred to as the fifth stage).

[0348] Among them, any one of the restoration threads uses a set of RAM spaces corresponding thereto (i.e., the first RAM memory region, the second RAM memory region, the third RAM memory region, and the fourth RAM memory region) to complete the restoration operation on each Extra data compression block.

[0349] The following will be described in combination with Figure 17 and Figure 24bThe available states of the first and third RAM memory areas in the above-mentioned stages are analyzed. The initial value of the available state of the first and third RAM memory areas is available. It is assumed that state = 0 indicates that the RAM memory area is available, and state = 1 indicates that the RAM memory area is unavailable.

[0350] In the first stage, the restoration thread writes the Extra data compression block read in the patch file into the first RAM memory area, and the state of the first RAM memory area changes from 0 to 1.

[0351] In the second stage, the restoration thread decompresses the Extra data compression block in the first RAM memory area, writes the decompressed Extra data block into the third RAM memory area, the state of the third RAM memory area changes from 0 to 1, and the state of the first RAM memory area changes from 1 to 0.

[0352] In the fifth stage, the restoration thread writes the new data synthesized in the third RAM memory area into a new file, i.e., falls into the target static partition, and changes the state of the third RAM memory area from 1 to 0 after the execution is completed.

[0353] Through the analysis of the above-mentioned process, it can be known that the restoration thread writes the new data synthesized in the third RAM memory area into a new file in the fifth stage. After the fifth stage ends, the restoration thread continues to process the next Extra data compression block, and the processing flow also involves the first stage. However, in the fifth stage, the available state of the first RAM memory area is available (state = 0), and the first RAM memory area is not used until the fifth stage ends. Thus, in the fifth stage, the first RAM memory area has a waiting delay, which affects the processing efficiency of the restoration thread to a certain extent.

[0354] Therefore, when the restoration thread continuously processes two data compression blocks (whether Diff data compression blocks or Extra data compression blocks), the restoration processing flows of the two data compression blocks involve the first and fifth stages, and the first stage of the restoration flow of the second data compression block starts only after the fifth stage of the restoration flow of the first data compression block ends, so that the first RAM memory area has a waiting delay, which affects the processing efficiency of the restoration thread to a certain extent.

[0355] In order to solve the above-mentioned problem, for each restoration thread, when it restores each data compression block described by a zone, two sub-threads can be used to complete the restoration.

[0356] Figure 25A differential file restoring method is shown. As shown in Figure 25 The flow of the restoring thread for restoring each data compression block described by a zone can include the following steps:

[0357] S601, the restoring thread parses zone data.

[0358] S602, the restoring thread determines the number of Diff data compression blocks Diffnum and the number of Extra data compression blocks Extranum described by the zone, and sets Diff-zone-offset and Extra-zone-offset to 0.

[0359] Diff-zone-offset and Extra-zone-offset are global variables. Diff-zone-offset is used to represent the serial number of the current processing Diff data compression block in each Diff data compression block described by the current zone; Extra-zone-offset is used to represent the serial number of the current processing Extra data compression block in each Extra data compression block described by the current zone.

[0360] In this embodiment, the initial value of Diff-zone-offset and Extra-zone-offset is set to 0, and the serial number of the Diff data compression block and the Extra data compression block described by the zone is counted from 1. For example, when Diff-zone-offset is 1, it indicates that the current processing Diff data compression block is the Diff data compression block with serial number 1; when Extra-zone-offset is 2, it indicates that the current processing Extra data compression block is the Extra data compression block with serial number 2.

[0361] Generally, the number of Diff data compression blocks Diffnum and the number of Extra data compression blocks Extranum described by a zone are both greater than 0. In special cases, Diffnum or Extranum is 0.

[0362] S603, the restoring thread creates and starts a first sub-thread and a second sub-thread, and restores each data compression block described by the zone through the parallel first sub-thread and second sub-thread.

[0363] The first sub-thread is configured to restore the Diff data compression block or the Extra data compression block, and the second sub-thread is also configured to restore the Diff data compression block or the Extra data compression block, and the first sub-thread and the second sub-thread are parallel.

[0364] It should be noted that the starting order of the first sub-thread and the second sub-thread can be specified or random, and the embodiment is not limited.

[0365] As shown in the foregoing, when the first sub-thread or the second sub-thread restores the Diff data compression block, the processing flow can be divided into a first stage, a second stage, a third stage, a fourth stage, and a fifth stage. When the first sub-thread or the second sub-thread restores the Extra data compression block, the processing flow can be divided into the first stage, the second stage, and the fifth stage.

[0366] When the sub-thread restoration processing operation is in different stages, the processing state of the sub-thread is different. For example, when the sub-thread restoration processing operation is in the first stage, the processing state of the sub-thread is reading the difference data; when the sub-thread restoration processing operation is in the second stage, the processing state of the sub-thread is decompressing the difference data; when the sub-thread restoration processing operation is in the third stage, the processing state of the sub-thread is reading the source data; when the sub-thread restoration processing operation is in the fourth stage, the processing state of the sub-thread is synthesizing the target data; and when the sub-thread restoration processing operation is in the fifth stage, the processing state of the sub-thread is writing the target data, that is, writing the target data (or new data) into the target file (or new file).

[0367] Figure 26a The processing flow of the first sub-thread is shown. As Figure 26a The first sub-thread restores the data compression block, and the steps include:

[0368] S701, the first sub-thread is started.

[0369] S702, the first sub-thread determines whether the Diff-zone-offset is 0, or the Extra-zone-offset is 0, or the processing state of the second sub-thread is writing the target data, if yes, S703 is executed, and if not, S702 is executed.

[0370] When the Diff-zone-offset is 0, it indicates that the restoration processing of each Diff data compression block described by the zone has not started; when the Extra-zone-offset is 0, it indicates that the restoration processing of each Extra data compression block described by the zone has not started.

[0371] When the processing state of the second sub-thread is writing target data, it indicates that the second sub-thread is in the fifth stage of the processing flow of the data compression block. At this time, in order to avoid the waiting delay of the first RAM space region, the first sub-thread can perform the restoration processing on the next data compression block, thereby realizing the parallel processing with the second sub-thread.

[0372] If the judgment result of the above judgment condition is no, the first sub-thread waits and continues to execute the judgment flow shown in S702.

[0373] S703, the first sub-thread judges whether Diff-zone-offset is less than Diffnum, if yes, S704 is executed, if no, S706 is executed.

[0374] Since Diff-zone-offset is used to represent the serial number of the current processing Diff data compression block in each Diff data compression block described by the current zone, when Diff-zone-offset is less than Diffnum, it indicates that there is an unprocessed Diff data compression block in each Diff data compression block described by the current zone.

[0375] S704, the first sub-thread increments Diff-zone-offset.

[0376] When Diff-zone-offset is less than Diffnum, Diff-zone-offset is incremented by 1 to determine the Diff data compression block to be processed by the first sub-thread.

[0377] S705, the first sub-thread performs the restoration processing on the Diff data compression block corresponding to Diff-zone-offset, and executes S702.

[0378] At this time, the first sub-thread performs the restoration processing on the Diff data compression block corresponding to Diff-zone-offset based on the set of RAM spaces corresponding to the restoration thread, and the detailed steps can be referred to the foregoing, which will not be described herein.

[0379] After the first sub-thread completes the restoration processing on the Diff data compression block corresponding to Diff-zone-offset, it returns to execute S702 to judge whether the condition for the first sub-thread to perform the restoration processing on the next data compression block is met.

[0380] S706, the first sub-thread judges whether Extra-zone-offset is less than Extranum, if yes, S707 is executed, if no, S709 is executed.

[0381] Since the Extra-zone-offset is used to represent the serial number of the current processing Extra data compression block in each Extra data compression block described in the current zone, when the Extra-zone-offset is less than the Extranum, it indicates that there is an Extra data compression block which has not been processed in each Extra data compression block described in the current zone.

[0382] S707, the first sub-thread increments the Extra-zone-offset.

[0383] When the Extra-zone-offset is less than the Extranum, the Extra-zone-offset is processed by adding 1 to determine the Extra data compression block to be processed by the first sub-thread.

[0384] S708, the first sub-thread restores the Extra data compression block corresponding to the Extra-zone-offset and executes S702.

[0385] At this time, the first sub-thread restores the Extra data compression block corresponding to the Extra-zone-offset based on the group of RAM spaces corresponding to the restoring thread, and the detailed steps can be referred to the foregoing, which will not be described here.

[0386] After the first sub-thread restores the Extra data compression block corresponding to the Extra-zone-offset, it returns to execute S702 to determine whether the condition for the first sub-thread to restore the next data compression block is met.

[0387] S709, the first sub-thread ends.

[0388] When the Diff-zone-offset is not less than the Diffnum, it indicates that there is no Diff data compression block which has not been processed in each Diff data compression block described in the current zone. When the Extra-zone-offset is not less than the Extranum, it indicates that there is no Extra data compression block which has not been processed in each Extra data compression block described in the current zone. At this time, the first sub-thread can end.

[0389] Figure 26b The processing flow of the second sub-thread is shown. Similar to the first sub-thread, as described above, the steps of the second sub-thread to restore the data compression block include: Figure 26b

[0390] ​S801, the second sub-thread is started.

[0391] S802, the second sub-thread judges whether Diff-zone-offset is 0, or Extra-zone-offset is 0, or the processing state of the first sub-thread is writing target data, if yes, S803 is executed, if not, S802 is executed.

[0392] When Diff-zone-offset is 0, it indicates that the each Diff data compression block described by the zone has not started to be processed; when Extra-zone-offset is 0, it indicates that the each Extra data compression block described by the zone has not started to be processed.

[0393] When the processing state of the first sub-thread is writing target data, it indicates that the processing flow of the first sub-thread to the data compression block is in the fifth stage. At this time, in order to avoid the waiting delay of the first RAM space area, the second sub-thread can process the next data compression block at this time, and the parallel processing with the first sub-thread is realized.

[0394] If the judgment results of the above judgment conditions are all no, the second sub-thread waits and continues to execute the judgment flow shown in S802.

[0395] S803, the second sub-thread judges whether Diff-zone-offset is less than Diffnum, if yes, S804 is executed, if not, S806 is executed.

[0396] Since Diff-zone-offset is used to indicate the serial number of the current processing Diff data compression block in the each Diff data compression block described by the current zone, when Diff-zone-offset is less than Diffnum, it indicates that there is an unprocessed Diff data compression block in the each Diff data compression block described by the current zone.

[0397] S804, the second sub-thread increments Diff-zone-offset.

[0398] When Diff-zone-offset is less than Diffnum, the Diff-zone-offset is processed by adding 1 to determine the Diff data compression block to be processed by the second sub-thread.

[0399] S805, the second sub-thread processes the Diff data compression block corresponding to Diff-zone-offset, and executes S802.

[0400] At this time, the second sub-thread restores the Diff data compression block corresponding to the Diff-zone-offset based on the set of RAM spaces corresponding to the restoring thread, and the detailed steps can be referred to the foregoing and will not be described herein.

[0401] After the second sub-thread completes the restoration of the Diff data compression block corresponding to the Diff-zone-offset, the execution returns to S802 to determine whether the condition for the second sub-thread to restore the next data compression block is met.

[0402] S806, the second sub-thread determines whether the Extra-zone-offset is less than the Extranum. If yes, S807 is executed, and if no, S809 is executed.

[0403] Since the Extra-zone-offset is used to indicate the serial number of the currently processed Extra data compression block in each Extra data compression block described in the current zone, when the Extra-zone-offset is less than the Extranum, it indicates that there is an Extra data compression block that has not been processed in each Extra data compression block described in the current zone.

[0404] S807, the second sub-thread increments the Extra-zone-offset.

[0405] When the Extra-zone-offset is less than the Extranum, the Extra-zone-offset is incremented by 1 to determine the Extra data compression block to be processed by the first sub-thread.

[0406] S808, the second sub-thread restores the Extra data compression block corresponding to the Extra-zone-offset, and the execution returns to S802.

[0407] At this time, the second sub-thread restores the Extra data compression block corresponding to the Extra-zone-offset based on the set of RAM spaces corresponding to the restoring thread, and the detailed steps can be referred to the foregoing and will not be described herein.

[0408] After the second sub-thread completes the restoration of the Extra data compression block corresponding to the Extra-zone-offset, the execution returns to S802 to determine whether the condition for the second sub-thread to restore the next data compression block is met.

[0409] S809, the second sub-thread ends.

[0410] When Diff-zone-offset is not less than Diffnum, it indicates that there is no unprocessed Diff data compression block in each Diff data compression block described by the current zone. When Extra-zone-offset is not less than Extranum, it indicates that there is no unprocessed Extra data compression block in each Extra data compression block described by the current zone. At this time, the second sub-thread can end.

[0411] S604, the restoration thread judges whether each data compression block described by the zone is processed completely and whether the first sub-thread and the second sub-thread are ended, if yes, S605 is executed, if not, S604 is executed.

[0412] The restoration thread judges whether each data compression block described by the zone is processed completely and whether the first sub-thread and the second sub-thread are ended, if not, it waits and continues to judge, if yes, the restoration thread ends the restoration processing operation of the data compression block described by the zone.

[0413] S605, the restoration thread ends the restoration processing operation of the data compression block described by the zone.

[0414] After the restoration thread ends the restoration processing operation of the data compression block described by the zone, the next data compression block described by the zone can be processed according to the restoration operation execution chain corresponding thereto, and the processing flow can still refer to S601-S605, which will not be repeated here, until the data compression blocks of each zone recorded in the restoration operation execution chain are processed, and the restoration thread ends.

[0415] In this way, when a restoration thread realizes the restoration processing of each data compression block described by a zone through two sub-threads, the restoration efficiency of the data compression block can be improved.

[0416] As shown in Figure 27a When the restoration processing of each data compression block described by a zone is realized through a single thread, the restoration processing of the next data compression block does not start until the fifth phase of the restoration processing of the previous data compression block ends, which causes a waiting delay in the first RAM memory area and reduces the processing efficiency of the restoration thread to a certain extent.

[0417] However, as shown in Figure 27bAs shown, when the two sub-threads are used to restore each data compression block of a zone description, at the fifth stage of the first sub-thread for restoring the Diff data compression block 1, the second sub-thread can start the first stage of restoring the Diff data compression block 2. Similarly, at the fifth stage of the second sub-thread for restoring the Diff data compression block 2, the first sub-thread can start the second stage of restoring the Extra data compression block 1; at the fifth stage of the first sub-thread for restoring the Extra data compression block 1, the second sub-thread can start the first stage of restoring the Extra data compression block 2. In this way, without waiting for the fifth stage of the restoration process of the previous data compression block to end before the first stage of the restoration process of the next data compression block starts, the first RAM memory area no longer has a waiting delay, and the restoration time of multiple data compression blocks is reduced (compared with the prior art, as shown in Figure 27a and Figure 27b It can be clearly seen that the processing efficiency of the restoration thread is improved.

[0418] As shown in Figure 28 is a structural schematic diagram of an electronic device 100. Optionally, the electronic device 100 can be referred to as a terminal, and can also be referred to as a terminal device. For example, the terminal can be a smart phone, and the terminal can also be a wearable electronic device, for example, a smart watch. The present application does not make any limitation. It should be noted that the structural schematic diagram of the electronic device 100 can be applicable to the smart watch 100 or the mobile phone 200 in Figure 1 It should be understood that Figure 28 The electronic device 100 shown in Figure 28 The various components shown in

[0419] The electronic device 100 may include: a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display 194, and a subscriber identification module (SIM) card interface 195. The sensor module 180 may include a pressure sensor, a gyroscope sensor, an acceleration sensor, a temperature sensor, a PPG (Photo Plethysmo Graphy) sensor, a motion sensor, an air pressure sensor, a magnetic sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, and the like.

[0420] The processor 110 may include one or more processing units. For example, the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural network processing unit (NPU). The different processing units may be independent devices or integrated into one or more processors. The processor 110 may also be provided with a memory for storing instructions and data.

[0421] The charging management module 140 is configured to receive charging input from a charger. While charging the battery 142 , the charging management module 140 can also provide power to the electronic device through the power management module 141 .

[0422] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor, and the baseband processor, etc. The mobile communication module 150 can provide a solution for wireless communication including 2G / 3G / 4G / 5G, etc. applied to the electronic device 100. The wireless communication module 160 can provide a solution for wireless communication including wireless local area networks (WLAN) (e.g., wireless fidelity (Wi-Fi) network), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR) technology, etc. applied to the electronic device 100.

[0423] In some embodiments, the antenna 1 and the mobile communication module 150 of the electronic device 100 are coupled, and the antenna 2 and the wireless communication module 160 are coupled, so that the electronic device 100 can communicate with a network and other devices through wireless communication technology.

[0424] The electronic device 100 implements the display function through the GPU, the display screen 194, and the application processor, etc. The processor 110 can include one or more GPUs that execute program instructions to generate or change display information.

[0425] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. In some embodiments, the electronic device 100 can include 1 or N display screens 194, N being a positive integer greater than 1.

[0426] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The internal memory 121 can be used to store computer executable program codes, including instructions. The processor 110 executes various function applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121, so that the electronic device 100 implements the firmware file restoration method in the embodiments of the present application.

[0427] In the embodiments of the present application, the internal memory 121 can be used to store programs implementing the differential file generation method, the differential file restoration method, the BSDiff algorithm, etc. in the embodiments of the present application.

[0428] The electronic device 100 can implement an audio function through an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone interface 170D, and an application processor, etc. For example, music play, recording, etc.

[0429] The audio module 170 is configured to convert digital audio information into an analog audio signal output, and to convert an analog audio input into a digital audio signal. The audio module 170 can also be configured to encode and decode an audio signal. In some embodiments, the audio module 170 can be disposed in the processor 110, or some of the functional modules of the audio module 170 can be disposed in the processor 110.

[0430] The gyroscope sensor can be configured to detect a motion posture of the electronic device 100. In some embodiments, the angular velocity of the electronic device 100 around three axes (i.e., x, y, and z axes) can be determined through the gyroscope sensor. In some embodiments, the gyroscope sensor can also be configured to identify the posture of the electronic device to implement the identification of the behavior state of the user wearing or holding the electronic device 100.

[0431] The acceleration sensor can be configured to detect the magnitude of acceleration of the electronic device 100 in each direction (generally three axes). In some embodiments, when the electronic device 100 is stationary, the magnitude and direction of gravity can be detected through the acceleration sensor. In some embodiments, the acceleration sensor can also be configured to identify the posture of the electronic device to implement the identification of the behavior state of the user wearing or holding the electronic device 100.

[0432] The temperature sensor can be configured to detect the temperature of the electronic device 100. In some embodiments, the body temperature of the user wearing the electronic device 100 can be detected through the temperature sensor.

[0433] The PPG (Photo Plethysmo Graphy) sensor can be configured to detect the physiological parameter information of the wearer of the electronic device 100. The principle of the PPG sensor is to detect the fluctuation of the blood volume in the tissue microvascular bed under the action of the heart contraction and relaxation through optical detection. For example, when the heart contracts, the blood volume of the tissue increases, and the light absorption increases, so the light intensity detected by the light detector is smaller; when the heart relaxes, the blood volume of the tissue decreases, and the light absorption decreases, so the light intensity detected by the light detector is larger. Since the change of the light intensity of the PPG sensor is related to the slight change of the blood perfusion of the tissue, the PPG sensor can be used to provide the information of the cardiovascular system of the wearer of the electronic device 100, such as the physiological parameter information of blood pressure, blood oxygen, pulse rate (heart rate), and respiration rate, etc.

[0434] The pressure sensor is configured to sense a pressure signal and convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor can be disposed on the display screen 194. The electronic device 100 can also calculate the position of a touch based on the detection signal of the pressure sensor.

[0435] The touch sensor, also referred to as a "touch panel". The touch sensor can be disposed on the display screen 194, and the touch sensor and the display screen 194 form a touch screen, also referred to as a "touch screen". The touch sensor is configured to detect a touch operation applied thereto or in the vicinity thereof. The touch sensor can transmit the detected touch operation to the application processor to determine the type of touch event.

[0436] The keys 190 include a power key (or power button), a volume key, and the like. The keys 190 can be mechanical keys. Alternatively, the keys 190 can be touch keys. The electronic device 100 can receive key inputs and generate key signal inputs related to user settings and function control of the electronic device 100.

[0437] The motor 191 can generate a vibration prompt. The motor 191 can be used for incoming call vibration prompts and touch vibration feedback.

[0438] The indicator 192 can be an indicator light, which can be used to indicate a charging state, a power change, and can also be used to indicate a message.

[0439] The software system of the electronic device 100 can adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservice architecture, or a cloud architecture. The embodiments of the present application take the operating system of the layered architecture as an example to exemplarily illustrate the software structure of the electronic device 100.

[0440] Figure 29 is a software structure block diagram of the electronic device 100 of the embodiments of the present application.

[0441] The layered architecture of the electronic device 100 divides the software into several layers, and each layer has a clear role and division of labor. The layers communicate with each other through a software interface. In some embodiments, taking the electronic device 100 as an example, as shown in Figure 29 the operating system can be divided into six layers, from top to bottom, the UI (User Interface, user interface) application layer, the system service layer, the algorithm layer, the hardware abstraction layer, the kernel layer, and the driver layer.

[0442] The UI application layer can include a series of application packages, for example, can be a watch face, motion recording, call, exercise, and the like.

[0443] The system service layer can include a series of system services. The system service layer can include a heart rate service, which can provide physiological parameter information of a smart watch wearer, such as blood pressure, blood oxygen, pulse rate, respiratory rate, body temperature, and the like, and can also detect physiological parameter change information of the smart watch wearer. The system service layer can also include a step counting service, a calorie service, and a heart health service.

[0444] The algorithm layer can include a series of algorithm models. As shown in Figure 29 The algorithm layer can include a differential restoration algorithm model. The differential restoration algorithm model can be used for the differential file restoration method provided in the embodiment.

[0445] The hardware abstraction layer (HAL) is an interface layer between the operating system kernel and the hardware circuit. The HAL layer includes but is not limited to an audio HAL. The audio HAL is used to process an audio stream, for example, to perform noise reduction, directional enhancement, and the like on the audio stream.

[0446] The kernel layer and the driver layer are layers between hardware and software. As shown in Figure 29 The kernel layer includes at least an operating system kernel, and the driver layer includes at least a Bluetooth driver, a WiFi driver, and the like.

[0447] It can be understood that Figure 29 The layers in the software structure shown and the components included in each layer do not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 can include more or fewer layers than shown, and each layer can include more or fewer components, and the present application does not limit the electronic device 100.

[0448] It can be understood that the electronic device 100 includes hardware and / or software modules corresponding to each function in order to implement the differential file restoration method in the embodiments of the present application. The algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in hardware or a combination of hardware and computer software. Whether a certain function is implemented in hardware or computer software driven hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in conjunction with the embodiments, but such implementation should not be considered beyond the scope of the present application.

[0449] In one example, Figure 30 A schematic block diagram of an apparatus 800 according to an embodiment of the present application is shown, which can include a processor 801 and a transceiver / transceiver pin 802, and optionally further include a memory 803.

[0450] The various components of the apparatus 800 are coupled together by a bus system 804, which can include a data bus, a power bus, a control bus, and a state line. For the sake of proper understanding of the figures, all of the buses make up the bus system 804, but are shown as a single bus.

[0451] Optionally, the memory 803 can be configured to store instructions of the server in the differential file generation method embodiments. The processor 801 can be configured to execute the instructions in the memory 803, and control the receiving pin to receive signals and the sending pin to send signals.

[0452] Optionally, the memory 803 can be configured to store instructions of the smart terminal in the differential file restoration method embodiments. The processor 801 can be configured to execute the instructions in the memory 803, and control the receiving pin to receive signals and the sending pin to send signals.

[0453] The apparatus 800 can be a server, such as an OTA server, in the differential file generation method embodiments, or a smart terminal, such as a smart phone, a smart watch, etc., in the differential file restoration method embodiments.

[0454] The embodiment further provides a computer storage medium, which stores computer instructions. When the computer instructions are run on an electronic device, the electronic device executes the related method steps to implement the differential file generation method in the above embodiments, or executes the related method steps to implement the differential file restoration method in the above embodiments.

[0455] The embodiment further provides a computer program product. When the computer program product is run on a computer, the computer executes the related steps to implement the differential file generation method in the above embodiments, or implements the differential file restoration method in the above embodiments.

[0456] In addition, the embodiment of the present application further provides an apparatus, which can be a chip, a component or a module, and can include a processor and a memory connected with each other. The memory is configured to store computer execution instructions. When the apparatus is running, the processor can execute the computer execution instructions stored in the memory, so that the chip executes the differential file generation method or the differential file restoration method in the above method embodiments.

[0457] The electronic device (such as a server or a terminal) provided by the embodiment, the computer storage medium, the computer program product or the chip are all used to execute the corresponding method provided above, and thus the beneficial effects achieved by the electronic device, the computer storage medium, the computer program product or the chip can refer to the beneficial effects of the corresponding method provided above, which will not be described here.

[0458] Through the description of the above embodiments, those skilled in the art can understand that, for the convenience and brevity of description, only the division of the above functional modules is exemplified, and in actual application, the above functions can be completed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above.

[0459] In several embodiments provided in the present application, it should be understood that the disclosed device and method can be implemented in other ways. For example, the device embodiments described above are only illustrative, for example, the division of modules or units is only a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another device, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the displayed or discussed ones can be through some interfaces, indirect coupling or communication connection between devices or units, which can be electrical, mechanical or other forms.

[0460] The above description and the above embodiments are only used to illustrate the technical solutions of the present application, but not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that the technical solutions recorded in the foregoing embodiments can be modified, or some technical features can be replaced by equivalents; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for restoring a differential file, characterized in that: Used in electronic equipment, including: Obtaining a differential file; wherein the differential file includes at least one set of data compression blocks, the set of data compression blocks including difference Diff data compression blocks and / or newly added Extra data compression blocks, and the data compression blocks are divided based on a preset block size before being compressed; Determine the number k of parallel restoration threads according to the block size and the RAM space size of the electronic device used for restoring the differential file, and allocate a group of RAM spaces for each restoration thread; The k restoration threads are used to perform restoration processing on the differential file in parallel, wherein each restoration thread uses a corresponding set of RAM spaces to perform restoration processing on at least one set of data compression blocks, and writes the data obtained after the restoration processing into the target file.

2. The method according to claim 1, characterized in that The group of RAM spaces includes: a first RAM memory area, a second RAM memory area, a third RAM memory area and a fourth RAM memory area; wherein, The size of the first RAM memory area and the second RAM memory area is the block size; The second RAM memory area and the fourth RAM memory area are respectively security buffer areas of the first RAM memory area and the third RAM memory area; Each of the restoration threads shares a fifth RAM memory area, and the fifth RAM memory area is used to run a data compression algorithm.

3. The method according to claim 2, characterized in that Determining the number k of parallel restoration threads according to the block size and the RAM space size of the electronic device for restoring the differential file includes: k=[(M-N1) / (zonesize+N2)]; wherein M is the RAM space size of the electronic device used for differential file restoration, N1 is the size of the fifth RAM memory area, zonesize is the block size, N2 is the size of the security buffer area, and [] is a rounding operation.

4. The method according to claim 2, characterized in that The Diff data corresponding to the Diff data compression block is obtained based on the first operation; Each of the restoration threads performs restoration processing on a group of compressed data blocks, including: The restoration thread performs data restoration processing on the Diff data compression blocks or the Extra data compression blocks in a group of data compression blocks in sequence according to the parsing order; Whenever a Diff data compression block is obtained through parsing, a second operation is performed on the Diff data corresponding to the Diff data compression block and the existing data to obtain first target data, which is written into a target file; wherein the existing data is data that matches the Diff data compression block and is read from an existing file corresponding to the differential file, and the second operation is an inverse operation of the first operation; Every time an Extra data compression block is obtained through parsing, the Extra data compression block is decompressed to obtain second target data, which is written into the target file.

5. The method according to claim 4, characterized in that Performing a second operation on the Diff data corresponding to the Diff data compression block and the existing data to obtain first target data, and writing the first target data into the target file, including: Temporarily storing the Diff data in compressed blocks in the first RAM memory area; Decompressing the Diff data compressed blocks and temporarily storing the obtained Diff data blocks in a third RAM memory area; Reading existing data corresponding to the Diff data block from the existing file and temporarily storing it in the first RAM memory area; performing a second operation on the data in the first RAM memory area and the data in the third RAM memory area, and temporarily storing the obtained first target data in the third RAM memory area; The first target data temporarily stored in the third RAM memory area is written into the target file.

6. The method according to claim 4, characterized in that Decompressing the Extra data compressed blocks to obtain second target data and writing the second target data into the target file includes: Temporarily storing the Extra data compressed blocks in the first RAM memory area; Decompressing the Extra data compressed blocks and temporarily storing the obtained second target data in the third RAM memory area; The second target data temporarily stored in the third RAM memory area is written into the target file.

7. The method according to claim 1, characterized in that Each restoration thread uses a corresponding set of RAM spaces to perform restoration processing on at least one set of compressed data blocks, including: Creating a linked list for each restoration thread according to the number of data compression block groups included in the differential file and the sequence number of each group of data compression blocks, so that the restoration thread completes the restoration process of at least one group of data compression blocks according to the corresponding linked list; In the linked list, the data portion of the node is filled with the sequence numbers of a group of compressed data blocks and the first addresses of the restored data corresponding to the group of compressed data blocks written in the target file.

8. The method according to claim 6, characterized in that The data structure of the differential file includes a header, a control block, and a group of data compression blocks described by the control block; The header is filled with the magic number of the differential file and the block size; The control block is filled with a first pointer offset and a second pointer offset; wherein the first pointer offset is used to determine the data reading starting address corresponding to the set of data compression blocks in the existing file; the second pointer offset is used to determine the data writing starting address corresponding to the set of data compression blocks in the target file.

9. The method according to claim 6, characterized in that According to the modulo result of the serial number of the data compression block and the parallel quantity, each group of data compression blocks to be processed by each restoration thread is determined respectively.

10. The method according to claim 5 or 6, characterized in that Each restoration thread uses a corresponding set of RAM spaces to perform restoration processing on at least one set of compressed data blocks, including: Each of the restoration threads creates a first sub-thread and a second sub-thread; Performing restoration processing on the Diff data compression blocks or the Extra data compression blocks included in the group of data compression blocks in sequence by using a group of RAM spaces corresponding to the restoration thread through the first sub-thread and the second sub-thread; When the second sub-thread reaches the target stage, the first sub-thread continues to perform restoration processing on the set of compressed data blocks; When the first sub-thread reaches the target stage, the second sub-thread continues to perform restoration processing on the set of compressed data blocks; The target stage is to write the data temporarily stored in the third RAM memory area into the target file.

11. An electronic device, characterized in that: include: one or more processors; Memory; and one or more computer programs, wherein the one or more computer programs are stored in the memory, and when the computer programs are executed by the one or more processors, the electronic device executes the differential file restoration method according to any one of claims 1 to 10.

12. A computer-readable storage medium comprising a computer program, characterized in that When the computer program is run on an electronic device, the electronic device is enabled to execute the differential file restoration method according to any one of claims 1 to 10.

Citation Information

Patent Citations

  • Parallel data difference method

    CN107016053A

  • Parallel change file tracking in a distributed file server virtual machine (FSVM) architecture

    US20210200641A1