Method and computing device for firmware segment decompression

By using a segmented firmware decompression method, the problem of increased storage space and hardware costs during firmware decompression is solved, achieving safe and reliable storage space utilization and cost reduction.

CN115529044BActive Publication Date: 2026-01-13XFUSION DIGITAL TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211214203.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-30
Publication Date
2026-01-13
Estimated Expiration
2042-09-30

AI Technical Summary

Technical Problem

Existing technologies require a large amount of storage space during firmware decompression, which increases hardware costs and carries the risk of decompression failure.

Method used

The firmware segmentation decompression method is adopted. By decompressing multiple segmented compressed packages in the compressed firmware, space is freed up and the segmented firmware is stored. This ensures that the decompressed segmented firmware does not occupy the undecompressed space, thereby saving storage space and reducing hardware costs.

Benefits of technology

It effectively saves storage space, reduces hardware costs, and prevents decompression failures, enabling a safe and reliable firmware decompression process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115529044B_ABST
    Figure CN115529044B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a method and a computing device for firmware segment decompression. A compressed firmware is obtained, each segment compressed package in the compressed firmware is decompressed to obtain each segment firmware, and each segment firmware is combined to form an original firmware. The total data space occupied by decompressing the compressed firmware is less than the sum of the data amount of the compressed firmware and the data amount of the original firmware. In the decompression process, a segment of space is released for each segment firmware decompressed. The segment firmware can be stored in the space released by the segment compressed package that has completed decompression. Therefore, the total data space occupied by decompressing the compressed firmware is less than the sum of the data amount of the compressed firmware and the data amount of the original firmware. Moreover, the space occupied by the segment compressed package that has completed decompression and the segment compressed package that has not completed decompression does not overlap. The segment firmware does not occupy the space of the segment compressed package that has not completed decompression. Therefore, the memory space is saved in the case of safe decompression.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a method and computing device for firmware segmentation and decompression. Background Technology

[0002] Currently, to reduce the storage space occupied by the firmware, the firmware is compressed and the compressed file is signed. During secure boot, the signature of the compressed file is verified first. If the verification is successful, the compressed file is decompressed to obtain the firmware, which is then run.

[0003] When both the signature verification and firmware execution are stored in separate memory, a relatively large amount of memory space is required during the decompression process to prevent the space occupied by the compressed file from being overwritten, which increases hardware costs.

[0004] Therefore, how to save storage space while safely decompressing is an urgent problem to be solved. Summary of the Invention

[0005] This application provides a method and computing device for segmented decompression of firmware. After obtaining compressed firmware, multiple segmented compressed packages in the compressed firmware are decompressed to obtain multiple segmented firmware. During the segmented decompression of the segmented firmware, each segmented compressed package can release a segment of space. The segmented firmware can be stored in the space released by the decompressed segmented compressed package. Therefore, the total data space occupied by decompressing the compressed firmware is less than the sum of the data volume of the compressed firmware and the data volume of the original firmware, thereby saving storage space and reducing hardware costs.

[0006] In a first aspect, embodiments of this application provide a method for firmware segmented decompression, including:

[0007] Obtain compressed firmware, which includes multiple segmented compressed packages, each segmented compressed package corresponding to a firmware segment;

[0008] The multiple segmented compressed packages are decompressed to obtain multiple segmented firmware, and the multiple segmented firmware are combined to form the original firmware; wherein, the total data space occupied by decompressing the compressed firmware is less than the sum of the data size of the compressed firmware and the data size of the original firmware.

[0009] The firmware segmented decompression method provided in this application involves obtaining compressed firmware and then decompressing multiple segmented compressed packages within it to obtain multiple segmented firmware files. During the segmented decompression process, each decompressed segment releases a portion of space, which can then be stored within the space released by the decompressed segments. Therefore, the total data space occupied by decompressing the compressed firmware is less than the sum of the data size of the compressed firmware and the original firmware, thus saving storage space and reducing hardware costs. Furthermore, the spaces occupied by decompressed and incompletely decompressed segmented packages do not overlap, preventing decompression failure and saving memory space while ensuring safe decompression, thereby reducing hardware costs.

[0010] Optionally, the plurality of segmented compressed packages includes a first compressed package and a second compressed package; the decompression of the plurality of segmented compressed packages specifically includes:

[0011] After decompressing the first compressed package in the first data space, the second data space occupied by the first compressed package is released; the data space that the second compressed package can occupy when decompressing is the second data space plus the first data space minus the data space occupied by the decompressed first compressed package; the capacity of the first data space is less than the data volume of the original firmware.

[0012] The firmware segmented decompression method provided in this embodiment decompresses the first compressed package in the first data space and then releases the second data space occupied by the first compressed package. When the second compressed package is decompressed, the data space that can be occupied is the second data space and the data space occupied by the first compressed package after decompression in the first data space. Since the second compressed package can occupy the second data space corresponding to the first compressed package when it is decompressed, the capacity of the first data space is smaller than the capacity of the original firmware, thereby achieving the purpose of saving storage space.

[0013] Optionally, the data size of the first compressed package is greater than or equal to the data size of the second compressed package.

[0014] The firmware segmentation decompression method provided in this embodiment allows the segmented firmware obtained after decompressing the second compressed package to be stored entirely within the second data space occupied by the first compressed package, thus saving storage space. If the data volume of the first compressed package is greater than or equal to the data volume of the second compressed package, the segmented firmware obtained after decompression of the second compressed package can be stored entirely within the second data space occupied by the first compressed package.

[0015] Optionally, before obtaining the compressed firmware, the method further includes:

[0016] The original firmware is divided into multiple firmware segments, each of the multiple firmware segments is compressed to generate multiple segmented compressed packages, and the multiple segmented compressed packages are assembled to generate the compressed firmware.

