WO2024051465A1 - 差分文件的还原方法及电子设备 - Google Patents

差分文件的还原方法及电子设备 Download PDF

Info

Publication number
WO2024051465A1
WO2024051465A1 PCT/CN2023/113549 CN2023113549W WO2024051465A1 WO 2024051465 A1 WO2024051465 A1 WO 2024051465A1 CN 2023113549 W CN2023113549 W CN 2023113549W WO 2024051465 A1 WO2024051465 A1 WO 2024051465A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
block
file
restoration
diff
Prior art date
Application number
PCT/CN2023/113549
Other languages
English (en)
French (fr)
Other versions
WO2024051465A9 (zh
Inventor
王艳召
张赠辉
陈超
黄九林
Original Assignee
荣耀终端有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 荣耀终端有限公司 filed Critical 荣耀终端有限公司
Publication of WO2024051465A1 publication Critical patent/WO2024051465A1/zh
Publication of WO2024051465A9 publication Critical patent/WO2024051465A9/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • G06F8/658Incremental updates; Differential updates
    • HELECTRICITY
    • H03ELECTRONIC CIRCUITRY
    • H03MCODING; DECODING; CODE CONVERSION IN GENERAL
    • H03M7/00Conversion of a code where information is represented by a given sequence or number of digits to a code where the same, similar or subset of information is represented by a different sequence or number of digits
    • H03M7/30Compression; Expansion; Suppression of unnecessary data, e.g. redundancy reduction

Definitions

  • the present application relates to the technical field of intelligent terminals, and in particular to a differential file restoration method and electronic equipment.
  • OTA upgrade methods mainly include full package upgrade and differential package upgrade.
  • terminal equipment In order to improve the efficiency of upgrade package transmission and firmware upgrade, terminal equipment mostly adopts differential package upgrade method, that is, only the different parts of the firmware are upgraded.
  • the terminal device uses the differential package upgrade method for online firmware upgrade
  • the differential file needs to be restored first, and the restore operation of the differential file requires RAM (Random Access Memory, random access memory) memory, and different terminal devices provide The RAM memory space for differential file restoration is different. Therefore, when using differential package upgrade to upgrade firmware, how to improve the restoration efficiency of differential files is a problem that needs to be solved.
  • embodiments of the present application provide a differential file restoration method and an electronic device.
  • the electronic device adaptively determines the parallel number of restoration threads based on 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. Improved the recovery efficiency of differential files.
  • embodiments of the present application provide a method for restoring differential files.
  • the method includes:
  • the electronic device obtains the differential file; wherein the differential file includes at least one group of data compression blocks, and the group of data compression blocks includes difference Diff data compression blocks and/or new Extra data compression blocks, and the data compression blocks are Before compression, it is divided based on the preset block size;
  • the electronic device determines the parallel number k of restoration threads based on the block size and the RAM space size used by the electronic device for differential file restoration, and divides a set of RAM spaces for each restoration thread;
  • the electronic device uses k restoration threads to perform restoration processing on the differential files in parallel.
  • Each restoration thread uses a corresponding set of RAM space to perform restoration processing on at least one set of data compression blocks, and restores the data obtained after the processing. Write to the target file.
  • the electronic device adaptively determines the parallel number of restoration threads according to the block size corresponding to the difference file and the size of the RAM memory space used for differential file restoration, and performs restoration processing in parallel through multiple threads, thereby improving the difference File restoration efficiency.
  • a set 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 first RAM memory area and the second RAM memory area The size is the block size; the second RAM memory area and the fourth RAM memory area are the safety buffer areas of the first RAM memory area and the third RAM memory area respectively; each restore thread shares the fifth RAM memory area, and the fifth RAM memory area Used to run data compression algorithms.
  • the electronic device can implement data compression and block restoration operations based on a smaller RAM memory space. Moreover, setting a safety buffer for the first RAM memory area and the third RAM memory area will not affect the accuracy of data processing in case the data actually increases after data compression.
  • Diff data corresponding to Diff data compression blocks is obtained based on the first operation; each restoration thread performs restoration processing on a group of data compression blocks, It can include: the restoration thread sequentially performs data restoration processing on the Diff data compression blocks or Extra data compression blocks in a group of data compression blocks in accordance with the parsing order; each time a Diff data compression block is obtained through parsing, the Diff data compression block is The Diff data corresponding to the block is subjected to a second operation with the existing data to obtain the first target data, which is written into the target file; among which, the existing data is the Diff data read in the existing file corresponding to the difference file. To compress the data matched in blocks, 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 the second target data and written into the target file. .
  • the first operation is a subtraction operation
  • the second operation is an addition operation
  • each restore thread can use Diff data compression blocks or Extra data compression blocks as an independent differential restore processing unit, so that the RAM memory consumption on the terminal side is smaller, and the terminal side The side can realize the differential data restoration function through a smaller RAM memory space.
  • the electronic device performs a second operation on the Diff data corresponding to the compressed blocks of the Diff data and the existing data to obtain the first target data, and writes it into the target file. It may include: the electronic device compresses the Diff data into blocks and temporarily stores them in the first RAM memory area; the electronic device performs data decompression processing on the Diff data compression blocks, and temporarily stores the obtained Diff data blocks into the third RAM memory area; The 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 combines the data in the first RAM memory area with the data in the third RAM memory area. In the second operation, the obtained first target data is temporarily stored 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.
  • the electronic device decompresses the Extra data into compressed blocks to obtain the second target data and writes it into the target file, which may include: the electronic device compresses the Extra data The blocks are temporarily stored in the first RAM memory area; the electronic device performs data decompression processing on the Extra data compression blocks, and the obtained second target data is temporarily stored in the third RAM memory area; the electronic device will be in the third RAM memory area The temporarily stored second target data is written into the target file.
  • each restoration thread uses a corresponding set of RAM space to perform restoration processing on at least one set of data compression blocks, which may include: the electronic device performs restoration processing according to the difference file
  • the number of data compression block groups included, as well as the sequence number of each group of data compression blocks creates a linked list for each restoration thread, 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 numbers of a set of data compression blocks, and the first address where the restored data corresponding to the set of data compression blocks is written in the target file.
  • the data structure of the differential file includes a header, a control block, and a set of data compression blocks described by the control block; the header is filled with the magic of the differential file. number and block size; the control block is filled with the first pointer offset and the second pointer offset; where the first pointer offset is used to determine the data corresponding to a set of data compression blocks in the existing file The first address is read; the second pointer offset is used to determine the first address of data writing corresponding to a group of data compression blocks in the target file.
  • the electronic device determines each group of data compression blocks to be processed by each restoration thread according to the remainder of the parallel number of the serial number of the data compression block.
  • each restoration thread uses a corresponding set of RAM space to restore at least one set of data compression blocks, which may include: each restoration thread creates a One 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 sequentially compress the Diff data blocks or Extra included in a group of data compression blocks.
  • Data compression is performed in blocks for restoration processing; among them, 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 At the same time, the second sub-thread continues to restore the data in a group of data compression blocks.
  • the target stage is to write the data temporarily stored in the third RAM memory area into the target file.
  • each restoration thread restores a group of data compression blocks, it does not need to wait until the restoration process of the previous data compression block is completely completed before the restoration process of the next data compression block starts, so that the first RAM There is no longer a waiting delay in the memory area, which reduces the restoration time of a group of data compression blocks and improves the processing efficiency of the restoration thread.
  • inventions of the present application provide an electronic device.
  • the electronic device includes: one or more processors; memory; and one or more computer programs, wherein the one or more computer programs are stored on the memory, and when the computer program is executed by the one or more processors, the electronic device Execute the differential file restoration method in the first aspect and any implementation manner of the first aspect.
  • the second aspect and any implementation manner of the second aspect respectively correspond to the first aspect and any implementation manner of the first aspect.
  • the technical effects corresponding to the second aspect and any implementation manner of the second aspect may be referred to the technical effects corresponding to the above-mentioned first aspect and any implementation manner of the first aspect, which will not be described again here.
  • inventions of the present application provide a computer-readable storage medium.
  • the computer-readable storage medium includes a computer program.
  • the computer program When the computer program is run on the electronic device, the electronic device performs the differential file restoration method as in the first aspect and any implementation of the first aspect.
  • the third aspect and any implementation manner of the third aspect are respectively the same as the first aspect and any one implementation manner of the first aspect. corresponding to the implementation methods.
  • the technical effects corresponding to the third aspect and any implementation manner of the third aspect please refer to the technical effects corresponding to the above-mentioned first aspect and any implementation manner of the first aspect, which will not be described again here.
  • embodiments of the present application provide a computer program product, including a computer program that, when the computer program is run, causes the computer to perform the differential file restoration method in the first aspect and any implementation of the first aspect. .
  • the fourth aspect and any implementation manner of the fourth aspect respectively correspond to the first aspect and any implementation manner of the first aspect.
  • the technical effects corresponding to the fourth aspect and any implementation manner of the fourth aspect please refer to the technical effects corresponding to the above-mentioned first aspect and any implementation manner of the first aspect, which will not be described again here.
  • this application provides a chip, which includes a processing circuit and transceiver pins.
  • the transceiver pin and the processing circuit communicate with each other through an internal connection path, and the processing circuit performs the differential file restoration method as in the first aspect and any implementation of the first aspect to control the receiving pin to receive the signal , to control the sending pin to send signals.
  • the fifth aspect and any implementation manner of the fifth aspect respectively correspond to the first aspect and any implementation manner of the first aspect.
  • the technical effects corresponding to the fifth aspect and any implementation manner of the fifth aspect please refer to the technical effects corresponding to the above-mentioned first aspect and any implementation manner of the first aspect, which will not be described again here.
  • Figure 1 is a schematic diagram of an exemplary application scenario
  • Figure 2 is a schematic flowchart illustrating a differential restoration of firmware files
  • Figure 3 is a schematic diagram of an exemplary differential principle
  • Figure 4 is a schematic diagram of the data structure of a differential file
  • Figure 5 is a schematic diagram showing an exemplary reduction principle
  • Figure 6 is a schematic diagram of an exemplary data restoration operation
  • Figure 7 is a schematic diagram of a method for generating a differential file provided in this embodiment.
  • Figure 8 is an example diagram of the data structure of a differential file provided in this embodiment.
  • Figure 9 is a schematic diagram of a method for generating a differential file provided in this embodiment.
  • Figure 10 is an example diagram of the data structure of a differential file provided in this embodiment.
  • Figure 11a is a schematic diagram of a method for generating a differential file provided in this embodiment
  • Figure 11b is a schematic diagram of a data block division method provided in this embodiment.
  • Figure 12 is a schematic diagram of a differential file restoration method provided in this embodiment.
  • Figure 13 is a schematic diagram of a differential file restoration operation provided in this embodiment.
  • Figure 14 is a schematic diagram of RAM space occupation during data restoration based on Diff data compression and block division provided in this embodiment
  • Figure 15 is a schematic diagram of RAM space occupation during data restoration based on Extra data compression and block division provided in this embodiment
  • Figure 16 shows the RAM space occupied during data restoration based on Diff data compression and block division provided in this embodiment.
  • Figure 17 is a schematic diagram of RAM space occupation during data restoration based on Extra data compression and block division provided in this embodiment
  • Figure 18 is a schematic diagram of RAM space occupation during data restoration based on Diff data compression and block division provided in this embodiment
  • Figure 19 is a schematic diagram of the RAM space occupied during data restoration based on Extra data compression and blocking provided in this embodiment
  • Figure 20 is a schematic diagram of an application scenario
  • Figure 21a is an exemplary schematic diagram of RAM space partitioning for restoring thread parallelism
  • Figure 21b is a schematic diagram of RAM space partitioning for restoring thread parallelism
  • Figure 22 is a schematic diagram illustrating parallel restoration of differential data
  • Figure 23 is an example diagram of the data structure of a differential file provided in this embodiment.
  • Figure 24a is a schematic diagram of the change in RAM memory area occupation status during data restoration based on Diff data compression and block division provided in this embodiment
  • Figure 24b is a schematic diagram of the change of RAM memory area occupation status during data restoration based on Extra data compression block provided in this embodiment
  • Figure 25 is a schematic diagram of the processing flow of the restore thread provided in this embodiment.
  • Figure 26a is a schematic diagram of the processing flow of the first sub-thread in the restoration thread provided by this embodiment
  • Figure 26b is a schematic diagram of the processing flow of the second sub-thread in the restoration thread provided by this embodiment.
  • Figure 27a is a schematic diagram of the duration of continuous data compression and block restoration based on a single thread provided in this embodiment
  • Figure 27b is a schematic diagram of the duration of continuous data compression and block restoration based on multi-threading provided in this embodiment
  • Figure 28 is a schematic diagram of the hardware structure of an exemplary electronic device
  • Figure 29 is a schematic diagram of the software structure of an exemplary electronic device
  • Figure 30 is a schematic structural diagram of an exemplary device.
  • a and/or B can mean: A exists alone, A and B exist simultaneously, and they exist alone. B these three situations.
  • first and second in the description and claims of the embodiments of this application are used to distinguish different objects, rather than to describe a specific order of objects.
  • first target object, the second target object, etc. are used to distinguish different target objects, rather than to describe a specific order of the target objects.
  • multiple processing units refer to two or more processing units; multiple systems refer to two or more systems.
  • the terminal device When the terminal device performs 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) generates the corresponding new version of the firmware file (hereinafter referred to as the new firmware file). Furthermore, the terminal device can complete the firmware upgrade according to the new version of the firmware file.
  • FIG. 1 exemplarily shows an application scenario, taking the smart watch 100 as an example for online firmware upgrade for explanation.
  • the smart watch 100 is a low-end smart terminal device without independent networking function (it can also be a lightweight embedded device).
  • the smart watch 100 can communicate with the smart phone 200 through Bluetooth.
  • an application APP corresponding to the smart watch 100 is installed in the smart phone 200 .
  • the application APP is used to connect the smart watch 100 and the smart phone 200 , and download applications or files for the smart watch 100 .
  • the smart watch 100 can communicate with the OTA server 300 through the application APP.
  • the smart watch 100 can periodically query the OTA server 300 through the application APP to see whether there is an upgrade differential package corresponding to the smart watch 100 .
  • the upgrade differential package can be sent to the OTA server 300 through the application APP when the online upgrade conditions are met (for example, the power status, networking status, Bluetooth status, etc. meet the preset conditions)
  • a package download request is made to download the corresponding upgrade differential package via the smartphone 200 .
  • the smart phone can send the downloaded upgrade differential package to the smart watch 100 through Bluetooth technology.
  • the smart watch 100 can restore the upgrade differential package, and complete the firmware upgrade based on the new version of the firmware file obtained after the restoration.
  • the upgrade differential package corresponding to the smart watch 100 can be produced based on the differential data package production platform 400 and uploaded to the OTA server 300 .
  • the upgrade differential package may also be generated in the OTA server 300, which is not limited in this embodiment. Regardless of whether the upgrade differential package is produced based on the differential data package production platform 400 or based on the OTA server 300 , the upgrade differential package is generated based on the old and new firmware files and the corresponding differential algorithm.
  • the smart phone 200 is an intelligent terminal device with an independent networking function and serves as a relay device between the smart watch 100 and the OTA server 300 .
  • the smart watch 100 can also communicate directly with the OTA server 300 to query the OTA server 300 to see whether there is an upgrade differential package corresponding to the smart watch 100, or to download it to the OTA server 300. Upgrade the differential package accordingly.
  • smart watch 100 is taken as an example to explain a terminal device that requires online firmware upgrade.
  • terminal devices that require online firmware upgrades can also be other wearable devices such as smart bracelets and smart headphones, or any embedded node device in the Internet of Everything scenario (for example, a node device that collects information such as temperature, humidity, etc. ), the comparison in this embodiment is not limited.
  • the terminal device that requires online firmware upgrade is a low-end device that does not have independent networking capabilities, it needs to communicate with the OTA server through a relay device. Download the upgrade differential package through the relay device.
  • the terminal device that requires online firmware upgrade is a low-end device with independent networking capabilities, it can directly communicate with the OTA server to download the upgrade differential package.
  • Figure 2 exemplarily shows a schematic flow chart of differential restoration of firmware files.
  • the server performs differential processing on pairs of new firmware files and old firmware files based on a preset differential algorithm (such as the BSDiff algorithm) to obtain a differential file (Patch file) .
  • a preset differential algorithm such as the BSDiff algorithm
  • 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 is not limited in this embodiment.
  • the server can compress and package the multiple differential files to generate an upgrade differential package.
  • the upgrade differential package may include multiple compressed differential files, description files corresponding to the multiple differential files, etc.
  • the terminal When the terminal needs to upgrade the firmware, it requests the server to download the upgrade differential package. After receiving the upgrade differential package, the terminal decompresses the upgrade differential package to obtain each differential file. Taking a differential file as an example, the terminal restores the differential file based on the old firmware file that matches the differential file to obtain the corresponding new firmware file. In this way, the terminal side can obtain multiple new firmware files, and can then perform firmware upgrade operations based on the multiple new firmware files.
  • the file differential operation and the differential package compression operation are performed on the server side, and the differential package decompression operation and the differential file restoration operation are performed on the terminal side.
  • the terminal When the terminal is a lightweight embedded device (such as a wearable device), its RAM resources are limited, which will seriously affect the efficiency of differential package decompression and restoration processing, and may even cause firmware upgrade failure due to the differential file being too large. Therefore, if the memory consumption involved in the differential file restoration process can be smaller, it will be better suitable for firmware upgrade scenarios of lightweight embedded devices.
  • a lightweight embedded device such as a wearable device
  • the core idea of the difference principle is to use as much data as possible in the old file and add as little new data as possible to build a new file.
  • Figure 3 exemplarily shows the file difference process based on the Bsdiff principle.
  • the data 01_new in the new file data is "10101010101010101”
  • the data 01_old in the old file data is "1010101110101011101”
  • the data 01_new in the new file data and the data 01_old in the old file data are the longest similarity string.
  • the data 03_new in the new file data and the data 02_old in the old file data are another longest similar substring.
  • data 02_new is between data 01_new and data 03_new. If there is no substring similar to data 02_new in the old file data, data 02_new is newly added data in the new file.
  • data 04_new is also newly added data.
  • the difference data can be calculated based on the similar substrings in the new file data and the old file data, and the difference data and the newly added data (Extra data) together constitute incremental update data (Patch data).
  • Diff data subtract the data 01_new in the new file and the data 01_old in the old file to get the Diff data 01 in the Patch data; subtract the data 03_new in the new file and the data 02_old in the old file.
  • Arithmetic yes Get Diff data 02 in the Patch data.
  • the data 02_new in the new file can be directly used as the Extra01 data in the Patch data
  • the data 04_new in the new file can be directly used as the Extra02 data in the Patch data.
  • all Diff data and Extra data can be obtained based on the new file data and old file data to form Patch data.
  • Diff data and Extra data appear in pairs, and each piece of Diff data is followed by a piece of Extra data.
  • the patch data includes at least one set of incremental update data, and each set of incremental update data usually includes Diff data and Extra data.
  • Diff data and Extra data may not appear in pairs. For example, in the last set of incremental update data in Patch data, only Diff data may be included and only Extra data may be included.
  • each Diff data and Extra data in the Patch data are consistent with the new file data.
  • new file data corresponding to the Patch data can be obtained.
  • the Patch data After the Patch data is obtained based on the new file data and the old file data, the Patch data can be data encoded to obtain the corresponding Patch file.
  • Figure 3 exemplarily shows the data structure of a Patch file.
  • the data structure includes a total encoding header, encoding information corresponding to a set of Diff data and Extra data, and Diff data and Extra data.
  • the encoding information corresponding to a certain set of Diff data and Extra data is used to describe the set of Diff data and Extra data, such as describing the byte length of Diff data, the byte length of Extra data, and the byte length of the Extra data in the old file.
  • the pointer offset of the read data is used to describe the set of Diff data and Extra data, such as describing the byte length of Diff data, the byte length of Extra data, and the byte length of the Extra data in the old file.
  • Figure 4 exemplarily shows the data structure of a Patch file.
  • the data structure of the Patch file includes header, control block, Diff block (difference data block) and Extra block (new data block).
  • Header includes 8 bytes, used to fill the magic number.
  • the magic number is used to determine the file type.
  • Each control block includes 24 bytes and is used to describe a set of Diff blocks and Extra blocks. That is, the data recorded in the control block can be used as the encoding information of a set of Diff blocks and Extra blocks that it describes.
  • the first 8 bytes of the control block are used to fill the byte length of the Diff block it describes; the middle 8 bytes of the control block are used to fill the byte length of the Extra block it describes; the last 8 bytes of the control block
  • the bytes are used to fill the pointer offset used to determine where in the old file the data (the data used to be added to the Diff data) is read.
  • each control block can be represented by (x, y, z), where x is the byte length of the Diff block, which is used to indicate that x bytes are read from the old file and the Diff block for addition. Operation; y is the byte length of the Extra block, used to indicate reading y bytes from the Extra block to add to the new file; z is the offset of the old file pointer, used to determine the next time from the old file
  • the pointer position of the read data is used to determine the offset of the pointer after reading the data in the old file this time.
  • z can represent the direction of the offset through positive and negative values. For example, a positive value indicates a forward offset, and a negative value indicates a backward offset.
  • Diff block is used to record Diff data, that is, it is used to record the difference between the longest similar substring in the old file and the new file.
  • Extra block is used to record Extra data, that is, it is used to record new data in new files.
  • the Patch files before packaging multiple Patch files, the Patch files can also be compressed.
  • compression can be performed by data blocks, that is, each control block (ie control block1 or control block2 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) are compressed.
  • each control block ie control block1 or control block2 or control block n
  • each Diff block i.e. Diff block 1 or Diff block 2 or Diff block n
  • each Extra block i.e. Extra block 1 or Extra block 2 or Extra block n
  • the entire file can be compressed, that is, Header, control block1, Diff block 1, Extra block 1, control block2, Diff block 2, Extra block 2,..., control block n, Diff block n, Extra block n are compressed together.
  • the entire file when compressing the Patch file with the data structure as shown in Figure 4, the entire file can be divided into x sub-files according to the preset size and then compressed. Assume that the entire file size is N, then the size of each sub-file is N/x.
  • the data block type when compressing the Patch file with the data structure shown in Figure 4, can be used to compress, that is, multiple control blocks (ie, control block1, control block2, ..., 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) for compression .
  • control blocks ie, control block1, control block2, ..., control block n
  • Diff blocks i.e. Diff block 1, Diff block 2,..., Diff block n
  • Extra blocks i.e. Extra block 1, Extra block 2,..., Extra block n
  • the server performs differential processing on each group of new firmware files and old firmware files to obtain multiple Patch files
  • the multiple Patch files are compressed and packaged to obtain the corresponding upgrade differential package for terminal query. And download the upgrade differential package.
  • patch file restoration is performed based on the bspatch principle in the BSDiff algorithm.
  • the bspatch principle can be understood as the reverse process of the bsdiff principle, that is, Patch file restoration can be understood as the reverse process of Patch file generation.
  • Figure 5 exemplarily shows the file restoration process based on the bspatch principle.
  • the terminal When the terminal obtains the Patch file, it parses the header of the Patch file. After knowing the file type according to the magic number recorded in the header, it can perform data decoding operations based on the data structure corresponding to the file type. Among them, every time the terminal decodes a piece of Diff data or Extra data, it restores the file based on the piece of Diff data or Extra data.
  • each control block is used to describe a pair of Diff blocks and Extra blocks.
  • the terminal can obtain the corresponding Diff data and Extra data based on the content recorded in the control block, and perform restoration processing based on the obtained Diff data and Extra data to obtain the data in the new file.
  • control block1 As shown in Figure 6, in the Patch file, the content filled in control block1 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.
  • the terminal parses the (x1, y1, z1) filled in control block1 in the Patch file. First, the terminal continues to read the Diff data of length x1 in the Patch file, and reads the data of length x1 in the old file, and adds the two pieces of data of length x1 to obtain the new file data of length x1, and writes into a new file (or target file). Then, the terminal continues to read the Extra data of length y1 in the Patch file, and directly writes it into the new file as the new file data of length y1.
  • control block0 may also be included, and control block0 is filled with (0, 0, z0).
  • control block0 is filled with z0, which is used to determine the pointer offset used to read x1 length data in the old file. Since the current position of the old file pointer is the starting position of the old file, after the old file pointer is offset by z0 from the starting position of the old file, the old file of x1 length matching the x1 length Diff data can be read in the old file.
  • File data is used to determine the pointer offset used to read x1 length data in the old file.
  • the terminal continues to parse the Patch file and reads (x2, y2, z2) filled in control block2.
  • the terminal continues to read x2 length Diff data in the Patch file, and reads x2 length data in the old file, and adds the two pieces of x2 length data to obtain new file data of x2 length, and writes into a new file.
  • the terminal continues to read the Extra data of length y2 in the Patch file, and directly writes it into the new file as the new file data of length y2.
  • the terminal can obtain a new file based on the Patch file and the old file, and complete the restoration process of a new file.
  • the terminal can restore each new file based on each Patch file in the upgrade difference package and the corresponding old files.
  • the Diff block and Extra block The byte length of is not fixed and unlimited. Its byte length is related to the difference between the old and new files. It can be tens of KB, or it can be as high as hundreds or even thousands of KB.
  • the amount of RAM memory space required is directly related to the byte length of the Diff block or Extra block.
  • the terminal's RAM memory space is limited, the terminal cannot or has difficulty meeting the demand for 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.
  • this embodiment provides a method for generating a differential file, and the method for generating a differential file is applied to the server side.
  • the server mentioned here can be understood as any electronic device used to generate differential files.
  • Figure 7 exemplarily shows the file difference process based on the Bsdiff principle provided in this embodiment.
  • the data 01_new in the new file data is "10101010101010101”
  • the data 01_old in the old file data is "1010101110101011101”
  • the data 01_new in the new file data and the data 01_old in the old file data are the longest similarity string.
  • the data 03_new in the new file data and the data 02_old in the old file data are another longest similar substring.
  • data 02_new is between data 01_new and data 03_new. If there is no substring similar to data 02_new in the old file data, data 02_new is newly added data in the new file.
  • data 04_new is also newly added data.
  • the difference data can be calculated based on the similar substrings in the new file data and the old file data, and the difference data and the newly added data (Extra data) together constitute incremental update data (Patch data).
  • 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.
  • the data 02_new in the new file can be directly used as the Extra01 data in the Patch data
  • the data 04_new in the new file can be directly used as the Extra02 data in the Patch data.
  • all Diff data and Extra data can be obtained based on the new file data and old file data to form Patch data.
  • Diff data and Extra data appear in pairs, and after each piece of Diff data is a piece of Extra data. Moreover, the position offset of each pair of Diff data and Extra data in the Patch data is consistent with the new file data.
  • the server side divides the Diff data and Extra data in the Patch data into data blocks according to the block size (zonesize).
  • Each Diff data block and Extra data block is the smallest independent processing data unit when the terminal restores the differential file.
  • zonesize can be determined based on the RAM memory space on the terminal side. Specifically, it can be determined based on the size of the continuous RAM memory space on the terminal side that can be used for differential file restoration. Zonesize can also be understood as the maximum number of processing bytes supported by the RAM memory space of the terminal when performing Diff data restoration processing.
  • the Diff data 01 in the Patch data is divided into n1 Diff data blocks according to zonesize.
  • the data size (or byte length) of the first (n1-1) Diff data blocks is zonesize, and the data size of the last Diff data block is less than or equal to zonesize.
  • the data sorting of these n1 Diff data blocks is the same as Diff data 01.
  • the Extra data 01 is also divided into n2 Extra data blocks according to zonesize.
  • the data size of the first (n2-1) Extra data blocks is zonesize, and the data size of the last Extra data block is less than or equal to zonesize.
  • the data sorting of these n2 Extra data blocks is also the same as Extra data 01.
  • the continuous RAM memory space used by the terminal device for differential file restoration can be divided into the first RAM. memory area, the second RAM memory area, the third RAM memory area and the fourth RAM memory area, where the first RAM memory area, the second RAM memory area and the third RAM memory area are jointly used for Diff data block restoration processing. Data storage operations, as well as data storage operations involved in Extra data block restoration processing, the fourth RAM memory area is used for data decompression operations.
  • the RAM memory space of the terminal device for differential file restoration is M
  • the memory space required by the data compression algorithm for data decompression operation is N1 (that is, the memory space of the fourth RAM memory area is N1)
  • the first RAM memory area, the second RAM memory area and the third RAM memory area can equally share the remaining RAM memory space, that is, the memory spaces of the first RAM memory area, the second RAM memory area and the third RAM memory area are all (M-N1) /3.
  • zonesize can be set to (M-N1)/3.
  • the RAM memory space is divided as follows: the first RAM memory area is 60KB, the second RAM memory area is 60KB, the third RAM memory area is 60KB, and the fourth RAM memory area is 20KB.
  • zonesize 60KB, which means that the terminal device can perform data restoration processing on 60KB of Diff data or Extra data at a time.
  • 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 third RAM memory area.
  • RAM memory area and fifth RAM memory area where the first RAM memory area and the third RAM memory area are jointly used for data storage operations involved in Diff data block restoration processing, and for data involved in Extra data block restoration processing
  • 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 is a safety buffer area of the first RAM memory area;
  • the fourth RAM memory area is located between the third RAM memory area and the fifth RAM memory area. Between them is the safety buffer area of the third RAM memory area.
  • the RAM memory space of the terminal device for differential file restoration is M
  • the memory space required by the data compression algorithm for data decompression operation is N1 (that is, the memory space of the fifth RAM memory area is N1)
  • the security buffer area requires The memory space is N2
  • the remaining space can be equally divided between the first RAM memory area and the third RAM memory area, that is, the memory spaces of the first RAM memory area and the third RAM memory area are both (M-N1-N2*2 )/2.
  • zonesize can be set to (M-N1-N2*2)/2.
  • zonesize 90KB, which means that the terminal device can perform data restoration processing on 90KB of Diff data or Extra data at a time.
  • the data size after data compression is larger than the data size before data compression, because the data size of Diff data block or Extra data block before compression is different from the first RAM memory area and the third RAM memory.
  • the size of the area is the same. Once the size of Diff data compression block or Extra data compression block becomes larger, It will overflow in the first RAM memory area or the third RAM memory area and affect normal data restoration processing. Therefore, setting a safe buffer area can effectively avoid the problem of abnormal data restoration caused by the increase in Diff data compression block size or Extra data compression block size overflowing the RAM memory area.
  • the RAM memory space can be divided into the first RAM memory area, the third RAM memory area and the fifth RAM memory area, where the first RAM memory area and the third RAM memory area are jointly used for data storage operations involved in Diff data block restoration processing, and for Extra data block Data storage operations involved in restoration processing, and the fifth RAM memory area is used for data decompression operations.
  • the RAM memory space of the terminal device for differential file restoration is M
  • the memory space required by the data compression algorithm for data decompression operation is N1 (that is, the memory space of the third RAM memory area is N1)
  • the first RAM memory The remaining space can be equally divided between the first RAM memory area and the second RAM memory area, that is, the memory spaces of the first RAM memory area and the second RAM memory area are both (M-N1)/2.
  • zonesize can be set to (M-N1)/2.
  • the RAM memory space is divided as follows: the first RAM memory area is 2KB, the second RAM memory area is 2KB, and the third RAM memory area is 16KB.
  • zonesize 2KB, which means that the terminal device can perform data restoration processing on 2KB of Diff data or Extra data at a time.
  • the security buffer area does not need to be set.
  • the divided and compressed Patch data can be data encoded to obtain the corresponding Patch file.
  • the data compression algorithm used to compress Diff data blocks or Extra data blocks uses 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 to reduce the RAM memory space occupied by the terminal device when restoring differential file data.
  • LZMA Lempel-Ziv-Markov chain-Algorithm
  • miniLZO Lempel-Ziv-Oberhumer
  • Figure 7 exemplarily shows the data structure of a Patch file.
  • the data structure includes a total encoding header, encoding information corresponding to multiple Diff data compression blocks and multiple Extra data compression blocks, and multiple Diff data compression chunking and multiple Extra data compression chunking.
  • the encoding information corresponding to multiple Diff data compression blocks and multiple Extra data compression blocks is used to describe the total byte length before multiple Diff data blocks are compressed, and the total byte length before multiple Extra data blocks are compressed.
  • the total encoding header can also include the zonesize field.
  • the value of the zonesize field is used to indicate the block size into which Diff data and Extra data are divided. It can be used by the terminal to combine it with the encoding information when restoring data. Perform data addressing. For example, the terminal can determine the offset of the old file pointer based on the value of the zonesize field, so as to read the old file data corresponding to each Diff data compression block in the old file. As another example, the terminal can be based on the value of the zonesize field and the total byte length before multiple Diff data blocks are compressed. Or the total byte length before multiple Extra data blocks are compressed, determining the number of Diff data blocks or the number of Extra data blocks.
  • the zonesize field is not included in the total encoding header, but the zonesize fields are set in each encoding information, which is not limited in this embodiment.
  • the number of Diff data compression chunks, the number of Extra data compression chunks, the byte length before and after each Diff data compression chunk is compressed, and the number of each Extra data compression chunk are set in each encoding information.
  • the length in bytes before and after the chunk is compressed.
  • this embodiment does not limit the description information (or coding information) of Diff data compression block and Extra data compression block, as long as the terminal side can implement the Patch file and the old data based on the corresponding description information. Perform data addressing in the file, and restore the target file based on each Diff data compression block and each Extra data compression block.
  • FIG 8 exemplarily shows the data structure of a Patch file provided by this embodiment.
  • the data structure of the Patch file includes header, control block (zone), Diff data and Extra data.
  • Header includes 16 bytes, used to fill the magic number and zonesize.
  • Each zone includes 24 bytes, used to describe multiple Diff data compression blocks and multiple Extra data compression blocks.
  • 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 be used as encoding information for multiple Diff data compression blocks and multiple Extra data compression blocks described by it.
  • the first 8 bytes of the zone can record the total byte length of the corresponding Diff data before multiple Diff data compression blocks are compressed, as well as the description information of 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 corresponding Extra data before multiple Extra data compression blocks are compressed, as well as the description information of each Extra data compression block (such as the byte length after compression);
  • zone The last 8 bytes are used to fill the pointer offset used to determine the location in the old file where the data is read (i.e. the data used for the addition with the Diff data chunk).
  • the pointer offset filled in the last 8 bytes of the zone may be an offset determined based on the current position of the pointer, and the offset direction is identified by the sign of the offset.
  • 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.
  • 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 blocks.
  • Extra data includes one or more Extra data compression blocks, and each Extra data compression block is used to record the compressed data of the Extra data block.
  • each Diff data compression block or Extra data compression block can be used as a data unit that can be processed independently when the terminal performs data restoration, thereby reducing the RAM memory consumption of the terminal during data restoration.
  • each Diff data block and Extra data block can also be compressed separately, and block encoding information can be added to each data compression block.
  • the block encoding information can be used as the block header of the data compression block, and the corresponding Diff compressed data or Extra compressed data can be used as the block data of the data compression block.
  • FIG. 9 exemplarily shows the data structure of a Patch file.
  • Diff data 01 in the Patch data it is divided into n1 Diff data blocks according to zonesize, and each Diff data block is compressed respectively to obtain the corresponding Diff data compression block.
  • each Diff data compression block is filled with encoding information describing the Diff data compression block.
  • the encoding information of the Diff data compression block may include, but is not limited to, the data size (csize) before compression of the Diff data block and the data size (usize) after compression.
  • each Extra data compression block is filled with encoding information describing the Extra data compression block.
  • the encoding information of the Extra data compression block may include, but is not limited to, the data size (csize) before the Extra data block compression and the data size (usize) after the compression.
  • encoding information 01 is used to describe Diff data 01 and Extra data 01, that is, it describes the total data size before compression of Diff data compression blocks 1-n1, and Extra data compression block 1-n2 The total data size before compression, and the pointer offset used to read the old file data corresponding to Diff data 02 in the old file.
  • Figure 10 exemplarily shows the data structure of a Patch file provided by this embodiment.
  • the data structure of the Patch file includes header, control block (zone), Diff data and Extra data.
  • Header includes 16 bytes, used to fill the magic number and zonesize.
  • Each zone includes 24 bytes, used to describe multiple Diff block compressed data and multiple Extra block compressed data.
  • the Diff data before multiple Diff block-compressed data are block-compressed
  • the Extra data before 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 multiple Diff block compressed data and multiple Extra block compressed data described by it.
  • the first 8 bytes of the zone can record the total byte length of the Diff data before multiple Diff block compressed data are compressed in blocks; the middle 8 bytes of the zone can record multiple Extra compressed data before being compressed in blocks.
  • the total byte length of the Extra data before the zone; the last 8 bytes of the zone are used to fill the pointer offset, which is used to determine the data to be read in the old file (used for adding in blocks with Diff data the location of the data being calculated).
  • 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 it describes is block-compressed; y is The total byte length of the Extra data before the multiple Extra compressed data described are block-compressed; z is the offset of the old file pointer, which is used to determine the first Diff segment described in the zone to which it is read from the old file.
  • the pointer position of the old file data corresponding to the block data.
  • the pointer offset can be an offset determined based on the current position of the pointer, and the offset direction is identified by the sign of the offset, or it can be an offset determined based on the starting position of the file. In this embodiment There is no restriction on this.
  • each zone can also be compressed separately.
  • the compressed zone is called Controls compression blocks.
  • the control compression block may include a block header and block data.
  • the block data is used to record compressed data corresponding to the zone content.
  • the block header is used to record compression description information corresponding to the control compression block.
  • the compression description information may include zone
  • the compressed data size (or the data size of the control compressed block), the compression description information may include but is not limited to the data size before zone compression (csize) and the data size after compression (csize).
  • Diff data includes one or more data compression blocks.
  • Each data compression block includes a block header and block data.
  • the block data is used to record the compressed data of the Diff data block
  • the block header is used to record Compression description information corresponding to the Diff data block compression data.
  • the compression description information may include but is not limited to the data size (csize) before the Diff data block compression and the data size (usize) after compression.
  • the compression description information may only include the data size (usize) after block compression of Diff data, that is, only include the data size of compressed blocks of Diff data.
  • Extra data includes one or more Extra data compression blocks.
  • Each Extra data compression block includes a block header and block data.
  • the block data is used to record the compressed data of the Extra data block.
  • the block header is For recording compression description information corresponding to the Extra data block compression data, the compression description information may include but is not limited to the data size (csize) before Extra data block compression and the data size (usize) after compression. Among them, the compression description information may only include the data size (usize) after Extra data block compression, that is, only include the data size of Extra data compression block.
  • each Diff data compression block or Extra data compression block can be used as a data unit that can be processed independently when the terminal performs data restoration, thereby reducing the RAM memory consumption of the terminal during data restoration.
  • the header in addition to filling the zonesize field, can also be filled with the data compression block maximum byte length (LengthMAX) field.
  • the value of this field is used to indicate each data The maximum data size of compressed blocks (including Diff data compressed blocks and Extra data compressed blocks).
  • the value of the LengthMAX field is used to indicate the maximum data size of each data compression block (including control compression block, Diff data compression block and Extra data compression block).
  • the terminal parses the patch file, it can determine whether the received patch file is incorrect based on the value of the LengthMAX field. For example, if the size of a certain Diff data compression block or Extra data compression block in the Patch file exceeds the value of the LengthMAX field, the terminal can determine that the Patch file is incorrect.
  • the Header can also fill in the total length of the target file data (NewfileLength) field.
  • the value of this field is used to indicate that the Patch file is based on the data structure. The total data length of the restored target file.
  • the terminal When the terminal restores the target file based on the Patch file, it 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 obtained by data restoration based on the Patch file is less than or greater than the value of the NewfileLength field, the terminal can determine that the target file obtained by the restoration is incorrect.
  • the data structure of the above-mentioned Patch file may also include a tail, and a check field may be filled in the tail.
  • the value of the check field is used to indicate that the data structure is based on the The hash value of the target file obtained by restoring the Patch file.
  • the terminal When the terminal restores the target file based on the patch file, it can also determine whether the restored target file is correct based on the value of the check field. For example, if the hash value of the target file obtained by data restoration based on the patch file is different from the value of the check field, the terminal can determine that the target file restored is incorrect.
  • corresponding Patch files can also be generated based on other pairs of old and new firmware files, thereby obtaining each Patch file corresponding to the differential upgrade package.
  • the server can package these Patch files to generate a corresponding differential upgrade package, and send the differential upgrade package to the terminal through the wireless network.
  • the Patch data obtained based on the BSDiff algorithm is re-encoded, and the Diff data and Extra data are compressed into blocks based on zonesize, so as to minimize data processing when restoring the Patch file.
  • the size of the unit is controllable. Among them, zonesize can be flexibly set according to the RAM memory space of lightweight embedded devices, which can be better suitable for firmware upgrade scenarios of lightweight embedded devices.
  • the applied RAM memory space may include a security buffer area
  • this embodiment also provides a method of dividing Diff data and Extra data into blocks based on zonesize.
  • Figure 11a exemplarily shows the file difference process based on the Bsdiff principle provided by this embodiment.
  • n1 Diff data blocks divide it into n1 Diff data blocks according to zonesize.
  • 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.
  • the data sorting of these n1 Diff data blocks is the same as Diff data 01.
  • the Extra data 01 in the Patch data is also divided into n2 Extra data blocks according to zonesize.
  • 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 zonesize.
  • the data sorting of these n2 Extra data blocks is also the same as Extra data 01.
  • the security buffer area refers to the security buffer area divided in the RAM memory space applied for when restoring differential files on the terminal side.
  • the division of the Diff data block can be adjusted. That is, the (n1+1)th Diff data block can be used to merge the n1th Diff data block and serve as the n1th Diff data block for final division.
  • the data size of the first (n1-1) Diff data block is zonesize, and the data size of the last Diff data block is greater than zonesize.
  • the division of the Diff data block is not adjusted.
  • the division of Diff data blocks can refer to Figure 7, no further details will be given.
  • Extra data 01 can be divided into (n2+1) Extra data blocks according to zonesize.
  • 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.
  • the data size of the (n2+1)th Extra data block is smaller than a preset ratio of the data size of the safe buffer area.
  • the data size of the (n2+1)th Extra data block is less than 50% of the data size of the safe buffer area.
  • the division of the Extra data block can be adjusted. That is, the (n2+1)th Extra data block can be used to merge the n2th Extra data block and serve as the n2th Extra data block for final division.
  • the data size of the first (n2-1) Extra data block is zonesize, and the data size of the last Extra data block is greater than zonesize.
  • the terminal can record the total byte length of the corresponding Diff data before multiple Diff data compression blocks are compressed based on the zone, the value of zonesize, and the data of the applied security buffer. Size, calculate whether there is a Diff data block with a byte length greater than zonesize, and the byte length of each Diff data block. Similarly, the terminal can calculate whether there is a byte length greater than the total byte length of the corresponding Extra data before multiple Extra data compression blocks are recorded in the zone, the value of zonesize, and the data size of the applied security buffer. Zonesize's Extra data blocks, and the byte length of each Extra data block.
  • a flag field can also be set in the header of the patch file.
  • the value of the flag field is used to indicate whether there is a data block with a byte length greater than zonesize (including Diff data block and Extra data chunking).
  • the terminal side When the terminal side performs data restoration operations based on the Patch file, it can determine whether there are data blocks with a byte length greater than zonesize (including Diff data blocks and Extra data blocks) by parsing the value of the flag field in the header of the Patch file. piece).
  • zonesize including Diff data blocks and Extra data blocks
  • this embodiment also provides a method for restoring a differential file, and the method for restoring a differential file is applied to the terminal side.
  • the terminal mentioned here can understand any electronic device that needs to restore the differential file, such as a smart phone, a smart watch, a smart bracelet, etc., and another example is any Internet of Things node device.
  • Figure 12 exemplarily shows the process of restoring target files based on Patch files provided by this embodiment.
  • the data structure of the Patch file includes a total encoding header, encoding information corresponding to multiple Diff data compression blocks and multiple Extra data compression blocks, as well as multiple Diff data compression blocks and multiple Extra data compression blocks. piece.
  • the encoding information corresponding to 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 be based on the encoding information. Perform data addressing.
  • the terminal When the terminal obtains the Patch file, it parses the header of the Patch file. After knowing 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 based on the data block size. Differential file restoration processing, and data decoding operations are performed based on the data structure corresponding to the file type.
  • the terminal decompresses a Diff data block or Extra data block, it restores the target file based on the Diff data block or Extra data block.
  • each piece of Diff data is followed by a piece of Extra data.
  • the sorting 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.
  • the terminal restores the target file based on the patch data, it performs the data restoration operation based on each Diff data block or Extra data block.
  • each zone is used to describe multiple Diff data compression blocks and multiple Extra data compression blocks. Therefore, the terminal can obtain each Diff data compression block and Extra data compression block according to the content recorded in the zone, perform a decompression operation, and perform restoration processing based on the decompressed Diff data block and Extra data block to obtain a new data in the file.
  • the terminal performs a data restoration operation based on each Diff data compression block (corresponding to Diff data 01) and Extra data compression block (corresponding to Extra data 01) described in the encoding information 01 as an example for explanation.
  • the terminal first decompresses Diff data 01 compressed block 1 to obtain Diff data 01 block 1.
  • the byte length of Diff data 01 block 1 is equal to zonesize.
  • the terminal performs data restoration operations based on Diff data 01 block 1, it reads the Diff data of Diff data 01 block 1, and reads the old file data (byte length) matching Diff data 01 block 1 in the old file.
  • Diff data 01 compressed block n1 is completed.
  • the byte length of the Diff data 01 block obtained by decompressing the Diff data 01 compressed block n1 is less than or equal to zonesize.
  • the terminal continues to decompress Extra data 01 compressed block 1, and obtains Extra data 01 block 1.
  • the byte length of Extra data 01 block 1 is equal to zonesize.
  • the terminal performs counting based on Extra data 01 block 1 During the data restore operation, read the Extra data of Extra data 01 block 1 and write these data directly into the new file.
  • the terminal continues to decompress Extra data 01 compressed block 2, and performs data restoration based on the decompressed Extra data 01 block 2 until the restoration process completes Extra data 01 compressed block n2.
  • the byte length of the Extra data 02 block obtained by decompressing the Extra data 01 compressed block n2 is less than or equal to zonesize.
  • the terminal has completed the target file restoration based on Diff data 01 and Extra data 01. The same is true for the terminal's operation of restoring target files based on other Diff data and Extra data.
  • the terminal can be based on each Diff data compression block and each Extra data compression block in the Patch file, as well as the data in the old file.
  • Related Data gets all the data in the new file.
  • z represents the pointer offset from the beginning of the 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, and Extra data 01 compressed block 1 and Extra data 01 compressed into chunks 2.
  • the total byte length of the Diff data obtained after decompressing Diff data 01 compressed block 1 and Diff data 01 compressed block 2 is x1
  • the byte length of Diff data 01 block 2 obtained after being decompressed is x1-m (x1-m ⁇ m); Extra data 01 is compressed
  • the total byte length of Extra data obtained after block 1 and Extra data 01 compressed block 2 are decompressed is y1.
  • the character length of Extra data 01 block 1 obtained after Extra data 01 compressed block 1 is decompressed is m.
  • the character length of Extra data 01 block 2 obtained after decompressing Extra data 01 compressed block 2 is y1-m (y1-m (
  • the terminal parses the (x1, y1, z1) filled in zone1 in the Patch file.
  • the terminal continues Diff data 01 compressed block 1 in the Patch file, decompresses Diff data 01 compressed block 1 to obtain m-length Diff data, and reads m-length data in the old file, and combines these two segments. Add m-length data to obtain m-length new file data and write it into the new file (or target file).
  • the terminal can read the m-length old file data corresponding to the m-length Diff data (Diff data 01 compression block 1) in the old file.
  • the terminal continues to read Diff data 01 compressed block 2 in the Patch file, decompresses Diff data 01 compressed block 2 to obtain (x1-m) length Diff data, and continues to read (x1- m) length data, and add the two pieces of (x1-m) length data to obtain new file data of (x1-m) length, and write it into the new file.
  • the terminal can read the m-length old file data corresponding to the m-length Diff data in the old file
  • the old file pointer continues to shift forward by m.
  • the terminal can continue to move forward in the old file based on the current position of the pointer. Read the (x1-m) length old data corresponding to the (x1-m) length Diff data from the file.
  • the terminal continues to read Extra data 01 compressed block 1 in the Patch file, decompresses Extra data 01 compressed block 1 to obtain m-length Extra data, and directly writes it into a 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 (y1-m) length Extra data, and directly writes it into a new file.
  • zone2 is used to describe Diff data 02 compressed block 1 and other Diff data 02 compressed block 2, as well as each Extra data 02 compressed block.
  • the terminal continues Diff data 02 compressed block 1 in the Patch file, decompresses Diff data 02 compressed block 1 to obtain m-length Diff data, and reads m-length data in the old file, and combines these two m-length Add the data to obtain new file data of length m, and continue writing it to the new file (or target file).
  • the terminal in order for the terminal to read the m-length old file data corresponding to the m-length Diff data (Diff data 02 compression block 1) in the old file, the old file needs to be re-determined based on the old file starting position and z2 pointer. That is, after the old file pointer is offset by z2 from the file starting position, the terminal can read the m-length old file data corresponding to the m-length Diff data (Diff data 01 compression block 1) in the old file.
  • the terminal continues to perform data restoration processing on the Diff data 02 compression block and Extra data 02 compression block described by zone2.
  • the terminal device 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.
  • the terminal device 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 with the same size as zonesize, and a RAM memory area for running the data compression algorithm (size and data compression algorithm).
  • the terminal device 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 with the same size as zonesize, and a RAM memory area for running the data compression algorithm (size and data compression algorithm).
  • N2 is the data size of the safe buffer area.
  • N2 is the data size of the safe buffer area.
  • the terminal when the terminal obtains the Patch file, it parses the header of the Patch file. After obtaining the value of the data block size (zonesize), it can apply for a continuous RAM memory space based on the zonesize value for differential data. Restore operation.
  • the RAM memory area is not reused, and the terminal applies for a continuous piece of RAM memory space for patch restoration operations.
  • the size of the RAM memory space is 3*zonesize+N1 (bytes), where N1 Bytes are 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, which are 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. Refer to Figure 14 and Figure 15 shown. Among them, the sizes of the first RAM memory area 201, the second RAM memory area 202, and the third RAM memory area 203 are equal, and are all zonesize (bytes).
  • the size of the fourth RAM memory area 204 is N1 bytes.
  • the data compression algorithm used to compress Diff data compression blocks or Extra data compression blocks may use LZMA.
  • 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 Diff data block restoration processing, including but not limited to storage of Diff data compression blocks, storage and decompression.
  • the final Diff data block is stored, and the new file data block (New data block) obtained after the addition operation is stored, as well as the data storage operations involved in the Extra data block restoration process, including but not limited to storing Extra data compression block , stores the decompressed Extra data blocks;
  • the fourth RAM memory area 204 is used for data decompression operations.
  • 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.
  • the terminal reads Diff data 01 compressed block 1 in the Patch file, and writes Diff data 01 compressed block 1 into the first RAM memory area 201.
  • the terminal calls the data compression algorithm to decompress the Diff data 01 compression 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 result is The data is written into the second RAM memory area 202.
  • the terminal reads the Old data 01 block 1 (byte length is zonesize) corresponding to the Diff data 01 block 1 from the running image file (equivalent to the old file that has not been upgraded), and temporarily stores it in the third RAM In the memory area 203, as shown at time T3.
  • the terminal reads Old data 01 block 1 in the third RAM memory area 203, and reads Diff data 01 block 1 in the second RAM memory area 202, and performs an addition operation.
  • the terminal can perform addition operations on the Diff data 01 block 1 and the Old data 01 block 1, so that the New data 01 block 1 obtained by the addition operation can be written in the second RAM memory area 202, and the second RAM The Diff data 01 temporarily stored in the memory area 202 is overwritten in block 1. Furthermore, at time T4, the terminal can read New data 01 in block 1 from the second RAM memory area 202 and write it into the static image file (or a newly created file). Among them, the static image file can be understood as the backup of the running image file.
  • the data temporarily stored in a certain RAM memory area can be overwritten or cleared, which is not limited in this embodiment.
  • the operation result can be directly written into the third RAM memory area 203.
  • a RAM memory area 201 overwrites the temporarily stored Diff data 01 compressed block 1.
  • the data temporarily stored in the first RAM memory area 201 can be cleared, and then in the third RAM memory area 203 Read the Old data 01 block 1, and read the Diff data 01 block 1 in the second RAM memory area 202.
  • the operation result can be directly written into the first RAM memory area 201.
  • the terminal has completed the data restoration operation based on Diff data 01 compression block 1.
  • the terminal can continue Continue the data restoration operation based on Diff data 01 compression block 2.
  • Diff data 01 compressed block 2 is the last compressed block of Diff data 01, then the 2-byte length of the Diff data 01 block obtained by decompressing it is less than or equal to zonesize.
  • the terminal When the terminal completes the data restoration operation based on each Diff data 01 compression block included in Diff data 01, it can continue to perform the data restoration operation based on each Extra data 01 compression block included in Extra data 01.
  • 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.
  • the terminal calls the data compression algorithm to decompress the Extra data 01 compression 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 result is The data is written into the second RAM memory area 202.
  • the decompression of Extra data 01 compressed block 1 is completed, and the Extra data 01 block 1 (byte length is zonesize) is temporarily stored in the second RAM memory area 202.
  • the terminal can read the Extra data 01 block 1 in the second RAM memory area 202 and continue writing it into the static image file. At this time, the data in the static image file is restored to New data 01 block 3.
  • the terminal has completed the data restoration operation based on Extra data 01 compression block 1.
  • the terminal can continue to perform data restoration operations based on Extra data 01 compression block 2.
  • Extra data 01 compressed block 2 is the last compressed block of Extra data 01
  • the length of the Extra data 01 block 2 obtained by decompressing it is less than or equal to zonesize.
  • the terminal applies for a continuous piece of RAM memory space for the patch restoration operation.
  • the size of the RAM memory space is 3*zonesize+3*N2+N1 (bytes). Among them, N2 bytes are the size of the RAM memory space occupied by the security buffer. This implementation will not be described again here.
  • the RAM memory area is reused, and the terminal applies for a continuous piece of RAM memory space for patch restoration operations.
  • the size of the RAM memory space is 2*zonesize+2*N2+N1 (bytes) , N1 bytes are the size of the RAM memory space required to run the data compression algorithm, and N2 bytes are 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, which are 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 is shown in FIG. 16 and FIG. 17 .
  • the sizes of the first RAM memory area 301 and the third RAM memory area 303 are equal, and both are zonesize (bytes); the size of the fifth RAM memory area 305 is N1 bytes; the second RAM memory area 302 is located at The safety buffer area of the first RAM memory area 301 is between the first RAM memory area 301 and the third RAM memory area 303.
  • the fourth RAM memory area 304 is located between the third RAM memory area 303 and the fifth RAM memory area 305. , 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 in size, both being N2 bytes.
  • the data compression algorithm used to compress Diff data compression blocks or Extra data compression blocks may use LZMA.
  • zonesize 90KB
  • N2 2KB
  • the first RAM memory area 301 and the third RAM memory area 303 are jointly used for data storage operations involved in Diff data block restoration processing, including but not limited to storing Diff data compression blocks and storing decompressed Diff data blocks.
  • Blocking; the fifth RAM memory area 304 is used for data decompression operations.
  • 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.
  • the terminal reads Diff data 01 compressed block 1 in the Patch file, and writes Diff data 01 compressed block 1 into the first RAM memory area 301.
  • the terminal calls the data compression algorithm to decompress the Diff data 01 compression 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 result is The data is written into the third RAM memory area 303.
  • Diff data 01 block 1 (byte length is zonesize).
  • the terminal reads the Old data 01 block 1 (byte length is zonesize) corresponding to the Diff data 01 block 1 from the running image file (equivalent to the old file that has not been upgraded), and temporarily stores it in the first RAM In the memory area 301, Diff data 01 is compressed into block 1 and overwritten, as shown at time T3.
  • the terminal reads Old data 01 block 1 in the first RAM memory area 301, and reads Diff data 01 block 1 in the third RAM memory area 303, and performs addition operations.
  • the terminal can perform addition operations on the Diff data 01 block 1 and the Old data 01 block 1, so that the New data 01 block 1 obtained by the addition operation can be written in the third RAM memory area 303, and the third RAM The Diff data 01 temporarily stored in the memory area 303 is overwritten in block 1. Furthermore, at time T4, the terminal can read New data 01 in block 1 from the third RAM memory area 303 and write it into the static image file.
  • the New data 01 block 1 obtained by the addition operation can also be written in the first RAM memory area 301, and the Old data 01 block 1 temporarily stored in the first RAM memory area 301 can be overwritten. Furthermore, the terminal can read the New data 01 in the first RAM memory area 301 and write the block 1 into the static image file.
  • the terminal has completed the data restoration operation based on Diff data 01 compression block 1.
  • the terminal can continue to perform data restoration operations based on Diff data 01 compression block 2.
  • Diff data 01 compressed block 2 is the last compressed block of Diff data 01, then the 2-byte length of the Diff data 01 block obtained by decompressing it is less than or equal to zonesize.
  • the terminal When the terminal completes the data restoration operation based on each Diff data 01 compression block included in Diff data 01, it can continue to perform the data restoration operation based on each Extra data 01 compression block included in Extra data 01.
  • 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.
  • the terminal calls the data compression algorithm to decompress the Extra data 01 compression 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 decompression result is The data is written into the third RAM memory area 303.
  • the decompression of Extra data 01 compressed block 1 is completed, and the Extra data 01 block 1 (byte length is zonesize) is temporarily stored in the third RAM memory area 303.
  • the terminal can read the Extra data 01 block 1 in the third RAM memory area 303 and continue writing it into the static image file. At this time, the data in the static image file is restored to New data 01 block 3.
  • the terminal has completed the data restoration operation based on Extra data 01 compression block 1.
  • the terminal can continue to perform data restoration operations based on Extra data 01 compression block 2.
  • Extra data 01 compressed block 2 is the last compressed block of Extra data 01
  • the length of the Extra data 01 block 2 obtained by decompressing it is less than or equal to zonesize.
  • the terminal applies for the second RAM memory area 302 as a safety buffer area of the first RAM memory area 301 to avoid the problem of data overflow in the first RAM memory area 301 causing data processing errors.
  • the terminal applies for the fourth RAM memory area 304 as a safety buffer for the third RAM memory area 303 to avoid the problem of data overflow in the third RAM memory area 303 causing data processing errors.
  • the data compression block will be temporarily stored in the first RAM memory. area or the third RAM memory area, it will cause the data to overflow into the second RAM memory area or the fourth RAM memory area accordingly.
  • the terminal device decompresses the compressed data blocks, it needs to decompress the data that overflows into the second RAM memory area or the fourth RAM memory area to ensure that the decompressed Diff data is divided into two parts. Correctness of Chunk or Extra data chunking.
  • the reuse of the RAM memory area can improve the efficiency of data restoration processing.
  • the terminal may not divide the applied RAM memory space into the second RAM memory area 302 and the fourth RAM memory area 304 as the safety buffer.
  • the terminal does not divide the second RAM memory area 302 and the fourth RAM memory area 304 as safety buffers in the applied RAM memory space, the terminal performs data restoration based on Diff data compression block and Extra data compression block.
  • the RAM memory usage is also similar and will not be repeated here.
  • the data compression algorithm used to compress Diff data compression blocks or Extra data compression blocks may use LZMA.
  • the terminal when the terminal performs data restoration operations based on Diff data compression block or Extra data compression block, the decompression operation and data storage operation are performed in the designated RAM memory area, fully and effectively utilizing the RAM memory space, and the differential restore operation consumes
  • the RAM memory is small, so that lightweight devices with small RAM space can also have differential restoration capabilities.
  • the RAM memory space applied for the Patch restoration operation includes a security buffer.
  • the data size of the security buffer is N2 bytes.
  • the RAM memory space applied for by the terminal may be continuous, as shown in Figure 16.
  • the RAM memory space applied by the terminal can also be non-continuous.
  • it applies for three RAM memory areas with a size of (zonesize+N2), and a RAM memory area for running the data compression algorithm (size and data compression). algorithm related). This embodiment does not limit this.
  • the operation can be based on the total byte length of the corresponding Diff data before multiple Diff data compression blocks are recorded in the zone, the value of zonesize, and the data size of the applied security buffer, and calculate whether there is a byte length greater than zonesize.
  • Diff data is divided into chunks.
  • the terminal's data restoration process based on multiple Diff data compression blocks can be found in the previous section and will not be described again here.
  • the terminal reads the compressed block n1 of Diff data 01 in the Patch file, and writes the compressed block n1 of Diff data 01 into the first RAM memory area 301.
  • the terminal calls the data compression algorithm to decompress the Diff data 01 compression 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 decompression result is The data is written into the third RAM memory area 303.
  • the decompression of the compressed block n1 of Diff data 01 is completed, and the decompressed block n1 of Diff data 01 is temporarily stored in the third RAM memory area 303.
  • Diff data 01 block n1 Since the byte length of Diff data 01 block n1 before being compressed is greater than zonesize, Diff data 01 block n1 not only fills up the third RAM memory area 303, but also writes part of the data into the fourth RAM memory area 304.
  • the terminal reads the Old data 01 block n1 (the byte length is greater than zonesize) corresponding to the Diff data 01 block n1 from the running image file (equivalent to the old file that has not been upgraded), and temporarily stores it in the first RAM in memory area 301.
  • Old data 01 block n1 will not only fill the first RAM memory area 301, but also part of the data will be written into the second RAM memory area 302, as shown at 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 in the third RAM memory area 303 and the fourth RAM memory area 304.
  • 01 is divided into blocks n1, and the addition operation is performed.
  • the terminal can perform addition operations 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 in the third RAM memory area 303 and the fourth RAM memory area. 304 in.
  • the terminal can read the New data 01 block n1 in the third RAM memory area 303 and the fourth RAM memory area 304 and write it into the static image file.
  • 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.
  • the terminal calls the data compression algorithm to decompress the Extra data 01 compression 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 decompression result is The data is written into the third RAM memory area 303.
  • 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.
  • Extra data 01 block n2 Since the byte length of Extra data 01 block n2 before being compressed is greater than zonesize, Extra data 01 block n2 not only fills the third RAM memory area 303, but also writes part of the data into the fourth RAM memory area 304. Furthermore, at time T6, the terminal can read Extra data in the third RAM memory area 303 and the fourth RAM memory area 304. 01 block n2 continues to be written into the static image file. At this time, the data in the static image file is restored to New data 01 block n2.
  • the terminal parses the value of the flag field in the header of the patch file and determines that there is a data block (including Diff data block and Extra data block) with a byte length greater than zonesize, it can be based on The data restoration process is performed as shown in the processing flow shown in Figures 17 and 18.
  • the terminal can also complete the corresponding data restoration operation with the help of the security buffer.
  • the data compression block maximum byte length (LengthMAX) field can also be filled.
  • the value of this field is used to indicate each data compression block ( The maximum data size including Diff data compression chunking and Extra data compression chunking).
  • the terminal when the terminal parses the Patch file, it can determine whether the received Patch file is incorrect based on the value of the LengthMAX field. For example, if the size of a certain Diff data compression block or Extra data compression block in the Patch file exceeds the value of the LengthMAX field, the terminal can determine that the Patch file is incorrect and no longer perform data restoration operations based on the Patch file.
  • the total length of the target file data (NewfileLength) field can also be filled. The value of this field is used to indicate the target restored based on the Patch file. The total data length of the file.
  • the terminal when the terminal restores the target file based on the Patch file, it 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 obtained by data restoration based on the Patch file is less than or greater than the value of the NewfileLength field, the terminal can determine that the restored target file is incorrect and no longer perform firmware upgrades based on the target file.
  • the data structure of the Patch file may also include a check field, the value of which is used to indicate the hash value of the target file restored based on the Patch file.
  • the terminal When the terminal restores the target file based on the patch file, it can also determine whether the restored target file is correct based on the value of the check field. For example, if the hash value of the target file obtained by data restoration based on the patch file is different from the value of the check field, the terminal can determine that the restored target file is incorrect and no longer perform firmware upgrades based on the target file.
  • the patch data is split into differential reduction unit data with controllable size, and the 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 reduction unit data at a time. , thus enabling lightweight devices with limited RAM space to have differential restoration capabilities.
  • the above explanation takes a set of image files (including running image files and static running files) as an example.
  • other static image files can also be filled with data based on other Patch files, thereby obtaining and upgrading All image files corresponding to the package.
  • the terminal can perform firmware upgrades based on these image files.
  • firmware upgrade based on these image files reference can be made to the existing technology and will not be described again here.
  • the Diff data server is generated based on subtraction operation as an example for explanation.
  • the terminal restores Diff data based on addition operations as an example for explanation.
  • Diff data can also be server-based For the data generated by other operations, let's call it Diff data, which is generated by the server based on the first operation.
  • the terminal can restore the Diff data based on the second operation, and the second operation is the inverse operation of the first operation. This embodiment does not limit the first operation and the second operation.
  • a firmware file is taken as an example for explanation.
  • the method of generating differential files and the method of restoring differential files provided in this embodiment can also be applied to differential restoration processing of other file types, such as patch files, APK (Android application package, Android application package), etc.
  • the differential file restoration method provided by the embodiments of the present application is not only suitable for lightweight electronic devices with small RAM memory space (for example, less than the first preset threshold), but is also suitable for RAM memory that can be used for differential file restoration. Other electronic devices with smaller space (for example, smaller than the second preset threshold).
  • the electronic device can execute the differential file restoration method provided in this embodiment to use the smaller RAM memory space to realize the restoration function of differential files.
  • Figure 20 illustrates an application scenario.
  • a dialog box 700 pops up on the interface.
  • the content in the dialog box 700 shows "The xx patch is currently detected. Do you want to download and update it immediately?" If the user agrees, he can click "Yes" option 701.
  • the dialog box disappears, as shown in (2) in Figure 20, and the user continues to use the mobile phone to play games.
  • the mobile phone background downloads the xx patch, performs differential file restoration based on the downloaded xx patch, and performs hot updates based on the restored patch file.
  • the RAM memory space of the mobile phone is not small, the RAM memory space allocated by the mobile phone for differential file restoration operations is limited so as not to affect the user's experience of using the mobile phone.
  • the mobile phone executes the differential file restoration method provided by the embodiment of the present application, the differential data restoration function can be realized through a smaller RAM memory space, and at the same time, the user experience will not be affected.
  • the APK differential package download and differential restoration operations may be performed in the background of the mobile phone.
  • the RAM memory space of mobile phones is large, in order not to affect the user experience, the RAM memory space allocated by mobile phones for differential file restoration operations is usually smaller.
  • the mobile phone executes the differential file restoration method provided by the embodiment of the present application, the differential data restoration function can be realized through a smaller RAM memory space, and at the same time, the user experience will not be affected.
  • embodiments of the present application also provide a method for restoring differential files.
  • the terminal device can adaptively restore the differential file according to the RAM memory space used for differential file restoration, so as to improve the restoration efficiency of the differential file.
  • each compression block (including Diff data compression block and Extra data compression block) in the Patch file is processed serially.
  • the compressed block restoration process can be executed in parallel to improve 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.
  • the terminal device can be 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. , to realize the restoration processing of a compressed block (Diff data compressed block or Extra data compressed block).
  • a compressed block Diff data compressed block or Extra data compressed block.
  • the size of the first RAM memory area 301 and the third RAM memory area 303 are equal, and both are zonesize (bytes); the size of the fifth RAM memory area 305 is N1 bytes, which is used for data decompression operations; the second The RAM memory area 302 is the security buffer area of the first RAM memory area 301, and the fourth RAM memory area 304 is the security buffer area of the third RAM memory area 304, both of which are N2 bytes.
  • a set of RAM spaces ie, 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 multiple compressed block restoration processes can be achieved to improve the restoration efficiency of differential files.
  • the first group of RAM space is used for the first restoration thread to perform restoration processing of compressed blocks (Diff data compression block or Extra data compression block), and the second group of RAM space is used for the second restoration thread to perform restoration processing.
  • the first restore thread and the second restore thread are parallel. In this way, when the terminal device can provide multiple sets of RAM space, the terminal device can restore Diff data compression blocks or Extra data compression blocks through multiple restore threads in parallel.
  • the RAM space used by the terminal device for differential file restoration processing is a static array, and a set of RAM spaces corresponding to each restoration thread can be divided in the static array, so that each restoration thread The thread restores the compressed blocks (Diff data compressed blocks or Extra data compressed blocks) based on a corresponding set of RAM spaces.
  • each group 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) are divided sequentially in the static array. and a fifth RAM memory area 305, wherein a group of RAM spaces corresponds to one restore thread.
  • the first RAM part, the second RAM part and the fifth RAM memory area 305 are sequentially divided in the static array.
  • a plurality of pairs of first RAM memory areas 301 and second RAM memory areas 302 are divided in sequence; in the second RAM part, a plurality of pairs of third RAM memory areas 303 and fourth RAM memory areas 304 are divided in sequence.
  • a pair of first RAM memory area 301 and second RAM memory area 302, and a pair of third RAM memory area 303 and fourth RAM memory area 304 correspond to a restore thread.
  • each restoration thread corresponds to a group 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) are sufficient, and parallelization of compressed block restoration can be achieved.
  • 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 the incremental update data described by a control block (zone).
  • a set of incremental update data includes Diff data blocks and Extra data blocks, and the number of Diff data blocks and Extra data blocks is one or more.
  • a set of incremental update data only includes Diff data blocks or Extra data blocks.
  • the terminal device creates a parallel first restore thread and a second restore thread for restoring patch data.
  • the first restore thread is used to restore the compressed blocks described by zone1
  • the second restore thread is used to restore the compressed blocks described by zone2
  • the first restore thread is used to restore the compressed blocks described by zone3.
  • the compressed block is restored
  • the second restore thread is used to restore the compressed block described by zone4, and so on.
  • the terminal device can restore patch data based on two parallel restoration threads, improving the efficiency of patch data restoration.
  • each restoration thread restores the compressed blocks described by a certain zone, it restores each Diff data block and Extra data block described by the zone in sequence.
  • the restoration thread restores the compressed blocks described by a certain zone, it restores each Diff data block and Extra data block described by the zone in sequence.
  • FIG 23 exemplarily shows the data structure of a Patch file provided by this embodiment.
  • the data structure of the Patch file includes header, control block (zone), Diff data and Extra data.
  • the description of Diff data and Extra data can be referred to the previous article, which is the same as the data structure of the Patch file shown in Figure 8.
  • the header also includes the total number of control blocks (zones).
  • each zone not only includes the first pointer offset used to read data in the old file Amount, also includes the offset of the second pointer at which the data is written in the new file.
  • the first pointer offset is a pointer offset determined based on the starting position of the old file
  • the second pointer offset is a pointer offset determined based on the starting position of the new file.
  • each zone also needs to include the sum of the byte lengths after compression of multiple Diff data blocks and multiple Extra data blocks described by the zone. For example, it can be the total byte length after compression of multiple Diff data blocks. And the total length in bytes after multiple Extra data blocks are compressed.
  • the first pointer offset is used to read the old data corresponding to the first Diff data block described by the zone in the old file, that is, reading the old data corresponding to the first Diff data block described by the zone in the old file.
  • the first Diff data chunk is added to the old data.
  • the second pointer offset is used to determine the first address where the restored data corresponding to the zone is written in the new file. In this way, when multiple restoration threads process the data blocks described by each zone in parallel, the first address of writing the restoration data corresponding to the zone in the new file can be determined based on the second pointer offset in each zone.
  • the total byte length after multiple Diff data blocks are compressed and the total byte length after multiple Extra data blocks are compressed described by a zone can be used by the restoration thread to calculate the next zone in the Patch file. address offset in . That is, the total length of bytes can be used to skip each data compression block described by the zone when the restoration thread reads data in the Patch file, so as to read the data filled in the next zone. That is to say, the restoration thread can read the data described by the zone that needs to be processed based on the total length of bytes compressed in multiple Diff data blocks described by each zone and the total length of bytes compressed in multiple Extra data blocks. Compression chunking.
  • a restore thread needs to process the restore operation of each data compression block described by zone2, it can read the total length of bytes and multiple Extras of the multiple Diff data blocks described by it in zone1.
  • the total byte length after data block compression determines the total byte length of the Diff data compression block and Extra data compression block described by zone1, and then skips these Diff data compression blocks when reading data in the Patch file. and Extra data compression block, and then the data filled in zone2 can be read.
  • the restore thread needs to process the restore operation of each data compression block described by zone4 the same is true, which will not be described again here.
  • each zone includes 32 bytes, which are used to describe multiple Diff data compression blocks and multiple Extra data compression blocks.
  • 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 be used as encoding information for multiple Diff data compression blocks and multiple Extra data compression blocks described by it.
  • the first 8 bytes of the zone can record the total byte length of the corresponding Diff data before and after multiple Diff data compression blocks are compressed, 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 corresponding Extra data before and after multiple Extra data compression blocks are compressed, as well as the description information of each Extra data compression block (such as the byte length after compression);
  • zone The third 8 bytes are used to fill the first pointer offset, which is used to determine the location in the old file to read the data (i.e. the data used to add the Diff data chunks) ;
  • the fourth 8 bytes of the zone are used to fill the second pointer offset, which is used to determine the location where the data (that is, the data resulting from the restore operation) is written in the new file.
  • each zone includes 32 bytes, which are used to describe multiple Diff data compression blocks and multiple Extra data compression blocks.
  • the first 8 bytes of the zone can record the total byte length of the corresponding Diff data before and after multiple Diff data compression blocks are compressed; the second 8 bytes of the zone can record the compression of multiple Extra data compression blocks.
  • This zone structure can also be applied to the data structure of the Patch file as shown in Figure 10, or can also be applied to other data structures of the Patch file provided by the embodiment of the present application, so that multiple restoration threads can process each zone description in parallel.
  • the first address for writing the restored data corresponding to the zone in the new file can be determined based on the second pointer offset in each zone.
  • this embodiment does not limit the order in which the first pointer offset and the second pointer offset are filled in the zone.
  • the restoration thread can 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.
  • each zone can also be filled with the zone number, so that each restoration thread can determine whether each data compression block described by the zone needs to be restored based on the read zone number.
  • zone number starts counting from 1.
  • Data compression chunking is processed by restore thread k.
  • % represents the remainder operation.
  • zone number starts counting from 0.
  • the zone number corresponding to each restore thread can be determined.
  • the zone number corresponding to a certain restoration thread means that each data compression block described by the zone needs to be processed by the restoration thread.
  • a restore operation execution linked list can be created for the k parallel restore threads based on the remainder of the number of restore threads based on the zone number.
  • 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 zone in the Patch file can refer to the address offset relative to the starting position of the file. It should be pointed out 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.
  • the address offset of zone2 relative to the start of the file is the cumulative sum of the address offset of zone1 relative to the start of the file and the total byte length of the data compression block described by zone1, and zone3 is relative to the start of the file.
  • the address offset of the location is the cumulative sum of the address offset of zone2 relative to the starting position of the file and the total length in bytes of the data compression block described by zone2, and so on.
  • each restore thread can execute the data of each node in the linked list based on the corresponding restore operation, read the corresponding zone in the Patch file, and perform data restoration processing on the data compression blocks described by the zone.
  • the embodiment of the present application provides a method for restoring differential files.
  • the process of the differential file restoration method specifically includes:
  • the electronic device parses the Patch file and obtains the block size zonesize and the total number of control blocks x.
  • the block size zonesize and the total number of control blocks (zones) x can be carried in the header of the Patch file.
  • the electronic device After the electronic device obtains the Patch file, it parses the header of the Patch file. After knowing the file type according to the magic number recorded in the header, it can read the zonesize and the total number of control blocks x in the header.
  • S502 The electronic device determines whether the electronic device supports the restoration process of the differential file based on the RAM space size M and zonesize used for differential restoration. If so, S503 is executed. If so, error reporting is performed.
  • the electronic device can calculate the minimum RAM space required for the restore operation of 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 restore operation, the electronic device can determine that it cannot Supports restoration of differential files and error reporting.
  • the electronic device can determine that it can support the restoration processing of the differential file.
  • the minimum RAM space required to restore Patch files is (zonesize+N2)*2+N1.
  • N1 is the size of the RAM memory space required to run the data compression algorithm
  • the electronic device can determine that it can support the restoration process of the differential file.
  • the RAM space used for differential restoration by the electronic devices 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 with a size of (zonesize+N2) and a RAM memory area with a size of N1.
  • the electronic device is capable of differential file restoration processing.
  • S503 The electronic device determines the parallel number k of restoration threads based on M and zonesize.
  • 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.
  • the parallel number of restoration threads k [(M-N1)/(zonesize+N2)]. Among them, [] represents the rounding operation. If the parallel number k ⁇ 2, the electronic device can restore the data compression blocks in the Patch file in parallel through k restore threads.
  • the electronic device can dynamically apply for RAM space. If it can apply for a 2k (k ⁇ 2) RAM memory area with a block size of (zonesize+N2), and With a RAM memory area of size N1, the electronic device can restore the data compression blocks in the Patch file in parallel through k restoration threads.
  • S504 The electronic device determines whether k is greater than or equal to 2. If not, S505 is executed. If yes, S506 is executed.
  • S505 The electronic device performs restoration processing of the differential file through a single thread.
  • S506 The electronic device creates k restoration threads.
  • the electronic device creates a corresponding number of restoration threads based on the determined parallel number k to implement parallel restoration processing of data compression blocks described in different zones in the Patch file.
  • S507 The electronic device divides a set 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 of control blocks x.
  • the electronic device creates a first restoration thread and a second restoration thread for parallel restoration processing of data compression blocks described in different zones in the Patch file.
  • the electronic device For each restoration thread, the electronic device needs to divide it into a corresponding set of RAM spaces, 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. It can be Refer to Figure 21a or Figure 21b.
  • the electronic device For each restore thread, the electronic device also needs to create a corresponding restore operation linked list.
  • the zone number corresponding to each restoration thread can be determined based on the remainder of the zone number and the number of restoration threads k.
  • 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.
  • the restore operation linked list the data part of each node is filled with the zone number and the address offset of the zone corresponding to the number in the Patch file.
  • the corresponding zone numbers are zone1, zone3, zone5, etc.
  • the data part of the first node is filled with zone1 and
  • the address offset of zone1 in the Patch file is 1.
  • the link (next) part is filled with the pointer of the second node; the data part of the second node is filled with zone3 and the address offset of zone3 in the Patch file.
  • Amount 3 the link (next) part is filled with the pointer of the third node; the data (data) part of the third node is filled with zone5 and the address offset 5 of zone5 in the Patch file, the link (next) part is filled with is the pointer of the fourth node, and so on.
  • 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 list, and uses a corresponding set of RAM space to compress these data blocks. Restore operation.
  • the restore thread sequentially restores each data compression block (including Diff data compression block and/or Extra data compression block) described by the zone corresponding to the node.
  • the restoration thread uses a corresponding set of RAM space to perform restoration processing on each Diff data compression block or Extra data compression block. You can refer to the previous article and will not go into details here.
  • the first restoration thread uses the first group of RAM space to sequentially process each data compression block described by zone1, zone3, zone5, etc.
  • the second restoration thread uses the second group of RAM space to sequentially process the data compression blocks described by zone2, zone4, zone6, etc. Each data is compressed into chunks.
  • zone1 describes 3 Diff data compression blocks and 4 Extra data compression blocks
  • the first restoration thread uses the first group of RAM space to process the 3 Diff data compression blocks and 4 Extra data compression blocks in sequence. After that, continue to process each data compression block described by zone3, and so on.
  • the first address of the restored new data written into the new file is the position corresponding to the second pointer offset in zone1.
  • zone2 describes 5 Diff data compression blocks and 2 Extra data compression blocks. Then the second restoration thread uses the second group of RAM space to process the 5 Diff data compression blocks and 2 Extra data compression blocks in sequence. After the block, continue to process each data compression block described by zone4, and so on.
  • the first address of the restored new data written into the new file is the position corresponding to the second pointer offset in zone2.
  • each restore thread restores the data compression block described by a zone, it will restore
  • the first address of the new data written into the new file is the position corresponding to the offset of the second pointer in the zone.
  • each restore thread Since the number of data compression blocks described by each zone is different, the length of time each restore thread performs the data restore operation is also not the same. After each restore thread completes the corresponding data compression block restore operation according to the restore operation list, all data compression blocks in the Patch file are restored.
  • the electronic device can determine whether the restored target file is correct based on the value of the check field in the Patch file. For example, assuming that the hash value of the target file obtained by data restoration based on the patch file is the same as the value of the check field, the terminal can determine that the restored target file is correct; otherwise, it can determine that the restored target file is incorrect.
  • any restoration thread can be roughly divided into the following stages when restoring Diff data blocks: the stage of reading Diff data compression blocks in the Patch file (referred to as the first stage), The stage of data compression and decompression in blocks (referred to as the second stage), the stage of reading data corresponding to Diff data compression blocks in the old file (referred to as the fourth stage), and the stage of synthesizing new data based on the old data and Diff data blocks. stage (referred to as the fourth stage), and the stage of writing data in a new file (referred to as the fifth stage).
  • any restoration thread uses its corresponding set of RAM spaces (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 compression of each Diff data. Blocked restore operations.
  • the available status of the first RAM memory area and the third RAM memory area in the above stages will be analyzed.
  • the restoration thread compresses and blocks the Diff data read in 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.
  • the restoration thread decompresses the Diff data compression blocks in the first RAM memory area, and writes the decompressed Diff data blocks into the third RAM memory area, and the state of the third RAM memory area Change from 0 to 1, and at the same time change the state of the first RAM memory area from 1 to 0.
  • the restore 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 (that is, the old file), and writes it into the first RAM memory area (overwriting Diff data compression block), the state of the first RAM memory area changes from 0 to 1.
  • the restore thread reads the old data in the first RAM memory area and the Diff data in the third RAM memory area to synthesize new target data, and writes the synthesized target data into the third RAM memory area.
  • the restoration thread will change the state of the third RAM memory area from 1 to 0, and apply to hold the object lock corresponding to the third RAM memory area to achieve data protection in the third RAM memory area.
  • the restoration thread 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 .
  • the restore thread writes the new data synthesized in the third RAM memory area into a new file, which is Disk to the target static partition, and change the state of the third RAM memory area from 1 to 0 after the execution is completed.
  • the restoration thread writes the new data synthesized in the third RAM memory area into a new file in the fifth stage.
  • 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.
  • any restore thread can be roughly divided into the following stages when restoring Extra data blocks: the stage of reading Extra data compression blocks in the Patch file (referred to as the first stage) , the stage of decompressing Extra data compression blocks (referred to as the second stage), and the stage of writing data in a new file (referred to as the fifth stage).
  • any restoration thread uses its corresponding set of RAM spaces (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 compression of each Extra data. Blocked restore operations.
  • the restoration thread compresses the Extra data read in 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.
  • the restoration thread decompresses the Extra data compression blocks in the first RAM memory area, and writes the decompressed Extra data blocks into the third RAM memory area, and the state of the third RAM memory area Change from 0 to 1, and at the same time change the state of the first RAM memory area from 1 to 0.
  • the restore thread writes the new data synthesized in the third RAM memory area into a new file, that is, it is dropped to the target static partition, and after the execution is completed, the state of the third RAM memory area is changed from 1 to 0. .
  • the restoration thread writes the new data synthesized in the third RAM memory area into a new file in the fifth stage.
  • the restoration thread continues to process the next Extra data compression block, and the processing process also involves the above-mentioned first phase.
  • the restoration thread continuously processes two data compression blocks (whether Diff data compression block or Extra data compression block)
  • the restoration processing flow of the two data compression blocks before and after involves the first stage and the fifth stage.
  • the first stage of the restoration process of the next data compression block starts, which causes a waiting delay in the first RAM memory area, which affects certain programs. Improves the processing efficiency of the restore thread.
  • each restoration thread when it restores each data compression block described by a zone, it can be completed based on two sub-threads.
  • Figure 25 shows a differential file restoration method provided by an embodiment of the present application. As shown in Figure 25, one also The original thread describes the process of restoring each data compression block for a zone, which may include the following steps:
  • the restoration thread determines the number Diffnum of Diff data compression blocks described by the zone and the number Extranum of Extra data compression blocks, and sets Diff-zone-offset and Extra-zone-offset to 0.
  • Diff-zone-offset and Extra-zone-offset are global variables.
  • 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 in the current zone;
  • Extra-zone-offset is used to represent each Extra data compression block described in the current zone. In the block, the sequence number of the currently processed Extra data compression block.
  • the initial values of Diff-zone-offset and Extra-zone-offset are set to 0, and the serial numbers of Diff data compression blocks and Extra data compression blocks described by zone start counting from 1. For example, when Diff-zone-offset is 1, it indicates that the currently processed Diff data compression block is the Diff data compression block with sequence number 1; when Extra-zone-offset is 2, it indicates that the currently processed Extra data compression block is The chunk is the Extra data compression chunk with sequence number 2.
  • Diffnum the number of Diff data compression blocks described by a zone
  • Extranum the number of Extra data compression blocks
  • the restoration thread creates and starts the first sub-thread and the second sub-thread, and restores each data compression block described by the zone through the parallel first sub-thread and the second sub-thread.
  • the first sub-thread is used to restore Diff data compression blocks or Extra data compression blocks
  • the second sub-thread is also used to restore Diff data compression blocks or Extra data compression blocks.
  • the first sub-thread is also used to restore Diff data compression blocks or Extra data compression blocks.
  • the thread and the second sub-thread are parallel.
  • the starting order of the first sub-thread and the second sub-thread may be specified or random, which is not limited in this embodiment.
  • the processing process can be divided into the first stage, the second stage, the third stage, the fourth stage and the fifth stage.
  • the processing flow can be divided into the first stage, the second stage and the fifth stage.
  • the processing status of the sub-thread is different.
  • the processing state of the sub-thread is to read differential data
  • the processing state of the sub-thread is to decompress differential data
  • the processing status of the sub-thread is reading source data
  • the processing status of the sub-thread is synthetic target data
  • the processing status of the sub-thread is writing target data, that is, writing target data (or new data) to the target file (or new file).
  • Figure 26a shows the processing flow of the first sub-thread.
  • the steps of the first sub-thread to restore data compression blocks include:
  • 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 to write target data, if so, execute S703, if not, execute S702.
  • the first sub-thread when the processing status of the second sub-thread is writing target data, it indicates that the second sub-thread's processing flow of data compression and block is in the fifth stage. At this time, in order to avoid the waiting delay in the first RAM space area, the first sub-thread can restore the next data compression block to achieve parallel processing with the second sub-thread.
  • the first sub-thread waits and continues to execute the judgment process shown in S702.
  • the first sub-thread determines whether Diff-zone-offset is less than Diffnum. If so, S704 is executed. If not, S706 is executed.
  • 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 each Diff data compression block described by the current zone Among the Diff data compression blocks, there are still unprocessed Diff data compression blocks.
  • Diff-zone-offset is incremented by 1 to determine the Diff data compression blocks to be processed by the first sub-thread.
  • S705 The first sub-thread performs restoration processing on the Diff data compression blocks corresponding to the Diff-zone-offset, and executes S702.
  • the first sub-thread performs restoration processing on the Diff data compression block corresponding to the Diff-zone-offset based on a set of RAM spaces corresponding to the restoration thread.
  • the detailed steps can be referred to the previous article and will not be repeated here.
  • the first sub-thread After the first sub-thread completes the restoration process of the Diff data compression block corresponding to the Diff-zone-offset, it returns to execution S702 to determine whether the conditions for the first sub-thread to restore the next data compression block are met.
  • S706 The first sub-thread determines whether Extra-zone-offset is less than Extranum. If so, S707 is executed. If not, S709 is executed.
  • Extra-zone-offset is used to represent the sequence number of the currently processed Extra data compression block in each Extra data compression block described by the current zone, when Extra-zone-offset is less than Extranum, it indicates that each Extra data compression block described by the current zone Among the Extra data compression blocks, there are still Extra data compression blocks that have not been processed.
  • Extra-zone-offset is incremented by 1 to determine the Extra data compression blocks to be processed by the first sub-thread.
  • S708 The first sub-thread restores the Extra data compression blocks corresponding to the Extra-zone-offset and executes S702.
  • the first sub-thread performs restoration processing on the Extra data compression block corresponding to the Extra-zone-offset based on a set of RAM spaces corresponding to the restoration thread.
  • the detailed steps can be referred to the previous article and will not be repeated here.
  • the first sub-thread After the first sub-thread completes the restoration process of the Extra data compression block corresponding to the Extra-zone-offset, it returns to execution S702 to determine whether the conditions for the first sub-thread to restore the next data compression block are met.
  • Diff-zone-offset is not less than Diffnum, it indicates that there are no unprocessed Diff data compression blocks in each Diff data compression block described by the current zone.
  • Extra-zone-offset is not less than Extranum, it indicates that there are no unprocessed Extra data compression blocks in each Extra data compression block described by the current zone. At this point, the first sub-thread can end.
  • 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 the second sub-thread to restore data compression blocks include:
  • 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, S803 is executed. If not, Then execute S802.
  • the processing status of the first sub-thread when the processing status of the first sub-thread is writing target data, it indicates that the first sub-thread's processing flow of data compression and block is in the fifth stage. At this time, in order to avoid the waiting delay in the first RAM space area, the second sub-thread can restore the next data compression block to achieve parallel processing with the first sub-thread.
  • the second sub-thread waits and continues to execute the judgment process shown in S802.
  • the second sub-thread determines whether Diff-zone-offset is less than Diffnum. If so, S804 is executed. If not, S806 is executed.
  • 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 each Diff data compression block described by the current zone Among the Diff data compression blocks, there are still unprocessed Diff data compression blocks.
  • Diff-zone-offset is incremented by 1 to determine the Diff data compression blocks to be processed by the second sub-thread.
  • S805 The second sub-thread performs restoration processing on the Diff data compression blocks corresponding to the Diff-zone-offset, and executes S802.
  • the second sub-thread performs restoration processing on the Diff data compression block corresponding to the Diff-zone-offset based on a set of RAM spaces corresponding to the restoration thread.
  • the detailed steps can be referred to the previous article and will not be repeated here.
  • S802 is returned to execute to determine whether the conditions for the second sub-thread to restore the next data compression block are met.
  • S806 The second sub-thread determines whether Extra-zone-offset is less than Extranum. If so, S807 is executed. If not, S809 is executed.
  • Extra-zone-offset is used to represent the sequence number of the currently processed Extra data compression block in each Extra data compression block described by the current zone, when Extra-zone-offset is less than Extranum, it indicates that each Extra data compression block described by the current zone Among the Extra data compression blocks, there are still Extra data compression blocks that have not been processed.
  • Extra-zone-offset is incremented by 1 to determine the Extra data compression blocks to be processed by the first sub-thread.
  • S808 The second sub-thread restores the Extra data compression blocks corresponding to the Extra-zone-offset and executes S802.
  • the second sub-thread performs restoration processing on the Extra data compression block corresponding to the Extra-zone-offset based on a set of RAM spaces corresponding to the restoration thread.
  • the detailed steps can be referred to the previous article and will not be repeated here.
  • S802 is returned to execute to determine whether the conditions for the second sub-thread to restore the next data compression block are met.
  • Diff-zone-offset is not less than Diffnum, it indicates that there are no unprocessed Diff data compression blocks in each Diff data compression block described by the current zone.
  • Extra-zone-offset is not less than Extranum, it indicates that there are no unprocessed Extra data compression blocks in each Extra data compression block described by the current zone.
  • S604 The restoration thread determines whether each data compression block described by the zone has been processed, and whether the first sub-thread and the second sub-thread have both ended. If so, S605 is executed; if not, S604 is executed.
  • the restoration thread determines whether each data compression block described by the zone has been processed, and whether the first sub-thread and the second sub-thread have ended. If not, wait and continue to make the judgment. If so, the restoration thread describes the zone. The restore processing operation of data compression blocks is completed.
  • the restoration thread restores the data compression block described by a zone, it can execute the linked list according to the corresponding restore operation and continue to restore the data compression block described by the next zone.
  • the processing process can still refer to S601 -S605, which will not be described in detail here, until the restoration operation is completed, the data compression block described by each zone recorded in the linked list is executed, and the restoration thread ends.
  • the second sub-thread when the restoration processing of each data compression block described by a zone is implemented through two sub-threads, in the fifth stage of the first sub-thread's restoration processing of Diff data compression block 1, the second sub-thread The thread can begin to restore the first stage of processing Diff data compression block 2.
  • the first sub-thread in the fifth stage of the second sub-thread's restoration and processing of Diff data compression block 2, the first sub-thread can start the second stage of restoration and processing of Extra data compression block 1; in the first sub-thread's restoration and processing of Extra data In the fifth stage of compression block 1, the second sub-thread can begin to restore and process the first stage of Extra data compression block 2.
  • Figure 28 shows a schematic structural diagram of the electronic device 10.
  • the electronic device 10 may be called a terminal or a terminal device, such as a smartphone, etc.
  • the terminal may be a wearable electronic device, such as a smart watch, which is not limited in this application.
  • the schematic structural diagram of the electronic device 10 can be applied to the smart watch 100 or the mobile phone 200 in FIG. 1 .
  • the electronic device 10 shown in FIG. 28 is only an example of the electronic device, and the electronic device 10 may have more or fewer components than shown in the figure, and two or more components may be combined. , or can have different component configurations.
  • the various components shown in Figure 28 may be implemented in hardware, software, or a combination of hardware and software including one or more signal processing and/or application specific integrated circuits.
  • 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.
  • Mobile communication module 150 wireless communication module 160, audio module 170, speaker 170A, receiver 170B, microphone 170C, headphone interface 170D, sensor module 180, button 190, motor 191, indicator 192, camera 193, display screen 194, And subscriber identification module (subscriber identification module, SIM) card interface 195, etc.
  • SIM subscriber identification module
  • the sensor module 180 may include a pressure sensor, a gyroscope sensor, an acceleration sensor, a temperature sensor, a PPG (Photo Plethysmo Graphy) sensor, a motion sensor, an air pressure sensor, a magnetic sensor, a distance sensor, a proximity light sensor, and a fingerprint sensor. , touch sensor, ambient light sensor, bone conduction sensor, etc.
  • the processor 110 may include one or more processing units.
  • the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processing unit (GPU), and an image signal processor. (image signal processor, ISP), controller, memory, video codec, digital signal processor (digital signal processor, DSP), baseband processor, and/or neural-network processing unit (NPU) wait.
  • application processor application processor
  • GPU graphics processing unit
  • image signal processor image signal processor
  • ISP image signal processor
  • controller memory
  • video codec digital signal processor
  • DSP digital signal processor
  • NPU neural-network processing unit
  • different processing units can be independent devices or integrated in one or more processors.
  • the processor 110 may also be provided with a memory for storing instructions and data.
  • the charging management module 140 is used to receive charging input from the charger. While the charging management module 140 charges the battery 142, it can also provide power to the electronic device through the power management module 141.
  • 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 modem processor and the baseband processor.
  • the mobile communication module 150 can provide solutions for wireless communication including 2G/3G/4G/5G applied on the electronic device 10 .
  • the wireless communication module 160 can provide applications on the electronic device 10 including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) network), Bluetooth (bluetooth, BT), and global navigation satellites.
  • WLAN wireless local area networks
  • WiFi wireless fidelity
  • Bluetooth bluetooth, BT
  • GNSS global navigation satellite system
  • frequency modulation frequency modulation, FM
  • NFC near field communication technology
  • infrared technology infrared, IR
  • the antenna 1 of the electronic device 10 is coupled to the mobile communication module 150, and the antenna 2 is coupled to the wireless communication module 160, so that the electronic device 10 can communicate with the network and other devices through wireless communication technology.
  • the electronic device 10 implements display functions through a GPU, a display screen 194, an application processor, and the like.
  • Processor 110 may include one or more GPUs that execute program instructions to generate or alter display information.
  • the display screen 194 is used to display images, videos, etc.
  • Display 194 includes a display panel.
  • the electronic device 10 may include 1 or N display screens 194, where N is a positive integer greater than 1.
  • 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 .
  • Internal memory 121 may be used to store computer executable program code, which includes instructions.
  • the processor 110 executes 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 in the embodiment of the present application.
  • the internal memory 121 may be used to store programs that implement the differential file generation method, differential file restoration method, BSDiff algorithm program, etc. in the embodiment of the present application.
  • the electronic device 10 can implement audio functions through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone interface 170D, and the application processor. Such as music playback, recording, etc.
  • 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. Audio module 170 may also be used to encode and decode audio signals. In some embodiments, the audio module 170 may be provided in the processor 110 , or some functional modules of the audio module 170 may be provided in the processor 110 .
  • the gyro sensor can be used to detect the motion posture of the electronic device 10 .
  • the angular velocity of electronic device 10 about three axes ie, x, y, and z axes
  • the gyro sensor can also be used to identify the posture of the electronic device to identify the behavioral state of the user who is wearing or holding the electronic device 10 .
  • the acceleration sensor can be used to detect the acceleration of the electronic device 10 in various directions (generally three axes). In some embodiments, when the electronic device 10 is stationary, the magnitude and direction of gravity can be detected through an acceleration sensor. In some embodiments, the acceleration sensor can also be used to identify the posture of the electronic device to identify the behavioral state of the user wearing or holding the electronic device 10 .
  • a temperature sensor may be used to detect the temperature of electronic device 10 .
  • the body temperature of the user wearing the electronic device 10 may be detected through a temperature sensor.
  • the PPG Photo Plethysmo Graphy
  • 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 light absorption increases, the light intensity detected by the light detector is smaller; when the heart relaxes, the blood volume of the tissue decreases, and the light absorption decreases, the light detector detects The light intensity is greater.
  • the changes in the light intensity of the PPG sensor are related to small changes in the 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 parameters such as blood pressure, blood oxygen, pulse rate (heart rate), and respiratory rate. information.
  • Pressure sensors are used to sense pressure signals and convert pressure signals into electrical signals.
  • the pressure sensor may be disposed on the display screen 194 .
  • the electronic device 10 may also calculate the touched position based on the detection signal of the pressure sensor.
  • Touch sensor also called “touch panel”.
  • the touch sensor can be disposed on the display screen 194, and the touch sensor and the display screen 194 form a touch screen, which is also called a "touch screen”.
  • Touch sensors are used to detect touches on or near them.
  • the touch sensor can pass the detected touch operation to the application processor to determine the touch event type.
  • the buttons 190 include a power button (also called a power button), a volume button, etc.
  • Key 190 may be a mechanical key. OK It is a touch button.
  • the electronic device 10 may receive key input and generate key signal input related to user settings and function control of the electronic device 10 .
  • the motor 191 can generate vibration prompts.
  • the motor 191 can be used for vibration prompts for incoming calls and can also be used for touch vibration feedback.
  • the indicator 192 may be an indicator light, which may be used to indicate charging status, power changes, or may be used to indicate messages.
  • the software system of the electronic device 10 may adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservice architecture, or a cloud architecture.
  • This embodiment of the present application takes an operating system with a layered architecture as an example to illustrate the software structure of the electronic device 10 .
  • Figure 29 is a software structure block diagram of the electronic device 10 according to the embodiment of the present application.
  • the layered architecture of the electronic device 10 divides the software into several layers, and each layer has clear roles and division of labor.
  • the layers communicate through software interfaces.
  • the operating system can be divided into six layers, from top to bottom: UI (User Interface, user interface) application layer, system service layer layer, algorithm layer, hardware abstraction layer, kernel layer, and driver layer.
  • UI User Interface, user interface
  • the UI application layer can include a series of application packages, such as watch faces, exercise records, calls, exercises, etc.
  • the system service layer can include a series of system services.
  • the system service layer can include a heart rate service.
  • the heart rate service can provide physiological parameter information of the smart watch wearer, such as blood pressure, blood oxygen, pulse rate, respiratory rate and body temperature, etc., and can also detect physiological parameter change information of the smart watch wearer.
  • the system service layer can also include step counting services, calorie services, and heart health services.
  • the algorithm layer can include a series of algorithm models. As shown in Figure 29, the algorithm layer may include a differential reduction algorithm model. Among them, the differential restoration algorithm model can be used in the differential file restoration method provided in this embodiment.
  • the hardware abstraction layer is the interface layer between the operating system kernel and the hardware circuit.
  • HAL layers include, but are not limited to, audio HALs. Among them, the audio HAL is used to process the audio stream, for example, perform noise reduction, directional enhancement, etc. on the audio stream.
  • the kernel layer and driver layer are the layers between hardware and software. As shown in Figure 29, the kernel layer at least includes the operating system kernel, and the driver layer at least includes Bluetooth driver, WiFi driver, etc.
  • the layers in the software structure shown in FIG. 29 and the components included in each layer do not constitute specific limitations on the electronic device 10 .
  • the electronic device 10 may include more or fewer layers than shown in the figures, and each layer may include more or fewer components, which is not limited by this application.
  • the electronic device 10 includes corresponding hardware and/or software modules that perform various functions.
  • the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is performed by hardware or computer software driving the 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 in conjunction with the embodiments for each specific application, but such implementations should not be considered to be beyond the scope of this application.
  • FIG. 30 shows a schematic block diagram of a device 800 according to an embodiment of the present application.
  • the device 800 can It includes: a processor 801 and a transceiver/transceiver pin 802, and optionally, a memory 803.
  • bus 804 includes, in addition to a data bus, a power bus, a control bus, and a status signal bus.
  • bus 804 includes, in addition to a data bus, a power bus, a control bus, and a status signal bus.
  • various buses are referred to as bus 804 in the figure.
  • the memory 803 can be used to store instructions of the server in the above differential file generation method embodiment.
  • the processor 801 can be used to execute instructions in the memory 803, and control the receiving pin to receive signals, and control the transmitting pin to send signals.
  • the memory 803 may be used to store instructions of the smart terminal in the above differential file restoration method embodiment.
  • the processor 801 can be used to execute instructions in the memory 803, and control the receiving pin to receive signals, and control the transmitting pin to send signals.
  • the device 800 may be a server, such as an OTA server, in the above embodiment of the differential file generation method, or a smart terminal, such as a smart phone, a smart watch, etc. in the above embodiment of the differential file restoration method.
  • a server such as an OTA server
  • a smart terminal such as a smart phone, a smart watch, etc. in the above embodiment of the differential file restoration method.
  • This embodiment also provides a computer storage medium that stores computer instructions.
  • the electronic device causes the electronic device to execute the above related method steps to achieve the generation of the differential file in the above embodiment. method, or causing the electronic device to execute the above related method steps to implement the differential file restoration method in the above embodiment.
  • This embodiment also provides a computer program product.
  • the computer program product When the computer program product is run on a computer, it causes the computer to perform the above related steps to implement the method for generating a differential file in the above embodiment, or to implement the method in the above embodiment. How to restore differential files.
  • inventions of the present application also provide a device.
  • This device may be a chip, a component or a module.
  • the device may include a connected processor and a memory.
  • the memory is used to store computer execution instructions.
  • the processor can execute computer execution instructions stored in the memory, so that the chip executes the method for generating a differential file or the method for restoring a differential file in the above method embodiment.
  • the electronic devices such as servers or terminals, etc.
  • computer storage media such as servers or terminals, etc.
  • computer program products or chips provided in this embodiment are all used to execute the corresponding methods provided above. Therefore, the beneficial effects they can achieve can be referred to The beneficial effects of the corresponding methods provided above will not be described again here.
  • the disclosed devices and methods can be implemented in other ways.
  • the device embodiments described above are only illustrative.
  • the division of modules or units is only a logical function division.
  • there may be other division methods for example, multiple units or components may be combined or can be integrated into another device, or some features can be ignored, or not implemented.
  • the coupling or direct coupling or communication connection between each other shown or discussed may be through some interfaces, and the indirect coupling or communication connection of the devices or units may be in electrical, mechanical or other forms.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本申请实施例提供了一种差分文件的还原方法及电子设备。在该方法中,差分文件中包括至少一组数据压缩分块,每组中的各数据压缩分块被压缩前是基于预设的分块尺寸进行划分的;在电子设备针对该差分文件进行还原时,首先根据分块尺寸和RAM空间尺寸确定还原线程的并行数量k,然后采用k个还原线程并行地对差分文件进行还原处理,其中,每个还原线程使用与其对应的一组RAM空间对至少一组数据压缩分块进行还原处理。这样,针对上述差分文件进行还原处理时,电子设备能够根据用于差分文件还原的RAM内存空间自适应地确定还原线程的并行数量,并通过多个线程并行处理以提高差分文件的还原效率。

