A method and device for generating a block differential upgrade package and block differential upgrade
The block differential upgrade package method efficiently addresses the high storage resource demands of existing firmware upgrade methods by splitting and sequencing upgrade blocks, minimizing storage needs and enabling efficient firmware upgrades.
Patent Information
- Application Number
- CN202211497718.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-25
- Publication Date
- 2025-07-15
- Estimated Expiration
- 2042-11-25
AI Technical Summary
The existing differential upgrade method has a large demand for hardware storage resources, especially the high requirements for flash space, which cannot be effectively solved.
By blocking the entire differential package of the upgrade source firmware and the target upgrade firmware, a very small differential upgrade package is generated, and the block control information and upgrade sequence are used to upgrade, reducing dependence on hardware storage resources.
It realizes that without relying on the source firmware and target firmware size, the requirements for hardware storage resources in the upgrade process, especially the flash space requirements, and improves the upgrade efficiency.
Smart Images

Figure CN115718614B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of firmware upgrade, and particularly to a method and device for generating a block differential upgrade package and block differential upgrade. Background Art
[0002] There are two main methods for current firmware upgrade, called Class A and Class B. Among them: The method of Class A upgrade is to download the target upgrade firmware from the host computer or platform to the device side at the device side, and the device side directly starts and runs the target upgrade firmware, which is called copy upgrade; The method of Class B upgrade is to first make an upgrade patch on the platform or host computer, and the device side downloads the upgrade patch from the host computer or platform side. After the download is completed, the target upgrade firmware is restored according to the upgrade patch and the original file, which is called differential upgrade.
[0003] The disadvantages of the Class A upgrade method include: The download process takes a long time, and it is necessary to download the entire target file. When the network coverage is poor or the bandwidth is limited, the download time is long, and the stability of a single full download is poor; The upgrade process has high requirements for hardware resources, and it is required that the flash space on the device side has at least twice the firmware storage space. The currently disclosed solutions of the Class B upgrade method can partially overcome the deficiency of "long download process time" in the Class A method, but do not solve the deficiency of "high requirements for hardware resources". Through special compression methods, the dependence on the size of the ram space can be reduced, but the problem of high requirements for the flash space is not solved. Summary of the Invention
[0004] Therefore, the technical problem to be solved by the present invention is to overcome the defect of high requirements for hardware storage resources in the existing differential upgrade method, so as to provide a method and device for generating a block differential upgrade package and block differential upgrade.
[0005] According to a first aspect, an embodiment of the present invention discloses a method for generating a differential upgrade package by blocks, including: obtaining a source firmware and a target upgrade firmware of a firmware to be upgraded; calculating a full differential package of the source firmware and the target upgrade firmware, where the full differential package includes control information, differential information, and unique information; performing block processing on the source firmware data and the target upgrade firmware data according to a target block size to obtain a plurality of block data of the source firmware and a plurality of block data of the target upgrade firmware, where each block data of the source firmware includes a corresponding block identifier, and each block data of the target upgrade firmware includes a corresponding block identifier; obtaining a plurality of control triple commands in the control information, where each control triple command includes first control information and second control information, the first control information represents the same information and differential information between the source firmware and the target upgrade firmware, and the second control information represents the unique information of the target upgrade firmware; decomposing each first control information according to the identifier corresponding to each block of the target upgrade firmware, the identifier corresponding to each block of the source firmware, the target block size, and an operation step length to obtain third control information corresponding to each block of the target upgrade firmware, where the third control information represents the same information and differential information in each block of the target upgrade firmware and the corresponding block of the source firmware; decomposing each second control information according to the block identifier corresponding to each block data of the target upgrade firmware, the target block size, and the operation step length to obtain fourth control information corresponding to each block of the target upgrade firmware, where the fourth control information is used to represent the same information and differential information in each block of the target upgrade firmware and the corresponding block of the source firmware; determining the differential information and unique information corresponding to each block of the target upgrade firmware according to the third control information, the fourth control information, the differential information, and the unique information; generating a differential upgrade package corresponding to each block of the target upgrade firmware according to the third control information, the fourth control information, and the differential information and unique information corresponding to each block of the target upgrade firmware; determining the upgrade order of each block of the target upgrade firmware according to the third control information; and packaging the differential upgrade package corresponding to each block of the target upgrade firmware and the upgrade order to obtain a differential upgrade package corresponding to the target upgrade firmware.
[0006] Optionally, before performing block processing on the source firmware data and the target upgrade firmware data according to the target block size to obtain a plurality of block data of the source firmware and a plurality of block data of the target upgrade firmware, the method further includes: obtaining the memory size of a target processor on the device side and the minimum erasure unit of a target flash memory on the device side; and determining the target block size according to the memory size of the target processor and the minimum erasure unit of the target flash memory.
[0007] Optionally, decompose each first control information according to the identifier corresponding to each target upgraded firmware block, the identifier corresponding to each source firmware block, the target block size, and the operation step size, to obtain third control information corresponding to each target upgraded firmware block, including: determining the current decomposition step size corresponding to the first control information according to the current operable byte number of the first control information, the remaining byte number in the currently operated source firmware block, and the remaining byte number in the currently operated target upgraded firmware block; decomposing the first control information according to the current decomposition step size corresponding to the first control information to obtain a first decomposition result, and recording the block identifier of the source firmware corresponding to each decomposition operation in the decomposition process of the first control information, the block identifier of the target upgraded firmware corresponding to it, the current first position offset pointer in the source firmware, the current second position offset pointer in the target upgraded firmware, and the current third position offset pointer in the differential information in the full differential packet; determining the third control information according to the first decomposition result, the first position offset pointer, the block identifier of the corresponding source firmware, the block identifier of the corresponding target upgraded firmware, the first position offset pointer, the second position offset pointer, and the third position offset pointer.
[0008] Decompose each second control information according to the block identifier corresponding to the block data of each target upgraded firmware, the target block size, and the operation step size, to obtain fourth control information corresponding to each target upgraded firmware block, including: determining the current decomposition step size corresponding to the second control information according to the current operable byte number of the second control information and the remaining byte number in the currently operated target upgraded firmware block; decomposing the second control information according to the current decomposition step size corresponding to the second control information to obtain a second decomposition result, and recording the block identifier of the target upgraded firmware corresponding to each decomposition operation in the decomposition process of the second control information, the current fourth position offset pointer in the target upgraded firmware, and the current fifth position offset pointer in the unique information in the full differential packet; determining the fourth control information according to the second decomposition result, the fourth position offset pointer, the fifth position offset pointer, and the block identifier of the target upgraded firmware.
[0009] Optionally, determining the upgrade order of each target upgraded firmware block according to the third control information includes: determining the block identifier of the target upgraded firmware corresponding to the third control information and the block identifier of the source firmware; determining the correspondence between the block identifier of each target upgraded firmware and the block identifier of the source firmware according to the block identifier of the target upgraded firmware corresponding to the third control information and the block identifier of the source firmware; performing topological sorting on the block identifiers of the target upgraded firmware and the block identifiers of the source firmware according to the correspondence between the block identifiers of the target upgraded firmware and the block identifiers of the source firmware; and determining the upgrade order of each target upgraded firmware block according to the topological sorting result.
[0010] Optionally, the method further includes: using a preset simulation program to perform an upgrade simulation operation on the source firmware with the differential upgrade package corresponding to the target upgraded firmware.
[0011] According to a second aspect, an embodiment of the present invention further discloses a block differential upgrade method, including: obtaining a target differential upgrade package, where the target differential upgrade package is obtained by the block differential upgrade package generation method described in the first aspect or any optional implementation manner of the first aspect; reading the upgrade order information of each target upgraded firmware block in the target differential upgrade package; and performing the upgrade command corresponding to each target upgraded firmware block on the firmware to be upgraded according to the upgrade order information of each target upgraded firmware block, so as to upgrade the firmware to be upgraded.
[0012] According to a third aspect, an embodiment of the present invention further discloses a device for generating a differential upgrade package in blocks, including: a first acquisition module, configured to acquire a source firmware and a target upgrade firmware of a firmware to be upgraded; a calculation module, configured to calculate a full differential package of the source firmware and the target upgrade firmware, where the full differential package includes control information, differential information, and unique information; a block processing module, configured to perform block processing on the source firmware data and the target upgrade firmware data according to a target block size, to obtain a plurality of block data of the source firmware and a plurality of block data of the target upgrade firmware, each block data of the source firmware includes a corresponding block identifier, and each block data of the target upgrade firmware includes a corresponding block identifier; a second acquisition module, configured to acquire a plurality of control triple commands in the control information, each control triple command includes first control information and second control information, the first control information represents the same information and differential information between the source firmware and the target upgrade firmware, and the second control information represents the unique information of the target upgrade firmware; a first decomposition module, configured to decompose each piece of the first control information according to the identifier corresponding to each block of the target upgrade firmware, the identifier corresponding to each block of the source firmware, the target block size, and an operation step length, to obtain third control information corresponding to each block of the target upgrade firmware, where the third control information represents the same information and differential information in each block of the target upgrade firmware and the corresponding block of the source firmware; a second decomposition module, configured to decompose each piece of the second control information according to the block identifier corresponding to the block data of each target upgrade firmware, the target block size, and the operation step length, to obtain fourth control information corresponding to each block of the target upgrade firmware, where the fourth control information is used to represent the same information and differential information in each block of the target upgrade firmware and the corresponding block of the source firmware; a first determination module, configured to determine the differential information and unique information corresponding to each block of the target upgrade firmware according to the third control information, the fourth control information, the differential information, and the unique information; a generation module, configured to generate a differential upgrade package corresponding to each block of the target upgrade firmware according to the third control information, the fourth control information, and the differential information and unique information corresponding to each block of the target upgrade firmware; a second determination module, configured to determine the upgrade order of each block of the target upgrade firmware according to the third control information; and a packaging module, configured to package the differential upgrade packages corresponding to each block of the target upgrade firmware and the upgrade order, to obtain a differential upgrade package corresponding to the target upgrade firmware.
[0013] According to a fourth aspect, an embodiment of the present invention further discloses a block differential upgrade device, including: a third acquisition module, configured to acquire a target differential upgrade package, where the target differential upgrade package is obtained by the block differential upgrade package generation method as described in the first aspect or any optional implementation manner of the first aspect; a reading module, configured to read the upgrade sequence information of each target upgrade firmware block in the target differential upgrade package; and an upgrade module, configured to execute, according to the upgrade sequence information of each target upgrade firmware block, the upgrade command corresponding to each target upgrade firmware block in the firmware to be upgraded, so as to upgrade the firmware to be upgraded.
[0014] According to a fifth aspect, an embodiment of the present invention further discloses an electronic device, including: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and when the instructions are executed by the at least one processor, the at least one processor is caused to execute the steps of the block differential upgrade package generation method as described in the first aspect or any optional implementation manner of the first aspect, or execute the steps of the block differential upgrade method as described in the second aspect.
[0015] According to a sixth aspect, an embodiment of the present invention further discloses a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the block differential upgrade package generation method as described in the first aspect or any optional implementation manner of the first aspect are implemented, or the steps of the block differential upgrade method as described in the second aspect are implemented.
[0016] The technical solution of the present invention has the following advantages:
[0017] The method / device for generating a segmented differential upgrade package provided by the present invention decomposes the control information in the full-difference package of the source firmware to be upgraded and the target upgraded firmware, determines the third control information and the fourth control information corresponding to each block of the target upgraded firmware during the upgrade, generates a differential upgrade package corresponding to each block of the target upgraded firmware according to the third control information and the fourth control information, determines the upgrade order corresponding to each block of the target upgraded firmware according to the third control information, packs the differential upgrade packages corresponding to each block of the target upgraded firmware and the upgrade order to obtain a differential upgrade package corresponding to the target upgraded firmware. The differential upgrade package corresponding to the target upgraded firmware is a minimal difference package, and the size of this difference package can be less than 10% of the source firmware or the target firmware. Subsequently, when upgrading the source firmware according to the differential upgrade package corresponding to the target upgraded firmware, the upgrade order corresponding to each block of the target upgraded firmware in the differential upgrade package can be read, and the control information corresponding to the corresponding block can be executed according to the upgrade order to restore each block of the target upgraded firmware in sequence, realizing the upgrade of the source firmware. During the upgrade process, it can be overwritten on the basis of the source firmware. The total memory required only depends on the block size and does not depend on the sizes of the source firmware and the target firmware, and no additional space is required, solving the defect that the differential upgrade method in the prior art has a large demand for hardware storage resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following will briefly introduce the drawings required for use in the description of the specific embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0019] Figure 1 It is a flowchart of a specific example of the method for generating a segmented differential upgrade package in an embodiment of the present invention;
[0020] Figure 2A It is a schematic diagram of a specific example of the method for generating a segmented differential upgrade package in an embodiment of the present invention;
[0021] Figure 2B It is a schematic diagram of a specific example of the method for generating a segmented differential upgrade package in an embodiment of the present invention;
[0022] Figure 3 It is a schematic diagram of a specific example of the method for generating a segmented differential upgrade package in an embodiment of the present invention;
[0023] Figure 4 It is a flowchart of a specific example of the method for segmented differential upgrade in an embodiment of the present invention;
[0024] Figure 5 It is a schematic block diagram of a specific example of the block differential upgrade package generation device in an embodiment of the present invention;
[0025] Figure 6 It is a schematic block diagram of a specific example of the block differential upgrade device in an embodiment of the present invention;
[0026] Figure 7 It is a specific example diagram of an electronic device in an embodiment of the present invention. Specific embodiments
[0027] Next, the technical solutions of the present invention will be clearly and completely described in conjunction with the accompanying drawings. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0028] In the description of the present invention, it should be noted that the orientation or positional relationship indicated by the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc. is based on the orientation or positional relationship shown in the accompanying drawings. It is only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and thus cannot be understood as a limitation of the present invention. In addition, the terms "first", "second", and "third" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance.
[0029] In the description of the present invention, it should be noted that unless otherwise clearly specified and limited, the terms "installation", "connection", and "connection" should be understood in a broad sense. For example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be directly connected or indirectly connected through an intermediate medium, and it can also be the communication inside two elements. It can be a wireless connection or a wired connection. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0030] In addition, the technical features involved in different embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0031] An embodiment of the present invention discloses a method for generating a block differential upgrade package, which can be applied to a host computer or a differential upgrade platform system. All historical firmware data and upgradeable firmware data on the device side to be upgraded are integrated on the host computer or the differential upgrade platform system; as Figure 1 shown, the method includes the following steps:
[0032] Step 101: Obtain the source firmware and the target upgrade firmware of the firmware to be upgraded.
[0033] Exemplarily, the firmware can be code stored in the memory operable by a single-chip microcomputer or MCU, which is a compiled binary file and can operate on hardware, usually referred to as: Firmware. The source firmware can be the firmware before the upgrade, also known as the old firmware; the target upgrade firmware can be the firmware after the upgrade, also known as the new firmware.
[0034] Step 102: Calculate the full-difference package of the source firmware and the target upgrade firmware, where the full-difference package includes control information, differential information, and unique information.
[0035] Exemplarily, the full-difference package can be a difference file between the target upgrade firmware and the source firmware made through a difference algorithm, called a patch file (Patch), which is completed by the host computer or the platform system. The difference algorithm can be a method or step for extracting the difference information between the source firmware and the target upgrade firmware. Commonly used difference algorithms are bsdiff and vcdiff. After both algorithms complete the matching search, they can be compressed again. For the characteristics of the firmware binary file, efficient matching can be completed. In the embodiments of the present application, the bsdiff difference algorithm can be used to extract the full-difference information. After the source firmware and the target upgrade firmware pass through the bsdiff algorithm, a patch file (full-difference information) is generated. The role of the patch file is that when the patch file is transmitted to the device to be upgraded, the device can restore the target upgrade firmware according to this patch file and the source firmware. The patch file consists of three parts of information: control information, differential information, and unique information of the new firmware. Among them, the control information consists of a series of commands, and each command consists of a triple in the fixed format of CMD(X, Y, Z). The composition of the patch file is shown in Table 1 below.
[0036] Table 1
[0037]
[0038]
[0039] Step 103: Perform block processing on the source firmware data and the target upgrade firmware data according to the target block size to obtain multiple block data of the source firmware and multiple block data of the target upgrade firmware. Each block data of the source firmware includes a corresponding block identifier, and each block data of the target upgrade firmware includes a corresponding block identifier.
[0040] Exemplarily, the target block size can be any size. The embodiments of the present application do not limit the specific content of the target block size, as long as it can achieve the block division of the source firmware and the target upgrade firmware. Those skilled in the art can determine it according to needs. In the embodiments of the present application, the source firmware and the target upgrade firmware can be block-processed according to the target block size. For example, when the target block size is 512 bytes, the size of the source firmware is 4672 bytes, and the size of the target upgrade firmware is 5580 bytes, the source firmware and the upgrade firmware are divided into blocks of 512 bytes, and the block identifier corresponding to each source firmware block and the block identifier corresponding to each target upgrade firmware block are recorded; the block identifier corresponding to each source firmware block can be the corresponding block number, and the block identifier corresponding to each target upgrade firmware block can be the corresponding block number.
[0041] Step 104, obtain a plurality of control triple commands in the control information. Each control triple command includes first control information and second control information. The first control information represents the same information and differential information between the source firmware and the target upgrade firmware, and the second control information represents the unique information of the target upgrade firmware.
[0042] Exemplarily, in the embodiments of the present application, the first control information can be X in the control triple (X, Y, Z). The meaning of X is to read X bytes from the differential information (D1D2D3…) and add them to the X bytes of the old firmware to obtain the content of the new firmware. The second control information can be Y in the control triple (X, Y, Z). The meaning of Y is to copy Y bytes of data from the unique information (E1E2E3…) and add the current position as the content of the new firmware.
[0043] Step 105, decompose each first control information according to the identifier corresponding to each target upgrade firmware block, the identifier corresponding to each source firmware block, the target block size, and the operation step length, to obtain the third control information corresponding to each target upgrade firmware block. The third control information represents the same information and differential information between each target upgrade firmware block and the corresponding source firmware block.
[0044] Exemplarily, the operation step length can be the number of operation bytes corresponding to each operation when decomposing the first control information. In the embodiments of the present application, the first control information is decomposed into reduction commands corresponding to each target upgrade firmware block. For example, the operation byte number of X in the first control triple is 1671 bytes, and the block size of each block is 512. Therefore, when X is executed, it will span 3 blocks and involve 4 block spaces. Therefore, when decomposing X, it needs to be decomposed into operation instructions corresponding to each block in the four block spaces.
[0045] Step 106: Decompose each second control information according to the block identifier corresponding to the segmented data of each target upgraded firmware, the target block size, and the operation step size, to obtain fourth control information corresponding to each block of each target upgraded firmware. The fourth control information is used to represent the same information and differential information in each block of each target upgraded firmware as compared with the corresponding source firmware block.
[0046] Exemplarily, the operation step size can be the number of operation bytes corresponding to each operation when decomposing the second control information. In the embodiments of the present application, the second control information is decomposed into reduction commands corresponding to each block of each target upgraded firmware. For example, the number of operation bytes of Y in the first control triple is 1,671 bytes, and the size of each block is 512, so Y will span 3 blocks during execution and involve 4 block spaces. Therefore, when decomposing Y, it needs to be decomposed into operation instructions corresponding to each block in the four block spaces.
[0047] Step 107: Determine the differential information and unique information corresponding to each block of each target upgraded firmware according to the third control information, the fourth control information, the differential information, and the unique information.
[0048] Exemplarily, the third control information is the control instruction corresponding to each block of each target upgraded firmware generated according to the same information and differential information between the target upgraded firmware and the source firmware. Then, the differential information of each block of each target upgraded firmware can be determined according to the third control information and the differential information in the full differential package; the fourth control information is the control instruction corresponding to each block of each target upgraded firmware generated according to the unique information of the target upgraded firmware. Then, the unique information of each block of each target upgraded firmware can be determined according to the fourth control information and the unique information in the full differential package.
[0049] Step 108: Generate a differential upgrade package corresponding to each block of each target upgraded firmware according to the third control information, the fourth control information, and the differential information and unique information corresponding to each block of each target upgraded firmware. Exemplarily, subsequently, according to the differential upgrade package corresponding to each block of each target upgraded firmware, execute the third control information and the fourth control information corresponding to the corresponding block to realize data reduction of each block of each target upgraded firmware.
[0050] Step 109: Determine the upgrade order of each block of each target upgraded firmware according to the third control information.
[0051] Exemplarily, in the embodiments of the present application, when restoring the target upgraded firmware through the differential upgrade package corresponding to each block of the target upgraded firmware subsequently, it can be overwritten on the source firmware, effectively reducing the requirement for Flash memory space during the firmware upgrade. However, when executing the corresponding control information to restore the target upgraded firmware, it is necessary to rely on the information in the source firmware. Therefore, it is necessary to determine the upgrade order of each block of the target upgraded firmware in order to perform the overwrite on the source firmware and achieve the restoration operation of the target upgraded firmware. The third control information includes operation commands for restoring each block of the target upgraded firmware. The information of the source firmware relied on when restoring each block of the target upgraded firmware can be determined according to the third control command, and then the source firmware block relied on by each block of the target upgraded firmware can be determined; according to the source firmware block relied on by each target upgraded firmware, the upgrade order of each block of the target upgraded firmware is determined. This upgrade order can be determined manually or by using some preset sorting algorithms.
[0052] Step 110, package the differential upgrade package corresponding to each block of the target upgraded firmware and the upgrade order to obtain the differential upgrade package corresponding to the target upgraded firmware.
[0053] Exemplarily, the host computer or the platform system obtains the differential upgrade package corresponding to the target upgraded firmware, and subsequently, the differential upgrade package can be sent to the device to be upgraded, facilitating the device to be upgraded to execute the corresponding upgrade operation of the source firmware according to the received differential upgrade package.
[0054] In the embodiments of the present application, the obtained differential upgrade package corresponding to the target upgraded firmware can be applied to Internet of Things devices with a small Flash space during subsequent firmware upgrades, solving the problem of firmware upgrades under extremely limited resources on the device side (Flash less than 32K, memory less than 1K). If the size of the source firmware is S1, the size of the target upgraded firmware is S2, and the size of the patch file is S3, during the upgrade process of the differential upgrade package obtained in this embodiment, the flash space requirement on the device side is: S2 + S3. In the currently disclosed solutions, the flash space requirement on the device side is (S1 + S2 + S3). Taking the hardware configuration of a general MCU as an example: S1 = 122K, S2 = 120K, S3 = 15K, the flash space size required for the differential upgrade package obtained in this embodiment during subsequent upgrades is: S2 + S3 = 135K; the flash space size required for other existing solutions is: S1 + S2 + S3 = 257K.
[0055] The method for generating a differential upgrade package provided by the present invention decomposes the control information in the full-difference package of the source firmware to be upgraded and the target firmware to be upgraded, determines the third control information and the fourth control information corresponding to each block of the target firmware during the upgrade, generates a differential upgrade package corresponding to each block of the target firmware according to the third control information and the fourth control information, determines the upgrade order corresponding to each block of the target firmware according to the third control information, and packages the differential upgrade package and the upgrade order corresponding to each block of the target firmware to obtain a differential upgrade package corresponding to the target firmware. The differential upgrade package corresponding to the target firmware is a minimal difference package, and the size of the difference package can be less than 10% of the source firmware or the target firmware. Subsequently, when upgrading the source firmware according to the differential upgrade package corresponding to the target firmware, the upgrade order corresponding to each block of the target firmware in the differential upgrade package can be read, and the control information corresponding to the corresponding block can be executed according to the upgrade order to restore each block of the target firmware in sequence, realizing the upgrade of the source firmware. During the upgrade process, it can be overwritten on the basis of the source firmware, and all the required memory only depends on the block size, does not depend on the sizes of the source firmware and the target firmware, and does not require the use of additional space, solving the defect that the differential upgrade method in the prior art has a large demand for hardware storage resources.
[0056] As an optional implementation manner of the present invention, before step 103, the method further includes: obtaining the memory size of the target processor on the device side and the minimum erasure unit of the target flash memory on the device side; determining the target block size according to the memory size of the target processor and the minimum erasure unit of the target flash memory.
[0057] Exemplarily, in the embodiments of the present application, the setting of the target block size will affect the size of the final differential upgrade package. The larger the block, the smaller the differential upgrade package, but the requirement for the memory size on the device side is also large. The setting of the block size must meet the following principles: meet the memory requirements on the device side and use the minimum unit of flash erasure on the device side as the minimum unit. Therefore, to achieve the best differential effect, assuming that the memory of the device-side MCU is size_mem and the erasure unit of the device-side memory is size_flash_erasor, the present application provides a calculation formula for setting the block size (block_size): block_size = M * size_flash_erasor, (where M is a positive integer); M = (size_mem / 4 + size_flash_erasor - 1) / size_flash_erasor; for example, for a resource-constrained MCU, size_mem = 8192B, size_flash_erasor = 512B, after calculation, M = 4, block_size = 2048B.
[0058] As an optional implementation manner of the present invention, step 105 includes:
[0059] Determine the current decomposition step corresponding to the first control information according to the current number of operable bytes of the first control information, the remaining bytes in the currently operated source firmware block, and the remaining bytes in the currently operated target upgrade firmware block.
[0060] Exemplarily, the current number of operable bytes of the first control information may be the remaining number of operation bytes of the first control information; the remaining bytes in the currently operated source firmware block may be the remaining length from the current operation position (old_from) in the source firmware block to the lower boundary (old_blk_upper_bound) of this block, specifically as Figure 2A shown; the remaining bytes in the currently operated target upgrade firmware block may be the remaining length from the current operation position (new_from) in the target upgrade firmware block to the lower boundary (new_blk_upper_bound) of this block, specifically as Figure 2B shown. The selection principle of the current operation step may be to select the minimum value among the three variables of the current number of operable bytes of the first control information, the remaining bytes in the currently operated source firmware block, and the remaining bytes in the currently operated target upgrade firmware block as the current decomposition step.
[0061] Decompose the first control information according to the current decomposition step corresponding to the first control information to obtain a first decomposition result, and record the block identifier of the source firmware corresponding to each decomposition operation in the decomposition process of the first control information, the block identifier of the target upgrade firmware corresponding thereto, the current first position offset pointer in the source firmware, the current second position offset pointer in the target upgrade firmware, and the current third position offset pointer in the differential information in the full differential packet.
[0062] Exemplarily, when decomposing the first control information, the current operation length of the first control information can be subtracted by the current decomposition step length, and the decomposition step length of each step can be recorded until the current operation length of the first control information is 0, then the decomposition of the first control information is completed. If the first control information is not completely decomposed, but the remaining byte count of the target upgraded firmware block and / or the source firmware block for the current operation is 0, then it is necessary to shift to the next block for the decomposition operation. During the decomposition process, it is also necessary to record the block identifier (new_blk_idx) of the target upgraded firmware corresponding to each decomposition operation, the block identifier (old_blk_idx) of the source firmware, the offset position old_from (the first position offset pointer) in the source firmware, the offset position new_from (the second position offset pointer) in the target upgraded firmware, and the offset position diff_from (the third position offset pointer) in the patch file (full differential information).
[0063] Determine the third control information according to the first decomposition result, the first position offset pointer, the block identifier of the corresponding source firmware, the block identifier of the corresponding target upgraded firmware, the first position offset pointer, the second position offset pointer, and the third position offset pointer.
[0064] Exemplarily, in the embodiment of the present application, when determining the third control information, it involves a command reconstruction process. When the type of the control command included in the control information corresponding to the first decomposition result is used for command reconstruction; the action with the command type of DIFF generated by decomposing X (the first control information) is subdivided into two command types: copy and diff. The subdivision principle is as follows: If the data involved in the differential information corresponding to the first decomposition result (with a length of step and an offset address being the offset of the differential block in the "command details") is all 0, that is, the differential information with a length of step in this paragraph is all 0, which is equivalent to not requiring differential and only depending on the old firmware. At this time, this command is defined as a copy command; if the data involved in the differential information is not all 0, that is, the decomposed control information is related to both the differential information and the source firmware, this command is defined as a diff command. Define a = 0 as a copy command, a = 1 as a diff command, use b to identify the operation step length step of the control information corresponding to the first decomposition result, and use c to identify the offset of the control information corresponding to the first decomposition result in the source firmware, and obtain the third control information (a, b, c). When a = 0, the meaning of (a, b, c) is to locate to the c position of the source firmware and copy b bytes from the source firmware; when a = 1, the meaning of (a, b, c) is to locate to the c position of the source firmware and add the b bytes copied from the source firmware to the b bytes in the differential information.
[0065] Step 106 includes:
[0066] Determine the current decomposition step corresponding to the second control information according to the current number of operable bytes of the second control information and the remaining bytes in the target upgraded firmware block currently being operated on.
[0067] Exemplarily, in the embodiments of the present application, the meaning of Y (the second control information) is to read Y bytes of data from the unique information and add it to the current operation position as the content of the target upgraded firmware. Therefore, the decomposition of the second control information does not involve the source firmware. Therefore, the current decomposition step can be determined only according to the current number of operable bytes of the second control information and the remaining bytes in the target upgraded firmware block currently being operated on. The selection principle of the current decomposition step corresponding to the second control information is: use the smaller value of the current number of operable bytes of the second control information and the remaining bytes in the target upgraded firmware block currently being operated on as the current decomposition step corresponding to the second control information.
[0068] Decompose the second control information according to the current decomposition step corresponding to the second control information to obtain a second decomposition result, and record the block identifier of the target upgraded firmware corresponding to each decomposition operation in the decomposition process of the second control information, the current fourth position offset pointer in the target upgraded firmware, and the current fifth position offset pointer in the unique information in the full differential package.
[0069] Exemplarily, decompose the second control information according to the current decomposition step corresponding to the second control information, and record the position offset new_from (the fourth position offset pointer) processed in the target upgraded firmware and the position offset extra_from (the fifth position offset pointer) of the exclusive block for each decomposition operation. After processing one step each time, record the block identifier of the corresponding target upgraded firmware.
[0070] Determine the fourth control information according to the second decomposition result, the fourth position offset pointer, the fifth position offset pointer, and the block identifier of the target upgraded firmware.
[0071] Exemplarily, in the embodiments of the present application, the control command operation type corresponding to the second decomposition result can be defined as an EXTRA action, a = 2 is defined as an extra command, and the operation step step of the control information corresponding to the second decomposition result is identified by b, to obtain a third control information (a, b, c), where c = 0 because the third control information has nothing to do with the old firmware. When a = 2, the meaning of (a, b, c) is to copy b bytes from the corresponding unique information.
[0072] As an alternative embodiment of the present invention, step 109 includes: determining the block identifier of the target upgrade firmware corresponding to the third control information and the block identifier of the source firmware. Exemplarily, the content of the third control information includes operations on the blocks of the target upgrade firmware and the source firmware, and the block identifier of the target upgrade firmware corresponding to the third control command and the block identifier of the source firmware can be determined.
[0073] According to the block identifier of the target upgrade firmware corresponding to the third control information and the block identifier of the source firmware, determine the correspondence between the block identifier of each target upgrade firmware and the block identifier of the source firmware. Exemplarily, when the third control information restores the corresponding target upgrade firmware block during execution, it will read the corresponding information from the corresponding source firmware. Therefore, the correspondence between the block identifier of the target upgrade firmware corresponding to the third control information and the block identifier of the source firmware can be used to determine the correspondence between the block identifier of each target upgrade firmware and the block identifier of the source firmware. For example, if target upgrade firmware blocks 10, 7, and 6 all need to obtain corresponding information from source firmware block 0 during restoration, then target upgrade firmware 10, 7, and 6 correspond to source firmware block 0.
[0074] Perform a topological sort on the block identifier of the target upgrade firmware and the block identifier of the source firmware according to the correspondence between the block identifier of the target upgrade firmware and the block identifier of the source firmware. Exemplarily, for example, when the correspondence between the block identifier of the target upgrade firmware and the block identifier of the source firmware includes:
[0075] old blk idx (target firmware block identifier): 0 corresponds to new blk idx (target firmware block identifier): 10, newblk idx: 7, and new blk idx: 6;
[0076] old blk idx: 2 corresponds to new blk idx: 11 and new blk idx: 10;
[0077] old blk idx: 2 corresponds to new blk idx: 11 and new blk idx: 10;
[0078] old blk idx: 3 corresponds to new blk idx: 10;
[0079] old blk idx: 4 corresponds to new blk idx: 10, new blk idx: 8, and new blk idx: 5;
[0080] old blk idx: 5 corresponds to new blk idx: 10;
[0081] The old block index: 6 corresponds to the new block index: 10, the new block index: 9, and the new block index: 8;
[0082] The old block index: 7 corresponds to the new block index: 11, the new block index: 10, the new block index: 9, the new block index: 8, the new block index: 6, and the new block index: 3.
[0083] Perform topological sorting on the block identifiers of the target upgraded firmware and the block identifiers of the source firmware according to the above corresponding relationships. As Figure 3 shown, this figure is a directed graph. The vertices represent the new firmware block identifiers and the source firmware block identifiers, and the edge set represents the corresponding relationships between the new firmware and the source firmware. The tail of the edge is the identifier of the new firmware block, and the head is the identifier of the source firmware block, which is used to identify the corresponding relationship between the new firmware block and the source firmware block. The reduction order of the target upgraded firmware blocks can be converted into performing topological sorting on this graph. There may be multiple result sequences for topological sorting, and any one of the result sequences can be used as the reduction order of the firmware. In this way, the problem of the reduction order of the new firmware is solved, and the problem of in-place overwriting on the original firmware without using additional space is also solved.
[0084] According to the topological sorting result, determine the upgrade order of each target upgraded firmware block. Exemplarily, in the embodiment of the present application, according to the Figure 3 figure shown, one of the sequences obtained after topological sorting is: 11 --> 10 --> 2 --> 3 --> 5 --> 9 --> 8 --> 4 --> 6 --> 7 --> 0 --> 1, and this order can be used as the reduction order corresponding to the target upgraded firmware blocks.
[0085] As an optional implementation manner of the present invention, the method further includes: using a preset simulation program to perform an upgrade simulation operation on the source firmware with the differential upgrade package corresponding to the target upgraded firmware.
[0086] Exemplarily, the preset simulation program can implement simulation upgrades according to the differential upgrade package corresponding to the target upgraded firmware. By simulating the control information flow in the differential upgrade package, simulating the reduction actions on the device side, ensuring that the newly generated firmware is exactly the same as the content of the real new firmware. If there are any abnormalities, the firmware generated this time cannot be used for upgrading.
[0087] In the embodiments of the present application, the differential upgrade package corresponding to the target upgrade firmware needs to be encrypted using the national cryptographic SM4 algorithm and a message authentication code (MAC code) is added to ensure the confidentiality and integrity of the firmware. The differential upgrade package corresponding to the target upgrade firmware also needs to add the CRC of the original firmware to ensure that the source firmware on the device side is the same as the source firmware corresponding to the differential upgrade package.
[0088] The embodiments of the present invention also disclose a block differential upgrade method applied to Internet of Things devices, such as Figure 4 shown. The method includes the following steps:
[0089] Step 201, obtain a target differential upgrade package, which is obtained by the block differential upgrade package generation method described in the above embodiments. Exemplarily, the target differential upgrade package can be any patch file that can perform differential upgrade on the source firmware in the Internet of Things device. In the embodiments of the present application, the target differential upgrade package is transmitted to the device side through a wireless or wired channel. The transmission process initiates a first-pack handshake by the device side and carries a request packet sequence number to ensure that the download is completed in the shortest time and has the ability to resume transmission at a breakpoint (or power failure). After the device side receives the complete encrypted differential upgrade package, it calls the secure decryption service of national cryptographic SM4 to obtain the plaintext differential upgrade package and the MAC_1 (message authentication code) of the differential upgrade package. The device side calls the secure MAC service of national cryptographic SM4 to recalculate the MAC_2 of the plaintext differential upgrade package. If MAC_1 and MAC_2 are the same, it means that this differential file has not been tampered with and is proven to be usable. After obtaining the plaintext target upgrade firmware differential upgrade package, obtain the source firmware CRC_1 in the differential upgrade package and calculate the CRC of the current firmware (source firmware) in real time to obtain CRC_2. If CRC_1 and CRC_2 are the same, it means that the version matching of this differential upgrade package is successful and it can be used to upgrade the new version of the firmware.
[0090] Step 202, read the upgrade sequence information of each target upgrade firmware block in the target differential upgrade package.
[0091] Step 203, according to the upgrade sequence information of each target upgrade firmware block, execute the upgrade command corresponding to each target upgrade firmware block in the firmware to be upgraded to upgrade the firmware to be upgraded.
[0092] A block differential upgrade method provided by the present invention realizes the upgrade operation of the firmware to be upgraded by obtaining a target differential upgrade package and executing the upgrade commands in the corresponding blocks according to the upgrade sequence information of a target upgrade firmware block included in the target differential upgrade package. During the upgrade process, overwriting can be performed on the basis of the source firmware. The total memory required only depends on the block size and does not depend on the sizes of the source firmware and the target firmware, and no additional space is required, thus solving the defect in the prior art that the differential upgrade method has a large demand for hardware storage resources.
[0093] An embodiment of the present invention also discloses a block differential upgrade package generation device, as Figure 5As shown in the figure, the device includes: a first acquisition module 301, configured to acquire the source firmware and the target upgrade firmware of the firmware to be upgraded; a calculation module 302, configured to calculate the full-difference package of the source firmware and the target upgrade firmware, the full-difference package including control information, differential information, and unique information; a block processing module 303, configured to perform block processing on the source firmware data and the target upgrade firmware data according to the target block size, to obtain a plurality of block data of the source firmware and a plurality of block data of the target upgrade firmware, each block data of the source firmware including a corresponding block identifier, and each block data of the target upgrade firmware including a corresponding block identifier; a second acquisition module 304, configured to acquire a plurality of control triple commands in the control information, each control triple command including first control information and second control information, the first control information representing the same information and differential information between the source firmware and the target upgrade firmware, and the second control information representing the unique information of the target upgrade firmware; a first decomposition module 305, configured to decompose each piece of the first control information according to the identifier corresponding to each block of the target upgrade firmware, the identifier corresponding to each block of the source firmware, the target block size, and the operation step length, to obtain third control information corresponding to each block of the target upgrade firmware, the third control information representing the same information and differential information in each block of the target upgrade firmware and the corresponding block of the source firmware; a second decomposition module 306, configured to decompose each piece of the second control information according to the block identifier corresponding to each block data of the target upgrade firmware, the target block size, and the operation step length, to obtain fourth control information corresponding to each block of the target upgrade firmware, the fourth control information being used to represent the same information and differential information in each block of the target upgrade firmware and the corresponding block of the source firmware; a first determination module 307, configured to determine the differential information and unique information corresponding to each block of the target upgrade firmware according to the third control information, the fourth control information, the differential information, and the unique information; a generation module 308, configured to generate a differential upgrade package corresponding to each block of the target upgrade firmware according to the third control information, the fourth control information, and the differential information and unique information corresponding to each block of the target upgrade firmware; a second determination module 309, configured to determine the upgrade order of each block of the target upgrade firmware according to the third control information; and a packaging module 310, configured to package the differential upgrade packages corresponding to each block of the target upgrade firmware and the upgrade order to obtain the differential upgrade package corresponding to the target upgrade firmware.
[0094] The block differential upgrade package generation device provided by the present invention decomposes the control information in the full-difference package of the firmware to be upgraded and the target upgrade firmware, determines the third control information and the fourth control information corresponding to each block of the target upgrade firmware during the upgrade, generates a differential upgrade package corresponding to each block of the target upgrade firmware according to the third control information and the fourth control information, determines the upgrade order corresponding to each block of the target upgrade firmware according to the third control information, packs the differential upgrade package and the upgrade order corresponding to each block of the target upgrade firmware to obtain a differential upgrade package corresponding to the target upgrade firmware. The differential upgrade package corresponding to the target upgrade firmware is a minimal difference package, and the size of the difference package can be less than 10% of the source firmware or the target firmware. Subsequently, when upgrading the source firmware according to the differential upgrade package corresponding to the target upgrade firmware, the upgrade order corresponding to each block of the target upgrade firmware in the differential upgrade package can be read, and the control information corresponding to the corresponding block can be executed according to the upgrade order to restore each block of the target upgrade firmware in turn, realizing the upgrade of the source firmware. During the upgrade process, it can be overwritten on the basis of the source firmware. The total memory required only depends on the block size and does not depend on the sizes of the source firmware and the target firmware, and no additional space is required, solving the defect that the differential upgrade method in the prior art has a large demand for hardware storage resources.
[0095] As an optional implementation manner of the present invention, the device further includes: a fourth acquisition module, configured to acquire the memory size of the target processor on the device side and the minimum erasure unit of the target flash memory on the device side; a third determination module, configured to determine the target block size according to the memory size of the target processor and the minimum erasure unit of the target flash memory.
[0096] As an optional implementation manner of the present invention, the first decomposition module includes: a first determination sub-module, configured to determine a current decomposition step corresponding to the first control information according to the current operable byte number of the first control information, the remaining byte number in the source firmware block currently being operated, and the remaining byte number in the target upgrade firmware block currently being operated; a first decomposition sub-module, configured to decompose the first control information according to the current decomposition step corresponding to the first control information to obtain a first decomposition result, and record the block identifier of the source firmware corresponding to each decomposition operation in the decomposition process of the first control information, the block identifier of the target upgrade firmware corresponding to the decomposition operation, the current first position offset pointer in the source firmware, the current second position offset pointer in the target upgrade firmware, and the current third position offset pointer in the differential information in the full differential package; a second determination sub-module, configured to determine the third control information according to the first decomposition result, the first position offset pointer, the block identifier of the corresponding source firmware, the block identifier of the corresponding target upgrade firmware, the first position offset pointer, the second position offset pointer, and the third position offset pointer.
[0097] The second decomposition module includes: a third determination sub-module, configured to determine a current decomposition step corresponding to the second control information according to the current operable byte number of the second control information and the remaining byte number in the target upgrade firmware block currently being operated; a second decomposition sub-module, configured to decompose the second control information according to the current decomposition step corresponding to the second control information to obtain a second decomposition result, and record the block identifier of the target upgrade firmware corresponding to each decomposition operation in the decomposition process of the second control information, the current fourth position offset pointer in the target upgrade firmware, and the current fifth position offset pointer in the unique information in the full differential package; a fourth determination sub-module, configured to determine the fourth control information according to the second decomposition result, the fourth position offset pointer, the fifth position offset pointer, and the block identifier of the target upgrade firmware.
[0098] As an optional implementation manner of the present invention, the second determination module includes: a fifth determination sub-module, configured to determine the block identifier of the target upgrade firmware and the block identifier of the source firmware corresponding to the third control information; a sixth determination sub-module, configured to determine the corresponding relationship between the block identifier of each target upgrade firmware and the block identifier of the source firmware according to the block identifier of the target upgrade firmware and the block identifier of the source firmware corresponding to the third control information; a sorting sub-module, configured to perform a topological sort on the block identifier of the target upgrade firmware and the block identifier of the source firmware according to the corresponding relationship between the block identifier of the target upgrade firmware and the block identifier of the source firmware; a seventh determination sub-module, configured to determine the upgrade order of each target upgrade firmware block according to the topological sort result.
[0099] As an optional embodiment of the present invention, the device further includes an upgrade simulation operation module, configured to perform an upgrade simulation operation on the source firmware by using a preset simulation program for the differential upgrade package corresponding to the target upgrade firmware.
[0100] An embodiment of the present invention also discloses a device for generating a block differential upgrade package, as Figure 6 shown. The device includes: a third acquisition module 501, configured to acquire a target differential upgrade package, where the target differential upgrade package is obtained by the method for generating a block differential upgrade package as described in the above embodiment; a reading module 502, configured to read the upgrade sequence information of each target upgrade firmware block in the target differential upgrade package; and an upgrade module 503, configured to execute, according to the upgrade sequence information of each target upgrade firmware block, an upgrade command corresponding to each target upgrade firmware block in the firmware to be upgraded, so as to upgrade the firmware to be upgraded.
[0101] The block differential upgrade device provided by the present invention realizes the upgrade operation of the firmware to be upgraded by acquiring a target differential upgrade package and executing the upgrade command in the corresponding block according to the upgrade sequence information of a target upgrade firmware block included in the target differential upgrade package. During the upgrade process, coverage can be performed on the basis of the source firmware. The total memory required only depends on the block size and does not depend on the sizes of the source firmware and the target firmware, and no additional space needs to be used, thus solving the defect in the prior art that the differential upgrade method has a large demand for hardware storage resources.
[0102] An embodiment of the present invention also provides an electronic device, as Figure 7 shown. The electronic device may include a processor 401 and a memory 402. The processor 401 and the memory 402 may be connected through a bus or other means, Figure 7 taking the connection through the bus as an example.
[0103] The processor 401 may be a central processing unit (CPU). The processor 401 may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. chips, or a combination of the above various types of chips.
[0104] The memory 402, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs, non-transitory computer-executable programs, and modules, such as program instructions / modules corresponding to the block differential upgrade package generation method or the block differential upgrade method in the embodiments of the present invention. The processor 401 executes various functional applications and data processing of the processor by running the non-transitory software programs, instructions, and modules stored in the memory 402, that is, implements the block differential upgrade package generation method or the block differential upgrade method in the above method embodiments.
[0105] The memory 402 may include a program storage area and a data storage area. Among them, the program storage area can store an operating system and application programs required for at least one function; the data storage area can store data created by the processor 401 and the like. In addition, the memory 402 may include high-speed random access memory, and may also include non-transitory memory, such as at least one magnetic disk storage device, a flash memory device, or other non-transitory solid-state storage devices. In some embodiments, the memory 402 may optionally include a memory remotely disposed relative to the processor 401, and these remote memories can be connected to the processor 401 through a network. Examples of the above network include but are not limited to the Internet, an enterprise intranet, a local area network, a mobile communication network, and combinations thereof.
[0106] The one or more modules are stored in the memory 402 and, when executed by the processor 401, execute as Figure 1 shown in the embodiments of the block differential upgrade package generation method or Figure 4 shown in the embodiments of the block differential upgrade method.
[0107] For specific details of the above electronic device, reference can be made to the corresponding relevant descriptions and effects in the embodiments shown in Figure 1 、 Figure 4 for understanding, and details are not described herein again.
[0108] Those skilled in the art can understand that to implement all or part of the processes in the above method embodiments, it can be completed by instructing relevant hardware through a computer program. The program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the above method embodiments. Among them, the storage medium can be a magnetic disk, an optical disc, a read-only memory (ROM), a random access memory (RAM), a flash memory, a hard disk drive (abbreviation: HDD), or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above types of memories.
[0109] Although embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations fall within the scope defined by the appended claims.
Claims
1. A method for generating a block differential upgrade package, characterized in that Including: Obtain the source firmware and the target upgrade firmware of the firmware to be upgraded; Calculate the full differential package of the source firmware and the target upgrade firmware, where the full differential package includes control information, differential information, and unique information; Perform block processing on the source firmware data and the target upgrade firmware data according to the target block size to obtain multiple block data of the source firmware and multiple block data of the target upgrade firmware. Each block data of the source firmware includes a corresponding block identifier, and each block data of the target upgrade firmware includes a corresponding block identifier; Obtain multiple control triple commands in the control information. Each control triple command includes first control information and second control information. The first control information represents the same information and differential information between the source firmware and the target upgrade firmware, and the second control information represents the unique information of the target upgrade firmware; Decompose each first control information according to the identifier corresponding to each target upgrade firmware block, the identifier corresponding to each source firmware block, the target block size, and the operation step length to obtain the third control information corresponding to each target upgrade firmware block. The third control information represents the same information and differential information in each target upgrade firmware block and the corresponding source firmware block; Decompose each second control information according to the block identifier corresponding to each block data of the target upgrade firmware, the target block size, and the operation step length to obtain the fourth control information corresponding to each target upgrade firmware block. The fourth control information is used to represent the same information and differential information in each target upgrade firmware block and the corresponding source firmware block; Determine the differential information and unique information corresponding to each target upgrade firmware block according to the third control information, the fourth control information, the differential information, and the unique information; Generate a differential upgrade package corresponding to each target upgrade firmware block according to the third control information, the fourth control information, and the differential information and unique information corresponding to each target upgrade firmware block; Determine the upgrade order of each target upgrade firmware block according to the third control information; Package the differential upgrade package corresponding to each target upgrade firmware block and the upgrade order to obtain the differential upgrade package corresponding to the target upgrade firmware.
2. The method according to claim 1, wherein Before performing block processing on the source firmware data and the target upgrade firmware data according to the target block size to obtain multiple block data of the source firmware and multiple block data of the target upgrade firmware, the method further includes: Obtain the memory size of the target processor on the device side and the minimum erasure unit of the target flash memory on the device side; Determine the target block size according to the memory size of the target processor and the minimum erasure unit of the target flash memory.
3. The method according to claim 1, wherein Decompose each first control information according to the identifier corresponding to each target upgrade firmware block, the identifier corresponding to each source firmware block, the target block size, and the operation step size, to obtain third control information corresponding to each target upgrade firmware block, including: Determine the current decomposition step size corresponding to the first control information according to the current operable byte count of the first control information, the remaining bytes in the currently operated source firmware block, and the remaining bytes in the currently operated target upgrade firmware block; Decompose the first control information according to the current decomposition step size corresponding to the first control information to obtain a first decomposition result, and record the block identifier of the source firmware corresponding to each decomposition operation, the block identifier of the target upgrade firmware corresponding to each decomposition operation, the current first position offset pointer in the source firmware, the current second position offset pointer in the target upgrade firmware, and the current third position offset pointer in the differential information in the full differential package during the decomposition process of the first control information; Determine the third control information according to the first decomposition result, the first position offset pointer, the block identifier of the corresponding source firmware, the block identifier of the corresponding target upgrade firmware, the second position offset pointer, and the third position offset pointer; Decompose each second control information according to the block identifier corresponding to the block data of each target upgrade firmware, the target block size, and the operation step size, to obtain fourth control information corresponding to each target upgrade firmware block, including: Determine the current decomposition step size corresponding to the second control information according to the current operable byte count of the second control information and the remaining bytes in the currently operated target upgrade firmware block; Decompose the second control information according to the current decomposition step size corresponding to the second control information to obtain a second decomposition result, and record the block identifier of the target upgrade firmware corresponding to each decomposition operation, the current fourth position offset pointer in the target upgrade firmware, and the current fifth position offset pointer in the unique information in the full differential package during the decomposition process of the second control information; Determine the fourth control information according to the second decomposition result, the fourth position offset pointer, the fifth position offset pointer, and the block identifier of the target upgrade firmware; 4. The method according to claim 3, wherein The determining the upgrade order of each target upgrade firmware block according to the third control information includes: Determine the block identifier of the target upgrade firmware and the block identifier of the source firmware corresponding to the third control information; Determine the corresponding relationship between the block identifier of each target upgrade firmware and the block identifier of the source firmware according to the block identifier of the target upgrade firmware and the block identifier of the source firmware corresponding to the third control information; Perform topological sorting on the block identifier of the target upgrade firmware and the block identifier of the source firmware according to the corresponding relationship between the block identifier of the target upgrade firmware and the block identifier of the source firmware; Determine the upgrade order of each target upgrade firmware block according to the topological sorting result.
5. The method according to claim 1, wherein The method further includes: Use a preset simulation program to perform an upgrade simulation operation on the source firmware using the differential upgrade package corresponding to the target upgrade firmware.
6. A block differential upgrade method, characterized in that Including: Obtain a target differential upgrade package, which is obtained by the method for generating a block differential upgrade package according to any one of claims 1-5; Read the upgrade sequence information of each target upgrade firmware block in the target differential upgrade package; According to the upgrade sequence information of each target upgrade firmware block, execute the upgrade command corresponding to each target upgrade firmware block in the firmware to be upgraded, and upgrade the firmware to be upgraded.
7. A block difference upgrade package generation device, characterized in that, Including: A first acquisition module for acquiring the source firmware and the target upgrade firmware of the firmware to be upgraded; A calculation module for calculating the full-difference package of the source firmware and the target upgrade firmware, where the full-difference package includes control information, differential information, and unique information; A block processing module for performing block processing on the source firmware data and the target upgrade firmware data according to the target block size to obtain a plurality of block data of the source firmware and a plurality of block data of the target upgrade firmware. Each block data of the source firmware includes a corresponding block identifier, and each block data of the target upgrade firmware includes a corresponding block identifier; A second acquisition module for acquiring a plurality of control triple commands in the control information. Each control triple command includes first control information and second control information. The first control information represents the same information and differential information between the source firmware and the target upgrade firmware, and the second control information represents the unique information of the target upgrade firmware; A first decomposition module for decomposing each first control information according to the identifier corresponding to each target upgrade firmware block, the identifier corresponding to each source firmware block, the target block size, and the operation step length to obtain third control information corresponding to each target upgrade firmware block. The third control information represents the same information and differential information in each target upgrade firmware block and the corresponding source firmware block; A second decomposition module for decomposing each second control information according to the block identifier corresponding to the block data of each target upgrade firmware, the target block size, and the operation step length to obtain fourth control information corresponding to each target upgrade firmware block. The fourth control information is used to represent the same information and differential information in each target upgrade firmware block and the corresponding source firmware block; A first determination module for determining the differential information and unique information corresponding to each target upgrade firmware block according to the third control information, the fourth control information, the differential information, and the unique information; A generation module for generating a differential upgrade package corresponding to each target upgrade firmware block according to the third control information, the fourth control information, and the differential information and unique information corresponding to each target upgrade firmware block; A second determination module for determining the upgrade sequence of each target upgrade firmware block according to the third control information; A packaging module, configured to package the differential upgrade packages corresponding to the chunks of each target upgrade firmware and the upgrade sequence to obtain a differential upgrade package corresponding to the target upgrade firmware.
8. A block differential upgrade device, characterized in that It includes: A third acquisition module, configured to acquire a target differential upgrade package, where the target differential upgrade package is obtained by the chunk differential upgrade package generation method according to any one of claims 1-5; A reading module, configured to read the upgrade sequence information of each target upgrade firmware chunk in the target differential upgrade package; An upgrade module, configured to execute the upgrade commands corresponding to each target upgrade firmware chunk in the firmware to be upgraded according to the upgrade sequence information of each target upgrade firmware chunk, and upgrade the firmware to be upgraded.
9. An electronic device, characterized in that, It includes: At least one processor; And a memory communicatively connected to the at least one processor; wherein, the memory stores instructions executable by the at least one processor, and when the instructions are executed by the at least one processor, the at least one processor is caused to execute the steps of the chunk differential upgrade package generation method according to any one of claims 1-5, or execute the steps of the chunk differential upgrade method according to claim 6.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the chunk differential upgrade package generation method according to any one of claims 1-5, or implements the steps of the chunk differential upgrade method according to claim 6.
Citation Information
Patent Citations
Firmware upgrading method and device, and terminal
CN111104149A
Differential upgrade package generation method, device and equipment
CN111258620A