Differential file restoration method and electronic equipment

CN119836620APending Publication Date: 2025-04-15HONOR DEVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202380058559.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2022-09-09
Filing Date
2023-08-17
Publication Date
2025-04-15

AI Technical Summary

Technical Problem

How to improve the efficiency of restoring differential files when performing firmware upgrades using the differential package upgrade method, especially for lightweight embedded devices with limited RAM memory space?

Method used

The number of parallel restoration threads is adaptively determined based on the block size of the differential file and the RAM memory space size. Multiple threads are used for parallel restoration processing. A safe buffer in the RAM memory space is used to avoid data overflow. A low-memory data compression algorithm such as LZMA is used for data block compression.

Benefits of technology

It improves the efficiency of differential file restoration and reduces RAM consumption, enabling lightweight embedded devices to efficiently complete firmware upgrades.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119836620A_ABST
    Figure CN119836620A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a method for restoring a differential file and electronic equipment. In the method, a differential file comprises 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 being compressed; when the electronic equipment restores the differential file, firstly, the parallel number k of restoration threads is determined according to the block size and the RAM space size, and then the k restoration threads are adopted to carry out restoration processing on the differential file in parallel, and each reduction thread uses the corresponding group of RAM spaces to perform reduction processing on the at least one group of data compression blocks. Therefore, when the differential file is subjected to reduction processing, the electronic equipment can adaptively determine the parallel number of the reduction threads according to the RAM memory space for reducing the differential file, and the reduction efficiency of the differential file is improved through parallel processing of the multiple threads.
Need to check novelty before this filing date? Find Prior Art

Description

Differential file restoration method and electronic device

[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office of China on September 9, 2022, with application number 202211101979.2 and application name “Differential file restoration method and electronic device”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] 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

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

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

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

[0006] Summary of the Invention

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

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

[0009] 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;

[0010] 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;

[0011] The electronic device uses k restoration threads to restore the differential file in parallel, wherein each restoration thread uses a corresponding set of RAM space to restore at least one set of data compression blocks, and writes the data obtained after the restoration process into the target file.

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

[0013] According to the first aspect, a group of RAM spaces may 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 block sizes; 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 restoration thread shares the fifth RAM memory area, and the fifth RAM memory area is used to run a data compression algorithm.

[0014] In this way, the electronic device can perform data compression and block restoration operations based on a smaller RAM memory space. Moreover, setting a safety buffer zone for the first RAM memory area and the third RAM memory area will not affect the accuracy of data processing even if the data increases after data compression.

[0015] According to the first aspect, or any implementation of the first aspect above, the electronic device determines the parallel number k of restoration threads based on the block size and the RAM space size of the electronic device used for differential file restoration, where 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 safety buffer area, and [] is a rounding operation.

[0016] According to the first aspect, or any implementation of the first aspect above, the Diff data corresponding to the Diff data compression block is obtained based on the first operation; each restoration thread performs restoration processing on a group of data compression blocks, which may include: the restoration thread performs data restoration processing on the Diff data compression block or the Extra data compression block in the group of data compression blocks in sequence according to the parsing order; each time a Diff data compression block is obtained through parsing, the Diff data corresponding to the Diff data compression block is subjected to a second operation with existing data to obtain first target data, and the data is written into the target file; wherein the existing data is data that matches the Diff data compression block read from the existing file corresponding to the differential file, and the second operation is the inverse operation of the first operation; each time an Extra data compression block is obtained through parsing, the Extra data compression block is decompressed to obtain second target data, and the data is written into the target file.

[0017] Exemplarily, the first operation is a subtraction operation, and the second operation is an addition operation.

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

[0019] According to the first aspect, or any implementation of the first aspect above, the electronic device performs a second operation on the Diff data corresponding to the Diff data compression block and the existing data to obtain first target data, and writes the first target data into the target file, which may include: the electronic device temporarily stores the Diff data compression block in the first RAM memory area; the electronic device decompresses 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 in the existing file and temporarily stores it in the first RAM memory area; the electronic device performs a 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; the electronic device writes the first target data temporarily stored in the third RAM memory area into the target file.

[0020] According to the first aspect, or any implementation method of the above first aspect, the electronic device decompresses the Extra data compressed blocks to obtain second target data, and writes them into the target file, which may include: the electronic device temporarily stores the Extra data compressed blocks in the first RAM memory area; the electronic device decompresses the Extra data compressed blocks and temporarily stores the obtained second target data in the third RAM memory area; the electronic device writes the second target data temporarily stored in the third RAM memory area into the target file.

[0021] According to the first aspect, or any implementation of the first aspect above, each restoration thread uses a corresponding group of RAM space to restore at least one group of data compression blocks, which may include: the electronic device creates a linked list for each restoration thread based on the number of data compression block groups included in the differential file and the sequence numbers of each group of data compression blocks, so that the restoration thread completes the restoration processing of at least one group of data compression blocks according to the corresponding linked list; wherein, in the linked list, the data part of the node is filled with the sequence number of a group of data compression blocks, and the first address of the restoration data corresponding to a group of data compression blocks written in the target file.

[0022] According to the first aspect, or any implementation of the first aspect above, 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 and block size of the differential file; 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 group of data compression blocks in the existing file; the second pointer offset is used to determine the data writing starting address corresponding to the group of data compression blocks in the target file.

[0023] According to the first aspect, or any implementation of the first aspect above, the electronic device determines each group of data compression blocks to be processed by each restoration thread according to the modulo result of the serial number of the data compression block and the parallel quantity.

[0024] According to the first aspect, or any implementation of the first aspect above, each restoration thread uses a group of RAM spaces corresponding to it to perform restoration processing on at least one group of data compression blocks, which may include: each restoration thread creates a first sub-thread and a second sub-thread; the electronic device uses a group of RAM spaces corresponding to the restoration thread through the first sub-thread and the second sub-thread to restore the Diff data compression blocks or the Extra data compression blocks included in a group of data compression blocks in turn; wherein, when the second sub-thread executes to the target stage, the first sub-thread continues to perform restoration processing on a group of data compression blocks; when the first sub-thread executes to the target stage, the second sub-thread continues to perform restoration processing on a group 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.

[0025] In this way, when each restoration thread restores a group of data compression blocks, there is no need to wait until the restoration process of the previous data compression block is completely completed before starting the restoration process of the next data compression block. This eliminates the waiting delay in the first RAM memory area, reduces the restoration time of a group of data compression blocks, and improves the processing efficiency of the restoration thread.

[0026] 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 differential file restoration method described in the first aspect and any one of the implementations of the first aspect.

[0027] The second aspect and any implementation of the second aspect correspond to the first aspect and any implementation of the first aspect, respectively. The technical effects corresponding to the second aspect and any implementation of the second aspect can be referred to the technical effects corresponding to the first aspect and any implementation of the first aspect, and will not be repeated here.

[0028] In a third aspect, an embodiment of the present application provides a computer-readable storage medium comprising a computer program, which, when executed on an electronic device, causes the electronic device to execute the differential file restoration method of the first aspect and any one of its implementations.

[0029] The third aspect and any implementation of the third aspect correspond to the first aspect and any implementation of the first aspect, respectively. The technical effects corresponding to the third aspect and any implementation of the third aspect can be referred to the technical effects corresponding to the first aspect and any implementation of the first aspect, and will not be repeated here.

[0030] In a fourth aspect, an embodiment of the present application provides a computer program product, including a computer program. When the computer program is run, the computer executes the differential file restoration method in the first aspect and any one of the implementations of the first aspect.

[0031] The fourth aspect and any implementation of the fourth aspect correspond to the first aspect and any implementation of the first aspect, respectively. The technical effects corresponding to the fourth aspect and any implementation of the fourth aspect can be referred to the technical effects corresponding to the first aspect and any implementation of the first aspect, and will not be repeated here.

[0032] In a fifth aspect, the present application provides a chip comprising a processing circuit and a transceiver pin. The transceiver pin and the processing circuit communicate with each other via an internal connection path, and the processing circuit executes the differential file restoration method of the first aspect and any one of the implementations of the first aspect to control the receiving pin to receive a signal and the transmitting pin to send a signal.

[0033] The fifth aspect and any implementation of the fifth aspect correspond to the first aspect and any implementation of the first aspect, respectively. The technical effects corresponding to the fifth aspect and any implementation of the fifth aspect can be referred to the technical effects corresponding to the first aspect and any implementation of the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] FIG1 is a schematic diagram illustrating an exemplary application scenario;

[0035] FIG2 is a schematic diagram illustrating an exemplary process of performing differential restoration on a firmware file;

[0036] FIG3 is a schematic diagram showing an exemplary differential principle;

[0037] FIG4 is a schematic diagram showing an exemplary data structure of a differential file;

[0038] FIG5 is a schematic diagram showing an exemplary reduction principle;

[0039] FIG6 is a schematic diagram illustrating an exemplary data restoration operation;

[0040] FIG7 is a schematic diagram of a method for generating a differential file provided in this embodiment;

[0041] FIG8 is a diagram illustrating an example of a data structure of a differential file provided in this embodiment;

[0042] FIG9 is a schematic diagram of a method for generating a differential file provided in this embodiment;

[0043] FIG10 is a diagram illustrating an example of a data structure of a differential file provided in this embodiment;

[0044] FIG11a is a schematic diagram of a method for generating a differential file provided in this embodiment;

[0045] FIG11b is a schematic diagram of a data block division method provided by this embodiment;

[0046] FIG12 is a schematic diagram of a method for restoring a differential file provided by this embodiment;

[0047] FIG13 is a schematic diagram of a differential file restoration operation provided by this embodiment;

[0048] FIG14 is a schematic diagram of RAM space usage when data restoration is performed based on Diff data compression and segmentation according to the present embodiment;

[0049] FIG15 is a schematic diagram of RAM space usage when data restoration is performed based on Extra data compression and segmentation according to this embodiment;

[0050] FIG16 is a schematic diagram of RAM space usage when data restoration is performed based on Diff data compression and segmentation according to this embodiment;

[0051] FIG17 is a schematic diagram of RAM space usage when data restoration is performed based on Extra data compression and block generation according to this embodiment;

[0052] FIG18 is a schematic diagram of RAM space usage when data restoration is performed based on Diff data compression and segmentation according to this embodiment;

[0053] FIG19 is a schematic diagram of RAM space usage when data restoration is performed based on Extra data compression and segmentation according to this embodiment;

[0054] FIG20 is a schematic diagram illustrating an exemplary application scenario;

[0055] FIG21 a is a schematic diagram showing an exemplary RAM space partition for restoring thread parallelism;

[0056] FIG21 b is a schematic diagram showing an exemplary RAM space division for parallel restoration of threads;

[0057] FIG22 is a schematic diagram illustrating an exemplary parallel restoration of differential data;

[0058] FIG23 is a diagram illustrating an example of a data structure of a differential file provided in this embodiment;

[0059] FIG24a is a schematic diagram showing changes in RAM memory area occupancy status when data restoration is performed based on Diff data compression and segmentation, provided by this embodiment;

[0060] FIG24b is a schematic diagram showing changes in RAM memory area occupancy during data restoration based on Extra data compression and block generation according to this embodiment;

[0061] FIG25 is a schematic diagram of the processing flow of the restoration thread provided by this embodiment;

[0062] FIG26a is a schematic diagram of the processing flow of the first sub-thread in the restoration thread provided by this embodiment;

[0063] FIG26 b is a schematic diagram of the processing flow of the second sub-thread in the restoration thread provided by this embodiment;

[0064] FIG27a is a schematic diagram showing the duration of continuous data compression and block restoration based on a single thread provided by this embodiment;

[0065] FIG27b is a schematic diagram showing the duration of continuous data compression and block restoration based on multi-threading provided by this embodiment;

[0066] FIG28 is a schematic diagram illustrating a hardware structure of an electronic device;

[0067] FIG29 is a schematic diagram illustrating an exemplary software structure of an electronic device;

[0068] FIG30 is a schematic structural diagram of an exemplary device. DETAILED DESCRIPTION

[0069] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0070] The term "and / or" in this article is merely a description of the association relationship between associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.

[0071] In the description and claims of the embodiments of this application, the terms "first" and "second" are used to distinguish different objects, rather than to describe a specific order of objects. For example, the terms "first target object" and "second target object" are used to distinguish different objects, rather than to describe a specific order of objects.

[0072] In the embodiments of this application, words such as "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of this application should not be interpreted as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner.

[0073] In the description of the embodiments of this application, unless otherwise specified, "multiple" means two or more. For example, "multiple processing units" means two or more processing units; "multiple systems" means two or more systems.

[0074] When the terminal device performs an online firmware upgrade, if the OTA differential package upgrade method is used for firmware upgrade, the terminal device needs to have the ability to restore the differential file, that is, based on the differential file and the existing firmware file corresponding to the differential file (that is, the old version of the firmware file, hereinafter referred to as the old firmware file), generate the corresponding new version of the firmware file (hereinafter referred to as the new firmware file). Then, the terminal device can complete the firmware upgrade based on the new version of the firmware file.

[0075] FIG1 illustrates an exemplary application scenario, using a smartwatch 100 as an example for online firmware upgrades. The smartwatch 100 is a low-end smart terminal device (also known as a lightweight embedded device) without independent networking capabilities. It can communicate with a smartphone 200 via Bluetooth. Referring to FIG1 , the smartphone 200 has an application app installed that corresponds to the smartwatch 100. This app is used to connect the smartwatch 100 and smartphone 200, downloading applications or files, etc. Furthermore, the smartwatch 100 can communicate with an OTA server 300 via this app. For example, the smartwatch 100 can periodically query the OTA server 300 through the app to determine whether an upgrade differential package corresponding to the smartwatch 100 exists. If an upgrade differential package corresponding to the smartwatch 100 is found, the app can send an upgrade differential package download request to the OTA server 300 when online upgrade conditions are met (e.g., battery level, network status, Bluetooth status, etc. meet preset conditions). This download request is then sent via the app to the smartphone 200. Among them, the smart phone can send the downloaded upgrade differential package to the smart watch 100 via Bluetooth technology. Then, 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 restoration.