Description

差分文件的还原方法及电子设备
本申请要求于2022年09月09日提交中国国家知识产权局、申请号为202211101979.2、申请名称为“差分文件的还原方法及电子设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及智能终端技术领域,尤其涉及一种差分文件的还原方法及电子设备。
背景技术
为了完善终端设备的功能、增强设备稳定性、修补设备缺陷或漏洞(bug)时,往往需要对终端设备的固件进行升级。
目前,通常采用空中下载(Over the Air,OTA)技术对终端设备进行在线固件升级。OTA升级方式主要包括整包升级和差分包升级。为了提升升级包传输效率及固件升级效率,终端设备多采用差分包升级方式,也即只针对固件的差异部分进行升级。
其中,终端设备采用差分包升级方式进行在线固件升级时,首先需要对差分文件进行还原,而对差分文件的还原操作需要占用RAM(Random Access Memory,随机存取存储器)内存,且不同终端设备供差分文件还原的RAM内存空间不尽相同。因此,在采用差分包升级的方式进行固件升级时,如何提升差分文件的还原效率是需要解决就问题。
发明内容
为了解决上述技术问题,本申请实施例提供一种差分文件的还原方法及电子设备。在该方法中,电子设备根据与差分文件对应的分块尺寸以及用于差分文件还原的RAM内存空间尺寸自适应地确定还原线程的并行数量,并通过多个线程并行地进行还原处理,以此提高了差分文件的还原效率。
第一方面,本申请实施例提供一种差分文件的还原方法。该方法包括:
电子设备获取差分文件;其中,在差分文件中包括至少一组数据压缩分块,一组数据压缩分块包括差异Diff数据压缩分块和/或新增Extra数据压缩分块,数据压缩分块被压缩前是基于预设的分块尺寸进行划分的;
电子设备根据分块尺寸和电子设备用于差分文件还原的RAM空间尺寸,确定还原线程的并行数量k,并为每个还原线程划分一组RAM空间;
电子设备采用k个还原线程并行地对差分文件进行还原处理,其中,每个还原线程使用与其对应的一组RAM空间对至少一组数据压缩分块进行还原处理,并将还原处理后得到的数据写入目标文件中。
这样,电子设备根据与差分文件对应的分块尺寸以及用于差分文件还原的RAM内存空间尺寸自适应地确定还原线程的并行数量,并通过多个线程并行地进行还原处理,以此提高了差分文件的还原效率。
根据第一方面,一组RAM空间可以包括:第一RAM内存区域、第二RAM内存区域、第三RAM内存区域和第四RAM内存区域;其中,第一RAM内存区域和第二RAM内存区域的尺寸为分块尺寸;第二RAM内存区域和第四RAM内存区域分别为第一RAM内存区域和第三RAM内存区域的安全缓冲区域;各个还原线程共用第五RAM内存区域,第五RAM内存区域用于运行数据压缩算法。
这样,电子设备可以基于较小的RAM内存空间实现对数据压缩分块还原操作。而且,为第一RAM内存区域和第三RAM内存区域设置安全缓冲区,针对数据压缩后数据反而增大的情况,也不会影响数据处理的准确性。
根据第一方面,或者以上第一方面的任意一种实现方式,电子设备根据分块尺寸和电子设备用于差分文件还原的RAM空间尺寸,确定还原线程的并行数量k,k=[(M-N1)/(zonesize+N2)];其中,M为电子设备用于差分文件还原的RAM空间尺寸,N1为第五RAM内存区域的尺寸,zonesize为分块尺寸,N2为安全缓冲区域的尺寸,[]为取整运算。
根据第一方面,或者以上第一方面的任意一种实现方式,与Diff数据压缩分块对应的Diff数据是基于第一运算得到的;每个还原线程对一组数据压缩分块进行还原处理,可以包括:还原线程按照解析顺序依次对一组数据压缩分块中的Diff数据压缩分块或Extra数据压缩分块进行数据还原处理;每解析得到一个Diff数据压缩分块时,将Diff数据压缩分块对应的Diff数据与已有数据进行第二运算,得到第一目标数据,写入目标文件中;其中,已有数据为在与差分文件对应的已有文件中,读取到的与Diff数据压缩分块匹配的数据,第二运算为第一运算的逆运算;每解析得到一个Extra数据压缩分块时,对Extra数据压缩分块进行数据解压,得到第二目标数据,写入目标文件中。
示例性的,第一运算为减运算,第二运算为加运算。
这样,电子设备对差分文件进行还原处理时,每个还原线程可以将Diff数据压缩分块或Extra数据压缩分块作为一个独立的差分还原处理单元,使得终端侧的RAM内存消耗更小,进而终端侧能够通过较小的RAM内存空间实现差分数据还原功能。
根据第一方面,或者以上第一方面的任意一种实现方式,电子设备将Diff数据压缩分块对应的Diff数据与已有数据进行第二运算,得到第一目标数据,写入目标文件中,可以包括:电子设备将Diff数据压缩分块暂存在第一RAM内存区域中;电子设备对Diff数据压缩分块进行数据解压处理,将得到的Diff数据分块暂存在第三RAM内存区域中;电子设备在已有文件中读取与Diff数据分块对应的已有数据,并暂存在第一RAM内存区域中;电子设备将第一RAM内存区域中的数据和第三RAM内存区域中的数据进行第二操作,所得的第一目标数据暂存在第三RAM内存区域中;电子设备将在第三RAM内存区域中暂存的第一目标数据,写入目标文件中。
根据第一方面,或者以上第一方面的任意一种实现方式,电子设备对Extra数据压缩分块进行数据解压,得到第二目标数据,写入目标文件中,可以包括:电子设备将Extra数据压缩分块暂存在第一RAM内存区域中;电子设备对Extra数据压缩分块进行数据解压处理,将得到的第二目标数据暂存在第三RAM内存区域中;电子设备将在第三RAM内存区域中暂存的第二目标数据,写入目标文件中。
根据第一方面,或者以上第一方面的任意一种实现方式,每个还原线程使用与其对应的一组RAM空间对至少一组数据压缩分块进行还原处理,可以包括:电子设备根据差分文件中包括的数据压缩分块组数,以及各组数据压缩分块的序号为每个还原线程分别创建链表,以使还原线程根据对应的链表完成对至少一组数据压缩分块进行还原处理;其中,在链表中,节点的数据部分填充一组数据压缩分块的序号,以及一组数据压缩分块对应的还原数据在目标文件中写入的首地址。
根据第一方面,或者以上第一方面的任意一种实现方式,差分文件的数据结构包括头部、控制块、以及通过控制块描述的一组数据压缩分块;头部中填充差分文件的魔数与分块尺寸;控制块中填充第一指针偏移量和第二指针偏移量;其中,第一指针偏移量用于在已有文件中确定与一组数据压缩分块对应的数据读取首地址;第二指针偏移量用于在目标文件中确定与一组数据压缩分块对应的数据写入首地址。
根据第一方面,或者以上第一方面的任意一种实现方式,电子设备根据数据压缩分块的序号对并行数量的取余结果,分别确定待每个还原线程处理的各组数据压缩分块。
根据第一方面,或者以上第一方面的任意一种实现方式,每个还原线程使用与其对应的一组RAM空间对至少一组数据压缩分块进行还原处理,可以包括:每个还原线程创建第一子线程和第二子线程;电子设备通过第一子线程和第二子线程使用与还原线程对应的一组RAM空间,依次对一组数据压缩分块中包括的Diff数据压缩分块或Extra数据压缩分块进行还原处理;其中,在第二子线程执行到目标阶段时,第一子线程继续在一组数据压缩分块数据压缩分块进行还原处理;在第一子线程执行到目标阶段时,第二子线程继续在一组数据压缩分块数据压缩分块进行还原处理;其中,目标阶段为将在第三RAM内存区域中暂存的数据,写入目标文件中。
这样,每个还原线程对一组数据压缩分块进行还原处理时,无需待前一个数据压缩分块的还原处理流程完全结束后,后一个数据压缩分块的还原流程才开始,使得第一RAM内存区域不再存在等待时延,减少了一组数据压缩分块的还原时长,提升了还原线程的处理效率。
第二方面,本申请实施例提供一种电子设备。该电子设备包括:一个或多个处理器;存储器;以及一个或多个计算机程序,其中一个或多个计算机程序存储在存储器上,当计算机程序被一个或多个处理器执行时,使得电子设备执行如第一方面以及第一方面的任意一种实现方式中的差分文件的还原方法。
第二方面以及第二方面的任意一种实现方式分别与第一方面以及第一方面的任意一种实现方式相对应。第二方面以及第二方面的任意一种实现方式所对应的技术效果可参见上述第一方面以及第一方面的任意一种实现方式所对应的技术效果,此处不再赘述。
第三方面,本申请实施例提供一种计算机可读存储介质。该计算机可读存储介质包括计算机程序,当计算机程序在电子设备上运行时,使得电子设备执行如第一方面以及第一方面的任意一种实现方式中的差分文件的还原方法。
第三方面以及第三方面的任意一种实现方式分别与第一方面以及第一方面的任意一 种实现方式相对应。第三方面以及第三方面的任意一种实现方式所对应的技术效果可参见上述第一方面以及第一方面的任意一种实现方式所对应的技术效果,此处不再赘述。
第四方面,本申请实施例提供一种计算机程序产品,包括计算机程序,当计算机程序被运行时,使得计算机执行如第一方面以及第一方面的任意一种实现方式中的差分文件的还原方法。
第四方面以及第四方面的任意一种实现方式分别与第一方面以及第一方面的任意一种实现方式相对应。第四方面以及第四方面的任意一种实现方式所对应的技术效果可参见上述第一方面以及第一方面的任意一种实现方式所对应的技术效果,此处不再赘述。
第五方面,本申请提供了一种芯片,该芯片包括处理电路、收发管脚。其中,该收发管脚和该处理电路通过内部连接通路互相通信,该处理电路执行如第一方面以及第一方面的任意一种实现方式中的差分文件的还原方法,以控制接收管脚接收信号,以控制发送管脚发送信号。
第五方面以及第五方面的任意一种实现方式分别与第一方面以及第一方面的任意一种实现方式相对应。第五方面以及第五方面的任意一种实现方式所对应的技术效果可参见上述第一方面以及第一方面的任意一种实现方式所对应的技术效果,此处不再赘述。
附图说明
图1为示例性示出的一种应用场景示意图;
图2为示例性示出的一种对固件文件进行差分还原的流程示意图;
图3为示例性示出的差分原理示意图;
图4为示例性示出的一种差分文件的数据结构示意图;
图5为示例性示出的还原原理示意图;
图6为示例性示出的数据还原操作示意图;
图7为本实施例提供的一种差分文件的生成方法示意图;
图8为本实施例提供的一种差分文件的数据结构示例图;
图9为本实施例提供的一种差分文件的生成方法示意图;
图10为本实施例提供的一种差分文件的数据结构示例图;
图11a为本实施例提供的一种差分文件的生成方法示意图;
图11b为本实施例提供的一种数据分块划分方法示意图;
图12为本实施例提供的一种差分文件的还原方法示意图;
图13为本实施例提供的一种差分文件的还原操作示意图;
图14为本实施例提供的在基于Diff数据压缩分块进行数据还原时RAM空间占用的示意图;
图15为本实施例提供的在基于Extra数据压缩分块进行数据还原时RAM空间占用的示意图;
图16为本实施例提供的在基于Diff数据压缩分块进行数据还原时RAM空间占用的 示意图;
图17为本实施例提供的在基于Extra数据压缩分块进行数据还原时RAM空间占用的示意图;
图18为本实施例提供的在基于Diff数据压缩分块进行数据还原时RAM空间占用的示意图;
图19为本实施例提供的在基于Extra数据压缩分块进行数据还原时RAM空间占用的示意图;
图20为示例性示出的一种应用场景示意图;
图21a为示例性示出的用于还原线程并行的RAM空间划分示意图;
图21b为示例性示出的用于还原线程并行的RAM空间划分示意图;
图22为示例性示出的差分数据并行还原的示意图;
图23为本实施例提供的一种差分文件的数据结构示例图;
图24a为本实施例提供的在基于Diff数据压缩分块进行数据还原时RAM内存区域占用状态变化示意图;
图24b为本实施例提供的在基于Extra数据压缩分块进行数据还原时RAM内存区域占用状态变化示意图;
图25为本实施例提供的还原线程的处理流程示意图;
图26a为本实施例提供的还原线程中第一子线程的处理流程示意图;
图26b为本实施例提供的还原线程中第二子线程的处理流程示意图;
图27a为本实施例提供的基于单线程连续进行数据压缩分块还原的时长示意图;
图27b为本实施例提供的基于多线程连续进行数据压缩分块还原的时长示意图;
图28为示例性示出的电子设备的硬件结构示意图;
图29为示例性示出的电子设备的软件结构示意图;
图30为示例性示出的一种装置的结构示意图。
具体实施方式
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
本文中术语“和/或”,仅仅是一种描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。
本申请实施例的说明书和权利要求书中的术语“第一”和“第二”等是用于区别不同的对象,而不是用于描述对象的特定顺序。例如,第一目标对象和第二目标对象等是用于区别不同的目标对象,而不是用于描述目标对象的特定顺序。
在本申请实施例中,“示例性的”或者“例如”等词用于表示作例子、例证或说明。本申请实施例中被描述为“示例性的”或者“例如”的任何实施例或设计方案不应被解 释为比其它实施例或设计方案更优选或更具优势。确切而言,使用“示例性的”或者“例如”等词旨在以具体方式呈现相关概念。
在本申请实施例的描述中,除非另有说明,“多个”的含义是指两个或两个以上。例如,多个处理单元是指两个或两个以上的处理单元;多个系统是指两个或两个以上的系统。
在终端设备进行在线固件升级时,若采用OTA差分包升级方式进行固件升级,则终端设备需要具备对差分文件进行还原的能力,也即根据差分文件和与该差分文件对应的已有固件文件(也即旧版本的固件文件,下述简称为旧固件文件),生成对应的新版本的固件文件(下述简称为新固件文件)。进而,终端设备可以根据新版本的固件文件完成固件升级。
图1示例性的示出一种应用场景,以智能手表100为例进行在线固件升级为例进行解释说明。其中,智能手表100为不具备独立联网功能的低端智能终端设备(也可以成为轻量级嵌入式设备),智能手表100可以通过蓝牙与智能手机200进行通信。参照图1,在智能手机200中安装有与智能手表100对应的应用APP,该应用APP用于连接智能手表100与智能手机200,为智能手表100下载应用或文件等。进而,智能手表100可以通过该应用APP与OTA服务器300进行通信。示例性的,智能手表100可以定期通过该应用APP向OTA服务器300查询是否存在与智能手表100对应的升级差分包。如果查询到存在与智能手表100对应的升级差分包,则可以在满足在线升级条件(例如电量状态、联网状态、蓝牙状态等满足预设条件)时,通过该应用APP向OTA服务器300发送升级差分包下载请求,以通过智能手机200下载相应的升级差分包。其中,智能手机可以通过蓝牙技术将下载得到的升级差分包发送至智能手表100中。进而,智能手表100可以对升级差分包进行还原,并基于还原后得到新版本的固件文件完成固件升级。
继续参照图1,与智能手表100对应的升级差分包可以基于差分数据包制作平台400制作而成,并被上传至OTA服务器300。在一些实现方式中,升级差分包也可以是在OTA服务器300中制作生成的,本实施例对此不做限定。无论升级差分包是基于差分数据包制作平台400制作而成,还是基于OTA服务器300制作而成,升级差分包均是基于新旧固件文件以及相应的差分算法而生成的。
其中,在如图1所示的应用场景中,智能手机200为具备独立联网功能的智能终端设备,作为智能手表100与OTA服务器300的中继设备。
在一些实现方式中,若智能手表100具备独立联网能力,也可以直接与OTA服务器300通信,以向OTA服务器300查询是否到存在与智能手表100对应的升级差分包,或者以向OTA服务器300下载相应的升级差分包。
在图1所示的应用场景中,以智能手表100为例对存在固件在线升级需求的终端设备进行解释。其中,存在固件在线升级需求的终端设备也可以是智能手环,智能耳机等其他穿戴式设备,也可以是万物互联场景中的任意嵌入式节点设备(例如为采集温度、湿度等信息的节点设备),本实施例对比不做限定。如果存在固件在线升级需求的终端设备为不具备独立联网功能的低端设备,则需要通过中继设备与OTA服务器进行通信,以 通过中继设备下载升级差分包。如果存在固件在线升级需求的终端设备为具备独立联网功能的低端设备,则可以直接与OTA服务器进行通信以下载升级差分包。
图2示例性的示出了固件文件差分还原的流程示意图。
如图2所示,在服务器侧(或工具侧),服务器根据预设的差分算法(例如BSDiff算法)对成对的新固件文件和旧固件文件进行差分处理,得到一个差分文件(Patch文件)。这样,服务器可以得到与固件升级对应的多个差分文件。差分文件的数量与待升级的固件有关,本实施例对此不做限定。进而,服务器可以对这多个差分文件进行压缩打包,生成升级差分包。其中,升级差分包中可以包括多个压缩后的差分文件,以及与这多个差分文件对应的描述文件等。
当终端需要进行固件升级时,向服务器请求下载升级差分包。终端接收到升级差分包后,对升级差分包进行解压,可以得到各个差分文件。以一个差分文件为例,终端根据与该差分文件匹配的旧固件文件,对该差分文件进行还原操作,即可得到相应的新固件文件。这样,终端侧可以得到多个新固件文件,进而可以基于这多个新固件文件进行固件升级操作。
继续参照图2,在固件文件差分还原的流程中,文件差分操作以及差分包压缩操作是在服务器侧执行的,差分包解压操作以及差分文件还原操作时在终端侧执行的。
当终端为轻量级嵌入式设备(如穿戴式设备)时,其RAM资源受限,会严重影响差分包解压还原处理的效率,甚至可能会由于差分文件过大而导致固件升级失败的问题。因此,如果差分文件还原过程涉及的内存消耗能够更小,则会更好地适用于轻量级嵌入式设备的固件升级场景。
下述以BSDiff算法为例,对差分还原算法的基本原理进行解释说明。
(一)差分原理(Bsdiff原理)
其中,差分原理的核心思想为尽可能多的利用旧文件中的数据,尽可能少的加入新的数据来构建新文件。
图3示例性的示出了基于Bsdiff原理的文件差分流程。
参照图3,对比旧文件数据和新文件数据,在二者中确定各个最长的相似子串(即子字符串)。示例性的,新文件数据中的数据01_new为“1010101010101010101”,旧文件数据中的数据01_old为“1010101110101011101”,新文件数据中的数据01_new和旧文件数据中的数据01_old为一个最长的相似子串。又示例性的,新文件数据中的数据03_new和旧文件数据中的数据02_old为另一个最长的相似子串。示例性的,在新文件数据中,介于数据01_new和数据03_new之间为数据02_new,在旧文件数据中没有与数据02_new相似的子串,则数据02_new为在新文件中新增的数据。类似的,在新文件数据中,数据04_new也为新增的数据。
由此,可以根据新文件数据和旧文件数据中的相似子串,计算差异数据(Diff数据),差异数据与新增数据(Extra数据)共同构成增量更新数据(Patch数据)。如图3所示,将新文件中的数据01_new和旧文件中的数据01_old进行减运算,可以得到Patch数据中的Diff数据01;将新文件中的数据03_new和旧文件中的数据02_old进行减运算,可以 得到Patch数据中的Diff数据02。同时,可以将新文件中的数据02_new直接作为Patch数据中的Extra01数据,将新文件中的数据04_new直接作为Patch数据中的Extra02数据。以此类推,即可基于新文件数据和旧文件数据得到所有Diff数据和Extra数据,组成Patch数据。
需要指出是,通常情况下,在依据BSDiff算法得到的Patch数据中,Diff数据和Extra数据是成对出现的,在每一块Diff数据后均为一块Extra数据。可以理解为,该Patch数据中包括至少一组增量更新数据,每组增量更新数据通常都包括Diff数据和Extra数据。在一些特殊情况下,Diff数据和Extra数据也可能不是成对出现的,例如在Patch数据中最后一组增量更新数据中,可能只包括Diff数据,可能只包括Extra数据。
需要注意的是,Patch数据中各Diff数据和Extra数据排序及位置偏移与新文件数据是一致的。由此,按顺序对Patch数据中的Diff数据和Extra数据进行数据还原处理,即可得到与Patch数据对应的新文件数据。
需要注意的是,在依据BSDiff算法得到的Patch数据中,
在基于新文件数据和旧文件数据得到Patch数据之后,即可对Patch数据进行数据编码,得到相应的Patch文件。
在图3中示例性的示出了一种Patch文件的数据结构,该数据结构包括总编码头,与一组Diff数据和Extra数据对应的编码信息,以及Diff数据和Extra数据。其中,与某一组Diff数据和Extra数据对应的编码信息,用于对该组Diff数据和Extra数据进行描述,例如描述Diff数据的字节长度、Extra数据的字节长度,以及在旧文件中读取数据的指针偏移量。
图4示例性的示出了一种Patch文件的数据结构。如图4所示,该Patch文件的数据结构包括头部(Header)、控制块(control block)、Diff块(差异数据块)和Extra块(新增数据块)。
其中,Header包括8个字节,用于填充魔数。在此处,魔数用于判断文件类型。
每个control block包括24个字节,用于描述一组Diff块和Extra块。也即,control block中记录的数据可以作为其描述的一组Diff块和Extra块的编码信息。其中,control block的前8个字节用于填充其描述的Diff块的字节长度;control block的中间8个字节用于填充其描述的Extra块的字节长度;control block的后8个字节用于填充指针偏移量,该指针偏移量用于确定在旧文件中读取数据(用于与Diff数据进行加运算的数据)的位置。
示例性的,每个control block可以使用(x,y,z)来表示,其中,x为Diff块的字节长度,用于指示从旧文件和Diff块中读取x个字节以进行加运算;y为Extra块的字节长度,用于指示从Extra块中读取y个字节以添加至新文件中;z为旧文件指针的偏移量,用于确定从旧文件中下一次读取数据的指针位置,也即用于确定本次在旧文件中读取数据后指针的偏移量。其中,当z表示的偏移量以指针当前位置为基准时,z可以通过正负值来表示偏移的方向,例如正值表示向前偏移,负值表示向后偏移。
Diff块,用于记录Diff数据,也即用于记录旧文件与新文件中一个最长的相似子串的差值。
Extra块,用于记录Extra数据,也即用于记录新文件中的新增数据。
其中,在将多个Patch文件进行打包之前,还可以对Patch文件进行压缩。
在一种可能的实现方式中,针对数据结构如图4所示的Patch文件进行压缩时,可以采用按数据块进行压缩的方式,也即分别对每个control block(即control block1或control block2或control block n)、每个Diff块(即Diff块1或Diff块2或Diff块n)和每个Extra块(即Extra块1或Extra块2或Extra块n)进行压缩。
在一种可能的实现方式中,针对数据结构如图4所示的Patch文件进行压缩时,可以采用对整个文件进行压缩的方式,也即将Header、control block1、Diff块1、Extra块1、control block2、Diff块2、Extra块2、…、control block n、Diff块n、Extra块n一起进行压缩。
在一种可能的实现方式中,针对数据结构如图4所示的Patch文件进行压缩时,可以采用将整个文件按预设大小划分为x个子文件后再进行压缩的方式,假设整个文件大小为N,则每个子文件的大小为N/x。
在一种可能的实现方式中,针对数据结构如图4所示的Patch文件进行压缩时,可以采用数据块类型进行压缩的方式,也即分别对多个control block(即control block1、control block2、…、control block n)、多个Diff块(即Diff块1、Diff块2、…、Diff块n)和多个Extra块(即Extra块1、Extra块2、…、Extra块n)进行压缩。
这样,在服务器分别对各组新固件文件和旧固件文件进行差分处理,得到多个Patch文件之后,将这多个Patch文件分别压缩后进行打包即可得到相应的升级差分包,以待终端查询并下载该升级差分包。
(二)还原原理(bspatch原理)
对应于上述bsdiff原理,在BSDiff算法中基于bspatch原理进行Patch文件还原。其中,bspatch原理可以理解为bsdiff原理的逆过程,也即Patch文件还原可以理解为Patch文件生成逆过程。
图5示例性的示出了基于bspatch原理的文件还原流程。
参照图5,对Patch文件进行数据解码,得到对应的Patch数据。此处对Patch文件数据进行解码的过程可以理解为对Patch数据进行数据编码的逆过程。
其中,关于Patch文件的数据结构可以参照上文关于图4的解释说明,在此不再赘述。由此,在对Patch文件进行数据解码得到的Patch数据中,Diff数据和Extra数据是成对出现的,在每一块Diff数据后均为一块Extra数据。而且,Patch数据中各对Diff数据和Extra数据的排序与新文件数据是一致的。
当终端获取到Patch文件时,对Patch文件的header进行解析,根据header中记录的魔数获知文件类型之后,即可根据与该文件类型对应的数据结构进行数据解码操作。其中,终端每解码到一块Diff数据或Extra数据之后,就根据这块Diff数据或Extra数据进行文件还原。
参照图4,在Patch文件中,每个control block用于描述一对Diff块和Extra块。由此,终端可以根据control block中记录的内容,获取相应的Diff数据以及Extra数据,并基于获取到的Diff数据和Extra数据进行还原处理得到新文件中的数据。
以Patch数据中的Diff01数据和Extra01数据为例,在进行新文件数据还原时:读取 Diff01数据,以及在旧文件中读取与Diff01数据匹配的数据01_old数据,并对Diff01数据和数据01_old数据进行加运算,即可得到数据01_new写入新文件中;读取Extra01数据,作为数据02_new直接写入新文件中。类似的,继续读取Diff02数据,以及在旧文件中读取与Diff02数据匹配的数据02_old数据,并对Diff02数据和数据02_old数据进行加运算,即可得到数据03_new写入新文件中;读取Extra02数据,作为数据04_new直接写入新文件中。以此类推,终端即可基于Patch文件中的Patch数据,以及旧文件中的相关数据得到新文件中的所有数据。
下述以每个control block使用(x,y,z)表示为例,结合图6对基于Patch文件进行还原的流程进行解释说明。
如图6所示,在Patch文件中,control block1中填充的内容为(x1,y1,z1),用于描述Diff块1和Extra块1。其中,Diff块1的字节长度为x1,Extra块1的字节长度为x2。
终端在Patch文件中解析到control block1中填充的(x1,y1,z1)。首先,终端在Patch文件中继续读取x1长度的Diff数据,以及在旧文件中读取x1长度的数据,并将这两段x1长度的数据进行加运算,得到x1长度的新文件数据,写入新文件(或者称为目标文件)中。然后,终端在Patch文件中继续读取y1长度的Extra数据,作为y1长度的新文件数据直接写入新文件中。
示例性的,在如图4所示的文件数据结构中,在头部之后以及控制块1之前,还可以包括control block0,在control block0中填充的是(0,0,z0)。其中,control block0中填充z0,用于在旧文件中确定用于读取x1长度数据的指针偏移量。由于旧文件指针当前位置为旧文件起始位置,则将旧文件指针由旧文件起始位置偏移z0后,即可在旧文件中读取到与x1长度的Diff数据匹配的x1长度的旧文件数据。
类似的,终端继续解析Patch文件,读取control block2中填充的(x2,y2,z2)。首先,终端在Patch文件中继续读取x2长度的Diff数据,以及在旧文件中读取x2长度的数据,并将这两段x2长度的数据进行加运算,得到x2长度的新文件数据,写入新文件中。其中,将旧文件的指针在当前位置的基础上再偏移z1后,即可在旧文件中读取到与x2长度的Diff数据对应的x2长度的旧文件数据。然后,终端在Patch文件中继续读取y2长度的Extra数据,作为y2长度的新文件数据直接写入新文件中。
以此类推,终端即可根据Patch文件和旧文件得到一个新文件,完成一个新文件的还原流程。
这样,终端可以基于升级差分包中的各个Patch文件以及相应的旧文件,实现对各个新文件的还原。
然而,在依据BSDiff算法得到的Patch文件,由于Diff块是基于新文件和旧文件的最长相似子串确定的,Extra块是基于新文件中的新增数据确定的,所以Diff块和Extra块的字节长度是不固定的且无限制的,其字节长度与新旧文件的差异情况有关,可以为几十KB,也可以高达几百甚至上千上万KB。
终端对Patch文件进行还原处理时,其所需的RAM内存空间大小与Diff块或Extra块的字节长度直接相关。Diff块或Extra块的字节长度越大,则终端对其处理时所需的 RAM内存空间就越大。例如,Diff块的字节长度为200KB,则终端至少要分配200KB以上的RAM内存空间以对其进行处理。当终端的RAM内存空间有限时,终端无法或很难满足处理该Diff块或Extra块的需求。由此,基于BSDiff算法得到的Patch文件的数据结构,对轻量级嵌入式设备的固件差分包升级场景极其不友好。
为了解决上述技术问题,以使差分文件还原过程涉及的终端RAM内存消耗能够更小,本实施例提供了一种差分文件的生成方法,该差分文件的生成方法应用于服务器侧。其中,此处提及的服务器可以理解为用于生成差分文件的任意电子设备。
图7示例性的示出了本实施例提供的基于Bsdiff原理的文件差分流程。
同前所述,对比旧文件数据和新文件数据,在二者中确定各个最长的相似子串(即子字符串)。示例性的,新文件数据中的数据01_new为“1010101010101010101”,旧文件数据中的数据01_old为“1010101110101011101”,新文件数据中的数据01_new和旧文件数据中的数据01_old为一个最长的相似子串。又示例性的,新文件数据中的数据03_new和旧文件数据中的数据02_old为另一个最长的相似子串。示例性的,在新文件数据中,介于数据01_new和数据03_new之间为数据02_new,在旧文件数据中没有与数据02_new相似的子串,则数据02_new为在新文件中新增的数据。类似的,在新文件数据中,数据04_new也为新增的数据。
由此,可以根据新文件数据和旧文件数据中的相似子串,计算差异数据(Diff数据),差异数据与新增数据(Extra数据)共同构成增量更新数据(Patch数据)。如图7所示,将新文件中的数据01_new和旧文件中的数据01_old进行减运算,可以得到Patch数据中的Diff数据01;将新文件中的数据03_new和旧文件中的数据02_old进行减运算,可以得到Patch数据中的Diff数据02。同时,可以将新文件中的数据02_new直接作为Patch数据中的Extra01数据,将新文件中的数据04_new直接作为Patch数据中的Extra02数据。以此类推,即可基于新文件数据和旧文件数据得到所有Diff数据和Extra数据,组成Patch数据。
需要指出是,在依据BSDiff算法得到的Patch数据中,Diff数据和Extra数据是成对出现的,在每一块Diff数据后均为一块Extra数据。而且,Patch数据中各对Diff数据和Extra数据的位置偏移与新文件数据是一致的。
在得到Patch数据之后,服务器侧对Patch数据中的各Diff数据以及Extra数据按照分块尺寸(zonesize)对Diff数据以及Extra数据进行数据分块。每个Diff数据分块和Extra数据分块为终端对差分文件进行还原时的最小独立处理数据单元。
其中,zonesize可以根据终端侧RAM内存空间确定,具体可以根据终端侧可用于进行差分文件还原的连续的RAM内存空间的大小确定。zonesize也可以理解为终端在进行Diff数据还原处理时RAM内存空间所支持的最大处理字节数。
继续参照图7,针对Patch数据中的Diff数据01,按照zonesize将其划分为n1个Diff数据分块。在这n1个Diff数据分块中,前(n1-1)个Diff数据分块的数据尺寸(或称字节长度)为zonesize,最后一个Diff数据分块的数据尺寸小于等于zonesize。其中,这n1个Diff数据分块的数据排序与Diff数据01是相同的。类似的,针对Patch数据中 的Extra数据01,也按照zonesize将其划分为n2个Extra数据分块。在这n1个Extra数据分块中,前(n2-1)个Extra数据分块的数据尺寸为zonesize,最后一个Extra数据分块的数据尺寸小于等于zonesize。其中,这n2个Extra数据分块的数据排序与Extra数据01也是相同的。
示例性的,在终端设备用于差分文件还原的RAM内存区域不复用的情况下,针对终端设备用于进行差分文件还原的连续的RAM内存空间,可以将该RAM内存空间划分为第一RAM内存区域、第二RAM内存区域、第三RAM内存区域和第四RAM内存区域,其中,第一RAM内存区域、第二RAM内存区域和第三RAM内存区域共同用于Diff数据分块还原处理涉及的数据存储操作,以及用于Extra数据分块还原处理涉及的数据存储操作,第四RAM内存区域用于数据解压操作。
假设,终端设备用于差分文件还原的RAM内存空间为M,数据压缩算法进行数据解压操作所需的内存空间为N1(也即第四RAM内存区域的内存空间为N1),则第一RAM内存区域、第二RAM内存区域和第三RAM内存区域可以均分剩余RAM内存空间,也即第一RAM内存区域、第二RAM内存区域和第三RAM内存区域的内存空间均为(M-N1)/3。此时,可以将zonesize设置为(M-N1)/3。例如,当M为200KB,N1为20KB时,RAM内存空间的划分情况为:第一RAM内存区域60KB、第二RAM内存区域60KB、第三RAM内存区域60KB、第四RAM内存区域20KB。此时,zonesize=60KB,表示终端设备可以每次对60KB的Diff数据或Extra数据进行数据还原处理。
又示例性的,在终端设备用于差分文件还原的RAM内存区域复用的情况下,可以将RAM内存顺序划分为第一RAM内存区域、第二RAM内存区域、第三RAM内存区域、第四RAM内存区域和第五RAM内存区域,其中,第一RAM内存区域和第三RAM内存区域共同用于Diff数据分块还原处理涉及的数据存储操作,以及用于Extra数据分块还原处理涉及的数据存储操作,第五RAM内存区域用于数据解压操作。第二RAM内存区域位于为第一RAM内存区域和第三RAM内存区域之间,为第一RAM内存区域的安全缓冲区域;第四RAM内存区域位于为第三RAM内存区域和第五RAM内存区域之间,为第三RAM内存区域的安全缓冲区域。
假设,终端设备用于差分文件还原的RAM内存空间为M,数据压缩算法进行数据解压操作所需的内存空间为N1(也即第五RAM内存区域的内存空间为N1),安全缓冲区域所需的内存空间为N2,则第一RAM内存区域和第三RAM内存区域可以均分剩余空间,也即第一RAM内存区域和第三RAM内存区域的内存空间均为(M-N1-N2*2)/2。此时,可以将zonesize设置为(M-N1-N2*2)/2。例如,当M为200KB,N1为16KB,N2为2KB时,RAM内存空间的划分情况为:第一RAM内存区域90KB、第二RAM内存区域2KB、第三RAM内存区域90KB、第四RAM内存区域2KB、第五RAM内存区域16KB。此时,zonesize=90KB,表示终端设备可以每次对90KB的Diff数据或Extra数据进行数据还原处理。
其中,在一些特殊情况下,数据压缩后的数据尺寸要大于数据压缩前的数据尺寸,由于Diff数据分块或Extra数据分块在压缩前的数据尺寸与第一RAM内存区域和第三RAM内存区域的大小相同,一旦Diff数据压缩分块或Extra数据压缩分块的尺寸变大, 则会在第一RAM内存区域或第三RAM内存区域中溢出而影响正常的数据还原处理。由此,设置安全缓冲区域可以有效避免由于Diff数据压缩分块或Extra数据压缩分块尺寸增大溢出RAM内存区域而导致的数据还原异常的问题。
再示例性的,在终端设备用于差分文件还原的RAM内存区域复用的情况下,针对终端设备用于进行差分文件还原的连续的RAM内存空间,可以将该RAM内存空间划分为第一RAM内存区域、第三RAM内存区域和第五RAM内存区域,其中,第一RAM内存区域和第三RAM内存区域共同用于Diff数据分块还原处理涉及的数据存储操作,以及用于Extra数据分块还原处理涉及的数据存储操作,第五RAM内存区域用于数据解压操作。
假设,终端设备用于差分文件还原的RAM内存空间为M,数据压缩算法进行数据解压操作所需的内存空间为N1(也即第三RAM内存区域的内存空间为N1),则第一RAM内存区域和第二RAM内存区域可以均分剩余空间,也即第一RAM内存区域和第二RAM内存区域的内存空间均为(M-N1)/2。此时,可以将zonesize设置为(M-N1)/2。例如,当M为20KB,N1为16KB时,RAM内存空间的划分情况为:第一RAM内存区域2KB、第二RAM内存区域2KB、第三RAM内存区域16KB。此时,zonesize=2KB,表示终端设备可以每次对2KB的Diff数据或Extra数据进行数据还原处理。
在一些极端情况下,如果终端设备可用于进行差分文件还原的连续的RAM内存空间特别小,如20KB等,也可以不设置安全缓冲区域。
关于如何基于终端申请到的RAM内存空间的各个区域进行数据还原的操作,将在后续描述的Patch文件的还原流程中进行详细解释说明,在此不再赘述。
在对Patch数据中的各Diff数据以及Extra数据进行数据分块划分并压缩后,即可对分块划分及压缩后的Patch数据进行数据编码,得到相应的Patch文件。
在本实施例中,用于对Diff数据分块或Extra数据分块进行数据压缩的数据压缩算法,采用内存消耗低、解压速度快的数据压缩算法,例如LZMA(Lempel-Ziv-Markov chain-Algorithm)、miniLZO(Lempel-Ziv-Oberhumer)等无损解压缩算法,以此减小终端设备进行差分文件数据还原时所占用的RAM内存空间。
在图7中示例性的示出了一种Patch文件的数据结构,该数据结构包括总编码头,与多个Diff数据压缩分块和多个Extra数据压缩分块对应的编码信息,以及多个Diff数据压缩分块和多个Extra数据压缩分块。其中,与多个Diff数据压缩分块和多个Extra数据压缩分块对应的编码信息,用于描述多个Diff数据分块被压缩前的总字节长度、多个Extra数据分块被压缩前的总字节长度、各个Diff数据分块被压缩后的字节长度、各个Extra数据分块被压缩后的字节长度,以及在旧文件中读取与Diff数据压缩分块对应的数据的指针偏移量。
其中,总编码头除了包括魔数,还可以包括zonesize字段,zonesize字段的值用于表示Diff数据和Extra数据被划分的分块尺寸,可以用于终端在进行数据还原时与编码信息进行结合以进行数据寻址。示例性的,终端可以基于zonesize字段的值确定旧文件指针的偏移量,以在旧文件中读取与各Diff数据压缩分块分别对应的旧文件数据。又示例性的,终端可以基于zonesize字段的值,以及多个Diff数据分块被压缩前的总字节长度 或多个Extra数据分块被压缩前的总字节长度,确定Diff数据分块的数量或Extra数据分块的数量。
在另一种示例中,总编码头中不包括zonesize字段,而是在各个编码信息中分别设置zonesize字段,本实施例对此不做限定。
在又一种示例中,在各个编码信息中设置Diff数据压缩分块的数量、Extra数据压缩分块的数量、每个Diff数据压缩分块被压缩前后的字节长度,以及每个Extra数据压缩分块被压缩前后的字节长度。
关于Patch文件的数据结构,本实施例对Diff数据压缩分块和Extra数据压缩分块的描述信息(或称编码信息)不做限定,只要终端侧基于相应的描述信息能够实现在Patch文件以及旧文件中进行数据寻址,并基于各个Diff数据压缩分块与各个Extra数据压缩分块还原得到目标文件即可。
图8示例性的示出了本实施例提供的一种Patch文件的数据结构。如图8所示,该Patch文件的数据结构包括头部(Header)、控制块(zone)、Diff数据和Extra数据。
其中,Header包括16个字节,用于填充魔数和zonesize。
每个zone包括24个字节,用于描述多个Diff数据压缩分块和多个Extra数据压缩分块。其中,多个Diff数据压缩分块和多个Extra数据压缩分块,对应于基于BSDiff算法得到的Patch数据中的一对Diff数据和Extra数据。zone中记录的数据,可以作为其描述的多个Diff数据压缩分块和多个Extra数据压缩分块的编码信息。其中,zone的前8个字节可以记录多个Diff数据压缩分块被压缩前对应的Diff数据的总字节长度,以及各个Diff数据压缩分块描述信息(如压缩后的字节长度);zone的中间8个字节可以记录多个Extra数据压缩分块被压缩前对应的Extra数据的总字节长度,以及各个Extra数据压缩分块描述信息(如压缩后的字节长度);zone的后8个字节用于填充指针偏移量,该指针偏移量用于确定在旧文件中读取数据(即用于与Diff数据分块进行加运算的数据)的位置。
在一种可选的实施方式中,zone的后8个字节填充的指针偏移量可以是基于指针当前位置确定的偏移量,并通过偏移量的正负来标识偏移方向。
在另一种可选的实施方式中,zone的后8个字节填充的指针偏移量可以是基于文件起始位置确定的偏移量。
Diff数据中包括一个或多Diff数据压缩分块,每个Diff数据压缩分块用于记录Diff数据分块被压缩后的数据。
Extra数据中包括一个或多个Extra数据数据压缩分块,每个Extra数据压缩分块用于记录Extra数据分块被压缩后的数据。
这样,在Patch文件中,每个Diff数据压缩分块或Extra数据压缩分块均可以作为终端进行数据还原时一个可独立处理的数据单元,以此降低终端进行数据还原时的RAM内存消耗。
在一种可选的实施方式中,当基于Patch数据生成Patch文件时,还可以将每个Diff数据分块以及Extra数据分块分别进行压缩,并对各个数据压缩块添加分块编码信息。其中,分块编码信息可以作为数据压缩分块的块头部,相应的Diff压缩数据或Extra压缩数据作为数据压缩分块的块数据。
以Patch数据中的Diff数据01和Extra数据01为例,图9示例性的示出了一种Patch文件的数据结构。如图9所示,针对Patch数据中的Diff数据01,按照zonesize将其划分为n1个Diff数据分块,并分别对每个Diff数据分块进行压缩,得到相应的Diff数据压缩分块。在Patch文件中,每个Diff数据压缩分块之前填充用于描述该Diff数据压缩分块的编码信息。示例性的,Diff数据压缩分块的编码信息可以包括但不限于Diff数据分块压缩前的数据尺寸(csize)和压缩后的数据尺寸(usize)。
类似的,继续参照图9,针对Patch数据中的Extra数据01,按照zonesize将其划分为n2个Extra数据分块,并分别对每个Extra数据分块进行压缩,得到相应的Extra数据压缩分块。在Patch文件中,每个Extra数据压缩分块之前填充用于描述该Extra数据压缩分块的编码信息。示例性的,Extra数据压缩分块的编码信息可以包括但不限于Extra数据分块压缩前的数据尺寸(csize)和压缩后的数据尺寸(usize)。
关于Patch数据中的其他Diff数据和Extra数据也是如此,在此不再赘述。由此,针对每个Diff数据压缩分块和每个Extra数据压缩分块,终端解析到相应的分块编码信息后,均可以将其作为一个可独立处理的数据单元,以执行数据还原操作。关于如何以Diff数据压缩分块或Extra数据压缩分块为一个数据处理单元进行目标文件还原的操作,将在后续描述的Patch文件的还原流程中进行详细解释说明,在此不再赘述。
需要指出的是,参照图9,编码信息01用于描述的是Diff数据01和Extra数据01,也即描述的是Diff数据压缩分块1-n1压缩前的总数据尺寸,Extra数据压缩分块1-n2压缩前的总数据尺寸,以及用于在旧文件中读取与Diff数据02对应的旧文件数据的指针偏移量。
图10示例性的示出了本实施例提供的一种Patch文件的数据结构。如图10所示,该Patch文件的数据结构包括头部(Header)、控制块(zone)、Diff数据和Extra数据。
其中,Header包括16个字节,用于填充魔数和zonesize。
每个zone包括24个字节,用于描述多个Diff分块压缩数据和多个Extra分块压缩数据。其中,多个Diff分块压缩数据被分块压缩前的Diff数据,以及多个Extra分块压缩数据被分块压缩前的Extra数据,对应于Patch数据中的一对Diff数据和Extra数据。zone中记录的数据,可以作为其描述的多个Diff分块压缩数据和多个Extra分块压缩数据的编码信息。其中,zone的前8个字节可以记录多个Diff分块压缩数据被分块压缩前的Diff数据的总字节长度;zone的中间8个字节可以记录多个Extra压缩数据被分块压缩前的Extra数据的总字节长度;zone的后8个字节用于填充指针偏移量,该指针偏移量用于确定在旧文件中读取数据(用于与Diff数据分块进行加运算的数据)的位置。
示例性的,每个zone可以使用(x,y,z)来表示,其中,x为其描述的多个Diff分块压缩数据被分块压缩前的Diff数据的总字节长度;y为其描述的多个Extra压缩数据被分块压缩前的Extra数据的总字节长度;z为旧文件指针的偏移量,用于确定从旧文件中读取与其所属的zone描述的首个Diff分块数据对应的旧文件数据的指针位置。其中,该指针偏移量可以是基于指针当前位置确定的偏移量,并通过偏移量的正负来标识偏移方向,也可以是基于文件起始位置确定的偏移量,本实施例对此不做限定。
在一种可选的示例中,每个zone也可以单独被压缩,在此将压缩后的zone称之为 控制压缩块。其中,控制压缩块可以包括块头部和块数据,块数据用于记录与zone内容对应的压缩数据,块头部用于记录与该控制压缩块对应的压缩描述信息,压缩描述信息可以包括zone压缩后的数据尺寸(或称控制压缩块的数据尺寸),压缩描述信息可以包括但不限于zone压缩前是数据尺寸(csize)和压缩后的数据尺寸(csize)。
Diff数据中包括一个或多个数据压缩分块,每个数据压缩分块包括块头部和块数据,其中,块数据用于记录Diff数据分块被压缩后的数据,块头部用于记录与该Diff数据分块压缩数据对应的压缩描述信息,压缩描述信息可以包括但不限于Diff数据分块压缩前的数据尺寸(csize)和压缩后的数据尺寸(usize)。其中,压缩描述信息可以只包括Diff数据分块压缩后的数据尺寸(usize),也即只包括Diff数据压缩分块的数据尺寸。
Extra数据中包括一个或多个Extra数据压缩分块,每个Extra数据压缩分块包括块头部和块数据,其中,块数据用于记录Extra数据分块被压缩后的数据,块头部用于记录与该Extra数据分块压缩数据对应的压缩描述信息,压缩描述信息可以包括但不限于Extra数据分块压缩前的数据尺寸(csize)和压缩后的数据尺寸(usize)。其中,压缩描述信息可以只包括Extra数据分块压缩后的数据尺寸(usize),也即只包括Extra数据压缩分块的数据尺寸。
这样,在Patch文件中,每个Diff数据压缩分块或Extra数据压缩分块均可以作为终端进行数据还原时一个可独立处理的数据单元,以此降低终端进行数据还原时的RAM内存消耗。
需要指出的是,本申请实施例提供的Patch文件仅为示例性的表达,对此不做限定。
在一种示例中,在上述Patch文件的数据结构的基础上,Header中除了填充zonesize字段外,还可以填充数据压缩分块最大字节长度(LengthMAX)字段,该字段的值用于指示各个数据压缩分块(包括Diff数据压缩分块和Extra数据压缩分块)的最大数据尺寸。
如果每个zone也单独被压缩,则LengthMAX字段的值用于指示各个数据压缩分块(包括控制压缩块、Diff数据压缩分块和Extra数据压缩分块)的最大数据尺寸。
终端对Patch文件进行解析时,可以基于LengthMAX字段的值判断接收到的Patch文件是否有误。例如,假设Patch文件中某个Diff数据压缩分块或Extra数据压缩分块尺寸超过LengthMAX字段的值,终端则可以确定该Patch文件有误。
在又一种示例中,在上述Patch文件的数据结构的基础上,Header中除了填充zonesize字段外,还可以填充目标文件数据总长度(NewfileLength)字段,该字段的值用于指示基于该Patch文件还原得到的目标文件的数据总长度。
终端在基于Patch文件进行目标文件还原时,可以基于NewfileLength字段的值判断还原得到目标文件是否正确。例如,假设基于Patch文件进行数据还原得到的目标文件的数据长度小于或大于NewfileLength字段的值,终端则可以确定还原得到的目标文件有误。
在另一种示例中,在上述Patch文件的数据结构的基础上,上述Patch文件的数据结构中还可以包括尾部,该尾部中可以填充校验字段,该校验字段的值用于指示基于该Patch文件还原得到的目标文件的哈希值。
终端在基于Patch文件进行目标文件还原时,还可以基于校验字段的值判断还原得到目标文件是否正确。例如,假设基于Patch文件进行数据还原得到的目标文件的哈希值,与校验字段的值不同,终端则可以确定还原得到的目标文件有误。
上述以生成一个Patch文件为进行解释说明,同理也可以基于其他成对的新旧固件文件生成对应的Patch文件,以此得到与差分升级包对应的各个Patch文件。进而,当终端向服务器请求下载升级差分包时,服务器可以将对这些Patch文件进行打包生成相应的差分升级包,并将差分升级包通过无线网络发送至终端。
在本实施例提供的差分文件的生成方法中,对基于BSDiff算法得到的Patch数据重新进行数据编码,将Diff数据和Extra数据基于zonesize进行分块压缩,以使对Patch文件进行还原时最小数据处理单元的大小可控,其中,zonesize可以根据轻量级嵌入式设备的RAM内存空间灵活设置,这样能够更好地适用于轻量级嵌入式设备的固件升级场景。
考虑到终端侧进行差分文件还原时,申请的RAM内存空间中可以包括安全缓冲区域,本实施例还提供了一种基于zonesize对Diff数据与Extra数据进行分块划分的方法。
图11a示例性的示出了本实施例提供的基于Bsdiff原理的文件差分流程。
其中,图11a和图7所示的文件差分流程是一致的,区别在于Diff数据分块与Extra数据分块进行划分方式。在此未尽详细解释之处,可以参见前述,不再赘述。
参照图11a,以Patch数据中的Diff数据01为例,按照zonesize将其划分为n1个Diff数据分块。在这n1个Diff数据分块中,前(n1-1)个Diff数据分块的数据尺寸(或称字节长度)为zonesize,最后一个Diff数据分块的数据尺寸可能会大于zonesize。其中,这n1个Diff数据分块的数据排序与Diff数据01是相同的。类似的,针对Patch数据中的Extra数据01,也按照zonesize将其划分为n2个Extra数据分块。在这n1个Extra数据分块中,前(n2-1)个Extra数据分块的数据尺寸为zonesize,最后一个Extra数据分块的数据尺寸可能会大于zonesize。其中,这n2个Extra数据分块的数据排序与Extra数据01也是相同的。
继续参照图11b中(1),继续以Diff数据01为例,按照zonesize将其划分为(n1+1)个Diff数据分块。在这(n1+1)个Diff数据分块中,前n1个Diff数据分块的数据尺寸为zonesize,第(n1+1)个Diff数据分块的数据尺寸远小于zonesize。示例性的,第(n1+1)个Diff数据分块的数据尺寸小于安全缓冲区域数据尺寸的预设比例。例如,第(n1+1)个Diff数据分块的数据尺寸小于安全缓冲区域数据尺寸的50%。其中,安全缓冲区域指的是终端侧进行差分文件还原时申请的RAM内存空间中划分的安全缓冲区域。
继续参照图11b中(1),在第(n1+1)个Diff数据分块的数据尺寸小于安全缓冲区域数据尺寸的预设比例时,可以对Diff数据分块的划分情况进行调整。也即,可以将第(n1+1)个Diff数据分块用于第n1个Diff数据分块合并后,作为最终划分的第n1个Diff数据分块。此时,在这n1个Diff数据分块中,前(n1-1)个Diff数据分块的数据尺寸为zonesize,最后一个Diff数据分块的数据尺寸大于zonesize。
在第(n1+1)个Diff数据分块的数据尺寸不小于安全缓冲区域数据尺寸的预设比例时,不对Diff数据分块的划分情况进行调整。此时,Diff数据分块的划分情况可以参照 图7,不再赘述。
以Extra数据01为例,亦是如此。如图11b中(2)所示,按照zonesize可以将Extra数据01划分为(n2+1)个Extra数据分块。在这(n2+1)个Extra数据分块中,前n2个Extra数据分块的数据尺寸为zonesize,第(n2+1)个Extra数据分块的数据尺寸远小于zonesize。示例性的,第(n2+1)个Extra数据分块的数据尺寸小于安全缓冲区域数据尺寸的预设比例。例如,第(n2+1)个Extra数据分块的数据尺寸小于安全缓冲区域数据尺寸的50%。
继续参照图11b中(2),在第(n2+1)个Extra数据分块的数据尺寸小于安全缓冲区域数据尺寸的预设比例时,可以对Extra数据分块的划分情况进行调整。也即,可以将第(n2+1)个Extra数据分块用于第n2个Extra数据分块合并后,作为最终划分的第n2个Extra数据分块。此时,在这n2个Extra数据分块中,前(n2-1)个Extra数据分块的数据尺寸为zonesize,最后一个Extra数据分块的数据尺寸大于zonesize。
在第(n2+1)个Extra数据分块的数据尺寸不小于安全缓冲区域数据尺寸的预设比例时,不对Extra数据分块的划分情况进行调整。此时,Extra数据分块的划分情况可以参照图7,不再赘述。
可以理解的,关于任意一个Diff数据或Extra数据,将其按照zonesize划分数据分块时,最后一个数据分块的尺寸是否大于zonesize,是与Diff数据或Extra数据的长度有关的。
此处关于差分文件的数据结构,以及生成流程等未尽详细解释之处,可以参见前文,在此不再赘述。
当终端侧基于Patch文件进行数据还原操作时,终端可以基于zone中记录多个Diff数据压缩分块被压缩前对应的Diff数据的总字节长度,zonesize的值,以及申请的安全缓冲区的数据尺寸,计算是否存在字节长度大于zonesize的Diff数据分块,以及各Diff数据分块的字节长度。类似的,终端可以基于zone中记录多个Extra数据压缩分块被压缩前对应的Extra数据的总字节长度,zonesize的值,以及申请的安全缓冲区的数据尺寸,计算是否存在字节长度大于zonesize的Extra数据分块,以及各Extra数据分块的字节长度。
在一种可选的实施方式中,也可以在Patch文件的头部中设置标志字段,该标志字段的值用于指示是否存在字节长度大于zonesize的数据分块(包括Diff数据分块和Extra数据分块)。
当终端侧基于Patch文件进行数据还原操作时,通过解析Patch文件的头部中标志字段的值,即可判断出是否存在字节长度大于zonesize的数据分块(包括Diff数据分块和Extra数据分块)。
与本实施例提供的差分文件的生成方法相对应的,本实施例还提供了一种差分文件的还原方法,该差分文件的还原方法应用于终端侧。其中,此处提及的终端可以理解需要对差分文件进行还原操作的任意电子设备,例如智能手机、智能手表、智能手环等,再例如是任意物联网节点设备。
图12示例性的示出了本实施例提供的基于Patch文件进行目标文件还原的流程。
参照图12,对Patch文件进行数据解码,得到对应的Patch数据。此处对Patch文件数据进行解码的过程可以理解为对Patch数据进行数据编码的逆过程。
参照图12,Patch文件的数据结构包括总编码头,与多个Diff数据压缩分块和多个Extra数据压缩分块对应的编码信息,以及多个Diff数据压缩分块和多个Extra数据压缩分块。其中,与多个Diff数据压缩分块和多个Extra数据压缩分块对应的编码信息,用于多个Diff数据压缩分块和多个Extra数据压缩分块进行描述,以使终端可以根据编码信息进行数据寻址。其中,关于Patch文件的数据结构可以参照上文关于图8的解释说明,在此不再赘述。
当终端获取到Patch文件时,对Patch文件的header进行解析,根据header中记录的魔数和zonesize获知文件类型及数据分块尺寸之后,即可根据该数据分块尺寸申请RAM内存空间以用于差分文件还原处理,并根据与该文件类型对应的数据结构进行数据解码操作。
其中,终端每解压到一个Diff数据分块或Extra数据分块之后,就根据这个Diff数据分块或Extra数据分块进行目标文件还原。
继续参照图12,在对Patch文件进行数据解码得到的Patch数据中,Diff数据和Extra数据是成对出现的,在每一块Diff数据后均为一块Extra数据。而且,Patch数据中各对Diff数据和Extra数据的排序与新文件数据是一致的。其中,每块Diff数据中包括多个解压后的Diff数据分块,每块Extra数据中包括多个解压后的Extra数据分块。其中,终端基于Patch数据进行目标文件还原时,分别基于每个Diff数据分块或Extra数据分块进行数据还原操作。
参照图8,在Patch文件中,每个zone用于描述多个Diff数据压缩分块和多个Extra数据压缩分块。由此,终端可以根据zone中记录的内容,获取到各个Diff数据压缩分块和Extra数据压缩分块,进行解压操作,并基于解压得到的Diff数据分块和Extra数据分块进行还原处理得到新文件中的数据。
继续参照图12,以终端基于编码信息01描述的各个Diff数据压缩分块(与Diff数据01对应)和Extra数据压缩分块(与Extra数据01)进行数据还原操作为例,进行解释说明。终端首先对Diff数据01压缩分块1进行解压,得到Diff数据01分块1,Diff数据01分块1的字节长度等于zonesize。终端在基于Diff数据01分块1进行数据还原操作时,读取Diff数据01分块1的Diff数据,以及在旧文件中读取与Diff数据01分块1匹配的旧文件数据(字节长度等于zonesize),并对Diff数据01分块1中的Diff数据和匹配的旧文件数据进行加运行,即可得到与Diff数据01分块1对应的新文件数据(字节长度等于zonesize),写入到新文件中。类似的,终端继续对Diff数据01压缩分块2进行解压,并基于解压得到的Diff数据01分块2进行数据还原,直至还原处理完成Diff数据01压缩分块n1。其中,对Diff数据01压缩分块n1解压得到的Diff数据01分块的字节长度小于等于zonesize。
接下来,终端继续对Extra数据01压缩分块1进行解压,得到Extra数据01分块1,Extra数据01分块1的字节长度等于zonesize。终端在基于Extra数据01分块1进行数 据还原操作时,读取Extra数据01分块1的Extra数据,并将这些数据直接写入新文件中。类似的,终端继续对Extra数据01压缩分块2进行解压,并基于解压得到的Extra数据01分块2进行数据还原,直至还原处理完成Extra数据01压缩分块n2。其中,对Extra数据01压缩分块n2解压得到的Extra数据02分块的字节长度小于等于zonesize。
至此,终端完成基于Diff数据01和Extra数据01的目标文件还原。关于终端基于其他Diff数据和Extra数据进行目标文件还原的操作亦是如此,以此类推,终端即可基于Patch文件中的各个Diff数据压缩分块和各个Extra数据压缩分块,以及旧文件中的相关数据得到新文件中的所有数据。
下述以每个zone使用(x,y,z)表示为例,结合图13对基于Patch文件进行还原的流程进行解释说明。
其中,在本示例中,z表示自文件起始位置的指针偏移量。
如图13所示,在Patch文件中,zone1中填充的内容为(x1,y1,z1),用于描述Diff数据01压缩分块1、Diff数据01压缩分块2、Extra数据01压缩分块1和Extra数据01压缩分块2。其中,Diff数据01压缩分块1和Diff数据01压缩分块2被解压后得到的Diff数据的字节总长度为x1,Diff数据01压缩分块1被解压后得到的Diff数据01分块1的字符长度为m(假设zonesize=m),Diff数据01压缩分块2被解压后得到的Diff数据01分块2的字节长度为x1-m(x1-m≤m);Extra数据01压缩分块1和Extra数据01压缩分块2被解压后得到的Extra数据的字节总长度为y1,Extra数据01压缩分块1被解压后得到的Extra数据01分块1的字符长度为m,Extra数据01压缩分块2被解压后得到的Extra数据01分块2的字符长度为y1-m(y1-m≤m)。
终端在Patch文件中解析到zone1中填充的(x1,y1,z1)。首先,终端在Patch文件中继续Diff数据01压缩分块1,对Diff数据01压缩分块1进行解压得到m长度的Diff数据,以及在旧文件中读取m长度的数据,并将这两段m长度的数据进行加运算,得到m长度的新文件数据,写入新文件(或者称为目标文件)中。其中,旧文件指针自文件起始位置偏移z1后,终端即可在旧文件中读取与m长度的Diff数据(Diff数据01压缩分块1)对应的m长度的旧文件数据。然后,终端在Patch文件中继续读取Diff数据01压缩分块2,对Diff数据01压缩分块2进行解压得到(x1-m)长度的Diff数据,以及在旧文件中继续读取(x1-m)长度的数据,并将这两段(x1-m)长度的数据进行加运算,得到(x1-m)长度的新文件数据,写入新文件中。其中,终端即可在旧文件中读取与m长度的Diff数据对应的m长度的旧文件数据之后,旧文件指针继续向前偏移了m,此时终端即可基于指针当前位置继续在旧文件中读取与(x1-m)长度的Diff数据对应的(x1-m)长度的旧数据。
至此,zone1描述的各个Diff数据01压缩分块已处理完成。
终端在Patch文件中继续读取Extra数据01压缩分块1,对Extra数据01压缩分块1进行解压得到m长度的Extra数据,直接写入新文件中。终端在Patch文件中继续读取Extra数据01压缩分块2,对Extra数据01压缩分块2进行解压得到(y1-m)长度的Extra数据,直接写入新文件中。
至此,zone1描述的各个Extra数据01压缩分块也已处理完成。
接下来,终端继续在Patch文件中读取到zone2中填充的(x2,y2,z2)。在Patch文件中,zone2用于描述Diff数据02压缩分块1和其他Diff数据02压缩分块2,以及各个Extra数据02压缩分块。终端在Patch文件中继续Diff数据02压缩分块1,对Diff数据02压缩分块1进行解压得到m长度的Diff数据,以及在旧文件中读取m长度的数据,并将这两段m长度的数据进行加运算,得到m长度的新文件数据,继续写入新文件(或者称为目标文件)中。其中,为了使终端可以在旧文件中读取到与m长度的Diff数据(Diff数据02压缩分块1)对应的m长度的旧文件数据,需要基于旧文件起始位置和z2重新确定旧文件指针。也即,旧文件指针自文件起始位置偏移z2后,终端即可在旧文件中读取与m长度的Diff数据(Diff数据01压缩分块1)对应的m长度的旧文件数据。
类似的,终端继续对zone2描述的Diff数据02压缩分块以及Extra数据02压缩分块进行数据还原处理。
同理,当终端完成对所有zone描述的Diff数据压缩分块以及Extra数据压缩分块的数据还原处理之后,即可完成新文件的还原流程。
下述分别对终端基于Diff数据压缩分块以及Extra数据压缩分块进行数据还原时的RAM内存占用情况进行解释说明。
需要指出的是,当终端设备进行差分文件还原时,可以申请连续的RAM内存空间,也可以申请不连续的RAM内存空间,本实施例对此不做限定。
其中,当终端设备申请不连续的RAM内存空间时,如果RAM内存区域复用,则可以申请两块尺寸与zonesize相同的RAM内存区域,以及一块用于运行数据压缩算法的RAM内存区域(尺寸与数据压缩算法有关)。当终端设备申请不连续的RAM内存空间时,如果RAM内存区域不复用,则可以申请三块尺寸与zonesize相同的RAM内存区域,以及一块用于运行数据压缩算法的RAM内存区域(尺寸与数据压缩算法有关)。
在一种可选的实施方式中,如果RAM内存区域复用,则可以申请两块尺寸为(zonesize+N2)的RAM内存区域,以及一块用于运行数据压缩算法的RAM内存区域(尺寸与数据压缩算法有关)。其中,N2为安全缓冲区域的数据尺寸。
类似的,如果RAM内存区域不复用,则可以申请三块尺寸为(zonesize+N2)的RAM内存区域,以及一块用于运行数据压缩算法的RAM内存区域(尺寸与数据压缩算法有关)。其中,N2为安全缓冲区域的数据尺寸。
由于申请不连续的RAM内存空间,容易产生RAM内存碎片,造成RAM空间浪费,故在本实施例中以终端设备申请连续的RAM内存空间为例进行解释说明。
其中,当终端获取到Patch文件时,对Patch文件的header进行解析,获取到数据分块尺寸(zonesize)的值之后,即可基于zonesize的值申请一块连续的RAM内存空间,用于进行差分数据还原操作。
在一种可能的实施方式中,RAM内存区域不复用,终端为进行Patch还原操作申请连续的一块RAM内存空间,该RAM内存空间的大小为3*zonesize+N1(字节),其中,N1字节为运行数据压缩算法所需的RAM内存空间的尺寸大小。其中,终端可以将该RAM内存空间划分为四个RAM内存区域,分别为第一RAM内存区域201、第二RAM内存区域202、第三RAM内存区域203和第四RAM内存区域204,参照图14和图15 所示。其中,第一RAM内存区域201、第二RAM内存区域202、第三RAM内存区域203的尺寸大小相等,均为zonesize(字节),第四RAM内存区域204的尺寸大小为N1字节。
示例性的,用于对Diff数据压缩分块或Extra数据压缩分块进行数据压缩的数据压缩算法,可以采用LZMA。以支持LZMA运行所需的RAM内存空间最小为16KB为例,则可以设置N1=16。假设zonesize=60KB,则在本实施方式中,终端可以为进行Patch还原操作申请连续的一块M字节的RAM内存空间,M=60*3+16=196KB。
其中,第一RAM内存区域201、第二RAM内存区域202、第三RAM内存区域203共同用于Diff数据分块还原处理涉及的数据存储操作,包括但不限于存储Diff数据压缩分块、存储解压后的Diff数据分块,存储加运算后得到的新文件数据分块(New数据分块),以及用于Extra数据分块还原处理涉及的数据存储操作,包括但不限于存储Extra数据压缩分块、存储解压后的Extra数据分块;第四RAM内存区域204用于数据解压操作。
示例性的,参照图14,在T0时刻,终端申请到第一RAM内存区域201、第二RAM内存区域202、第三RAM内存区域203和第四RAM内存区域204。在T1时刻,终端在Patch文件中读取到Diff数据01压缩分块1,将Diff数据01压缩分块1写入第一RAM内存区域201中。接下来,终端调用数据压缩算法对第一RAM内存区域201中的Diff数据01压缩分块1进行解压,数据压缩算法执行解压过程使用的RAM内存区域为第四RAM内存区域204,并将解压得到的数据写入第二RAM内存区域202中。在T2时刻,对Diff数据01压缩分块1解压完成,第二RAM内存区域202中暂存的是Diff数据01分块1(字节长度为zonesize)。接下来,终端在运行态镜像文件(相当于未升级的旧文件)中读取与Diff数据01分块1对应的Old数据01分块1(字节长度为zonesize),并暂存在第三RAM内存区域203中,如T3时刻所示。在T3时刻,终端在第三RAM内存区域203中读取Old数据01分块1,以及在第二RAM内存区域202中读取Diff数据01分块1,进行加运算。其中,终端可以对Diff数据01分块1和Old数据01分块1进行加等操作,以使加运算得到的New数据01分块1可以写在第二RAM内存区域202中,对第二RAM内存区域202中暂存的Diff数据01分块1进行覆盖。进而,在T4时刻,终端可以在第二RAM内存区域202中读取New数据01分块1写入静止态镜像文件(或者新建的一个文件)中。其中,静止态镜像文件可以理解为运行态镜像文件的备份。
需要指出的是,某个RAM内存区域中暂存的数据可以被覆盖,也可以被清空,本实施例对比不做限定。例如,在第三RAM内存区域203中读取Old数据01分块1,以及在第二RAM内存区域202中读取Diff数据01分块1,进行加运算时,可以将运算结果直接写入第一RAM内存区域201,对其暂存的Diff数据01压缩分块1进行覆盖。再例如,在对第一RAM内存区域201中暂存的Diff数据01压缩分块1进行解压之后,可以清空第一RAM内存区域201中暂存的数据,进而,在第三RAM内存区域203中读取Old数据01分块1,以及在第二RAM内存区域202中读取Diff数据01分块1,进行加运算时,可以将运算结果直接写入第一RAM内存区域201。
至此,终端完成基于Diff数据01压缩分块1的数据还原操作。同理,终端可以继续 基于Diff数据01压缩分块2继续进行数据还原操作。其中,若Diff数据01压缩分块2为Diff数据01的最后一个压缩分块,则对其解压得到的Diff数据01分块2字节长度小于等于zonesize。
当终端基于Diff数据01包括的各个Diff数据01压缩分块完成数据还原操作时,即可继续基于Extra数据01包括的各个Extra数据01压缩分块进行数据还原操作。
示例性的,参照图15,在T5时刻,终端在Patch文件中读取到Extra数据01压缩分块1,将Extra数据01压缩分块1写入第一RAM内存区域201中。接下来,终端调用数据压缩算法对第一RAM内存区域201中的Extra数据01压缩分块1进行解压,数据压缩算法执行解压过程使用的RAM内存区域为第四RAM内存区域204,并将解压得到的数据写入第二RAM内存区域202中。在T6时刻,对Extra数据01压缩分块1解压完成,第二RAM内存区域202中暂存的是Extra数据01分块1(字节长度为zonesize)。进而,在T6时刻,终端可以在第二RAM内存区域202中读取Extra数据01分块1继续写入静止态镜像文件中。此时,静止态镜像文件中的数据还原到New数据01分块3。
至此,终端完成基于Extra数据01压缩分块1的数据还原操作。同理,终端可以继续基于Extra数据01压缩分块2继续进行数据还原操作。其中,若Extra数据01压缩分块2为Extra数据01的最后一个压缩分块,则对其解压得到的Extra数据01分块2字节长度小于等于zonesize。以此类推,当静止态镜像文件中的数据被写满时,终端完成基于Patch文件的数据还原操作。
在此种实施方式中,也可以考虑为RAM内存区域设置安全缓冲区,本实施例对此不做限定。示例性的,终端为进行Patch还原操作申请连续的一块RAM内存空间,该RAM内存空间的大小为3*zonesize+3*N2+N1(字节)。其中,N2字节为安全缓冲区所占的RAM内存空间的尺寸大小。关于此种实施方式,在此不再赘述。
在另一种可能的实施方式中,RAM内存区域复用,终端为进行Patch还原操作申请连续的一块RAM内存空间,该RAM内存空间的大小为2*zonesize+2*N2+N1(字节),N1字节为运行数据压缩算法所需的RAM内存空间的尺寸大小,N2字节为安全缓冲区所占的RAM内存空间的大小。其中,终端可以将该RAM内存空间划分为五个RAM内存区域,分别为第一RAM内存区域301、第二RAM内存区域302、第三RAM内存区域303、第四RAM内存区域304和第五RAM内存区域305,参照图16和图17所示。其中,第一RAM内存区域301、第三RAM内存区域303的尺寸大小相等,均为zonesize(字节);第五RAM内存区域305的尺寸大小为N1字节;第二RAM内存区域302位于为第一RAM内存区域301和第三RAM内存区域303之间,为第一RAM内存区域301的安全缓冲区域,第四RAM内存区域304位于为第三RAM内存区域303和第五RAM内存区域305之间,为第三RAM内存区域304的安全缓冲区域,且第二RAM内存区域302和第四RAM内存区域304的尺寸大小相等,均为N2字节。
示例性的,用于对Diff数据压缩分块或Extra数据压缩分块进行数据压缩的数据压缩算法,可以采用LZMA。以支持LZMA运行所需的RAM内存空间最小为16KB为例,则可以设置N1=16。假设zonesize=90KB,N2=2KB,则在本实施方式中,终端可以为进行Patch还原操作申请连续的一块M字节的RAM内存空间,M=90*2+2*2+16=200KB。
其中,第一RAM内存区域301和第三RAM内存区域303共同用于Diff数据分块还原处理涉及的数据存储操作,包括但不限于存储Diff数据压缩分块、存储解压后的Diff数据分块,存储加运算后得到的新文件数据分块(New数据分块),以及用于Extra数据分块还原处理涉及的数据存储操作,包括但不限于存储Extra数据压缩分块、存储解压后的Extra数据分块;第五RAM内存区域304用于数据解压操作。
示例性的,参照图16,在T0时刻,终端申请到第一RAM内存区域301、第二RAM内存区域302、第三RAM内存区域303、第四RAM内存区域304和第五RAM内存区域305。在T1时刻,终端在Patch文件中读取到Diff数据01压缩分块1,将Diff数据01压缩分块1写入第一RAM内存区域301中。接下来,终端调用数据压缩算法对第一RAM内存区域301中的Diff数据01压缩分块1进行解压,数据压缩算法执行解压过程使用的RAM内存区域为第五RAM内存区域304,并将解压得到的数据写入第三RAM内存区域303中。在T2时刻,对Diff数据01压缩分块1解压完成,第三RAM内存区域303中暂存的是Diff数据01分块1(字节长度为zonesize)。接下来,终端在运行态镜像文件(相当于未升级的旧文件)中读取与Diff数据01分块1对应的Old数据01分块1(字节长度为zonesize),并暂存在第一RAM内存区域301中,将Diff数据01压缩分块1进行覆盖,如T3时刻所示。继续参照T3时刻,终端在第一RAM内存区域301中读取Old数据01分块1,以及在第三RAM内存区域303中读取Diff数据01分块1,进行加运算。其中,终端可以对Diff数据01分块1和Old数据01分块1进行加等操作,以使加运算得到的New数据01分块1可以写在第三RAM内存区域303中,对第三RAM内存区域303中暂存的Diff数据01分块1进行覆盖。进而,在T4时刻,终端可以在第三RAM内存区域303中读取New数据01分块1写入静止态镜像文件中。
其中,也可以将加运算得到的New数据01分块1写在第一RAM内存区域301中,对第一RAM内存区域301中暂存的Old数据01分块1进行覆盖。进而,终端可以在第一RAM内存区域301中读取New数据01分块1写入静止态镜像文件中。
至此,终端完成基于Diff数据01压缩分块1的数据还原操作。同理,终端可以继续基于Diff数据01压缩分块2继续进行数据还原操作。其中,若Diff数据01压缩分块2为Diff数据01的最后一个压缩分块,则对其解压得到的Diff数据01分块2字节长度小于等于zonesize。
当终端基于Diff数据01包括的各个Diff数据01压缩分块完成数据还原操作时,即可继续基于Extra数据01包括的各个Extra数据01压缩分块进行数据还原操作。
示例性的,参照图17,在T5时刻,终端在Patch文件中读取到Extra数据01压缩分块1,将Extra数据01压缩分块1写入第一RAM内存区域301中。接下来,终端调用数据压缩算法对第一RAM内存区域301中的Extra数据01压缩分块1进行解压,数据压缩算法执行解压过程使用的RAM内存区域为第五RAM内存区域305,并将解压得到的数据写入第三RAM内存区域303中。在T6时刻,对Extra数据01压缩分块1解压完成,第三RAM内存区域303中暂存的是Extra数据01分块1(字节长度为zonesize)。进而,在T6时刻,终端可以在第三RAM内存区域303中读取Extra数据01分块1继续写入静止态镜像文件中。此时,静止态镜像文件中的数据还原到New数据01分块3。
至此,终端完成基于Extra数据01压缩分块1的数据还原操作。同理,终端可以继续基于Extra数据01压缩分块2继续进行数据还原操作。其中,若Extra数据01压缩分块2为Extra数据01的最后一个压缩分块,则对其解压得到的Extra数据01分块2字节长度小于等于zonesize。以此类推,当静止态镜像文件中的数据被写满时,终端完成基于Patch文件的数据还原操作。
其中,终端申请第二RAM内存区域302,作为第一RAM内存区域301的安全缓冲区,能够第一RAM内存区域301中数据溢出而导致数据处理出错的问题。同理,终端申请第四RAM内存区域304,作为第三RAM内存区域303的安全缓冲区,能够第三RAM内存区域303中数据溢出而导致数据处理出错的问题。
需要指出的是,假设某个Diff数据压缩分块或Extra数据压缩分块的尺寸大于压缩前的Diff数据分块或Extra数据压缩的尺寸时,将该数据压缩分块暂存到第一RAM内存区域或第三RAM内存区域中时,会造成数据相应地溢出到第二RAM内存区域或第四RAM内存区域中的情形。此时,终端设备对该数据压缩分块进行数据解压处理时,需要一并对溢出到第二RAM内存区域或第四RAM内存区域中的数据进行解压处理,以此保证解压得到的Diff数据分块或Extra数据分块的正确性。
当终端设备申请用于差分数据还原的连续的RAM内存空间为某个确定值时,相比RAM内存区域不复用的情况,RAM内存区域复用能够提高数据还原处理效率。
当终端可分配用于差分数据还原处理的RAM内存空间极小时,终端在申请到的RAM内存空间中也可以不划分作为安全缓冲区的第二RAM内存区域302和第四RAM内存区域304。当终端在申请到的RAM内存空间中不划分作为安全缓冲区的第二RAM内存区域302和第四RAM内存区域304时,终端基于Diff数据压缩分块以及Extra数据压缩分块进行数据还原时的RAM内存占用情况也是类似的,在此不再赘述。
示例性的,用于对Diff数据压缩分块或Extra数据压缩分块进行数据压缩的数据压缩算法,可以采用LZMA。以支持LZMA运行所需的RAM内存空间最小为16KB为例,则可以设置N1=16。假设zonesize=2KB,则在本实施方式中,终端可以为进行Patch还原操作申请连续的一块M字节的RAM内存空间,M=2*2+16=20KB。
这样,终端基于Diff数据压缩分块或Extra数据压缩分块进行数据还原操作时,解压操作及数据存储操作均在指定的RAM内存区域中进行,充分有效地利用了RAM内存空间,差分还原操作消耗的RAM内存较小,使得RAM空间较小的轻量级设备也能具备差分还原能力。
对应于图11a-图11b所示的数据分块划分方式,终端对Patch文件进行数据还原时,申请的用于Patch还原操作的RAM内存空间包括安全缓冲区。其中,安全缓冲区的数据尺寸为N2字节。
示例性的,终端申请的RAM内存空间可以是连续的,可以参照图16所示。又示例性的,终端申请的RAM内存空间也可以是非连续的,例如申请三块尺寸为(zonesize+N2)的RAM内存区域,以及一块用于运行数据压缩算法的RAM内存区域(尺寸与数据压缩算法有关)。本实施例对此不做限定。
当终端基于某个zone描述的Diff数据压缩分块或Extra数据压缩分块进行数据还原 操作,可以基于zone中记录多个Diff数据压缩分块被压缩前对应的Diff数据的总字节长度,zonesize的值,以及申请的安全缓冲区的数据尺寸,计算是否存在字节长度大于zonesize的Diff数据分块。
如果不存在字节长度大于zonesize的Diff数据分块,则终端基于多个Diff数据压缩分块进行数据还原的处理流程可以参见前文,在此不再赘述。
假设某个zone描述的最后一个Diff数据压缩分块(如Diff数据01压缩分块n1)被压缩前的Diff数据分块的字节长度大于zonesize,下述对终端基于Diff数据01压缩分块n1进行数据还原处理的流程进行解释说明。
参照图18,在T1时刻,终端在Patch文件中读取到Diff数据01压缩分块n1,将Diff数据01压缩分块n1写入第一RAM内存区域301中。接下来,终端调用数据压缩算法对第一RAM内存区域301中的Diff数据01压缩分块n1进行解压,数据压缩算法执行解压过程使用的RAM内存区域为第五RAM内存区域304,并将解压得到的数据写入第三RAM内存区域303中。在T2时刻,对Diff数据01压缩分块n1解压完成,解压得到Diff数据01分块n1暂存到第三RAM内存区域303中。由于Diff数据01分块n1被压缩前的字节长度大于zonesize,则Diff数据01分块n1不仅将第三RAM内存区域303写满,部分数据还会写入第四RAM内存区域304中。接下来,终端在运行态镜像文件(相当于未升级的旧文件)中读取与Diff数据01分块n1对应的Old数据01分块n1(字节长度大于zonesize),并暂存在第一RAM内存区域301中。其中,Old数据01分块n1不仅将将第一RAM内存区域301写满,部分数据还会写入第二RAM内存区域302中,如T3时刻所示。继续参照T3时刻,终端在第一RAM内存区域301和第二RAM内存区域302中读取Old数据01分块n1,以及在第三RAM内存区域303和第四RAM内存区域304中读取Diff数据01分块n1,进行加运算。其中,终端可以对Diff数据01分块n1和Old数据01分块n1进行加等操作,以使加运算得到的New数据01分块n1可以写在第三RAM内存区域303和第四RAM内存区域304中。进而,在T4时刻,终端可以在第三RAM内存区域303和第四RAM内存区域304中读取New数据01分块n1写入静止态镜像文件中。
假设某个zone描述的最后一个Extra数据压缩分块(如Extra数据01压缩分块n2)被压缩前的Extra数据分块的字节长度大于zonesize,下述对终端基于Extra数据01压缩分块n2进行数据还原处理的流程进行解释说明。
示例性的,参照图19,在T5时刻,终端在Patch文件中读取到Extra数据01压缩分块n2,将Extra数据01压缩分块n2写入第一RAM内存区域301中。接下来,终端调用数据压缩算法对第一RAM内存区域301中的Extra数据01压缩分块n2进行解压,数据压缩算法执行解压过程使用的RAM内存区域为第五RAM内存区域305,并将解压得到的数据写入第三RAM内存区域303中。在T6时刻,对Extra数据01压缩分块n2解压完成,解压得到Extra数据01分块n2暂存到第三RAM内存区域303中。由于Extra数据01分块n2被压缩前的字节长度大于zonesize,则Extra数据01分块n2不仅将第三RAM内存区域303写满,部分数据还会写入第四RAM内存区域304中。进而,在T6时刻,终端可以在第三RAM内存区域303和第四RAM内存区域304中读取Extra数据 01分块n2继续写入静止态镜像文件中。此时,静止态镜像文件中的数据还原到New数据01分块n2。
在一种示例中,如果终端解析到Patch文件的头部中标志字段的值,确定判断出存在字节长度大于zonesize的数据分块(包括Diff数据分块和Extra数据分块),则可以依据如图17和18所示的处理流程进行数据还原处理。
这样,当某个数据分块的尺寸稍大于zonesize,终端也可以借助于安全缓冲区完成相应的数据还原操作。
在一种示例中,Patch文件的数据结构中,Header中除了填充zonesize字段外,还可以填充数据压缩分块最大字节长度(LengthMAX)字段,该字段的值用于指示各个数据压缩分块(包括Diff数据压缩分块和Extra数据压缩分块)的最大数据尺寸。
在此情形下,终端对Patch文件进行解析时,可以基于LengthMAX字段的值判断接收到的Patch文件是否有误。例如,假设Patch文件中某个Diff数据压缩分块或Extra数据压缩分块尺寸超过LengthMAX字段的值,终端则可以确定该Patch文件有误,进而不再基于该Patch文件进行数据还原操作。
在又一种示例中,Patch文件的数据结构中,Header中除了填充zonesize字段外,还可以填充目标文件数据总长度(NewfileLength)字段,该字段的值用于指示基于该Patch文件还原得到的目标文件的数据总长度。
在此情形下,终端在基于Patch文件进行目标文件还原时,可以基于NewfileLength字段的值判断还原得到目标文件是否正确。例如,假设基于Patch文件进行数据还原得到的目标文件的数据长度小于或大于NewfileLength字段的值,终端则可以确定还原得到的目标文件有误,进而不再基于该目标文件进行固件升级。
在另一种示例中,Patch文件的数据结构还可以包括校验字段,该字段的值用于指示基于该Patch文件还原得到的目标文件的哈希值。
终端在基于Patch文件进行目标文件还原时,还可以基于校验字段的值判断还原得到目标文件是否正确。例如,假设基于Patch文件进行数据还原得到的目标文件的哈希值,与校验字段的值不同,终端则可以确定还原得到的目标文件有误,进而不再基于该目标文件进行固件升级。
这样,在本申请实施例中,将Patch数据拆分为大小可控的差分还原单元数据,其数据尺寸与终端RAM空间大小有关,以使终端设备每次只需对一块差分还原单元数据进行处理,进而使得RAM空间有限的轻量级设备也能具备差分还原能力。
上述以一组镜像文件(包括运行态镜像文件和静止态运行文件)为例进行解释说明,同理也可以基于其他Patch文件对应地将其他静止态镜像文件中数据写满,由此得到与升级包对应的所有镜像文件。此时,终端即可基于这些镜像文件进行固件升级。关于终端基于这些镜像文件进行固件升级的解释可以参照已有技术,在此不再赘述。
需要指出的是,在前述差分文件的生成方法实施例中,以Diff数据服务器是基于减运算生成为例进行解释说明的。相应的,在前述差分文件的还原方法实施例中,终端基于加运算对Diff数据进行还原为例进行解释说明的。其中,Diff数据还可以是服务器基 于其他运算生成的,暂且称之为Diff数据是服务器基于第一运算生成的。相应的,终端可以基于第二运算对Diff数据进行还原,第二运算为第一运算的逆运算。本实施例对第一运算和第二运算不做限定。
需要指出的是,在前述差分文件的生成方法实施例以及差分文件的还原方法实施例中,均以固件文件为例进行解释说明。其中,本实施例提供的差分文件的生成方法以及差分文件的还原方法还可以适用于其他文件类型的差分还原处理,例如补丁文件、APK(Android application package,Android应用程序包)等。
另外,本申请实施例提供的差分文件的还原方法,不仅适用于RAM内存空间较小(例如小于第一预设阈值)的轻量级电子设备,还适用于可用于进行差分文件还原的RAM内存空间较小(例如小于第二预设阈值)的其他电子设备。
也就是说,当电子设备的RAM内存空间不小,但其分配用于进行差分文件还原的RAM内存空间较小时,电子设备可以执行本实施例提供的差分文件的还原方法,以使用较小的RAM内存空间来实现对差分文件的还原功能。
图20示例性的示出了一种应用场景。如图20中(1)所示,用户使用手机玩游戏时,界面上弹出对话框700。其中,对话框700中的内容显示“当前检测到xx补丁,是否立即下载并更新”。若用户同意,则可以点击“是”选项701。响应于用户的操作,对话框消失,如图20中(2)所示,用户继续使用手机玩游戏。与此同时,手机后台执行下载xx补丁,基于下载的xx补丁进行差分文件还原的操作,以及基于还原后的补丁文件进行热更新。
在该应用场景中,虽然手机的RAM内存空间不小,但手机分配的用于进行差分文件还原操作的RAM内存空间有限,以不对用户使用手机的体验产生影响。此时,若手机执行本申请实施例提供的差分文件的还原方法,则可以通过较小的RAM内存空间实现差分数据还原功能,同时也不会对用户的使用体验产生影响。
在另外一些应用场景中,假设用户开启了手机的APK自动更新功能,则在用户使用手机的同时,手机后台可能进行APK差分包下载及差分还原操作。虽然手机的RAM内存空间不小,但为了不对用户的使用体验产生影响,手机分配用于进行差分文件还原操作的RAM内存空间通常会较小。此时,若手机执行本申请实施例提供的差分文件的还原方法,则可以通过较小的RAM内存空间实现差分数据还原功能,同时也不会对用户的使用体验产生影响。
然而,在实际应用中,同种终端设备往往存在多个版本,这多个版本的终端设备可能都存在固件升级的诉求,而不同版本的终端设备的硬件配置不一定相同(通常为硬件资源的高低配置)。如果针对每个版本的终端设备,单独开发升级差分包,无疑会增加升级差分包的版本数量,进而增加人工维护成本。因此,为了减少升级差分包的版本数量,可以针对多个版本的终端设备开发相同的升级差分包,满足一包多发的场景诉求,实现不同版本终端设备的升级差分包的统一。
其中,当升级差分包中的差分文件是基于前述方案生成时,如果终端设备分配用于进行差分文件还原的RAM内存空间较大时,如何提升差分文件还原的效率是需要解决 的问题。
为了解决上述问题,本申请实施例还提供了一种差分文件的还原方法。其中,终端设备能够根据用于差分文件还原的RAM内存空间自适应地进行差分文件的还原,以提高差分文件的还原效率。
在前文描述中,参照图13,Patch文件中的各个压缩分块(包括Diff数据压缩分块和Extra数据压缩分块)是被串行处理的。当终端设备分配用于进行差分文件还原的RAM内存空间较大时,压缩分块的还原处理可以被并行执行,以此提升差分文件的还原效率。其中,压缩分块还原处理的并行化与终端设备分配用于进行差分文件还原的RAM内存空间尺寸有关。
如前文所述,参照图16和图17,终端设备可以基于第一RAM内存区域301、第二RAM内存区域302、第三RAM内存区域303、第四RAM内存区域304和第五RAM内存区域305,实现对一个压缩分块(Diff数据压缩分块或Extra数据压缩分块)的还原处理。其中,第一RAM内存区域301、第三RAM内存区域303的尺寸大小相等,均为zonesize(字节);第五RAM内存区域305的尺寸大小为N1字节,用于数据解压操作;第二RAM内存区域302为第一RAM内存区域301的安全缓冲区域,第四RAM内存区域304为第三RAM内存区域304的安全缓冲区域,均为N2字节。
这样,除了能够提供用于数据解压操作的第五RAM内存区域,一组RAM空间(即第一RAM内存区域301、第二RAM内存区域302、第三RAM内存区域303以及第四RAM内存区域304)即可实现对一个压缩分块的还原处理。因此,除了第五RAM内存区域之外,只要终端设备还能够提供多组RAM空间,即可实现对多个压缩分块还原处理的并行化,以提升差分文件的还原效率。
例如,参照图21a,第一组RAM空间用于第一还原线程进行压缩分块(Diff数据压缩分块或Extra数据压缩分块)的还原处理,第二组RAM空间用于第二还原线程进行压缩分块(Diff数据压缩分块或Extra数据压缩分块)的还原处理,第一还原线程和第二还原线程是并行的。这样,当终端设备能够提供多组RAM空间时,终端设备就可以通过并行的多个还原线程对Diff数据压缩分块或Extra数据压缩分块进行还原处理。
在一种可选的实施方式中,终端设备用于差分文件还原处理的RAM空间为静态数组,可以在该静态数组中分别划分与每个还原线程对应的一组RAM空间,以使每个还原线程基于对应的一组RAM空间对压缩分块(Diff数据压缩分块或Extra数据压缩分块)进行还原处理。
示例性的,如图21a所示,在静态数组中依次划分各组RAM空间(包括第一RAM内存区域301、第二RAM内存区域302、第三RAM内存区域303和第四RAM内存区域304)以及第五RAM内存区域305,其中,一组RAM空间对应于一个还原线程。
又示例性的,如图21b所示,在静态数组中依次划分第一RAM部分、第二RAM部分以及第五RAM内存区域305。在第一RAM部分中,依次划分多对第一RAM内存区域301和第二RAM内存区域302;在第二RAM部分中,依次划分多对第三RAM内存区域303和第四RAM内存区域304。其中,一对第一RAM内存区域301和第二RAM内存区域302,以及一对第三RAM内存区域303和第四RAM内存区域304,对应于一 个还原线程。
需要指出的是,上述RAM空间的划分仅为示例性的举例说明,本实施例对此不做限定,只要每个还原线程单独对应于一组RAM空间(包括第一RAM内存区域301、第二RAM内存区域302、第三RAM内存区域303和第四RAM内存区域304)即可,就可以实现压缩分块还原的并行化。
本申请实施例中,在对Patch数据的还原过程中,可以以每组增量更新数据作为还原线程独立执行还原操作的单位。其中,一组增量更新数据即为一个控制块(zone)描述的增量更新数据。一般情况下,一组增量更新数据包括Diff数据分块和Extra数据分块,Diff数据分块和Extra数据分块的数量为一个或多个。特殊情况下,一组增量更新数据只包括Diff数据分块或Extra数据分块。
示例性的,终端设备创建并行的第一还原线程和第二还原线程用于Patch数据的还原。如图22所示,第一还原线程用于对zone1描述的压缩分块进行还原处理,第二还原线程用于对zone2描述的压缩分块进行还原处理,第一还原线程用于对zone3描述的压缩分块进行还原处理,第二还原线程用于对zone4描述的压缩分块进行还原处理,以此类推。这样,终端设备即可基于两个并行的还原线程实现对Patch数据的还原处理,提升了Patch数据的还原效率。
其中,每个还原线程对某个zone描述的压缩分块进行还原处理时,按顺序依次对该zone描述的各个Diff数据分块和Extra数据分块进行还原处理。关于还原线程依次对各个Diff数据分块和Extra数据分块进行还原处理的操作,可以参照前文,在此不再赘述。
为了实现Patch数据还原的并行化,本实施例对Patch文件的数据结构进行适应性的调整。图23示例性的示出了本实施例提供的一种Patch文件的数据结构。如图23所示,该Patch文件的数据结构包括头部(Header)、控制块(zone)、Diff数据和Extra数据。其中,关于Diff数据和Extra数据的描述可以参照前文,与图8所示的Patch文件的数据结构相同。
与图8所示的Patch文件的数据结构不同的是,在如图23所示的Patch文件的数据结构中,头部(Header)中还包括控制块(zone)总数量。
与图8所示的Patch文件的数据结构不同的是,在如图23所示的Patch文件的数据结构中,每个zone中不仅包括用于在旧文件中读取数据的第一指针偏移量,还包括在新文件中写入数据的第二指针偏移量。其中,第一指针偏移量是基于旧文件起始位置确定的指针偏移量,第二指针偏移量是基于新文件起始位置确定的指针偏移量。而且,每个zone中还需包括该zone描述的多个Diff数据分块和多个Extra数据分块压缩后的字节长度总和,例如可以是多个Diff数据分块压缩后的字节总长度以及多个Extra数据分块压缩后的字节总长度。
在本实施例中,第一指针偏移量用于在旧文件中读取与该zone描述的首个Diff数据分块对应的旧数据,也即在旧文件中读取用于与该zone描述的首个Diff数据分块进行加运算的旧数据。第二指针偏移量用于确定在新文件中写入与该zone对应的还原数据的首地址。这样,多个还原线程并行处理各个zone描述的数据分块时,可以基于各个zone中的第二指针偏移量确定在新文件中写入与该zone对应的还原数据的首地址。
在本实施例中,一个zone描述的多个Diff数据分块压缩后的字节总长度以及多个Extra数据分块压缩后的字节总长度,可以用于还原线程计算下一个zone在Patch文件中的地址偏移量。也即,该字节总长度,可以用于还原线程在Patch文件中读取数据时,跳过该zone描述的各个数据压缩分块,以读取到下个zone中填充的数据。也即,还原线程可以基于各个zone描述的多个Diff数据分块压缩后的字节总长度以及多个Extra数据分块压缩后的字节总长度,读取到需要其处理的zone描述的数据压缩分块。例如,某个还原线程需要处理zone2描述的各个数据压缩分块的还原操作,则可以根据在zone1中读取到的其描述的多个Diff数据分块压缩后的字节总长度以及多个Extra数据分块压缩后的字节总长度,确定zone1描述的Diff数据压缩分块和Extra数据压缩分块的总字节长度,进而在Patch文件中读取数据时,跳过这些Diff数据压缩分块和Extra数据压缩分块,继而可以读取zone2中填充的数据。类似的,若该还原线程需要处理zone4描述的各个数据压缩分块的还原操作,亦是如此,在此不再赘述。
示例性的,参照图23,每个zone包括32个字节,用于描述多个Diff数据压缩分块和多个Extra数据压缩分块。其中,多个Diff数据压缩分块和多个Extra数据压缩分块,对应于基于BSDiff算法得到的Patch数据中的一对Diff数据和Extra数据。zone中记录的数据,可以作为其描述的多个Diff数据压缩分块和多个Extra数据压缩分块的编码信息。其中,zone的首个8字节可以记录多个Diff数据压缩分块被压缩前后对应的Diff数据的总字节长度,以及各个Diff数据压缩分块描述信息(如压缩后的字节长度);zone的第二个8字节可以记录多个Extra数据压缩分块被压缩前后对应的Extra数据的总字节长度,以及各个Extra数据压缩分块描述信息(如压缩后的字节长度);zone的第三个8字节用于填充第一指针偏移量,第一指针偏移量用于确定在旧文件中读取数据(即用于与Diff数据分块进行加运算的数据)的位置;zone的第四个8字节用于填充第二指针偏移量,第二指针偏移量用于确定在新文件中写入数据(即还原操作所得的数据)的位置。
在另一种可选的实施方式中,每个zone包括32个字节,用于描述多个Diff数据压缩分块和多个Extra数据压缩分块。其中,zone的首个8字节可以记录多个Diff数据压缩分块被压缩前后对应的Diff数据的总字节长度;zone的第二个8字节可以记录多个Extra数据压缩分块被压缩前后对应的Extra数据的总字节长度;zone的第三个8字节用于填充第一指针偏移量,第一指针偏移量用于确定在旧文件中读取数据(即用于与Diff数据分块进行加运算的数据)的位置;zone的第四个8字节用于填充第二指针偏移量,第二指针偏移量用于确定在新文件中写入数据(即还原操作所得的数据)的位置。该zone结构也可以应用于如图10所示的Patch文件的数据结构中,或者也可以应用于本申请实施例提供的Patch文件的其它数据结构中,以使多个还原线程并行处理各个zone描述的数据分块时,可以基于各个zone中的第二指针偏移量确定在新文件中写入与该zone对应的还原数据的首地址。
其中,对于第一指针偏移量和第二指针偏移量在zone中填充的先后顺序,本实施例不做限定。
示例性的,还原线程还可以基于在Patch文件中读取到zone的顺序,确定zone的编号,并基于zone的编号判断该zone描述的各个数据压缩分块是否需要其进行还原处理。
又示例性的,每个zone中还可以填充该zone的编号,以使每个还原线程可以基于读取到的zone编号判断该zone描述的各个数据压缩分块是否需要其进行还原处理。
在一种可选的实施方式中,假设k个还原线程并行处理Patch文件的还原处理,则可以根据zone编号对还原线程数量的取余结果,来判断一个zone描述的各个数据压缩分块是否需要其进行还原处理。
假设zone编号由1开始计数。针对编号为x的zone:如果x%k=1,则该zone描述的各个数据压缩分块由还原线程1进行处理;如果x%k=2,则该zone描述的各个数据压缩分块由还原线程2进行处理;如果x%k=n,0<n≤k-1,则该zone描述的各个数据压缩分块由还原线程n进行处理;如果x%k=0,则该zone描述的各个数据压缩分块由还原线程k进行处理。其中,%表示取余操作。
假设zone编号由0开始计数。针对编号为x的zone:如果x%k=0,则该zone描述的各个数据压缩分块由还原线程1进行处理;如果x%k=1,则该zone描述的各个数据压缩分块由还原线程2进行处理;如果x%k=n,0<n<k-1,则该zone描述的各个数据压缩分块由还原线程n+1进行处理;如果x%k=k-1,则该zone描述的各个数据压缩分块由还原线程k进行处理。
在另一种可选的实施方式中,假设zone数量为x,可以将这x个平均划分为k份,第一份对应的各个zone描述的数据压缩分块由还原线程1进行处理,第二份对应的各个zone描述的数据压缩分块由还原线程2进行处理,以此类推。
这样,就可以确定出与每个还原线程对应的zone编号。其中,与某个还原线程对应的zone编号,意味着该zone描述的各个数据压缩分块需要该还原线程进行处理。
在本实施例中,可以根据zone编号对还原线程数量的取余结果,为并行的k个还原线程分别创建还原操作执行链表。其中,在每个还原操作执行链表中,各个节点中填充的数据为zone编号以及在该zone在Patch文件中的地址偏移量。其中,zone在Patch文件中的地址偏移量,可以指的是相对于文件起始位置的地址偏移量。需要指出的是,各个zone在Patch文件中的地址偏移量,可以根据zone编号以及各个zone描述的数据压缩分块的字节总长度进行计算。例如,zone2相对于文件起始位置的地址偏移量为zone1相对于文件起始位置的地址偏移量与zone1描述的数据压缩分块的字节总长度的累加和,zone3相对于文件起始位置的地址偏移量为zone2相对于文件起始位置的地址偏移量与zone2描述的数据压缩分块的字节总长度的累加和,以此类推。
进而,各个还原线程可以基于对应还原操作执行链表中各节点的数据,在Patch文件中读取相应的zone,并对该zone描述的数据压缩分块进行数据还原处理。
本申请实施例提供了一种差分文件的还原方法。其中,该差分文件的还原方法的流程具体包括:
S501,电子设备解析Patch文件,获取分块尺寸zonesize以及控制块总数量x。
示例性的,分块尺寸zonesize以及控制块(zone)总数量x可以在Patch文件的header中携带。
电子设备获取到Patch文件之后,对Patch文件的header进行解析,根据header中记录的魔数获知文件类型之后,即可在header读取zonesize以及控制块总数量x。
S502,电子设备根据用于差分还原的RAM空间尺寸M以及zonesize,判断电子设备是否支持差分文件的还原处理,若是,则执行S503,若是,则进行报错处理。
电子设备根据zonesize可以计算得到对Patch文件进行还原操作所需的最小RAM空间,如果电子设备用于差分还原的RAM空间尺寸M小于还原操作所需的最小RAM空间,则电子设备可以判断出其无法支持差分文件的还原处理,进行报错处理。
如果电子设备用于差分还原的RAM空间尺寸M大于等于还原操作所需的最小RAM空间,则电子设备可以判断出其能够支持差分文件的还原处理。
如前文所述,对Patch文件进行还原操作所需的最小RAM空间为(zonesize+N2)*2+N1。其中,N1为运行数据压缩算法所需的RAM内存空间的尺寸大小,N2为安全缓冲区所占的RAM内存空间的大小。示例性的,N2=2KB,N1=16KB。
如果电子设备用于差分还原的RAM空间尺寸M大于等于((zonesize+N2)*2+N1,则电子设备可以判断出其能够支持差分文件的还原处理。
需要指出的是,此处提及的电子设备用于差分还原的RAM空间是连续的,例如通过静态数组实现。如果电子设备用于差分还原的RAM空间是动态分配的非连续的,则需要电子设备申请到两块尺寸为(zonesize+N2)的RAM内存区域,以及一块尺寸为N1的RAM内存区域,以使电子设备能够差分文件的还原处理。
S503,电子设备根据M以及zonesize,确定还原线程的并行数量k。
当电子设备用于差分还原的RAM空间尺寸M较大时,电子设备可以通过几个并行的还原线程完成对Patch文件的还原操作,以提升Patch文件的还原效率。
当电子设备用于差分还原的RAM空间M为连续RAM空间(如静态数组)时,则还原线程的并行数量k=[(M-N1)/(zonesize+N2)]。其中,[]表示取整操作。如果并行数量k≥2,则电子设备可以通过k个还原线程并行地对Patch文件中的数据压缩分块进行还原处理。
当电子设备用于差分还原的RAM空间为非连续RAM空间时,则电子设备可以动态申请RAM空间,如果能够申请到2k(k≥2)块尺寸为(zonesize+N2)的RAM内存区域,以及一块尺寸为N1的RAM内存区域,则电子设备可以通过k个还原线程并行地对Patch文件中的数据压缩分块进行还原处理。
S504,电子设备判断k是否大于等于2,若否,则执行S505,若是,则执行S506。
其中,k不大于等于2时,由于在此之前已判断出电子设备支持差分文件的还原处理,则k=1,电子设备通过单线程执行差分文件的还原处理。
S505,电子设备通过单线程执行差分文件的还原处理。
当电子设备通过单线程执行差分文件的还原处理时,Patch文件中各个zone描述的数据压缩分块依次被串行处理,可以参照前文的相关描述,在此不再赘述。
S506,电子设备创建k个还原线程。
电子设备根据确定的并行数量k,创建相应数量的还原线程,以实现Patch文件中不同zone描述的数据压缩分块的并行还原处理。
S507,电子设备划分与每个还原线程对应的一组RAM空间,并根据控制块总数量x创建与每个还原线程对应的还原操作链表。
示例性的,假设并行数量k=2,电子设备创建第一还原线程和第二还原线程,以用于对Patch文件中不同zone描述的数据压缩分块进行并行还原处理。
针对每个还原线程,电子设备需要为其划分与其对应的一组RAM空间,包括第一RAM空间区域301、第二RAM空间区域302、第三RAM空间区域303、第四RAM空间区域304,可以参照图21a或图21b。
针对每个还原线程,电子设备还需要为其创建与其对应的还原操作链表。如前文所述,可以根据zone编号与还原线程数量k的取余结果,确定与每个还原线程对应的zone编号。进而,在电子设备确定各个zone在Patch文件中的地址偏移量之后,即可创建与每个还原线程对应的还原操作链表。其中,在还原操作链表中,各个节点的数据(data)部分中填充的是zone编号以及该编号对应的zone在Patch文件中的地址偏移量。
示例性的,以第一还原线程为例,与其对应的zone编号为zone1、zone3、zone5等,则在与其对应的还原操作列表中,第一节点的数据(data)部分中填充的是zone1以及zone1在Patch文件中的地址偏移量1,链接(next)部分填充的是第二节点的指针;第二节点的数据(data)部分中填充的是zone3以及zone3在Patch文件中的地址偏移量3,链接(next)部分填充的是第三节点的指针;第三节点的数据(data)部分中填充的是zone5以及zone5在Patch文件中的地址偏移量5,链接(next)部分填充的是第四节点的指针,以此类推。
S508,电子设备的每个还原线程根据对应的还原操作链表中各节点中的数据,在Patch文件中读取相应的数据压缩分块,并利用对应的一组RAM空间对这些数据压缩分块进行还原操作。
针对还原操作链表中一个节点,还原线程依次对与该节点对应的zone描述的各个数据压缩分块(包括Diff数据压缩分块和/或Extra数据压缩分块)进行还原处理。其中,还原线程利用对应的一组RAM空间,对每个Diff数据压缩分块或Extra数据压缩分块进行还原处理的过程,可以参照前文,在此不再赘述。
示例性的,第一还原线程利用第一组RAM空间依次处理zone1、zone3、zone5等描述的各个数据压缩分块,第二还原线程利用第二组RAM空间依次处理zone2、zone4、zone6等描述的各个数据压缩分块。
例如,zone1描述3个Diff数据压缩分块和4个Extra数据压缩分块,则第一还原线程利用第一组RAM空间依次处理完这3个Diff数据压缩分块和4个Extra数据压缩分块之后,再继续处理zone3描述的各个数据压缩分块,以此类推。
需要指出的是,第一还原线程在对zone1描述的数据压缩分块进行还原处理时,将还原后的新数据写入新文件中的首地址为zone1中第二指针偏移量对应的位置。
再例如,zone2描述5个Diff数据压缩分块和2个Extra数据压缩分块,则第二还原线程利用第二组RAM空间依次处理完这5个Diff数据压缩分块和2个Extra数据压缩分块之后,再继续处理zone4描述的各个数据压缩分块,以此类推。
需要指出的是,第二还原线程在对zone2描述的数据压缩分块进行还原处理时,将还原后的新数据写入新文件中的首地址为zone2中第二指针偏移量对应的位置。
也就是说,每个还原线程在对一个zone描述的数据压缩分块进行还原处理时,将还 原后的新数据写入新文件中的首地址为该zone中第二指针偏移量对应的位置。
S509,当各个还原线程均根据还原操作链表完成相应的数据压缩分块还原操作之后,电子设备对得到的目标文件进行校验。
由于各个zone描述的数据压缩分块的数量不尽相同,则各个还原线程执行数据还原操作的时长也不仅相同。待各个还原线程均根据还原操作链表完成相应的数据压缩分块还原操作之后,Patch文件中所有的数据压缩分块均被还原完成。
此时,电子设备可以基于Patch文件中校验字段的值判断还原得到目标文件是否正确。例如,假设基于Patch文件进行数据还原得到的目标文件的哈希值,与校验字段的值相同,终端则可以确定还原得到的目标文件无误,否则可以确定还原得到的目标文件有误。
如前文所述,任意一个还原线程在对Diff数据分块进行还原处理时大致可以划分为如下几个阶段:在Patch文件中读取Diff数据压缩分块的阶段(简称第一阶段)、对Diff数据压缩分块进行解压的阶段(简称第二阶段)、在旧文件中读取与Diff数据压缩分块对应数据的阶段(简称第四阶段)、根据旧数据和Diff数据分块合成新数据的阶段(简称第四阶段),以及在新文件中写入数据的阶段(简称第五阶段)。
其中,任意一个还原线程均是利用与其对应的一组RAM空间(即第一RAM内存区域、第二RAM内存区域、第三RAM内存区域以及第四RAM内存区域),来完成针对各个Diff数据压缩分块的还原操作。
下面结合图16和图24a,对上述几个阶段中,第一RAM内存区域和第三RAM内存区域的可用状态进行分析。其中,在第一RAM内存区域和第三RAM内存区域的可用状态的初始值为可用。假设,state=0时,表明RAM内存区域可用,state=1时,表明RAM内存区域不可用。
在第一阶段,还原线程将在Patch文件中读取的Diff数据压缩分块写入第一RAM内存区域,第一RAM内存区域的state由0变成1。
在第二阶段,还原线程对第一RAM内存区域中的Diff数据压缩分块进行解压缩操作,并将解压后得到的Diff数据分块写入第三RAM内存区域,第三RAM内存区域的state由0变成1,同时将第一RAM内存区域的state由1变成0。
在第三阶段,还原线程在静态分区(即旧文件)中读取与第三RAM内存区域中Diff数据压缩分块对应的旧数据(或称源数据),写入第一RAM内存区域(覆盖Diff数据压缩分块),第一RAM内存区域的state由0变成1。
在第四阶段,还原线程读取第一RAM内存区域中的旧数据与第三RAM内存区域中的Diff数据合成新目标数据,并将合成的目标数据写入第三RAM内存区域中。此阶段中,还原线程会将第三RAM内存区域的state由1变成0,并申请持有与第三RAM内存区域对应的对象锁,以实现对第三RAM内存区域中的数据保护。待还原线程执行完数据合成操作之后,释放与第三RAM内存区域对应的对象锁,并将第一RAM内存区域的state由1变成0,将第三RAM内存区域的state由0变成1。
在第五阶段,还原线程将第三RAM内存区域中合成的新数据写入新文件中,即落 盘到目标静态分区,并在执行完成后将第三RAM内存区域的state由1变成0。
通过分析上述流程可知,还原线程在第五阶段将第三RAM内存区域中合成的新数据写入新文件中。待第五阶段结束后,还原线程继续处理下一个Diff数据压缩分块或Extra数据压缩分块,处理流程均涉及上述第一阶段。然而,在第五阶段中,第一RAM内存区域的可用状态为可用(state=0),待第五阶段结束后才会继续被还原线程使用。这样,在第五阶段中,第一RAM内存区域存在等待时延,在一定程序上影响了还原线程的处理效率。
类似的,如前文所述,任意一个还原线程在对Extra数据分块进行还原处理时大致可以划分为如下几个阶段:在Patch文件中读取Extra数据压缩分块的阶段(简称第一阶段)、对Extra数据压缩分块进行解压的阶段(简称第二阶段)、以及在新文件中写入数据的阶段(简称第五阶段)。
其中,任意一个还原线程均是利用与其对应的一组RAM空间(即第一RAM内存区域、第二RAM内存区域、第三RAM内存区域以及第四RAM内存区域),来完成针对各个Extra数据压缩分块的还原操作。
下面结合图17和图24b,对上述几个阶段中,第一RAM内存区域和第三RAM内存区域的可用状态进行分析。其中,在第一RAM内存区域和第三RAM内存区域的可用状态的初始值为可用。假设,state=0时,表明RAM内存区域可用,state=1时,表明RAM内存区域不可用。
在第一阶段,还原线程将在Patch文件中读取的Extra数据压缩分块写入第一RAM内存区域,第一RAM内存区域的state由0变成1。
在第二阶段,还原线程对第一RAM内存区域中的Extra数据压缩分块进行解压缩操作,并将解压后得到的Extra数据分块写入第三RAM内存区域,第三RAM内存区域的state由0变成1,同时将第一RAM内存区域的state由1变成0。
在第五阶段,还原线程将第三RAM内存区域中合成的新数据写入新文件中,即落盘到目标静态分区,并在执行完成后将第三RAM内存区域的state由1变成0。
通过分析上述流程可知,还原线程在第五阶段将第三RAM内存区域中合成的新数据写入新文件中。待第五阶段结束后,还原线程继续处理下一个Extra数据压缩分块,处理流程也涉及上述第一阶段。然而,在第五阶段中,第一RAM内存区域的可用状态为可用(state=0),待第五阶段结束后才会继续被还原线程使用。这样,在第五阶段中,第一RAM内存区域存在等待时延,在一定程序上影响了还原线程的处理效率。
由此,还原线程连续处理两个数据压缩分块(无论是Diff数据压缩分块还是Extra数据压缩分块)时,前后两个数据压缩分块的还原处理流程均涉及第一阶段和第五阶段,且待前一个数据压缩分块的还原处理流程第五阶段结束后,后一个数据压缩分块的还原流程第一阶段才开始,使得第一RAM内存区域存在等待时延,在一定程序上影响了还原线程的处理效率。
为了解决上述问题,针对每个还原线程,在其对一个zone描述的各个数据压缩分块进行还原处理时,可以基于两个子线程来完成。
图25示出了本申请实施例提供的一种差分文件的还原方法。如图25所示,一个还 原线程针对一个zone描述各个数据压缩分块进行还原处理操作的流程,具体可以包括如下步骤:
S601,还原线程解析zone数据。
S602,还原线程确定zone描述的Diff数据压缩分块的数量Diffnum,Extra数据压缩分块的数量Extranum,并将Diff-zone-offset和Extra-zone-offset设置为0。
其中,Diff-zone-offset和Extra-zone-offset为全局变量。Diff-zone-offset用于表示在当前zone描述的各个Diff数据压缩分块中,当前处理的Diff数据压缩分块的序号;Extra-zone-offset用于表示在当前zone描述的各个Extra数据压缩分块中,当前处理的Extra数据压缩分块的序号。
在本实施例中,Diff-zone-offset和Extra-zone-offset的初始值被设置为0,zone描述的Diff数据压缩分块和Extra数据压缩分块的序号由1开始计数。示例性的,Diff-zone-offset为1时,表明当前处理的Diff数据压缩分块是序号为1的Diff数据压缩分块;Extra-zone-offset为2时,表明当前处理的Extra数据压缩分块是序号为2的Extra数据压缩分块。
一般情况下,一个zone描述的Diff数据压缩分块的数量Diffnum,以及Extra数据压缩分块的数量Extranum均大于0。特殊情况下,Diffnum或Extranum为0。
S603,还原线程创建并启动第一子线程和第二子线程,通过并行的第一子线程和第二子线程对zone描述的各个数据压缩分块进行还原处理。
其中,第一子线程用于对Diff数据压缩分块或Extra数据压缩分块进行还原处理,第二子线程也用于对Diff数据压缩分块或Extra数据压缩分块进行还原处理,第一子线程和第二子线程是并行的。
需要指出的是,第一子线程和第二子线程的启动顺序可以是指定的,也可以是随机的,本实施例不做限定。
如前文所示,当第一子线程或第二子线程对Diff数据压缩分块进行还原处理时,处理流程可以划分为第一阶段、第二阶段、第三阶段、第四阶段以及第五阶段。当第一子线程或第二子线程对Extra数据压缩分块进行还原处理时,处理流程可以划分为第一阶段、第二阶段以及第五阶段。
其中,当子线程还原处理操作的所处的阶段不同,子线程的处理状态不同。示例性的,当子线程还原处理操作处于第一阶段时,子线程的处理状态为读取差分数据;当子线程还原处理操作处于第二阶段时,子线程的处理状态为解压差分数据;当子线程还原处理操作处于第三阶段时,子线程的处理状态为读取源数据;当子线程还原处理操作处于第四阶段时,子线程的处理状态为合成目标数据;当子线程还原处理操作处于第五阶段时,子线程的处理状态为写入目标数据,即向目标文件(或新文件)中写入目标数据(或新数据)。
图26a示出了第一子线程的处理流程。如图26a所述,第一子线程对数据压缩分块进行还原处理的步骤包括:
S701,第一子线程启动。
S702,第一子线程判断Diff-zone-offset是否为0,或者Extra-zone-offset是否为0, 或者第二子线程的处理状态是否为写入目标数据,若是,则执行S703,若否,则执行S702。
其中,当Diff-zone-offset为0时,表明该zone描述的各个Diff数据压缩分块还未开始被进行还原处理;当Extra-zone-offset为0时,表明该zone描述的各个Extra数据压缩分块还未开始被进行还原处理。
其中,当第二子线程的处理状态为写入目标数据时,表明第二子线程对数据压缩分块的处理流程处于第五阶段。此时,为了避免第一RAM空间区域的等待延时,此时第一子线程即可对下一个数据压缩分块进行还原处理,实现与第二子线程的并行处理。
如果针对上述判断条件的判断结果均为否,则第一子线程等待,继续执行S702所示的判断流程。
S703,第一子线程判断Diff-zone-offset是否小于Diffnum,若是,则执行S704,若否,则执行S706。
由于Diff-zone-offset用于表示在当前zone描述的各个Diff数据压缩分块中,当前处理的Diff数据压缩分块的序号,则当Diff-zone-offset小于Diffnum时,表明当前zone描述的各个Diff数据压缩分块中,还存在未被处理的Diff数据压缩分块。
S704,第一子线程将Diff-zone-offset递增。
在Diff-zone-offset是否小于Diffnum时,将Diff-zone-offset进行加1处理,以确定第一子线程要处理的Diff数据压缩分块。
S705,第一子线程对与Diff-zone-offset对应的Diff数据压缩分块进行还原处理,执行S702。
此时,第一子线程基于与还原线程所对应的一组RAM空间对与Diff-zone-offset对应的Diff数据压缩分块进行还原处理,详细步骤可以参照前文,在此不再赘述。
待第一子线程对与Diff-zone-offset对应的Diff数据压缩分块进行还原处理完成之后,返回执行S702,以判断是否符合第一子线程对下个数据压缩分块进行还原处理的条件。
S706,第一子线程判断Extra-zone-offset是否小于Extranum,若是,则执行S707,若否,则执行S709。
由于Extra-zone-offset用于表示在当前zone描述的各个Extra数据压缩分块中,当前处理的Extra数据压缩分块的序号,则当Extra-zone-offset小于Extranum时,表明当前zone描述的各个Extra数据压缩分块中,还存在未被处理的Extra数据压缩分块。
S707,第一子线程将Extra-zone-offset递增。
在Extra-zone-offset是否小于Extranum时,将Extra-zone-offset进行加1处理,以确定第一子线程要处理的Extra数据压缩分块。
S708,第一子线程对与Extra-zone-offset对应的Extra数据压缩分块进行还原处理,执行S702。
此时,第一子线程基于与还原线程所对应的一组RAM空间对与Extra-zone-offset对应的Extra数据压缩分块进行还原处理,详细步骤可以参照前文,在此不再赘述。
待第一子线程对与Extra-zone-offset对应的Extra数据压缩分块进行还原处理完成之后,返回执行S702,以判断是否符合第一子线程对下个数据压缩分块进行还原处理的条件。
S709,第一子线程结束。
当Diff-zone-offset不小于Diffnum时,表明当前zone描述的各个Diff数据压缩分块中,不存在未被处理的Diff数据压缩分块。当Extra-zone-offset不小于Extranum时,表明当前zone描述的各个Extra数据压缩分块中,不存在未被处理的Extra数据压缩分块。此时,第一子线程可以结束。
图26b示出了第二子线程的处理流程。与第一子线程类似,如图26b所述,第二子线程对数据压缩分块进行还原处理的步骤包括:
S801,第二子线程启动。
S802,第二子线程判断Diff-zone-offset是否为0,或者Extra-zone-offset是否为0,或者第一子线程的处理状态是否为写入目标数据,若是,则执行S803,若否,则执行S802。
其中,当Diff-zone-offset为0时,表明该zone描述的各个Diff数据压缩分块还未开始被进行还原处理;当Extra-zone-offset为0时,表明该zone描述的各个Extra数据压缩分块还未开始被进行还原处理。
其中,当第一子线程的处理状态为写入目标数据时,表明第一子线程对数据压缩分块的处理流程处于第五阶段。此时,为了避免第一RAM空间区域的等待延时,此时第二子线程即可对下一个数据压缩分块进行还原处理,实现与第一子线程的并行处理。
如果针对上述判断条件的判断结果均为否,则第二子线程等待,继续执行S802所示的判断流程。
S803,第二子线程判断Diff-zone-offset是否小于Diffnum,若是,则执行S804,若否,则执行S806。
由于Diff-zone-offset用于表示在当前zone描述的各个Diff数据压缩分块中,当前处理的Diff数据压缩分块的序号,则当Diff-zone-offset小于Diffnum时,表明当前zone描述的各个Diff数据压缩分块中,还存在未被处理的Diff数据压缩分块。
S804,第二子线程将Diff-zone-offset递增。
在Diff-zone-offset是否小于Diffnum时,将Diff-zone-offset进行加1处理,以确定第二子线程要处理的Diff数据压缩分块。
S805,第二子线程对与Diff-zone-offset对应的Diff数据压缩分块进行还原处理,执行S802。
此时,第二子线程基于与还原线程所对应的一组RAM空间对与Diff-zone-offset对应的Diff数据压缩分块进行还原处理,详细步骤可以参照前文,在此不再赘述。
待第二子线程对与Diff-zone-offset对应的Diff数据压缩分块进行还原处理完成之后,返回执行S802,以判断是否符合第二子线程对下个数据压缩分块进行还原处理的条件。
S806,第二子线程判断Extra-zone-offset是否小于Extranum,若是,则执行S807,若否,则执行S809。
由于Extra-zone-offset用于表示在当前zone描述的各个Extra数据压缩分块中,当前处理的Extra数据压缩分块的序号,则当Extra-zone-offset小于Extranum时,表明当前zone描述的各个Extra数据压缩分块中,还存在未被处理的Extra数据压缩分块。
S807,第二子线程将Extra-zone-offset递增。
在Extra-zone-offset是否小于Extranum时,将Extra-zone-offset进行加1处理,以确定第一子线程要处理的Extra数据压缩分块。
S808,第二子线程对与Extra-zone-offset对应的Extra数据压缩分块进行还原处理,执行S802。
此时,第二子线程基于与还原线程所对应的一组RAM空间对与Extra-zone-offset对应的Extra数据压缩分块进行还原处理,详细步骤可以参照前文,在此不再赘述。
待第二子线程对与Extra-zone-offset对应的Extra数据压缩分块进行还原处理完成之后,返回执行S802,以判断是否符合第二子线程对下个数据压缩分块进行还原处理的条件。
S809,第二子线程结束。
当Diff-zone-offset不小于Diffnum时,表明当前zone描述的各个Diff数据压缩分块中,不存在未被处理的Diff数据压缩分块。当Extra-zone-offset不小于Extranum时,表明当前zone描述的各个Extra数据压缩分块中,不存在未被处理的Extra数据压缩分块。此时,第二子线程可以结束。
S604,还原线程判断zone描述的各个数据压缩分块是否均处理完成,以及第一子线程和第二子线程是否均结束,若是,则执行S605,若否,则执行S604。
还原线程判断zone描述的各个数据压缩分块是否均处理完成,以及第一子线程和第二子线程是否均结束,若否,则等待,并继续进行判断,若是,则还原线程对zone描述的数据压缩分块的还原处理操作结束。
S605,还原线程对zone描述的数据压缩分块的还原处理操作结束。
在还原线程对一个zone描述的数据压缩分块的还原处理操作结束之后,可以依据与其对应的还原操作执行链表,继续对下一个zone描述的数据压缩分块进行还原处理,处理流程依旧可以参照S601-S605,在此不再赘述,直至完成还原操作执行链表中记录的各个zone描述的数据压缩分块,结束本还原线程。
这样,在一个还原线程通过两个子线程实现对一个zone描述的各个数据压缩分块进行还原处理时,也能够提升对数据压缩分块的还原效率。
如图27a所示,当通过还原线程这个单线程实现对一个zone描述的各个数据压缩分块进行还原处理时,待前一个数据压缩分块的还原处理流程第五阶段结束后,后一个数据压缩分块的还原流程第一阶段才开始,使得第一RAM内存区域存在等待时延,在一定程度上降低了还原线程的处理效率。
然而,如图27b所示,当通过两个子线程实现对一个zone描述的各个数据压缩分块进行还原处理时,在第一子线程还原处理Diff数据压缩分块1的第五阶段,第二子线程即可开始还原处理Diff数据压缩分块2的第一阶段。类似的,在第二子线程还原处理Diff数据压缩分块2的第五阶段,第一子线程即可开始还原处理Extra数据压缩分块1的第二阶段;在第一子线程还原处理Extra数据压缩分块1的第五阶段,第二子线程即可开始还原处理Extra数据压缩分块2的第一阶段。这样,无需待前一个数据压缩分块的还原处理流程第五阶段结束后,后一个数据压缩分块的还原流程第一阶段才开始,使得第一RAM内存区域不再存在等待时延,减少了多个数据压缩分块的还原时长(对比图27a和图27b 清晰可见),提升了还原线程的处理效率。
如图28所示为电子设备10的结构示意图。可选地,电子设备10可以称为终端,也可以称为终端设备,例如可以为智能手机等,终端可以为可穿戴式电子设备,例如可以是智能手表,本申请不做限定。需要说明的是,电子设备10的结构示意图可以适用于图1中的智能手表100或手机200。应该理解的是,图28所示电子设备10仅是电子设备的一个范例,并且电子设备10可以具有比图中所示的更多的或者更少的部件,可以组合两个或多个的部件,或者可以具有不同的部件配置。图28中所示出的各种部件可以在包括一个或多个信号处理和/或专用集成电路在内的硬件、软件、或硬件和软件的组合中实现。
电子设备10可以包括:处理器110,外部存储器接口120,内部存储器121,通用串行总线(universal serial bus,USB)接口130,充电管理模块140,电源管理模块141,电池142,天线1,天线2,移动通信模块150,无线通信模块160,音频模块170,扬声器170A,受话器170B,麦克风170C,耳机接口170D,传感器模块180,按键190,马达191,指示器192,摄像头193,显示屏194,以及用户标识模块(subscriber identification module,SIM)卡接口195等。其中传感器模块180可以包括压力传感器,陀螺仪传感器,加速度传感器,温度传感器,PPG(Photo Plethysmo Graphy,光电容积脉搏波)传感器,运动传感器,气压传感器,磁传感器,距离传感器,接近光传感器,指纹传感器,触摸传感器,环境光传感器,骨传导传感器等。
处理器110可以包括一个或多个处理单元,例如:处理器110可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processing unit,GPU),图像信号处理器(image signal processor,ISP),控制器,存储器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。处理器110中还可以设置存储器,用于存储指令和数据。
充电管理模块140用于从充电器接收充电输入。充电管理模块140为电池142充电的同时,还可以通过电源管理模块141为电子设备供电。
电子设备10的无线通信功能可以通过天线1,天线2,移动通信模块150,无线通信模块160,调制解调处理器以及基带处理器等实现。移动通信模块150可以提供应用在电子设备10上的包括2G/3G/4G/5G等无线通信的解决方案。无线通信模块160可以提供应用在电子设备10上的包括无线局域网(wireless local area networks,WLAN)(如无线保真(wireless fidelity,Wi-Fi)网络),蓝牙(bluetooth,BT),全球导航卫星系统(global navigation satellite system,GNSS),调频(frequency modulation,FM),近距离无线通信技术(near field communication,NFC),红外技术(infrared,IR)等无线通信的解决方案。
在一些实施例中,电子设备10的天线1和移动通信模块150耦合,天线2和无线通信模块160耦合,使得电子设备10可以通过无线通信技术与网络以及其他设备通信。
电子设备10通过GPU,显示屏194,以及应用处理器等实现显示功能。处理器110可包括一个或多个GPU,其执行程序指令以生成或改变显示信息。
显示屏194用于显示图像,视频等。显示屏194包括显示面板。在一些实施例中, 电子设备10可以包括1个或N个显示屏194,N为大于1的正整数。
外部存储器接口120可以用于连接外部存储卡,例如Micro SD卡,实现扩展电子设备10的存储能力。内部存储器121可以用于存储计算机可执行程序代码,所述可执行程序代码包括指令。处理器110通过运行存储在内部存储器121的指令,从而执行电子设备10的各种功能应用以及数据处理,使得电子设备10实现本申请实施例中的固件文件还原方法。
在本申请实施例中,内部存储器121可以用于存储实现本申请实施例中差分文件生成方法的程序、差分文件还原方法的程序、BSDiff算法的程序等。
电子设备10可以通过音频模块170,扬声器170A,受话器170B,麦克风170C,耳机接口170D,以及应用处理器等实现音频功能。例如音乐播放,录音等。
音频模块170用于将数字音频信息转换成模拟音频信号输出,也用于将模拟音频输入转换为数字音频信号。音频模块170还可以用于对音频信号编码和解码。在一些实施例中,音频模块170可以设置于处理器110中,或将音频模块170的部分功能模块设置于处理器110中。
陀螺仪传感器可以用于检测电子设备10的运动姿态。在一些实施例中,可以通过陀螺仪传感器确定电子设备10围绕三个轴(即,x,y和z轴)的角速度。在一些实施例中,陀螺仪传感器还可以用于识别电子设备的姿态,以实现对佩戴或者手持电子设备10的用户进行行为状态的识别。
加速度传感器可以用于检测电子设备10在各个方向上(一般为三轴)加速度的大小。在一些实施例中,当电子设备10静止时,可以通过加速度传感器检测出重力的大小及方向。在一些实施例中,加速度传感器还可以用于识别电子设备的姿态,以实现对佩戴或者手持电子设备10的用户进行行为状态的识别。
温度传感器可以用于检测电子设备10的温度。在一些实施例中,可以通过温度传感器检测电子设备10佩戴用户的体温。
PPG(Photo Plethysmo Graphy,光电容积脉搏波)传感器可以用于检测电子设备10佩戴者的生理参数信息。PPG传感器的原理是通过光学检测出组织微血管床中血容量在心脏收缩舒张作用下的波动性变化。例如,心脏收缩时,组织的血容量增多、光吸收量增加,则光检测器检测到的光强度较小;心脏舒张时,组织的血容量减少、光吸收量减少,则光检测器检测到的光强度较大。由于PPG传感器光强度的变化与组织的血液灌注的微小变化相关,所以可以用来提供电子设备10佩戴者心血管系统的信息,例如血压、血氧、脉搏率(心率)和呼吸率等生理参数信息。
压力传感器用于感受压力信号,可以将压力信号转换成电信号。在一些实施例中,压力传感器可以设置于显示屏194。电子设备10也可以根据压力传感器的检测信号计算触摸的位置。
触摸传感器,也称“触控面板”。触摸传感器可以设置于显示屏194,由触摸传感器与显示屏194组成触摸屏,也称“触控屏”。触摸传感器用于检测作用于其上或附近的触摸操作。触摸传感器可以将检测到的触摸操作传递给应用处理器,以确定触摸事件类型。
按键190包括开机键(或称电源键),音量键等。按键190可以是机械按键。也可以 是触摸式按键。电子设备10可以接收按键输入,产生与电子设备10的用户设置以及功能控制有关的键信号输入。
马达191可以产生振动提示。马达191可以用于来电振动提示,也可以用于触摸振动反馈。
指示器192可以是指示灯,可以用于指示充电状态,电量变化,也可以用于指示消息。
电子设备10的软件系统可以采用分层架构,事件驱动架构,微核架构,微服务架构,或云架构。本申请实施例以分层架构的操作系统为例,示例性说明电子设备10的软件结构。
图29是本申请实施例的电子设备10的软件结构框图。
电子设备10的分层架构将软件分成若干个层,每一层都有清晰的角色和分工。层与层之间通过软件接口通信。在一些实施例中,以电子设备10为智能手表为例,如图29所示,可以将操作系统分为六层,从上至下分别为UI(User Interface,用户界面)应用层,系统服务层,算法层,硬件抽象层,内核层,以及驱动层。
UI应用层可以包括一系列应用程序包,例如可以是表盘、运动记录、通话、锻炼等。
系统服务层可以包括一系列系统服务。系统服务层可以包括心率服务,心率服务可以提供智能手表佩戴者的生理参数信息,例如血压、血氧、脉搏率、呼吸率和体温等,还可以检测智能手表佩戴者的生理参数变化信息。系统服务层还可以包括计步服务、卡路里服务、心脏健康服务。
算法层可以包括一系列算法模型。如图29所示,算法层可以包括差分还原算法模型。其中,差分还原算法模型可以用于本实施例提供的差分文件还原方法。
硬件抽象层(hardware abstraction layer,HAL)为位于操作系统内核与硬件电路之间的接口层。HAL层包括但不限于音频HAL。其中,音频HAL用于对音频流进行处理,例如,对音频流进行降噪、定向增强等处理。
内核层和驱动层是硬件和软件之间的层。如图29所示,内核层至少包括操作系统内核,驱动层至少包括蓝牙驱动,WiFi驱动等。
可以理解的是,图29示出的软件结构中的层以及各层中包含的部件,并不构成对电子设备10的具体限定。在本申请另一些实施例中,电子设备10可以包括比图示更多或更少的层,以及每个层中可以包括更多或更少的部件,本申请不做限定。
可以理解的是,电子设备10为了实现本申请实施例中的差分文件的还原方法,其包含了执行各个功能相应的硬件和/或软件模块。结合本文中所公开的实施例描述的各示例的算法步骤,本申请能够以硬件或硬件和计算机软件的结合形式来实现。某个功能究竟以硬件还是计算机软件驱动硬件的方式来执行,取决于技术方案的特定应用和设计约束条件。本领域技术人员可以结合实施例对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。
一个示例中,图30示出了本申请实施例的一种装置800的示意性框图,装置800可 包括:处理器801和收发器/收发管脚802,可选地,还包括存储器803。
装置800的各个组件通过总线804耦合在一起,其中总线804除包括数据总线之外,还包括电源总线、控制总线和状态信号总线。但是为了清楚说明起见,在图中将各种总线都称为总线804。
可选地,存储器803可以用于存储上述差分文件生成方法实施例中服务器的指令。该处理器801可用于执行存储器803中的指令,并控制接收管脚接收信号,以及控制发送管脚发送信号。
可选地,存储器803可以用于存储上述差分文件还原方法实施例中智能终端的指令。该处理器801可用于执行存储器803中的指令,并控制接收管脚接收信号,以及控制发送管脚发送信号。
装置800可以是上述差分文件生成方法实施例中服务器,例如OTA服务器,或者是上述差分文件还原方法实施例中智能终端,例如智能手机、智能手表等。
本实施例还提供一种计算机存储介质,该计算机存储介质中存储有计算机指令,当该计算机指令在电子设备上运行时,使得电子设备执行上述相关方法步骤实现上述实施例中的差分文件的生成方法,或者使得电子设备执行上述相关方法步骤实现上述实施例中的差分文件的还原方法。
本实施例还提供了一种计算机程序产品,当该计算机程序产品在计算机上运行时,使得计算机执行上述相关步骤,以实现上述实施例中的差分文件的生成方法,或者实现上述实施例中的差分文件的还原方法。
另外,本申请的实施例还提供一种装置,这个装置具体可以是芯片,组件或模块,该装置可包括相连的处理器和存储器;其中,存储器用于存储计算机执行指令,当装置运行时,处理器可执行存储器存储的计算机执行指令,以使芯片执行上述方法实施例中的差分文件的生成方法或者差分文件的还原方法。
其中,本实施例提供的电子设备(如服务器或终端等)、计算机存储介质、计算机程序产品或芯片均用于执行上文所提供的对应的方法,因此,其所能达到的有益效果可参考上文所提供的对应的方法中的有益效果,此处不再赘述。
通过以上实施方式的描述,所属领域的技术人员可以了解到,为描述的方便和简洁,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。
在本申请所提供的几个实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,模块或单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个装置,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
以上所述,以上实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前 述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的范围。