[0017] The firmware segmentation decompression method provided in this embodiment compresses the firmware into segments to generate compressed firmware. Then, when the original firmware needs to be run, the various segmented compressed packages of the compressed firmware can be decompressed to form segmented firmware. Since each segment is decompressed and a segment of space is released during the process of forming segmented firmware, the segmented firmware can occupy the space where the decompressed segmented compressed packages are located, thereby saving memory space.

[0018] Optionally, after assembling the multiple segmented compressed packages to generate the compressed firmware, the method further includes:

[0019] Sign the compressed firmware;

[0020] The decompression of multiple segmented compressed packages specifically includes:

[0021] The signature of the compressed firmware is verified, and after successful verification, the multiple segmented compressed packages are decompressed.

[0022] The firmware segmentation decompression method provided in this embodiment signs the compressed firmware after it is generated, thereby improving the security of the compressed firmware.

[0023] Optionally, the step of dividing the original firmware into multiple firmware segments, compressing each of the multiple firmware segments to generate the multiple segmented compressed packages, and assembling the multiple segmented compressed packages to generate the compressed firmware specifically includes:

[0024] The original firmware is divided into multiple firmware segments, each segment is labeled, each segment is compressed to generate a segmented compressed package, and the segmented compressed packages are assembled according to the labels of each original firmware segment to generate the compressed firmware.

[0025] The firmware segmentation decompression method provided in this embodiment divides the original firmware into segments to form segmented firmware. Each segment of the original firmware is then labeled so that the corresponding segmented compressed packages can be combined according to the labels to form compressed firmware, thereby improving the accuracy of the formed compressed firmware.

[0026] Optionally, the combination of the multiple segmented firmware to form the original firmware specifically includes:

[0027] The original firmware is formed by sequentially combining the multiple segment firmwares according to the corresponding labels of each segment firmware.

[0028] The firmware segment decompression method provided in this embodiment decompresses the segmented compressed package and then combines the segmented firmware sequentially according to the corresponding number of each segment to form the original firmware, thereby improving the accuracy of the formed original firmware.

[0029] Optionally, dividing the original firmware into multiple firmware segments specifically includes:

[0030] The memory is pre-divided into multiple spatial regions;

[0031] The original firmware is segmented according to the capacity of the multiple spatial regions.

[0032] The firmware segmentation and decompression method provided in this embodiment pre-divides the memory into multiple spatial regions so that the original firmware can be segmented according to each spatial region of the memory.

[0033] Optionally, the plurality of spatial regions include a first spatial region and a second spatial region, wherein the capacity of the first spatial region is greater than or equal to the capacity of the second spatial region, and the capacity of the second spatial region is greater than or equal to the capacity of the other spatial regions in the plurality of spatial regions except the first spatial region;

[0034] The segmentation of the original firmware based on the capacity of the multiple spatial regions includes:

[0035] When the amount of data in the original firmware is greater than the capacity of the first spatial region, a first firmware segment is divided from the original firmware and stored in the first spatial region, and the amount of data in the first firmware segment is equal to the capacity of the first spatial region.

[0036] When the amount of data in the original firmware excluding the first firmware segment is less than or equal to the capacity of the second space region, the data in the original firmware excluding the first firmware segment is stored in the second space region.

[0037] The firmware segmentation decompression method provided in this embodiment involves dividing the original firmware into a first segment when the data volume of the original firmware is greater than the capacity of the first space region. The data volume of the first segment is equal to the capacity of the first space region. Then, the data of the original firmware excluding the first segment is further divided. When the data volume of the original firmware excluding the first segment is less than or equal to the capacity of the second space region, the data of the original firmware excluding the first segment is stored in the second space region. Thus, the original firmware is stored in the first and second space regions of the memory according to the space regions of the memory.

[0038] Optionally, the plurality of spatial regions further includes a third spatial region, the capacity of which is greater than or equal to the capacity of the other spatial regions in the plurality of spatial regions excluding the first spatial region and the second spatial region;

[0039] When the amount of data in the original firmware excluding the first firmware is greater than the capacity of the second space region, a second firmware segment is divided from the data in the original firmware excluding the first firmware segment and stored in the second space region. The amount of data in the second firmware segment is equal to the capacity of the second space region.

[0040] When the amount of data in the original firmware excluding the first and second firmware segments is less than or equal to the capacity of the third space region, the data in the original firmware excluding the first and second firmware segments is stored in the third space region.

[0041] The firmware segmentation decompression method provided in this embodiment divides the data of the original firmware after the first firmware segment into a second firmware segment and stores it in the second space area when the data of the original firmware after the first firmware segment is greater than the capacity of the second space area. When the data of the original firmware after the first firmware segment and the second firmware segment is less than or equal to the capacity of the third space area, the data of the original firmware after the first firmware segment and the second firmware segment is stored in the third space area. Thus, the original firmware is stored in the first space area and the second space area of ​​the memory according to the space area of ​​the memory.

[0042] Optionally, after assembling the multiple segmented compressed packages to generate compressed firmware, the method further includes:

[0043] An identifier is added before the compressed firmware to indicate the start position of the compressed firmware.

[0044] The firmware segmentation decompression method provided in this embodiment adds an identifier before the compressed firmware after it is generated. The identifier is used to indicate the start position of the compressed firmware, thereby accurately obtaining the compressed firmware.

[0045] Secondly, embodiments of this application provide a computing device, the computing device comprising: a processor and a memory, wherein the processor is connected to the memory;

[0046] The processor is used to obtain compressed firmware, decompress multiple segmented compressed packages in the compressed firmware, obtain multiple segmented firmware, and then combine the multiple segmented firmware to form the original firmware.