[0076] Continuing with FIG1 , the upgrade differential package corresponding to the smartwatch 100 can be generated based on the differential data package production 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, but this embodiment does not limit this. Regardless of whether the upgrade differential package is generated based on the differential data package production 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.

[0077] In the application scenario shown in FIG1 , the smart phone 200 is a smart terminal device with independent networking capabilities, serving as a relay device between the smart watch 100 and the OTA server 300 .

[0078] In some implementations, if the smart watch 100 has independent networking capabilities, it can also communicate directly 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 to download the corresponding upgrade differential package from the OTA server 300.

[0079] In the application scenario shown in Figure 1, the terminal device with the need for online firmware upgrade is explained by taking the smart watch 100 as an example. Among them, the terminal device with the need for online firmware upgrade can also be a smart bracelet, smart headphones and other wearable devices, or it can be any embedded node device in the Internet of Things scenario (for example, a node device for collecting information such as temperature and humidity), which is not limited in this embodiment. If the terminal device with the need for online firmware upgrade is a low-end device that does not have an independent networking function, it is necessary to communicate with the OTA server through a relay device to download the upgrade differential package through the relay device. If the terminal device with the need for online firmware upgrade is a low-end device with an independent networking function, it can directly communicate with the OTA server to download the upgrade differential package.

[0080] FIG2 exemplarily shows a flowchart of firmware file differential restoration.

[0081] As shown in Figure 2, on the server side (or tool side), the server performs differential processing on the paired new firmware files and old firmware files according to a preset differential algorithm (such as the BSDiff algorithm) to obtain a differential file (Patch file). In this way, the server can obtain multiple differential files corresponding to the firmware upgrade. The number of differential files is related to the firmware to be upgraded, and this embodiment does not limit this. Furthermore, the server can compress and package these multiple differential files to generate an upgraded differential package. Among them, the upgraded differential package can include multiple compressed differential files, as well as description files corresponding to these multiple differential files, etc.

[0082] When a terminal needs to upgrade its firmware, it requests the server to download the upgrade differential package. After receiving the upgrade differential package, the terminal decompresses it to obtain the individual differential files. For example, the terminal restores a differential file based on the old firmware file that matches it to obtain the corresponding new firmware file. This allows the terminal to obtain multiple new firmware files, which can then be used to perform firmware upgrades.

[0083] 2 , in the firmware file differential restoration process, the file differential operation and the differential packet compression operation are performed on the server side, and the differential packet decompression operation and the differential file restoration operation are performed on the terminal side.

[0084] When the terminal is a lightweight embedded device (such as a wearable device), its RAM resources are limited, which can seriously affect the efficiency of the differential package decompression and restoration process. It may even cause the firmware upgrade to fail due to the excessive size of the differential file. Therefore, if the memory consumption involved in the differential file restoration process can be reduced, it will be more suitable for firmware upgrade scenarios of lightweight embedded devices.

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

[0086] (1) Difference Principle (Bsdiff Principle)

[0087] The core idea of ​​the differential principle is to utilize as much data as possible from the old file and add as little new data as possible to construct the new file.

[0088] FIG3 exemplarily shows a file difference process based on the Bsdiff principle.

[0089] Referring to Figure 3, the old file data and the new file data are compared to determine the longest similar substrings (i.e., substrings) in the two. Exemplarily, the data 01_new in the new file data is "1010101010101010101", and the data 01_old in the old file data is "101010111010101011101", and the data 01_new in the new file data and the data 01_old in the old file data are one longest similar substring. Another exemplary embodiment, the data 03_new in the new file data and the data 02_old in the old file data are another longest similar substring. Exemplarily, in the new file data, data 02_new is between data 01_new and data 03_new, and there is no substring similar to data 02_new in the old file data, so data 02_new is the data newly added in the new file. Similarly, in the new file data, data 04_new is also the newly added data.

[0090] Therefore, the difference data (Diff data) can be calculated based on the similar substrings in the new file data and the old file data. The difference data and the newly added data (Extra data) together constitute the incremental update data (Patch data). As shown in Figure 3, the data 01_new in the new file and the data 01_old in the old file are subtracted to obtain the Diff data 01 in the Patch data; the data 03_new in the new file and the data 02_old in the old file are subtracted to obtain the Diff data 02 in the Patch data. At the same time, 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. By analogy, all the Diff data and Extra data can be obtained based on the new file data and the old file data to form the Patch data.

[0091] It should be noted that, typically, in patch data generated using the BSDiff algorithm, Diff data and Extra data appear in pairs, with each block of Diff data followed by a block of Extra data. This means that the patch data includes at least one set of incremental update data, and each set of incremental update data typically includes both Diff data and Extra data. In some special cases, Diff data and Extra data may not appear in pairs. For example, the last set of incremental update data in the patch data may include only Diff data or only Extra data.

[0092] It should be noted that the order and position offset of the Diff data and Extra data in the Patch data are consistent with the new file data. Therefore, by performing data restoration processing on the Diff data and Extra data in the Patch data in sequence, the new file data corresponding to the Patch data can be obtained.

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

[0094] After obtaining the Patch data based on the new file data and the old file data, the Patch data may be encoded to obtain a corresponding Patch file.

[0095] Figure 3 illustrates an exemplary data structure of a patch file, which includes a general encoding header, encoding information corresponding to a set of diff data and extra data, and the diff data and 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, such as 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.

[0096] Figure 4 exemplarily shows a data structure of a Patch file. As shown in Figure 4, the data structure of the Patch file includes a header, a control block, a Diff block (difference data block) and an Extra block (newly added data block).

[0097] The header contains 8 bytes, which are used to fill in the magic number. Here, the magic number is used to determine the file type.

[0098] Each control block consists of 24 bytes, which are used to describe a set of Diff blocks and Extra blocks. In other words, the data recorded in the control block can be used as encoding information for the set of Diff blocks and Extra blocks it describes. The first 8 bytes of the control block are used to fill in the byte length of the Diff block it describes; the middle 8 bytes of the control block are used to fill in the byte length of the Extra block it describes; and the last 8 bytes of the control block are used to fill in the pointer offset, which is used to determine the location in the old file where to read data (data used for addition operations with the Diff data).

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

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

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

[0102] Before packaging multiple Patch files, the Patch files may be compressed.

[0103] In one possible implementation, when compressing a Patch file having a data structure as shown in FIG4 , compression may be performed by data blocks, that is, each control block (i.e., control block 1 or control block 2 or control block n), each Diff block (i.e., Diff block 1 or Diff block 2 or Diff block n), and each Extra block (i.e., Extra block 1 or Extra block 2 or Extra block n) may be compressed separately.

[0104] In one possible implementation, when compressing a Patch file with a data structure as shown in FIG4 , the entire file can be compressed, that is, the Header, control block 1, Diff block 1, Extra block 1, control block 2, Diff block 2, Extra block 2, …, control block n, Diff block n, and Extra block n are compressed together.

[0105] In one possible implementation, when compressing a Patch file having a data structure as shown in FIG4 , the entire file may be divided into x sub-files according to a preset size and then compressed. Assuming that the size of the entire file is N, the size of each sub-file is N / x.

[0106] In one possible implementation, when compressing a Patch file having a data structure as shown in FIG4 , compression may be performed by data block type, that is, compressing multiple control blocks (i.e., control block 1, control block 2, ..., control block n), multiple Diff blocks (i.e., Diff block 1, Diff block 2, ..., Diff block n), and multiple Extra blocks (i.e., Extra block 1, Extra block 2, ..., Extra block n) separately.

[0107] In this way, after the server performs differential processing on each group of new firmware files and old firmware files to obtain multiple Patch files, these multiple Patch files are compressed and packaged to obtain corresponding upgrade differential packages, waiting for the terminal to query and download the upgrade differential packages.

[0108] (2) Reduction principle (bspatch principle)

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

[0110] FIG5 exemplarily shows a file restoration process based on the bspatch principle.

[0111] 5 , 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 encoding the Patch data.

[0112] The data structure of the Patch file can be found in the explanation of Figure 4 above and will not be repeated 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. Furthermore, the ordering of each pair of Diff data and Extra data in the Patch data is consistent with the new file data.

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

[0114] As shown in Figure 4, in a patch file, each control block is used to describe a pair of diff blocks and extra blocks. Therefore, the terminal can obtain the corresponding diff data and extra data based on the content recorded in the control block, and restore the obtained diff data and extra data to obtain the data in the new file.

[0115] Taking the Diff01 and Extra01 data in the Patch data as an example, when restoring the new file data: Diff01 data is read, and data 01_old matching Diff01 data is read from the old file. Diff01 data and data 01_old are added to obtain data 01_new and written to the new file. Extra01 data is read and written directly to the new file as data 02_new. Similarly, Diff02 data is read, and data 02_old matching Diff02 data is read from the old file. Diff02 data and data 02_old are added to obtain data 03_new and written to the new file. Extra02 data is read and written directly to the new file as data 04_new. Similarly, the terminal can obtain all the data in the new file based on the Patch data in the Patch file and the relevant data in the old file.

[0116] The following uses (x, y, z) to represent each control block as an example, and explains the restoration process based on the Patch file in conjunction with Figure 6.

[0117] As shown in Figure 6, in the Patch file, the content filled in control block 1 is (x1, y1, z1), which is used to describe Diff block 1 and Extra block 1. Among them, the byte length of Diff block 1 is x1, and the byte length of Extra block 1 is x2.

[0118] The terminal parses the patch file and finds the (x1, y1, z1) filled in control block 1. First, the terminal reads x1-length Diff data from the patch file and x1-length data from the old file. It then adds these two x1-length data segments to obtain x1-length new file data and writes them to the new file (or target file). Then, the terminal reads y1-length Extra data from the patch file and writes it directly to the new file as y1-length new file data.

[0119] For example, in the file data structure shown in FIG4 , after the header and before the control block 1, a control block 0 may be included, which is filled with (0, 0, z0). The z0 filled in the control block 0 is used to determine the pointer offset for reading x1-length data in the old file. Since the old file pointer is currently at the starting position of the old file, after offsetting the old file pointer by z0 from the starting position of the old file, the old file data of x1 length that matches the x1-length Diff data can be read from the old file.

[0120] 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 Diff data of x2 length in the Patch file, and reads the data of x2 length in the old file, and adds these two segments of data of x2 length to obtain new file data of x2 length, and writes them into the new file. Among them, after the pointer of the old file is offset by z1 based on the current position, the old file data of x2 length corresponding to the Diff data of x2 length can be read in the old file. Then, the terminal continues to read the Extra data of y2 length in the Patch file, and writes it directly into the new file as the new file data of y2 length.

[0121] Similarly, the terminal can obtain a new file based on the Patch file and the old file, completing the restoration process of a new file.

[0122] In this way, the terminal can restore each new file based on each patch file in the upgrade differential package and the corresponding old file.

[0123] 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. Its byte length is related to the difference between the new and old files, and can be tens of KB, or up to hundreds or even thousands of KB.

[0124] When a terminal restores a patch file, the amount of RAM memory space required is directly related to the byte length of the Diff block or Extra block. The larger the byte length of the Diff block or Extra block, the more RAM memory space the terminal requires to process it. For example, if the byte length of the Diff block is 200KB, the terminal must allocate at least 200KB of RAM memory space to process it. When the terminal's RAM memory space is limited, it is impossible or difficult for the terminal to meet the requirements of processing the Diff block or Extra block. Therefore, the data structure of the Patch file obtained based on the BSDiff algorithm is extremely unfriendly to the firmware differential package upgrade scenario of lightweight embedded devices.

[0125] To solve the above technical problems and reduce the terminal RAM memory consumption involved in the differential file restoration process, this embodiment provides a differential file generation method, which is applied to the server side. The server mentioned here can be understood as any electronic device for generating differential files.

[0126] FIG7 exemplarily shows a file difference process based on the Bsdiff principle provided by this embodiment.

[0127] As mentioned above, the old file data and the new file data are compared to determine the longest similar substrings (i.e., substrings) in the two. Exemplarily, the data 01_new in the new file data is "1010101010101010101", and the data 01_old in the old file data is "101010111010101011101", and the data 01_new in the new file data and the data 01_old in the old file data are one longest similar substring. Exemplarily, the data 03_new in the new file data and the data 02_old in the old file data are another longest similar substring. Exemplarily, in the new file data, the data 02_new is between the data 01_new and the data 03_new, and there is no substring similar to the data 02_new in the old file data, so the data 02_new is the data newly added in the new file. Similarly, in the new file data, the data 04_new is also the newly added data.

[0128] Thus, the difference data (Diff data) can be calculated based on the similar substrings in the new file data and the old file data. The difference data and the newly added data (Extra data) together constitute the incremental update data (Patch data). As shown in Figure 7, the data 01_new in the new file and the data 01_old in the old file are subtracted to obtain the Diff data 01 in the Patch data; the data 03_new in the new file and the data 02_old in the old file are subtracted to obtain the Diff data 02 in the Patch data. At the same time, 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. By analogy, all the Diff data and Extra data can be obtained based on the new file data and the old file data to form the Patch data.

[0129] It should be noted that in the patch data generated using the BSDiff algorithm, the Diff data and Extra data appear in pairs, with each block of Diff data followed by a block of Extra data. Furthermore, the position offsets of each pair of Diff data and Extra data in the patch data are consistent with the new file data.

[0130] After obtaining the patch data, the server divides the Diff data and Extra data in the patch data into blocks according to the block size (zonesize). Each Diff data block and Extra data block is the minimum independent processing data unit when the terminal restores the differential file.

