Differential package generation method, differential package reduction method, electronic equipment and storage medium
The shortest suffix array set is generated by sorting the data in lexicographic order, and the coverage line set is obtained by traversing the second version data. This solves the problem of low efficiency of existing differential upgrades and realizes efficient firmware upgrades in a limited memory environment.
Patent Information
- Application Number
- CN202510831044.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-19
- Publication Date
- 2025-09-16
AI Technical Summary
The existing differential upgrade method is inefficient in calculating differences, resulting in low firmware upgrade efficiency, which is particularly difficult to apply in single-chip microcomputer devices with limited computing and storage resources.
By obtaining the first version data and the second version data, using the lexicographical order rule to sort and generate the shortest suffix array set, traversing the second version data to obtain the coverage line set, generating a differential package, reducing the number of suffix arrays and coverage lines to be compared, and improving the efficiency of generating differential packages.
It speeds up the generation of coverage line sets, reduces the amount of data in differential packets, improves the efficiency of firmware upgrades, and is suitable for fast differential upgrades in limited memory environments.
Smart Images

Figure CN120658728A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a differential packet generation method, a differential packet restoration method, an electronic device, and a storage medium. Background Art
[0002] With the rapid development of IoT technology, regular firmware upgrades have become a key part of maintaining digital ecosystem security in order to ensure that devices maintain efficient operation, eliminate potential safety hazards, and continuously expand functional boundaries.
[0003] Although differential upgrade can shorten the firmware upgrade time and improve the reliability and stability of the firmware upgrade, the existing differential upgrade method is inefficient in calculating the difference, resulting in low firmware upgrade efficiency. Summary of the Invention
[0004] The purpose of the embodiments of the present application is to provide a differential packet generation method, a differential packet restoration method, an electronic device and a storage medium, which are used to generate a differential data packet between the new version data and the old version data according to the coverage line set for firmware upgrade, obtain a differential packet that occupies a small storage volume, and improve the efficiency of the firmware upgrade.
[0005] In a first aspect, an embodiment of the present application provides a differential packet generation method, including: obtaining first version data and second version data; the second version data is used to update the first version data; the suffix array of the first version data is sorted according to the lexicographical rule to obtain the shortest suffix array set of the first version data; the shortest suffix array set includes the first suffix array with different data as the first byte after the suffix array of the first version data is sorted according to the lexicographical rule; the second version data is traversed according to the shortest suffix array set to obtain a coverage line set; the coverage line set includes the maximum matching data segment between the data segment in the second version data, which is composed of different data as the first byte to the last byte of the second version data, and the first version data; a differential packet of the first version data and the second version data is generated according to the coverage line set.
[0006] In the embodiment of the present application, since the shortest suffix data set includes the first suffix array with different data as the first byte after the first version data is sorted according to the lexicographic order rule, the number of suffix arrays that need to be compared when obtaining the coverage line set is reduced, thereby speeding up the acquisition of the coverage line set. Furthermore, since the shortest suffix data set only stores the first suffix array with different data as the first byte, the number of generated coverage lines is also reduced, thereby reducing the data volume of the generated differential packets, improving the efficiency of generating differential packets based on the coverage line set, and thereby improving the efficiency of firmware upgrades.
[0007] In some embodiments, the first version data is sorted lexicographically to obtain the shortest suffix array set of the first version data, including: using a sorting search algorithm to construct a suffix array set of the first version data after sorting the lexicographically; the suffix array set includes sub-suffix array sets with different data as the first byte; and obtaining the shortest suffix array set of the first version data based on the first suffix array in each sub-suffix array set.
[0008] The embodiment of the present application quickly obtains the suffix array set of the first version data through a sorting search algorithm. Since the suffix array set is already an array sorted by the lexicographical order rule, the shortest suffix array set can be quickly obtained, thereby improving the efficiency of generating differential packets based on the coverage line set, thereby improving the efficiency of firmware upgrades.
[0009] In some embodiments, the second version data is traversed according to the shortest suffix array set to obtain a coverage line set, including: determining the target shortest suffix array: taking the data value corresponding to the target index of the second version data as the basic index value, querying the target shortest suffix array corresponding to the basic index value and the index value that satisfies a preset relationship with the basic index value in the shortest suffix array set; the target index is determined by adding the target index in the previous loop and the data segment length of the maximum matching data segment determined in the previous loop; the target index corresponding to the first loop is the index of the first byte in the second version data; determining the maximum matching data segment: determining that the data segment of the second version data from the target index to the last byte is a continuous and equal data segment compared with each target shortest suffix array, taking the data segment with the longest length in the data segment as the maximum matching data segment, and writing the maximum matching data segment into the coverage line set; looping the steps of determining the target shortest suffix array and determining the maximum matching data segment until the target index is greater than the length of the second version data to obtain the coverage line set.
[0010] In the process of generating a coverage line set, the embodiment of the present application uses the data value corresponding to the target index of the second version data as the basic index value, and determines the target shortest suffix array based on the basic index value and the index value that satisfies a preset relationship with the basic index value, so that the target shortest suffix array has a high degree of matching with the data segment of the second version data starting from the target index to the last byte, thereby improving the quality of the determined maximum matching data segment. In addition, the target index is determined by adding the target index in the previous loop and the data segment length of the maximum matching data segment determined in the previous loop, which reduces the number of loops and speeds up the generation of the coverage line set. The efficiency of generating differential packets based on the coverage line set is improved, thereby improving the efficiency of firmware upgrades.
[0011] In some embodiments, the maximum matching data segment is written into the coverage line set, including: if the first maximum matching data segment obtained in the current loop is co-linear with the second maximum matching data segment obtained in the previous loop, the first maximum matching data segment and the second maximum matching data segment are merged to form a third maximum matching data segment; the first maximum matching data segment and the second maximum matching data segment are deleted, and the third maximum matching data segment is written into the coverage line set; if the first maximum matching data segment obtained in the current loop covers the second maximum matching data segment obtained in the previous loop, the second maximum matching data segment is deleted, and the first maximum matching data segment is written into the coverage line set; if the first maximum matching data segment obtained in the current loop is covered by the second maximum matching data segment obtained in the previous loop, the first maximum matching data segment is deleted.
[0012] The embodiment of the present application merges the collinear maximum matching data segments, deletes the merged maximum matching data segments, and also deletes the covered maximum matching data segments, so that the only data retained are the maximum matching data segments that do not overlap with each other, thereby further reducing the number of coverage lines in the coverage line set and improving the quality of the coverage lines, thereby reducing the data volume of the generated differential packets, improving the efficiency of generating differential packets based on the coverage line set, and improving the efficiency of firmware upgrades.
[0013] In some embodiments, the maximum matching data segment includes the first starting position of the maximum matching data segment in the first version data and the second starting position of the maximum matching data segment in the second version data; the method for determining whether the first maximum matching data segment obtained in the current loop and the second maximum matching data segment obtained in the previous loop are collinear is as follows: if the sum of the first starting position of the first maximum matching data segment and the first starting position of the second maximum matching data segment is equal to the sum of the second starting position of the first maximum matching data segment and the second starting position of the second maximum matching data segment, then it is determined that the first maximum matching data segment and the second maximum matching data segment are collinear; or, if the distance between the first maximum matching data segment and the second maximum matching data segment is not greater than a preset distance threshold, then it is determined that the first maximum matching data segment and the second maximum matching data segment are collinear.
[0014] The embodiment of the present application determines whether the first maximum matching data segment and the second maximum matching data segment are collinear, merges the collinear first maximum matching data segment and the second maximum matching data segment, reduces the number of coverage lines in the coverage line set, thereby reducing the data volume of the generated differential packet, and improves the efficiency of generating differential packets based on the coverage line set, thereby improving the efficiency of firmware upgrades.
[0015] In some embodiments, a differential package of first version data and second version data is generated based on a set of coverage lines, including: obtaining verification parameters; generating first differential data based on the number of maximum matching data segments in the set of coverage lines, the data segment length of each maximum matching data segment, the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the first version data, and the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the second version data; encoding and compressing the first differential data to obtain differential compressed data; and generating a differential package based on the differential compressed data and the verification parameters.
[0016] This embodiment of the present application generates first differential data based on the offset increments of two adjacent maximum matching data segments, thereby reducing the amount of stored data and, therefore, the amount of first differential data. By encoding and compressing the first differential data, the amount of differential packet data is reduced. Furthermore, by combining the first differential data with verification parameters to generate a differential packet, the integrity and legitimacy of the differential packet are improved.
[0017] In some embodiments, the method further includes: if there is a gap between two adjacent maximum matching data segments in the coverage line set in the second version data, the difference data corresponding to the gap in the second version data and the offset increment of the difference data relative to the starting position of the second version data are written into the first differential data to generate second differential data; accordingly, the first differential data is encoded and compressed to obtain differential compressed data, including: encoding and compressing the second differential data to obtain differential compressed data.
[0018] In an embodiment of the present application, taking into account the existence of differential data between the first version data and the second version data, that is, the area not covered by the cover lines in the cover line set, the second differential data is generated by writing the differential data between the first version data and the second version data and the offset increment of the differential data relative to the starting position of the second version data into the first differential data, and then generating a differential package based on the second differential data, thereby improving the integrity of the differential package.
[0019] In a second aspect, an embodiment of the present application provides a differential packet restoration method, which is applied to a terminal whose firmware is to be upgraded, and the method includes: receiving a differential packet generated by the method of any one embodiment of the first aspect; the differential packet includes differential compressed data; decompressing the differential compressed data to obtain decompressed differential data; and performing differential restoration based on the decompressed differential data.
[0020] When performing differential restoration, the embodiment of the present application receives a differential packet generated according to the differential packet generation method. Since the data volume of the differential packet is small, the time consumed for restoration based on the differential packet is shorter and the required dynamic memory space is smaller, thereby improving the efficiency of differential restoration and thus improving the efficiency of firmware upgrade.
[0021] In some embodiments, the differential data includes the number of maximum matching data segments in the coverage line set, the data segment length of each maximum matching data segment, the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the first version data, and the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the second version data; the first version data is stored in the terminal, and the second version data is used to update the first version data; differential restoration is performed based on the decompressed differential data, including: reading the corresponding data segment from the first version data according to the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the first version data and the data segment length of each maximum matching data segment; writing the data segment to the storage area corresponding to the second version data based on the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the second version data, so as to perform differential restoration.
[0022] The embodiment of the present application reads the corresponding data segment from the first version data based on the offset increment of each maximum matching data segment in the differential packet relative to the previous maximum matching data segment in the first version data and the data segment length of each maximum matching data segment. When the second version data contains data identical to the first version data, it is directly read from the first version data stored in the terminal and written into the storage area corresponding to the second version data, thereby improving the efficiency of differential restoration.
[0023] In some embodiments, the method further includes: if the differential data further includes difference data and an offset increment of the difference data relative to a starting position of the second version data, then writing the difference data into a storage area corresponding to the second version data based on the offset increment.
[0024] In an embodiment of the present application, when the differential data includes difference data, the difference data is written into a storage area corresponding to the second version data, thereby improving the integrity of the differential restoration.
[0025] In some embodiments, the differential packet further includes a verification parameter; before decompressing the differential compressed data, the method further includes: verifying the verification parameter; if the verification is successful, executing the step of decompressing the differential compressed data.
[0026] The embodiment of the present application verifies the verification parameters before decompressing the differential compressed data, thereby improving the legitimacy of the differential restoration.
[0027] In a third aspect, an embodiment of the present application provides a differential packet generation device, which includes: an acquisition module for acquiring first version data and second version data; the second version data is used to update the first version data; a first acquisition module for sorting the suffix array of the first version data according to the lexicographical order rule to obtain the shortest suffix array set of the first version data; the shortest suffix array set includes the first suffix array with different data as the first byte after the suffix array of the first version data is sorted according to the lexicographical order rule; a second acquisition module for traversing the second version data according to the shortest suffix array set to obtain a coverage line set; the coverage line set includes the maximum matching data segment between the data segment in the second version data with different data as the first byte to the last byte of the second version data and the first version data; a generation module, a user generates a differential packet of the first version data and the second version data according to the coverage line set.
[0028] In a fourth aspect, an embodiment of the present application provides a differential packet restoration device, which includes: a receiving module for receiving a differential packet generated by the method of any one embodiment of the first aspect; the differential packet includes differential compressed data; a decompression module for decompressing the differential compressed data to obtain decompressed differential data; and a restoration module for performing differential restoration based on the decompressed differential data.
[0029] In a fifth aspect, an embodiment of the present application provides an electronic device, comprising: a processor and a memory, the memory storing machine-readable instructions executable by the processor, and the machine-readable instructions, when executed by the processor, can execute the method steps of any one of the embodiments of the first aspect, the second aspect, or both aspects.
[0030] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium, comprising: computer program instructions are stored on the computer-readable storage medium, and when the computer program instructions are executed by a processor, the method steps of any one embodiment of the first aspect, the second aspect, or both aspects are executed.
[0031] In a seventh aspect, an embodiment of the present application provides a computer program product, comprising: computer program instructions, which, when executed by a processor, execute the method steps of the first aspect, the second aspect, or any one of the embodiments of these two aspects.
[0032] Other features and advantages of the present application will be described in the subsequent description, and in part will become apparent from the description, or will be understood by practicing the embodiments of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without creative work.
[0034] Figure 1 A flowchart of a differential packet generation method provided in an embodiment of the present application; Figure 2 A flowchart of another differential packet generation method provided in an embodiment of the present application; Figure 3 A flowchart of a differential packet restoration method provided in an embodiment of the present application; Figure 4 A flowchart of another differential packet restoration method provided in an embodiment of the present application; Figure 5 A schematic structural diagram of a differential packet generation device provided in an embodiment of the present application; Figure 6 A schematic diagram of the structure of a differential packet restoration device provided in an embodiment of the present application; Figure 7 A schematic diagram of the electronic device structure provided in an embodiment of the present application. DETAILED DESCRIPTION
[0035] The following embodiments of the technical solution of the present application will be described in detail with reference to the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present application and are therefore only examples and are not intended to limit the scope of protection of the present application.
[0036] It should be noted that all technical and scientific terms used herein have the same meanings as those commonly understood by technicians in the technical field to which this application belongs; the terms used herein are only for the purpose of describing specific embodiments and are not intended to limit this application; the terms "including" and "having" in the specification and claims of this application and the above-mentioned figure descriptions and any variations thereof are intended to cover non-exclusive inclusions.
[0037] In the description of the embodiments of this application, the technical terms "first" and "second" are used only to distinguish different objects and should not be understood to indicate or imply relative importance or implicitly specify the quantity, specific order, or primary and secondary relationship of the indicated technical features. In the description of the embodiments of this application, the meaning of "plurality" is more than two, unless otherwise clearly and specifically defined.
[0038] In the description of the embodiments of this application, the term "and / or" is simply a description of the association relationship between associated objects, indicating that three relationships can exist. For example, A and / or B can represent the following three situations: A exists alone, A and B exist simultaneously, and B exists alone. In addition, the character " / " in this document generally indicates that the associated objects are in an "or" relationship.
[0039] It should be noted that, unless otherwise specified, in the specific implementation of this application, when it involves request, response data and other related data, when the embodiments of this application are applied to specific products or technologies, user permission or consent must be obtained, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0040] The firmware upgrade process for microcontroller devices is limited by slow transmission links and small Flash memory capacity, forcing the full firmware package to be written while being transferred. This results in long firmware upgrade times and a poor upgrade experience. Furthermore, if the device loses power midway, the transmission and upgrade will be interrupted, ultimately causing device failures. Therefore, performing a full firmware upgrade on a device is inefficient and risky.
[0041] While differential upgrades can reduce firmware upgrade time and improve reliability and stability, existing differential upgrade solutions generate patch files based on row- or block-based difference comparisons, resulting in low computational efficiency and inability to efficiently process binary files. This makes them difficult to apply to microcontrollers with limited computing and storage resources, and their firmware upgrade efficiency is also low.
[0042] In response to the above problems, the embodiments of the present application provide a differential packet generation method, a differential packet restoration method, an electronic device and a storage medium, which are used to generate a differential data packet between the new version data and the old version data based on the coverage line set for firmware upgrade, and obtain a differential packet that occupies a small storage capacity, so that differential upgrades can be performed quickly even in a limited memory environment, thereby improving the efficiency of firmware upgrades.
[0043] Figure 1 This is a flow chart of a differential packet generation method provided in an embodiment of the present application. It is understood that the differential packet generation method provided in an embodiment of the present application can be applied to terminal devices (also referred to as electronic devices) and servers; the terminal devices may specifically be smartphones, tablet computers, computers, personal digital assistants (PDAs), etc.; and the servers may specifically be application servers or web servers. To facilitate understanding of the technical solutions provided in an embodiment of the present application, the following describes the application scenarios of the differential packet generation method provided in an embodiment of the present application, using a server as an example execution subject.
[0044] like Figure 1 As shown, the method includes: Step S101: The server obtains first version data and second version data; the second version data is used to update the first version data.
[0045] In a specific implementation process, the first version data refers to the version data of the last firmware upgrade (also called old version data olddata), and the second version data refers to the version data of the current firmware upgrade (also called new version data newdata).
[0046] For example, the first version data is ABABCCDEF, and the second version data is ABABCCDEG. The difference data between the second version data and the first version data is "G", so the first version data is updated by the second version data to upgrade the firmware.
[0047] The version data can be a binary file or a text file. Therefore, the differential package generation method and the differential package restoration method provided in the embodiments of the present application can be applied to both binary files and text files.
[0048] The server obtains the first version data and the second version data by obtaining the first version data and the second version data input by the user, or by reading the first version data and the second version data stored in the database. The specific acquisition method can be determined according to actual conditions.
[0049] In step S102, the server sorts the suffix array of the first version data according to the lexicographical order rule to obtain the shortest suffix array set of the first version data; the shortest suffix array set includes the first suffix array with different data as the first byte after the suffix array of the first version data is sorted according to the lexicographical order rule.
[0050] Lexicographic order sorting is a rule that arranges elements according to the order of their characters in the dictionary. The core idea is to simulate the arrangement of words in a dictionary, comparing the size of each character from left to right until the order is determined.
[0051] The basic rules for lexicographical sorting are as follows: (1) High-order first rule: Compare characters from left to right, and the first different character determines the overall order. Characters are compared based on their ASCII value (or Unicode value), for example: 'A' (ASCII=65) < 'a' (ASCII=97) (uppercase letters are less than lowercase letters).
[0052] (2) Shortest string priority principle: If one string is a prefix of another string, the shorter string comes first (for example: "apple" < "apples").
[0053] (3) Comparison of characters at the same position: If the characters at the kth position are different, the string with the smaller character value is smaller, for example: "cat" < "dog", because 'c' (ASCII=99) < 'd' (ASCII=100).
[0054] For example, the string sorting: ["banana", "apple", "cherry"] is arranged in lexicographical order as ["apple", "banana", "cherry"].
[0055] Lexicographical sorting includes the following algorithm categories: (1) Explicit comparison algorithms: quick sort, merge sort, heap sort, and insertion sort, etc.
[0056] (2) Implicit lexicographic ordering algorithms: radix sort, dictionary tree sort, suffix array-specific algorithms, etc.; among them, suffix array-specific algorithms include: divsufsort open source algorithm and other family algorithms under this algorithm system, DC3 algorithm, SA-IS algorithm, post-sort construction method, BWT algorithm and qsufsort algorithm, etc.
[0057] The suffix array is an index array consisting of all the suffixes of a string.
[0058] For example, the suffix array of the first version data ABABCCDEF includes: ABABCCDEF (starting from index 0), BABCCDEF (starting from index 1), ABCCDEF (starting from index 2), BCCDEF (starting from index 3), CCDEF (starting from index 4), CDEF (starting from index 5), DEF (starting from index 6), EF (starting from index 7), and F (starting from index 8). Therefore, the suffix array of the first version data is [0, 1, 2, 3, 4, 5, 6, 7, 8].
[0059] The shortest suffix array refers to the first suffix array with a different character as the first byte after the suffix arrays of the string are sorted according to the lexicographic order rule.
[0060] For example, the suffix array of the first version data ABABCCDEF, after being sorted in lexicographic order, is: ABABCCDEF (index 0), ABCCDEF (index 2), BABCCDEF (index 1), BCCDEF (index 3), CCDEF (index 4), CDEF (index 5), DEF (index 6), EF (index 7), and F (index 8). The suffix array of the first version data, after being sorted in lexicographic order, is [0, 2, 1, 3, 4, 5, 6, 7, 8].
[0061] Among them, ABABCCDEF (index 0) and ABCCDEF (index 2) both start with "A", but ABABCCDEF (index 0) comes before ABCCDEF (index 2). Therefore, the shortest suffix array of a string starting with "A" is ABABCCDEF (index 0). BABCCDEF (index 1) and BCCDEF (index 3) both start with "B", but BABCCDEF (index 1) comes before BCCDEF (index 3). Therefore, the shortest suffix array of a string starting with "B" is BABCCDEF (index 1). CCDEF (index 4) and CDEF (index 5) both start with "C", but CCDEF (index 4) comes before CDEF (index 5). Therefore, the shortest suffix array of a string starting with "C" is CCDEF (index 4).
[0062] Based on the above analysis, the shortest suffix array set of the first version data ABABCCDEF includes: ABABCCDEF (index 0), BABCCDEF (index 1), CCDEF (index 4), DEF (index 6), EF (index 7) and F (index 8).
[0063] To reduce the amount of data stored, the starting index position of each shortest suffix array is recorded at the end [0, 1, 4, 6, 7, 8]. The corresponding shortest suffix array is constructed from the byte corresponding to the starting index to the last byte of the first version data.
[0064] Step S103: The server traverses the second version data according to the shortest suffix array set to obtain a covering line set; the covering line set includes the maximum matching data segment between the first version data and the data segment consisting of the first byte of the second version data and the last byte of the second version data; Step S104: The server generates a differential package of the first version data and the second version data according to the coverage line set.
[0065] In practice, a coverage line refers to the largest continuous data segment in the second version of the data, starting from a different starting position and ending at the last byte of the second version of the data, that matches the first version of the data. This helps identify the largest portion of the second version of the data that overlaps and matches the first version of the data, thereby determining the data range that needs to be updated.
[0066] Through cover line analysis, the largest common part between the second version data and the first version data can be identified to avoid repeated transmission of the same data.
[0067] The server traverses the second version data according to the shortest suffix array set to obtain a coverage line set, including: comparing the data segments of the second version data from different starting positions to the last byte with each shortest suffix array in the shortest suffix array set byte by byte to find the corresponding maximum matching data segment and obtain the coverage line set.
[0068] For example, the first version data is ABABCCDEF and the second version data is ABABCCDEG. According to analysis, the largest matching data segment between the first version data and the second version data is "ABABCCDE", and the difference is "G".
[0069] Finally, a differential package of the first version data and the second version data is generated according to the coverage line set.
[0070] In the embodiment of the present application, since the shortest suffix data set includes the first suffix array with different data as the first byte after the first version data is sorted according to the lexicographic order rule, the number of suffix arrays that need to be compared when obtaining the coverage line set is reduced, thereby speeding up the acquisition of the coverage line set. Furthermore, since the shortest suffix data set only stores the first suffix array with different data as the first byte, the number of generated coverage lines is also reduced, thereby reducing the data volume of the generated differential packets, improving the efficiency of generating differential packets based on the coverage line set, and thereby improving the efficiency of firmware upgrades.
[0071] In some embodiments, the server sorts the first version data lexicographically to obtain the shortest suffix array set of the first version data, including: the server uses a sorting search algorithm to construct a suffix array set after the first version data is sorted lexicographically; the suffix array set includes sub-suffix array sets with different data as the first byte; the server obtains the shortest suffix array set of the first version data based on the first suffix array in each sub-suffix array set.
[0072] In a specific implementation process, the sorting search algorithm may be any algorithm in the algorithm classification included in the lexicographic order rule sorting in the above embodiment.
[0073] By using any of the above algorithms, a suffix array set of the first version of the data, sorted lexicographically, can be obtained. A minimum binary search algorithm is then used to select from the suffix array set the shortest suffix arrays corresponding to strings with different data as the first byte, forming a shortest suffix array set.
[0074] To save storage space, a cache lookup table, cached_char_range, is created for each set of shortest suffix arrays. This cache lookup table stores the index of the first byte of each shortest suffix array in the first version of the data, that is, the byte offset of the first byte of each shortest suffix array relative to the first address of the first version of the data. For details, see the examples in the above embodiment.
[0075] The cache lookup table stores data in the form of key-value pairs, where the key is the ASCII value or Unicode value corresponding to the character of the first byte of each shortest suffix array, and the value is the byte offset of the first byte of each shortest suffix array relative to the first address of the first version data.
[0076] In one embodiment, the representation range of the cache lookup table is [0, 255].
[0077] The embodiment of the present application quickly obtains the suffix array set of the first version data through a sorting search algorithm. Since the suffix array set is already an array sorted by the lexicographical order rule, the shortest suffix array set can be quickly obtained, thereby improving the efficiency of generating differential packets based on the coverage line set, thereby improving the efficiency of firmware upgrades.
[0078] In some embodiments, the server traverses the second version data according to the shortest suffix array set to obtain a coverage line set, including: determining the target shortest suffix array: taking the data value corresponding to the target index of the second version data as the basic index value, querying the target shortest suffix array corresponding to the basic index value and the index value that satisfies a preset relationship with the basic index value in the shortest suffix array set; the target index is determined by adding the target index in the previous loop and the data segment length of the maximum matching data segment determined in the previous loop; the target index corresponding to the first loop is the index of the first byte in the second version data; determining the maximum matching data segment: determining that the data segment of the second version data from the target index to the last byte is a continuous and equal data segment compared with each target shortest suffix array, taking the data segment with the longest length in the data segment as the maximum matching data segment, and writing the maximum matching data segment into the coverage line set; looping the steps of determining the target shortest suffix array and determining the maximum matching data segment until the target index is greater than the length of the second version data to obtain the coverage line set.
[0079] During the specific implementation process, in order to speed up the generation of the coverage line set, when determining the target shortest suffix array, the data value corresponding to the target index of the second version of the data is used as the basic index value, and the target shortest suffix array corresponding to the basic index value and the index value that satisfies a preset relationship with the basic index value is queried in the shortest suffix array set.
[0080] The preset relationship is a pre-set value. For example, the basic index value is v, and other index values that meet the preset relationship are v-1, v+1, v+2, etc.
[0081] The data value corresponding to the target index of the second version data refers to the ASCII value or Unicode value of the character corresponding to the target index. For example, the ASCII value of the first A in the second version data ABABCCDEG is 65.
[0082] It should be noted that if the second version data is directly represented by ASCII or Unicode values, the value corresponding to the target index can be directly obtained. If the second version data is represented by binary data, the binary data is converted to ASCII or Unicode values. If the second version data is represented by characters, the characters are converted to the corresponding ASCII or Unicode values.
[0083] After determining the target shortest suffix array, determine the maximum matching data segment. Specifically, determine the data segment of the second version data from the target index to the last byte, which is continuous and equal to the data segment compared with each target shortest suffix array. Take the data segment with the longest length in the data segment as the maximum matching data segment, and write the maximum matching data segment into the coverage line set.
[0084] Then, the steps of determining the target shortest suffix array and determining the maximum matching data segment are executed in a loop until the target index is greater than the length of the second version data, thereby obtaining a set of coverage lines.
[0085] Exemplarily, for the j-th byte in the second version of data (newdata), its value is v=newdata[j]. The suffix arrays of v-1, v, and v+1 are found in the cache lookup table cached_char_range. The character string from the j-th byte to the last byte of the second version of data is retrieved in turn and compared with the suffix arrays corresponding to v-1, v, and v+1 respectively. The length of consecutive equal characters is determined respectively, and then the longest data segment is obtained as the maximum matching data segment. The length L of the maximum matching data segment and the starting index of the maximum matching data segment in the first version of data and the second version of data are recorded respectively, and they are recorded in the coverage line set.
[0086] The set of covered lines is denoted as cover_seg. The maximum matching data segment obtained by the above search is denoted as (i, j, L) in cover_seg, where i represents the starting index of the maximum matching data segment in the first version of the data, j represents the starting index of the maximum matching data segment in the second version of the data, and L represents the length of the maximum matching data segment.
[0087] If the j+Lth byte of the second version data exists, continue to perform the above operation on the j+Lth byte in newdata until the j+Lth byte of the second version data does not exist. At this point, the maximum matching data segment between the shortest suffix array set and the second version data is retrieved, and the cover line set cover_seg is obtained.
[0088] In the process of generating a coverage line set, the embodiment of the present application uses the data value corresponding to the target index of the second version data as the basic index value, and determines the target shortest suffix array based on the basic index value and the index value that satisfies a preset relationship with the basic index value, so that the target shortest suffix array has a high degree of matching with the data segment of the second version data starting from the target index to the last byte, thereby improving the quality of the determined maximum matching data segment. In addition, the target index is determined by adding the target index in the previous loop and the data segment length of the maximum matching data segment determined in the previous loop, which reduces the number of loops and speeds up the generation of the coverage line set. The efficiency of generating differential packets based on the coverage line set is improved, thereby improving the efficiency of firmware upgrades.
[0089] In some embodiments, the server writes the maximum matching data segment into the coverage line set, including: if the first maximum matching data segment obtained in the current loop is co-linear with the second maximum matching data segment obtained in the previous loop, merging the first maximum matching data segment and the second maximum matching data segment to form a third maximum matching data segment; deleting the first maximum matching data segment and the second maximum matching data segment, and writing the third maximum matching data segment into the coverage line set; if the first maximum matching data segment obtained in the current loop covers the second maximum matching data segment obtained in the previous loop, deleting the second maximum matching data segment, and writing the first maximum matching data segment into the coverage line set; if the first maximum matching data segment obtained in the current loop is covered by the second maximum matching data segment obtained in the previous loop, deleting the first maximum matching data segment.
[0090] In the specific implementation process, since the shortest suffix array in the shortest suffix array set of the first version data is compared with the data segment composed of characters from different starting positions to the last byte of the second version data, the maximum matching data segment is obtained to be collinear. In order to optimize the quantity and quality of the maximum matching data segments in the coverage line set, when adding the current maximum matching data segment to the coverage line set, it is necessary to perform collinearity judgment and coverage judgment with the maximum matching data segment added to the coverage line set last time.
[0091] Illustratively, when adding a cover line to the cover line set cover_seg, the first largest matching data segment to be added to the cover line set cover_seg is recorded as cur_cover(cur_oldpos, cur_newpos, cur_length). Here, cur_oldpos represents the starting index of the first largest matching data segment in the first version of the data, that is, the offset of the first largest matching data segment relative to the first address of the first version of the data; cur_newpos represents the starting index of the first largest matching data segment in the second version of the data, that is, the offset of the first largest matching data segment relative to the first address of the second version of the data; and cur_length represents the length of the first largest matching data segment.
[0092] The last largest matching data segment added to the cover line set cover_seg is denoted as last_cover(last_oldpos, last_newpos, last_length). Here, last_oldpos represents the starting index of the second largest matching data segment in the first version of the data, that is, the offset of the second largest matching data segment relative to the first address of the first version of the data; last_newpos represents the starting index of the second largest matching data segment in the second version of the data, that is, the offset of the second largest matching data segment relative to the first address of the second version of the data; and last_length represents the length of the second largest matching data segment.
[0093] Check whether cur_cover and last_cover are on the same line. If so, the two maximum matching data segments are considered collinear. In this case, cur_cover and last_cover are directly merged and the merged data segment is written to the cover line set. The current maximum matching data segment and the last maximum matching data segment in the cover line set are deleted.
[0094] If cur_cover and last_cover are not on the same line, add the current maximum matching data segment to the cover line set.
[0095] In addition to determining whether the first maximum matching data segment is collinear with the second maximum matching data segment obtained in the previous loop, it is also possible to determine whether cur_cover is covered by last_cover, or whether last_cover is covered by cur_cover; if cur_cover is covered by last_cover, then cur_cover is deleted; if last_cover is covered by cur_cover, then cur_cover is added to the coverage line set and last_cover is deleted.
[0096] When judging coverage, the judgment is made based on the starting indexes of cur_cover and last_cover in the second version data and whether cur_cover completely contains last_cover or whether last_cover completely contains cur_cover.
[0097] Exemplarily, if the starting index of cur_cover in the second version of the data is less than or equal to the starting index of last_cover in the second version of the data, and cur_cover completely includes last_cover, then cur_cover covers last_cover.
[0098] The embodiment of the present application merges the collinear maximum matching data segments, deletes the merged maximum matching data segments, and also deletes the covered maximum matching data segments, so that the only data retained are the maximum matching data segments that do not overlap with each other, thereby further reducing the number of coverage lines in the coverage line set and improving the quality of the coverage lines, thereby reducing the data volume of the generated differential packets, improving the efficiency of generating differential packets based on the coverage line set, and improving the efficiency of firmware upgrades.
[0099] In some embodiments, the maximum matching data segment includes the first starting position of the maximum matching data segment in the first version data and the second starting position of the maximum matching data segment in the second version data; the method for determining whether the first maximum matching data segment obtained in the current loop and the second maximum matching data segment obtained in the previous loop are collinear is as follows: if the sum of the first starting position of the first maximum matching data segment and the first starting position of the second maximum matching data segment is equal to the sum of the second starting position of the first maximum matching data segment and the second starting position of the second maximum matching data segment, then it is determined that the first maximum matching data segment and the second maximum matching data segment are collinear; or, if the distance between the first maximum matching data segment and the second maximum matching data segment is not greater than a preset distance threshold, then it is determined that the first maximum matching data segment and the second maximum matching data segment are collinear.
[0100] During the specific implementation process, the first starting position of the maximum matching data segment is recorded as cur_oldpos, the first starting position of the second maximum matching data segment is recorded as last_oldpos, the second starting position of the first maximum matching data segment is recorded as cur_newpos, and the second starting position of the second maximum matching data segment is recorded as last_newpos. If last_oldpos+cur_oldpos=last_newpos+cur_newpos, then the first maximum matching data segment and the second maximum matching data segment are considered to be collinear.
[0101] In another embodiment, when determining whether the first maximum matching data segment and the second maximum matching data segment are collinear, the spacing between the first maximum matching data segment and the second maximum matching data segment is calculated by cur_newpos-(last_newpos+last_length), and then the spacing is compared with a preset distance threshold. If the spacing is less than or equal to the preset distance threshold, the first maximum matching data segment and the second maximum matching data segment are collinear; if the spacing is greater than the preset distance threshold, the first maximum matching data segment and the second maximum matching data segment are not collinear.
[0102] The preset distance threshold is set in advance based on the size and similarity between the first version data and the second version data.
[0103] The embodiment of the present application determines whether the first maximum matching data segment and the second maximum matching data segment are collinear, merges the collinear first maximum matching data segment and the second maximum matching data segment, reduces the number of coverage lines in the coverage line set, thereby reducing the data volume of the generated differential packet, and improves the efficiency of generating differential packets based on the coverage line set, thereby improving the efficiency of firmware upgrades.
[0104] In some embodiments, a server generates a differential package of first version data and second version data based on a set of coverage lines, including: the server obtains verification parameters; the server generates first differential data based on the number of maximum matching data segments in the set of coverage lines, the data segment length of each maximum matching data segment, the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the first version data, and the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the second version data; the server encodes and compresses the first differential data to obtain differential compressed data; During the specific implementation process, the total number of maximum matching data segments contained in the coverage line set is written into the temporary buffer buf, and then each maximum matching data segment in the coverage line set is written into the temporary buffer buf.
[0105] Specifically, the maximum matching data segments are written into the temporary buffer buf in sequence according to the writing order of the maximum matching data segments in the coverage line set.
[0106] When writing each maximum matching data segment into the temporary buffer buf, the data segment length of each maximum matching data segment, the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the first version of the data, and the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the second version of the data are written in sequence.
[0107] If a maximum matching data segment does not have a previous maximum matching data segment (i.e., the first maximum matching data segment written into the coverage line set), then the offset increment of the maximum matching data segment relative to the first address of the first version data is written, and the offset increment of the maximum matching data segment relative to the first address of the second version data is written.
[0108] For example, if the index position of a maximum matching data segment in the first version of the data is 5, and the index position of the previous maximum matching data segment in the first version of the data is 3, then the offset increment of this maximum matching data segment relative to the previous maximum matching data segment in the first version of the data is (5-3) = 2. Similarly, the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the second version of the data can be calculated.
[0109] After the first differential data is generated, the first differential data is coded and compressed to obtain differential compressed data.
[0110] In order to save storage resources of the temporary buffer buf and reduce the data volume of the generated differential packet, the first differential data is deleted, the differential compressed data is written to the temporary buffer buf, and the dictionary size of the differential compressed data is written to the header of the temporary buffer buf.
[0111] In order to improve the accuracy and legitimacy of differential restoration performed by the terminal whose firmware is to be upgraded, the server further obtains verification parameters, which are used by the terminal whose firmware is to be upgraded to verify the legitimacy and accuracy of the differential packet.
[0112] The verification parameters include at least one of the identifier upgrade mode "hc", the project name, the first version data version number, the second version data version number, the first version data size, the second version data size, and reserved content. The reserved content is used to store special information of a special project.
[0113] After obtaining the verification parameters, the identifier upgrade mode "hc" (2 bytes), project name (8 bytes, if the length exceeds this range, the current process will be stopped and an error will be output, and the insufficient distribution will be filled with 0), first version data version number (8 bytes, if the length exceeds this range, the current process will be stopped and an error will be output, and the insufficient distribution will be filled with 0), second version data version number (8 bytes, if the length exceeds this range, the current process will be stopped and an error will be output, and the insufficient distribution will be filled with 0), first version data size (4 bytes, in bytes), second version data size (4 bytes, in bytes) and reserved content (6 bytes, each byte is filled with 0x55).
[0114] After writing the verification parameters, in order to enable the terminal whose firmware is to be upgraded to verify the integrity of the differential packet, an md5 value may be generated from the content stored in the temporary buffer buf and the md5 value may be written into the temporary buffer header.
[0115] Create a differential package file, write the contents of the temporary buffer buf into the differential package file, and generate a differential package.
[0116] This embodiment of the present application generates first differential data based on the offset increments of two adjacent maximum matching data segments, thereby reducing the amount of stored data and, therefore, the amount of first differential data. By encoding and compressing the first differential data, the amount of differential packet data is reduced. Furthermore, by combining the first differential data with verification parameters to generate a differential packet, the integrity and legitimacy of the differential packet are improved.
[0117] In some embodiments, the method further includes: if there is a gap between two adjacent maximum matching data segments in the coverage line set in the second version data, the difference data corresponding to the gap in the second version data and the offset increment of the difference data relative to the starting position of the second version data are written into the first differential data to generate second differential data; accordingly, the first differential data is encoded and compressed to obtain differential compressed data, including: encoding and compressing the second differential data to obtain differential compressed data.
[0118] During the specific implementation process, if there is a gap between two adjacent maximum matching data segments in the coverage line set in the second version data, it indicates that there is an area in the second version data that is not covered by the maximum matching data segment in the coverage line set, and the difference data of the uncovered area needs to be written into the first differential data.
[0119] For example, if the first version of data is ABABCCDEF and the second version of data is ABABCCDEG, and the difference between the second and first versions is "G," then "G" and the offset increment of "G" relative to the start position of the second version of data are written into the first differential data to generate the second differential data.
[0120] In an embodiment of the present application, taking into account the existence of differential data between the first version data and the second version data, that is, the area not covered by the cover lines in the cover line set, the second differential data is generated by writing the differential data between the first version data and the second version data and the offset increment of the differential data relative to the starting position of the second version data into the first differential data, and then generating a differential package based on the second differential data, thereby improving the integrity of the differential package.
[0121] Figure 2 A flow chart of another differential packet generation method provided in an embodiment of the present application is shown as follows: Figure 2 As shown, a suffix array set of the old version data (first version data) is generated after being sorted by the lexicographical order rule; a cache lookup table is generated based on the suffix array set to obtain the shortest suffix array set; the new version data (second version data) is traversed based on the shortest suffix array set to generate a cover line set; the cover line set is optimized (collinearity judgment and cover judgment); the cover line set is written into the temporary cache area and compressed; the differential package data version related information (verification parameters) is written, and the MD5 checksum value of the differential package header is written to obtain the differential package.
[0122] Figure 3 A flowchart of a differential packet restoration method provided in an embodiment of the present application is shown as follows: Figure 3 The method is applied to a terminal whose firmware is to be upgraded, which may be a smartphone, tablet computer, smart home device, or vehicle-mounted terminal. The method includes: Step S301: The terminal receives a differential packet generated by the method of any one of the above embodiments; the differential packet includes differential compression data; Step S302: The terminal decompresses the differential compressed data to obtain decompressed differential data. In step S303, the terminal performs differential restoration based on the decompressed differential data.
[0123] During implementation, if the second version data is written directly to the same storage address as the first version data, and the upgrade process is interrupted for various reasons, the first and second version data will be mixed, causing device failure. Furthermore, the differential packet data must be independent and complete and cannot be overwritten, otherwise the differential information will be corrupted and the upgrade cannot be completed. Therefore, three non-overlapping segments are selected on the terminal where the firmware is to be upgraded: one for storing the first version data, the differential packet generated using any of the above-described methods, and the second version data after the restoration step.
[0124] According to the dictionary size of the differentially compressed data, a dynamic memory space of the dictionary size is opened to store the differentially compressed data, and a dynamic memory space of a preset size is opened to store part of the directly read differentially compressed data, part of the first version data, and part of the decompressed differential data.
[0125] The preset size of the dynamic memory space can be 1024 bytes, 256 bytes, etc. It is set according to the remaining memory of the device to be upgraded.
[0126] Finally, differential restoration is performed based on the decompressed differential data.
[0127] When performing differential restoration, the embodiment of the present application receives a differential packet generated according to the differential packet generation method. Since the data volume of the differential packet is small, the time consumed for restoration based on the differential packet is shorter and the required dynamic memory space is smaller, thereby improving the efficiency of differential restoration and thus improving the efficiency of firmware upgrade.
[0128] In some embodiments, the differential data includes the number of maximum matching data segments in the coverage line set, the data segment length of each maximum matching data segment, the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the first version data, and the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the second version data; the first version data is stored in the terminal, and the second version data is used to update the first version data; the terminal performs differential restoration based on the decompressed differential data, including: reading the corresponding data segment from the first version data according to the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the first version data and the data segment length of each maximum matching data segment; writing the data segment to the storage area corresponding to the second version data based on the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the second version data, for differential restoration.
[0129] During the specific implementation process, the corresponding data segments are read from the first version data stored in the firmware terminal to be upgraded based on the offset increment and data segment length of each maximum matching data segment in the decompressed differential data in the first version data, and then the data segments are written into the storage area corresponding to the second version data based on the offset increment of each maximum matching data segment in the second version data to perform differential restoration.
[0130] The embodiment of the present application reads the corresponding data segment from the first version data based on the offset increment of each maximum matching data segment in the differential packet relative to the previous maximum matching data segment in the first version data and the data segment length of each maximum matching data segment. When the second version data contains data identical to the first version data, it is directly read from the first version data stored in the terminal and written into the storage area corresponding to the second version data, thereby improving the efficiency of differential restoration.
[0131] In some embodiments, the method further includes: if the differential data further includes difference data and an offset increment of the difference data relative to a starting position of the second version data, then writing the difference data into a storage area corresponding to the second version data based on the offset increment.
[0132] In a specific implementation process, if there is still difference data in the decompressed differential data, the difference data is directly written into the discontinuous storage area range in the second version data.
[0133] In an embodiment of the present application, when the differential data includes difference data, the difference data is written into a storage area corresponding to the second version data, thereby improving the integrity of the differential restoration.
[0134] In some embodiments, the differential packet further includes a verification parameter; before decompressing the differential compressed data, the method further includes: verifying the verification parameter; if the verification is successful, executing the step of decompressing the differential compressed data.
[0135] In the specific implementation process, the verification parameters can be found in the above embodiment and will not be described again here.
[0136] If the difference packet also includes an MD5 value, first take out the original MD5 value stored in the difference packet, recalculate the MD5 value of the remaining content of the difference packet except the MD5 value, and compare whether the two are consistent. If they are inconsistent, directly return an error.
[0137] The verification process based on the verification parameters is as follows: The upgrade method identifier is read and checked to see if it is equal to "hc." If not, an error is returned. If not, the project name is read and compared to the project name entered by the user or read from the file name. If not, an error is returned. If not, the first version data version number is read and compared to the first version data version number entered by the user or read from the file name. If not, an error is returned. If not, the second version data version number is read and compared to the second version data version number entered by the user or read from the file name. If not, an error is returned. If not, the first version data size is read and compared to see if the read string matches the first version data size. If not, an error is returned. If not, the second version data size is read and recorded for use in subsequent differential restoration to compare the restored data size. If so, the restoration is considered successful; if not, the restoration fails. Finally, the reserved content is read.
[0138] After verifying the verification parameters one by one, if all the verifications are successful, the differential compressed data is decompressed.
[0139] The embodiment of the present application verifies the verification parameters before decompressing the differential compressed data, thereby improving the legitimacy of the differential restoration.
[0140] Figure 4 A flow chart of another differential packet restoration method provided in an embodiment of the present application is shown as follows: Figure 4 As shown, the method includes: obtaining "old version data storage address, differential package storage address, new version data storage address, project name, old data version number, new data version number, old version data size and new version data size" from a file or input by a user; performing MD5 verification on the differential package; checking the input basic information; judging whether the input basic information matches the information stored in the differential package, and if not, returning an error; if they match, reading the compression dictionary size; opening up dynamic memory space according to the compression dictionary size; decompressing the differential compressed data; restoring according to the differential coverage line information; writing the restored data into the storage area of the new version data in the storage; judging whether the new version data size is equal to the amount of data written by the above-mentioned differential restoration step, and if so, the restoration is successful, and if not, returning an error.
[0141] To verify the effectiveness of the differential packet generation method and differential packet restoration method provided in the embodiments of the present application, the following verification is performed: The differential packet generation method and differential packet restoration method provided in the embodiments of the present application can be implemented based on C language, Java language, and Python language, and can be deployed on multiple system platforms (Windows or Linux).
[0142] The differential packet data size processed by the differential packet generation method of the embodiment of the present application has a data size compression rate of up to 50% compared with the differential method based on a hash set. It is more suitable for deployment in embedded devices (RTOS systems, Linux systems, Android systems, etc.).
[0143] Table 1
[0144] As shown in Table 1, the differential packet generated by the differential packet generation method of the present embodiment uses a smaller amount of data, resulting in a smaller dynamic memory footprint for restoration. Dynamic memory usage only requires the dictionary size used in the compression algorithm and the dynamic memory space associated with the differential packet size. Furthermore, restoration using the differential packet restoration method of the present embodiment takes less time, requiring less than 2 seconds to restore 6KB of new version data.
[0145] Figure 5 A schematic diagram of the structure of a differential packet generation device provided in an embodiment of the present application is shown as follows: Figure 5 As shown, the device includes: an acquisition module 501, which is used to acquire first version data and second version data; the second version data is used to update the first version data; a first acquisition module 502, which is used to sort the suffix array of the first version data according to the lexicographical order rule to obtain the shortest suffix array set of the first version data; the shortest suffix array set includes the first suffix array with different data as the first byte after the suffix array of the first version data is sorted according to the lexicographical order rule; a second acquisition module 503, which is used to traverse the second version data according to the shortest suffix array set to obtain a coverage line set; the coverage line set includes the maximum matching data segment between the data segment with different data as the first byte to the last byte of the second version data in the second version data and the first version data; a generation module 504, in which the user generates a differential package of the first version data and the second version data according to the coverage line set.
[0146] Based on the above embodiment, the first obtaining module 502 is specifically used to: construct a suffix array set of the first version data after sorting it according to the lexicographical order rule using a sorting search algorithm; the suffix array set includes sub-suffix array sets with different data as the first byte; and obtain the shortest suffix array set of the first version data based on the first suffix array in each sub-suffix array set.
[0147] On the basis of the above embodiment, the second acquisition module 503 is specifically used to: determine the target shortest suffix array: take the data value corresponding to the target index of the second version data as the basic index value, and query the target shortest suffix array corresponding to the basic index value and the index value that satisfies a preset relationship with the basic index value in the shortest suffix array set; the target index is determined by adding the target index in the previous loop and the data segment length of the maximum matching data segment determined in the previous loop; the target index corresponding to the first loop is the index of the first byte in the second version data; determine the maximum matching data segment: determine the data segment of the second version data from the target index to the last byte, which is continuous and equal to each target shortest suffix array, take the data segment with the longest length in the data segment as the maximum matching data segment, and write the maximum matching data segment into the coverage line set; loop the steps of determining the target shortest suffix array and determining the maximum matching data segment until the target index is greater than the length of the second version data, and obtain the coverage line set.
[0148] Based on the above embodiment, the second acquisition module 503 is specifically used to: if the first maximum matching data segment obtained in the current loop is collinear with the second maximum matching data segment obtained in the previous loop, the first maximum matching data segment and the second maximum matching data segment are merged to form a third maximum matching data segment; the first maximum matching data segment and the second maximum matching data segment are deleted, and the third maximum matching data segment is written into the coverage line set; if the first maximum matching data segment obtained in the current loop covers the second maximum matching data segment obtained in the previous loop, the second maximum matching data segment is deleted, and the first maximum matching data segment is written into the coverage line set; if the first maximum matching data segment obtained in the current loop is covered by the second maximum matching data segment obtained in the previous loop, the first maximum matching data segment is deleted.
[0149] Based on the above embodiment, the maximum matching data segment includes the first starting position of the maximum matching data segment in the first version data and the second starting position of the maximum matching data segment in the second version data; the method for determining whether the first maximum matching data segment obtained in the current cycle and the second maximum matching data segment obtained in the previous cycle are collinear is as follows: if the sum of the first starting position of the first maximum matching data segment and the first starting position of the second maximum matching data segment is equal to the sum of the second starting position of the first maximum matching data segment and the second starting position of the second maximum matching data segment, then it is determined that the first maximum matching data segment and the second maximum matching data segment are collinear; or, if the distance between the first maximum matching data segment and the second maximum matching data segment is not greater than the preset distance threshold, then it is determined that the first maximum matching data segment and the second maximum matching data segment are collinear.
[0150] Based on the above embodiments, the generation module 504 is specifically used to: obtain verification parameters; generate first differential data according to the number of maximum matching data segments in the coverage line set, the data segment length of each maximum matching data segment, the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the first version data, and the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the second version data; encode and compress the first differential data to obtain differential compressed data; generate a differential package according to the differential compressed data and the verification parameters.
[0151] Based on the above embodiment, the generation module 504 is specifically used to: if there is a gap between two adjacent maximum matching data segments in the coverage line set in the second version data, then the difference data corresponding to the gap in the second version data and the offset increment of the difference data relative to the starting position of the second version data are written into the first differential data to generate second differential data; accordingly, the first differential data is encoded and compressed to obtain differential compressed data, including: encoding and compressing the second differential data to obtain differential compressed data.
[0152] It should be understood that this device corresponds to the aforementioned differential packet generation method embodiment and is capable of executing each of the steps involved in the aforementioned method embodiment. The specific functions of this device can be found in the description above; to avoid repetition, a detailed description is omitted here. The device includes at least one software functional module that can be stored in a memory in the form of software or firmware or embedded in the device's operating system (OS).
[0153] Figure 6 A schematic diagram of the structure of a differential packet restoration device provided in an embodiment of the present application is shown as follows: Figure 6 As shown, the device includes: a receiving module 601, used to receive a differential packet generated by the method of any one of the above embodiments; the differential packet includes differential compressed data; a decompression module 602, used to decompress the differential compressed data to obtain decompressed differential data; and a restoration module 603, used to perform differential restoration based on the decompressed differential data.
[0154] Based on the above embodiment, the differential data includes the number of maximum matching data segments in the coverage line set, the data segment length of each maximum matching data segment, the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the first version data, and the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the second version data; the first version data is stored in the terminal, and the second version data is used to update the first version data; the restoration module 603 is specifically used to: read the corresponding data segment from the first version data according to the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the first version data and the data segment length of each maximum matching data segment; write the data segment into the storage area corresponding to the second version data based on the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the second version data to perform differential restoration.
[0155] Based on the above embodiment, the restoration module 603 is specifically configured to: if the differential data further includes differential data and an offset increment of the differential data relative to the starting position of the second version data, write the differential data into the storage area corresponding to the second version data based on the offset increment.
[0156] Based on the above embodiment, the differential packet further includes a verification parameter; the device further includes a verification module, which is used to: verify the verification parameter; if the verification is successful, execute the step of decompressing the differential compressed data.
[0157] It should be understood that this device corresponds to the aforementioned differential packet restoration method embodiment and is capable of executing each of the steps involved in the aforementioned method embodiment. The specific functions of this device can be found in the description above; to avoid repetition, a detailed description is omitted here. This device includes at least one software functional module that can be stored in a memory in the form of software or firmware or embedded in the device's operating system (OS).
[0158] Figure 7 This is a schematic diagram of the electronic device structure provided in the embodiment of the present application, such as Figure 7 As shown, the electronic device includes a processor 701 (processor), a memory 702 (memory), and a bus 703. The processor 701 and the memory 702 communicate with each other via the bus 703. The processor 701 is used to call program instructions in the memory 702 to execute the methods provided by the above-mentioned method embodiments.
[0159] Processor 701 can be an integrated circuit chip with signal processing capabilities. The processor 701 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor.
[0160] The memory 702 can be implemented by any type of volatile or non-volatile memory device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0161] An embodiment of the present application provides a computer program product, including: computer program instructions, which, when executed by a processor, execute the methods provided by the above-mentioned method embodiments.
[0162] An embodiment of the present application provides a computer-readable storage medium, including: computer program instructions stored on the computer-readable storage medium, and the computer program instructions execute the methods provided by the above-mentioned method embodiments when executed by a processor.
[0163] Computer-readable storage media can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0164] In the embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interface, the indirect coupling or communication connection of the device or unit can be electrical, mechanical or other forms.
[0165] In addition, the units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0166] Furthermore, the functional modules in each embodiment of the present application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0167] The above are merely examples of the present application and are not intended to limit the scope of protection of the present application. Those skilled in the art will appreciate that various modifications and variations are possible. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present application shall be included within the scope of protection of the present application.
Claims
1. A differential packet generation method, characterized in that: include: Obtain first version data and second version data; the second version data is used to update the first version data; Sorting the suffix array of the first version data according to a lexicographical order rule to obtain a shortest suffix array set of the first version data; the shortest suffix array set includes the first suffix array with different data as the first byte after the suffix array of the first version data is sorted according to a lexicographical order rule; Traversing the second version data according to the shortest suffix array set to obtain a covering line set; the covering line set includes a maximum matching data segment between a data segment consisting of a first byte of different data to a last byte of the second version data in the second version data and the first version data; A differential package of the first version data and the second version data is generated according to the set of coverage lines.
2. The method according to claim 1, characterized in that The step of performing lexicographical sorting on the first version data to obtain a shortest suffix array set of the first version data includes: Constructing a suffix array set after the first version data is sorted according to the lexicographic order rule using a sorting search algorithm; the suffix array set includes a sub-suffix array set with different data as the first byte; The shortest suffix array set of the first version data is obtained according to the first suffix array in each of the sub-suffix array sets.
3. The method according to claim 1, characterized in that The traversing the second version data according to the shortest suffix array set to obtain a set of coverage lines includes: Determining a target shortest suffix array: using the data value corresponding to the target index of the second version of the data as a base index value, querying the shortest suffix array set for the target shortest suffix arrays corresponding to the base index value and the index values that satisfy a preset relationship with the base index value; the target index is determined by adding the target index in the previous loop and the data segment length of the maximum matching data segment determined in the previous loop; the target index corresponding to the first loop is the index of the first byte in the second version of the data; Determine a maximum matching data segment: determine a data segment of the second version data from the target index to the last byte that is continuously equal to each of the target shortest suffix arrays, use the longest data segment among the data segments as the maximum matching data segment, and write the maximum matching data segment into the coverage line set; The steps of determining the target shortest suffix array and determining the maximum matching data segment are executed in a loop until the target index is greater than the length of the second version data, thereby obtaining the set of coverage lines.
4. The method according to claim 3, characterized in that Writing the maximum matching data segment into the set of coverage lines comprises: If the first maximum matching data segment obtained in the current loop is colinear with the second maximum matching data segment obtained in the previous loop, then merge the first maximum matching data segment and the second maximum matching data segment to form a third maximum matching data segment; delete the first maximum matching data segment and the second maximum matching data segment, and write the third maximum matching data segment into the coverage line set; If the first largest matching data segment obtained in the current loop covers the second largest matching data segment obtained in the previous loop, deleting the second largest matching data segment and writing the first largest matching data segment into the coverage line set; If the first largest matching data segment obtained in the current cycle is overwritten by the second largest matching data segment obtained in the previous cycle, the first largest matching data segment is deleted.
5. The method according to claim 4, characterized in that The maximum matching data segment includes a first starting position of the maximum matching data segment in the first version data and a second starting position of the maximum matching data segment in the second version data. A method for determining whether the first maximum matching data segment obtained in the current cycle and the second maximum matching data segment obtained in the previous cycle are collinear is as follows: If the sum of the first starting position of the first maximum matching data segment and the first starting position of the second maximum matching data segment is equal to the sum of the second starting position of the first maximum matching data segment and the second starting position of the second maximum matching data segment, then determining that the first maximum matching data segment and the second maximum matching data segment are collinear; or, If the distance between the first maximum matching data segment and the second maximum matching data segment is not greater than a preset distance threshold, it is determined that the first maximum matching data segment and the second maximum matching data segment are collinear.
6. The method according to any one of claims 1 to 5, characterized in that: Generating a differential package of the first version data and the second version data according to the set of coverage lines includes: Get verification parameters; generating first differential data according to the number of maximum matching data segments in the set of coverage lines, the data segment length of each maximum matching data segment, the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the first version data, and the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the second version data; encoding and compressing the first differential data to obtain differential compressed data; A differential packet is generated according to the differential compression data and the verification parameter.
7. The method according to claim 6, characterized in that The method further comprises: If there is a gap between two adjacent maximum matching data segments in the cover line set in the second version data, writing difference data corresponding to the gap in the second version data and an offset increment of the difference data relative to a starting position of the second version data into the first differential data to generate second differential data; Accordingly, encoding and compressing the first differential data to obtain differential compressed data includes: The second differential data is encoded and compressed to obtain differential compressed data.
8. A differential packet restoration method, characterized in that: The method is applied to a terminal whose firmware is to be upgraded, and the method includes: Receiving a differential packet generated by the method according to any one of claims 1 to 7, wherein the differential packet includes differential compressed data; Decompressing the differential compressed data to obtain decompressed differential data; Perform differential restoration based on the decompressed differential data.
9. The method according to claim 8, characterized in that The differential data includes the number of maximum matching data segments in the coverage line set, the data segment length of each maximum matching data segment, the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the first version of the data, and the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the second version of the data; The first version data is stored in the terminal, and the second version data is used to update the first version data; and performing differential restoration based on the decompressed differential data includes: Reading a corresponding data segment from the first version data according to an offset increment of each of the maximum matching data segments relative to a previous maximum matching data segment in the first version data and a data segment length of each of the maximum matching data segments; Based on the offset increment of each maximum matching data segment relative to the previous maximum matching data segment in the second version data, the data segment is written into the storage area corresponding to the second version data to perform differential restoration.
10. The method according to claim 9, characterized in that The method further comprises: If the differential data further includes difference data and an offset increment of the difference data relative to the starting position of the second version data, the difference data is written into a storage area corresponding to the second version data based on the offset increment.
11. The method according to any one of claims 8 to 10, characterized in that: The differential packet also includes a verification parameter; before decompressing the differential compressed data, the method further includes: Verifying the verification parameters; If the verification is successful, the step of decompressing the differential compressed data is performed.
12. An electronic device, characterized in that: include: A processor and a memory, wherein the memory stores machine-readable instructions executable by the processor, and when the machine-readable instructions are executed by the processor, the method according to any one of claims 1 to 11 is performed.
13. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer program instructions, and when the computer program instructions are executed by a processor, the method according to any one of claims 1 to 11 is executed.
14. A computer program product, characterized in that include: Computer program instructions, which, when executed by a processor, perform the method according to any one of claims 1 to 11.
Citation Information
Patent Citations
Internet of Things equipment upgrading method and system
CN114924761A