[0047] The memory is used to store the compressed firmware and the original firmware.

[0048] The firmware segmented decompression method provided in this application obtains compressed firmware, which includes multiple segmented compressed packages. Each segmented compressed package corresponds to a segment of firmware. The method decompresses the multiple segmented compressed packages within the compressed firmware to obtain multiple segmented firmware files, which are then combined to form the original firmware. Since each segmented compressed package released during the decompression process frees up space, the segmented firmware can be stored within the space freed up by the decompressed segmented compressed packages. Therefore, the total data space occupied by decompressing the compressed firmware is less than the sum of the data size of the compressed firmware and the original firmware, achieving the goal of saving storage space and reducing hardware costs. Furthermore, the spaces occupied by the decompressed segmented compressed packages and the undecompressed segmented compressed packages do not overlap, and the segmented firmware will not occupy the space occupied by the undecompressed segmented compressed packages, preventing decompression failure. This allows for safe decompression while saving memory space and reducing hardware costs. Attached Figure Description

[0049] To more clearly illustrate the technical solutions in this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0050] Figure 1 This is a flowchart of a firmware segmentation decompression method provided in an embodiment of this application;

[0051] Figures 2-4 This is a schematic diagram of the structure of a segmented firmware and a segmented compressed package provided in an embodiment of this application;

[0052] Figure 5 This is a flowchart of another firmware segmentation decompression method provided in the embodiments of this application;

[0053] Figures 6-8 This is a schematic diagram of a memory storage segment firmware provided in an embodiment of this application;

[0054] Figure 9 This is a flowchart of another firmware segmentation decompression method provided in the embodiments of this application;

[0055] Figure 10 This is a flowchart of another firmware segmentation decompression method provided in the embodiments of this application. Detailed Implementation

[0056] The terminology used in the implementation section of this application is for the purpose of explaining specific embodiments of this application only, and is not intended to limit this application.

[0057] To facilitate understanding, the relevant technical terms involved in the embodiments of this application will first be explained and described.

[0058] Firmware: A binary executable file that runs in DDR (also known as DDR SDRAM, Double Data Rate Synchronous Dynamic Random Access Memory) or SRAM (Static Random Access Memory) and connects the hardware and operating system when the computer starts up.

[0059] Before firmware runs, it typically undergoes security verification. Secure boot refers to verifying the firmware after it has been read into memory before starting the firmware. Signature verification can be performed in shared DDR or SRAM, or firmware can run in independent DDR or SRAM. However, verification in shared DDR or SRAM is less secure and more vulnerable to attack.

[0060] Therefore, signature verification and firmware execution can be performed in separate DDR or SRAM. However, when both signature verification and firmware execution are in separate DDR or SRAM, during the decompression process...

[0061] To prevent the compressed file's storage space from being overwritten during decompression, a larger DDR or SRAM space can be used to prevent the compressed file's storage space from overlapping with the decompressed file's storage space, but this increases hardware costs.

[0062] Based on this, this application provides a method for segmented decompression of firmware. The method obtains compressed firmware, which includes multiple segmented compressed packages, each corresponding to a segment of firmware. The multiple segmented compressed packages within the compressed firmware are decompressed to obtain individual segmented firmware. Each decompression of a firmware segment releases a segment of space. The segmented firmware can be stored within the space released from the decompressed segmented compressed packages. Therefore, the total data space occupied by decompressing the compressed firmware is less than the sum of the data size of the compressed firmware and the original firmware, achieving the goal of saving storage space and reducing hardware costs. Furthermore, since the space where the segmented firmware resides does not overlap with the space where the undecompressed segmented compressed packages reside, the segmented firmware will not occupy the space of the undecompressed segmented compressed packages, preventing decompression failure. This allows for safe decompression while saving memory space and reducing hardware costs.

[0063] The firmware segmentation decompression method provided in this application embodiment will be described in detail below through specific implementation methods.

[0064] Figure 1 This is a flowchart illustrating a method for segmented decompression of firmware according to an embodiment of this application. (See reference...) Figure 1 As shown, the firmware segmentation decompression method provided in this application embodiment includes:

[0065] S101. Obtain compressed firmware. The compressed firmware includes multiple segmented compressed packages, and each segmented compressed package corresponds to a piece of firmware.

[0066] Retrieve compressed firmware from memory. The compressed firmware consists of multiple segmented compressed packages, each obtained by compressing a segmented firmware, which in turn is derived from segments of the original firmware. (Reference) Figure 2 As shown, the compressed firmware can include N segmented compressed packages, namely bin1, bin2, ..., binN, where N is a positive integer greater than 1.

[0067] refer to Figure 2 As shown, when the memory is used to store firmware, the memory space can include firmware space and blank space. Firmware space is the space occupied by the original firmware, and blank space can be unused space. The firmware space here can include multiple regions, each used to store a segment of firmware from the original firmware. (Reference) Figure 3 As shown, when the memory is used to run firmware, the memory space can include firmware space, blank space, and space occupied by the decompression program. The firmware space can include multiple regions, each region used to store a segmented compressed package in the compressed firmware. The space occupied by the decompression program is used to store the decompression program, which is used to decompress the compressed firmware. The memory can be, for example, DDR or SRAM.

[0068] S102. Decompress multiple segmented compressed packages to obtain multiple segmented firmware, and combine the multiple segmented firmware to form the original firmware.

[0069] The compressed firmware is decompressed segment by segment sequentially. Each decompressed segment releases a corresponding space, allowing the resulting segmented firmware to be stored within the space occupied by the decompressed segment. The total data space occupied during decompression is less than the sum of the compressed firmware's data size and the original firmware's data size, saving storage space. The spaces occupied by undecompressed and decompressed segmented firmware segments do not overlap, ensuring that the space occupied by undecompressed segmented firmware is not occupied and preventing decompression failure. (Reference) Figure 2 As shown, the memory includes a decompression program, which is used to decompress the compressed firmware, that is, to decompress each segmented compressed package.

