Firmware differentiated hot upgrade method
Patent Information
- Application Number
- CN202211232758.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-10
- Publication Date
- 2026-08-28
- Estimated Expiration
- 2042-10-10
AI Technical Summary
三种升级方式适用的场合不同,当相邻固件版本发生较大变动时,以全包更新的方式对所有的程序进行更新较为方便,但是全包升级消耗内存较大,对设备硬件的要求很高
[0038]本发明的有益效果在于:根据固件的功能模块对固件分段,再在分段文件中选取差异文件传输至下位机,使得在下位机设备运行期间依然能进行补丁升级,仅停用正在补丁升级的功能模块,以实现设备热升级。并且改进bsdiff文件差分算法,生成的补丁文件较原算法生成的补丁文件占用的内存更少和查询的时间更短,具有更好的可压缩性和更高的升级效率。
Smart Images

Figure CN115509591B_ABST
Abstract
Claims
1. A firmware differentiated hot upgrade method, characterized in that, Including the following steps: Step 1: Import the new firmware file new.bin, the old firmware file old.bin, the new firmware file new.map, and the old firmware file old.map into the host computer; Step 2: Extract the differences between the new.map file of the new firmware and the old.map file of the old firmware, and construct the upgrade information file ctrl.bin; Step 3: Divide the old and new firmware into segments according to the functional modules of the firmware. Use the upgrade information file ctrl.bin to filter out the new firmware segment file new_partx.bin and the old firmware segment file old_partx.bin that correspond to the differences between the old and new firmware segment files, where x is the sequence number of the segment file; Step 4: Input the filtered new firmware segment file new_partx.bin and old firmware segment file old_partx.bin into the host computer, and run the upgrade patch construction algorithm to obtain the optimal upgrade patch file update.bin; Step 5: The host computer transfers the upgrade information file ctrl.bin and the upgrade file update.bin to the slave computer; Step 6: The lower-level machine restores the new firmware new_partx.bin using the old firmware old.bin and the upgrade file update.bin, and performs hot upgrades on the firmware file by functional module according to the upgrade information file ctrl.bin; Step 4, the algorithm for constructing the upgrade patch to generate the patch file update.bin, includes the following steps: a. Run the differential algorithm on the host computer to extract the difference information between the new firmware file new_partx.bin and the old firmware file old_partx.bin, and generate a difference file diffx.bin, where x is the difference file number; b. Run the cyclic redundancy check algorithm to generate check bits, concatenate the check bits with the difference file diffx.bin, and concatenate all the difference files diffx.bin segment by segment into a single file diff.bin; c. Compress the difference file diff.bin using a compression algorithm to generate the upgrade patch file update.bin; In step a, a difference file diffx.bin with a smaller memory footprint is constructed by finding the longest approximate prefix of the new firmware file new_partx.bin and the old firmware file old_partx.bin and performing dynamic programming. The longest approximate prefix is obtained by expanding the matching of approximate strings based on the longest common prefix. The diff file diffx.bin consists of two instructions: copy and add. By quantifying the memory usage of each instruction and using dynamic programming, the optimal diff file with the least memory consumption is found. The add and copy instructions respectively include: Where 0 and 1 are identifiers, 0 represents the add instruction and 1 represents the copy instruction; len represents the length of data involved in the current instruction; string is the data type added by the add and copy instructions; address represents the starting address of the copy instruction. When constructing the optimal difference file, the processing steps for the i-th character in the new firmware segment file new_partx.bin include: a1. Find the longest approximate prefix of the i-th character in the segmented file old_partx.bin, and denote its length as k; a2. Calculate the cost of the add instruction at the i-th character in the segmented file new_partx.bin. When the instruction in opt[i-1] is copy, add a complete add instruction; when the instruction in opt[i-1] is add, add[i] = min(add[i-1] + 1, copy[i-1] + 3); a3. Calculate the cost of the copy instruction for the i-th character in the segmented file new_partx.bin. When k is greater than 0, copy[i] = copy[i+1-k] + len*K; when k equals 0, it means that the current byte has no similar prefix, and copy[i] is the maximum value. a4. Compare the costs of the copy[i] instruction and the add[i] instruction for the i-th character, and select the one with the minimum cost as opt[i], i.e., opt[i] = min(copy[i], add[i]); a5. Save the corresponding data result[i], address[i], and datalen[i] of the instructions in opt[i]; a6. Repeat steps a1 to a5 to obtain the minimum cost of all characters in the segment file new_partx.bin and obtain the optimal difference file opt[datalen]. Where opt[i-1] is the minimum cost required to construct the (i-1)th byte in new_partx.bin, add[i-1] and copy[i-1] are the costs required when using add and copy instructions for the (i-1)th byte, respectively, K represents the data compression ratio, result[i], address[i] and datalen[i] represent the instruction type, starting address and length of the data for the i-th byte, respectively, and datalen represents the length of the data in the new segment file new_partx.bin.
2. The firmware differentiated hot upgrade method as described in claim 1, characterized in that, The lower-level machine's memory includes a raw code area, an upgrade code area, and an upgrade record area. The raw code area stores the old firmware file, the upgrade code area stores the new firmware file used for updating during firmware upgrade, and the upgrade record area stores the changes made during the upgrade.
3. The firmware differentiated hot upgrade method as described in claim 2, characterized in that, The original code area also contains an indirect addressing table, which is used to store the location information of each function in the old firmware file. The location information is obtained through a map file.
4. The firmware differentiated hot upgrade method as described in claim 1, characterized in that, In step b, each difference file diffx.bin is added with an identifier and then merged into a single difference file diff.bin. The identifier represents the functional module number corresponding to the difference file diffx.bin.
5. The firmware differentiated hot upgrade method as described in claim 1, characterized in that, In the process of approximate string expansion matching to obtain the longest approximate prefix, the matching formula is used to describe the overall similarity of the expanded strings. When the matching formula is true, the approximate string expansion matching ends. The matching formula is: Where cnt represents the number of times the approximate string is matched with the same character in the extended match, and len represents the length of the extended string.
6. The firmware differentiated hot upgrade method as described in claim 5, characterized in that, In the string approximation expansion process, when the i-th character is matched, the approximation rate of the matched string is... To ensure that local regions of similar strings still have high similarity, the approximation rate of the next character is calculated according to the following formula: in, Indicates the matched Approximation rate per character This represents the matching result of the (i+1)th character, where T is the threshold.
Citation Information
Patent Citations
Firmware differentiation upgrading method
CN111258621A
Firmware upgrading method for single-chip microcomputer
CN112732318A
Differential upgrading method based on national cryptographic algorithm
CN114968323A