[0131] The zonesize can be determined based on the terminal's RAM memory space, specifically the size of the contiguous RAM memory space available for differential file restoration. The zonesize can also be understood as the maximum number of bytes supported by the terminal's RAM memory space during differential file restoration.

[0132] Continuing with reference to Figure 7, for the Diff data 01 in the Patch data, it is divided into n1 Diff data blocks according to zonesize. In 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 is less than or equal to zonesize. Among them, the data sorting of these n1 Diff data blocks is the same as that of Diff data 01. Similarly, for the Extra data 01 in the Patch data, it is also divided into n2 Extra data blocks according to zonesize. In 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 is less than or equal to zonesize. Among them, the data sorting of these n2 Extra data blocks is also the same as that of Extra data 01.

[0133] Exemplarily, when the RAM memory area used by the terminal device for differential file restoration is not reused, the continuous RAM memory space used by the terminal device for differential file restoration 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, wherein the first RAM memory area, the second 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 fourth RAM memory area is used for data decompression operations.

[0134] Assume that the terminal device's RAM memory space for differential file restoration is M, and the memory space required for data decompression by the data compression algorithm is N1 (i.e., the memory space of the fourth RAM memory area is N1). The remaining RAM memory space can be evenly divided among the first, second, and third RAM memory areas. In other words, the memory space of the first, second, and third RAM memory areas is (M-N1) / 3. In this case, the zonesize can be set to (M-N1) / 3. For example, when M is 200KB and N1 is 20KB, the RAM memory space is divided into: 60KB for the first RAM memory area, 60KB for the second RAM memory area, 60KB for the third RAM memory area, and 20KB for the fourth RAM memory area. In this case, zonesize = 60KB, indicating that the terminal device can restore 60KB of Diff data or Extra data at a time.

[0135] As another example, in the case where the RAM memory area of ​​the terminal device is reused for differential file restoration, the RAM memory can be sequentially divided into a first RAM memory area, a second RAM memory area, a third RAM memory area, a fourth 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 process, and for data storage operations involved in the Extra data block restoration process, and the fifth RAM memory area is used for data decompression operations. The second RAM memory area is located between the first RAM memory area and the third RAM memory area and serves as a safety buffer area for the first RAM memory area; the fourth RAM memory area is located between the third RAM memory area and the fifth RAM memory area and serves as a safety buffer area for the third RAM memory area.

[0136] Assume that the terminal device's RAM memory space for differential file restoration is M, the memory space required for data decompression by the data compression algorithm is N1 (that is, the memory space of the fifth RAM memory area is N1), and the memory space required for the safety buffer area is N2. The remaining space can be evenly divided between the first and third RAM memory areas. In other words, the memory space of both the first and third RAM memory areas is (M - N1 - N2 * 2) / 2. In this case, the zonesize can be set to (M - N1 - N2 * 2) / 2. For example, when M is 200KB, N1 is 16KB, and N2 is 2KB, the RAM memory space is divided into: 90KB for the first RAM memory area, 2KB for the second RAM memory area, 90KB for the third RAM memory area, 2KB for the fourth RAM memory area, and 16KB for the fifth RAM memory area. In this case, zonesize = 90KB, indicating that the terminal device can perform data restoration on 90KB of Diff data or Extra data at a time.

[0137] In some special cases, the size of the compressed data is larger than the size before compression. Since the size of the Diff data block or Extra data block before compression is the same as the size of the first RAM memory area and the third RAM memory area, once the size of the Diff data block or Extra data block increases, it will overflow the first RAM memory area or the third RAM memory area, affecting normal data restoration processing. Therefore, providing a safety buffer area can effectively avoid data restoration anomalies caused by the increase in the size of the Diff data block or Extra data block overflowing the RAM memory area.

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

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

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

[0141] How to perform data restoration based on the various areas of RAM memory space applied for by the terminal will be explained in detail in the subsequent description of the Patch file restoration process and will not be repeated here.

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

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

[0144] FIG7 exemplarily illustrates a data structure of a Patch file, which includes a general encoding header, encoding information corresponding to multiple Diff data compressed blocks and multiple Extra data compressed blocks, and multiple Diff data compressed blocks and multiple Extra data compressed blocks. The encoding information corresponding to the multiple Diff data compressed blocks and multiple Extra data compressed blocks is used to describe the total byte length of the multiple Diff data blocks before compression, the total byte length of the multiple 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 data corresponding to the Diff data compressed blocks in the old file.

[0145] Among them, in addition to the magic number, the total encoding header may also include a zonesize field. The value of the zonesize field is used to indicate the block size into which the Diff data and the Extra data are divided, and can be used by the terminal in combination with the encoding information to perform data addressing when performing data restoration. Exemplarily, 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. Another exemplary embodiment is that 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 multiple Diff data blocks before compression or the total byte length of multiple Extra data blocks before compression.

[0146] In another example, the overall coding header does not include the zonesize field, but the zonesize field is set in each coding information respectively, which is not limited in this embodiment.

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

[0148] Regarding the data structure of the Patch file, this embodiment does not limit the description information (or encoding information) of the Diff data compression blocks and the Extra data compression blocks. As long as the terminal side can realize 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, it will be sufficient.

[0149] Figure 8 exemplarily shows a data structure of a Patch file provided by this embodiment. As shown in Figure 8 , the data structure of the Patch file includes a header, a control block (zone), diff data, and extra data.

[0150] The header consists of 16 bytes, which are used to fill the magic number and zonesize.

[0151] Each zone consists of 24 bytes, which are used to describe multiple Diff data compression blocks and multiple Extra data compression blocks. These multiple Diff data compression blocks and multiple 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 serve as the encoding information for the multiple Diff data compression blocks and multiple Extra data compression blocks it describes. The first 8 bytes of the zone can record the total byte length of the Diff data corresponding to the multiple Diff data compression blocks before compression, as well as description information for each Diff data compression block (such as the byte length after compression); the middle 8 bytes of the zone can record the total byte length of the Extra data corresponding to the multiple Extra data compression blocks before compression, as well as description information for each Extra data compression block (such as the byte length after compression); and the last 8 bytes of the zone are used to fill in the pointer offset, which is used to determine the location of the data read in the old file (i.e., the data used for addition operations with the Diff data blocks).

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

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

[0154] The Diff data includes one or more Diff data compression blocks, and each Diff data compression block is used to record the compressed data of the Diff data block.

[0155] The Extra data includes one or more Extra data compression blocks, each of which is used to record the compressed data of the Extra data block.

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

[0157] In an optional embodiment, when generating a Patch file based on Patch data, each Diff data block and each Extra data block may be compressed separately, and block encoding information may be added to each compressed data block. The block encoding information may serve as a block header of the compressed data block, and the corresponding Diff compressed data or Extra compressed data may serve as block data of the compressed data block.

[0158] Taking Diff data 01 and Extra data 01 in Patch data as an example, Figure 9 exemplifies the data structure of a Patch file. As shown in Figure 9, for Diff data 01 in Patch data, it is divided into n1 Diff data blocks according to zonesize, and each Diff data block is compressed separately to obtain the corresponding Diff data compression block. In the Patch file, each Diff data compression block is filled with encoding information for describing the Diff data compression block. Exemplarily, the encoding information of the Diff data compression block may include but is not limited to the data size (csize) of the Diff data block before compression and the data size (usize) after compression.

[0159] Similarly, referring to Figure 9, for the Extra data 01 in the Patch data, it is divided into n2 Extra data blocks according to the zonesize, and each Extra data block is compressed separately to obtain the corresponding Extra data compressed block. In the Patch file, each Extra data compressed block is filled with encoding information for describing the Extra data compressed block. Exemplarily, the encoding information of the Extra data compressed block may include but is not limited to the data size (csize) of the Extra data block before compression and the data size (usize) after compression.

[0160] The same is true for other Diff data and Extra data in the Patch data, which will not be described in detail here. Therefore, for each Diff data compression block and each Extra data compression block, after the terminal parses the corresponding block encoding information, it can use it as an independently processable data unit to perform data restoration operations. The operation of restoring the target file using the Diff data compression block or the Extra data compression block as a data processing unit will be explained in detail in the Patch file restoration process described later, and will not be described in detail here.

[0161] It should be pointed out that, referring to Figure 9, the encoding information 01 is used to describe the Diff data 01 and the Extra data 01, that is, it describes the total data size of the Diff data compression blocks 1-n1 before compression, the total data size of the Extra data compression blocks 1-n2 before compression, and the pointer offset for reading the old file data corresponding to the Diff data 02 in the old file.

[0162] Figure 10 exemplarily shows a data structure of a Patch file provided by this embodiment. As shown in Figure 10, the data structure of the Patch file includes a header, a control block (zone), diff data and extra data.

[0163] The header consists of 16 bytes, which are used to fill the magic number and zonesize.

[0164] Each zone includes 24 bytes, which are used to describe multiple Diff block compressed data and multiple Extra block compressed data. Among them, the Diff data before the multiple Diff block compressed data are block compressed, and the Extra data before the multiple Extra block compressed data are block compressed, 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 multiple Diff block compressed data and the multiple Extra block compressed data described by it. Among them, the first 8 bytes of the zone can record the total byte length of the Diff data before the multiple Diff block compressed data are block compressed; the middle 8 bytes of the zone can record the total byte length of the Extra data before the multiple Extra compressed data are block compressed; the last 8 bytes of the zone are used to fill the pointer offset, which is used to determine the location of reading data (data used for addition operation with the Diff data block) in the old file.

[0165] Exemplarily, each zone can be represented by (x, y, z), where x is the total byte length of the Diff data before the multiple Diff block compressed data described by it are compressed in blocks; y is the total byte length of the Extra data before the multiple Extra compressed data described by it are compressed in blocks; and z is the offset of the old file pointer, which is used to determine the pointer position for reading the old file data corresponding to the first Diff block data described by the zone to which it belongs from the old file. The pointer offset can be an offset determined based on the current position of the pointer, with the offset direction identified by the positive or negative sign of the offset, or it can be an offset determined based on the starting position of the file, which is not limited in this embodiment.

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

[0167] The Diff data includes one or more compressed data blocks, each of which includes a block header and block data. The block data is used to record the compressed data of the Diff data block, and the block header is used to record the compression description information corresponding to the compressed data of the Diff data block. The compression description information may include, but is not limited to, the data size (csize) of the Diff data block before compression and the data size (usize) after compression. The compression description information may only include the data size (usize) of the Diff data block after compression, that is, only include the data size of the Diff data compressed block.

[0168] The extra data includes one or more compressed extra data blocks. Each compressed extra data block includes a block header and block data. The block data is used to record the compressed data of the extra data block, and the block header is used to record the compression description information corresponding to the compressed data of the extra data block. The compression description information may include, but is not limited to, the data size (csize) of the extra data block before compression and the data size (usize) after compression. The compression description information may only include the data size (usize) of the compressed extra data block, that is, only include the data size of the compressed extra data block.

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

[0170] It should be noted that the Patch file provided in the embodiment of the present application is merely an exemplary expression and is not intended to be limiting.

[0171] In one example, based on the data structure of the above-mentioned Patch file, in addition to filling the zonesize field in the Header, the data compression block maximum byte length (LengthMAX) field can also be filled. The value of this field is used to indicate the maximum data size of each data compression block (including Diff data compression block and Extra data compression block).

[0172] 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 the control compression block, the Diff data compression block, and the Extra data compression block).

[0173] When a terminal parses a 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 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.

[0174] In another example, based on the data structure of the above-mentioned Patch file, in addition to filling the zonesize field in the Header, the total length of the target file data (NewfileLength) field can also be filled. The value of this field is used to indicate the total length of the data of the target file restored based on the Patch file.

[0175] When restoring a target file based on a patch file, the terminal can determine whether the restored target file is correct based on the value of the NewfileLength field. For example, if the data length of the target file restored from 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.

[0176] In another example, based on the data structure of the above-mentioned Patch file, the data structure of the above-mentioned Patch file can also include a tail, which can be filled with a check field, and the value of the check field is used to indicate the hash value of the target file restored based on the Patch file.

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

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

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

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

[0181] FIG. 11 a exemplarily shows a file difference process based on the Bsdiff principle provided by this embodiment.

[0182] The file difference process shown in FIG11a is the same as that shown in FIG7 , and the difference lies in the way the Diff data blocks and the Extra data blocks are divided.

[0183] Referring to Figure 11a, taking 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.

[0184] Continuing with reference to (1) in Figure 11b, and 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.

[0185] Continuing with reference to (1) in FIG. 11b , when the data size of the (n1+1)th Diff data block is smaller than a 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 to serve as the final n1th Diff data block. At this point, 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.

[0186] 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. At this time, the division of the Diff data block can be referred to Figure 7 and will not be repeated.

[0187] The same is true for Extra data 01. As shown in (2) in FIG11b, Extra data 01 can be divided into (n2+1) Extra data blocks according to zonesize. Among these (n2+1) Extra data blocks, the data size of the first n2 Extra data blocks is zonesize, and the data size of the (n2+1)th Extra data block is much smaller than 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.

[0188] Continuing with reference to (2) in FIG11b , 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 to serve as the final divided n2th Extra data block. At this point, 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.

[0189] 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 blocks is not adjusted. At this time, the division of the Extra data blocks can be referred to Figure 7 and will not be repeated.

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

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

[0192] When the terminal performs a data restoration operation based on a patch file, the terminal can calculate whether there are Diff data blocks with a byte length greater than the zonesize, as well as the byte length of each Diff data block, based on the total byte length of the Diff data corresponding to the multiple Diff data compression blocks recorded in the zone before compression, the zonesize value, and the data size of the requested security buffer. Similarly, the terminal can calculate whether there are Extra data blocks with a byte length greater than the zonesize, as well as the byte length of each Extra data block, based on the total byte length of the Extra data corresponding to the multiple Extra data compression blocks recorded in the zone before compression, the zonesize value, and the data size of the requested security buffer.