[0070] In some embodiments, the multiple segmented compressed packages include a first compressed package and a second compressed package. After the first compressed package is decompressed in the first data space, the second data space occupied by the first compressed package is released. When the second compressed package is decompressed, it can occupy the second data space released by the second compressed package, and it can also occupy the data space in the first data space excluding the data space occupied by the decompressed first compressed package. This makes the first data space smaller than the data size of the original firmware, thereby saving memory space.

[0071] For example, if the data size of the first compressed package is greater than or equal to the data size of the second compressed package, then after the second compressed package is decompressed, it can be entirely stored in the second data space occupied by the first compressed package.

[0072] refer to Figure 3 As shown, the segmented compressed package includes compressed bin1, compressed bin2, ..., compressed binN. After decompressing compressed bin1 to obtain bin1, the space occupied by compressed bin1 can be used, but the space occupied by compressed bin2, compressed bin3, ..., compressed binN will not be occupied. Similarly, after decompressing compressed bin2 to obtain bin2, the space occupied by compressed bin2 can be used, but the space occupied by compressed bin3, ..., compressed binN will not be occupied, and so on. After decompressing compressed binN-1 to obtain binN-1, the space occupied by compressed binN-1 can be used, but the space occupied by compressed binN will not be occupied.

[0073] For example, if the original firmware's compressed file is 72k and the decompressed file is 88k, directly decompressing the entire compressed file would require at least 160k of space to prevent the compressed and decompressed files from overlapping. However, if the compressed firmware consists of two segments, 64k and 8k, after the 64k segment is decompressed, the 8k segment can occupy the space previously occupied by the 64k segment. This saves storage space, reduces hardware costs, and prevents the decompressed firmware from occupying the space previously occupied by the undecompressed segment.

[0074] Each segmented compressed package is decompressed to obtain the corresponding segmented firmware. These segmented firmware are then combined to form the original firmware. Optionally, the segmented firmware can be combined sequentially according to the segmented compressed package labels to form the original firmware. For example, if the compressed firmware includes N segmented compressed packages, labeled bin1, bin2, ..., binN, with bin1 labeled as 1, bin2 labeled as 2, ..., and binN labeled as N, then bin1 is decompressed to obtain segmented firmware bin1, bin2 is decompressed segmentally to obtain segmented firmware bin2, ..., and binN is decompressed segmentally to obtain segmented firmware binN. During decompression, the labels of each compressed bin are retained, and the segmented firmware corresponding to each compressed bin is combined sequentially according to their labels to form the original firmware, for example, combining bin1, bin2, ..., binN to form the original firmware.

[0075] Optional, see reference Figure 4 As shown, the memory can also store an identifier header, which indicates the starting position of the compressed firmware. When the compressed firmware includes a signature, the memory can include a verification program to verify the compressed firmware. After verification, a decompression program is used to decompress the segmented compressed packages in the compressed firmware.

[0076] The firmware segmentation decompression method provided in this application decompresses multiple segmented compressed packages in compressed firmware to obtain individual segmented firmware. Each decompressed firmware segment releases a space, and the segmented firmware is stored in the space of the decompressed segmented compressed package. Multiple segmented firmware are combined to form the original firmware. Because the segmented firmware can occupy the space of the decompressed segmented compressed package during the decompression process, and the space of the decompressed segmented compressed package and the space of the undecompressed segmented compressed package do not overlap, the segmented firmware will not occupy the space of the undecompressed segmented compressed package, preventing decompression failure, saving memory space, and reducing hardware costs.

[0077] Figure 5 A flowchart illustrating a firmware segmentation compression method according to an embodiment of this application. (See reference...) Figure 5 As shown, the firmware segmentation compression method provided in this application includes:

[0078] S201. Divide the original firmware into multiple firmware segments, compress each firmware segment to generate multiple segmented compressed packages, and assemble the multiple segmented compressed packages to generate compressed firmware.

[0079] The original firmware is divided into N segments, where N is a positive integer greater than 1, denoted as bin1, bin2, ..., binN. When segmenting the original firmware, the segmentation can be based on the storage capacity of each region of the memory. For example, the memory space can be divided into M regions according to their storage capacity from largest to smallest, where M is a positive integer greater than 1, such as region 1, region 2, ..., region M. Adjacent regions can have the same or different storage capacities. Regions located earlier in the sequence have larger storage capacities, and regions located later in the sequence have smaller storage capacities; for example, the storage capacity of region 1 is greater than that of region M.

[0080] Optionally, if the capacity of the original firmware is greater than or equal to the maximum storage capacity of each region, the original firmware is divided into segments, and the capacity of this segment is equal to the maximum storage capacity. If the capacity of the original firmware is less than the maximum storage capacity of each region, the original firmware may not be segmented. After dividing the original firmware into segments, and ensuring that the capacity of this segment is equal to the maximum storage capacity, the remaining capacity of the original firmware is compared with the next storage capacity until the remaining capacity of the original firmware is less than or equal to the minimum storage capacity, at which point the original firmware is no longer segmented.

[0081] The memory can be pre-divided into multiple regions, some of which may have the same or different capacities. The specific region division can be determined based on the actual situation and is not limited here.

[0082] In some embodiments, the multiple spaces include a first space region and a second space region. The capacity of the first space region is greater than or equal to the capacity of the second space region, and the capacity of the second space region is greater than or equal to the capacity of the other space regions besides the first space region. Therefore, when the data volume of the original firmware is greater than the capacity of the first space region, a first firmware segment with a capacity equal to that of the first space region can be extracted from the original firmware. When the data volume of the original firmware excluding the first firmware segment is less than or equal to the capacity of the second space region, the data of the original firmware excluding the first firmware segment is stored in the second space region, thereby storing the original firmware in the first and second space regions of the memory according to the memory's space regions.