Claims (12)

  1. 一种差分文件的还原方法,其特征在于,应用于电子设备中,包括:
    获取差分文件;其中,在所述差分文件中包括至少一组数据压缩分块,所述一组数据压缩分块包括差异Diff数据压缩分块和/或新增Extra数据压缩分块,所述数据压缩分块被压缩前是基于预设的分块尺寸进行划分的;
    根据所述分块尺寸和所述电子设备用于差分文件还原的RAM空间尺寸,确定还原线程的并行数量k,并为每个所述还原线程划分一组RAM空间;
    采用所述k个所述还原线程并行地对所述差分文件进行还原处理,其中,每个所述还原线程使用与其对应的一组RAM空间对至少一组数据压缩分块进行还原处理,并将还原处理后得到的数据写入目标文件中。
  2. 根据权利要求1所述的方法,其特征在于,所述一组RAM空间,包括:第一RAM内存区域、第二RAM内存区域、第三RAM内存区域和第四RAM内存区域;其中,
    所述第一RAM内存区域和所述第二RAM内存区域的尺寸为所述分块尺寸;
    所述第二RAM内存区域和所述第四RAM内存区域分别为所述第一RAM内存区域和所述第三RAM内存区域的安全缓冲区域;
    各个所述还原线程共用第五RAM内存区域,所述第五RAM内存区域用于运行数据压缩算法。
  3. 根据权利要求2所述的方法,其特征在于,根据所述分块尺寸和所述电子设备用于差分文件还原的RAM空间尺寸,确定还原线程的并行数量k,包括:
    k=[(M-N1)/(zonesize+N2)];其中,M为所述电子设备用于差分文件还原的RAM空间尺寸,N1为所述第五RAM内存区域的尺寸,zonesize为所述分块尺寸,N2为安全缓冲区域的尺寸,[]为取整运算。
  4. 根据权利要求2所述的方法,其特征在于,与所述Diff数据压缩分块对应的Diff数据是基于第一运算得到的;
    每个所述还原线程对一组数据压缩分块进行还原处理,包括:
    所述还原线程按照解析顺序依次对一组数据压缩分块中的Diff数据压缩分块或Extra数据压缩分块进行数据还原处理;
    每解析得到一个Diff数据压缩分块时,将所述Diff数据压缩分块对应的Diff数据与已有数据进行第二运算,得到第一目标数据,写入目标文件中;其中,所述已有数据为在与所述差分文件对应的已有文件中,读取到的与所述Diff数据压缩分块匹配的数据,所述第二运算为所述第一运算的逆运算;
    每解析得到一个Extra数据压缩分块时,对所述Extra数据压缩分块进行数据解压,得到第二目标数据,写入所述目标文件中。
  5. 根据权利要求4所述的方法,其特征在于,将所述Diff数据压缩分块对应的Diff数据与已有数据进行第二运算,得到第一目标数据,写入目标文件中,包括:
    将所述Diff数据压缩分块暂存在第一RAM内存区域中;
    对所述Diff数据压缩分块进行数据解压处理,将得到的Diff数据分块暂存在第三RAM内存区域中;
    在所述已有文件中读取与所述Diff数据分块对应的已有数据,并暂存在所述第一RAM内存区域中;
    将所述第一RAM内存区域中的数据和所述第三RAM内存区域中的数据进行第二操作,所得的第一目标数据暂存在所述第三RAM内存区域中;
    将在所述第三RAM内存区域中暂存的第一目标数据,写入所述目标文件中。
  6. 根据权利要求4所述的方法,其特征在于,对所述Extra数据压缩分块进行数据解压,得到第二目标数据,写入所述目标文件中,包括:
    将所述Extra数据压缩分块暂存在第一RAM内存区域中;
    对所述Extra数据压缩分块进行数据解压处理,将得到的第二目标数据暂存在第三RAM内存区域中;
    将在所述第三RAM内存区域中暂存的第二目标数据,写入所述目标文件中。
  7. 根据权利要求1所述的方法,其特征在于,每个所述还原线程使用与其对应的一组RAM空间对至少一组数据压缩分块进行还原处理,包括:
    根据所述差分文件中包括的数据压缩分块组数,以及各组数据压缩分块的序号为每个所述还原线程分别创建链表,以使所述还原线程根据对应的链表完成对至少一组数据压缩分块进行还原处理;
    其中,在所述链表中,节点的数据部分填充一组数据压缩分块的序号,以及所述一组数据压缩分块对应的还原数据在目标文件中写入的首地址。
  8. 根据权利要求6所述的方法,其特征在于,所述差分文件的数据结构包括头部、控制块、以及通过所述控制块描述的一组数据压缩分块;
    所述头部中填充所述差分文件的魔数与所述分块尺寸;
    所述控制块中填充第一指针偏移量和第二指针偏移量;其中,所述第一指针偏移量用于在已有文件中确定与所述一组数据压缩分块对应的数据读取首地址;所述第二指针偏移量用于在目标文件中确定与所述一组数据压缩分块对应的数据写入首地址。
  9. 根据权利要求6所述的方法,其特征在于,根据数据压缩分块的序号对并行数量的取余结果,分别确定待每个还原线程处理的各组数据压缩分块。
  10. 根据权利要求5或6所述的方法,其特征在于,每个所述还原线程使用与其对应的一组RAM空间对至少一组数据压缩分块进行还原处理,包括:
    每个所述还原线程创建第一子线程和第二子线程;
    通过所述第一子线程和所述第二子线程使用与所述还原线程对应的一组RAM空间,依次对一组数据压缩分块中包括的Diff数据压缩分块或Extra数据压缩分块进行还原处理;
    其中,在所述第二子线程执行到目标阶段时,所述第一子线程继续在所述一组数据压缩分块数据压缩分块进行还原处理;
    在第一子线程执行到所述目标阶段时,所述第二子线程继续在所述一组数据压缩分块数据压缩分块进行还原处理;
    所述目标阶段为将在所述第三RAM内存区域中暂存的数据,写入所述目标文件中。
  11. 一种电子设备,其特征在于,包括:
    一个或多个处理器;
    存储器;
    以及一个或多个计算机程序,其中所述一个或多个计算机程序存储在所述存储器上,当所述计算机程序被所述一个或多个处理器执行时,使得所述电子设备执行如权利要求1-10中任一项所述的差分文件的还原方法。
  12. 一种计算机可读存储介质,包括计算机程序,其特征在于,当所述计算机程序在电子设备上运行时,使得所述电子设备执行如权利要求1-10中任一项所述的差分文件的还原方法。
