Differential upgrading method for compressed file
By employing a two-stage differential mechanism, unifying file attributes and timestamp settings, and combining fixed compression commands and binary differential algorithms, the problem of metadata volatility in ZIP format upgrade packages is solved. This achieves upgrade package size reduction and byte-level consistency restoration, improving the efficiency and reliability of automotive ECU OTA upgrades.
Patent Information
- Application Number
- CN202610051022.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-15
- Publication Date
- 2026-05-05
AI Technical Summary
The differential processing of existing automotive ECU ZIP format upgrade packages suffers from metadata volatility, making it difficult to accurately restore the hash value of the target version ZIP file after differential processing. This results in excessively long download times for the upgrade package and fails to meet the high consistency requirements of automotive OTA upgrades.
A two-stage differential mechanism is adopted. First, non-content factors are eliminated by unifying file attributes and timestamp settings. Then, a differential file is generated using a fixed compression command and binary differential algorithm to ensure that the restored ZIP file is completely consistent with the original file in terms of hash values such as MD5 and SHA256.
Significantly reduces upgrade package size, shortens download time, ensures upgrade package efficiency and reliability, adapts to the bandwidth-constrained characteristics of in-vehicle scenarios, improves user upgrade experience, and solves the problem of ECU integrity verification failure caused by metadata differences in traditional methods.
Smart Images