[0083] Multiple spatial regions may also include a third spatial region, the capacity of which is greater than or equal to the capacity of the other spatial regions excluding the first and second spatial regions. When the capacity of the original firmware excluding the first firmware segment is greater than the capacity of the second spatial region, a second firmware segment is partitioned from the data of the original firmware excluding the first firmware segment and stored in the second spatial region. The data size of the second firmware segment is equal to the capacity of the second spatial region. Then, the remaining data in the original firmware excluding the first and second firmware segments are further partitioned. When the data size of the original firmware excluding the first and second firmware segments is less than or equal to the capacity of the third spatial region, the data of the original firmware excluding the first and second firmware segments is stored in the third spatial region. Thus, the original firmware is stored in the first, second, and third spatial regions of the memory according to the memory's spatial regions.

[0084] The memory comprises nine regions, which will be described in detail below. (See reference...) Figure 6 As shown, the nine regions are designated as Region 1, Region 2, Region 3, Region 4, Region 5, Region 6, Region 7, Region 8, and Region 9. The storage capacity of Region 1, Region 2, and Region 3 is the first capacity, the storage capacity of Region 4 is the second capacity, the storage capacity of Region 5 is the third capacity, the storage capacity of Region 6 is the fourth capacity, the storage capacity of Region 7 is the fifth capacity, and the storage capacity of Region 8 and Region 9 is the sixth capacity.

[0085] The initial capacity of the original firmware is compared with the first capacity of the first region. If the initial capacity of the original firmware is greater than or equal to the first capacity, the original firmware is divided into bin1, the capacity of bin1 is equal to the first capacity, the first remaining capacity of the original firmware is equal to the initial capacity minus the first capacity, and bin1 is stored in the first region.

[0086] If the first remaining capacity of the original firmware is greater than or equal to the first capacity, the original firmware is divided into bin2, and the capacity of bin2 is equal to the first capacity. The second remaining capacity of the original firmware is equal to the first remaining capacity minus the first capacity. That is, the second remaining capacity of the original firmware is equal to the initial capacity of the original firmware minus two first capacities. The second area stores bin2.

[0087] When the second remaining capacity of the original firmware is equal to the initial capacity of the original firmware minus two first capacities, the second remaining capacity of the original firmware is compared with the first capacity of the second region. If the second remaining capacity of the original firmware is still greater than or equal to the first capacity, the original firmware is divided into bin3, and the capacity of bin3 is equal to the first capacity. The third remaining capacity of the original firmware is equal to the second remaining capacity minus the first capacity. That is, the third remaining capacity of the original firmware is equal to the initial capacity of the original firmware minus three first capacities. The third region stores bin3.

[0088] When the third remaining capacity of the original firmware equals the initial capacity of the original firmware minus three first capacities, the third remaining capacity of the original firmware is compared with the first capacity of the third region. If the third remaining capacity is less than the first capacity, the third remaining capacity is compared with the second capacity of the fourth region. If the third remaining capacity is less than the second capacity, the third remaining capacity is compared with the third capacity of the fifth region. If the third remaining capacity is greater than or equal to the third capacity, the original firmware is divided into bin4, and the capacity of bin4 is equal to the third capacity. The fourth remaining capacity of the original firmware is equal to the third remaining capacity minus the third capacity. That is, the fourth remaining capacity of the original firmware is equal to the initial capacity of the original firmware minus three first capacities and one third capacity. The fifth region stores bin4.

[0089] When the fourth remaining capacity of the original firmware is equal to the initial capacity of the original firmware minus three first capacities and one third capacity, the fourth remaining capacity of the original firmware is compared with the fourth capacity of the sixth region. If the fourth remaining capacity is greater than or equal to the fourth capacity, the original firmware is divided into bin5, and the capacity of bin5 is equal to the fourth capacity. The fifth remaining capacity of the original firmware is equal to the fourth remaining capacity of the original firmware minus the fourth capacity. That is, the fifth remaining capacity of the original firmware is equal to the initial capacity of the original firmware minus three first capacities, one third capacity and one fourth capacity. The sixth region stores bin5.

[0090] When the fifth remaining capacity of the original firmware is equal to the initial capacity of the original firmware minus three first capacities, one third capacity, and one fourth capacity, the fifth remaining capacity of the original firmware is compared with the fifth capacity of the seventh region. If the fifth remaining capacity is greater than or equal to the fifth capacity, the original firmware is divided into bin6, and the capacity of bin6 is equal to the fifth capacity. The sixth remaining capacity of the original firmware is equal to the fifth remaining capacity minus the fifth capacity. The sixth remaining capacity of the original firmware is equal to the initial capacity of the original firmware minus three first capacities, one third capacity, one fourth capacity, and one fifth capacity. The seventh region stores bin6.

[0091] When the sixth remaining capacity of the original firmware is equal to the initial capacity of the original firmware minus three first capacities, one third capacity, one fourth capacity, and one fifth capacity, the sixth remaining capacity of the original firmware is compared with the sixth capacity of the eighth region. If the sixth remaining capacity is greater than or equal to the sixth capacity, the original firmware is divided into bin7, and the capacity of bin7 is equal to the sixth capacity. The seventh remaining capacity of the original firmware is equal to the sixth remaining capacity of the original firmware minus the sixth capacity. The seventh remaining capacity of the original firmware is equal to the initial capacity of the original firmware minus three first capacities, one third capacity, one fourth capacity, one fifth capacity, and one sixth capacity. The eighth region stores bin7.

