Program updating method, electronic equipment and server
By splitting the new and old files of the device system or program into a data block, and only retaining the necessary data blocks in RAM, the problem of high memory demand during the equipment upgrade process is improved, and the upgrade efficiency is improved.
Patent Information
- Application Number
- CN202310932422.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-26
- Publication Date
- 2025-01-28
AI Technical Summary
In the prior art, when upgrading device systems or programs, a large number of new and old files need to be loaded into random memory (RAM), resulting in high memory requirements and low upgrade efficiency, especially on thin devices with limited resources.
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, and only a limited data block is retained in RAM, so as to keep the RAM use at a small level.
Effectively reduced the demand for the equipment for RAM, improved the software upgrade efficiency on RAM's limited devices, and reduced memory occupation and I/O overhead in the upgrade process.
Smart Images

Figure CN119376753A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of information technology (IT) technology, and in particular to a program updating method, an electronic device and a server. Background Art
[0002] With the development of the Internet of Things, the system upgrade of large and small devices in the Internet of Things requires downloading the upgrade package from the server and executing the upgrade program on the device. In general, when upgrading the system or program on the device, the device needs to create a new file based on the differential package downloaded from the server and the old file to be upgraded on the device. Then, the device upgrades the system or program on the device based on the created new file.
[0003] Since, in the process of upgrading the system or program on the device, all the new and old files required for the upgrade need to be loaded into the random-access memory (RAM), the memory requirement of the device is relatively high. As the systems and programs become more and more complex, the system or program updates on the device have an increasingly higher demand for device memory. The method of completely loading all the new and old files required for the upgrade into the device's RAM to perform the upgrade operation has gradually become a performance bottleneck for the upgrade of the system or program on the device. Summary of the invention
[0004] The present application provides a program update method, an electronic device, a server, and a computer-readable medium, namely a computer program product. When updating, new and old files are split into data blocks, and only 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 the use of RAM at a small level.
[0005] In a first aspect, the present application provides a program updating method, which is applied to an electronic device, and the method comprises: obtaining an upgrade package of a target program, wherein the upgrade package carries a matching sequence and a non-matching data stream, wherein the matching sequence comprises a matching field and a non-matching field, wherein the matching field is 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, and the non-matching field is used to indicate that a string in the first program file matches a string in the non-matching data stream, wherein 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; 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.
[0006] In this solution, during the process of upgrading the target software on the terminal device, the second program file corresponding to the target software before upgrading is divided into multiple data blocks. When the first program file is generated in the RAM, if it is necessary to read data at a certain position in the first program file or the second program file, only the data block corresponding to the data segment needs to be read into the RAM, and the entire first program file or the second program file does not need to be read into the RAM, so that the RAM usage is maintained at a small level. This enables efficient software upgrades on thin devices with limited RAM.
[0007] 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 consists of at least a portion of the data in the first program file.
[0008] That is, in 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.
[0009] In a possible implementation, the size of at least a portion of the data is the same as the size of the source data block.
[0010] That is, when the first program file is generated in the RAM, the generated first program file also needs to be divided into data blocks, and whenever the data in the intermediate file of the generated first program file meets the size of a data block, the data block is written into the ROM. This ensures that only one block is reserved at the end where the second program file is generated in the RAM, thereby reducing the use of the RAM.
[0011] 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 a first program file matches another string in a second program file, and the self-matching field is used to indicate that a string in a 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: a data position and a 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.
[0012] That is to say, 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 position 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 for generating the first program file according to the self-matching field or the mutual matching field. Among them, when the matching field is a mutual match, the corresponding matching field refers to the mutual match field, and when the matching field is a self match, the corresponding matching field refers to the self-matching field.
[0013] 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.
[0014] 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 according to the type of the matching field.
[0015] In a 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.
[0016] That is to say, due to the limited RAM, the number of data blocks loaded in the RAM cannot exceed the set threshold. If the set threshold is reached, a data block in the RAM needs to be replaced. Based on the I / O overhead of reading data blocks into the RAM, the probability that the data block that has not been used for the longest time in the RAM will participate in the match again is smaller. Therefore, the strategy for replacing data blocks in the RAM can be to replace the data block that has not been used for the longest time in the RAM each time.
[0017] In a second aspect, the present application provides a program updating 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 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 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 according to 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.
[0018] In this solution, the server generates an upgrade package of 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. Among them, in the process of generating a matching sequence and a 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 in the intermediate file obtained in the process of generating the first program file can be included in the matching cost. This enables the most optimized matching result to be obtained, and ensures the optimization of the number of data block loading times, while being able to finely balance the differential rate and the number of I / O times.
[0019] In one possible implementation, 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.
[0020] That is to say, 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.
[0021] 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 the 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.
[0022] In other words, the matching costs under different matching methods can be calculated separately, and the matching cost, non-matching cost and loading cost corresponding to the minimum matching cost 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.
[0023] In a third aspect, the present application provides an electronic device, including:
[0024] at least one memory for storing a program;
[0025] 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 manner of the first aspect.
[0026] In a fourth aspect, the present application provides a server, including:
[0027] at least one memory for storing a program;
[0028] 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 manner of the second aspect.
[0029] In a fifth aspect, the present application provides a computer storage medium, in which instructions are stored. 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.
[0030] 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
[0031] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0032] Figure 1 A schematic diagram of a process of system update on a device provided in an embodiment of the present application;
[0033] Figure 2 A schematic diagram of a general differential upgrade process provided in an embodiment of the present application;
[0034] Figure 3 A schematic diagram of an upgrade scenario of a terminal device provided in an embodiment of the present application;
[0035] Figure 4 A schematic diagram of the hardware structure of a server provided in an embodiment of the present application;
[0036] Figure 5 A schematic diagram of the structure of a terminal device provided in an embodiment of the present application;
[0037] Figure 6 A schematic diagram of a new file representation process provided in an embodiment of the present application;
[0038] Figure 7 A schematic diagram of a matching method provided in an embodiment of the present application;
[0039] Figure 8 A schematic diagram of another matching method provided in an embodiment of the present application;
[0040] Fig. 9 A schematic diagram of the generation principle of a new file provided in an embodiment of the present application;
[0041] Fig.10 A schematic diagram of a process for generating a new file in RAM provided in an embodiment of the present application;
[0042] Fig.11 A flowchart of a program update method provided in an embodiment of the present application;
[0043] Fig.12 A flowchart of another program updating method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0044] 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 in conjunction with the accompanying drawings.
[0045] In the description of the embodiments of the present application, any embodiment or design scheme of "exemplary", "for example" or "for example" should not be understood as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary", "for example" or "for example" is intended to present related concepts in a specific way.
[0046] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. The terms "include", "comprises", "has" and their variations all mean "including but not limited to", unless otherwise specifically emphasized.
[0047] Before introducing this solution, the technical terms involved in this solution are first introduced.
[0048] Rich devices: devices with abundant random-access memory (RAM) and central processing unit (CPU), such as smartphones and smart watches.
[0049] Thin devices: terminal devices with limited resources, such as wristbands and sports watches.
[0050] Match: A continuous piece of data is found in the same or similar segments from other sources, where the same is called a perfect match. In the embodiments of this application, "match" refers to a perfect match.
[0051] LZ77 algorithm: LZ77 is a universal compression algorithm based on bytes. Its principle is to replace repeated bytes in the source file (i.e., repeated bytes that appear in the previous text) with a triple of (distance, length, nextchar). Among them, 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, that is, how many characters match the previous text; nextchar represents the next character of the current matching string. Under normal circumstances, the universal compressor follows not only one char after a match, but a string of chars as a literal.
[0052] Next, this solution is introduced.
[0053] The system or program upgrade of the device needs to download the upgrade package from the server, and execute the upgrade program on the device according to the downloaded upgrade package. Among them, the size of the upgrade package directly affects the traffic cost, user experience, development cycle, etc. of the system or program on the device during the upgrade process. For example, Figure 1 FIG. 1 shows a process of updating a system on a device. Figure 1 As shown, after the development department specifies, develops, and generates a new image for the device, it enters the packaging process. The packaging process occurs on the server. The packaging tool on the server generates 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 service and the new image file that the device needs to upgrade. Then, the generated multiple differential packages are packaged together and sent to the device. The differential package refers to the part where there is a difference between the new image file and the old image file. After receiving the differential package sent by the server, the device generates a new image file based on the old image file and the differential package on the device, and updates the system on the device based on the generated new image file.
[0054] Existing equipment 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 FIG. 2 shows a general differential upgrade process flow diagram. Figure 2 As shown, given a binary new and old file 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", and 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.
[0055] Table 1
[0056] Difference method type feature imagediff System image upgrade tool Parsing, by file and block differences archive-patcher Application package upgrade tool Parse + decompress, by file difference bsdiff General difference algorithm The difference rate is the best, but the speed and resource consumption are high. Gdelta General difference algorithm Faster speed, but the difference rate needs to be improved Rock General difference algorithm Differential upgrades are performed on thin devices, but the differential rate and update rate are poor
[0057] In the process of upgrading through differential packages, the measurement criteria for the general differential algorithm used mainly include: (1) differential package size; (2) the rate at which new files are generated based on differential packages on the device; (3) the resource overhead of generating new files; (4) the rate at which differential packages are generated on the server. Based on the measurement criteria of the general differential algorithm, when upgrading software on rich devices such as PCs and smart devices, the bsdiff algorithm and the Rock algorithm can usually be used.
[0058] Bsdiff is a general-purpose binary file difference algorithm with byte granularity, which 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 imperfect matching, that is, the required modifications to the fields of the ADD operation are recorded separately. For example, DIFF(5,'a') means changing the 5th byte of the new file to 'a'. The differential package obtained by bsdiff usually contains the following parts: (1) a sequence consisting of ADD and INSERT; (2) a sequence consisting of DIFF; (3) an extra data stream. These three parts are compressed and packaged by a compressor with excellent compression ratio.
[0059] It is understandable that the way bsdiff obtains a match is to construct a suffix array, scan the new file from front to back, and find the longest match for each byte. When the difference bytes starting from a certain position exceed a certain ratio, a match is output. However, the match may not be a perfect match, and the difference content needs to be given by an additional DIFF data stream. Therefore, the position where bsdiff finds a match may be arbitrary.
[0060] In the process of upgrading the software on the device, bsdiff can achieve the upgrade of the software on the device. However, in the process of generating differential packets, bsdiff needs to rely on the black box compression algorithm to reduce the size of the generated differential packets, which increases the complexity of bsdiff and leads to poor scalability of bsdiff. Secondly, in the process of generating new files based on differential packets and old files, bsdiff matches in a specific greedy way. Although it works for most data, it is difficult to adapt or improve other systems.
[0061] Rock can perform differential calculations on the server side for new and old files to obtain differential packages. And Rock can also complete differential updates based on differential packages on devices with only tens of KB of RAM. Although Rock can complete differential updates on smaller RAM, there are still problems of loss of differential rate and high restoration time overhead during differential upgrades through Rock.
[0062] The kernel algorithms of software on rich devices such as computers and smart devices are relatively fixed, but the differential methods for upgrading thin devices in resource-constrained scenarios still need to be improved. Existing thin devices face strict resource limitations during software upgrades, such as: (1) Only a small amount of RAM can be used 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. At present, the update methods used are either inefficient algorithms such as Rock or full updates, which causes users to need dozens of minutes to transfer the upgrade package and perform the update operation when upgrading the system or program. With the increasing requirements for the user experience of thin devices, the increase in APP applications and the complexity of functions, 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.
[0063] Table 2
[0064]
[0065] As shown in the data in Table 2, during the upgrade process of the G3 watch, the data transmission time is 4 minutes to 90 minutes, the installation time is about 6 minutes, and the upgrade process takes a total of 10 minutes to 96 minutes. Since the conventional differential upgrade algorithm cannot be used on wearable devices with limited RAM, the upgrade time of existing wearable devices is long and the user upgrade experience is poor.
[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 a terminal device, the old files stored in the terminal device and the new files that have 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 A schematic diagram of an upgrade scenario of a terminal device provided in an embodiment of the present application is shown. Figure 3 The figure includes: a server 100 deployed in a content delivery network (CDN), a first terminal device 200, and a second terminal device 300. Among them, the first terminal device 200 can be a rich device, such as a smart phone; the second terminal device 300 can be a thin device, such as a sports watch. The sports watch communicates with the smart phone via WiFi and Bluetooth, and the smart phone can communicate with the server in the CDN via WiFi and mobile network. When the system or software in the sports watch needs to be upgraded, the installation package corresponding to the system or software to be upgraded can be downloaded from the server in the CDN through the smart phone. Then, the smart phone upgrades the sports watch through the APP corresponding to the sports watch on the smart phone (such as a sports health APP). It can be understood that Figure 3 The device upgrade scenario shown is only an example of an application scenario of the embodiment of the present application. In actual applications, it may include Figure 3 More or fewer devices. For example, Figure 3 When the sports watch in the device needs to be upgraded, the differential package required for the upgrade can be directly downloaded from the server in the CDN network.
[0068] Next, Figure 3 The hardware structure of the server and terminal devices in the device upgrade scenario shown is introduced.
[0069] For example, Figure 4 FIG. 1 shows a schematic diagram of the hardware structure of a server. Figure 4As shown, 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 (or referred to as 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 memory 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 is understandable that the embodiments of the present application Figure 3 The illustrated structure does not constitute a specific limitation on the server 100. In other embodiments of the present application, the server 100 may be a cloud server. The server 100 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0074] For example, Figure 5 FIG. 1 shows a schematic diagram of the structure of a terminal device. It can be understood that the terminal device can be Figure 3 The first terminal device 200 in the example may also be the second terminal device 300, and the terminal device may 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 the terminal device 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 the terminal device.
[0075] like Figure 5 As shown, 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 a program, which may be run 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 may read data stored in the memory 520. The memory 520 and the processor 510 may be provided separately. Optionally, the memory 520 may also be integrated in 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, the communication module 540 may provide a solution for wireless communications including 2G / 3G / 4G / 5G applied to the terminal device. Exemplarily, the communication module 540 may be used for the terminal device to communicate with a server or other terminal devices to obtain an update package of 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. Exemplarily, the input device 550 may be, but is not limited to, a mouse, a keyboard, and the like.
[0081] It is understandable that the embodiments of the present application Figure 5 The illustrated structure 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 in the figure, or combine some components, or split some components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0082] Next, Figure 4 and Figure 5 Taking the server and terminal device shown as an example, a file update process provided by an embodiment of the present application is introduced. It includes a process of generating a differential package of the file to be updated on the server, and a process of 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 mainly involves processing on the server side and the terminal device side.
[0083] (1) Generate a differential package of the file to be updated
[0084] In the embodiment of the present application, the file to be updated mainly refers to the file 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 side 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 can be understood 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 of 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 with the new file to generate a differential package of 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 match + self-match + non-match". Among them, mutual match refers to forming a dictionary of all the 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-match 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 current matched characters in the previous text is recorded; non-match refers to the strings in the new file that neither match the strings in the old file nor match other strings in the new file.
[0087] In a possible example, S[i,j] is used to represent the string S from bytes i to j, which includes the i-th byte but not the j-th byte. Assume that the old file is represented by S in bytes, with a length of L_load bytes, and the new file is recorded 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). Among them, type∈{old_match, self_match, non_match} is an enumeration type, and distance and length are integers. Assume that the current position processed in the new file is 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, and 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 FIG. 2 shows a process of representing a new file, that is, a process of representing a new file in a "mutual matching + self-matching + non-matching" manner. Figure 6As shown, the new file includes the characters "abedcfadepdcfa", and the characters in the old file are "abedcfaa". When matching the new file and the old file, the matching starts from the first character (i.e., t=1). Through the matching, it can be seen 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}. Then, the server continues to match from the 8th character in the new file. Through the matching, it can be seen that there are no characters in the characters in the old file and the characters from t=1 to t=7 in the new file that match the characters from t=8 to t=10. At this time, the characters from t=8 to t=10 (dep) can be used as the newly added data stream Literal, and the characters from t=8 to t=10 can be represented as M2={non_match,none,3}. The server continues to match from the 11th character in the new file. Through matching, it can be known 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 is understandable that in the process of matching the new file with the old file, the size of the operation sequence generated by the match and the number of operation sequences are closely related to the size of the generated differential packet, and when the new file is matched with the old file, the string to be matched in the new file is not unique. Figure 6 In the example, characters from t=11 to t=14 in the new file match characters from t=4 to t=7 in the old file and characters from t=4 to t=7 in the new file. When generating the operation sequence in the differential packet, a matching string can be selected from multiple strings matching the current position by calculating the best match.
[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]
[0092] 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, match_price(distance,nm) is the cost of input[m..n] in the case of forward distance to find a match, and the costs of both methods are estimated by the given method. S[m] represents the cost of representing characters from 0 to m-1.
[0093] When the old file is introduced for matching, the calculation method of S[n] can be recursively expressed as:
[0094]
[0095] 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.
[0096] Because, in the embodiment of the present application, the terminal device needs to divide the old file and the generated new file into blocks according to a fixed length. When the terminal device generates a 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 last time 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.
[0097] In the case of introducing the loading overhead on the terminal device, the calculation method of S[n] can be recursively expressed as,
[0098]
[0099] 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.
[0100] If the block already in RAM is called a cache block, the reload_cost item is determined by whether the block is a cache block and the number of cache blocks that have been read recently. Its value is equivalent to the number of bytes after compression. For example, the cost of reading data from a block that has not been loaded can be set to 20 bytes, and the cost of a loaded block can be set to 0.1r bytes, where r represents the number of times the block has been read recently. Only when the benefit of this match is greater than 20 bytes can it be adopted.
[0101] In the process of calculating the optimal match, a large number of fragmented and scattered matches are intuitively removed by introducing the loading overhead on the terminal device, and large-block matches or matches in the cache block are used.
[0102] For example, Figure 7 Figure 1 shows a matching method. When a candidate match is not in the cache block, the candidate match will be adopted only when the match length reaches the reload cost. Figure 7 As shown in the figure, 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 3 candidate matches in the block of the new file and the old file, but the lengths of the 3 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.
[0103] After a match is taken, the corresponding block will become a cacheblock when performing a restore match, so the matches in this block will not be subject to the reload cost threshold. Figure 8As shown in the figure, 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 match 2 and candidate match 3 in block 1 match candidate match 2 and candidate match 3 in block 2 respectively, it is not necessary to consider whether the length of candidate match 2 and candidate match 3 is greater than R, and candidate match 2 and candidate match 3 will definitely be adopted.
[0104] Get the operation sequence on the server After the non-matching stream literal, the resulting sequence of operations needs to be The non-matching stream literal is entropy encoded and cut into blocks for packaging to obtain a differential package of the system / software to be updated on the terminal device.
[0105] (2) Generate a new file based on the differential package of the file to be updated
[0106] 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 according to the received differential package and the old file of the system / software to be updated stored on the terminal device.
[0107] For example, Fig. 9 A schematic diagram of the generation principle of a new file is shown. Fig. 9 As shown, after the terminal device decodes the differential packet, it reads out the operation sequence in the differential packet in sequence. and non-matching stream literals. Then, the terminal device follows the sequence of operations 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.
[0108] Under normal circumstances, when the 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 all the old files 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 are operated directly on RAM, the RAM needs to have a large capacity, and with so many matching operations, the data reading time overhead is large. Therefore, in the embodiment of the present application, the old file and the generated new file are divided into blocks according to a fixed length. During the matching process, the old and new files of the terminal device are split into blocks, and only the blocks of data to be read and written are loaded into RAM, and only a limited number of blocks are retained in RAM, thereby keeping the RAM usage at a small level.
[0109] Specifically, the terminal device divides the old files of the system / software to be updated into multiple blocks according to a preset length. Usually, the length of a 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 obtains the sequence of operations in the differential packet. After the non-matching stream literal, the terminal device follows the operation sequence The information carried is used to obtain the corresponding data from the old file, the non-matching stream literal or the generated new file to generate a new file. The new file is generated in the RAM of the terminal device. When the data is read into the RAM, the block corresponding to the data segment to be read is read into the RAM. For the new file generated in the RAM, when the size of the generated new file is one block, the new file needs to be written into the ROM. For the end where the new file is generated, only one block needs to be retained in the RAM.
[0110] Since RAM is limited, the number of blocks loaded into RAM is limited (usually several 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, and 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, and all blocks of old files and blocks that have been generated in new files may be loaded as cache blocks. When performing matching calculations, it is necessary to ensure that it does not span more than one block.
[0111] For example, Fig.10 A schematic diagram of the process of generating a new file in RAM is shown, showing the location where the new and old files and cache blocks are stored in the terminal device and the method of data transfer. Fig.10As shown, the old file block and the generated new file block are stored in ROM. When the terminal device generates a new file, it reads the block where the data to be read is located from the middle of ROM into RAM. After the new file generated in RAM meets the size of a block, it needs to write the new file back to ROM.
[0112] It is understandable that the matching information and non-matching data streams in the differential packet have a length limit when they are packaged, and are read sequentially. Therefore, after the terminal device obtains the differential packet, it only needs to decode the current packet into RAM, and there is no need to block the data in the differential packet.
[0113] In a possible example, assume that the old file of the system / software to be updated stored in the terminal device package is "abedcfaapcpdfd", and 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-matching stream literal is "dep". The terminal device first divides the old file into 2 blocks, each of which is 7 bytes in size. Among them, the data contained in block1 is "abedcfa" and the data contained in block2 is "apcpdfd". Then, the terminal device decodes the differential packet into RAM and starts matching from the first byte of the new file, that is, t = 1. Specifically, the first operation sequence M1 in the differential packet is parsed. Since the type in M1 is old_match, the distance is 0, and the length is 7, it means that the 1st to 7th bytes in the old file are matched with the 1st to 7th bytes in the new file. Since the 1st to 7th bytes belong to block1, the data in block1 is read into RAM and matched with the 1st to 7th bytes in block1 to generate the 1st to 7th bytes of the new file. After obtaining the 1st to 7th bytes of the new file, since its size satisfies a block, the generated new file needs to be written into ROM. t is updated to 8, and the terminal device continues to parse the second operation sequence M2. Since the type in M2 is non_match, the distance is none, and the length is 3, it means that the 8th to 10th bytes in the new file need to be read from the newly added data stream Literal. Therefore, the first 3 bytes are read from Literal in sequence as the 8th to 10th bytes of the new file. At this time, t is updated to 11, and the terminal device continues to parse the third operation sequence M3. Since the type in M3 is self_match, the distance is 7, and the length is 4, it means that the 4th to 7th bytes in the new file are the same as the 11th to 14th bytes in the new file. Since the 4th to 7th bytes belong to the first block of the new file and the first block has been loaded into the ROM, it is necessary to read the first block of the new file from the ROM into the RAM and match the 4th to 7th bytes in the first block to generate the 11th to 14th bytes of the new file.
[0114] In the embodiment of the present application, when the system / software on the device is differentially upgraded, the upgrade process is in the RAM. In order to avoid reading all the data into the RAM, the data blocks need to be divided into blocks, and the blocks to which the required data belongs are read into the RAM. At the same time, when reading the blocks of the new / old files, the blocks that have been read recently are read first, saving I / O overhead. It can be understood that the above method is not only applicable to the differential upgrade scenario of the system / software on the device, but also to other application scenarios involving storage devices and databases.
[0115] In the embodiment of the present application, the server generates a differential upgrade package of the system / software to be updated on the terminal device based on "mutual matching + self-matching + non-matching", and in the matching calculation process of generating the differential upgrade package, the cost of loading the block is included in the matching cost, so that the optimal matching result ensures the optimization of the number of data block loading times, and can finely balance the differential rate and IO times. In the process of upgrading the system / software to be updated on the terminal device, the new and old files are split into blocks, and only the blocks of data to be read and written are loaded into RAM, and only a limited number of blocks are retained in RAM, so as to keep the use of RAM at a small level.
[0116] 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.
[0117] For example, Fig.11 A schematic diagram of a program update method provided in an embodiment of the present application is shown. Figure 3 The server in the implementation. Fig.11 The method shown includes: step 1101-step 1103.
[0118] Step 1101, obtaining a first program file and a second program file of a target program.
[0119] 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 a file corresponding to the target program after the upgrade, and the second program file may be a file corresponding to the target software before the upgrade. The second program file may be referred to as an old file, and the first program file may be referred to as a new file. The first program file and the second program file of the target program may be pre-stored in the server, or may be input into the server in real time by the user as needed.
[0120] Step 1102 , determining 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 of the target program.
[0121] In this embodiment, the loading cost is the cost of reading data in the second program file when generating the first program file on the electronic device or the cost of reading data in the intermediate file obtained in the process of generating the first program file on the electronic device. The intermediate file obtained in the process of generating the first program file includes a file stored in the ROM and a file belonging to the first program file stored in the RAM. 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.
[0122] After obtaining the first program file and the second program file 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 records the sequence in an extended LZ77 manner. Among them, recording the representation sequence of the new file in an extended LZ77 manner means that the string in the first program file is represented by a triple operation sequence M, M = (type, distance, length), where type∈{old_match, self_match, non_match} is an enumeration type, and distance and length are integers.
[0123] 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 current position 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.
[0124] 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 loading cost of the data 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 loading cost of the data when the first program file is generated on the electronic device refers to the cost of reading the block each time. The cost of reading the block is determined by whether the block is a cache block and the number of cache blocks that are read most recently. Its value is equivalent to the number of bytes after compression. The matching cost of the 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.
[0125] 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. Among them, the calculation method of S[n] can be recursively expressed as follows:
[0126]
[0127] 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.
[0128] 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, and its value is equivalent to the number of bytes after compression.
[0129] 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 of the string in the first program file, the matching sequence (which can also be determined by the operation 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. ). 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.
[0130] 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 difference between the first program file and the second program file.
[0131] In this embodiment, after obtaining the matching sequence and the non-matching data stream corresponding to the first program file, the server may encode and segment the obtained matching sequence and the non-matching data stream to obtain an upgrade package of the target program.
[0132] In the embodiment of the present application, when matching the second program file with the first program file to generate an upgrade package, the block loading cost when generating the second program file on the electronic device is included in the matching cost. This ensures that the optimal matching result is obtained while ensuring the optimization of the number of data block loadings, and can finely balance the difference rate and IO times.
[0133] For example, Fig.12 A schematic diagram of a program update method provided by an embodiment of the present application is shown. The method is mainly executed by an electronic device, which may be a Figure 3 The terminal device 1 in the example may also be the terminal device 2. Fig.12 As shown, the method includes: step 1201-step 1204.
[0134] Step 1201: Obtain an upgrade package of a target program, wherein the upgrade package carries a matching sequence and a non-matching data stream.
[0135] 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 may be a file corresponding to the target program after the upgrade, and the second program file may be a file corresponding to the target software before the upgrade. The first program file may also be referred to as an old file, and the second program file may be referred to as 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.
[0136] Step 1202: parse the upgrade package in the random access memory RAM to obtain matching fields, non-matching fields and non-matching data streams.
[0137] In this embodiment, since the matching sequence and the non-matching data stream in the upgrade package have a length limit when they are packaged, and the matching sequence and the non-matching data stream in the upgrade package are read sequentially, after receiving the upgrade package, the electronic device can directly decode the upgrade package into the RAM without causing too much overhead.
[0138] 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.
[0139] 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 the block can be 1KB to 16KB. And in the process of generating the first program file corresponding to the target program, the intermediate file obtained in the process of generating the first program file is divided into multiple blocks. Since the RAM on the electronic device is limited, when the electronic device generates the first program file, if it needs to read data at a certain position in the first program file or data in the intermediate file obtained in the process of generating the first program file, it only needs to read the block corresponding to the data segment into the RAM.
[0140] When generating the first program file of the target program, the electronic device can obtain the target data for generating the first program file according to 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 data in the first program file, data in the second program file, and 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 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 string associated with the matching field.
[0141] 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 according to 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 according to 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.
[0142] 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, data in the target string only needs to be sequentially obtained from the non-matching data stream according to the length of the target string.
[0143] In one possible example, assuming that 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}, it can be determined based on M1 that the matching 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 the 5th to 10th characters in the second program file belong into the RAM, where the 5th to 10th characters belong to block1 of the second program file. If block1 is not in the RAM, block1 needs to be read into the RAM.
[0144] If a non-matching field in the upgrade package is M2 = {non_match, none, 2}, it can be determined according to M2 that the match type is non-matching, and the length of the data to be obtained is 2 characters. At this time, the electronic device only needs to sequentially obtain 2 characters from the newly added data stream in the RAM as the data in the first program file, and delete the obtained character string from the newly added data stream.
[0145] If a matching field in the upgrade package is M3 = {self_match, 2, 3}, it can be determined from M3 that the matching type is self-matching, the starting position of the data to be matched in the first program file is the 3rd (5-2 = 3)th character, and the length of the matched data is 3 characters. Among them, the 3rd to 5th characters 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 read into RAM.
[0146] Step 1204: Generate a first program file based on at least one source data block and / or target character string in the RAM.
[0147] In this embodiment, when generating the first program file in the RAM, it 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. When 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. So that only one block is retained at the end where the first program file is generated in the RAM.
[0148] 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. When 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.
[0149] 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 blocks of data to be read and 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.
[0150] It is understandable that the size of the sequence number of each step in the above embodiment does not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application. In addition, in some possible implementations, each step in the above embodiment can be selectively executed according to actual conditions, and can be partially executed or fully executed, which is not limited here.
[0151] Next, taking the system update on Hawe Watch G3 as an example, the file update process in the above embodiment is explained. When updating the system of GT3, the differential packet calculation can be completed on the electronic device, and the file restoration process can be tested on the development board of GT3. Among them, the maximum stack of the development board parameters is 32KB, and the maximum heapsize is 256KB. In the process of generating differential packets, the minimum matching length MIN_MATCH_LEN can be set to 5 when generating differential packets, and the default encoding method is finite stateentropy (FSE). In the process of file restoration, the block size BLOCK_LEN of the new file and the old file is divided into 4096, and the maximum number of blocks that can be stored in RAM NUM_BUF_BLOCK=8. The file sizes corresponding to the 5 pairs of new and old systems on GT3 are shown in Table 3.
[0152] Table 3
[0153] File name Old file size (bytes) New file size (bytes) glyphs.bin 29929522 29930320 prompt01.bin 3964604 8347192 prompt02.bin 13034244 13034244 gui104.bin 6656520 6691064 gui109.bin 6512912 6633816 TOTAL 60097802 64636636
[0154] The difference package size and restoration time obtained by the conventional program update method are shown in Table 4.
[0155] Table 4
[0156] File name Differential packet size (byte) Restore time(s) glyphs.bin 9591781 1266 prompt01.bin 4391197 10.09 prompt02.bin 33149 13.10 gui104.bin 1373364 74.07 gui109.bin 695289 24.78 TOTAL 16084780 1388.04
[0157] The difference packet size and restoration time obtained by using the program update method in the embodiment of the present application are shown in Table 5.
[0158] Table 5
[0159] File name Old file size (bytes) Restore time(s) Is the restored file accurate? glyphs.bin 2092768 29.65 true prompt01.bin 3588750 8.85 true prompt02.bin 733 5.68 true gui104.bin 12657 2.50 true gui109.bin 33672 2.28 true TOTAL 5728580 48.96
[0160] Among them, the restoration time refers to the time taken to obtain a new file based on the old file and the differential package. By comparing Table 4 and Table 5, it can be seen that the size of the differential package obtained by using the program update method in the embodiment of the present application and the restoration time of the new file are improved. Among them, the size of the differential package obtained by using the program update method in the embodiment of the present application is 35% of the size of the differential package obtained by using the conventional program update method, and the time required for restoration is 3.5% of the time required for restoration by using the conventional program update method.
[0161] 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.
[0162] 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.
[0163] 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, and the software modules 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.
[0164] 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 may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted through the computer-readable storage medium. The computer instructions may be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may 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 may 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 disk (SSD)), etc.
[0165] It should be understood that the various numerical numbers involved in the embodiments of the present application are only used for the convenience of description and are not used 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 that needs to be upgraded on the 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 according to a matching cost, a non-matching cost and a loading cost of data in the first program file and the second program file; the loading cost is a cost of reading data in the second program file when generating the first program file on the electronic device or data in an 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 in the first program file other than the first string 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 identical to 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
Cited By
Program update method, electronic device, and server
EP4528487A1
Program update method, electronic device, and server
WO2025020520A1