PCT/CN2023/113549 2022-09-09 2023-08-17 差分文件的还原方法及电子设备 WO2024051465A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202211101979.2 2022-09-09
CN202211101979.2A CN117707588A (zh) 2022-09-09 2022-09-09 差分文件的还原方法及电子设备

Publications (2)

Publication Number Publication Date
WO2024051465A1 true WO2024051465A1 (zh) 2024-03-14
WO2024051465A9 WO2024051465A9 (zh) 2024-05-02

Family

ID=90159364

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/113549 WO2024051465A1 (zh) 2022-09-09 2023-08-17 差分文件的还原方法及电子设备

Country Status (2)

Country Link
CN (1) CN117707588A (zh)
WO (1) WO2024051465A1 (zh)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8078653B1 (en) * 2008-10-07 2011-12-13 Netapp, Inc. Process for fast file system crawling to support incremental file system differencing
CN107016053A (zh) * 2017-03-02 2017-08-04 中国科学院信息工程研究所 一种并行的数据差分方法
US20180173723A1 (en) * 2015-06-04 2018-06-21 Here Global B.V. Incremental update of compressed navigational databases
US20180246711A1 (en) * 2014-11-17 2018-08-30 Hitachi Automotive Systems, Ltd. In-Vehicle Control Device, Program Update System, and Program Update Software
CN113835870A (zh) * 2020-06-23 2021-12-24 华为技术有限公司 数据处理方法及系统
CN114327574A (zh) * 2020-09-28 2022-04-12 深圳Tcl新技术有限公司 一种差分升级方法、电子设备及存储介质

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8078653B1 (en) * 2008-10-07 2011-12-13 Netapp, Inc. Process for fast file system crawling to support incremental file system differencing
US20180246711A1 (en) * 2014-11-17 2018-08-30 Hitachi Automotive Systems, Ltd. In-Vehicle Control Device, Program Update System, and Program Update Software
US20180173723A1 (en) * 2015-06-04 2018-06-21 Here Global B.V. Incremental update of compressed navigational databases
CN107016053A (zh) * 2017-03-02 2017-08-04 中国科学院信息工程研究所 一种并行的数据差分方法
CN113835870A (zh) * 2020-06-23 2021-12-24 华为技术有限公司 数据处理方法及系统
CN114327574A (zh) * 2020-09-28 2022-04-12 深圳Tcl新技术有限公司 一种差分升级方法、电子设备及存储介质

