Firmware difference method, device, equipment, medium and product
By constructing a list of similar data block ranges and using a preset threshold for filtering, a final mapping table and differential packets are generated, solving the problems of large differential packet size and low transmission efficiency in existing technologies, and achieving efficient firmware differential and upgrade.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-05
- Publication Date
- 2026-03-10
AI Technical Summary
Existing firmware differential methods suffer from a large number of jump addresses, resulting in large differential packet sizes, low transmission efficiency, and high memory requirements, which negatively impacts user experience.
By acquiring the pre-differential packets, a list of similar data block ranges is constructed, jump instructions are identified, an initial mapping table is generated, and a final mapping table and differential packets are finally generated through filtering by a preset threshold, thereby reducing differential time and improving data compression and transmission efficiency.
It reduces differential time, increases data compression and transmission efficiency, ensures the accuracy of the restoration process, and reduces the demand for memory resources.
Smart Images

Figure CN121644362A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the technical field of Internet of Things (IoT) updates, and particularly relates to a firmware differential method, apparatus, device, medium, and product. Background Technology
[0002] Current firmware upgrades mainly use a differential method, which generates a differential firmware by subtracting the firmware to be upgraded from the firmware currently running on the device. This differential firmware is then compressed and sent to the device to be upgraded. The device receives the differential firmware, decompresses it, and combines it with the old firmware to reconstruct the new full firmware. The advantages of this differential method are small firmware size, fast upgrade speed, and significant reduction in traffic or bandwidth resources.
[0003] However, the differential method currently used results in a large overall size of differential packets and low transmission efficiency due to the large number of jump addresses in the firmware. Moreover, the restoration process requires a large amount of memory resources from the firmware, which undoubtedly increases the firmware burden and affects the user experience. Summary of the Invention
[0004] This application provides a firmware differential method, apparatus, device, medium, and product that can increase data compression, reduce differential packet size, and improve transmission efficiency.
[0005] On one hand, embodiments of this application provide a firmware differential method, the method comprising: Obtain a pre-difference packet, which is generated based on the firmware to be upgraded and the firmware that has been upgraded. The pre-difference packet includes control data, difference data, and update data. Based on the control data, difference data, and update data, a similar data block range list is constructed. The similar data block range list is used to characterize the mapping relationship between the firmware to be upgraded and the firmware that has been upgraded. Jump instruction identification is performed on the pre-update data of the firmware to be upgraded and the post-update data of the firmware after the upgrade in the similar data block range list to generate an initial mapping table. The initial mapping table is used to represent address pairs with consistent jump address pairs, including the estimated jump instruction to be upgraded and the jump instruction of the firmware after the upgrade. The initial mapping table is filtered according to a preset counting threshold to obtain the final mapping table; Based on the final mapping table, the control data, the difference data, and the update data, the final difference package is generated.
[0006] Optionally, before generating the final difference package based on the final mapping table, the control data, the difference data, and the update data, the method further includes: Obtain the firmware location corresponding to the jump address in the initial mapping table; Set the difference data corresponding to the firmware position to 0 to obtain new difference data; The step of generating the final difference package based on the final mapping table, the control data, the difference data, and the update data includes: Based on the final mapping table, the control data, the new difference data, and the updated data, the final difference package is generated.
[0007] Optionally, the list of similar data blocks includes the start position of the firmware to be upgraded and its corresponding end position, as well as the start position of the firmware to be upgraded and its corresponding end position. The step of identifying jump instructions for the pre-update data of the firmware to be upgraded and the post-update data of the upgraded firmware in the similar data block range list, and generating an initial mapping table, includes: The list of similar data blocks is traversed, and the jump instruction is identified from the starting position of the firmware to be upgraded according to the first preset number of bytes to obtain the first identification result. If the first identification result indicates that the jump instruction has been successfully identified, the first instruction location and the first jump address are determined based on the first current location of the firmware to be upgraded. Based on the first instruction position, a jump instruction is identified from the starting position of the completed firmware upgrade according to a first preset number of bytes to obtain a second identification result; If the second identification result indicates that the jump instruction has been successfully identified, the second instruction position and the second jump position are determined based on the second current position after the firmware upgrade is completed. An initial mapping table is generated based on the first instruction location, the first jump address, the second instruction location, and the second jump location.
[0008] Optionally, if the second result indicates that the jump instruction recognition failed, the method further includes: For each of the first instruction position, the first jump position, and the second instruction position, multiple exception mapping sets are constructed based on the first instruction position, the first jump position, and the second instruction position; An exception mapping table is generated based on the multiple exception mapping sets.
[0009] Optionally, if the first identification result is that the jump instruction identification fails, the process is to traverse backward by a second preset number of bytes until the first identification result is that the jump instruction identification is successful.
[0010] Optionally, before filtering the initial mapping table according to a preset counting threshold to obtain the final mapping table, the method further includes: Based on the first jump position and the second jump position, a jump address pair is generated; Count the first number of each jump address pair; The step of filtering the initial mapping table according to a preset counting threshold to obtain the final mapping table includes: Based on the first quantity and a preset counting threshold, the jump address pairs in the initial mapping table are filtered to obtain target jump address pairs, wherein the target jump address pairs include jump address pairs whose first quantity is greater than the preset counting threshold; Based on the target jump address pair, a final mapping table is generated.
[0011] Optionally, before generating the final mapping table based on the target jump address pair, the method further includes: The initial mapping table is traversed, and the first jump position in the initial mapping table is compared to obtain the comparison result. If the comparison result includes the existence of at least two jump address pairs with the same first jump position, compare the first number of the at least two jump address pairs, and delete the jump address corresponding to the smallest first number from the initial mapping table.
[0012] Optionally, after generating the final difference package based on the final mapping table, the control data, the difference data, and the new data, the method further includes: For the target firmware to be upgraded, the final differential packet is parsed to determine the list of similar data block ranges and the final mapping table. Based on the range of similar data blocks to be searched, the target firmware to be upgraded is identified by byte traversal to obtain a third identification result; If the third identification result indicates that the jump instruction has been successfully identified, the target jump address and the target instruction location are obtained; If the target jump address is included in the final mapping table, differential packet reconstruction is performed based on the target jump address and the target instruction location to obtain the reconstructed packet; The target firmware to be upgraded is upgraded based on the restore package to obtain the final firmware.
[0013] On the other hand, embodiments of this application provide a firmware differential device, the device comprising: The acquisition module is used to acquire the pre-difference packet, which is generated based on the firmware to be upgraded and the firmware to be upgraded. The pre-difference packet includes control data, difference data and update data. The construction module is used to construct a similar data block range list based on the control data, difference data, and update data. The similar data block range list is used to characterize the mapping relationship between the firmware to be upgraded and the firmware that has been upgraded. The identification module is used to identify jump instructions in the data before the firmware upgrade and the data after the firmware upgrade in the similar data block range list, and generate an initial mapping table. The initial mapping table is used to represent address pairs with consistent jump address pairs, including the estimated jump instruction to be upgraded and the jump instruction of the firmware upgrade. The filtering module is used to filter the initial mapping table according to a preset counting threshold to obtain the final mapping table; The generation module is used to generate the final difference package based on the final mapping table, the control data, the difference data, and the update data.
[0014] In another aspect, embodiments of this application provide an electronic device, the device comprising: a processor and a memory storing computer program instructions; When the processor executes the computer program instructions, it implements the firmware differential method as described in the first aspect.
[0015] In another aspect, embodiments of this application provide a computer storage medium on which computer program instructions are stored, which, when executed by a processor, implement the firmware differential method as described in the first aspect.
[0016] In another aspect, embodiments of this application provide a computer program product in which instructions, when executed by a processor of an electronic device, cause the electronic device to perform the firmware differential method as described in the first aspect.
[0017] The firmware differential method, apparatus, device, medium, and product of this application embodiment first perform pre-differentiation on the firmware to be upgraded and the firmware to be upgraded, obtaining a pre-differentiation packet. Then, a similar data block range list is constructed based on the control data, difference data, and update data in the pre-differentiation packet to map the relationship between the firmware to be upgraded and the firmware to be upgraded. Instruction identification and parsing are performed on the similar data block range list without disassembly and full firmware parsing, which can reduce differential time. At the same time, filtering and screening are performed through preset technical thresholds to ensure that the generated final mapping table is unique and to ensure the accuracy of the restoration process. This ensures that the generated final differential packet data has high compression and small size, which can improve transmission efficiency. Attached Figure Description
[0018] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 This is a flowchart illustrating a firmware differential method provided in one embodiment of this application; Figure 2 This is a schematic diagram of a list of similar data block ranges provided in one embodiment of this application; Figure 3 This is a flowchart illustrating a firmware differential method provided in another embodiment of this application; Figure 4 This is a flowchart illustrating a firmware differential method provided in another embodiment of this application; Figure 5 This is a flowchart illustrating a firmware differential method provided in another embodiment of this application; Figure 6 This is a flowchart illustrating a firmware differential method provided in another embodiment of this application; Figure 7 This is a flowchart illustrating a firmware differential method provided in another embodiment of this application; Figure 8 This is a schematic diagram of the firmware differential device provided in another embodiment of this application; Figure 9 This is a schematic diagram of the structure of an electronic device provided in another embodiment of this application. Detailed Implementation
[0020] The features and exemplary embodiments of various aspects of this application will be described in detail below. To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain this application and not to limit it. For those skilled in the art, this application can be implemented without some of these specific details. The following description of the embodiments is merely to provide a better understanding of this application by illustrating examples.
[0021] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising..." does not exclude the presence of additional identical elements in the process, method, article, or apparatus that includes said element.
[0022] To address the problems of existing technologies, embodiments of this application provide a firmware differential method, apparatus, device, medium, and product. In this embodiment, pre-differentiation is first performed on the firmware to be upgraded and the firmware to be upgraded, resulting in a pre-differentiation packet. Then, a similar data block range list is constructed based on the control data, difference data, and update data in the pre-differentiation packet to map the relationship between the firmware to be upgraded and the firmware to be upgraded. Instruction identification and parsing are performed on the similar data block range list without disassembly and full firmware parsing, reducing differential time. Simultaneously, filtering and selection are performed using preset technical thresholds to ensure the uniqueness of the generated final mapping table, guaranteeing the accuracy of the restoration process. This ensures high compression and small size of the generated final differential packet data, improving transmission efficiency.
[0023] The firmware differential method provided in the embodiments of this application will be introduced first below.
[0024] Figure 1 A flowchart illustrating a firmware differential method provided in one embodiment of this application is shown. Figure 1 As shown, the firmware differential method may include S101-S105: S101, Obtain the pre-difference package.
[0025] In some embodiments, for firmware updates and upgrades, the common differential algorithm bsdiff can be used to generate a pre-difference package from the firmware to be upgraded and the firmware to be upgraded. The pre-difference package is generated based on the firmware to be upgraded and the firmware to be upgraded, and includes control data, difference data and update data.
[0026] In some embodiments, the control data may include multiple sets of overlay lines. Each set of overlay lines may include similar data length ctrl[i][0], update data length ctrl[i][1], and the offset of the next set of firmware to be upgraded ctrl[i][2], where i represents the i-th overlay line.
[0027] S102, Based on control data, difference data, and update data, construct a list of similar data block ranges.
[0028] In some embodiments, the list of similar data block ranges generated from the control data, difference data, and update data described above can be found here. Figure 2 The list of similar data block ranges is used to characterize the mapping relationship between the firmware to be upgraded and the firmware that has been upgraded.
[0029] As an example, a list of similar data block ranges can be expressed using the following expression: old_pos_start[i]=sum(ctrl[k][0]+ctrl[k][2],k=0,...,i-1), old_pos_end[i]=old_pos_start[i]+ctrl[i][0], new_pos_start[i]=sum(ctrl[k][0]+ctrl[k][1],k=0,...,i-1) new_pos_end[i]=new_pos_start[i]+ctrl[i][0].
[0030] Wherein, old_pos_start[i]: the starting position of the i-th similar block in the old file; old_pos_end[i]: the ending position of the i-th similar block in the old file; new_pos_start[i]: the starting position of the i-th similar block in the new file; new_pos_end[i]: the ending position of the i-th similar block in the new file.
[0031] S103, identify jump instructions for the pre-update data of the firmware to be upgraded and the post-update data of the firmware after the upgrade in the similar data block range list, and generate an initial mapping table.
[0032] In some embodiments, the initial mapping table is used to characterize address pairs that match the jump address pair, which includes the estimated jump instruction to be upgraded and the jump instruction to complete the firmware upgrade. This provides the basis for subsequent jump addresses.
[0033] S104. Filter the initial mapping table according to the preset counting threshold to obtain the final mapping table.
[0034] In this embodiment, a threshold method can be used for filtering to ensure the uniqueness of jump address pairs and to highly compress the amount of data.
[0035] S105, based on the final mapping table, control data, difference data, and update data, generates the final difference package.
[0036] In this embodiment, the firmware to be upgraded and the firmware to be upgraded are first pre-differentialized to obtain a pre-differential packet. Then, a similar data block range list is constructed based on the control data, difference data, and update data in the pre-differential packet to map the relationship between the firmware to be upgraded and the firmware to be upgraded. Instruction identification and parsing are performed on the similar data block range list without disassembly and full firmware parsing, which can reduce the differential time. At the same time, filtering and screening are performed through preset technical thresholds to ensure that the generated final mapping table is unique and to ensure the accuracy of the restoration process. This ensures that the generated final differential packet data has high compression and small size, which can improve transmission efficiency.
[0037] In some embodiments, the list of similar data block ranges includes the start position and corresponding end position of the firmware to be upgraded, and the start position and corresponding end position of the firmware to be upgraded; S103 may include: The list of similar data blocks is traversed, and the jump instruction is identified from the starting position of the firmware to be upgraded according to the first preset number of bytes to obtain the first identification result. If the first identification result is that the jump instruction is successfully identified, the first instruction location and the first jump address are determined based on the first current location of the firmware to be upgraded; Based on the first instruction position, jump instructions are identified from the position where the firmware upgrade is completed according to the first preset number of bytes to obtain the second identification result; If the second identification result indicates that the jump instruction has been successfully identified, the second instruction position and the second jump position are determined based on the second current position after the firmware upgrade is completed. An initial mapping table is generated based on the first instruction location, the first jump address, the second instruction location, and the second jump location. In this embodiment, the data before and after the update corresponding to the similar data block range list are iterated by byte for instruction identification. After obtaining the jump address pairs, the similar data block range list can be traversed. Starting from the jump start position of the firmware to be upgraded, the jump instruction is identified according to a first preset number of bytes to obtain the first identification result. The first preset number of bytes can be 4 bytes. The jump instruction identification method can specifically adopt the computer's internal identification method, that is, each firmware has a corresponding jump instruction such as the jmp instruction. It is only necessary to identify the corresponding instruction in the similar data block range list to achieve successful identification. If it is not the jump instruction, it means that the identification has failed.
[0038] If the first identification result indicates successful recognition of the jump instruction, the jump address can be parsed. This parsing method is the same as the firmware's parsing method and is not limited here. If the jump instruction is successfully recognized, the first instruction position and the first jump address can be determined based on the first current position of the firmware to be upgraded. That is, the current position in the similar data block range list is used as the first instruction position and the first jump position. Since the above similar data block range list is generated based on the firmware to be upgraded and the firmware to be upgraded, after obtaining the first instruction position and the first jump position, the second instruction position and the second jump position of the firmware to be upgraded can be determined from the second current position of the firmware to be upgraded based on the first instruction position and the first jump position. At this time, an initial mapping table can be generated based on the first instruction position, the first jump address, the second instruction position, and the second jump position.
[0039] As a concrete example, the list of similar data block ranges is traversed. Starting from `old_pos_start`, 4 bytes are taken for jump instruction identification. If identification fails, both the firmware to be upgraded and the firmware that has been upgraded are shifted forward by 2 bytes to continue the loop. If identification succeeds, the jump address is parsed, resulting in the instruction position `oldpos` and the jump address `oldjmp`. Then, 4 bytes are taken from the position `newpos(oldpos+(new_pos_start[i]-old_pos_start[i]))` of the firmware that has been upgraded, corresponding to `oldpos`, for jump instruction identification. If identification succeeds, the jump address is parsed. Combining this with the previous information, ...<oldpos,newpos,oldjmp,newjmp> Store in the initial mapping table.
[0040] In other embodiments, the jump instruction recognition may fail because there may be cases where the jump instruction is not actually a jump instruction. It may also fail due to misalignment during the generation of the similar data block range list, or because corresponding code has been added or deleted after an update. Therefore, if the second result is that the jump instruction recognition fails, the method further includes: For each first instruction position, first jump position, and second instruction position, multiple exception mapping sets are constructed based on the first instruction position, first jump position, and second instruction position; In this embodiment, the code that fails to be identified can be stored in an exception mapping table, and multiple exception mapping sets can be constructed based on the first instruction position, the first jump position, and the second instruction position. Through these multiple exception mapping sets, an exception mapping table can be constructed to highlight the differences.
[0041] In other embodiments, if the first identification result is that the jump instruction identification fails, the system traverses by shifting backward by a second preset number of bytes until the first identification result is that the jump instruction identification succeeds.
[0042] In this embodiment, during the process of identifying the jump instruction according to the first preset number of bytes from the jump start position of the firmware to be upgraded and obtaining the first identification result, there may be other instructions. At this time, the jump instruction can be identified by offsetting by 2 bytes until the jump instruction is identified, so as to identify all instructions in the similar data block range list.
[0043] It is worth noting that because the thumb2 and riscv instruction sets contain instructions of 2-byte and 4-byte lengths, the traversal of firmware data needs to be offset by 2 bytes; while the jump instructions that need to be identified are all 4-byte long. Therefore, after the firmware to be upgraded identifies the jump instruction, it needs to be offset by 4 bytes next time. Among them, the thumb2 and riscv instructions are traversal instructions.
[0044] The traversal is based on the data before the firmware update because the device only has the old firmware during firmware restoration. The restoration phase is also traversed according to the range of similar blocks. If a jump instruction is detected, it is processed; otherwise, it is offset by 2 bytes and continues.
[0045] In other embodiments, if the old firmware is a jump instruction (i.e., the firmware to be upgraded is a jump instruction) and the new firmware is a non-jump instruction (i.e., the upgrade completion instruction is a non-jump instruction), then the jump address pair can be recorded in the anomaly mapping table to facilitate anomaly finding for the user.
[0046] In some embodiments, in order to compress the data size of the final differential packet, the method may further include, before S104: Generate a jump address pair based on the first jump position and the second jump position; Count the first number of each jump address pair; The initial mapping table is filtered according to a preset counting threshold to obtain the final mapping table, which includes: Based on the first quantity and the preset counting threshold, the jump address pairs in the initial mapping table are filtered to obtain the target jump address pairs; The final mapping table is generated based on the target jump address pair.
[0047] In this embodiment, in order to ensure the uniqueness of the initial mapping table, a preset counting threshold can be used to filter the initial mapping table. Entries with a first count greater than the first preset threshold are retained, while those with a first count less than the first preset threshold are moved to the abnormal mapping table, thus ensuring the uniqueness of the jump address pairs in the initial mapping table.
[0048] Specifically, jump address pairs can be generated based on the first jump position and the second jump position. The number of each jump address pair is counted to obtain the first number. Then, the first number can be compared with a preset counting threshold to filter out the target jump address pairs from the initial mapping table. The target jump address pairs include jump address pairs whose first number is greater than the preset counting threshold.
[0049] In this embodiment, since each jump address pair in the initial mapping table occupies 8 bytes, and optimizing the matching of similar data blocks using mapping table entries is expected to save 2-4 bytes of space each time, a preset counting threshold of 3 is generally used. If it is desired to reduce the number of entries in the final mapping table, a larger threshold can be used. Entries in the initial mapping table with a count greater than 3 are deleted and moved to the abnormal mapping table.
[0050] In some other embodiments, the method further includes generating the final mapping table based on the target jump address pairs: The initial mapping table is traversed, and the first jump position in the initial mapping table is compared to obtain the comparison result. If the comparison result includes the existence of at least two jump address pairs with the same first jump position, compare the first number of the at least two jump address pairs and delete the jump address corresponding to the smallest first number from the initial mapping table.
[0051] In this embodiment, the initial mapping table may contain at least two entries with the same first jump address but different second jump addresses. Since the restoration phase requires the old firmware to find the corresponding second jump address after instruction recognition and parsing to the first jump position, a one-to-many situation would lead to abnormal matching. Therefore, it is necessary to ensure that the mapping table has only one-to-one entries. The initial mapping table is traversed, and the first jump address of each entry is compared. If an entry with the same first jump address is found, the first number is compared, and the entry with the smaller first number is deleted and added to the abnormal mapping table. This results in an initial mapping table without duplicate first jump addresses. Finally, the initial mapping table is...<oldjmp, newjmp> Generate a two-dimensional array to obtain the final mapping table.
[0052] After the above filtering, the final mapping table is relatively small. Generally, an 8M firmware has 4,000 entries. The final mapping table is sorted according to the size of the first jump position to obtain a two-dimensional array of the final mapping table, which facilitates subsequent restoration and transmission.
[0053] See Figure 3 As a specific example, Figure 3 This diagram illustrates the process of generating the initial mapping table and the exception mapping table. The method may include: S301, begin traversing the list of similar data block ranges; S302: Recognition of firmware upgrade jump command. If recognition fails, proceed to S303. If recognition succeeds, proceed to S304. S303, complete the firmware upgrade and the offset of the firmware to be upgraded by 2 bytes, return to S302; S304, obtain the first jump address and the first instruction address; S305: Successfully identify the firmware upgrade jump command. If identification is successful, proceed to S306; otherwise, proceed to S307. S306, store the first jump address, the first instruction address, the second jump address, and the second instruction address into the initial mapping table; S307, store the first jump address, the first instruction address and the second instruction address into the exception mapping table; S308, complete the firmware upgrade and the offset of the firmware to be upgraded by 4 bytes, and return to S302.
[0054] In some other embodiments, in order to improve the data compression rate and actually reduce the size of the final differential packet, the method may further include, before S105: Obtain the firmware location corresponding to the jump address in the initial mapping table; Set the difference data corresponding to the firmware location to 0 to obtain new difference data; S105 may include: The final difference package is generated based on the final mapping table, control data, new difference data, and updated data.
[0055] In this embodiment, the jump address in the initial mapping table can be obtained for a male firmware position, and the difference data corresponding to the firmware position can be set to 0. This indicates that the corresponding difference data is consistent for the firmware that has been upgraded and the firmware to be upgraded, and no changes are needed. In addition, since this part can be recovered in the restoration stage by recognizing jump instructions and generating new instructions, this part of the data does not need to be saved in the difference data, thereby reducing the size of the final differential packet and improving the data compression rate.
[0056] As an example, see Figure 4 , Figure 4 The flowchart shows the process of setting the difference data corresponding to the firmware position to 0 to obtain new difference data, which will not be described in detail here.
[0057] See Figure 5 The final process for creating the differential package is as follows: Figure 5 As shown, firmware differential methods may include: S501 uses the diff algorithm to perform differential analysis on the upgraded firmware V1.bin and the firmware to be upgraded V0.bin to obtain control data, diff data, and extra data.
[0058] S502, traverse the control data to obtain the initial mapping table gen jmp list; S503 obtains the jump address list jmp list and the instruction address list pos list through the initial mapping table; S504 generates the final mapping table rebuild diff data based on control data, diff data, extra data, and instruction address list; S505 generates the final differential packet based on the final mapping table.
[0059] In some other embodiments, after the terminal corresponding to the firmware to be upgraded receives the final differential packet, the terminal needs to restore the final differential packet. Therefore, after S105, the method may include: For the target firmware to be upgraded, the final differential packet is parsed to determine the list of similar data block ranges and the final mapping table. Based on the range of similar data blocks, the target firmware to be upgraded is identified by byte traversal to obtain the third identification result; If the third identification result indicates that the jump instruction has been successfully identified, obtain the target jump address and the target instruction location; If the final mapping table includes the target jump address, differential packet reconstruction is performed based on the target jump address and the target instruction location to obtain the reconstructed packet; The target firmware to be upgraded is upgraded based on the restore package to obtain the final firmware.
[0060] In this embodiment, the final differential packet contains four parts: control data (CD), similarity data difference (DD), new data (ND), and mapping table (LJM). The control data stores multiple sets of coverage lines. Each set of coverage lines includes: similar data length ctrl[i][0], new data length ctrl[i][1], and the offset of the next set of old firmware positions ctrl[i][2], where i represents the i-th coverage line.
[0061] Similar to the final differential packet creation process, a list of similar data block ranges between the old and new firmware is constructed using the data above: old_pos_start[i]=sum(ctrl[k][0]+ctrl[k][2], k=0,...,i-1), old_pos_end[i]=old_pos_start[i]+ctrl[i][0], new_pos_start[i]=sum(ctrl[k][0]+ctrl[k][1],k=0,...,i-1), new_pos_end[i]=new_pos_start[i]+ctrl[i][0].
[0062] Then, based on the list of similar data block ranges, the jump instruction identification is performed by byte-by-byte traversal of the data before the update. If identification fails, the firmware will be upgraded and the loop will continue by shifting 2 bytes forward. If identification is successful, the first jump address oldjmp and the first instruction position oldpos are obtained. The jump address oldjmp is searched in the final mapping table. If it appears in the final mapping table, it means that the difference data corresponding to this instruction has been set to 0. The final instruction needs to be obtained by calculation. The jump address pair <first jump address, second jump address> is retrieved from the final mapping table. The second instruction address newpos corresponding to this jump instruction is calculated using the list of similar data block ranges: newpos = oldpos + (new_pos_start[i] - old_pos_start[i]). Then, the new jump instruction new instruction is calculated using the second instruction address newpos and the second jump address newjmp and saved to the new instruction replacement list NIRL:{<newpos,newins> If the first jump address oldjmp fails to find the address in the final mapping table, shift 4 bytes forward and continue the loop.
[0063] As a concrete example, see Figure 6 The restoration process is as follows: S601, begin traversing the list of similar data block ranges; S602, the firmware to be upgraded will identify the jump command. If the identification fails, it will jump to S603. If the identification is successful, it will jump to S604. S603, firmware to be upgraded is offset by 2 bytes, then transferred to S602; S604, search for the first jump address in the final mapping table. If the search is successful, proceed to S605; if the search fails, proceed to S607. S605, calculates the new instruction replacement list; S606, restore based on the new instruction replacement list; S607, firmware to be upgraded is offset by 4 bytes, and then transferred to S602.
[0064] In this embodiment, the conventional restoration algorithm bsdiff can be used, which will not be elaborated further here.
[0065] Because the difference in similar data was set to 0 during the creation of the differential package, the instructions in a specific part of the restored primary new firmware are still the original instructions from the old firmware. Therefore, these need to be replaced with new instructions. The new instruction replacement list is iterated through to obtain each new replacement instruction.<newpos,newins> The system locates the newpos of the initial new firmware, replaces oldins with newins at that location, and obtains the final new firmware, thus ending the restoration process.
[0066] See Figure 7 As a specific example, the restoration process is as follows: S701, performs data parsing on the final differential packet to obtain differential data, additional data, control data, and jump list; S702, Generate a new insertion list based on the jump list and control data; S703 generates patch files based on the newly inserted list, firmware to be upgraded, difference data, additional data, and control data; S704, determine the replacement insertion item based on the patch file and the new insertion list; S705, based on the replacement insertion item, completes the upgrade of the target firmware to be upgraded, and obtains the final firmware.
[0067] Based on the firmware differential method provided in the above embodiments, this application also provides specific implementations of the firmware differential device. Please refer to the following embodiments.
[0068] First see Figure 8 The firmware differential device 800 provided in this application embodiment may include: The acquisition module 801 is used to acquire the pre-difference packet. The pre-difference packet is generated based on the firmware to be upgraded and the firmware to be upgraded. The pre-difference packet includes control data, difference data and update data. The construction module 802 is used to construct a similar data block range list based on control data, difference data, and update data. The similar data block range list is used to characterize the mapping relationship between the firmware to be upgraded and the firmware that has been upgraded. The identification module 803 is used to identify jump instructions in the data before the firmware upgrade and the data after the firmware upgrade in the similar data block range list, and generate an initial mapping table. The initial mapping table is used to represent address pairs with consistent jump address pairs, including the estimated jump instruction to be upgraded and the jump instruction of the firmware upgrade. The filtering module 804 is used to filter the initial mapping table according to a preset counting threshold to obtain the final mapping table; The generation module 805 is used to generate the final difference package based on the final mapping table, control data, difference data, and update data.
[0069] As an optional implementation, the generation module 805 can also be used for: Obtain the firmware location corresponding to the jump address in the initial mapping table; Set the difference data corresponding to the firmware location to 0 to obtain new difference data; Based on the final mapping table, control data, difference data, and update data, the final difference package is generated, including: The final difference package is generated based on the final mapping table, control data, new difference data, and updated data.
[0070] As an optional implementation, the list of similar data block ranges includes the start position of the firmware to be upgraded and its corresponding end position, as well as the start position of the firmware to be upgraded and its corresponding end position. The recognition module 803 can also be used for: Jump instruction identification is performed on the pre-update data and post-update data of the firmware to be upgraded in the similar data block range list to generate an initial mapping table, including: The list of similar data blocks is traversed, and the jump instruction is identified from the starting position of the firmware to be upgraded according to the first preset number of bytes to obtain the first identification result. If the first identification result is that the jump instruction is successfully identified, the first instruction location and the first jump address are determined based on the first current location of the firmware to be upgraded; Based on the first instruction position, jump instructions are identified from the position where the firmware upgrade is completed according to the first preset number of bytes to obtain the second identification result; If the second identification result indicates that the jump instruction has been successfully identified, the second instruction position and the second jump position are determined based on the second current position after the firmware upgrade is completed. An initial mapping table is generated based on the first instruction location, the first jump address, the second instruction location, and the second jump location.
[0071] As an optional implementation, if the second result is that the jump instruction recognition fails, the recognition module 803 can also be used to: For each first instruction position, first jump position, and second instruction position, multiple exception mapping sets are constructed based on the first instruction position, first jump position, and second instruction position; An exception mapping table is generated based on multiple exception mapping sets.
[0072] As an alternative implementation, the identification module 803 can also be used for: If the first recognition result is that the jump instruction recognition failed, the system will traverse forward by the second preset number of bytes until the first recognition result is that the jump instruction recognition was successful.
[0073] As an alternative implementation, the filtering module 804 can also be used for: Generate a jump address pair based on the first jump position and the second jump position; Count the first number of each jump address pair; The initial mapping table is filtered according to a preset counting threshold to obtain the final mapping table, which includes: Based on the first quantity and the preset counting threshold, the jump address pairs in the initial mapping table are filtered to obtain the target jump address pairs. The target jump address pairs include jump address pairs whose first quantity is greater than the preset counting threshold. The final mapping table is generated based on the target jump address pair.
[0074] As an alternative implementation, the filtering module 804 can also be used for: The initial mapping table is traversed, and the first jump position in the initial mapping table is compared to obtain the comparison result. If the comparison result includes the existence of at least two jump address pairs with the same first jump position, compare the first number of the at least two jump address pairs and delete the jump address corresponding to the smallest first number from the initial mapping table.
[0075] As an alternative implementation, the generation module 805 can also be used for: For the target firmware to be upgraded, the final differential packet is parsed to determine the list of similar data block ranges and the final mapping table. Based on the range of similar data blocks, the target firmware to be upgraded is identified by byte traversal to obtain the third identification result; If the third identification result indicates that the jump instruction has been successfully identified, obtain the target jump address and the target instruction location; If the final mapping table includes the target jump address, differential packet reconstruction is performed based on the target jump address and the target instruction location to obtain the reconstructed packet; The target firmware to be upgraded is upgraded based on the restore package to obtain the final firmware.
[0076] Figure 9 A schematic diagram of the hardware structure of the electronic device provided in an embodiment of this application is shown.
[0077] An electronic device may include a processor 901 and a memory 502 storing computer program instructions.
[0078] Specifically, the processor 901 may include a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits that can be configured to implement the embodiments of this application.
[0079] Memory 902 may include mass storage for data or instructions. For example, and not limitingly, memory 902 may include a hard disk drive (HDD), floppy disk drive, flash memory, optical disk, magneto-optical disk, magnetic tape, or Universal Serial Bus (USB) drive, or a combination of two or more of these. In one instance, memory 902 may include removable or non-removable (or fixed) media, or memory 902 may be non-volatile solid-state memory. Memory 902 may be internal or external to the integrated gateway disaster recovery device.
[0080] In one instance, memory 902 may be read-only memory (ROM). In one instance, the ROM may be a mask-programmed ROM, a programmable ROM (PROM), an erasable PROM (EPROM), an electrically erasable PROM (EEPROM), an electrically rewritable ROM (EAROM), or flash memory, or a combination of two or more of these.
[0081] Memory 902 may include read-only memory (ROM), random access memory (RAM), disk storage media device, optical storage media device, flash memory device, electrical, optical, or other physical / tangible memory storage device. Therefore, typically, memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the firmware differential method according to the first aspect of this disclosure.
[0082] The processor 901 reads and executes computer program instructions stored in the memory 902 to achieve... Figure 1 A firmware differential method is shown in the embodiment.
[0083] In one example, the electronic device may also include a communication interface 903 and a bus 904. For example, Figure 9 As shown, the processor 901, memory 902, and communication interface 903 are connected through bus 904 and complete communication with each other.
[0084] The communication interface 903 is mainly used to realize communication between various modules, devices, units and / or equipment in the embodiments of this application.
[0085] Bus 904 includes hardware, software, or both, that couples components of an electronic device together. For example, and not limitingly, the bus may include an Accelerated Graphics Port (AGP) or other graphics bus, an Extended Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a Hyper Transport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an Infinite Bandwidth Interconnect, a Low Pin Count (LPC) bus, a memory bus, a Microchannel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local (VLB) bus, or other suitable buses, or combinations of two or more of these. Where appropriate, bus 504 may include one or more buses. Although specific buses are described and illustrated in embodiments of this application, this application contemplates any suitable bus or interconnect.
[0086] The electronic device can execute the firmware differential method in the embodiments of this application, thereby achieving the combination Figures 1-8 The firmware differential method and apparatus described herein.
[0087] Furthermore, in conjunction with the firmware differential methods in the above embodiments, this application embodiment can provide a computer storage medium for implementation. This computer storage medium stores computer program instructions; when these computer program instructions are executed by a processor, they implement any of the firmware differential methods in the above embodiments.
[0088] In an optional embodiment, in conjunction with the firmware differential method in the above embodiments, this application embodiment can provide a computer program product to implement it. The instructions in the computer program product are executed by the processor of the electronic device, enabling the electronic device to implement any of the firmware differential methods in the above embodiments.
[0089] It should be clarified that this application is not limited to the specific configurations and processes described above and shown in the figures. For the sake of brevity, detailed descriptions of known methods are omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of this application is not limited to the specific steps described and shown. Those skilled in the art can make various changes, modifications, and additions, or change the order of steps, after understanding the spirit of this application.
[0090] The functional blocks shown in the above block diagram can be implemented as hardware, software, firmware, or a combination thereof. When implemented in hardware, they can be, for example, electronic circuits, application-specific integrated circuits (ASICs), appropriate firmware, plug-ins, function cards, etc. When implemented in software, the elements of this application are programs or code segments used to perform the required tasks. Programs or code segments can be stored on a machine-readable medium or transmitted over a transmission medium or communication link via data signals carried on a carrier wave. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, fiber optic media, radio frequency (RF) links, etc. Code segments can be downloaded via computer networks such as the Internet, intranets, etc.
[0091] It should also be noted that the exemplary embodiments mentioned in this application describe methods or systems based on a series of steps or apparatus. However, this application is not limited to the order of the above steps; that is, the steps can be performed in the order mentioned in the embodiments, or in a different order, or several steps can be performed simultaneously.
[0092] The aspects of this disclosure have been described above with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It should be understood that each block in the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus to produce a machine such that these instructions, executable via the processor of the computer or other programmable data processing apparatus, enable the implementation of the functions / actions specified in one or more blocks of the flowchart illustrations and / or block diagrams. Such a processor can be, but is not limited to, a general-purpose processor, a special-purpose processor, a special application processor, or a field-programmable logic circuit. It is also understood that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can also be implemented by special-purpose hardware performing the specified functions or actions, or can be implemented by a combination of special-purpose hardware and computer instructions.
[0093] The above description is merely a specific implementation of this application. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, modules, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. It should be understood that the protection scope of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the protection scope of this application.
Claims
1. A firmware differential method, characterized by, The method comprises the following steps: obtaining a pre-differential package, the pre-differential package being generated based on a firmware to be upgraded and a firmware after upgrading, the pre-differential package comprising control data, difference data and update data; constructing a similar data block range list based on the control data, the difference data and the update data, the similar data block range list being used to represent a mapping relationship between the firmware to be upgraded and the firmware after upgrading; performing jump instruction identification on the pre-update data of the firmware to be upgraded and the post-update data of the firmware after upgrading in the similar data block range list to generate an initial mapping table, the initial mapping table being used to represent a consistent address pair of a jump address pair, the jump address pair comprising a jump instruction of the firmware to be upgraded and a jump instruction of the firmware after upgrading; screening the initial mapping table according to a pre-designed number threshold to obtain a final mapping table; generating a final differential package based on the final mapping table, the control data, the difference data and the update data.
2. The method of claim 1, wherein, Before the step of generating the final differential package based on the final mapping table, the control data, the difference data and the update data, the method further comprises the following steps: obtaining a firmware position corresponding to the jump address in the initial mapping table; setting the difference data corresponding to the firmware position to 0 to obtain new difference data; the step of generating the final differential package based on the final mapping table, the control data, the difference data and the update data comprises the following step: generating the final differential package based on the final mapping table, the control data, the new difference data and the update data.
3. The method of claim 1, wherein, The similar data block range list comprises a jump start position and a corresponding end position of the firmware to be upgraded, and a jump start position and a corresponding end position of the firmware after upgrading; the step of performing jump instruction identification on the pre-update data of the firmware to be upgraded and the post-update data of the firmware after upgrading in the similar data block range list to generate an initial mapping table comprises the following steps: performing jump instruction identification on the jump start position of the firmware to be upgraded according to a first preset byte number to obtain a first identification result; in a case where the first identification result is a successful jump instruction identification, determining a first instruction position and a first jump address based on a first current position of the firmware to be upgraded; performing jump instruction identification on the jump start position of the firmware after upgrading based on the first instruction position according to the first preset byte number to obtain a second identification result; in a case where the second identification result is a successful jump instruction identification, determining a second instruction position and a second jump position based on a second current position of the firmware after upgrading; generating the initial mapping table based on the first instruction position, the first jump address, the second instruction position and the second jump position.
4. The method of claim 3, wherein, in a case where the second result is a failed jump instruction identification, the method further comprises the following steps: for each of the first instruction position, the first jump position and the second instruction position, constructing a plurality of abnormal mapping sets based on the first instruction position, the first jump position and the second instruction position; generating an abnormal mapping table based on the plurality of abnormal mapping sets.
5. The method of claim 3, wherein, In a case where the first identification result is a jump instruction identification failure, traversing is performed in a backward direction by a second preset byte quantity until the first identification result is a jump instruction identification success.
6. The method of claim 3, wherein, Before the initial mapping table is filtered according to the preset design quantity threshold to obtain the final mapping table, the method further includes: generating a jump address pair based on the first jump position and the second jump position; counting a first quantity of each jump address pair; the filtering of the initial mapping table according to the preset design quantity threshold to obtain the final mapping table includes: filtering the jump address pairs in the initial mapping table based on the first quantity and the preset design quantity threshold to obtain a target jump address pair, the target jump address pair including the jump address pairs with the first quantity greater than the preset design quantity threshold; generating the final mapping table based on the target jump address pair.
7. The method of claim 6, wherein, Before the final mapping table is generated based on the target jump address pair, the method further includes: traversing the initial mapping table, and comparing the first jump positions in the initial mapping table to obtain a comparison result; in a case where the comparison result includes at least two jump address pairs with the same first jump position, comparing the first quantities of the at least two jump address pairs, and deleting the jump address corresponding to the smallest first quantity from the initial mapping table.
8. The method of claim 1, wherein, After the final difference package is generated based on the final mapping table, the control data, the difference value data and the new data, the method further includes: performing data analysis on the final difference package to determine a similar data block range list and a final mapping table for a target firmware to be upgraded; performing jump instruction identification on the target firmware to be upgraded according to byte traversal based on the similar data block range to obtain a third identification result; in a case where the third identification result is a jump instruction identification success, obtaining a target jump address and a target instruction position; in a case where the final mapping table includes the target jump address, performing difference package restoration based on the target jump address and the target instruction position to obtain a restored package; upgrading the target firmware to be upgraded based on the restored package to obtain a final firmware.
9. A firmware differential apparatus, characterized by, The device includes: an acquisition module configured to acquire a pre-difference package, the pre-difference package being generated based on a firmware to be upgraded and a completed upgraded firmware, the pre-difference package including control data, difference value data and update data; a construction module configured to construct a similar data block range list based on the control data, the difference value data and the update data, the similar data block range list being used to represent a mapping relationship between the firmware to be upgraded and the completed upgraded firmware; an identification module configured to perform jump instruction identification on pre-update data of the firmware to be upgraded and post-update data of the completed upgraded firmware in the similar data block range list to generate an initial mapping table, the initial mapping table being used to represent address pairs with consistent jump address pairs, the jump address pairs including jump instructions of the firmware to be upgraded and jump instructions of the completed upgraded firmware; a filtering module configured to filter the initial mapping table according to a preset design quantity threshold to obtain a final mapping table; A generating module is configured to generate a final difference package based on the final mapping table, the control data, the difference data and the update data.
10. An electronic device, comprising: The device comprises a processor and a memory storing computer program instructions; The processor executes the computer program instructions to implement the firmware difference method in any one of claims 1-8.
11. A computer readable storage medium, characterized in that, The computer readable storage medium stores computer program instructions, and the computer program instructions are executed by the processor to implement the firmware difference method in any one of claims 1-8.
12. A computer program product, characterised in that, The instructions in the computer program product are executed by the processor of the electronic device to enable the electronic device to perform the firmware difference method in any one of claims 1-8.