[0092] When the seventh remaining capacity of the original firmware is equal to the initial capacity of the original firmware minus three first capacities, one third capacity, one fourth capacity, one fifth capacity, and one sixth capacity, the seventh remaining capacity of the original firmware is compared with the sixth capacity of the ninth region. If the seventh remaining capacity is less than or equal to the sixth capacity, the original firmware is divided into bin8, and the capacity of bin8 is equal to the seventh remaining capacity. The ninth region stores bin8.

[0093] As shown above, the various segmented firmware in the original firmware occupy the first, second, third, fifth, sixth, seventh, eighth, and ninth regions of the memory, respectively. It should be noted that each region of the memory can be used to store segmented firmware, or it can be temporarily left unused; the specific choice depends on the size of the segmented firmware. The segmented firmware can be unevenly divided during the segmentation process to further prevent data loss.

[0094] For example, the memory space is 256k, refer to Figure 7 As shown, the memory space is divided into nine regions. Regions 1, 2, and 3 each have a storage capacity of 64k; region 4 has a storage capacity of 32k; region 5 has a storage capacity of 16k; region 6 has a storage capacity of 8k; region 7 has a storage capacity of 4k; and regions 8 and 9 each have a storage capacity of 2k. For example, if the original firmware size is 223k, it can be divided into eight segments: bin1 (64k) occupies region 1; bin2 (64k) occupies region 2; bin3 (64k) occupies region 3; bin4 (16k) occupies region 5; bin5 (8k) occupies region 6; bin6 (4k) occupies region 7; bin7 (2k) occupies region 8; and bin8 (1k) occupies region 9.

[0095] The original firmware is divided into N segments: bin1, bin2, ..., binN-1 and binN. Each segment is compressed sequentially. Compressing bin1 yields compressed bin1, compressing bin2 yields compressed bin2, ..., and compressing binN yields compressed binN. The compression algorithm used for each segment can be determined based on specific needs and is not limited here. For example, the LZMA (Lempel-Ziv-Markov chain-Algorithm) algorithm can be used.

[0096] refer to Figure 8 As shown, Figure 8The compressed segmented firmware occupies the following space: Bin1 is compressed to 64KB, Bin2 to 64KB, Bin3 to 17646B, Bin4 to 6930B, Bin5 to 4096B, Bin6 to 2048B, Bin7 to 2048B, and Bin8 to 1024B. The total space occupied by compressed bin1 through compressed bin7 is 161KB. Compared to... Figure 7 The original firmware in the file can be segmented and compressed to save 62k of space, which can increase the size of the original firmware.

[0097] Compressed firmware is composed of compressed bin1, compressed bin2, ..., compressed binN. For example, compressed firmware is composed of compressed bin1, compressed bin2, ..., compressed binN in sequence according to their labels, where compressed bin1 is labeled as 1, compressed bin2 is labeled as 2, ..., and compressed binN is labeled as N.

[0098] Optionally, after segmenting the original firmware, each segment can be labeled. After compressing each segment, the label of each segment can be retained, and the compressed firmware can be assembled according to the labels of each segment. For example, bin1 is labeled as 1, bin2 as 2, ..., binN as N. After compressing bin1, compressed bin1 is obtained, and compressed bin1 is labeled as 1. After compressing bin2, compressed bin2 is obtained, and compressed bin2 is labeled as 2, ..., after compressing binN, compressed binN is obtained, and compressed bin is labeled as N. The compressed firmware is assembled according to the labels of each compressed bin.

[0099] It should be noted that firmware can be stored in binary form within a binary executable file, so compressing firmware can be done by compressing the binary executable file.

[0100] Optional, see reference Figure 2 As shown, an identifier header can be added before the compressed firmware. Since the compressed firmware includes multiple compressed bin1s, an identifier header is added before each compressed bin1, indicating the start position of the compressed firmware. After the compressed firmware is formed, it can be signed to ensure its security and integrity. This allows other storage devices to obtain the signature of the compressed firmware and verify whether it has been tampered with.

[0101] For example, firmware running in a separate memory mainly includes two stages: compilation and firmware execution. In the compilation and execution stage, the raw firmware generated by compilation is divided into multiple segments, and the segmented firmware is compressed to generate segmented compressed packages. The various segmented compressed packages are then assembled to form compressed firmware.

[0102] S202. Decompress multiple segmented compressed packages in the compressed firmware to obtain segmented firmware, and combine multiple segmented firmware to form the original firmware.

[0103] The multiple segmented compressed packages in the compressed firmware are decompressed sequentially. For the segmented compressed packages that have been decompressed, their space can be occupied to save storage space. For the segmented compressed packages that have not been decompressed, their space cannot be occupied to prevent decompression failure.

[0104] After decompressing each segment of the compressed package to obtain the individual segment firmware, the individual segment firmware is combined to form the original firmware.

[0105] For example, during the firmware runtime phase, the various segmented compressed packages in the compressed firmware can be decompressed to obtain segmented firmware, the various segmented components can be combined to form the original firmware, and then the original firmware can be run.

[0106] Optionally, the signature of the compressed firmware can be verified first. After the verification is successful, the compressed firmware can be decompressed to obtain the segmented firmware, which can then be assembled and run. This ensures that security verification and firmware operation are both in independent memory, preventing external tampering and improving the security of firmware operation.

[0107] The firmware segmented decompression method provided in this application compresses the firmware into segments to generate compressed firmware. Then, when the original firmware needs to be run, each segment of the compressed firmware is decompressed to form segmented firmware. The segmented firmware is then combined to form the original firmware. During the segmented decompression process, each segment of firmware is decompressed and releases a segment of space. The segmented firmware occupies the space of the decompressed segmented compressed package. Since the space of the decompressed segmented compressed package and the space of the undecompressed segmented compressed package do not overlap, the segmented firmware will not occupy the space of the undecompressed segmented compressed package, preventing decompression failure and thus saving memory space to complete firmware loading and updating within limited resources.