Also Published As

Publication number Publication date
WO2024051465A9 (zh) 2024-05-02
CN117707588A (zh) 2024-03-15

Similar Documents

Publication Publication Date Title
WO2019222934A1 (zh) 文件处理方法、装置和系统
US20220188093A1 (en) Patching Method, Related Apparatus, and System
CN105740016B (zh) 应用程序的增量发布方法和装置、升级方法和装置
CN108650287B (zh) 物联网中的终端设备的升级方法、设备及计算机可读介质
CN108804130B (zh) 程序安装包生成方法及装置
JP6970747B2 (ja) 並列復号を可能にする可変長シンボルの符号化
CN112068903A (zh) 应用程序的加载方法、应用程序的加载装置、介质与设备
WO2023221735A1 (zh) 嵌入式设备固件更新方法、嵌入式设备及开发端设备
US20230162317A1 (en) Picture Loading Method and Related Apparatus
WO2022141513A1 (zh) 模型处理方法和装置
CN115017096A (zh) 数据迁移方法、可读介质和电子设备
CN106688015B (zh) 处理用于当解码图像时对于块的操作的参数
CN111125602B (zh) 页面构建方法、装置、设备和存储介质
CN112506878A (zh) 文件处理方法、装置、存储介质及电子设备
CN116028095B (zh) 差分文件的生成方法、还原方法及电子设备
CN109697034B (zh) 一种数据写入方法、装置、电子设备及存储介质
CN113641634B (zh) 一种日志流量控制的方法以及电子设备
WO2024051465A1 (zh) 差分文件的还原方法及电子设备
EP2930616B1 (en) Device and method for generating application package
WO2023273766A1 (zh) 一种编译优化方法和装置
KR20180127085A (ko) 데이터를 압축하는 전자 장치 및 그 동작 방법
CN116432737A (zh) 基于深度学习的模型压缩训练的方法、装置和设备
CN113508536A (zh) 就地安全解压缩
KR20050096623A (ko) 미디어 재생 장치 및 재생 방법
WO2021097624A1 (zh) 一种文件处理方法、文件处理装置及终端设备

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 23862162

Country of ref document: EP

Kind code of ref document: A1