[0193] In an optional implementation, a flag field may also be set in the header of the Patch file, and the value of the flag field is used to indicate whether there are data blocks (including Diff data blocks and Extra data blocks) whose byte length is greater than the zonesize.

[0194] When the terminal performs data restoration based on the Patch file, it can determine whether there are data blocks (including Diff data blocks and Extra data blocks) with a byte length greater than the zonesize by parsing the value of the flag field in the Patch file header.

[0195] Corresponding to the differential file generation method provided in this embodiment, this embodiment also provides a differential file restoration method, which is applied to the terminal side. The terminal mentioned here can be understood as any electronic device that needs to restore the differential file, such as a smartphone, smartwatch, smart bracelet, etc., or any IoT node device.

[0196] FIG12 exemplarily shows the process of restoring a target file based on a Patch file provided in this embodiment.

[0197] 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 encoding the Patch data.

[0198] Referring to Figure 12, the data structure of a Patch file includes a general encoding header, encoding information corresponding to multiple Diff data compression blocks and multiple Extra data compression blocks, and multiple Diff data compression blocks and multiple Extra data compression blocks. The encoding information corresponding to the multiple Diff data compression blocks and multiple Extra data compression blocks is used to describe the multiple Diff data compression blocks and multiple Extra data compression blocks so that the terminal can perform data addressing based on the encoding information. The data structure of the Patch file can be referred to the explanation of Figure 8 above and will not be repeated here.

[0199] When the terminal obtains the Patch file, it parses the header of the Patch file. After obtaining the file type and data block size based on the magic number and zonesize recorded in the header, it can apply for RAM memory space for differential file restoration processing based on the data block size, and perform data decoding operations based on the data structure corresponding to the file type.

[0200] After decompressing each Diff data block or Extra data block, the terminal restores the target file according to the Diff data block or Extra data block.

[0201] Continuing with reference to Figure 12, in the Patch data obtained by decoding the Patch file, Diff data and Extra data appear in pairs, with each block of Diff data followed by a block of Extra data. Furthermore, the ordering 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 multiple decompressed Diff data blocks, and each block of Extra data includes multiple decompressed Extra data blocks. When the terminal restores the target file based on the Patch data, it performs data restoration operations based on each Diff data block or Extra data block.

[0202] As shown in Figure 8, in a patch file, each zone is used to describe multiple compressed Diff data blocks and multiple compressed Extra data blocks. Therefore, the terminal can retrieve each compressed Diff data block and each compressed Extra data block based on the content recorded in the zone, decompress them, and then restore them to the data in the new file based on the decompressed Diff data blocks and Extra data blocks.

[0203] Continuing with reference to FIG12 , the terminal performs a data restoration operation based on the various Diff data compressed blocks (corresponding to Diff data 01) and Extra data compressed blocks (corresponding to Extra data 01) described in the coding information 01 as an example for explanation. The terminal first decompresses Diff data 01 compressed block 1 to obtain Diff data 01 block 1, where the byte length of Diff data 01 block 1 is equal to zonesize. When performing a data restoration operation based on Diff data 01 block 1, the terminal reads the Diff data of Diff data 01 block 1 and reads the old file data (byte length equal to zonesize) that matches Diff data 01 block 1 in the old file. The terminal then performs an addition operation on the Diff data in Diff data 01 block 1 and the matching old file data to obtain new file data (byte length equal to zonesize) corresponding to Diff data 01 block 1 and writes it into the new file. Similarly, the terminal continues to decompress Diff data 01 compressed block 2 and restores the data based on the decompressed Diff data 01 block 2 until the restoration process completes Diff data 01 compressed block n1. The byte length of the Diff data 01 block obtained by decompressing Diff data 01 compressed block n1 is less than or equal to zonesize.

[0204] Next, the terminal continues to decompress Extra Data 01 compressed block 1 to obtain Extra Data 01 block 1. The byte length of Extra Data 01 block 1 is equal to zonesize. When performing a data restoration operation based on Extra Data 01 block 1, the terminal reads the Extra data of Extra Data 01 block 1 and writes this data directly to a new file. Similarly, the terminal continues to decompress Extra Data 01 compressed block 2 and restores data based on the decompressed Extra Data 01 block 2 until the restoration process is complete for Extra Data 01 compressed block n2. The byte length of Extra Data 02 block obtained by decompressing Extra Data 01 compressed block n2 is less than or equal to zonesize.

[0205] At this point, the terminal has completed the target file restoration based on Diff data 01 and Extra data 01. The terminal's operation of restoring target files based on other Diff data and Extra data is the same. Similarly, the terminal can obtain all the data in the new file based on each compressed Diff data block and each compressed Extra data block in the Patch file, as well as the relevant data in the old file.

[0206] The following uses (x, y, z) as an example to represent each zone, and explains the restoration process based on the Patch file in conjunction with Figure 13.

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

[0208] As shown in Figure 13, 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).

[0209] The terminal parses the patch file and finds (x1, y1, z1) filled in zone1. First, the terminal continues to read Diff Data 01 compressed block 1 in the patch file, decompresses it to obtain m-length Diff data, reads m-length data from the old file, adds these two m-length data segments, and obtains m-length new file data, which is then written to the new file (or target file). After the old file pointer is offset by z1 from the file's starting position, the terminal can read the m-length old file data corresponding to the m-length Diff data (Diff Data 01 compressed block 1) in the old file. Then, the terminal continues to read Diff Data 01 compressed block 2 in the patch file, decompresses it to obtain (x1-m)-length Diff data, and continues to read (x1-m)-length data from the old file. These two (x1-m)-length data segments are added to obtain (x1-m)-length new file data, which is then written to the new file. Among them, after the terminal reads the old file data of m length corresponding to the Diff data of m length in the old file, the old file pointer continues to shift forward by m. At this time, the terminal can continue to read the old data of (x1-m) length corresponding to the Diff data of (x1-m) length in the old file based on the current position of the pointer.

[0210] At this point, the compression blocks of each Diff data 01 described by zone1 have been processed.

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

[0212] At this point, the compression blocks of each Extra data 01 described by zone1 have also been processed.

[0213] Next, the terminal continues to read (x2, y2, z2) from the Patch file, filling zone 2. In the Patch file, zone 2 is used to describe Diff Data 02 Compressed Block 1, other Diff Data 02 Compressed Block 2, and various Extra Data 02 Compressed Blocks. The terminal then continues to decompress Diff Data 02 Compressed Block 1 in the Patch file to obtain m-length Diff data. It also reads m-length data from the old file and adds these two m-length data segments to obtain m-length new file data, which it then writes to the new file (or target file). In order for the terminal to read the 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's starting position and z2. That is, after the old file pointer is offset by z2 from the file's starting position, the terminal can then read the m-length old file data corresponding to the m-length Diff data (Diff Data 01 Compressed Block 1) in the old file.

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

[0215] Similarly, when the terminal completes the data restoration processing of the Diff data compression blocks and the Extra data compression blocks described in all zones, the new file restoration process can be completed.

[0216] The following explains the RAM usage of the terminal when restoring data based on Diff data compression and Extra data compression.

[0217] It should be noted that when the terminal device performs differential file restoration, it can apply for continuous RAM memory space or discontinuous RAM memory space, which is not limited in this embodiment.

[0218] Among them, when the terminal device applies for discontinuous RAM memory space, if the RAM memory area is reused, it can apply for two RAM memory areas of the same size as zonesize, and a RAM memory area for running the data compression algorithm (the size is related to the data compression algorithm). When the terminal device applies for discontinuous RAM memory space, if the RAM memory area is not reused, it can apply for three RAM memory areas of the same size as zonesize, and a RAM memory area for running the data compression algorithm (the size is related to the data compression algorithm).

[0219] In an alternative embodiment, if the RAM memory area is reused, two RAM memory areas of size (zonesize + N2) can be applied, and one RAM memory area for running the data compression algorithm (the size depends on the data compression algorithm). Where N2 is the data size of the safety buffer area.

[0220] Similarly, if the RAM memory area is not reused, three RAM memory areas of size (zonesize + N2) can be requested, and one RAM memory area for running the data compression algorithm (the size depends on the data compression algorithm). Among them, N2 is the data size of the safety buffer area.

[0221] Since applying for discontinuous RAM memory space is likely to generate RAM memory fragments, resulting in RAM space waste, this embodiment is explained by taking the case where the terminal device applies for contiguous RAM memory space as an example.

[0222] Among them, when the terminal obtains the Patch file, it parses the header of the Patch file and obtains the value of the data block size (zonesize). Then, it can apply for a continuous RAM memory space based on the value of zonesize for differential data restoration operation.

[0223] In one possible implementation, the RAM memory area is not reused, and the terminal applies for a continuous piece of RAM memory space for the Patch restore operation. The size of the RAM memory space is 3*zonesize+N1 (bytes), wherein N1 bytes is the size of the RAM memory space required to run the data compression algorithm. The terminal can divide the RAM memory space into four RAM memory areas, namely 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, as shown in Figures 14 and 15. The sizes of the first RAM memory area 201, the second RAM memory area 202 and the third RAM memory area 203 are equal, all of which are zonesize (bytes), and the size of the fourth RAM memory area 204 is N1 bytes.

[0224] For example, the data compression algorithm used to compress the Diff data compression block or the Extra data compression block can be LZMA. For example, if the minimum RAM memory space required to support LZMA operation is 16KB, N1 can be set to 16. Assuming zonesize = 60KB, in this embodiment, the terminal can apply for a continuous block of M bytes of RAM memory space for the Patch restore operation, where M = 60*3+16 = 196KB.

[0225] Among them, the first RAM memory area 201, the second RAM memory area 202, and the third RAM memory area 203 are jointly used for data storage operations involved in the Diff data block restoration processing, including but not limited to storing Diff data compression blocks, storing decompressed Diff data blocks, storing new file data blocks (New data blocks) obtained after the addition operation, and for data storage operations involved in the Extra data block restoration processing, including but not limited to storing Extra data compression blocks, storing decompressed Extra data blocks; the fourth RAM memory area 204 is used for data decompression operations.

[0226] For example, referring to Figure 14, at time 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 time T1, the terminal reads the Diff data 01 compressed block 1 in the Patch file and writes the Diff data 01 compressed block 1 into the first RAM memory area 201. Next, the terminal calls the data compression algorithm to decompress the Diff 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 T2, the decompression of the Diff data 01 compressed block 1 is completed, and the Diff data 01 block 1 (byte length is zonesize) is temporarily stored in the second RAM memory area 202. Next, the terminal reads Old Data 01 Block 1 (byte length is zonesize) corresponding to Diff Data 01 Block 1 from the running state image file (equivalent to the old file that has not been upgraded) and temporarily stores it in the third RAM memory area 203, as shown at time T3. At time T3, the terminal reads Old Data 01 Block 1 from the third RAM memory area 203 and Diff Data 01 Block 1 from the second RAM memory area 202, performing an addition operation. The terminal can perform operations such as addition on Diff Data 01 Block 1 and Old Data 01 Block 1, so that the New Data 01 Block 1 obtained by the addition operation can be written to the second RAM memory area 202, overwriting the Diff Data 01 Block 1 temporarily stored in the second RAM memory area 202. Furthermore, at time T4, the terminal can read New Data 01 Block 1 from the second RAM memory area 202 and write it to the static state image file (or a newly created file). The static state image file can be understood as a backup of the running state image file.

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

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

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

[0230] For example, referring 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.

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

[0232] In this implementation, a security buffer zone may also be provided for the RAM memory area, although this embodiment does not limit this. For example, the terminal requests a continuous block of RAM memory space for the patch restore operation. The size of this RAM memory space is 3*zonesize+3*N2+N1 (bytes). N2 bytes represents the size of the RAM memory space occupied by the security buffer zone. This implementation is not further described here.

[0233] In another possible implementation, the RAM memory area is reused, and the terminal applies for a continuous piece of RAM memory space for the Patch restoration operation. The size of the RAM memory space is 2*zonesize+2*N2+N1 (bytes), where N1 bytes is the size of the RAM memory space required to run 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, namely 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, as shown in Figures 16 and 17. Among them, the sizes of the first RAM memory area 301 and the third RAM memory area 303 are equal, both are 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 the safety 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 the safety buffer area of ​​the third RAM memory area 304; and the sizes of the second RAM memory area 302 and the fourth RAM memory area 304 are equal, both are N2 bytes.

[0234] For example, the data compression algorithm used to compress the Diff data compression blocks or the Extra data compression blocks can be LZMA. For example, if the minimum RAM memory space required to support LZMA operation is 16KB, N1 can be set to 16. Assuming zonesize = 90KB and N2 = 2KB, in this embodiment, the terminal can apply for a continuous block of M bytes of RAM memory space for the Patch restore operation: M = 90*2 + 2*2 + 16 = 200KB.

[0235] Among them, the first RAM memory area 301 and the third RAM memory area 303 are jointly used for data storage operations involved in the Diff data block restoration processing, including but not limited to storing Diff data compression blocks, storing decompressed Diff data blocks, storing new file data blocks (New data blocks) obtained after addition operations, and for data storage operations involved in the Extra data block restoration processing, including but not limited to storing Extra data compression blocks, storing decompressed Extra data blocks; the fifth RAM memory area 304 is used for data decompression operations.