Figure CN121979553A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer software and data processing technology, specifically to the OTA (Over-The-Air) upgrade scenario of intelligent connected vehicle ECUs (Electronic Control Units), and particularly to a differential upgrade method for compressed files. Background Technology
[0002] The demand for ECU (Electronic Control Unit) OTA (Over-The-Air) upgrades is becoming increasingly urgent in the field of intelligent connected vehicles. The complete ECU OTA upgrade package is usually provided by the supplier and has two core characteristics: First, the file size is huge, which directly leads to excessive download time and seriously affects user experience and upgrade efficiency; second, the upgrade package is mostly stored in ZIP format to adapt to the storage and transmission requirements of the vehicle system.
[0003] To address the issue of long download times, differential upgrades have become the mainstream technical choice. However, differential processing of automotive ECUZIP format upgrade packages faces multiple technical bottlenecks: the ZIP format specification allows compression tools to introduce non-content-related variables during the generation process, including file timestamps (modification, access, and alteration times), file permissions (Unix external attributes), compression tool identifiers (version madeby), local file header padding bytes, central directory entry order, ZIP64 extended locator location, and checksum calculation context; different toolchains (such as zip, 7z, Info-ZIP, miniz), and even different versions or operating environments of the same tool, can all lead to ZIP outputs with different hash values for the same set of source files. Automotive OTA upgrades have extremely high requirements for the integrity and consistency of the upgrade package, ensuring that the restored ZIP file is completely identical to the original compressed file of the target version in terms of MD5, SHA256, and other hash values. Otherwise, the integrity verification of the in-vehicle system will fail, leading to upgrade failure or even vehicle malfunction.
[0004] Furthermore, ZIP metadata is not purely derived information. Fields such as CRC32, compressed / uncompressed size, and filename length of each entry in the central directory depend on the actual layout and padding strategy of the local file header. The length of "extra fields," compression method identifiers, and encryption flags in the local file header are dynamically affected by file content characteristics and compression parameters, forming cross-level coupling effects. Traditional solutions attempt to normalize by pre-setting timestamps or ignoring timestamp fields, but they cannot solve problems such as semantic ambiguity of external attribute fields (e.g., inconsistent permission mapping between Windows and Linux), dynamic offset of padding areas, uncontrollable sorting of central directory entries, and sensitive triggering conditions of ZIP64 extended structures. This results in a systematic deviation between the decompressed and recompressed ZIP file and the original upgrade package at the metadata level. This not only makes the first-layer patch, which relies solely on content difference, unable to support high-precision restoration, but also directly causes changes in the MD5 value of the recompressed file, failing to meet the strict verification requirements of automotive OTA upgrades.
[0005] Existing binary differential tools (such as bsdiff and xdelta) are not optimized for the syntactic structure constraints, semantic layering characteristics, and high consistency requirements of the ZIP format in automotive OTA scenarios. They only perform coarse-grained byte stream comparisons on metadata differences, which not only generates redundant patches and increases the download burden, but also cannot guarantee the automatic recalculation and consistency maintenance of check fields such as CRC32, making it difficult to meet the stringent requirements of ECU upgrade packages for byte-level restoration accuracy.
[0006] Therefore, there is an urgent need for a two-stage differential mechanism that takes into account the determinism of file content, the stability of directory structure, and the compliance of ZIP metadata syntax. This mechanism can reduce the size of the upgrade package and shorten the download time, while ensuring that the decompressed and recompressed ZIP file is completely consistent with the original target version at the byte level, thus achieving efficient and reliable end-to-end differential upgrade of automotive ECU ZIP format upgrade packages. Summary of the Invention
[0007] This invention provides a differential upgrade method for compressed files, aiming to solve the technical problem in existing differential upgrades of automotive ECUZIP format upgrade packages where the volatility of ZIP format metadata makes it difficult to accurately restore the hash value of the target version ZIP file after differential upgrade. By constructing a two-stage differential mechanism, the method achieves the dual goals of reducing the upgrade package size and restoring byte-level consistency, ensuring the efficiency and reliability of automotive OTA upgrades.
[0008] This invention provides a differential upgrade method for compressed files, including a differential stage and a restoration stage; The differential phase includes: S1: Decompress the original compressed file of the starting version and the original compressed file of the target version respectively to obtain the first folder and the second folder; S2: Set uniform file attributes and timestamps for all files in the first folder and the second folder respectively to obtain the first new folder and the second new folder; S3: Use a fixed compression command to compress the first new folder and the second new folder, resulting in a first new compressed file and a second new compressed file respectively; S4: Generate the first difference file based on the differences in file content and structure between the first new folder and the second new folder; S5: Generate a second differential file based on the differences in binary data and metadata between the second new compressed file and the original compressed file of the target version; The restoration phase includes: R1: Decompress the original compressed file from the initial version to obtain the first folder; R2: Set uniform file attributes and timestamps for all files in the first folder to create a new first folder; R3: Use the first difference file to restore the first new folder and obtain the second reconstructed folder; R4: Compress the second rebuilt folder using a fixed compression command to obtain a second new compressed file; R5: Use the second differential file to restore the second new compressed file, and obtain the original compressed file of the target version.
[0009] Further, in step S4, a binary difference algorithm is used to generate the first difference file.
[0010] Furthermore, in step S5, a second difference file is generated using a binary difference algorithm.
[0011] Furthermore, unified file attribute and timestamp settings include: Set the modification time, access time, and change time of all files in the folder to the same fixed value, and set the file permission attributes to the same fixed configuration.
[0012] Furthermore, the fixed compression command includes the specified compression tool, compression level, and compression parameters to ensure that when compressing the same set of file contents and directory structures, the output compressed file is completely identical at the byte level.
[0013] Furthermore, both the original compressed files of the initial version and the original compressed files of the target version are ZIP and ZIP64 format files.
[0014] Furthermore, the original compressed file is an OTA upgrade package for the automotive ECU (Electronic Control Unit) firmware.
[0015] Furthermore, step S5 also includes: reconstructing the complete metadata of the original compressed file of the target version, specifically including the following operations: Before performing binary differential operations between the second new compressed file and the original compressed file of the target version, a lossless parsing operation is performed on the original compressed file of the target version. The lossless parsing operation is achieved by directly reading the original byte stream of the original compressed file of the target version and performing syntax and semantic compliance checks according to the ZIP format specification. The metadata set, which is independent of the actual file content data, is identified and extracted. The metadata set includes at least: the original byte values of the structured fields of the local file header, the original byte sequence of the central directory structure, the original byte values of the external attribute fields of each file entry, and the ZIP comment fields. During the generation of the second differential file, based on the metadata set of the second new compressed file and the metadata set of the target version original compressed file, differential calculations are performed on the binary data of the corresponding fields to generate a simplified differential file specifically for metadata reconstruction.
[0016] Furthermore, lossless parsing is performed on the original compressed file of the target version, including differential analysis and instruction encoding of the metadata set. The specific steps are as follows: The metadata set extracted from the original compressed file of the target version is compared item by item with the corresponding structural information extracted from the second new compressed file to identify the metadata difference type; the metadata difference type is: entry addition / deletion, field value change, byte padding; For adding or deleting entries, generate entry operation instructions based on the specific information of the added or deleted entries. For adding entries, extract the metadata of the added entries from the original compressed file of the target version and generate entry operation instructions in the format of addition instruction, entry identifier, and complete metadata. For deleting entries, obtain the central directory entry index position corresponding to it in the second new compressed file and generate entry operation instructions in the format of deletion instruction and entry identifier. For field value changes, if the change occurs within a contiguous block of bytes and this contiguous block does not carry independent semantic field boundaries in the ZIP structure, a binary differential algorithm optimized based on the rolling hash algorithm and the longest common subsequence (LCS) algorithm is used to output a compact binary patch stream; if the change occurs on a structured field with a clearly defined syntax position and semantic type, a structured field patch instruction is used for encoding. The format of the structured field patch instruction is field identifier and new byte value. For byte padding, perform padding consistency checks: By comparing the starting offset, padding length, and padding byte pattern of each padding region in the original compressed file of the target version with the second new compressed file, determine whether the padding was introduced due to differences in compression algorithms, block alignment strategies, or toolchain implementations during the process of recompressing the second new folder to generate the second new compressed file; if it is determined to be new padding or the padding length has changed, and the padding region is located at the end of the local file header, before or after the central directory entry, or near the ZIP64 locator structure, or other positions allowed by the ZIP format specification, then generate padding control instructions. The format of the padding control instructions is: the starting offset address within the ZIP file byte stream, the total length of the padding bytes, and the padding pattern; The entry operation instructions, structured field patch instructions, and padding control instructions are arranged according to their byte offset order in the ZIP file structure to obtain the instruction sequence; The instruction sequence is encapsulated together with the embedded lightweight virtual machine bytecode program to form a second differential file. The virtual machine bytecode program has the functions of instruction decoding, memory mapping access, ZIP structure offset calculation, metadata byte writing and CRC32 checksum recalculation. At runtime, the complete byte stream of the original compressed file of the target version is used as the initial memory image. Each instruction is interpreted and executed in sequence in the specified execution context, and finally the complete metadata that is completely consistent with the original compressed file of the target version is reconstructed.
[0017] Furthermore, in step R5, the specific steps for restoring the second new compressed file using the second differential file to obtain the original compressed file of the target version are as follows: The second new folder is compressed using a fixed compression command to generate an intermediate ZIP file that includes the contents of the target file and the basic ZIP structure. The embedded lightweight virtual machine bytecode program encapsulated in the second differential file is loaded and run. Taking the complete byte stream of the intermediate ZIP file as input, the metadata reconstruction instructions encoded in it are executed to generate a final file that is completely consistent with the original compressed file of the target version at the byte level. The embedded lightweight virtual machine is a dedicated virtual machine based on a stack architecture. Its instruction set contains 16 core operation instructions, covering core functions such as metadata reading and writing, offset calculation, verification and recalculation.
[0018] Compared with the prior art, the present invention has the following advantages and beneficial effects: First, content normalization eliminates interference from non-content factors, ensuring that the first differential file focuses solely on the substantive changes in file content and structure within the ECU firmware upgrade package. The metadata reconstruction stage generates a simplified instruction stream based on metadata differences, avoiding redundant patches caused by binary differential processing of the entire ZIP format upgrade package. Compared to traditional binary differential methods, this significantly reduces the size of automotive OTA upgrade packages, shortening download time by over 60%. It is particularly well-suited to the bandwidth-constrained and high-stability requirements of in-vehicle scenarios, effectively improving the user upgrade experience.
[0019] Secondly, by losslessly parsing the metadata set of the original compressed file of the target version, combined with structured patch instructions and a lightweight virtual machine execution mechanism, it is possible to accurately reproduce all the metadata of the ECU firmware upgrade package, ensuring that the restored target version compressed file is completely consistent with the original file in hash values such as MD5 and SHA256. This perfectly solves the problem of ECU integrity verification failure caused by metadata differences in traditional methods, ensuring the security and reliability of OTA upgrades and avoiding the risk of vehicle function abnormalities caused by upgrade failures.
[0020] Third, the design of unified file attributes and fixed compression commands makes the differential stage unaffected by ECU supplier compression tools (such as WinZip, 7-Zip, customized compression modules, etc.) and compilation environment variables. It can handle ZIP format firmware packages with the same content generated by different suppliers, different compression parameters, and different timestamp settings, which significantly improves the universality of the differential upgrade method in multi-ECU model and multi-supplier collaboration scenarios in the automotive industry.
[0021] Fourth, the dual-stage differential architecture breaks down the complex ECU firmware compressed file differential process into two independent steps: content differential and metadata differential. The first differential file generation utilizes a mature binary differential algorithm to efficiently handle content differences in firmware core programs, calibration data, and other files. The second differential file significantly reduces the computational complexity of metadata reconstruction through instruction-based encoding. The overall upgrade process time is significantly reduced compared to full file transfer, and the on-board restoration process has low resource consumption, adapting to the limited computing power of ECU hardware.
[0022] Fifth, it is deeply optimized for ZIP and ZIP64 format files, fully supporting special structures such as multi-volume compression, encrypted compression, and symbolic link entries commonly found in automotive ECU firmware upgrade packages. It can be directly applied to OTA upgrade packages for various ECUs such as engine control ECUs, intelligent driving domain controllers, and body control modules, without requiring modification of the original compressed file format provided by suppliers, thus reducing the adaptation costs for automakers and suppliers.
[0023] Other features and advantages of the invention will be set forth in the following description, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention may be realized and obtained by means of the structures particularly pointed out in the written description and the accompanying drawings.
[0024] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description
[0025] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings: Figure 1 A schematic diagram illustrating the steps of the differential phase in a differential upgrade method for compressed files; Figure 2 A schematic diagram illustrating the steps of the restoration phase in a differential upgrade method for compressed files; Figure 3 A schematic diagram illustrating the steps involved in reconstructing the complete metadata of the original compressed file for the target version. Detailed Implementation
[0026] The preferred embodiments of the present invention will be described below with reference to the accompanying drawings. It should be understood that the preferred embodiments described herein are for illustration and explanation only and are not intended to limit the present invention.
[0027] This invention provides a differential upgrade method for compressed files, such as... Figure 1 , Figure 2 As shown, it includes a difference stage and a reduction stage; The differential phase includes: S1: Decompress the original compressed file of the starting version and the original compressed file of the target version respectively to obtain the first folder and the second folder; S2: Set uniform file attributes and timestamps for all files in the first folder and the second folder respectively to obtain the first new folder and the second new folder; S3: Use a fixed compression command to compress the first new folder and the second new folder, resulting in a first new compressed file and a second new compressed file respectively; S4: Generate the first difference file based on the differences in file content and structure between the first new folder and the second new folder; S5: Generate a second differential file based on the differences in binary data and metadata between the second new compressed file and the original compressed file of the target version; The restoration phase includes: R1: Decompress the original compressed file from the initial version to obtain the first folder; R2: Set uniform file attributes and timestamps for all files in the first folder to create a new first folder; R3: Use the first difference file to restore the first new folder and obtain the second reconstructed folder; R4: Compress the second rebuilt folder using a fixed compression command to obtain a second new compressed file; R5: Use the second differential file to restore the second new compressed file to obtain the original compressed file of the target version; In a specific application implementation, taking a car manufacturer releasing a new firmware upgrade package (v2.5.0_ECU) for the intelligent driving domain controller ECU and pushing an OTA differential upgrade package to vehicles equipped with the old firmware (v2.4.0_ECU) as an example, the entire process is implemented as follows: Differential phase (server-side operation): S1: The server extracts the v2.4.0_ECU original firmware upgrade package (ZIP format, 890MB in size, containing key components such as core control program, sensor calibration data, algorithm model file, configuration parameter set, etc.) and the v2.5.0_ECU original firmware upgrade package (ZIP format, 912MB in size) to the temporary directories / tmp / ecu_v2.4.0_src / and / tmp / ecu_v2.5.0_src / respectively, to ensure the complete restoration of the file tree structure, including nested subdirectories, hidden system files, symbolic links and firmware-specific signature files, to avoid subsequent differential deviations due to incomplete decompression; S2: Traverse all 328 core files in two temporary directories (covering ECU executable binary programs, FPGA configuration bitstreams, sensor calibration XML files, CAN bus communication protocol configurations, security key certificates, etc.), and uniformly standardize the execution permissions for each file: In the Linux environment, execute chmod755 (to ensure ECU executable permissions) and uniformly change the owner to root:root; in the Windows environment, configure equivalent execution permissions through the SetACL tool, forcibly setting mtime (modification time), atime (access time), and ctime (status change time) to January 1, 2024, 00:00:00 (UTC), generating completely consistent standardized directories / tmp / ecu_v2.4.0_norm / and / tmp / ecu_v2.5.0_norm / , completely eliminating non-functional metadata fluctuations caused by differences in firmware compilation environment, packaging time, and vendor permission policies; S3: Using a preset deterministic ZIP compression command (specifying the 7-Zip23.01 tool, compression level 6, disabling timestamp embedding, enabling a fixed file sorting algorithm, and preserving symbolic links and original file attributes), the two standardized directories are packaged separately, generating byte-level reproducible archive files ecu_v2.4.0_norm.zip and ecu_v2.5.0_norm.zip. This compression process ensures that the order of file entries inside the ZIP, the central directory offset, the local file header position, and the starting address of EOCD (End of Central Directory) are completely determined by the directory traversal order, avoiding structural differences caused by the randomness of the compression tool and ensuring the accuracy of subsequent differential processing. S4: The bsdiff tool is called to perform a full-path hierarchical comparison of the two standardized directories / tmp / ecu_v2.4.0_norm / and / tmp / ecu_v2.5.0_norm / , accurately identifying core firmware differences: newly added files (such as sensor_new_calib.xml, new sensor calibration data), deleted files (such as legacy_algorithm.dll, old redundant algorithm library), files with changed content (such as main_control.bin, core control program binary update, fixing logic vulnerabilities in driving assistance functions), and configuration file modifications (such as can_protocol.conf, bus communication parameter optimization), generating a structure-aware differential file delta_ecu_struct.bin. This file contains a complete path mapping table, operation type markers (ADD / DEL / MOD / REN), file content patch blocks, and SHA256 checksums to ensure integrity verification during vehicle-side restoration. S5: The xdelta3 tool is called to perform a byte-by-byte comparison between ecu_v2.5.0_norm.zip and the original v2.5.0_ECU firmware upgrade package (non-standardized, containing the manufacturer's original build timestamp, permission configuration, and firmware signature metadata). This accurately captures the ZIP metadata offset introduced by standardized compression: including changes in the order of file entries in the ZIP central directory, deviations in the recalculation of CRC32 checksums in each file header, misalignment of the physical arrangement of uncompressed data blocks, and drift in the values of the "central directorysize" and "central directory offset" fields in the EOCD record. A metadata repair differential file delta_ecu_meta.xdelta (only 186KB in size) is generated. This file is specifically used to restore a compliant ZIP upgrade package that conforms to the manufacturer's original specifications and can pass ECU firmware integrity verification (such as HMAC-SHA256 signature verification) on the vehicle side, ensuring the security and compatibility of firmware upgrades. Restoration phase (vehicle-mounted operation): R1: After receiving the OTA upgrade command, the vehicle T-Box (Remote Information Processing Terminal) reads the cached v2.4.0_ECU original firmware package from the vehicle storage unit and decompresses it to the temporary working directory / ota / temp / ecu_v2.4.0_src / . The decompression process strictly preserves the original directory structure, symbolic links and firmware-specific file attributes to avoid introducing additional differences during the decompression process. R2: Executes the standardized script on the vehicle side, traversing all files and subdirectories under / ota / temp / ecu_v2.4.0_src / , and standardizing execution permissions and timestamps: In the Linux-based ECU environment, execute chmod755 and chown root:root, and force synchronization of timestamps to January 1, 2024 00:00:00 (UTC) using the touch command; ensuring that the local file status is strictly consistent with the standardized directory on the server, providing a unified benchmark for differential restoration; R3: The vehicle-mounted unit loads the delta_ecu_struct.bin differential file and performs restoration operations item by item according to its embedded operation sequence: First, it creates the missing directory (e.g., / new_sensor_config / ); then it writes the new file sensor_new_calib.xml, immediately calculates the SHA256 hash value after writing and compares it with the preset digest in the differential file. If the verification fails, the upgrade is immediately terminated and the fault is reported; next, it performs a bspatch binary patch update on main_control.bin to fix the vulnerability of the old firmware. After the patch is completed, it calculates the MD5 value and compares it with the expected MD5 (f9e3d2a1...) marked in delta_ecu_struct.bin; finally, it modifies the bus communication baud rate parameter in can_protocol.conf according to the structured parsing rules to maintain the consistency of the configuration file format, indentation, and newline characters, and avoids ECU parsing failure due to format disorder; after all operations are completed, it generates a structurally complete and accurate intermediate directory / ota / temp / ecu_v2.5.0_norm / . R4: Invokes the same deterministic ZIP compression command as server-side S3 to compress the files in the intermediate directory / ota / temp / ecu_v2.5.0_norm / , generating a byte-level reproducible ecu_v2.5.0_norm.zip. This compressed package has completely identical file hashes, central directory layouts, and EOCD structures to the ecu_v2.5.0_norm.zip generated by the server, ensuring the accuracy of subsequent metadata repair. R5: The vehicle-mounted system uses the xdelta3 tool to incrementally update ecu_v2.5.0_norm.zip, applying the delta_ecu_meta.xdelta metadata repair patch to the intermediate ZIP package. This process precisely corrects the order of entries in the central directory of the ZIP, rewrites the CRC32 and compressed / uncompressed size fields in each file header, adjusts the offset between the local file header and data blocks, relocates the EOCD record to the end of the file, and recalculates the overall HMAC-SHA256 signature of the firmware. This ensures that the entire ZIP file fully complies with automotive industry ECU firmware upgrade specifications (such as ISO15765) and manufacturer-defined verification requirements. The final output is the v2.5.0_ECU.zip firmware upgrade package, which can be successfully recognized by the ECU and the upgrade process can be executed. After the upgrade, the driving assistance functions, sensor data processing accuracy, and bus communication stability are completely consistent with the original full firmware package released by the manufacturer. Furthermore, it passes the ECU's built-in integrity verification and security authentication, eliminating the risk of upgrade failure or malicious tampering.
[0028] The working principle of the above technical solution is as follows: by eliminating redundant changes introduced by factors such as the randomness of compression algorithms, timestamp fluctuations, and differences in file attributes during the compressed file upgrade process through a dual differential mechanism, the compression efficiency and restoration accuracy of the differential package are significantly improved. Its core lies in transforming the uncontrollable differences of the original compressed file into a controllable and standardized intermediate representation, and constructing differential relationships in two orthogonal dimensions: one is the structured content differential based on the semantics of the decompressed file system, and the other is the precise byte-level differential based on the compressed binary stream. During the differential phase, S1 performs lossless decompression on the original compressed file, removing interference from the compression layer and returning it to a comparable file system level; S2 performs forced normalization processing, uniformly resetting non-content-related metadata such as access permissions (e.g., rwx bits in Linux or ACL flags in Windows), owner identifier (UID / GID or SID), modification time (mtime), access time (atime), and status change time (ctime) of all files in the first and second folders to preset fixed values (e.g., permissions are set to 0755 to ensure ECU has executable permissions, owner is set to root:root, and timestamp is set to January 1, 2024, 00:00:00). UTC is used to eliminate metadata jitter caused by differences in build environment, packaging tools, and packaging time; S3 uses fully deterministic compression parameters (including fixed compression level, disabling timestamp embedding, disabling filename case sensitivity, and enabling deterministic hash sorting of directory entries) to recompress the normalized folder, ensuring that the same input will produce the same output, generating a first and second new compressed file with strong determinism; S4 uses deep file comparison algorithms (such as combining inode path tree traversal, content fingerprint (SHA-256) clustering, binary block-level similarity detection (rsync rolling hash) and structural change recognition (addition / deletion / renaming / modification)) based on the normalized first and second new folders to generate the first The differential file describes the minimum set of file system operations required to move from the first new folder to the second new folder in the form of a sequence of instructions. It includes file copy instructions (copy-from), content patch instructions (binary-patch), symbolic link reconstruction instructions (symlink-create), and permission / attribute batch setting instructions (chmod-chown-batch). S5 then compares the second new compressed file generated by S3 with the original compressed file of the target version byte by byte, extracting all binary-level differences between the two, such as the compression format header (e.g., ZIP central directory structure, GZIP magic number and FLG fields), compressed data stream (DEFLATE block sequence), checksum (CRC32 / Adler32), and extended metadata (e.g., ZIP extra field). It generates the second differential file, which is a pure binary incremental stream. It is encoded using a binary differential algorithm (e.g., bsdiff, xdelta3, or customized LZ77 aligned differential) to accurately capture the underlying disturbances inside the compressed format caused by the normalization of the original file's metadata, such as compression dictionary offset, block boundary migration, and changes in entropy encoding statistical distribution. During the restoration phase, R1-R2 reproduce the decompression and normalization process of the differential phase to ensure consistency of the starting point; R3 loads the first differential file and, based on its semantic instruction set, precisely reconstructs a second new folder on the local file system that is completely identical to the input of the differential phase S3. This process does not depend on the original target file, but only on the starting version file and the differential instructions, and has strong reproducibility; R4 compresses the second new folder with the same deterministic compression command as S3, which will inevitably generate a copy that is bit identical to the second new compressed file in S3; R5 uses the second differential file as a binary patch and directly applies it to the corresponding byte positions of the second new compressed file output by R4. Through memory mapping writing or streaming overlay, it accurately repairs the residual format layer differences between the second new compressed file and the target version, and finally outputs a bit-equivalent target version original compressed file.
[0029] The beneficial effects of the above technical solution are as follows: By adopting the solution provided in this embodiment, the entire process forms a closed-loop verification. The normalization and deterministic compression in the differential stage eliminate semantic noise, so that the differential package only needs to focus on the real file content and structural changes. Compared with the traditional solution of directly performing binary differential on the original compressed file (such as directly performing bsdiff on two ZIP packages), the size of the differential package can be reduced, which can significantly reduce bandwidth usage and storage overhead. Through dual differential verification of the file system semantic layer and the compressed binary layer, the end-to-end accuracy of the restoration process is ensured.
[0030] In one embodiment, in step S4, a binary difference algorithm is used to generate a first difference file.
[0031] The working principle of the above technical solution is as follows: First, a full structural traversal and content mapping are performed on the first and second new folders, recursively extracting the paths, metadata (such as file size, modification time, and permission identifiers) and original binary byte streams of all files in both folders; Second, bidirectional matching is performed based on path consistency and content similarity: files with the same path and completely identical content are marked as "no difference" and skipped; files with missing paths or changed content enter the differential process; For files that need to be differentially analyzed, instead of relying on text semantics or format parsing, the entire file is treated as a continuous byte sequence, and a binary search based on rolling hashing (such as Rabin-Karp) and a sliding window is used. The binary differential algorithm (such as a variant of bsdiff or a standard implementation of VCDIFF) builds a reference index on the target file in the second new folder, identifies reusable byte segments (copy instructions), new bytes to be inserted (add instructions), and redundant bytes to be deleted (remove instructions), and generates a compact instruction set description. Finally, all single-file differential results are organized according to the file system hierarchy, and path change metadata (such as renaming, moving, and adding directories) is added and encapsulated into a structured first differential file. This file can be used independently to accurately restore the complete state of the second new folder from the first new folder, and has high compression ratio, deterministic output, and cross-platform binary compatibility.
[0032] The beneficial effects of the above technical solution are as follows: by adopting the solution provided in this embodiment, the efficiency and accuracy of differential upgrade of compressed files are significantly improved.
[0033] In one embodiment, in step S5, a binary difference algorithm is used to generate a second difference file.
[0034] The working principle of the above technical solution is as follows: In step S5, the system first takes the second new compressed file and the original compressed file of the target version as input, and synchronously reads the corresponding binary byte streams and complete metadata (including but not limited to file header structure, compression algorithm identifier, block size parameters, checksum, timestamp, file path information, etc.); then, a fine-grained byte-level differential algorithm based on a sliding window (such as bsdiff or its improved VCDIFF variant) is used for the binary data part. By constructing the suffix array and LCP array of the source file, the system accurately identifies and extracts the added, deleted, moved and modified binary fragments, and generates a compact instruction sequence (including COPY, ADD, RUN and other opcodes); at the same time, the metadata part is subjected to structured parsing and semantic comparison to identify field-level changes (such as compression level changing from 6 to 9, CRC32 check value update, ZIP central directory entry offset rearrangement, etc.), and the differences are encoded into structured patch segments in the form of key-value pairs; finally, the binary differential instruction stream and metadata difference segments are processed according to a predefined binary protocol (such as Google Protocol). The buffer serialization format is integrated and encapsulated to generate a single, independently applicable second differential file. This file not only contains all the incremental information needed to recover the second new compressed file, but is also guaranteed by hash verification and integrity signature to ensure that the differential process is unambiguous, reversible, and resistant to bit flipping.
[0035] The beneficial effects of the above technical solution are as follows: by adopting the solution provided in this embodiment, the size of the differential file can be significantly reduced. Compared with the traditional whole file replacement method, the size of the upgrade package is reduced on average while retaining the structural characteristics of the compressed file.
[0036] In one embodiment, the unified file attributes and timestamp settings include: Set the modification time, access time, and change time of all files in the folder to the same fixed value, and set the file permission attributes to the same fixed configuration.
[0037] The working principle of the above technical solution is as follows: The system-level API interface is used to call the file system kernel module to traverse all file nodes under the target folder (including recursive traversal of subdirectories) and obtain the inode metadata structure of each file. For the timestamp field, ctime (state change time), mtime (content modification time), and atime (access time) are forcibly overridden to the Unix timestamp preset in the configuration file (e.g., uniformly set to 1672531200 seconds corresponding to 2023-01-01 00:00:00), and written to the disk via the utimes system call. For permission attributes, an octal permission mask (e.g., 0644 represents read / write for owner, read for group, and read for others) is used to uniformly set the file's mode field. For special files (e.g., executable files are set to 0755), separate processing is performed through conditional branches to ensure that execution permissions are configured differently from ordinary files. In network transmission scenarios, unified timestamps can avoid hash verification failures caused by differences in local file creation times, while standardized permissions eliminate compatibility issues caused by differences in permission models between different operating systems (such as Linux and Windows), improve the compatibility of vehicle systems with ECUs from multiple vendors, and adapt to upgrade packages generated by compression tools from different manufacturers.
[0038] The beneficial effects of the above technical solution are as follows: by adopting the solution provided in this embodiment, the interference of file metadata differences on the differential upgrade process of compressed files can be effectively eliminated.
[0039] In one embodiment, the fixed compression command includes a specified compression tool, compression level, and compression parameters to ensure that when compressing the same set of file contents and directory structures, the output compressed file is completely identical at the byte level. This invention conducted comparative experiments, specifically: ① compression using attribute standardization alone, ② compression using a fixed compression command alone, and ③ compression using a combination of both. The specific ECU firmware upgrade package test results are compared in the table below: Experimental group Experimental conditions Test samples (ZIP / ZIP64 format) Metadata randomness difference percentage Differential redundancy change Byte-level consistency after restoration Test environment Control group 1 Standardize attributes individually (unify file modification, access, timestamp change, and permission configuration). 1. Intelligent Driving Domain Controller ECU Firmware Upgrade Package (v2.4→v2.5, 890MB→912MB, containing 328 core files) 2. Engine Control ECU Firmware Upgrade Package (v1.8→v1.9, 560MB→575MB, containing 216 core files) 3. Body Control Module ECU Firmware Upgrade Package (v3.0→v3.1, 320MB→332MB, containing 189 core files) Intelligent driving domain controller ECU: 18.7%; Engine control ECU: 15.3%; Body control module ECU: 19.2%; Average: 17.7%. A reduction of 8.3% compared to the baseline group (without any standardization). 82.5% (Only the file content is consistent; metadata has random deviations) Linux-based ECU system (ARM architecture), in-vehicle T-Box operating environment, server-side Linux CentOS 7.9, compression tools: 7-Zip 23.01, Info-ZIP 3.0 Control group 2 Use a fixed compression command alone (specify 7-Zip23.01, compression level 6, disable timestamp embedding, and fix the file sorting algorithm). The three test samples were the same as those in control group 1. Intelligent Driving Domain Controller ECU: 2.1%; Engine Control ECU: 1.8%; Body Control Module ECU: 2.3%; Average: 2.1% Increased by 25.6% compared to the baseline group. 97.8% (Metadata is basically the same, but differences in file content lead to increased redundancy) The testing environment was the same as that of control group 1. experimental group Attribute standardization and fixed compression commands (Solution of this invention) The three test samples were the same as those in control group 1. Intelligent Driving Domain Controller ECU: 0% Engine Control ECU: 0% Body Control Module ECU: 0% Average: 0% The rate was 40.3% lower than the baseline group, 36.8% lower than control group 1, and 52.1% lower than control group 2. 100% (MD5 / SHA256 hash value is completely consistent with the target version) The testing environment was the same as that of control group 1. In the above experiments, the calculation method for the proportion of random differences in metadata was: (Metadata byte difference of compressed files with the same content generated under different environments / Total metadata byte size) × 100%. Metadata includes core fields such as local file header, central directory structure, external attribute fields, and ZIP comments. The change in differential redundancy was calculated by directly performing binary differential on the original compressed file as a baseline group, and the ratio of the difference between the differential file size of each group and the baseline group was calculated. Negative values indicate a decrease in redundancy, and positive values indicate an increase in redundancy. The byte-level consistency after restoration was calculated by comparing the complete byte stream of the restored file with the target version of the original compressed file, and the proportion of bytes that completely matched was calculated. 100% indicates no byte difference. The test samples of the experiment covered different ECU types, different file numbers and sizes in the automotive industry to ensure the industry relevance of the experimental data. Each group of experiments was repeated 3 times, and the average value was taken. The error range was ±0.5%, and the data was statistically significant.
[0040] The working principle of the above technical solution is as follows: A unified compression tool (such as a specified version of 7-Zip, WinRAR, or tar+gzip combination) is predefined, and the compression level is fixed (e.g., set to the highest compression level to ensure consistency, or a specific intermediate level to balance compression efficiency and result stability). Simultaneously, all necessary compression parameters are specified (such as whether to retain the original file timestamps, whether to use a fixed file order sorting algorithm, whether to disable randomized checksum generation, and setting fixed compression dictionary size and block size, etc.). When compressing the same set of file contents and directory structures, because the compression tool, compression level, and all parameters are completely consistent, the logical path, encoding method, and processing method of file metadata (under parameter control) of the compression algorithm will also be completely identical. This ensures that the final compressed file is completely consistent in byte sequence, avoiding differential upgrade interference caused by uncertainties in the compression process.
[0041] The beneficial effects of the above technical solution are as follows: The solution provided in this embodiment can fundamentally eliminate the inconsistency problem of compressed files caused by factors such as differences in tool versions, different parameter configurations, or randomized algorithm processing during the compression process. Experimental results show that the combination of attribute standardization and fixed compression commands proposed in this invention has achieved significant results in eliminating metadata randomness differences. The proportion of metadata randomness differences in all three test samples has been reduced to 0%, completely solving the problem of inconsistency in compressed files caused by metadata fluctuations. In terms of differential redundancy control, this solution reduces redundancy by 40.3% compared to the baseline group, 36.8% compared to control group 1 which only uses attribute standardization, and 52.1% compared to control group 2 which only uses fixed compression commands. This fully demonstrates its superiority in reducing redundant data during differential upgrades, effectively reducing the size of differential files, improving upgrade efficiency, and saving bandwidth resources. This solution achieves 100% byte-level consistency of the restored compressed file, with the MD5 / SHA256 hash value completely consistent with the target version, ensuring accurate matching between the upgraded system and the target version, and eliminating various operational risks that may be caused by inconsistencies in the restored files.
[0042] In one embodiment, both the original compressed file of the initial version and the original compressed file of the target version are ZIP and ZIP64 format files.
[0043] The working principle of the above technical solution is as follows: Through in-depth analysis and standardization of the ZIP and ZIP64 format file structures, it is ensured that the parsing and generation rules of key structural parts such as file header, central directory record, local file header, data descriptor (if present), and tail record of the original compressed files of the starting version and the target version are completely consistent. When processing the original compressed files of the starting version and the target version, since both follow the above unified ZIP and ZIP64 format parsing and generation rules, the subsequent differential comparison based on these two versions of the file can accurately locate the differences in the actual file content and structure, rather than pseudo-differences caused by different format parsing or generation methods, thus laying a solid foundation for efficient and accurate differential upgrades.
[0044] The beneficial effects of the above technical solution are as follows: By adopting the solution provided in this embodiment, false differences caused by the differences in processing details of different ZIP and ZIP64 format parsing or generation tools can be effectively avoided, ensuring that the object of differential comparison is the substantial content and core structure of the file, reducing the amount of redundant data in the differential upgrade package, reducing the occupation of network transmission bandwidth and storage resources, and significantly improving the execution efficiency and accuracy of the differential algorithm.
[0045] In one embodiment, the original compressed file is an OTA (Over-The-Air) firmware upgrade package for automotive ECUs (Electronic Control Units), including ZIP format upgrade packages for various ECUs such as engine control ECUs, intelligent driving domain controllers, and body control modules.
[0046] The working principle of the above technical solution is as follows: The core control program, sensor calibration data, communication protocol configuration, and other related files contained in the original compressed file (i.e., the ECU firmware OTA upgrade package) are modularly split and structured indexed to establish a file hierarchy directory and unique identifier mapping relationship. When performing a differential upgrade, the corresponding module files in the starting and target version upgrade packages are quickly located based on this index relationship. Then, for each module file, a content-based block hash comparison algorithm is used to divide the file into fixed-size or variable-size data blocks and calculate hash values. New, deleted, or modified data blocks are identified by comparing hash value sequences. For modified data blocks, a binary differential algorithm is further used to calculate the specific differences within the block. Finally, all the different data blocks, their location information, and identification information are integrated and encapsulated into a differential upgrade package, achieving a precise and efficient upgrade from the starting version to the target version.
[0047] The beneficial effects of the above technical solution are as follows: by adopting the solution provided in this embodiment, the amount of data to be transmitted during the ECUOTA upgrade process can be significantly reduced, avoiding the repeated transmission of the complete upgrade package under the traditional full upgrade method, and saving vehicle network resources and transmission time.
[0048] In one embodiment, such as Figure 3 As shown, step S5 also includes: reconstructing the complete metadata of the original compressed file of the target version, specifically including the following operations: Before performing binary differential operations between the second new compressed file and the original compressed file of the target version, a lossless parsing operation is performed on the original compressed file of the target version. The lossless parsing operation is achieved by directly reading the original byte stream of the original compressed file of the target version and performing syntax and semantic compliance checks according to the ZIP format specification. The metadata set, which is independent of the actual file content data, is identified and extracted. The metadata set includes at least: the original byte values of the structured fields of the local file header, the original byte sequence of the central directory structure, the original byte values of the external attribute fields of each file entry, and the ZIP comment fields. During the generation of the second differential file, based on the metadata set of the second new compressed file and the metadata set of the target version original compressed file, differential calculations are performed on the binary data of the corresponding fields to generate a simplified differential file specifically for metadata reconstruction.
[0049] The working principle of the above technical solution is as follows: Since the metadata of compressed files (such as local file headers, central directories, etc.) not only contains the file's descriptive information, but also directly affects the integrity and parsability of the compressed file, if only the actual content data of the compressed file is differentially analyzed, it may lead to metadata mismatch, making the reconstructed target version compressed file unusable. This invention first performs lossless parsing on the original target version compressed file to accurately extract its metadata set, and then performs binary differential analysis between the metadata set of the second new compressed file and the extracted metadata set to generate a simplified differential file specifically for metadata reconstruction. In this way, when reconstructing the original target version compressed file based on the second differential file and the second new compressed file, the metadata of the second new compressed file can be specifically corrected using this simplified differential file to ensure that the reconstructed metadata is completely consistent with the original target version compressed file, thereby ensuring the syntactic and semantic compliance of the target version compressed file and improving the reliability and accuracy of the differential upgrade method.
[0050] The beneficial effects of the above technical solution are as follows: The solution provided in this embodiment can fundamentally solve the problem of unusable reconstructed files caused by differences in compressed file metadata; through lossless parsing, the original byte stream is directly read and verified according to the ZIP format specification, ensuring the accuracy and completeness of the extracted metadata set and avoiding deviations caused by additional modifications or loss of key information introduced during the parsing process; the generation of a simplified differential file specifically for metadata reconstruction allows for precise, small-scale correction of metadata when reconstructing the original compressed file of the target version. Compared to differentially dividing the entire compressed file, this reduces the amount of metadata-related differentials, improves the efficiency of differential calculation, and reduces the size of the differential file; simultaneously, due to the accurate reconstruction of metadata, the final generated target version compressed file is completely consistent with the original file at the metadata level, thus ensuring its normal parsing and use in ECU firmware parsing environments, in-vehicle T-Box systems, and automotive industry upgrade tools, effectively improving the robustness and applicability of the differential upgrade method.
[0051] In one embodiment, lossless parsing is performed on the original compressed file of the target version, including differential analysis and instruction encoding of the metadata set. The specific steps are as follows: The metadata set extracted from the original compressed file of the target version is compared item by item with the corresponding structural information extracted from the second new compressed file to identify the metadata difference type; the metadata difference type is: entry addition / deletion, field value change, byte padding; For adding or deleting entries, generate entry operation instructions based on the specific information of the added or deleted entries. For adding entries, extract the metadata of the added entries from the original compressed file of the target version and generate entry operation instructions in the format of addition instruction, entry identifier, and complete metadata. For deleting entries, obtain the central directory entry index position corresponding to it in the second new compressed file and generate entry operation instructions in the format of deletion instruction and entry identifier. For field value changes, if the change occurs within a contiguous block of bytes and this contiguous block does not carry independent semantic field boundaries in the ZIP structure, a binary differential algorithm optimized based on the rolling hash algorithm and the longest common subsequence (LCS) algorithm is used to output a compact binary patch stream; if the change occurs on a structured field with a clearly defined syntax position and semantic type, a structured field patch instruction is used for encoding. The format of the structured field patch instruction is field identifier and new byte value. This invention employs a binary differential algorithm optimized based on the rolling hash algorithm and the longest common subsequence (LCS) algorithm. It is not a simple superposition of the two algorithms, but rather a three-layer core optimization implemented to address the structured characteristics of ZIP metadata, the requirements for differential efficiency, and the requirements for cross-platform compatibility. The details are as follows: For the rolling hash algorithm, a fixed window size of 64 bytes is used (matching the common alignment length of ZIP metadata fields) to avoid fluctuations in hash results caused by window adaptation; a fixed hash seed (such as 0x12345678) is used to ensure that the same byte block generates consistent hash values on different platforms (Windows / Linux / macOS) and different toolchains, solving the difference and ambiguity problem caused by seed randomization in traditional rolling hash; the sliding step is set to 8 bytes (aligned with the field length of ZIP file header and central directory entries) to avoid computational redundancy caused by too small a step or missed matches caused by too large a step. A hash check whitelist is set for key structures in ZIP metadata (such as the local file header start identifier 0x504B0304 and the central directory start identifier 0x504B0102) to force exact matching and ensure that the core structure has no differential deviation. A dual hash check (Rabin-Karp algorithm + CRC32) is adopted. First, candidate matching blocks are quickly filtered by Rabin-Karp, and then byte-level consistency is verified by CRC32. For frequently occurring fixed fields in ZIP metadata (such as compression method identifier and file attribute flag), a hash cache table is preset to avoid repeated calculations and improve matching efficiency. For the LCS algorithm, the metadata difference type is first identified (entry addition / deletion, field value change, byte padding). LCS calculation is only performed on continuous byte block differences in "field value change", skipping non-continuous differences corresponding to entry addition / deletion and byte padding to reduce computation. For continuous byte blocks with a length of less than 32 bytes, binary byte-by-byte comparison is used directly instead of LCS to avoid the algorithm call overhead exceeding the actual benefit. ZIP format semantic rules (such as the length range of central directory entries, a fixed 4-byte CRC32 field, and a fixed 4 / 8-byte file size field) are injected to verify the legality of the LCS algorithm's matching results and eliminate those that do not conform to the ZIP specification. Invalid matching paths are avoided; the longest matching length of LCS is limited to no more than the maximum length of a single metadata field (e.g., a ZIP comment field with a maximum of 65535 bytes) to prevent differential instruction errors caused by cross-field matching; a one-dimensional array is used instead of the traditional two-dimensional array to store the dynamic programming state, reducing the space complexity from O(n×m) to O(min(n,m)), which meets the memory limitations of embedded lightweight virtual machines (adapting to a streamlined execution environment with 16 core instructions); for large metadata blocks exceeding 1MB (e.g., a central directory containing a large number of file entries), block-based LCS calculation is used, with each block generating differential instructions independently to avoid excessive resource consumption in a single calculation.
[0052] The above algorithms are optimized collaboratively by first using a rolling hash algorithm to quickly scan two metadata byte streams, identifying consecutive byte blocks (reusable blocks) with consistent hash values. LCS calculation is then performed only on regions with inconsistent hash values (difference candidate regions), reducing the overall computational load by over 60%. Reusable blocks identified by rolling hashing directly generate "COPY instructions," while difference regions calculated by LCS generate "ADD / REPLACE instructions," avoiding the inefficiency caused by traditional LCS algorithms calculating the entire byte stream. Based on the longest common subsequence result of the LCS algorithm, adjacent difference segments are merged to generate a continuous binary patch stream. To avoid redundancy caused by fragmented instructions, the offset address of the difference fragment in the metadata byte stream is directly located by combining the window position information of the rolling hash. The byte order difference is ignored during the algorithm calculation (ZIP format is little-endian byte order). The metadata byte stream of different platforms is processed through a unified byte order conversion interface to ensure that the hash value calculation and LCS matching results are consistent under Windows / Linux / macOS. The output binary patch stream adopts network byte order (big-endian) encoding, and with the byte order adaptation instructions of the embedded virtual machine, the differential instructions can be correctly executed on different architecture devices (x86 / ARM). For byte padding, perform padding consistency checks: By comparing the starting offset, padding length, and padding byte pattern of each padding region in the original compressed file of the target version with the second new compressed file, determine whether the padding was introduced due to differences in compression algorithms, block alignment strategies, or toolchain implementations during the process of recompressing the second new folder to generate the second new compressed file; if it is determined to be new padding or the padding length has changed, and the padding region is located at the end of the local file header, before or after the central directory entry, or near the ZIP64 locator structure, or other positions allowed by the ZIP format specification, then generate padding control instructions. The format of the padding control instructions is: the starting offset address within the ZIP file byte stream, the total length of the padding bytes, and the padding pattern; The entry operation instructions, structured field patch instructions, and padding control instructions are arranged according to their byte offset order in the ZIP file structure to obtain the instruction sequence; The instruction sequence is encapsulated together with the embedded lightweight virtual machine bytecode program to form a second differential file. The virtual machine bytecode program has the functions of instruction decoding, memory mapping access, ZIP structure offset calculation, metadata byte writing and CRC32 checksum recalculation. At runtime, it uses the complete byte stream of the original compressed file of the target version as the initial memory image, interprets and executes each instruction in sequence in the specified execution context, and finally reconstructs the complete metadata that is completely consistent with the original compressed file of the target version. The CRC32 checksum recalculation includes all checksum fields appearing in the ZIP file (such as local file header, central directory entry, etc.).
[0053] The working principle of the above technical solution is as follows: By performing a deep, structured comparison of the metadata sets of the original compressed file and the second new compressed file, the three core differences—entry addition / deletion, field value modification, and byte padding—are accurately identified. A layered encoding strategy is adopted for different difference types: for entry addition / deletion, semantically clear entry operation instructions are generated to directly locate the identifier and specific information of the added or deleted entry; for field value modification, depending on whether it is located in a structured semantic field, either a binary difference algorithm or a structured field patching instruction is selected to ensure both accuracy and compression efficiency; for byte padding, a padding consistency judgment is used to generate control instructions only for valid padding differences allowed by the ZIP format specification; and various instructions are then categorized... After byte offset ordering, it is encapsulated with a lightweight virtual machine bytecode program with complete metadata reconstruction capabilities into a second differential file. At runtime, the virtual machine uses the original compressed file byte stream as the initial image, executes instructions in sequence, completes precise modification, addition, and deletion of metadata, and performs CRC32 verification and recalculation in real time. Finally, it efficiently reconstructs the metadata structure that is completely consistent with the target version locally, thereby achieving accurate upgrades based on metadata differences. The optimization of rolling hash and LCS algorithms can solve the problems of low matching efficiency, redundant differential instructions, and poor cross-platform compatibility of traditional binary differential algorithms in ZIP metadata processing, so that metadata differential can ensure byte-level accuracy while taking into account execution efficiency and lightweight deployment requirements.
[0054] The beneficial effects of the above technical solution are as follows: by adopting the solution provided in this embodiment, the amount of redundant information transmission in the metadata differential process can be significantly reduced. Through the fine classification of metadata difference types and targeted encoding strategies, the traditional method of full replacement of the entire metadata block is avoided.
[0055] In one embodiment, step R5, which involves using the second differential file to restore the second new compressed file to obtain the original compressed file of the target version, comprises the following steps: The second new folder is compressed using a fixed compression command to generate an intermediate ZIP file that includes the contents of the target file and the basic ZIP structure. The embedded lightweight virtual machine bytecode program, encapsulated in the second differential file, is loaded and run. Taking the complete byte stream of the intermediate ZIP file as input, the encoded metadata reconstruction instructions are executed to generate a final file that is completely identical to the original compressed file of the target version at the byte level. The embedded lightweight virtual machine is a dedicated virtual machine based on a stack architecture. Its instruction set contains 16 core operation instructions, covering core functions such as metadata reading and writing, offset calculation, verification, and recalculation. The instruction set architecture of the embedded lightweight virtual machine is stack-based, and the core operation instructions include PUSH, POP, WRITE, CALC_OFFSET, etc.
[0056] The working principle of the above technical solution is as follows: By compressing the second new folder into an intermediate ZIP file that includes the target file content and the basic ZIP structure, the accuracy of the file data is first ensured, providing the correct content carrier for subsequent metadata repair. Subsequently, the embedded lightweight virtual machine uses the complete byte stream of this intermediate ZIP file as the initial working image. This means that the virtual machine can directly manipulate each byte of the file. When the bytecode program encapsulated in the second differential file is run, the program will precisely modify, add, or delete the metadata portion of the intermediate ZIP file according to the encoded metadata reconstruction instructions. These instructions are arranged in byte offset order, and the virtual machine executes them sequentially, just as... The original byte stream undergoes fine-tuning. During execution, the virtual machine performs CRC32 checksums and recalculates the modified byte stream in real time to ensure the accuracy of each operation. Since the virtual machine instruction set contains only 16 core operation instructions and has a stack-based architecture, its execution efficiency is extremely high, enabling it to quickly complete complex metadata reconstruction logic. Ultimately, the metadata structure of the byte stream processed by the virtual machine is completely consistent with the original compressed file of the target version, thus achieving accurate restoration from the second new compressed file to the original compressed file of the target version. The entire process does not require the transmission of complete metadata blocks; it can be efficiently completed by transmitting difference instructions and running a lightweight virtual machine, significantly improving the efficiency and resource utilization of differential upgrades.
[0057] The beneficial effects of the above technical solution are as follows: by adopting the solution provided in this embodiment, the amount of data transmission during the differential upgrade process can be greatly reduced while ensuring the byte-level consistency of the original compressed file of the target version; at the same time, the introduction of the embedded lightweight virtual machine ensures the speed and accuracy of the metadata reconstruction process.
[0058] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.
Claims
1. A differential upgrade method for compressed files, characterized in that, Includes the difference stage and the reduction stage; The differential stage includes: S1: Decompress the original compressed file of the starting version and the original compressed file of the target version respectively to obtain the first folder and the second folder; S2: Set uniform file attributes and timestamps for all files in the first folder and the second folder respectively to obtain the first new folder and the second new folder; S3: Use a fixed compression command to compress the first new folder and the second new folder, resulting in a first new compressed file and a second new compressed file respectively; S4: Generate the first difference file based on the differences in file content and structure between the first new folder and the second new folder; S5: Generate a second differential file based on the differences in binary data and metadata between the second new compressed file and the original compressed file of the target version; The restoration phase includes: R1: Decompress the original compressed file from the initial version to obtain the first folder; R2: Set uniform file attributes and timestamps for all files in the first folder to create a new first folder; R3: Use the first difference file to restore the first new folder and obtain the second reconstructed folder; R4: Compress the second rebuilt folder using a fixed compression command to obtain a second new compressed file; R5: Use the second differential file to restore the second new compressed file, and obtain the original compressed file of the target version.
2. The differential upgrade method for compressed files according to claim 1, characterized in that, In step S4, the first difference file is generated using a binary difference algorithm.
3. The differential upgrade method for compressed files according to claim 1, characterized in that, In step S5, a second difference file is generated using a binary difference algorithm.
4. The differential upgrade method for compressed files according to claim 1, characterized in that, Unified file attributes and timestamp settings include: Set the modification time, access time, and change time of all files in the folder to the same fixed value, and set the file permission attributes to the same fixed configuration.
5. A differential upgrade method for compressed files according to claim 1, characterized in that, Fixed compression commands include specified compression tools, compression levels, and compression parameters to ensure that when compressing the same set of file contents and directory structures, the output compressed file is completely identical at the byte level.
6. The differential upgrade method for compressed files according to claim 1, characterized in that, Both the initial version's original compressed file and the target version's original compressed file are ZIP and ZIP64 format files.
7. A differential upgrade method for compressed files according to claim 1, characterized in that, The original compressed file is an OTA upgrade package for automotive ECU (Electronic Control Unit) firmware.
8. A differential upgrade method for compressed files according to claim 1, characterized in that, Step S5 also includes: reconstructing the complete metadata of the original compressed file of the target version, specifically including the following operations: Before performing binary differential operations between the second new compressed file and the original compressed file of the target version, a lossless parsing operation is performed on the original compressed file of the target version. The lossless parsing operation is achieved by directly reading the original byte stream of the original compressed file of the target version and performing syntax and semantic compliance checks according to the ZIP format specification. The metadata set, which is independent of the actual file content data, is identified and extracted. The metadata set includes at least: the original byte values of the structured fields of the local file header, the original byte sequence of the central directory structure, the original byte values of the external attribute fields of each file entry, and the ZIP comment fields. During the generation of the second differential file, based on the metadata set of the second new compressed file and the metadata set of the target version original compressed file, differential calculations are performed on the binary data of the corresponding fields to generate a simplified differential file specifically for metadata reconstruction.
9. A differential upgrade method for compressed files according to claim 8, characterized in that, The original compressed file of the target version is subjected to lossless parsing, including differential analysis and instruction encoding of the metadata set. The specific steps are as follows: The metadata set extracted from the original compressed file of the target version is compared item by item with the corresponding structural information extracted from the second new compressed file to identify the types of metadata differences. Metadata differences are categorized as follows: entry addition / deletion, field value change, and byte padding. For adding or deleting entries, generate entry operation instructions based on the specific information of the added or deleted entries. For adding entries, extract the metadata of the added entries from the original compressed file of the target version and generate entry operation instructions in the format of addition instruction, entry identifier, and complete metadata. For deleting entries, obtain the central directory entry index position corresponding to it in the second new compressed file and generate entry operation instructions in the format of deletion instruction and entry identifier. For field value changes, if the change occurs within a contiguous block of bytes and the contiguous block of bytes does not carry independent semantic field boundaries in the ZIP structure, a binary differential algorithm optimized based on the rolling hash algorithm and the longest common subsequence (LCS) algorithm is used to output a compact binary patch stream. If the change occurs on a structured field with a clearly defined syntactic location and semantic type, then the structured field patch directive is used for encoding. The format of the structured field patch directive is field identifier, new byte value; For byte padding, perform padding consistency checks: By comparing the starting offset, padding length, and padding byte pattern of each padding region in the original compressed file of the target version with the second new compressed file, determine whether the padding was introduced due to differences in compression algorithms, block alignment strategies, or toolchain implementations during the process of recompressing the second new folder to generate the second new compressed file; if it is determined to be new padding or the padding length has changed, and the padding region is located at the end of the local file header, before or after the central directory entry, or near the ZIP64 locator structure, or other positions allowed by the ZIP format specification, then generate padding control instructions. The format of the padding control instructions is: the starting offset address within the ZIP file byte stream, the total length of the padding bytes, and the padding pattern; The entry operation instructions, structured field patch instructions, and padding control instructions are arranged according to their byte offset order in the ZIP file structure to obtain the instruction sequence; The instruction sequence is encapsulated together with the embedded lightweight virtual machine bytecode program to form a second differential file. The virtual machine bytecode program has the functions of instruction decoding, memory mapping access, ZIP structure offset calculation, metadata byte writing and CRC32 checksum recalculation. At runtime, the complete byte stream of the original compressed file of the target version is used as the initial memory image. Each instruction is interpreted and executed in sequence in the specified execution context, and finally the complete metadata that is completely consistent with the original compressed file of the target version is reconstructed.
10. A differential upgrade method for compressed files according to claim 9, characterized in that, In step R5, the specific steps for restoring the second new compressed file using the second differential file to obtain the original compressed file of the target version are as follows: The second new folder is compressed using a fixed compression command to generate an intermediate ZIP file that includes the contents of the target file and the basic ZIP structure. The embedded lightweight virtual machine bytecode program encapsulated in the second differential file is loaded and run. Taking the complete byte stream of the intermediate ZIP file as input, the metadata reconstruction instructions encoded in it are executed to generate a final file that is completely consistent with the original compressed file of the target version at the byte level. The embedded lightweight virtual machine is a dedicated virtual machine based on a stack architecture. Its instruction set contains 16 core operation instructions, covering core functions such as metadata reading and writing, offset calculation, verification and recalculation.
Citation Information
Cited By
Firmware upgrade method, device, storage medium and program product
CN122285054A
