Program update method, electronic device, and server
By splitting new and old files into data blocks and loading only in RAM, it is necessary to solve the problem of high memory requirements on the system or program upgrade of the device, and realize the efficient upgrade on the resource restricted device.
Patent Information
- Application Number
- PCT/CN2024/078554
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-07-26
- Filing Date
- 2024-02-26
- Publication Date
- 2025-01-30
AI Technical Summary
When upgrading systems or programs on the device, the new and old files required for the upgrade need to be fully loaded into the device's RAM, resulting in high memory requirements and bottlenecks in upgrading performance, especially on thin devices with limited resources, it is difficult to upgrade efficiently.
By splitting new and old files into data blocks, and only data blocks that are to be read and write data are loaded into RAM, the RAM is used at a small level to achieve efficient software upgrades.
Effectively reduced memory occupation on RAM's limited devices, improved the efficiency of software upgrades, and upgraded the system or program efficiently on thin devices.
Smart Images

Figure CN2024078554_30012025_PF_FP_ABST
Abstract
Description
Program updating method, electronic device and server
[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office of China on July 26, 2023, with application number 202310932422.1 and application name “A program update method, electronic device and server”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of information technology (IT), and in particular to a program updating method, an electronic device, and a server. Background Art
[0003] With the development of the Internet of Things (IoT), system upgrades for both large and small IoT devices require downloading upgrade packages from a server and executing the upgrade program on the device. Typically, when upgrading a device's system or program, the device creates a new file based on the differential package downloaded from the server and the existing file to be upgraded. The device then uses the created file to upgrade the system or program.
[0004] During a system or program upgrade on a device, all required files, both new and old, must be loaded into random-access memory (RAM), placing high demands on the device's memory. As systems and programs become increasingly complex, the memory requirements for system or program updates on devices are increasing. The requirement to completely load all required files into the device's RAM to perform the upgrade has become a performance bottleneck for system or program upgrades on devices.
[0005] Summary of the Invention
[0006] The present application provides a program update method, electronic device, server, computer-readable medium, i.e., a computer program product. When updating, new and old files are split into data blocks, and only the data blocks of data to be read and written are loaded into RAM, and only a limited number of data blocks are retained in RAM, thereby keeping RAM usage at a small level.
[0007] In a first aspect, the present application provides a program update method, which is applied to an electronic device, and the method includes: obtaining an upgrade package of a target program, the upgrade package carrying a matching sequence and a non-matching data stream, the matching sequence including a matching field and a non-matching field, the matching field being used to indicate that a string in a first program file matches a string in the first program file or a string in a second program file, the non-matching field being used to indicate that a string in the first program file matches a string in the non-matching data stream, the first program file and the second program file being program files of different versions of the target program, and the version of the first program file being higher than the version of the second program file; in a random read storage The upgrade package is parsed in the RAM of the device to obtain matching fields, non-matching fields and non-matching data streams; according to the order of matching fields and non-matching fields in the matching sequence, when the field currently required to be operated is the matching field, the source data block to which the string associated with the matching field belongs is determined, and the source data block is read into the RAM, wherein the source data block is obtained by segmenting the second program file or the intermediate file obtained in the process of generating the first program file; when the field currently required to be operated is the non-matching field, the target string associated with the non-matching field is read from the non-matching data stream; and the first program file is generated based on at least one source data block and / or target string in the RAM.
[0008] In this solution, during the upgrade of target software on a terminal device, the corresponding second program file before the upgrade is divided into multiple data blocks. When generating the first program file in RAM, if data at a certain location in the first or second program file needs to be read, only the data block corresponding to that data segment needs to be read into RAM, without having to read the entire first or second program file into RAM. This keeps RAM usage to a minimum. This enables efficient software upgrades on thin devices with limited RAM.
[0009] In one possible implementation, generating a first program file based on at least one source data block and / or target character string in RAM includes: generating an intermediate file of the first program file in RAM, and writing at least a portion of the intermediate file into a read-only memory (ROM), wherein the intermediate file of the first program file is composed of at least a portion of the data in the first program file.
[0010] That is, during the process of generating the first program file in the RAM, the intermediate file of the first program file may be written into the ROM to reduce the occupation of the RAM.
[0011] In one possible implementation, the size of at least a portion of the data is the same as the size of the source data block.
[0012] That is, when the first program file is generated in RAM, it is also divided into data blocks. Whenever the data in the intermediate file of the first program file meets the size of a data block, the data block is written to ROM. This ensures that only one block is retained in RAM at the end where the second program file is generated, reducing RAM usage.
[0013] In one possible implementation, the matching field includes a mutual matching field and a self-matching field. The mutual matching field is used to indicate that a string in the first program file matches another string in the second program file, and the self-matching field is used to indicate that a string in the first program file matches a string other than the first string in the first program file. Both the mutual matching field and the self-matching field also include: data position and data length. The data position is used to identify the starting position of the string associated with the corresponding matching field in the first program file or the second program file, and the data length is used to identify the length of the string associated with the corresponding matching field.
[0014] In other words, the matching field may also include a self-matching field and a mutual-matching field. Both the self-matching field and the mutual-matching field contain the data location and data length of the corresponding matching field in the self-matching field and the mutual-matching field, so that the corresponding matching field can be obtained from the second program file or the intermediate file used to generate the first program file based on the self-matching field or the mutual-matching field. When the matching field is a mutual match, the corresponding matching field refers to the mutual match field; when the matching field is a self match, the corresponding matching field refers to the self-matching field.
[0015] In one possible implementation, determining the source data block to which the character string associated with the matching field belongs includes: when the matching fields are mutually matched, determining the source data block from the second program file; when the matching fields are self-matched, determining the source data block from an intermediate file obtained in the process of generating the first program file.
[0016] That is, when determining the data block to which the character string associated with the matching field belongs, it can be determined to which file the data block associated with the matching field belongs based on the type of the matching field.
[0017] In one possible implementation, before reading the source data block into the RAM, the method further includes: when the number of source data blocks in the RAM exceeds a first threshold, replacing the source data block in the RAM that has not been used for the longest time with the source data block.
[0018] In other words, due to RAM limitations, the number of data blocks loaded into RAM cannot exceed a set threshold. If the threshold is reached, a data block in RAM must be replaced. Given the I / O overhead of reading data blocks into RAM, the probability of a data block in RAM being matched again decreases with the longest unused block in RAM. Therefore, a strategy for replacing data blocks in RAM could be to replace the longest unused block in RAM each time.
[0019] In a second aspect, the present application provides a program update method, which is applied to a server, and the method includes: obtaining a first program file and a second program file of a target program, the target program is a program that needs to be upgraded on an electronic device, the first program file and the second program file are program files of different versions of the target program, and the version of the first program file is higher than the version of the second program file; determining a matching sequence and a non-matching data stream based on the matching cost, non-matching cost and loading cost of the data in the first program file and the second program file; the loading cost is the cost of reading the data in the second program file when generating the first program file on the electronic device or the data in the intermediate file obtained in the process of generating the first program file on the electronic device, the matching sequence includes a matching field and a non-matching field, the matching field is used to indicate that a string in the first program file matches a string other than the first string in the first program file or a string in the second program file, and the non-matching field is used to indicate that a string in the first program file is the same as a string in the non-matching data stream; generating an upgrade package for the target program based on the matching sequence and the non-matching data stream, the upgrade package is used to indicate the difference between the first program file and the second program file.
[0020] In this solution, the server generates an upgrade package for the target program based on the first program file and the second program file of the target program. In the process of generating the upgrade package, the first program file can be represented in the form of a matching sequence and a non-matching data stream. In the process of generating the matching sequence and the non-matching data stream representing the first program file, when calculating the matching cost of the string in the first program file, the loading cost of the data read in the second program file when generating the first program file on the electronic device or the intermediate file obtained in the process of generating the first program file can be included in the matching cost. This makes it possible to obtain the most optimized matching result, ensures the optimization of the number of data block loading times, and can finely balance the differential rate and the number of I / O times.
[0021] In one possible implementation, the matching cost of data in the first program file and the second program file includes: mutual matching cost and self-matching cost. The mutual matching cost is the cost of a string in the first program file finding another matching string in the second program file, and the self-matching cost is the cost of a string in the first program file finding another matching string other than the first string in the first program file.
[0022] That is, when matching the data in the first program file, it includes matching the string in the first program file with the string in the second program file (i.e., mutual matching), and matching the string in the first program file with other strings in the first program file (self-matching). Therefore, when calculating the matching cost of the string in the first program file, the mutual matching cost and the self-matching cost are calculated.
[0023] In one possible implementation, a matching sequence and a non-matching data flow are determined based on the matching cost, non-matching cost, and loading cost of data in a first program file and a second program file of a target program, including: obtaining at least one matching overhead based on the matching cost, non-matching cost, and loading cost of data in the first program file and the second program file under different matching modes; selecting a minimum matching overhead from the at least one matching overhead, and determining the matching sequence and non-matching data flow of the first program file based on the matching cost, non-matching cost, and loading cost corresponding to the minimum matching overhead.
[0024] That is to say, the matching overhead under different matching methods can be calculated separately, and the matching cost, non-matching cost and loading cost corresponding to the minimum matching overhead can be selected to determine the matching sequence and non-matching data flow of the first program file, which can ensure that the generated matching sequence of the first file is the optimal matching sequence.
[0025] In a third aspect, the present application provides an electronic device, comprising:
[0026] at least one memory for storing a program;
[0027] At least one processor is used to execute the program stored in the memory. When the program stored in the memory is executed, the processor is used to execute the method described in the first aspect or any possible implementation of the first aspect.
[0028] In a fourth aspect, the present application provides a server, comprising:
[0029] at least one memory for storing a program;
[0030] At least one processor is used to execute the program stored in the memory. When the program stored in the memory is executed, the processor is used to execute the method described in the second aspect or any possible implementation of the second aspect.
[0031] In a fifth aspect, the present application provides a computer storage medium having instructions stored therein. When the instructions are executed on a computer, the computer executes the method described in any possible implementation of the first aspect or the second aspect.
[0032] In a sixth aspect, an embodiment of the present application provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the method described in any possible implementation of the first aspect or the second aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] The following is a brief introduction to the drawings required for describing the embodiments or prior art.
[0034] FIG1 is a schematic diagram of a system update process on a device provided in an embodiment of the present application;
[0035] FIG2 is a schematic diagram of a general differential upgrade process provided by an embodiment of the present application;
[0036] FIG3 is a schematic diagram of an upgrade scenario of a terminal device provided in an embodiment of the present application;
[0037] FIG4 is a schematic diagram of the hardware structure of a server provided in an embodiment of the present application;
[0038] FIG5 is a schematic structural diagram of a terminal device provided in an embodiment of the present application;
[0039] FIG6 is a schematic diagram of a new file presentation process provided by an embodiment of the present application;
[0040] FIG7 is a schematic diagram of a matching method provided in an embodiment of the present application;
[0041] FIG8 is a schematic diagram of another matching method provided in an embodiment of the present application;
[0042] FIG9 is a schematic diagram of a new file generation principle provided by an embodiment of the present application;
[0043] FIG10 is a schematic diagram of a process for generating a new file in RAM according to an embodiment of the present application;
[0044] FIG11 is a flow chart of a program updating method provided in an embodiment of the present application;
[0045] FIG12 is a flow chart of another program updating method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described below with reference to the accompanying drawings.
[0047] In the description of the embodiments of this application, any embodiment or design scheme using "exemplary," "for example," or "for example" should not be understood as being more preferred or advantageous than other embodiments or designs. Rather, the use of words such as "exemplary," "for example," or "for example" is intended to present the relevant concepts in a concrete manner.
[0048] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly identifying the technical features being referred to. Thus, features specified as "first" or "second" may explicitly or implicitly include one or more of such features. The terms "include," "comprising," "having," and their variations all mean "including but not limited to," unless otherwise specifically emphasized.
[0049] Before introducing this solution, we first introduce the technical terms involved in this solution.
[0050] Rich devices: Devices with abundant random-access memory (RAM) and central processing unit (CPU) resources, such as smartphones and smartwatches.
[0051] Thin devices: terminal devices with limited resources, such as wristbands and sports watches.
[0052] Match: A continuous data segment is found to have the same or similar segments in the same or other sources, where the same is called a perfect match. In the present application, "match" refers to a perfect match.
[0053] LZ77 algorithm: LZ77 is a general-purpose byte-based compression algorithm that replaces repeated bytes in the source file (i.e., bytes that appear in the previous text) with a triplet of (distance, length, nextchar). Distance represents the distance between the current character to be matched and the first letter of the matching string; length represents the length of the matching string, i.e., the number of characters that match the previous text; and nextchar represents the next character in the current matching string. Generally, general-purpose compressors follow a match with a literal string of characters, rather than just a single character.
[0054] Next, this solution is introduced.
[0055] Upgrading a device's system or program requires downloading an upgrade package from a server and executing the upgrade program on the device based on the downloaded upgrade package. The size of the upgrade package directly impacts the traffic cost, user experience, and development cycle of the system or program on the device during the upgrade process. For example, Figure 1 illustrates the process of updating a system on a device. As shown in Figure 1, after the development department specifies, develops, and generates a new image for the device, they enter the packaging process. This packaging process occurs on the server, where a packaging tool creates a corresponding differential package for each pair of old and new image files, based on the old image file on the device stored on the server and the new image file to be upgraded. The generated differential packages are then packaged together and sent to the device. A differential package refers to the portion of the image file that differs from the old image file. After receiving the differential package from the server, the device generates a new image file based on the old image file and the differential package, and then updates the system on the device based on the generated new image file.
[0056] Existing device upgrades are mainly performed through differential packages. During the differential upgrade process, the differential upgrade tools of the operating system and software will split a large software system into multiple binary files that need to be updated through steps such as parsing and pairing, and then call a general differential algorithm. For example, Figure 2 shows a flow chart of a general differential upgrade. As shown in Figure 2, given new and old binary files with similar content, the goal of the general differential algorithm is to calculate the "increment" of the new version of the file relative to the old version of the file, that is, to perform "old file + new file → differential package". The goal of the restoration algorithm is to generate a new file through the old file on the device and the received differential package, that is, "old file + differential package → new file". For example, Table 1 shows some commonly used differential algorithms.
[0057] Table 1
[0058] During the upgrade process using differential packets, the metrics for the general differential algorithm used include: (1) differential packet size; (2) the rate at which new files are generated on the device based on the differential packets; (3) the resource overhead of generating new files; and (4) the rate at which differential packets are generated on the server. Based on the metrics for general differential algorithms, the bsdiff algorithm and the Rock algorithm are usually used when upgrading software on rich devices such as PCs and smart devices.
[0059] Bsdiff is a general-purpose binary file difference algorithm with byte granularity. It represents the new file as a sequence of ADD and INSERT operations. ADD(p,k) means copying k bytes from position p of the old file to the current position of the new file, and INSERT(j) means copying j bytes from the extra extra stream to the current position. At the same time, bsdiff allows for imperfect matching, that is, recording the required modifications to the fields of the ADD operation separately. For example, DIFF(5,'a') means changing the 5th byte of the new file to 'a'. The differential packet obtained by bsdiff usually contains the following parts: (1) a sequence consisting of ADD and INSERT; (2) a sequence consisting of DIFF; and (3) an extra data stream. These three parts are compressed and packaged by a compressor with an excellent compression ratio.
[0060] As you can understand, bsdiff finds matches by constructing a suffix array and scanning the new file from front to back, searching for the longest match for each byte. A match is output when the difference in bytes starting at a certain position exceeds a certain percentage. However, the match may not be perfect; the differences are provided by an additional diff data stream. Therefore, the position at which bsdiff finds a match may be arbitrary.
[0061] While bsdiff can be used to upgrade device software, it relies on a black-box compression algorithm to reduce the size of differential packets, which increases bsdiff's complexity and results in poor scalability. Furthermore, when generating new files from differential packets and old files, bsdiff uses a greedy, ad-hoc matching method. While this method works for most data, it is difficult to adapt or improve upon with other systems.
[0062] Rock can perform differential calculations on the server side between new and old files to generate differential packages. Furthermore, Rock can perform differential updates based on differential packages even on devices with only a few dozen KB of RAM. While Rock can perform differential updates on smaller RAM footprints, differential upgrades using Rock still suffer from loss of differential rate and high restore time.
[0063] The core algorithms of software on rich devices such as computers and smart devices are relatively fixed, but the differential methods used in the upgrade process of resource-constrained scenarios on thin devices still need to be improved. Existing thin devices face strict resource limitations during software upgrades, such as: (1) There is only a small amount of RAM available on thin devices, about 100KB; (2) The computing power of thin devices is much lower than that of smart devices, and some thin devices do not have a CPU but only an MCU (main frequency ~100MHz); (3) The read-only memory (ROM) on thin devices is large enough, but the read and write performance is poor, with a random read time of about 2ms. Due to these limitations, commonly used general differential upgrade methods such as bsdiff cannot run on thin devices. Currently, the update methods used are either inefficient algorithms such as Rock or full updates, which cause users to spend tens of minutes transmitting the upgrade package and executing the update operation when performing system or program upgrades. As thin devices have higher requirements for user experience, the number of APP applications has increased, and the functions have become more complex, the upgrade package is getting larger and larger, and the time-consuming device upgrade has become a major pain point in the use of terminal products. Take watch products as an example. Table 2 shows the time required to upgrade a watch product in different ways.
[0064] Table 2
[0065] As shown in Table 2, during the G3 watch upgrade process, data transmission took between 4 and 90 minutes, installation took approximately 6 minutes, and the total upgrade process took between 10 and 96 minutes. Conventional differential upgrade algorithms are incapable of working on RAM-constrained wearable devices, leading to extended upgrade times and a poor user experience.
[0066] In view of this, an embodiment of the present application provides a program update method, which represents a new file as a sequence of "old match + self-match + non-match", and records this sequence in an extended LZ77 manner. Then, when a new file is generated on the terminal device, the old file saved in the terminal device and the new file that has been generated are divided into different blocks. When it is necessary to read data at a certain position in a new file or an old file, the block corresponding to the data segment is read into the RAM. When the new file generated in the RAM meets the size of a block, the generated block belonging to the new file can be written into the ROM. In the process of generating a new file on the terminal device, the files required to generate the new file are stored in the RAM in units of blocks, which reduces the demand for RAM on the terminal device when the file is updated.
[0067] For example, Figure 3 shows a schematic diagram of a terminal device upgrade scenario provided by an embodiment of the present application. As shown in Figure 3, it includes: a server 100 deployed in a content delivery network (CDN), a first terminal device 200, and a second terminal device 300. The first terminal device 200 can be a rich device, such as a smartphone; the second terminal device 300 can be a thin device, such as a sports watch. The sports watch communicates with the smartphone via WiFi or Bluetooth, and the smartphone can communicate with the server in the CDN via WiFi or a mobile network. When the system or software in the sports watch needs to be upgraded, the smartphone can download the installation package corresponding to the system or software to be upgraded from the server in the CDN via the smartphone. The smartphone can then upgrade the sports watch using the corresponding app on the smartphone (such as a sports health app). It will be understood that the device upgrade scenario shown in Figure 3 is only an example of an application scenario in the embodiment of the present application. In actual applications, more or fewer devices may be included than shown in Figure 3. For example, when the sports watch in Figure 3 needs to be upgraded, the differential package required for the upgrade can be downloaded directly from the server in the CDN network.
[0068] Next, the hardware structures of the server and terminal devices in the device upgrade scenario shown in FIG3 are introduced.
[0069] For example, Figure 4 shows a schematic diagram of the hardware structure of a server. As shown in Figure 4, the server 100 may include: a processor 110, a network interface 120, and a memory 130. The processor 110, the network interface 120, and the memory 130 may be connected via a bus or other means.
[0070] In the embodiment of the present application, the processor 110 (also called a central processing unit (CPU)) is the computing core and control core of the server 100 .
[0071] The network interface 120 may include a standard wired interface, a wireless interface (such as WI-FI, a mobile communication interface, etc.), and is controlled by the processor 110 to send and receive data, for example, receiving data request information sent by the first terminal device 200 or the second terminal device 300, and sending data packets to the first terminal device 200 or the second terminal device 300.
[0072] The memory 130 (memory) is a storage device of the server 100 and is used to store programs and data, for example, old files and new files corresponding to the system or software in the first terminal device 200 or the second terminal device 300.
[0073] It should be understood that the structure illustrated in FIG. 3 of the embodiment of the present application does not constitute a specific limitation on server 100. In other embodiments of the present application, server 100 may be a cloud server. Server 100 may include more or fewer components than shown, or may combine or separate certain components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of hardware and software.
[0074] For example, FIG5 shows a schematic diagram of the structure of a terminal device. It is understandable that the terminal device can be the first terminal device 200 in FIG3 or the second terminal device 300, and the terminal device can be, but is not limited to, a mobile phone, a tablet computer, a laptop computer, a wearable device, a smart TV or other electronic device. Exemplary embodiments of terminal devices include but are not limited to electronic devices equipped with iOS, Android, Windows, Harmony OS or other operating systems. The embodiment of the present application does not specifically limit the type of terminal device.
[0075] As shown in Figure 5, the terminal device includes: a processor 510, a memory 520, a display screen 530, a communication module 540 and an input device 550. The processor 510, the memory 520, the display screen 530, the communication module 540 and the input device 550 can be connected via a bus or other means.
[0076] The processor 510 is the computing core and control core of the terminal device, and the processor 510 may include one or more processing units, wherein different processing units may be independent devices or integrated into one or more processors.
[0077] The memory 520 may store programs that can be executed by the processor 510, so that the processor 510 executes part or all of the methods required to be executed by the terminal device provided in the embodiments of the present application. The memory 520 may also store files corresponding to the system or application on the terminal device. The processor 510 can read data stored in the memory 520. The memory 520 and the processor 510 may be provided separately. Alternatively, the memory 520 may also be integrated into the processor 510.
[0078] The display screen 530 is used to display images, videos, etc.
[0079] The communication module 540 may include a mobile communication module. When the communication module 540 is a mobile communication module, it may provide solutions for wireless communications, including 2G / 3G / 4G / 5G, applied to the terminal device. For example, the communication module 540 may be used to enable the terminal device to communicate with a server or other terminal device to obtain an update package for the system or software to be updated on the terminal device.
[0080] In some embodiments, the terminal device may further include an input device 550. Information may be input to the terminal device and / or control instructions may be issued via the input device 550. For example, the input device 550 may be, but is not limited to, a mouse, a keyboard, or the like.
[0081] It is understood that the structure illustrated in FIG. 5 of the embodiment of the present application does not constitute a specific limitation on the terminal device. In other embodiments of the present application, the terminal device may include more or fewer components than shown, or may combine or separate certain components, or may have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0082] Next, using the server and terminal device shown in Figures 4 and 5 as examples, a file update process provided by an embodiment of the present application is described. This process includes generating a differential package of the file to be updated on the server, and generating a new file of the file to be updated based on the differential package of the file to be updated on the terminal device. The file update process involved in the embodiment of the present application primarily involves processing on the server and the terminal device.
[0083] (1) Generate a differential package of the file to be updated
[0084] In the embodiment of the present application, the files to be updated mainly refer to files corresponding to the system or software to be updated in the terminal device. Before updating the system or software in the terminal device, a differential package of the system or software to be updated needs to be generated on the server side.
[0085] The server pre-stores the "old files" corresponding to the system or software to be updated on the terminal device and the "new files" used to update the system or software on the terminal device. It is understandable that in the embodiment of the present application, the "old files" refer to the files corresponding to the system or software currently running on the terminal device, and the "new files" refer to the files used to update the system or software running on the terminal device. For example, the system version running on the terminal device is 2.0, and the system running on the terminal device needs to be upgraded to version 3.0. Among them, the files corresponding to system version 2.0 are old files, and the files corresponding to system version 3.0 are new files.
[0086] When the server generates a differential package for the system or software to be updated, it first needs to obtain the old file and the new file of the system or software to be updated. Then, the server matches the obtained old file and the new file to generate a differential package for the system or software to be updated on the terminal device. Specifically, the server matches the new file with the old file, and the new file with the new file, so as to represent the new file as "mutual matching + self-matching + non-matching". Among them, mutual matching refers to forming a dictionary of all the character strings in the old file, matching the characters in the new file with the characters in the old file, and recording the position of the matched characters in the old file; self-matching refers to matching the bytes that need to be matched at the current position in the new file with the bytes that have been matched in the previous text. If the match is successful, the position of the currently matched characters in the previous text is recorded; non-matching refers to the character strings in the new file that neither match the character strings in the old file nor match other character strings in the new file.
[0087] In one possible example, let S[i,j] represent the string S from bytes i to j, which includes byte i but not byte j. Assume that the old file is represented by bytes as S, with a length of L_load bytes, and the new file is denoted as T, with a length of L_new bytes. A "mutual match + self-match + non-match" can be represented by a triple M, M = (type, distance, length). Here, type∈{old_match, self_match, non_match} is an enumeration type, and distance and length are integers. Let the current position of the new file be t. For the old match, M_old = (type = old_match, distance, length) means that S[t-distance, t-distance+length] is exactly the same as T[t, t+length]. For the self-match, M_self = (type = self_match, distance, length) means that T[t-distance, t-distance+length] is exactly the same as T[t, t+length]. For non-match, M_non=(type=non_match,distance=none,length) means that T[t,t+length] needs to be read from the additional data stream Literal. In this case, distance is meaningless. Under the above representation method, the new file T can be completely restored by S plus the operation sequence M={M1,M2,…,Mn} and Literal. The differential packet is composed of the operation sequence and non-matching stream literals.
[0088] In one possible example, Figure 6 illustrates a new file representation process, namely, a process for representing a new file using a "mutual match + self-match + non-match" approach. As shown in Figure 6, the new file includes the characters "abedcfadepdcfa," and the characters in the old file are "abedcfaa." When matching the new and old files, the matching begins with the first character (i.e., t=1). The matching indicates that the characters from t=1 to t=7 in the new file match the characters from t=1 to t=7 in the old file. Therefore, the characters from t=1 to t=7 in the new file can be represented as M1={old_match,0,7}. The server then continues matching from the eighth character in the new file. The matching indicates that neither the characters from t=1 to t=7 in the old file nor the characters from t=1 to t=7 in the new file match the characters from t=8 to t=10. At this point, the characters from t=8 to t=10 (dep) can be used as the new data stream Literal, and the characters from t=8 to t=10 are represented as M2={non_match,none,3}. The server continues to match the 11th character in the new file. The matching results show that the characters from t=11 to t=14 match the characters from t=4 to t=7 in the old file. The characters from t=11 to t=14 in the new file are represented as M3={old_match,7,4}.
[0089] It's understandable that when matching a new file with an old file, the size and number of the resulting operation sequence are closely related to the size of the generated differential packet. Furthermore, when matching a new file with an old file, the string to be matched in the new file is not unique. For example, in Figure 6, characters from t=11 to t=14 in the new file match both characters from t=4 to t=7 in the old file and characters from t=4 to t=7 in the new file. However, when generating the operation sequence in the differential packet, the optimal match can be calculated to select a matching string from multiple strings matching the current position.
[0090] When calculating the optimal match, for a segment of input data input[0..n], including the 0th byte but not including the nth byte, S[n] is used to represent the shortest length S[n] obtained by encoding input[0..n] in LZ77 mode. Without introducing old files for matching, the calculation method of S[n] can be recursively expressed as follows:
[0091] Where m is an enumeration variable ranging from 0 to n-1, indicating the starting position of the last match, literal_price(input[m,n]) is the cost of input[m..n] when there is no match, and match_price(distance,nm) is the cost of input[m..n] when a match is found by forward distance. Both costs are estimated using the given method. S[m] represents the cost of representing characters from 0 to the m-1th character.
[0092] When old files are introduced for matching, the calculation method of S[n] can be recursively expressed as follows:
[0093] Among them, m is an enumeration variable ranging from 0 to n-1, indicating the starting position of the last match, literal_price(input[m,n]) is the cost of input[m..n] in the case of no match, self_match_price(distance,nm) is the cost of input[m..n] when a match is found in the forward distance, old_match_price(pos,nm) is the cost of input[m..n] when a match is found at the POS position of the old file, and S[m] represents the representation cost from 0 to the m-1th character.
[0094] Because, in the embodiment of the present application, the terminal device needs to divide the old file and the generated new file into blocks of fixed length. When the terminal device generates the new file of the system / software to be updated based on the differential package of the system / software to be updated received from the server and the old file on the terminal device, it needs to read the data at a certain position of the file, and then load the block corresponding to the data segment into RAM to reduce the demand for blocks on the terminal device. However, when reading the block, the distance between the position of the block read each time and the block read previously is different, and the cost is also different. Therefore, in order to further reduce the IO overhead when generating a new file on the terminal device, additional loading overhead can be introduced when calculating the optimal match.
[0095] In the case of introducing the loading overhead on the terminal device, the calculation method of S[n] can be recursively expressed as,
[0096] Among them, m is an enumeration variable ranging from 0 to n-1, indicating the starting position of the last match, literal_price(input[m,n]) is the cost of input[m..n] in the case of no match, self_match_price(distance,nm) is the cost of input[m..n] when a match is found in the forward distance, old_match_price(pos,nm) is the cost of input[m..n] when a match is found at the POS position of the old file, and S[m] represents the representation cost from 0 to the m-1th character.
[0097] If a block already in RAM is called a cache block, the reload_cost term is determined by whether the block is a cache block and how recently it was read. Its value is equivalent to the number of bytes after compression. For example, you could set the cost of reading data from an unloaded block to 20 bytes, and the cost of reading data from an already loaded block to 0.1r bytes, where r represents the number of times the block was recently read. Only matches with a benefit greater than 20 bytes are considered acceptable.
[0098] In the process of calculating the optimal match, by introducing the loading overhead on the terminal device, a large number of fragmented and scattered matches are intuitively removed, and large-block matches or matches within the cache block are used.
[0099] Exemplarily, FIG7 shows a matching method. For the case where the candidate match is not in the cache block, the candidate match will be adopted only after the match length reaches the reload cost. As shown in FIG7 , for case 1, there is only one candidate match in the block of the new file and the old file, and the length is less than the threshold R, so the candidate match is not adopted. For case 2, there are three candidate matches in the block of the new file and the old file, but the lengths of the three candidate matches are all less than the threshold R, so the candidate match in the block is not adopted. For case 3, there is only one candidate match in the block of the new file and the old file, and the length is greater than the threshold R, so the candidate match is adopted.
[0100] After a match is taken, the corresponding block becomes a cache block when performing a restore match, so the matches in this block are no longer subject to the reload cost threshold. As shown in Figure 8, candidate match 1 in block 1 in the old file matches candidate match 1 in block 2 in the new file, and the length of candidate match 1 is greater than R. Therefore, block 1 is read into RAM and becomes a cache block. If candidate matches 2 and 3 in block 1 match candidate matches 2 and 3 in block 2, respectively, there is no need to consider whether the lengths of candidate matches 2 and 3 are greater than R; candidate matches 2 and 3 will definitely be taken.
[0101] Get the operation sequence on the server After the non-matching stream literal, the resulting operation sequence needs to be The non-matching stream literal is entropy-encoded and then cut into pieces and packaged to obtain a differential package of the system / software to be updated on the terminal device.
[0102] (2) Generate a new file based on the differential package of the file to be updated
[0103] After receiving the differential package of the system / software to be updated sent by the server, the terminal device needs to generate a new file of the system / software to be updated based on the received differential package and the old file of the system / software to be updated stored on the terminal device.
[0104] For example, FIG9 shows a schematic diagram of the principle of generating a new file. As shown in FIG9, after the terminal device decodes the differential packet, it reads out the operation sequence in the differential packet in sequence. and non-matching stream literal. Then, the terminal device operates according to the sequence Match the corresponding data from the old file or the new file, and use the matched data to generate a new file, or the terminal device can generate the new file according to the operation sequence. Get the corresponding data from the non-matching stream literal to generate a new file.
[0105] Under normal circumstances, when a terminal device generates a differential package of the system / software to be updated based on the differential package and the old file, the most direct operation method is to load the old file and the differential package into RAM, wait for the new file to be generated in RAM, and then write the new file back to ROM. 5 ~10 6If all matching copies were operated directly on RAM, a large RAM capacity would be required, and with so many matching operations, the data reading time overhead would be high. Therefore, in the embodiment of the present application, the old file and the generated new file are divided into blocks of fixed length. During the matching process, the terminal device splits the old and new files into blocks and only loads the blocks of data to be read or written into RAM. Only a limited number of blocks are retained in RAM, thereby keeping RAM usage at a low level.
[0106] Specifically, the terminal device divides the old files of the system / software to be updated into multiple blocks according to the pre-set length. Usually, the length of the block can be set to 1KB to 16KB. Then, the terminal device decodes the received differential packets and reads out the operation sequence in the differential packets in sequence. The terminal device operates on the differential packet after receiving the differential packet. After the non-matching stream literal, the terminal device operates according to the sequence The information carried is obtained from an old file, a non-matching stream literal, or a newly generated file to generate a new file. The new file is generated in the terminal device's RAM. When reading data into RAM, the block corresponding to the data segment to be read is read into RAM. If the new file generated in RAM is a single block in size, it must be written to ROM. Only one block needs to be retained in RAM on the end where the new file is generated.
[0107] Due to limited RAM, the number of blocks loaded into RAM is limited (usually a few to dozens of cache blocks). When the number of blocks in RAM reaches the upper limit, the blocks in RAM need to be replaced in a certain way. For example, the replacement strategy can be the N most frequently used blocks in RAM. The data and position of the blocks in RAM that are not replaced do not change. It can be understood that the block that has been read into RAM is called a cache block. All blocks of the old file and the blocks that have been generated in the new file may be loaded as cache blocks. When performing matching calculations, it is necessary to ensure that more than one block is not spanned.
[0108] For example, Figure 10 illustrates a process for generating a new file in RAM, showing the storage locations of the old and new files, cache blocks, and data transfer methods in a terminal device. As shown in Figure 10, the old file blocks and the newly generated file blocks are stored in ROM. When generating a new file, the terminal device reads the block containing the required data from ROM into RAM. Once the new file in RAM meets the size of a block, it is written back to ROM.
[0109] It's understandable that the matching information and non-matching data streams in the differential packet have a maximum length when packaged and are read sequentially. Therefore, after receiving the differential packet, the terminal device only needs to decode the current packet into RAM, without having to further block the data in the differential packet.
[0110] In one possible example, assume that the old file "abedcfaapcpdfd" stored in the terminal device package for the system / software to be updated is stored in the differential packet. The operation sequence carried in the differential packet includes: M1 = {old_match, 0, 7}, M2 = {non_match, none, 3}, M3 = {old_match, 7, 4}, and the non-match stream literal is "dep". The terminal device first divides the old file into two blocks, each 7 bytes in size. Block 1 contains the data "abedcfa" and block 2 contains the data "apcpdfd". The terminal device then decodes the differential packet into RAM and begins matching the new file from the first byte, i.e., t = 1. Specifically, the first operation sequence M1 in the differential packet is parsed. Since M1 contains type "old_match", distance 0, and length 7, it indicates a match between bytes 1 to 7 in the old file and bytes 1 to 7 in the new file. Since bytes 1 through 7 belong to block 1, the data in block 1 is read into RAM and matched against bytes 1 through 7 in block 1 to generate bytes 1 through 7 of the new file. After obtaining bytes 1 through 7 of the new file, since their size fits within a block, the generated new file needs to be written to ROM. t is updated to 8, and the terminal device continues to parse the second operation sequence, M2. Since type in M2 is non_match, distance is none, and length is 3, bytes 8 through 10 of the new file need to be read from the newly added data stream, Literal. Therefore, the first three bytes from Literal are read sequentially as bytes 8 through 10 of the new file. At this point, t is updated to 11, and the terminal device continues to parse the third operation sequence, M3. Since type in M3 is self_match, distance is 7, and length is 4, bytes 4 through 7 of the new file are identical to bytes 11 through 14 of the new file. Since bytes 4 to 7 belong to the first block of the new file, and the first block has been loaded into ROM, it is necessary to read the first block of the new file from ROM into RAM and match bytes 4 to 7 in the first block to generate bytes 11 to 14 of the new file.
[0111] In an embodiment of the present application, when performing a differential upgrade of the system / software on a device, the upgrade process is in RAM. To avoid reading all data into RAM, the data blocks are divided into blocks, and the blocks to which the required data belongs are read into RAM. Furthermore, when reading blocks of new / old files, the most recently read blocks are prioritized, thus saving I / O overhead. It will be appreciated that the above method is applicable not only to the differential upgrade scenario of the system / software on a device, but also to other application scenarios involving storage devices and databases.
[0112] In an embodiment of the present application, a differential upgrade package for the system / software to be updated on a terminal device is generated on the server side based on a "mutual match + self match + non-match" process. During the matching calculation process for generating the differential upgrade package, the cost of loading blocks is factored into the matching cost. This optimizes the matching result while ensuring the optimization of the number of data block loads, while also achieving a precise balance between the differential rate and the number of I / O operations. During the terminal device's system / software upgrade, the old and new files are split into blocks, and only the blocks of data to be read or written are loaded into RAM. Only a limited number of blocks are retained in RAM, thereby keeping RAM usage low.
[0113] Next, based on the file update process in the above embodiment, a program update method provided in an embodiment of the present application is introduced.
[0114] For example, Figure 11 shows a flowchart of a program updating method provided by an embodiment of the present application, which is mainly executed by the server in Figure 3. As shown in Figure 11, the method includes: steps 1101 to 1103.
[0115] Step 1101: Obtain a first program file and a second program file of a target program.
[0116] In this embodiment, the target program is a software program that needs to be upgraded on the electronic device, and the first program file and the second program file are program files of different versions of the target program, and the version of the first program file is higher than the version of the second program file. For example, the first program file may be the file corresponding to the target program after the upgrade, and the second program file may be the file corresponding to the target software before the upgrade. The second program file may be referred to as the old file, and the first program file may be referred to as the new file. The first program file and the second program file of the target program may be pre-stored on the server, or may be input into the server in real time by the user as needed.
[0117] Step 1102 : Determine a matching sequence and a non-matching data flow based on the matching cost, non-matching cost, and loading cost of the data in the first program file and the second program file of the target program.
[0118] In this embodiment, the load cost is the cost of reading data from the second program file when generating the first program file on the electronic device, or the cost of reading data from an intermediate file obtained during the process of generating the first program file on the electronic device. The intermediate files obtained during the process of generating the first program file include files stored in ROM and files belonging to the first program file stored in RAM. The match sequence includes a match field and a non-match field. The match field is used to indicate that a string in the first program file matches a string other than the first string in the first program file or a string in the second program file. The non-match field is used to indicate that a string in the first program file is identical to a string in the non-matching data stream.
[0119] After obtaining the first and second program files of the target program, the server represents the first program file as a "mutual match + self match + non-match" sequence by matching the first program file with the second program file and matching the data in the first program file with each other, and then records the sequence in an extended LZ77 format. Recording the representation sequence of the new file in the extended LZ77 format means representing the string in the first program file as a triple operation sequence M, where M = (type, distance, length), where type∈{old_match, self_match, non_match} is an enumeration type, and distance and length are integers.
[0120] When matching the data in the first program file, for the same string to be matched, there may be multiple matching results or no matching result. For example, when matching the data in the first program file, assume that the position currently processed by the first program file is t, and t is a natural number greater than or equal to 1. The data of length t+length in the first program file can be matched with the data in the second program file, or with the data before position t in the first program file. If there is no string matching the string of length t+length in the data before position t in the second program file and the first program file, the data of length t+length in the first program file can be saved in the newly added data stream.
[0121] In the case where there are multiple matches for data of length t+length, the matching cost of the matching data in the first program file can be determined by calculating the matching cost of each string and the data loading cost when the first program file is generated on the electronic device. The matching cost of the matching data in the first program file corresponding to different matching results is different. Among them, the second program file stored on the electronic device and the newly generated first program file are divided into blocks on the electronic device. The data loading cost when the first program file is generated on the electronic device refers to the cost of reading a block each time. The cost of reading a block is determined by whether the block is a cache block and the number of cache blocks read most recently. Its value is equivalent to the number of bytes after compression. The matching cost of a string includes: mutual matching cost and self-matching cost. The mutual matching cost is the cost of a string in the first program file finding another matching string in the second program file. The self-matching cost is the cost of a string in the first program file finding another matching string other than the first string in the first program file.
[0122] In the embodiment of the present application, when matching the strings in the first program file, in order to ensure that the matching cost of each string is minimized, it is necessary to calculate the optimal match. When calculating the optimal match, the entire first program file is calculated as a whole. The length S[n] of the first program file represented by the extended LZ77 method can be used to identify the matching cost of the first program file. The calculation method of S[n] can be recursively expressed as follows:
[0123] Among them, m is an enumeration variable ranging from 0 to n-1, indicating the starting position of the last match, literal_price(input[m,n]) is the cost of input[m..n] in the case of no match, self_match_price(distance,nm) is the cost of input[m..n] when a match is found in the forward distance, old_match_price(pos,nm) is the cost of input[m..n] when a match is found at the POS position of the second program file, and S[m] represents the representation cost from 0 to the m-1th character.
[0124] If the block already in the RAM of an electronic device is called a cache block, the reload_cost item is determined by whether the block is a cache block and how many times it is the cache block that has been read most recently. Its value is equivalent to the number of bytes after compression.
[0125] When determining the best match in the first program file, the matching string corresponding to the minimum matching cost among the multiple matching costs of the string can be used as the best match. After obtaining the best matching string for the string in the first program file, the matching sequence corresponding to the string in the first program file can be determined based on the program file to which the best matching string belongs and the position relationship in the program file (the matching sequence can also be determined using the operation sequence). ). And a non-matching data stream corresponding to the first program file can also be generated according to the unmatched character string in the first program file.
[0126] Step 1103 : Generate an upgrade package of the target program according to the matching sequence and the non-matching data stream, where the upgrade package is used to indicate the differences between the first program file and the second program file.
[0127] In this embodiment, after obtaining the matching sequence and non-matching data stream corresponding to the first program file, the server may encode and segment the obtained matching sequence and non-matching data stream to obtain an upgrade package of the target program.
[0128] In this embodiment of the present application, when matching the second program file with the first program file to generate the upgrade package, the block loading cost when generating the second program file on the electronic device is factored into the matching cost. This ensures that the optimal matching result is achieved while optimizing the number of data block loads and precisely balancing the difference rate and I / O times.
[0129] For example, FIG12 shows a flowchart of a program update method provided in an embodiment of the present application, which is mainly performed by an electronic device, which can be the terminal device 1 or the terminal device 2 in FIG3 . As shown in FIG12 , the method includes: steps 1201 to 1204 .
[0130] Step 1201: Obtain an upgrade package of a target program, wherein the upgrade package carries a matching sequence and a non-matching data stream.
[0131] In this embodiment, the upgrade package is used to indicate the difference between the first program file and the second program file. The matching sequence includes a matching field and a non-matching field. The matching field is used to indicate that a string in the first program file matches a string other than the first string in the first program file or a string in the second program file, and the non-matching field is used to indicate that a string in the first program file is the same as a string in the non-matching data stream. The first program file and the second program file are program files of different versions of the target program, and the version of the first program file is higher than the version of the second program file. For example, the first program file can be the file corresponding to the target program after the upgrade, and the second program file is the file corresponding to the target software before the upgrade. The first program file can also be called an old file, and the second program file can be called a new file. After the electronic device receives the upgrade package of the target program sent by the server, the electronic device can directly decode the upgrade package into the RAM of the electronic device.
[0132] Step 1202: Parse the upgrade package in a random access memory (RAM) to obtain matching fields, non-matching fields, and non-matching data streams.
[0133] In this embodiment, since the matching sequences and non-matching data streams in the upgrade package are packaged with a length limit, and the matching sequences and non-matching data streams in the upgrade package are read sequentially, the electronic device can directly decode the upgrade package into RAM after receiving it without incurring excessive overhead.
[0134] Step 1203, according to the order of matching fields and non-matching fields in the matching sequence, when the field currently required to be operated is a matching field, determine the source data block to which the string associated with the matching field belongs; when the field currently required to be operated is a non-matching field, read the target string associated with the non-matching field from the non-matching data stream.
[0135] In this embodiment, before restoring and generating the first program file corresponding to the target program on the electronic device, the electronic device also needs to divide the second program file stored on the electronic device into multiple blocks according to a fixed length, where the length of a block can be 1KB to 16KB. In addition, during the process of generating the first program file corresponding to the target program, the intermediate file obtained during the generation of the first program file is divided into multiple blocks. Due to the limited RAM on the electronic device, when generating the first program file, if the electronic device needs to read data at a certain location in the first program file or data in the intermediate file obtained during the generation of the first program file, it only needs to read the block corresponding to the data segment into the RAM.
[0136] When generating the first program file of the target program, the electronic device can obtain the target data for generating the first program file based on the matching field in the matching sequence carried in the upgrade package corresponding to the target program. Among them, the target data for generating the first program file can be the data in the first program file, the data in the second program file, and the data in the newly added data stream. Specifically, the matching sequence includes matching fields and non-matching fields. Both the matching field and the non-matching field include matching type, data position and data length. Among them, the matching types include mutual matching (old_match), self-matching (self_match) and non-matching (non_match), the matching type corresponding to the matching field is mutual matching or self-matching, and the corresponding matching type in the non-matching field is non-matching. The data position is used to identify the starting position of the character string associated with the matching field in the first program file or the second program file. The data length is used to identify the length of the character string associated with the matching field.
[0137] The electronic device determines the matching type of the matching field according to the order of the matching field and the non-matching field in the matching sequence, when the field currently required to be operated is the matching field. If the matching type is mutual matching, the target data block is determined from the second program file based on the data position and data length in the matching field. If the matching type is self-matching, the target data block is determined from the intermediate file obtained in the process of generating the first program file based on the data position and data length in the matching field, and the target data block is read into the RAM. It is understandable that in the process of generating the first program file in the RAM, the intermediate file of the first program file generated in the RAM may be stored in the RAM or may be written into the ROM.
[0138] When the field currently to be operated is a non-matching field, the target string associated with the non-matching field is read from the non-matching data stream. When obtaining the target string from the non-matching data stream, it is only necessary to sequentially obtain the data in the target string from the non-matching data stream according to the length of the target string.
[0139] In one possible example, assuming the length of a block is 16KB, and the first program file matches the 5th character, if a matching field in the upgrade package is M1 = {old_match, 0, 6}, then based on M1, it can be determined that the match type is a mutual match, and the starting position of the data to be matched in the second program file is the 5th (5-0 = 5)th character, and the length of the matched data is 6 characters. At this time, the electronic device needs to read the block to which characters 5 to 10 belong in the second program file into RAM, where characters 5 to 10 belong to block 1 of the second program file. If block 1 is not in RAM, block 1 needs to be read into RAM.
[0140] If a non-match field in the upgrade package is M2 = {non_match, none, 2}, M2 indicates that the match type is non-match and the length of the data to be retrieved is 2 characters. In this case, the electronic device only needs to sequentially retrieve the 2 characters from the newly added data stream in RAM as the data in the first program file and delete the already retrieved character string from the newly added data stream.
[0141] If a match field in the upgrade package is M3 = {self_match, 2, 3}, M3 indicates a self-match match. The matching data in the first program file starts at the third character (5-2 = 3), and the matching data length is 3 characters. Characters 3-5 belong to block 1 of the first program file. If block 1 is not in RAM, block 1 in the first program file needs to be loaded into RAM.
[0142] Step 1204: Generate a first program file based on at least one source data block and / or target character string in the RAM.
[0143] In this embodiment, generating the first program file in the RAM includes generating an intermediate file of the first program file in the RAM and writing at least a portion of the data in the intermediate file into a read-only memory (ROM), wherein the intermediate file of the first program file is composed of at least a portion of the data in the first program file. When generating the first program file in the RAM of the electronic device, it is also necessary to divide the data in the intermediate file of the generated first program file into data blocks, wherein the size of the data block can be the same as the size of the source data block. If the data in the intermediate file of the first program file meets the size of a block, the block is written into the read-only memory (ROM) of the electronic device. This ensures that only one block is retained at the end of the generated first program file in the RAM.
[0144] Since the number of data blocks that can be stored in the RAM is limited, when the data block to which the target data belongs is read into the RAM, it is necessary to determine whether the number of data blocks stored in the RAM exceeds a first threshold after the data block is read in. If the number of data blocks in the RAM exceeds the first threshold, the data block to which the target data belongs can be used to replace the data block in the RAM that has not been used for the longest time.
[0145] In an embodiment of the present application, when the electronic device upgrades the target software, the second program file and the first program file are divided into blocks, and only the blocks of data to be read or written are read into the RAM, so that only a limited number of blocks are retained in the RAM, thereby keeping the RAM usage at a small level.
[0146] It is understood that the order of execution of the steps in the above embodiments does not necessarily imply a specific order of execution. The order of execution of each process should be determined by its function and inherent logic, and should not constitute any limitation on the implementation process of the embodiments of the present application. In addition, in some possible implementations, the steps in the above embodiments can be selectively executed according to actual circumstances, and can be executed partially or completely, which is not limited here.
[0147] Next, the file update process in the above embodiment is explained by taking the system update on the Hawe Watch G3 as an example. When updating the GT3 system, the differential packet calculation can be completed on the electronic device, and the file restoration process can be tested on the GT3 development board. Among them, the maximum stack size of the development board parameters is 32KB, and the maximum heap size is 256KB. In the process of generating the differential packet, the minimum matching length MIN_MATCH_LEN can be set to 5 when generating the differential packet, and the default encoding method is finite state entropy (FSE). In the file restoration process, the block size BLOCK_LEN of the new file and the old file is 4096, and the maximum number of blocks that can be stored in RAM NUM_BUF_BLOCK = 8. The file sizes corresponding to the five pairs of new and old systems on the GT3 are shown in Table 3.
[0148] Table 3
[0149] The difference package size and restoration time obtained by the conventional program update method are shown in Table 4.
[0150] Table 4
[0151] The difference packet size and restoration time obtained by the program update method in the embodiment of the present application are shown in Table 5.
[0152] Table 5
[0153] Restoration time refers to the time it takes to generate a new file from the old file and the differential package. Comparing Tables 4 and 5 shows that the program update method in this embodiment improves both the size of the differential package and the time it takes to restore the new file. The size of the differential package obtained using the program update method in this embodiment is 35% of the size of the differential package obtained using a conventional program update method, and the time required for restoration is 3.5% of the time required using a conventional program update method.
[0154] Based on the method in the above embodiment, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program runs on a processor, the processor executes the method in the above embodiment.
[0155] Based on the method in the above embodiment, an embodiment of the present application provides a computer program product, characterized in that when the computer program product runs on a processor, the processor executes the method in the above embodiment.
[0156] The method steps in the embodiments of the present application can be implemented by hardware or by a processor executing software instructions. The software instructions can be composed of corresponding software modules, which can be stored in random access memory (RAM), flash memory, read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), registers, hard disks, mobile hard disks, CD-ROMs or any other form of storage medium known in the art. An exemplary storage medium is coupled to the processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an ASIC.
[0157] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted via the computer-readable storage medium. The computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid state drive (SSD)).
[0158] It will be understood that the various numerical numbers involved in the embodiments of the present application are merely distinctions for the convenience of description and are not intended to limit the scope of the embodiments of the present application.
Claims
1. A program updating method, characterized in that: Applied to electronic equipment, the method comprises: Obtain an upgrade package of a target program, the upgrade package carrying a matching sequence and a non-matching data stream, the matching sequence including a matching field and a non-matching field, the matching field being used to indicate that a string in the first program file matches a string in the first program file or a string in the second program file, the non-matching field being used to indicate that a string in the first program file matches a string in the non-matching data stream, the first program file and the second program file being program files of different versions of the target program, and a version of the first program file is higher than a version of the second program file; Parsing the upgrade package in a random access memory RAM to obtain the matching field, the non-matching field and the non-matching data stream; According to the order of the matching fields and the non-matching fields in the matching sequence, when the field currently to be operated is the matching field, determining the source data block to which the string associated with the matching field belongs, and reading the source data block into the RAM, wherein the source data block is obtained by segmenting the second program file or an intermediate file obtained in the process of generating the first program file; when the field currently to be operated is the non-matching field, reading the target string associated with the non-matching field from the non-matching data stream; A first program file is generated based on at least one source data block and / or the target character string in the RAM.
2. The method according to claim 1, characterized in that The step of generating a first program file based on at least one source data block and / or the target character string in the RAM comprises: An intermediate file of the first program file is generated in the RAM, and at least a portion of the data in the intermediate file is written into a read-only memory ROM, wherein the intermediate file of the first program file is composed of at least a portion of the data in the first program file.
3. The method according to claim 2, characterized in that The size of the at least part of the data is the same as the size of the source data block.
4. The method according to claim 1, characterized in that: The matching field includes a mutual matching field and a self-matching field, wherein the mutual matching field is used to indicate that a string in the first program file matches another string in the second program file, and the self-matching field is used to indicate that a string in the first program file matches a string other than the first string in the first program file; Both the mutual matching field and the self-matching field also include: data position and data length, the data position is used to identify the starting position of the character string associated with the corresponding matching field in the first program file or the second program file, and the data length is used to identify the length of the character string associated with the corresponding matching field.
5. The method according to claim 4, characterized in that The determining the source data block to which the character string associated with the matching field belongs includes: In the case where the matching fields are mutually matched, determining the source data block from the second program file; In the case where the matching field is self-matching, the source data block is determined from an intermediate file obtained in the process of generating the first program file.
6. The method according to any one of claims 1 to 5, characterized in that: Before reading the source data block into the RAM, the method further comprises: When the number of source data blocks in the RAM exceeds a first threshold, the source data block is used to replace the source data block in the RAM that has not been used for the longest time.
7. A program updating method, characterized in that: The method is applied to a server, and the method comprises: Acquire a first program file and a second program file of a target program, wherein the target program is a program on an electronic device that needs to be upgraded, the first program file and the second program file are program files of different versions of the target program, and the version of the first program file is higher than the version of the second program file; Determine a matching sequence and a non-matching data stream according to the matching cost, non-matching cost and loading cost of the data in the first program file and the second program file; the loading cost is the data in the second program file read when the first program file is generated on the electronic device; the cost of data in an intermediate file obtained in the process of generating the first program file on the electronic device or the process of generating the first program file on the electronic device, the matching sequence includes a matching field and a non-matching field, the matching field is used to indicate that a string in the first program file matches a string other than the first string in the first program file or a string in a second program file, and the non-matching field is used to indicate that a string in the first program file is the same as a string in the non-matching data stream; An upgrade package of the target program is generated according to the matching sequence and the non-matching data stream, wherein the upgrade package is used to indicate the difference between the first program file and the second program file.
8. The method according to claim 7, characterized in that The matching cost of data in the first program file and the second program file includes: a mutual matching cost and a self-matching cost. The mutual matching cost is the cost of a string in the first program file finding another matching string in the second program file, and the self-matching cost is the cost of a string in the first program file finding another matching string other than the first string in the first program file.
9. The method according to claim 8, characterized in that The determining of the matching sequence and the non-matching data stream according to the matching cost, the non-matching cost and the loading cost of the data in the first program file and the second program file of the target program comprises: Obtaining at least one matching cost according to matching costs, non-matching costs, and loading costs of the data in the first program file and the second program file in different matching modes; A minimum matching cost is selected from the at least one matching cost, and a matching sequence and a non-matching data flow of the first program file are determined according to a matching cost, a non-matching cost and a loading cost corresponding to the minimum matching cost.
10. An electronic device, characterized in that: include: at least one memory for storing a program; At least one processor is used to execute the program stored in the memory. When the program stored in the memory is executed, the processor is used to execute the method according to any one of claims 1 to 6.
11. A server, characterized in that: include: at least one memory for storing a program; At least one processor is used to execute the program stored in the memory. When the program stored in the memory is executed, the processor is used to execute the method according to any one of claims 7 to 9.
12. A computer-readable medium, wherein instructions are stored in the computer storage medium. When the instructions are executed on a computer, the computer executes the method according to any one of claims 1 to 6 or claims 7 to 10.
13. A computer program product comprising instructions, which, when executed on a computer, causes the computer to perform the method according to any one of claims 1 to 6 or claims 7 to 9.
Citation Information
Patent Citations
Program updating method, electronic equipment and server
CN119376753A
Method and device for manufacturing of software upgrading package and method and device for program upgrading
CN102831001A
OTA upgrade package downloading method and device, computer equipment and storage medium
CN109814893A
Differential package file generation method, interrupt recovery method and related devices
CN111176704A
Differential packet generation method and related equipment
CN111522574A