[0236] For example, referring to Figure 16, at time 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 time T1, the terminal reads the Diff data 01 compressed block 1 in the Patch file and writes the Diff data 01 compressed block 1 into the first RAM memory area 301. Next, the terminal invokes the data compression algorithm to decompress the Diff data 01 compressed block 1 in the first RAM memory area 301. The RAM memory area used by the data compression algorithm to perform the decompression process is the fifth RAM memory area 304, and the decompressed data is written into the third RAM memory area 303. At time 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 Old Data 01 Block 1 (byte length is zonesize) corresponding to Diff Data 01 Block 1 from the running state image file (equivalent to the old file that has not been upgraded), and temporarily stores it in the first RAM memory area 301, overwriting the compressed Diff Data 01 Block 1, as shown at time T3. Continuing with reference to time T3, the terminal reads Old Data 01 Block 1 from the first RAM memory area 301 and Diff Data 01 Block 1 from the third RAM memory area 303, performing an addition operation. The terminal can perform operations such as addition on Diff Data 01 Block 1 and Old Data 01 Block 1, so that the New Data 01 Block 1 obtained by the addition operation can be written to the third RAM memory area 303, overwriting the Diff Data 01 Block 1 temporarily stored in the third RAM memory area 303. Furthermore, at time T4, the terminal can read New Data 01 Block 1 from the third RAM memory area 303 and write it to the static state image file.

[0237] The New Data 01 Block 1 obtained by the addition operation may also be written into the first RAM memory area 301, overwriting the Old Data 01 Block 1 temporarily stored in the first RAM memory area 301. Furthermore, the terminal may read the New Data 01 Block 1 from the first RAM memory area 301 and write it into the static image file.

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

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

[0240] For example, referring to Figure 17, 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 301. Next, the terminal calls the data compression algorithm to decompress Extra Data 01 compressed block 1 in the first RAM memory area 301. 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 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 third RAM memory area 303. Furthermore, at time T6, the terminal can read Extra Data 01 block 1 in the third RAM memory area 303 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.

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

[0242] The terminal applies for the second RAM memory area 302 as a safety buffer for the first RAM memory area 301, thereby resolving the problem of data processing errors caused by data overflow in the first RAM memory area 301. Similarly, the terminal applies for the fourth RAM memory area 304 as a safety buffer for the third RAM memory area 303, thereby resolving the problem of data processing errors caused by data overflow in the third RAM memory area 303.

[0243] It should be noted that if the size of a Diff data compression block or Extra data compression block is larger than the size of the Diff data block or Extra data compression before compression, temporarily storing the data compression block in the first RAM memory area or the third RAM memory area will cause data to overflow into the second RAM memory area or the fourth RAM memory area. In this case, when the terminal device decompresses the data compression block, it is necessary to also decompress the data that overflowed into the second RAM memory area or the fourth RAM memory area to ensure the correctness of the decompressed Diff data block or Extra data block.

[0244] When the continuous RAM memory space applied by the terminal device for differential data restoration is a certain value, compared with the case where the RAM memory area is not reused, the RAM memory area reuse can improve the data restoration processing efficiency.

[0245] When the terminal has very little RAM memory space available for differential data restoration processing, the terminal may not allocate the second RAM memory area 302 and the fourth RAM memory area 304 as a safety buffer within the applied RAM memory space. When the terminal does not allocate the second RAM memory area 302 and the fourth RAM memory area 304 as a safety buffer within the applied RAM memory space, the RAM memory usage of the terminal when performing data restoration based on the Diff data compression blocks and the Extra data compression blocks is similar and will not be further described here.

[0246] For example, the data compression algorithm used to compress the Diff data compression block or the Extra data compression block can be LZMA. For example, if the minimum RAM memory space required to support LZMA operation is 16KB, N1 can be set to 16. Assuming zonesize = 2KB, in this embodiment, the terminal can apply for a continuous block of M bytes of RAM memory space for the Patch restore operation, where M = 2*2+16 = 20KB.

[0247] In this way, when the terminal performs data restoration operations based on Diff data compression blocks or Extra data compression blocks, the decompression operation and data storage operations are both performed in the specified RAM memory area, which fully and effectively utilizes the RAM memory space. The differential restoration operation consumes less RAM memory, so that lightweight devices with smaller RAM space can also have differential restoration capabilities.

[0248] Corresponding to the data block division method shown in Figures 11a and 11b, when the terminal restores the data of the Patch file, the RAM memory space applied for the Patch restoration operation includes a security buffer, wherein the data size of the security buffer is N2 bytes.

[0249] For example, the RAM memory space requested by the terminal may be continuous, as shown in FIG16 . For another example, the RAM memory space requested by the terminal may be non-contiguous, for example, requesting three RAM memory areas of size (zonesize+N2) and one RAM memory area for running a data compression algorithm (the size of which is related to the data compression algorithm). This embodiment does not limit this.

[0250] When a terminal performs a data restoration operation based on a Diff data compression block or Extra data compression block described by a zone, it can calculate whether there is a Diff data block with a byte length greater than the zonesize based on the total byte length of the Diff data corresponding to multiple Diff data compression blocks before compression recorded in the zone, the zonesize value, and the data size of the requested security buffer.

[0251] If there is no Diff data block with a byte length greater than zonesize, the processing flow of the terminal performing data restoration based on multiple Diff data compression blocks can be found in the previous text and will not be repeated here.

[0252] Assume that the byte length of the last Diff data compression block described by a zone (such as Diff data 01 compression block n1) before compression is greater than zonesize. The following explains the process of the terminal performing data restoration processing based on Diff data 01 compression block n1.

[0253] Referring to Figure 18, at time T1, the terminal reads the Diff data 01 compressed block n1 in the Patch file and writes the Diff data 01 compressed block n1 into the first RAM memory area 301. Next, the terminal invokes the data compression algorithm to decompress the Diff data 01 compressed block n1 in the first RAM memory area 301. The RAM memory area used by the data compression algorithm to perform the decompression process is the fifth RAM memory area 304, and the decompressed data is written into the third RAM memory area 303. At time T2, the decompression of the Diff data 01 compressed block n1 is completed, and the decompressed Diff data 01 block n1 is temporarily stored in the third RAM memory area 303. Since the byte length of the Diff data 01 block n1 before compression is greater than the zonesize, the Diff data 01 block n1 not only fills the third RAM memory area 303, but also partially writes the data into the fourth RAM memory area 304. Next, the terminal reads the Old data 01 block n1 (byte length greater than zonesize) corresponding to the Diff data 01 block n1 in the running state image file (equivalent to the old file that has not been upgraded) and temporarily stores it in the first RAM memory area 301. Among them, the Old data 01 block n1 will not only fill the first RAM memory area 301, but also write part of the data into the second RAM memory area 302, as shown at time T3. Continuing to refer to time T3, the terminal reads the Old data 01 block n1 in the first RAM memory area 301 and the second RAM memory area 302, and reads the Diff data 01 block n1 in the third RAM memory area 303 and the fourth RAM memory area 304, and performs an addition operation. Among them, the terminal can perform operations such as addition on the Diff data 01 block n1 and the Old data 01 block n1, so that the New data 01 block n1 obtained by the addition operation can be written into the third RAM memory area 303 and the fourth RAM memory area 304. Furthermore, at time T4, the terminal may read the New data 01 block n1 from the third RAM memory area 303 and the fourth RAM memory area 304 and write the block n1 into the static image file.

[0254] Assume that the byte length of the last Extra data compression block described by a zone (such as Extra data 01 compression block n2) before compression is greater than zonesize. The following explains the process of the terminal performing data restoration processing based on Extra data 01 compression block n2.

[0255] For example, referring to FIG19 , at time T5, the terminal reads the Extra Data 01 compressed block n2 in the Patch file and writes the Extra Data 01 compressed block n2 into the first RAM memory area 301. Next, the terminal invokes the data compression algorithm to decompress the Extra Data 01 compressed block n2 in the first RAM memory area 301. 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 time 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 the zonesize, the Extra Data 01 block n2 not only fills the third RAM memory area 303, but also partially writes the data into the fourth RAM memory area 304. Then, at time 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 writing it into the static image file. At this time, the data in the static image file is restored to the New data 01 block n2.

[0256] In one example, if the terminal parses the value of the flag field in the header of the Patch file and determines that there are data blocks (including Diff data blocks and Extra data blocks) with a byte length greater than the zonesize, data restoration can be performed according to the processing flow shown in Figures 17 and 18.

[0257] In this way, when the size of a data block is slightly larger than the zonesize, the terminal can also complete the corresponding data restoration operation with the help of the security buffer.

[0258] In one example, in the data structure of the Patch file, in addition to filling the zonesize field in the Header, the data compression block maximum byte length (LengthMAX) field can also be filled. The value of this field is used to indicate the maximum data size of each data compression block (including Diff data compression block and Extra data compression block).

[0259] 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 Diff data compressed block or Extra data compressed block in the patch file exceeds the value of the LengthMAX field, the terminal can determine that the patch file is incorrect and will not perform data restoration operations based on the patch file.

[0260] In another example, in the data structure of the Patch file, in addition to filling the zonesize field in the Header, the total length of the target file data (NewfileLength) field can also be filled. The value of this field is used to indicate the total length of the target file data restored based on the Patch file.

[0261] In this case, when restoring a target file based on a patch file, the terminal can determine whether the restored target file is correct based on the value of the NewfileLength field. For example, if the data length of the target file restored from 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 and will not proceed with the firmware upgrade based on that target file.

[0262] In another example, the data structure of the Patch file may further include a checksum field, the value of which is used to indicate a hash value of the target file restored based on the Patch file.

[0263] 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 from the patch file differs from the value of the checksum field, the terminal can determine that the restored target file is incorrect and will not proceed with the firmware upgrade based on that target file.

[0264] In this way, in an embodiment of the present application, the patch data is split into differential restoration unit data of controllable size, and its data size is related to the size of the terminal RAM space, so that the terminal device only needs to process one piece of differential restoration unit data at a time, thereby enabling lightweight devices with limited RAM space to have differential restoration capabilities.

[0265] The above explanation uses a set of image files (including running image files and static running files) as an example. Similarly, other static image files can be filled with data based on other patch files to obtain all the image files corresponding to the upgrade package. At this point, the terminal can perform a firmware upgrade based on these image files. The explanation of how the terminal performs a firmware upgrade based on these image files can be referred to the existing technology and will not be repeated here.

[0266] It should be noted that in the aforementioned embodiment of the method for generating a differential file, the explanation is based on the example of a Diff data server generating the data based on a subtraction operation. Accordingly, in the aforementioned embodiment of the method for restoring a differential file, the explanation is based on the example of a terminal restoring the Diff data based on an addition operation. The Diff data can also be generated by the server based on other operations. For the time being, let's say that the Diff data is generated by the server based on the first operation. Accordingly, the terminal can restore the Diff data based on a second operation, where the second operation is the inverse of the first operation. This embodiment does not limit the first and second operations.

[0267] It should be noted that in the aforementioned embodiments of the differential file generation method and the differential file restoration method, firmware files are used as an example for explanation. The differential file generation method and the differential file restoration method provided in this embodiment can also be applied to differential restoration processing of other file types, such as patch files and APKs (Android application packages).

[0268] In addition, the differential file restoration method provided in the embodiment of the present application 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.

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

[0270] Figure 20 exemplifies an application scenario. As shown in (1) of Figure 20, when a user plays games on a mobile phone, a dialog box 700 pops up on the interface. The content in the dialog box 700 displays "Currently detected xx patch, do you want to download and update immediately?" If the user agrees, the user can click the "Yes" option 701. In response to the user's operation, the dialog box disappears, as shown in (2) of Figure 20, and the user continues to play games on the mobile phone. At the same time, the mobile phone background executes the operation of downloading the xx patch, restoring the differential file based on the downloaded xx patch, and performing hot updates based on the restored patch file.

[0271] 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 user's experience of using the mobile phone. In this case, if the mobile phone executes the differential file restoration method provided in the embodiment of the present application, the differential data restoration function can be achieved with a smaller RAM memory space, and at the same time, the user's experience will not be affected.

[0272] In other application scenarios, assuming the user has enabled the APK automatic update function on their phone, the phone may be downloading APK differential packages and performing differential restoration operations in the background while the user is using the phone. Although the phone's RAM memory space is not small, in order to not affect the user's experience, the RAM memory space allocated by the phone for differential file restoration operations is usually small. In this case, if the phone executes the differential file restoration method provided in the embodiments of the present application, the differential data restoration function can be achieved using a smaller RAM memory space without affecting the user's experience.

[0273] However, in actual applications, the same terminal device often has multiple versions. These multiple versions of terminal devices may all require firmware upgrades, and the hardware configurations of different versions of terminal devices may not be the same (usually high or low configurations of hardware resources). If a separate upgrade differential package is developed for each version of the terminal device, the number of upgrade differential package versions will undoubtedly increase, thereby increasing manual maintenance costs. Therefore, in order to reduce the number of upgrade differential package versions, the same upgrade differential package can be developed for multiple versions of terminal devices to meet the scenario requirements of sending one package to multiple devices, and achieve the unification of upgrade differential packages for different versions of terminal devices.

[0274] Among them, when the differential file in the upgrade differential package is generated based on the above solution, if the RAM memory space allocated by the terminal device for differential file restoration is large, how to improve the efficiency of differential file restoration is a problem that needs to be solved.

[0275] To solve the above problem, an embodiment of the present application further provides a differential file restoration method, wherein the terminal device can adaptively restore the differential file according to the RAM memory space used for differential file restoration, thereby improving the differential file restoration efficiency.

[0276] In the foregoing description, referring to FIG13 , each compressed block in the Patch file (including the Diff data compressed block and the Extra data compressed block) is processed serially. When the terminal device allocates a large amount of RAM memory space for differential file restoration, the restoration process of the compressed blocks can be performed in parallel, thereby improving the efficiency of differential file restoration. The parallelization of the compressed block restoration process is related to the size of the RAM memory space allocated by the terminal device for differential file restoration.

[0277] As described above, with reference to Figures 16 and 17, the terminal device can restore a compressed block (Diff data compressed block or Extra data compressed block) based on 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. The first RAM memory area 301 and the third RAM memory area 303 are of equal size, both of which are zonesize (bytes); the size of the fifth RAM memory area 305 is N1 bytes and is used for data decompression operations; the second RAM memory area 302 is a safety buffer area for the first RAM memory area 301, and the fourth RAM memory area 304 is a safety buffer area for the third RAM memory area 304, both of which are N2 bytes.