[0108] Figure 9 This is a flowchart illustrating a method for segmented decompression of firmware according to an embodiment of this application. (See reference...) Figure 9 As shown, the firmware segmentation decompression method provided in this application embodiment includes:

[0109] S301. Obtain compressed firmware. The compressed firmware includes multiple segmented compressed packages, and each segmented compressed package corresponds to a firmware segment.

[0110] The compressed firmware is retrieved from the memory. The compressed firmware consists of multiple segmented compressed packages, each of which is obtained by compressing a segmented firmware. Each segmented firmware is obtained by segmenting the original firmware.

[0111] S302. Decompress multiple segmented compressed packages to obtain multiple segmented firmware, and combine the multiple segmented firmware to form the original firmware.

[0112] The compressed firmware is decompressed segment by segment sequentially. The space occupied by the decompressed segment can be used to save storage space, while the space occupied by the undecompressed segment will not be used to prevent decompression failure.

[0113] For example, a segmented compressed archive includes compressed bin1, compressed bin2, ..., compressed binN. After decompressing compressed bin1 to obtain bin1, the space occupied by compressed bin1 can be used, but the space occupied by compressed bin2, compressed bin3, ..., compressed binN will not be occupied. Similarly, after decompressing compressed bin2 to obtain bin2, the space occupied by compressed bin2 can be used, but the space occupied by compressed bin3, ..., compressed binN will not be occupied, and so on. Likewise, after decompressing compressed binN-1 to obtain binN-1, the space occupied by compressed binN-1 can be used, but the space occupied by compressed binN will not be occupied.

[0114] Each segmented compressed package is decompressed to obtain the corresponding segmented firmware. For example, decompressing bin1 yields bin1, bin2 yields bin2, bin3 yields bin3, and so on, until binN yields binN. Then, these segmented firmwares are combined to form the original firmware.

[0115] S303, running the original firmware.

[0116] After obtaining the original firmware, run the original firmware.

[0117] The firmware segmented decompression method provided in this application decompresses each segmented compressed package in the compressed firmware to obtain each segmented firmware, combines the segmented firmware to form the original firmware, and then runs the original firmware. Because the segmented firmware can occupy the space of the already decompressed segmented compressed packages during the decompression process, without occupying the space of the undecompressed segmented compressed packages, decompression failure is prevented, while also saving memory space and reducing hardware costs.

[0118] Figure 10 This is a flowchart illustrating a method for segmented decompression of firmware according to an embodiment of this application. (See reference...) Figure 10As shown, the firmware segmentation decompression method provided in this application embodiment includes:

[0119] S401, Generate the original firmware.

[0120] Compile the program code based on the functions to be implemented to generate the original firmware.

[0121] S402. Divide the original firmware into multiple firmware segments, compress each firmware segment to generate a segmented compressed package, and assemble multiple segmented compressed packages to generate compressed firmware.

[0122] The compiled raw firmware can be divided into multiple segments to generate multi-segment firmware, and each segment firmware can be compressed to generate a segmented compressed package.

[0123] For example, the original firmware can be divided into N segments, where N is a positive integer greater than 1, and denoted as bin1, bin2, ..., binN respectively.

[0124] Then, the various segmented compressed packages are assembled to generate compressed firmware.

[0125] S403. Sign the compressed firmware to generate a signed compressed firmware.

[0126] After generating compressed firmware, it can be signed to generate signed compressed firmware, thereby improving the security of the compressed firmware.

[0127] It should be noted that the steps S401, S402 and S403 mentioned above can be understood as the firmware compilation and building phase.

[0128] S404. Obtain the signed compressed firmware and verify the signature.

[0129] After obtaining the signed compressed firmware, first verify the signature of the compressed firmware.

[0130] S405. After the signature verification is passed, the multiple segmented compressed packages in the compressed firmware are decompressed to obtain multiple segmented firmware, and the multiple segmented firmware are combined to form the original firmware.

[0131] S406, running the original firmware.

[0132] It should be noted that the steps S404, S405 and S406 mentioned above can be understood as the firmware operation phase.

[0133] The firmware segmented decompression method provided in this application, after generating the original firmware, segments the original firmware to generate compressed firmware, and signs the compressed firmware. Then, when the original firmware needs to be run, the signature of the compressed firmware is first verified. After the verification is successful, each segmented compressed package in the compressed firmware is decompressed to form segmented firmware. The segmented firmware is then combined to form the original firmware. During the segmented decompression process, the segmented firmware occupies the space of the segmented compressed packages that have been decompressed. The space of the segmented compressed packages that have been decompressed and the space of the segmented compressed packages that have not been decompressed do not overlap. The segmented firmware will not occupy the space of the segmented compressed packages that have not been decompressed, thus preventing decompression failure and saving memory space, so as to complete firmware loading and updating within limited resources.

[0134] This application also provides a computing device, including a processor and a memory communicatively connected to the processor. The memory is used to store computer execution instructions, and the processor is used to implement the above-described firmware segmented decompression method according to the computer execution instructions stored in the memory.

[0135] In the description of this application, it should be noted that, unless otherwise expressly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, an indirect connection through an intermediate medium, or the internal communication between two components or the interaction between two components. Those skilled in the art can understand the specific meaning of the above terms in this application according to the specific circumstances.

[0136] The devices or elements referred to in this application or implied herein must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be construed as limiting this application. In the description of this application, "a plurality of" means two or more, unless otherwise precisely specified.

[0137] The terms “first,” “second,” etc. (if present) in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a particular order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented, for example, in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0138] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.