[0278] Thus, in addition to providing the fifth RAM memory area for data decompression, a set of RAM spaces (i.e., 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) can realize the restoration processing of a compressed block. Therefore, in addition to the fifth RAM memory area, as long as the terminal device can provide multiple sets of RAM spaces, it is possible to parallelize the restoration processing of multiple compressed blocks, thereby improving the restoration efficiency of differential files.

[0279] For example, referring to Figure 21a, the first group of RAM space is used by the first restoration thread to restore the compressed blocks (Diff data compressed blocks or Extra data compressed blocks), and the second group of RAM space is used by the second restoration thread to restore the compressed blocks (Diff data compressed blocks or Extra data compressed blocks). The first restoration thread and the second restoration thread are parallel. In this way, when the terminal device can provide multiple groups of RAM space, the terminal device can restore the Diff data compressed blocks or Extra data compressed blocks through multiple parallel restoration threads.

[0280] In an optional embodiment, the RAM space used by the terminal device for differential file restoration processing is a static array, and a group of RAM spaces corresponding to each restoration thread can be divided in the static array, so that each restoration thread can restore the compressed blocks (Diff data compressed blocks or Extra data compressed blocks) based on the corresponding group of RAM spaces.

[0281] Exemplarily, as shown in FIG21a , each group of RAM spaces (including a first RAM memory area 301 , a second RAM memory area 302 , a third RAM memory area 303 and a fourth RAM memory area 304 ) and a fifth RAM memory area 305 are divided in sequence in a static array, wherein one group of RAM spaces corresponds to one restoration thread.

[0282] As another example, as shown in FIG21b , a first RAM portion, a second RAM portion, and a fifth RAM memory area 305 are sequentially divided in the static array. Multiple pairs of first RAM memory areas 301 and second RAM memory areas 302 are sequentially divided in the first RAM portion; and multiple pairs of third RAM memory areas 303 and fourth RAM memory areas 304 are sequentially divided in the second RAM portion. Each pair of first RAM memory area 301 and second RAM memory area 302, and each pair of third RAM memory area 303 and fourth RAM memory area 304, corresponds to a restore thread.

[0283] It should be pointed out that the above-mentioned division of RAM space is only an illustrative example and is not limited in this embodiment. As long as each restoration thread corresponds to a set of RAM spaces (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 compressed block restoration can be achieved.

[0284] In an embodiment of the present application, during the restoration of patch data, each set of incremental update data can be used as a unit for the restoration thread to independently perform the restoration operation. A set of incremental update data is defined as the incremental update data described by a control block (zone). Generally, a set of incremental update data includes one or more Diff data blocks and Extra data blocks. In special cases, a set of incremental update data may include only Diff data blocks or only Extra data blocks.

[0285] Exemplarily, the terminal device creates a first and a second parallel restoration thread for restoring patch data. As shown in Figure 22, the first restoration thread is used to restore the compressed blocks described by zone 1, the second restoration thread is used to restore the compressed blocks described by zone 2, the first restoration thread is used to restore the compressed blocks described by zone 3, the second restoration thread is used to restore the compressed blocks described by zone 4, and so on. In this way, the terminal device can restore the patch data based on two parallel restoration threads, improving the efficiency of patch data restoration.

[0286] When each restoration thread restores a compressed block described by a zone, it restores each Diff data block and Extra data block described by that zone in sequence. The restoration process of each Diff data block and Extra data block by the restoration thread can be found in the previous section and will not be repeated here.

[0287] In order to achieve parallelization of Patch data restoration, this embodiment adaptively adjusts the data structure of the Patch file. Figure 23 exemplifies the data structure of a Patch file provided by this embodiment. As shown in Figure 23, the data structure of the Patch file includes a header, a control block (zone), diff data, and extra data. The description of diff data and extra data can be referred to above, which is the same as the data structure of the Patch file shown in Figure 8.

[0288] Different from the data structure of the Patch file shown in FIG8 , in the data structure of the Patch file shown in FIG23 , the header also includes the total number of control blocks (zones).

[0289] Unlike 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 includes not only a first pointer offset for reading data in the old file, but also a second pointer offset for writing data in the new file. The first pointer offset is a pointer offset determined based on the starting position of the old file, and the second pointer offset is a pointer offset determined based on the starting position of the new file. Moreover, each zone must also include the sum of the compressed byte lengths of the multiple Diff data blocks and the multiple Extra data blocks described in the zone, for example, the total compressed byte length of the multiple Diff data blocks and the total compressed byte length of the multiple Extra data blocks.

[0290] In this embodiment, the first pointer offset is used to read the old data corresponding to the first Diff data block described by the zone from the old file. Specifically, the old data to be added to the first Diff data block described by the zone is read from the old file. The second pointer offset is used to determine the first address to write the restored data corresponding to the zone into the new file. In this way, when multiple restore threads process the data blocks described by each zone in parallel, the first address to write the restored data corresponding to that zone into the new file can be determined based on the second pointer offset in each zone.

[0291] In this embodiment, the total compressed byte length of the multiple Diff data blocks and the total compressed byte length of the multiple Extra data blocks described in a zone can be used by the restore thread to calculate the address offset of the next zone in the patch file. In other words, this total byte length can be used by the restore thread to skip the compressed data blocks described in that zone when reading data from the patch file, in order to read the data filled in the next zone. In other words, the restore thread can read the compressed data blocks described in the zone it needs to process based on the total compressed byte length of the multiple Diff data blocks and the total compressed byte length of the multiple Extra data blocks described in each zone. For example, if a restore thread needs to restore the compressed data blocks described in zone2, it can determine the total byte length of the compressed Diff data blocks and the compressed Extra data blocks described in zone1 based on the total compressed byte length of the multiple Diff data blocks and the total compressed byte length of the multiple Extra data blocks read from zone1. Then, when reading data from the patch file, it can skip these compressed Diff data blocks and the compressed Extra data blocks and continue to read the data filled in zone2. Similarly, if the restore thread needs to process the restore operation of each data compression block described by zone4, the same is true and will not be repeated here.

[0292] For example, referring to Figure 23 , each zone includes 32 bytes, which are used to describe multiple compressed diff data blocks and multiple compressed extra data blocks. These multiple compressed diff data blocks and multiple compressed extra data blocks correspond to a pair of diff data and extra data in patch data obtained using the BSDiff algorithm. The data recorded in a zone can serve as encoding information for the multiple compressed diff data blocks and multiple compressed extra data blocks it describes. Among them, the first 8 bytes of zone can record the total byte length of the Diff data corresponding to multiple Diff data compression blocks before and after compression, as well as the description information of each Diff data compression block (such as the byte length after compression); the second 8 bytes of zone can record the total byte length of the Extra data corresponding to multiple Extra data compression blocks before and after compression, as well as the description information of each Extra data compression block (such as the byte length after compression); the third 8 bytes of zone are used to fill the first pointer offset, and the first pointer offset is used to determine the location of reading data in the old file (that is, the data used for addition operation with the Diff data block); the fourth 8 bytes of zone are used to fill the second pointer offset, and the second pointer offset is used to determine the location of writing data in the new file (that is, the data obtained by the restore operation).

[0293] In another optional embodiment, each zone includes 32 bytes for describing multiple Diff data compression blocks and multiple Extra data compression blocks. Among them, the first 8 bytes of the zone can record the total byte length of the Diff data corresponding to the multiple 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 multiple 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 location of reading data in the old file (i.e., data for addition operation with the Diff data block); 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 location of writing data in the new file (i.e., data obtained by the restore operation). The zone structure can also be applied to the data structure of the Patch file as shown in Figure 10, or it can also be applied to other data structures of the Patch file provided in the embodiment of the present application, so that when multiple restore threads process the data blocks described by each zone in parallel, the first address of the restored data corresponding to the zone can be determined based on the second pointer offset in each zone in the new file.

[0294] This embodiment does not limit the order in which the first pointer offset and the second pointer offset are filled in the zone.

[0295] Exemplarily, the restoration thread may also determine the zone number based on the order in which the zones are read in the Patch file, and determine whether each data compression block described by the zone requires restoration processing based on the zone number.

[0296] As another example, each zone may also be filled with the zone number, so that each restoration thread can determine whether each data compression block described by the zone requires restoration processing based on the read zone number.

[0297] In an optional implementation, assuming that k restoration threads process the restoration of the Patch file in parallel, it is possible to determine whether each data compression block described by a zone requires restoration based on the modulo result of the zone number and the number of restoration threads.

[0298] Assume that zone numbers start at 1. For zone x: if x%k = 1, then the compressed data blocks described by this zone are processed by restore thread 1; if x%k = 2, then the compressed data blocks described by this zone are processed by restore thread 2; if x%k = n, 0 < n ≤ k-1, then the compressed data blocks described by this zone are processed by restore thread n; if x%k = 0, then the compressed data blocks described by this zone are processed by restore thread k. Here, % represents the remainder operation.

[0299] Assume that zone numbers start counting from 0. For zone number x: if x%k=0, then each compressed data block described by this zone is processed by restore thread 1; if x%k=1, then each compressed data block described by this zone is processed by restore thread 2; if x%k=n, 0<n<k-1, then each compressed data block described by this zone is processed by restore thread n+1; if x%k=k-1, then each compressed data block described by this zone is processed by restore thread k.

[0300] In another optional implementation, assuming that the number of zones is x, these x zones can be divided into k equal parts. The data compression blocks described by each zone corresponding to the first part are processed by restoration thread 1, the data compression blocks described by each zone corresponding to the second part are processed by restoration thread 2, and so on.

[0301] In this way, the zone number corresponding to each restoration thread can be determined. The zone number corresponding to a restoration thread means that each data compression block described by the zone needs to be processed by the restoration thread.

[0302] In this embodiment, a restore operation execution linked list can be created for each of the k parallel restore threads based on the modulo result of the zone number and the number of restore threads. In each restore operation execution linked list, 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 based on 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 cumulative 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 cumulative 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.

[0303] Furthermore, each restoration thread can execute the data of each node in the linked list based on the corresponding restoration operation, read the corresponding zone in the Patch file, and perform data restoration processing on the data compression blocks described by the zone.

[0304] The present application provides a method for restoring a differential file. The process of the method for restoring a differential file specifically includes:

[0305] S501: The electronic device parses the Patch file to obtain the zone size zonesize and the total number x of control blocks.

[0306] For example, the zone size zonesize and the total number x of control zones can be carried in the header of the Patch file.

[0307] After the electronic device obtains the Patch file, it parses the header of the Patch file. After knowing the file type based on the magic number recorded in the header, it can read the zonesize and the total number of control blocks x in the header.

[0308] S502, the electronic device determines whether the electronic device supports differential file restoration processing based on the RAM space size M and zonesize used for differential restoration. If so, execute S503, and if so, perform error processing.

[0309] The electronic device can calculate the minimum RAM space required to restore the Patch file based on the zonesize. 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 process of the differential file and report an error.

[0310] If the RAM space size M of the electronic device used 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 process of the differential file.

[0311] As mentioned above, the minimum RAM space required to restore a patch file is (zonesize + N2) * 2 + N1. N1 is the RAM size required to run the data compression algorithm, and N2 is the RAM size occupied by the security buffer. For example, N2 = 2KB and N1 = 16KB.

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

[0313] It should be noted that the RAM space used by the electronic device for differential restoration mentioned here is continuous, for example, implemented through a static array. If the RAM space used by the electronic device for differential restoration is dynamically allocated and non-contiguous, the electronic device needs to apply for two RAM memory areas of size (zonesize + N2) and one RAM memory area of ​​size N1 to enable the electronic device to perform differential file restoration.

[0314] S503: The electronic device determines the number k of parallel restoration threads according to M and zonesize.

[0315] When the RAM space size M of the electronic device used 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.

[0316] When the RAM space M used by the electronic device for differential restoration is continuous RAM space (such as a static array), the number of parallel restoration threads k = [(M-N1) / (zonesize+N2)], where [] represents a rounding operation. If the parallel number k ≥ 2, the electronic device can restore the compressed data blocks in the patch file in parallel using k restoration threads.

[0317] When the RAM space used by the electronic device for differential restoration is non-continuous RAM space, the electronic device can dynamically apply for RAM space. If it can apply for 2k (k≥2) RAM memory areas with a block size of (zonesize+N2) and a RAM memory area with a size of N1, the electronic device can restore the data compression blocks in the Patch file in parallel through k restoration threads.

[0318] S504, the electronic device determines whether k is greater than or equal to 2, if not, executes S505, and if so, executes S506.

[0319] When k is not greater than or equal to 2, since it has been determined that the electronic device supports the restoration process of the differential file, k=1, and the electronic device performs the restoration process of the differential file through a single thread.

[0320] S505: The electronic device performs a restoration process of the differential file through a single thread.

[0321] When the electronic device performs the restoration processing of the differential file through a single thread, the data compression blocks described by each zone in the Patch file are processed serially in turn. Please refer to the relevant description in the previous article and will not repeat them here.

[0322] S506: The electronic device creates k restoration threads.

[0323] The electronic device creates a corresponding number of restoration threads according to the determined parallel number k, so as to implement parallel restoration processing of the data compression blocks described by different zones in the Patch file.

[0324] S507: The electronic device divides a group of RAM spaces corresponding to each restoration thread, and creates a restoration operation linked list corresponding to each restoration thread according to the total number x of control blocks.

[0325] Exemplarily, assuming that the parallel number k=2, the electronic device creates a first restoration thread and a second restoration thread to perform parallel restoration processing on the data compression blocks described in different zones in the Patch file.

[0326] For each restoration thread, the electronic device needs to divide a corresponding set of RAM spaces for it, including a first RAM space area 301, a second RAM space area 302, a third RAM space area 303, and a fourth RAM space area 304, as shown in Figure 21a or Figure 21b.

[0327] For each restore thread, the electronic device also needs to create a corresponding restore operation linked list. As mentioned above, the zone number corresponding to each restore thread can be determined based on the modulo of the zone number and the number of restore threads k. Furthermore, after the electronic device determines the address offset of each zone in the Patch file, it can create a restore operation linked list corresponding to each restore thread. In the restore operation linked list, the data portion of each node is filled with the zone number and the address offset of the zone corresponding to that number in the Patch file.

[0328] For example, taking the first restore thread as an example, the corresponding zones are numbered zone1, zone3, zone5, etc. Then, in the corresponding restore operation list, 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 to 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 to 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 to the fourth node, and so on.

[0329] S508, each restoration 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 restoration operation linked list, and uses a corresponding set of RAM spaces to perform a restoration operation on these data compression blocks.

[0330] For a node in the restore operation linked list, the restore thread sequentially restores each compressed data block (including Diff data compressed blocks and / or Extra data compressed blocks) described by the zone corresponding to that node. The restore thread uses the corresponding set of RAM space to restore each Diff data compressed block or Extra data compressed block. The process can be found in the previous section and will not be repeated here.

[0331] Exemplarily, the first restoration thread uses the first set of RAM space to sequentially process the data compression blocks described by zone1, zone3, zone5, etc., and the second restoration thread uses the second set of RAM space to sequentially process the data compression blocks described by zone2, zone4, zone6, etc.

[0332] For example, zone1 describes 3 Diff data compression blocks and 4 Extra data compression blocks. The first restoration thread uses the first set of RAM space to process these 3 Diff data compression blocks and 4 Extra data compression blocks in sequence, and then continues to process the data compression blocks described by zone3, and so on.

[0333] It should be noted that when the first restoration thread restores the data compression block described by zone1, it writes the restored new data into the new file at a first address corresponding to the second pointer offset in zone1.

[0334] For another example, zone2 describes 5 Diff data compression blocks and 2 Extra data compression blocks. The second restoration thread uses the second set of RAM space to process these 5 Diff data compression blocks and 2 Extra data compression blocks in sequence, and then continues to process the data compression blocks described by zone4, and so on.

[0335] It should be noted that when the second restoration thread restores the data compression block described by zone2, it writes the restored new data into the new file at a first address corresponding to the second pointer offset in zone2.

[0336] That is, when each restoration thread restores the compressed data block described by a zone, it writes the restored new data into the new file at a first address corresponding to the position of the second pointer offset in the zone.

[0337] S509: After each restoration thread completes the corresponding data compression block restoration operation according to the restoration operation linked list, the electronic device verifies the obtained target file.

[0338] Because the number of compressed data blocks described by each zone varies, the time it takes for each restore thread to perform the data restore operation is also different. After each restore thread completes the corresponding data compressed block restore operation according to the restore operation chain list, all data compressed blocks in the patch file are restored.

[0339] At this point, the electronic device can determine whether the restored target file is correct based on the value of the checksum field in the Patch file. For example, if the hash value of the target file restored based on the Patch file is the same as the value of the checksum field, the terminal can determine that the restored target file is correct. Otherwise, it can be determined that the restored target file is incorrect.

[0340] As mentioned above, any restoration thread can be roughly divided into the following stages when restoring Diff data blocks: the stage of reading Diff data compressed blocks in the Patch file (referred to as the first stage), the stage of decompressing the Diff data compressed blocks (referred to as the second stage), the stage of reading data corresponding to the Diff data compressed blocks in the old file (referred to as the fourth stage), the stage of synthesizing new data based on the old data and the Diff data blocks (referred to as the fourth stage), and the stage of writing data in the new file (referred to as the fifth stage).

[0341] Among them, any restoration thread uses a group of RAM spaces corresponding thereto (ie, the first RAM memory area, the second RAM memory area, the third RAM memory area and the fourth RAM memory area) to complete the restoration operation for each Diff data compression block.

[0342] The following, in conjunction with Figures 16 and 24a, analyzes the availability status of the first and third RAM memory areas during the aforementioned stages. The initial availability status of the first and third RAM memory areas is "available." Assume that when state = 0, the RAM memory area is available, and when state = 1, the RAM memory area is unavailable.

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

[0344] In the second stage, the restoration thread decompresses the Diff data compressed blocks in the first RAM memory area, and writes the decompressed Diff data blocks 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.

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

[0346] In the fourth stage, the restoration thread reads the old data in the first RAM memory area and the Diff data in the third RAM memory area to synthesize the new target data, and then writes the synthesized target data to the third RAM memory area. During this stage, the restoration thread changes the state of the third RAM memory area from 1 to 0 and applies for the object lock corresponding to the third RAM memory area to protect the data in the third RAM memory area. After the restoration thread completes the data synthesis operation, it releases the object lock corresponding to the third RAM memory area, changes the state of the first RAM memory area from 1 to 0, and changes the state of the third RAM memory area from 0 to 1.

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

[0348] By analyzing the above process, it can be seen 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 is over, the restoration thread continues to process the next Diff data compression block or Extra data compression block, and the processing flow involves the above-mentioned first stage. However, in the fifth stage, the available state of the first RAM memory area is available (state=0), and it will continue to be used by the restoration thread after the fifth stage is over. In this way, in the fifth stage, there is a waiting delay in the first RAM memory area, which affects the processing efficiency of the restoration thread to a certain extent.

[0349] Similarly, as mentioned above, any restore thread can be roughly divided into the following stages when restoring Extra data blocks: the stage of reading Extra data compressed blocks in the Patch file (referred to as the first stage), the stage of decompressing Extra data compressed blocks (referred to as the second stage), and the stage of writing data in the new file (referred to as the fifth stage).

[0350] Among them, any restoration thread uses a group of RAM spaces corresponding thereto (i.e., the first RAM memory area, the second RAM memory area, the third RAM memory area, and the fourth RAM memory area) to complete the restoration operation for each Extra data compression block.

[0351] The following, in conjunction with Figures 17 and 24b, analyzes the availability status of the first and third RAM memory areas during the aforementioned stages. The initial value of the availability status of the first and third RAM memory areas is available. Assume that when state = 0, the RAM memory area is available, and when state = 1, the RAM memory area is unavailable.

[0352] In the first stage, the restore thread compresses and writes the Extra data read from the Patch file into the first RAM memory area, and the state of the first RAM memory area changes from 0 to 1.

[0353] In the second stage, the restoration thread decompresses the Extra data compressed blocks in the first RAM memory area, and writes the decompressed Extra data blocks to 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.

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

[0355] By analyzing the above process, it can be seen 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 is over, the restoration thread continues to process the next Extra data compression block, and the processing flow also involves the above-mentioned first stage. However, in the fifth stage, the availability status of the first RAM memory area is available (state=0), and it will continue to be used by the restoration thread after the fifth stage is over. In this way, in the fifth stage, there is a waiting delay in the first RAM memory area, which affects the processing efficiency of the restoration thread to a certain extent.

[0356] Therefore, when the restoration thread continuously processes two data compression blocks (no matter whether they are Diff data compression blocks or Extra data compression blocks), the restoration processing flow of the two data compression blocks involves the first stage and the fifth stage, and the first stage of the restoration process of the second data compression block will not start until the fifth stage of the restoration processing flow of the previous data compression block is completed, resulting in a waiting delay in the first RAM memory area, which affects the processing efficiency of the restoration thread to a certain extent.

[0357] To solve the above problem, for each restoration thread, when restoring each compressed data block described by a zone, it can be completed based on two sub-threads.

[0358] Figure 25 shows a method for restoring differential files provided by an embodiment of the present application. As shown in Figure 25, a restoration thread performs restoration processing operations on each compressed data block described in a zone, which may specifically include the following steps:

[0359] S601, the restoration thread parses zone data.

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

[0361] Diff-zone-offset and Extra-zone-offset are global variables. Diff-zone-offset indicates the sequence number of the currently processed Diff data compression block among the Diff data compression blocks described by the current zone; Extra-zone-offset indicates the sequence number of the currently processed Extra data compression block among the Extra data compression blocks described by the current zone.

[0362] In this embodiment, the initial values ​​of Diff-zone-offset and Extra-zone-offset are set to 0, and the sequence numbers of the Diff data compression blocks and Extra data compression blocks described by the zone start counting from 1. For example, when Diff-zone-offset is 1, it indicates that the Diff data compression block currently being processed is the Diff data compression block with sequence number 1; when Extra-zone-offset is 2, it indicates that the Extra data compression block currently being processed is the Extra data compression block with sequence number 2.

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

[0364] S603: The restoration thread creates and starts a first sub-thread and a second sub-thread, and performs restoration processing on each compressed data block described by the zone through the first sub-thread and the second sub-thread in parallel.

[0365] The first sub-thread is used to restore the Diff data compressed blocks or the Extra data compressed blocks, and the second sub-thread is also used to restore the Diff data compressed blocks or the Extra data compressed blocks. The first sub-thread and the second sub-thread are parallel.

[0366] It should be noted that the order of starting the first sub-thread and the second sub-thread may be specified or random, which is not limited in this embodiment.

[0367] As described above, when the first or second sub-thread restores the compressed Diff data blocks, the process can be divided into the first, second, third, fourth, and fifth stages. When the first or second sub-thread restores the compressed Extra data blocks, the process can be divided into the first, second, and fifth stages.

[0368] The processing state of the child thread is different when the child thread restore processing operation is in different stages. For example, when the child thread restore processing operation is in the first stage, the processing state of the child thread is reading differential data; when the child thread restore processing operation is in the second stage, the processing state of the child thread is decompressing differential data; when the child thread restore processing operation is in the third stage, the processing state of the child thread is reading source data; when the child thread restore processing operation is in the fourth stage, the processing state of the child thread is synthesizing target data; when the child thread restore processing operation is in the fifth stage, the processing state of the child thread is writing target data, that is, writing target data (or new data) to the target file (or new file).

[0369] Figure 26a shows the processing flow of the first sub-thread. As shown in Figure 26a, the steps of the first sub-thread restoring the data compressed blocks include:

[0370] S701: The first sub-thread starts.

[0371] S702, the first sub-thread determines whether Diff-zone-offset is 0, or whether Extra-zone-offset is 0, or whether the processing status of the second sub-thread is writing target data. If so, execute S703, if not, execute S702.

[0372] Among them, when Diff-zone-offset is 0, it indicates that the various Diff data compression blocks described by the zone have not yet started to be restored; when Extra-zone-offset is 0, it indicates that the various Extra data compression blocks described by the zone have not yet started to be restored.

[0373] When the second sub-thread's processing status is "writing target data," it indicates that the second sub-thread's processing of the compressed data block is in stage 5. At this point, to avoid waiting for the first RAM space area, the first sub-thread can restore the next compressed data block, achieving parallel processing with the second sub-thread.

[0374] If the judgment results for the above judgment conditions are all negative, the first sub-thread waits and continues to execute the judgment process shown in S702.

[0375] S703, the first child thread determines whether Diff-zone-offset is less than Diffnum, if so, executes S704, if not, executes S706.

[0376] Since Diff-zone-offset is used to represent the sequence number of the currently processed 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 are still unprocessed Diff data compression blocks in each Diff data compression block described by the current zone.

[0377] S704: The first sub-thread increments Diff-zone-offset.

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

[0379] S705: The first sub-thread restores the Diff data compression block corresponding to the Diff-zone-offset and executes S702.

[0380] At this time, the first sub-thread restores the Diff data compression blocks corresponding to the Diff-zone-offset based on a group of RAM spaces corresponding to the restoration thread. The detailed steps can be referred to the previous text and will not be repeated here.

[0381] After the first sub-thread completes the restoration process on the Diff data compression block corresponding to the Diff-zone-offset, the process returns to S702 to determine whether the conditions for the first sub-thread to restore the next data compression block are met.

[0382] S706, the first child thread determines whether Extra-zone-offset is less than Extranum, if so, executes S707, if not, executes S709.

[0383] Since Extra-zone-offset is used to indicate the sequence number of the currently processed Extra data compression block in each Extra data compression block described in the current zone, when Extra-zone-offset is less than Extranum, it indicates that there are still unprocessed Extra data compression blocks in each Extra data compression block described in the current zone.

[0384] S707: The first child thread increments Extra-zone-offset.

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

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

[0387] At this time, the first sub-thread restores the Extra data compression blocks corresponding to the Extra-zone-offset based on a group of RAM spaces corresponding to the restoration thread. The detailed steps can be referred to the previous text and will not be repeated here.

[0388] After the first sub-thread completes the restoration process on the Extra data compression block corresponding to the Extra-zone-offset, the process returns to S702 to determine whether the conditions for the first sub-thread to restore the next data compression block are met.

[0389] S709: The first sub-thread ends.

[0390] When Diff-zone-offset is not less than Diffnum, there are no unprocessed Diff data compression blocks in the current zone's description. When Extra-zone-offset is not less than Extranum, there are no unprocessed Extra data compression blocks in the current zone's description. At this point, the first child thread can terminate.

[0391] Figure 26b shows the processing flow of the second sub-thread. Similar to the first sub-thread, as shown in Figure 26b, the steps of restoring the compressed data blocks by the second sub-thread include:

[0392] S801, the second sub-thread starts.

[0393] S802, the second sub-thread determines whether Diff-zone-offset is 0, or whether Extra-zone-offset is 0, or whether the processing status of the first sub-thread is to write target data. If so, execute S803, if not, execute S802.

[0394] Among them, when Diff-zone-offset is 0, it indicates that the various Diff data compression blocks described by the zone have not yet started to be restored; when Extra-zone-offset is 0, it indicates that the various Extra data compression blocks described by the zone have not yet started to be restored.

[0395] When the first sub-thread's processing status is "writing target data," it indicates that the first sub-thread's processing of the compressed data block is in stage 5. At this point, to avoid waiting for the first RAM space area, the second sub-thread can restore the next compressed data block, achieving parallel processing with the first sub-thread.

[0396] If the judgment results for the above judgment conditions are all negative, the second sub-thread waits and continues to execute the judgment process shown in S802.

[0397] S803, the second sub-thread determines whether Diff-zone-offset is less than Diffnum, if so, executes S804, if not, executes S806.

[0398] Since Diff-zone-offset is used to represent the sequence number of the currently processed 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 are still unprocessed Diff data compression blocks in each Diff data compression block described by the current zone.

[0399] S804: The second sub-thread increments Diff-zone-offset.

[0400] 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 second sub-thread.

[0401] S805: The second sub-thread restores the Diff data compression block corresponding to the Diff-zone-offset and executes S802.

[0402] At this time, the second sub-thread restores the Diff data compression blocks corresponding to the Diff-zone-offset based on a group of RAM spaces corresponding to the restoration thread. The detailed steps can be referred to the previous text and will not be repeated here.

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

[0404] S806, the second child thread determines whether Extra-zone-offset is less than Extranum, if so, executes S807, if not, executes S809.

[0405] Since Extra-zone-offset is used to indicate the sequence number of the currently processed Extra data compression block in each Extra data compression block described in the current zone, when Extra-zone-offset is less than Extranum, it indicates that there are still unprocessed Extra data compression blocks in each Extra data compression block described in the current zone.

[0406] S807: The second sub-thread increments Extra-zone-offset.

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

[0408] S808: The second sub-thread restores the Extra data compression block corresponding to the Extra-zone-offset and executes S802.

[0409] At this time, the second sub-thread restores the Extra data compression blocks corresponding to the Extra-zone-offset based on a group of RAM spaces corresponding to the restoration thread. The detailed steps can be referred to the previous text and will not be repeated here.

[0410] After the second sub-thread completes the restoration process on the Extra data compression block corresponding to Extra-zone-offset, the process returns to S802 to determine whether the conditions for the second sub-thread to restore the next data compression block are met.

[0411] S809: The second sub-thread ends.

[0412] When Diff-zone-offset is not less than Diffnum, there are no unprocessed Diff data compression blocks in the current zone's description. When Extra-zone-offset is not less than Extranum, there are no unprocessed Extra data compression blocks in the current zone's description. At this point, the second child thread can terminate.

[0413] S604, the restoration thread determines whether all data compression blocks described by the zone have been processed, and whether the first sub-thread and the second sub-thread have both ended. If so, execute S605; if not, execute S604.

[0414] The restoration thread determines whether all the data compression blocks described by the zone have been processed, and whether the first sub-thread and the second sub-thread have ended. If not, it waits and continues to judge. If so, the restoration thread ends the restoration processing operation of the data compression blocks described by the zone.

[0415] S605: The restoration thread completes the restoration process of the compressed data blocks described by the zone.

[0416] After the restoration thread completes the restoration processing operation on the data compression block described by a zone, it can continue to restore the data compression block described by the next zone according to the corresponding restoration operation execution linked list. The processing flow can still refer to S601-S605 and will not be repeated here until the data compression blocks described by each zone recorded in the restoration operation execution linked list are completed, and the restoration thread is terminated.

[0417] In this way, when a restoration thread restores each compressed data block described by a zone through two sub-threads, the restoration efficiency of the compressed data block can also be improved.

[0418] As shown in Figure 27a, when the restoration process of each data compression block described by a zone is implemented through a single thread, the restoration process of the previous data compression block will not start until the fifth stage of the restoration process of the previous data compression block is completed. This causes a waiting delay in the first RAM memory area, which reduces the processing efficiency of the restoration thread to a certain extent.

[0419] However, as shown in Figure 27b, when the restoration processing of each data compression block described by a zone is implemented through two sub-threads, when the first sub-thread is restoring the fifth stage of the Diff data compression block 1, the second sub-thread can start the first stage of the restoration processing of the Diff data compression block 2. Similarly, when the second sub-thread is restoring the fifth stage of the Diff data compression block 2, the first sub-thread can start the second stage of the restoration processing of the Extra data compression block 1; when the first sub-thread is restoring the fifth stage of the Extra data compression block 1, the second sub-thread can start the first stage of the restoration processing of the Extra data compression block 2. In this way, there is no need to wait until the fifth stage of the restoration process of the previous data compression block is completed before starting the first stage of the restoration process of the next data compression block, so that there is no waiting delay in the first RAM memory area, which reduces the restoration time of multiple data compression blocks (clearly visible by comparing Figures 27a and 27b), and improves the processing efficiency of the restoration thread.

[0420] As shown in Figure 28, a schematic diagram of the structure of the electronic device 10 is shown. Optionally, the electronic device 10 can be called a terminal or a terminal device, for example, a smart phone, etc. The terminal can be a wearable electronic device, for example, a smart watch, which is not limited in this application. It should be noted that the schematic diagram of the structure of the electronic device 10 can be applied to the smart watch 100 or the mobile phone 200 in Figure 1. It should be understood that the electronic device 10 shown in Figure 28 is only an example of an electronic device, and the electronic device 10 can have more or fewer components than shown in the figure, can combine two or more components, or can have different component configurations. The various components shown in Figure 28 can be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application-specific integrated circuits.

[0421] The electronic device 10 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 sensor, a fingerprint sensor, a touch sensor, an ambient light sensor, a bone conduction sensor, and the like.

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

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

[0424] The wireless communication function of the electronic device 10 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modulation and demodulation processor and the baseband processor. The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G applied on the electronic device 10. The wireless communication module 160 can provide solutions for wireless communications including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication technology (NFC), infrared technology (IR), etc. applied on the electronic device 10.

[0425] In some embodiments, antenna 1 of electronic device 10 is coupled to mobile communication module 150 , and antenna 2 is coupled to wireless communication module 160 , so that electronic device 10 can communicate with a network and other devices via wireless communication technology.

[0426] The electronic device 10 implements display functions through a GPU, a display screen 194 , and an application processor, etc. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.

[0427] 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 10 may include one or N display screens 194, where N is a positive integer greater than one.

[0428] 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 10. The internal memory 121 can be used to store computer executable program code, which includes instructions. The processor 110 executes the instructions stored in the internal memory 121 to execute various functional applications and data processing of the electronic device 10, so that the electronic device 10 implements the firmware file restoration method of the embodiment of the present application.

[0429] In the embodiment of the present application, the internal memory 121 can be used to store a program for implementing the differential file generation method, a program for the differential file restoration method, a program for the BSDiff algorithm, etc. in the embodiment of the present application.

[0430] The electronic device 10 can implement audio functions such as music playback and recording through the audio module 170 , the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.

[0431] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be provided in the processor 110, or some functional modules of the audio module 170 can be provided in the processor 110.

[0432] The gyroscope sensor can be used to detect the motion posture of the electronic device 10. In some embodiments, the gyroscope sensor can be used to determine the angular velocity of the electronic device 10 around three axes (i.e., the x, y, and z axes). In some embodiments, the gyroscope sensor can also be used to identify the posture of the electronic device to enable identification of the behavioral status of the user wearing or holding the electronic device 10.

[0433] The accelerometer can be used to detect the magnitude of acceleration of the electronic device 10 in various directions (generally three axes). In some embodiments, when the electronic device 10 is stationary, the accelerometer can detect the magnitude and direction of gravity. In some embodiments, the accelerometer can also be used to identify the posture of the electronic device to identify the behavior of the user wearing or holding the electronic device 10.

[0434] The temperature sensor can be used to detect the temperature of the electronic device 10. In some embodiments, the temperature sensor can be used to detect the body temperature of the user wearing the electronic device 10.

[0435] The PPG (Photo Plethysmo Graphy) sensor can be used to detect physiological parameter information of the wearer of the electronic device 10. The principle of the PPG sensor is to optically detect the fluctuating changes in blood volume in the tissue microvascular bed under the action of cardiac contraction and relaxation. For example, when the heart contracts, the blood volume of the tissue increases and the amount of 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 amount of light absorption decreases, so the light intensity detected by the light detector is larger. Since the change in light intensity of the PPG sensor is related to the slight change in blood perfusion of the tissue, it can be used to provide information about the cardiovascular system of the wearer of the electronic device 10, such as physiological parameter information such as blood pressure, blood oxygen, pulse rate (heart rate) and respiratory rate.

[0436] The pressure sensor is used to sense pressure signals and convert the pressure signals into electrical signals. In some embodiments, the pressure sensor can be provided on the display screen 194. The electronic device 10 can also calculate the position of the touch based on the detection signal of the pressure sensor.

[0437] A touch sensor, also known as a "touch panel," can be mounted on display screen 194. The touch sensor and display screen 194 together form a touch screen, also known as a "touch screen." The touch sensor detects touch operations applied to or near the touch sensor. The touch sensor can communicate the detected touch operations to the application processor to determine the type of touch event.

[0438] Keys 190 include a power button (also known as a power button), a volume button, and the like. Keys 190 may be mechanical keys or touch-sensitive keys. Electronic device 10 may receive key inputs and generate key signal inputs related to user settings and function control of electronic device 10.

[0439] Motor 191 can generate vibration prompts. Motor 191 can be used for incoming call vibration prompts and can also be used for touch vibration feedback.

[0440] The indicator 192 may be an indicator light, which may be used to indicate the charging status, the change in the power level, or a message.

[0441] The software system of the electronic device 10 can adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a micro-service architecture, or a cloud architecture. In the embodiment of the present application, the software structure of the electronic device 10 is exemplified by taking an operating system of a layered architecture as an example.

[0442] FIG29 is a block diagram of the software structure of the electronic device 10 according to an embodiment of the present application.

[0443] The layered architecture of the electronic device 10 divides the software into several layers, each with a clear role and division of labor. Layers communicate with each other via software interfaces. In some embodiments, taking the electronic device 10 as a smartwatch as an example, as shown in FIG29 , the operating system can be divided into six layers: from top to bottom, the UI (User Interface) application layer, the system service layer, the algorithm layer, the hardware abstraction layer, the kernel layer, and the driver layer.

[0444] The UI application layer may include a series of application packages, such as watch faces, sports records, calls, exercises, etc.

[0445] The system service layer can include a range of system services. These services include a heart rate service, which provides physiological parameter information for the smartwatch wearer, such as blood pressure, blood oxygen, pulse rate, respiratory rate, and body temperature, and can also detect changes in physiological parameters of the smartwatch wearer. The system service layer can also include a step counting service, a calorie service, and a heart health service.

[0446] The algorithm layer may include a series of algorithm models. As shown in FIG29 , the algorithm layer may include a differential restoration algorithm model. The differential restoration algorithm model may be used in the differential file restoration method provided in this embodiment.

[0447] The Hardware Abstraction Layer (HAL) is the interface between the operating system kernel and the hardware circuitry. The HAL layer includes, but is not limited to, the audio HAL. The audio HAL is used to process audio streams, for example, by performing noise reduction and directional enhancement.

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

[0449] It is understood that the layers in the software structure shown in FIG29 and the components contained in each layer do not constitute a specific limitation on the electronic device 10. In other embodiments of the present application, the electronic device 10 may include more or fewer layers than shown, and each layer may include more or fewer components, and this application does not limit this.

[0450] It is understandable that, in order to implement the differential file restoration method in the embodiment of the present application, the electronic device 10 includes hardware and / or software modules that perform the corresponding functions. In combination with the algorithm steps of each example described in the embodiment disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving 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 combination with the embodiments, but such implementation should not be considered to be beyond the scope of the present application.

[0451] In one example, FIG30 shows a schematic block diagram of a device 800 according to an embodiment of the present application. The device 800 may include: a processor 801 and a transceiver / transceiver pin 802 , and optionally, a memory 803 .

[0452] The various components of the device 800 are coupled together via a bus 804, wherein the bus 804 includes, in addition to a data bus, a power bus, a control bus, and a status signal bus. However, for the sake of clarity, all buses are referred to as bus 804 in the figure.

[0453] Optionally, the memory 803 may be used to store instructions of the server in the embodiment of the differential file generation method. The processor 801 may be used to execute the instructions in the memory 803 and control the receiving pin to receive a signal and control the sending pin to send a signal.

[0454] Optionally, the memory 803 may be used to store instructions of the intelligent terminal in the embodiment of the differential file restoration method. The processor 801 may be used to execute the instructions in the memory 803 and control the receiving pin to receive a signal and control the sending pin to send a signal.

[0455] The device 800 can be a server in the above-mentioned differential file generation method embodiment, such as an OTA server, or a smart terminal in the above-mentioned differential file restoration method embodiment, such as a smart phone, a smart watch, etc.

[0456] This embodiment also provides a computer storage medium, which stores computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the above-mentioned related method steps to implement the differential file generation method in the above-mentioned embodiment, or causes the electronic device to execute the above-mentioned related method steps to implement the differential file restoration method in the above-mentioned embodiment.

[0457] This embodiment also provides a computer program product. When the computer program product is run on a computer, it enables the computer to execute the above-mentioned related steps to implement the differential file generation method in the above-mentioned embodiment, or implement the differential file restoration method in the above-mentioned embodiment.

[0458] In addition, an embodiment of the present application also provides a device, which can specifically be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store computer-executable instructions, and when the device is running, the processor can execute the computer-executable instructions stored in the memory to enable the chip to execute the differential file generation method or the differential file restoration method in the above method embodiment.

[0459] Among them, the electronic equipment (such as a server or terminal, etc.), computer storage medium, computer program product or chip provided in this embodiment are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here.

[0460] Through the description of the above implementation methods, technical personnel in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0461] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of modules or units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0462] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to 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 used 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.