Claims

1. A method for segmented decompression of firmware, characterized in that, include: The memory is pre-divided into multiple spatial regions; The original firmware is segmented according to the capacity of the multiple spatial regions; Obtain compressed firmware, which includes multiple segmented compressed packages, each segmented compressed package corresponding to a firmware segment; The multiple segmented compressed packages are decompressed to obtain multiple segmented firmware; the segmented firmware is stored in the space released by the decompressed segmented compressed packages; The multiple segmented firmwares are combined to form the original firmware; wherein the total data space occupied by decompressing the compressed firmware is less than the sum of the data size of the compressed firmware and the data size of the original firmware; The plurality of spatial regions include a first spatial region and a second spatial region. The capacity of the first spatial region is greater than or equal to the capacity of the second spatial region, and the capacity of the second spatial region is greater than or equal to the capacity of the other spatial regions in the plurality of spatial regions except the first spatial region. The segmentation of the original firmware based on the capacity of the multiple spatial regions includes: When the amount of data in the original firmware is greater than the capacity of the first spatial region, a first firmware segment is divided from the original firmware and stored in the first spatial region, and the amount of data in the first firmware segment is equal to the capacity of the first spatial region. When the amount of data in the original firmware excluding the first firmware segment is less than or equal to the capacity of the second space region, the data in the original firmware excluding the first firmware segment is stored in the second space region.

2. The method according to claim 1, characterized in that, The plurality of segmented compressed packages includes a first compressed package and a second compressed package; the decompression of the plurality of segmented compressed packages includes: After decompressing the first compressed package in the first data space, the second data space occupied by the first compressed package is released; the data space that the second compressed package can occupy when decompressing is the second data space plus the first data space minus the data space occupied by the decompressed first compressed package; the capacity of the first data space is less than the data volume of the original firmware.

3. The method according to claim 2, characterized in that, The data size of the first compressed package is greater than or equal to the data size of the second compressed package.

4. The method according to claim 1, characterized in that, After segmenting the original firmware according to the capacity of the multiple spatial regions, the method further includes: Each segment of the firmware is compressed separately to generate the multiple segmented compressed packages, and the multiple segmented compressed packages are assembled to generate the compressed firmware.

5. The method according to claim 4, characterized in that, After assembling the multiple segmented compressed packages to generate the compressed firmware, the method further includes: Sign the compressed firmware; The decompression of the multiple segmented compressed packages specifically includes: The signature of the compressed firmware is verified, and after successful verification, the multiple segmented compressed packages are decompressed.

6. The method according to claim 4, characterized in that, The process of dividing the original firmware into multiple firmware segments, compressing each of the multiple firmware segments to generate multiple segmented compressed packages, and assembling the multiple segmented compressed packages to generate the compressed firmware specifically includes: The original firmware is divided into multiple firmware segments, each segment is labeled, each segment is compressed to generate a segmented compressed package, and the segmented compressed packages are assembled according to the labels of each original firmware segment to generate the compressed firmware.

7. The method according to claim 6, characterized in that, The combination of the multiple segmented firmwares to form the original firmware specifically includes: The original firmware is formed by sequentially combining the multiple segment firmwares according to the corresponding labels of each segment firmware.

8. The method according to claim 1, characterized in that, The plurality of spatial regions also includes a third spatial region, the capacity of which is greater than or equal to the capacity of the other spatial regions in the plurality of spatial regions excluding the first spatial region and the second spatial region; When the amount of data in the original firmware excluding the first firmware segment is greater than the capacity of the second space region, a second firmware segment is partitioned from the data in the original firmware excluding the first firmware segment and stored in the second space region. The amount of data in the second firmware segment is equal to the capacity of the second space region. When the amount of data in the original firmware excluding the first and second firmware segments is less than or equal to the capacity of the third space region, the data in the original firmware excluding the first and second firmware segments is stored in the third space region.

9. The method according to any one of claims 4-7, characterized in that, After assembling the multiple segmented compressed packages to generate compressed firmware, the method further includes: An identifier is added before the compressed firmware to indicate the start position of the compressed firmware.

10. A computing device, characterized in that, The computing device includes a processor and a memory, wherein the processor is connected to the memory; The processor is used to pre-divide the memory into multiple spatial regions; The original firmware is segmented according to the capacity of the multiple spatial regions; Obtain compressed firmware, which includes multiple segmented compressed packages, each segmented compressed package corresponding to a firmware segment; The multiple segmented compressed packages are decompressed to obtain multiple segmented firmware; the segmented firmware is stored in the space released by the decompressed segmented compressed packages; The multiple segmented firmwares are combined to form the original firmware; wherein the total data space occupied by decompressing the compressed firmware is less than the sum of the data size of the compressed firmware and the data size of the original firmware; The plurality of spatial regions include a first spatial region and a second spatial region. The capacity of the first spatial region is greater than or equal to the capacity of the second spatial region, and the capacity of the second spatial region is greater than or equal to the capacity of the other spatial regions in the plurality of spatial regions except the first spatial region. The segmentation of the original firmware based on the capacity of the multiple spatial regions includes: When the amount of data in the original firmware is greater than the capacity of the first spatial region, a first firmware segment is divided from the original firmware and stored in the first spatial region, and the amount of data in the first firmware segment is equal to the capacity of the first spatial region. When the amount of data in the original firmware excluding the first firmware segment is less than or equal to the capacity of the second space region, the data in the original firmware excluding the first firmware segment is stored in the second space region. The memory is used to store the compressed firmware and the original firmware.

Citation Information

Patent Citations

  • Method and system for reducing storage requirements during decompressing compressed file

    CN101582067A

  • Firmware compression method and firmware decompression method and device

    CN104636140A