Method and device for differential file generation and firmware online upgrade

By making the modified function compilation binary code consistent with the original function length, differential files are generated, and the upgrade failure problem caused by excessive differential packages in FOTA upgrade is solved, and the upgrade success rate and simplification are improved The upgrade process.

CN111930412BActive Publication Date: 2024-11-19ALIBABA GROUP HOLDING LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201910395530.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-05-13
Publication Date
2024-11-19
Estimated Expiration
2039-05-13

Smart Images

  • Figure CN111930412B_ABST
    Figure CN111930412B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for differential file generation and firmware online upgrade. The differential file generation method comprises: modifying the code of a specific function in the source code; compiling the modified code to generate a binary code; generating a differential file based on the modified binary code of the specific function, wherein the replacement code recovered from the differential file is the same size as the binary code of the specific function before modification. Thus, by keeping the binary code size of the specific function consistent before and after modification, the replacement code can directly cover the same physical storage space, avoiding the influence of the modification of one or some functions on the overall binary code segment, thereby reducing the size of the differential file and effectively improving the upgrade success rate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to OTA upgrade, and in particular to a method and device for generating a differential file, and a method and device for performing firmware online upgrade using the differential file. Background Art

[0002] With the development of the Internet of Things, the types of smart devices are becoming more and more diverse. In order to reduce maintenance costs and improve user experience, FOTA (Firmware Over-the-Air, which can be called "Firmware Online Upgrade" or "Firmware Air Upgrade") technology has become the standard in the era of smart Internet of Things. With the popularization of 4G, WiFi and Bluetooth Mesh technology in IoT upgrade devices, more devices have increasing requirements for upgrades.

[0003] During the FOTA upgrade process, due to the size of the data transmitted at one time (for example, no more than 250 bytes) and the limitations of the embedded system, incremental upgrade solutions are more often used. In incremental upgrades, if the differential packet is too large, more transmission times and larger storage space are required, which can easily lead to upgrade failure.

[0004] Therefore, a solution is needed to further reduce the size of the upgrade package and effectively improve the upgrade success rate. Summary of the invention

[0005] In view of this, the present invention proposes a differential file upgrade solution, which addresses the problem that source code modification causes the size of the function to change after compilation, thereby affecting address-related instructions. By making the length of the modified function compiled binary code consistent with the original function, the impact on other instructions is eliminated, thereby further reducing the size of the differential file and effectively improving the upgrade success rate.

[0006] According to one aspect of the present invention, a differential file generation method is proposed, comprising: modifying a specific function in a source code; compiling the modified code to generate a binary code; generating a differential file based on the modified binary code of the specific function, wherein the replacement code recovered from the differential file is the same size as the binary code of the specific function before modification. Thus, by making the length of the compiled binary code of the modified function consistent with that of the original function, the physical storage space occupied by the binary code of the specific function before modification on the upgraded device can be covered, thereby removing the impact on other instructions, and further reducing the size of the differential file, effectively improving the upgrade success rate.

[0007] Preferably, based on the modified binary code of the specific function, generating a differential file includes: generating a differential file including a replacement code of the same size as the binary code of the specific function before modification, wherein the replacement code can execute at least part or all of the functions of the modified specific function. Thus, the code coverage operation is simplified by directly including the replacement code of the same size in the differential file.

[0008] Preferably, the differential file is a binary file that only includes the replacement code and offset-related instructions, thereby facilitating the upgrade operation and further reducing the size of the differential file.

[0009] Preferably, the replacement code includes a null instruction code for filling the modified binary code of the specific function to the same length as the binary code of the specific function before modification, thereby facilitating the production of replacement codes of the same length.

[0010] Preferably, based on the modified binary code of the specific function, generating a differential file includes: comparing the length of the modified binary code of the specific function with the length of the binary code of the specific function before modification; when the length of the modified binary code of the specific function is less than the length of the binary code of the specific function before modification, performing a null instruction filling operation so that the replacement code recovered from the differential file has the same length as the binary code of the specific function before modification; and generating a differential file based on the modified binary code of the specific function after the null instruction filling operation. Thus, the shorter modified code is completed by null instruction filling.

[0011] Preferably, performing an empty instruction filling operation so that the replacement code recovered from the differential file has the same length as the binary code of the specific function before modification includes at least one of the following: filling empty instructions after the source code of the modified specific function so that the filled binary code compiled has the same length as the binary code of the specific function before modification; filling empty instructions after the modified binary code of the specific function until it has the same length as the binary code of the specific function before modification; filling empty instructions for the intermediate code in the compilation process so that the filled binary code compiled has the same length as the binary code of the specific function before modification; and adding instructions for filling empty instructions to the source code of the modified specific function, the intermediate code in the compilation process or the modified binary code of the specific function, so that the modified binary code of the specific function after the empty instruction filling operation is filled to the same length as the binary code of the specific function before modification on the upgrade device based on the instructions for filling empty instructions.

[0012] Preferably, based on the modified binary code of the specific function, generating a differential file also includes: when the length of the modified binary code of the specific function is greater than the length of the binary code before modification of the specific function, further dividing the modified specific function into a main function and an additional function called by the main function, wherein the main function and the additional function are divided so that the length of the binary code compiled by the main function is less than or equal to the length of the binary code before modification of the specific function; when the length of the binary code of the main function is less than the length of the binary code before modification of the specific function, filling the main function with empty instructions so that the length of the binary code after filling of the main function is the same as the length of the binary code before modification of the specific function; using the length of the binary code after filling of the main function as the replacement code and the binary code of the additional function as the additional code to generate a differential file. Thus, the longer modified code is converted into a part with the same length and an additional part by functional difference. Preferably, the differential file also includes offset-related instructions for appending the additional code to the code segment after the upgrade device.

[0013] Preferably, the differential file is a bin file or a compressed package thereof extracted from the compiled ELF file and only for the specific function, thereby facilitating the direct code overwriting operation of the upgraded device.

[0014] Preferably, the differential file includes a plurality of replacement instructions and their respective offset-related instructions, wherein each replacement instruction is directed to a specific function among a plurality of modified specific functions.

[0015] According to another aspect of the present invention, a FOTA (Firmware Online Upgrade) method is also proposed, comprising: obtaining the differential file as described above; and using the replacement code recovered from the differential file to overwrite the physical storage space occupied by the pre-modification binary code of the specific function.

[0016] Preferably, the differential file includes replacement code corresponding to the main function binary code, additional code of the additional function referenced by the main function, and offset-related instructions for appending the additional code to a specified position, wherein the main function and the additional function are used together to implement the functionality of the modified specific function, and the method also includes: based on the offset-related instructions contained in the differential file, appending the additional code after the firmware code segment.

[0017] Preferably, the differential file is a bin file extracted from the ELF file, and using the replacement code recovered from the differential file to overwrite the physical storage space occupied by the binary code of the specific function before modification includes: overwriting the physical storage space occupied by the binary code of the specific function before modification with the bin file to form a complete ELF file in the physical storage of the upgraded device.

[0018] Preferably, the bin file includes the binary code of the modified specific function, the offset value code and the length code of the binary code of the modified specific function, and overwriting the physical storage space occupied by the binary code of the specific function before modification with the bin file to form a complete ELF file in the physical storage of the upgraded device includes: moving the binary code of the modified specific function of the length corresponding to the length code to the position corresponding to the offset value code.

[0019] According to another aspect of the present invention, a differential file generating device is also proposed, comprising: a source code modification unit, used to perform code modification on a specific function in the source code; a compilation unit, used to compile the modified code to generate a binary code; and a differential file generating unit, used to generate a differential file based on the modified binary code of the specific function, wherein the replacement code recovered from the differential file is the same size as the binary code of the specific function before modification.

[0020] Preferably, the differential file generating unit is used to generate a differential file including a replacement code having the same size as the binary code of the specific function before modification, wherein the replacement code can execute at least part or all of the functions of the modified specific function.

[0021] Preferably, the differential file generating unit is used to: compare the length of the modified binary code of the specific function with the length of the binary code of the specific function before modification; when the length of the modified binary code of the specific function is less than the length of the binary code of the specific function before modification, perform an empty instruction filling operation so that the replacement code recovered from the differential file has the same length as the binary code of the specific function before modification; and generate a differential file based on the modified binary code of the specific function after the empty instruction filling operation.

[0022] Preferably, the differential file generation unit is further used to: fill empty instructions after the source code of the modified specific function so that the filled binary code obtained by compilation has the same length as the binary code of the specific function before modification; fill empty instructions after the modified binary code of the specific function until it has the same length as the binary code of the specific function before modification; fill empty instructions with the intermediate code in the compilation process so that the filled binary code obtained by compilation has the same length as the binary code of the specific function before modification; and add instructions for filling empty instructions with the source code of the modified specific function, the intermediate code in the compilation process or the modified binary code of the specific function, so that the modified binary code of the specific function after the empty instruction filling operation is filled to the same length as the binary code of the specific function before modification on the upgrade device based on the instructions for filling empty instructions.

[0023] Preferably, the differential file generating unit is further used for: when the modified binary code length of the specific function is greater than the binary code length of the specific function before modification, further dividing the modified specific function into a main function and an additional function called by the main function, wherein the main function and the additional function are divided so that the binary code length compiled by the main function is less than or equal to the binary code length of the specific function before modification; when the binary code length of the main function is less than the binary code length of the specific function before modification, filling the main function with empty instructions so that the filled binary code length of the main function is the same as the binary code length of the specific function before modification; and using the filled binary code length of the main function as the replacement code and the binary code of the additional function as the additional code to generate a differential file.

[0024] According to another aspect of the present invention, a computing device is provided, comprising: a processor; and a memory on which executable codes are stored, and when the executable codes are executed by the processor, the processor is caused to execute the method described above.

[0025] According to another aspect of the present invention, an Internet of Things device is provided, comprising: a processor; and a memory having executable code stored thereon, wherein when the executable code is executed by the processor, the processor is caused to execute any of the above methods. Preferably, the memory comprises a FLASH storage device.

[0026] According to yet another aspect of the present invention, a non-transitory machine-readable storage medium is provided, on which executable code is stored. When the executable code is executed by a processor of an electronic device, the processor is caused to execute any of the methods described above.

[0027] Therefore, a differential file generation and corresponding FOTA solution of the present invention makes the length of the modified function compiled binary code consistent with the original function, removes the influence on other instructions, so that the differential file can only include the relevant content of the modified function, so as to reduce the size of the differential file and improve the upgrade success rate. For shorter modified codes, simple empty instruction filling can be used to fill them, and for longer modified codes, the same length of replacement code and the additional code part attached to the code segment can be realized by the difference of function functions. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] The above and other objects, features and advantages of the present disclosure will become more apparent through a more detailed description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, wherein like reference numerals generally represent like components in the exemplary embodiments of the present disclosure.

[0029] Figure 1A and 1B An example of system connection during OTA firmware upgrade is shown.

[0030] Figure 2 An example of the impact of a firmware upgrade on a device's physically stored firmware text in the prior art is shown.

[0031] Figure 3 A schematic flow chart of a differential file generation method according to an embodiment of the present invention is shown.

[0032] Figure 4 An example of the impact of a firmware upgrade on a device according to the present invention on its physically stored firmware text is shown.

[0033] Figure 5 An example of firmware upgrade when the modified binary code is smaller than the source code is shown.

[0034] Figure 6 An example of a firmware upgrade when the modified binary code is larger than the source code is shown.

[0035] Figure 7 An example of a normal compilation process is shown.

[0036] Figure 8 An example of creating a differential file according to the present invention is shown.

[0037] Fig. 9 A schematic flow chart of a FOTA method according to an embodiment of the present invention is shown.

[0038] Fig.10 A schematic diagram showing the device-side upgrade process.

[0039] Fig.11 A schematic block diagram of a differential file generating device according to an embodiment of the present invention is shown.

[0040] Fig.12 A schematic diagram of the structure of a computing device according to an embodiment of the present invention is shown. Fig.13 A schematic diagram of the structure of an Internet of Things device that can be used to implement the above-mentioned FOTA method according to an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0041] The preferred embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the preferred embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to make the present disclosure more thorough and complete, and to fully convey the scope of the present disclosure to those skilled in the art.

[0042] The Internet of Things (IoT) is a network that relies on information carriers such as the Internet and telecommunications networks to interconnect all ordinary objects that can perform independent functions. The IoT represents an important development trend that gradually connects all aspects of daily life. Unlike the early wireless devices such as routers (for example, one per room or office), which are limited in number, the IoT can penetrate deeply into all aspects and connect a large number of devices. For example, in a home environment, we can remotely lock doors, open and close curtains, control lighting, and manage temperature and humidity by using IoT technology.

[0043] The large-scale deployment of the Internet of Things faces many challenges, such as: many devices sharing terminals in close proximity and a large number of devices interconnected. These challenges have given rise to the need for FOTA upgrades, which will be an indispensable component of the Internet of Things system. The effectiveness of FOTA has been proven in many applications. For example, mobile phones receive new features and patch vulnerabilities through regular upgrades. To prevent virus attacks, device firmware can obtain the latest patches and more security algorithms through the FOTA upgrade process. Any IoT system consists of two parts: hardware and firmware. In SoC-based applications, the FOTA upgrade function can not only update the firmware, but also reconfigure the on-chip hardware resources.

[0044] Figure 1A and 1B An example of system connection during FOTA upgrade is shown. Figure 1AAs shown, in some application scenarios or for some specific devices, the IoT single-chip device 1 can be directly connected to the Internet to download the required upgrade package from, for example, the OTA management platform 2 when a new version needs to be installed. The upgrade package on the OTA management platform 2 is, for example, prepared and uploaded by a device supplier (not shown) based on the original version and the updated version. Figure 1B As shown, the IoT single-chip device 1 can also be upgraded by connecting to the OTA management platform 2 via, for example, a mobile phone or a gateway device 3. At this time, the intermediate device 3 can use the OTA APP to download and issue the upgrade package and perform related OTA management operations.

[0045] During the FOTA upgrade process, due to the size of the data transmitted at one time (for example, LoRaWAN does not exceed 250 bytes) and the limitations of the embedded system, incremental upgrade solutions are more often used. In incremental upgrades, if the differential packet is too large, more transmission times and larger storage space are required, which can easily lead to upgrade failures.

[0046] Most FOTA upgrades are bug fixes, which may only involve modifying a few or dozens of lines in the source code. However, since the size of the function changes after compilation, the addresses of other functions also change during the link redirection process, affecting address-related instructions, and ultimately making the compiled file have a large difference from the original file.

[0047] Figure 2 FIG. 2 shows an example of the impact of a firmware upgrade on a device's physically stored firmware text in the prior art. Figure 2 As shown on the left, the device to be upgraded has a firmware text portion including five functions (foo1 to foo5) stored in its FLASH (flash memory). In a certain upgrade, although only the source code of the foo1 function is modified, the final binary code will be as follows: Figure 2 As shown on the right, it actually affects the binary code of each subsequent function, and the resulting differential file is also larger. Figure 2 In the example above, the gray background indicates the affected part of the code ( Figure 4-6 The same below).

[0048] To this end, the present invention proposes a novel differential file generation scheme, which addresses the problem that source code modification causes the size of the function to change after compilation, thereby affecting address-related instructions. By making the length of the modified function compiled binary code consistent with the original function, the impact on other instructions is eliminated, thereby further reducing the size of the differential file and effectively improving the upgrade success rate.

[0049] Figure 3The flowchart of the differential file generation method according to an embodiment of the present invention is shown. Obviously, the method is performed on a host for generating differential files, and the generated differential files can then be transmitted to the corresponding device end for firmware upgrade.

[0050] In step S310, code modification is performed on a specific function in the source code. In step S320, the modified code is compiled to generate a binary code. In step S330, a differential file is generated based on the binary code of the modified specific function, wherein the size of the replacement code recovered from the differential file remains unchanged, that is, the same as the size of the binary code of the specific function before modification. In other words, the replacement code recovered from the differential file (which may also include the case where the recovered code is the differential file itself) has the same length as the code before modification. The recovery code of the same length can be used to cover the same physical storage space occupied by the binary code of the specific function before modification on the upgraded device.

[0051] Since the upgrade involves the modification of specific functions, and what is ultimately run on the device side is binary code, the differential file sent to the device side needs to contain the binary code information of the modified specific function. In different implementations, the differential file may contain the binary code itself or its compressed information (which needs to be decompressed on the device side). Regardless of whether it is compressed or not, by making the replacement code recovered from the differential file have the same size as the binary code of the specific function before modification, it is possible to directly overwrite the physical storage space occupied by the binary code of the specific function before modification on the upgraded device, so that the modification of the function will not roughly link the changes in the addresses of other functions during the redirection process and affect the address-related instructions, thereby ensuring that the binary code corresponding to other functions on the device side remains unchanged.

[0052] Figure 4 An example of the impact of a device-side firmware upgrade on its physically stored firmware text according to the present invention is shown. Figure 2 , Figure 4 The left side shows that the device to be upgraded has a firmware text portion including five functions (foo1 to foo5) stored in its FLASH (flash memory). In a certain upgrade, only the source code of the foo1 function is modified. Since the length of the replacement code recovered from the differential file is the same as the length of the foo1 code before the modification, and directly overwrites the foo1 binary code before the modification, this modification is transparent to the subsequent functions foo2 to foo5, and has no effect on the subsequent functions. Figure 4 Shown on the right.

[0053] The differential file may directly include a replacement code of the same size as the binary code of the specific function before modification, and the replacement code can execute at least part or all of the functions of the modified specific function. For example, the differential file may be a binary file that only includes the replacement code and offset-related instructions, such as the bin file described below. Thus, step S330 may include: generating a differential file including a replacement code of the same size as the binary code of the specific function before modification. As an alternative, the differential file may include code that is smaller than the size of the binary code before modification (for example, including empty instruction filling instructions), and the above code can be restored to the same size as the binary code of the specific function before modification on the device side.

[0054] In one embodiment, the replacement code may include an empty instruction code for filling the modified binary code of the specific function to the same length as the binary code of the specific function before modification. Here, "empty instruction code" refers to code that can occupy a storage location in the storage space of the upgrade device but will not cause it to perform any meaningful operation. The aforementioned "empty instruction filling instruction" is an instruction that causes the empty instruction code to be filled. For example, the binary code of the foo1 function before modification occupies 1000 bytes, and the compiled modified binary code occupies 800 bytes. At this time, the empty instruction code occupying 200 bytes can be directly added to the modified binary code to obtain the replacement code that constitutes the differential file; the above-mentioned empty instruction filling instruction can also be added to the modified binary code. The empty instruction filling instruction itself is less than 200 bytes, but it will cause the replacement code in the differential file to be filled with 200 bytes of empty instructions when it is restored on the upgraded device.

[0055] When modifying a specific function, you may encounter a situation where the binary code of the modified function is smaller or larger than the original function. In this case, you can take different action methods.

[0056] Therefore, step S310 may include: comparing the length of the modified binary code of the specific function with the length of the binary code before modification of the specific function; when the length of the modified binary code of the specific function is less than the length of the binary code before modification of the specific function, performing a null instruction filling operation so that the replacement code recovered from the differential file has the same length as the binary code before modification of the specific function; and generating a differential file based on the modified binary code of the specific function after the null instruction filling operation. Thus, through null instruction filling, the modified binary code that is originally smaller than the original function code can be filled into a replacement code with the same length as the original function code. Figure 5 An example of firmware upgrade when the modified binary code is smaller than the source code is shown. Figure 2 and 4 , Figure 5 The left side shows that the device to be upgraded has a firmware text portion including five functions (foo1 to foo5) stored in its FLASH (flash memory). In a certain upgrade, only the source code of the foo1 function is modified. Since the modified binary code is smaller than the binary code of the original function (i.e., shorter in length), empty instructions can be filled after the new foo1 function until it has the same length as the original foo1 function, so as to directly overwrite the foo1 binary code before the modification. Similarly, this modification is transparent to the subsequent functions foo2 to foo5, and has essentially no effect on the subsequent functions, such as Figure 5 Shown on the right.

[0057] In the case where the binary code of the modified function is larger than the original function, step S310 may further include: in the case where the length of the modified binary code of the specific function is larger than the length of the binary code before modification of the specific function, further dividing the modified specific function into a main function and an additional function called by the main function, wherein the main function and the additional function are divided so that the length of the binary code compiled by the main function is less than or equal to the length of the binary code before modification of the specific function; in the case where the length of the binary code of the main function is smaller than the length of the binary code before modification of the specific function, filling empty instructions for the main function so that the length of the filled binary code of the main function is the same as the length of the binary code before modification of the specific function; using the length of the filled binary code of the main function as the replacement code and the binary code of the additional function as the additional code, generating a differential file. Thus, through function splitting and jumping, the modified binary code that is originally larger than the original function code can be split into a replacement code of the same length as the original function code (which may need to be filled with empty instructions) and an additional code for the additional function.

[0058] Figure 6 An example of firmware upgrade when the modified binary code is larger than the source code is shown. Figure 2 , 4 and 5, Figure 6The left side shows that the device to be upgraded has a firmware text portion including five functions (foo1 to foo5) stored in its FLASH (flash memory). In a certain upgrade, only the source code of the foo1 function is modified. Since the modified binary code is larger than the binary code of the original function (i.e., longer in length), directly using it as a replacement code to replace the original foo1 will cause subsequent function codes (e.g., part of the code of the foo2 function) to be overwritten, thereby affecting the normal operation of the firmware. To this end, the modified function can be split into a main function and an additional function. For example, an additional function foo_tmp is added to the new foo1 function (corresponding to the main function), and the new foo1 function calls the foo_tmp. When performing function splitting, it is necessary to make the binary code of the main function smaller than (but as close as possible to) the length of the original function foo1. If the length of the main function is exactly equal to the length of the original function, no additional empty instruction filling operation is required. Otherwise, empty instructions need to be filled at the end of the main function to make it consistent with the size of the original function foo1. For the additional function foo_tmp, you need to first append it to the end of the code segment of the source code, and compile the foo_tmp into a separate part (for example, use the gcc-ffunction-sections compilation option). During the linking stage of compilation, modify the linking script to append foo_tmp to the end of the binary code segment. At this point, the obtained differential file includes the binary code of foo1 (main function) and foo_tmp (additional function). Furthermore, the differential file also needs to include offset-related instructions for appending the additional code to the code segment on the upgraded device. Therefore, when the firmware is upgraded, the new fool code in the differential file can directly overwrite the foo1 binary code before the modification, and foo_tmp is attached to the end of the code segment (for example, after function foo5). Similarly, this modification is transparent to subsequent functions foo2~foo5, and has essentially no effect on subsequent functions, such as Figure 6 Shown on the right.

[0059] The empty instruction filling operation for the modified function (or its main function) can be performed on the code before, during, and after compilation. Specifically, empty instructions can be filled after the source code of the modified specific function so that the compiled filled binary code has the same length as the binary code before modification of the specific function; empty instructions can be filled after the modified binary code of the specific function until the length is the same as the binary code before modification of the specific function; empty instructions can be filled for the intermediate code in the compilation process so that the compiled filled binary code has the same length as the binary code before modification of the specific function. Figure 7 An example of the normal compilation process is shown in FIG. Figure 7As shown, after the technical staff amends the source code, it is necessary to obtain the final executable binary ELF file through compiling, assembling and linking processes. For example, the above-mentioned additional function foo_tmp just needs the linker to be attached to the original code segment of the ELF file by calling the link script. The above-mentioned compiling, assembling and linking processes are the processes involved in the "compile" operation in a broad sense. So, the empty instruction filling in the present invention can be the filling for the source code, for the intermediate code (for example, the illustrated Asm or Obj file), or for the filling of the ELF file finally obtained.

[0060] Furthermore, the above-mentioned filling is even performed on the upgraded device. Specifically, instructions for filling empty instructions can be added to the source code of the modified specific function, the intermediate code in the compilation process, or the modified binary code of the specific function, so that the modified binary code of the specific function after the empty instruction filling operation is filled to the same length as the binary code of the specific function before modification based on the instructions for filling empty instructions on the upgraded device. In other words, "instructions for filling empty instructions" can be added to the source code, Asm code, Obj code or binary code, and the above instructions can eventually implement the actual filling operation on the upgraded device. Here, it should be understood that, although the code addition for different files involves the same operation or empty instructions, the added instruction forms are different. For example, adding empty instructions to the source code involves the operation of the source code instruction line, while adding empty instructions to the binary code involves the direct addition of binary numbers.

[0061] In addition, it should be understood that, although it is preferred to add empty instructions directly after the code with practical significance for the sake of operational convenience, in other embodiments, empty instructions can also be interspersed in the actual code, as long as the binary code length is the same as the binary code length of the original function.

[0062] Figure 8An example of making a differential file according to the present invention is shown. As shown in the figure, the binary ELF file before the firmware upgrade is retained on the host, and a modified binary ELF file after length completion (for example, an empty instruction filling operation) is generated. The two files are differentiated to obtain a differential file in the form of a bin file. In other words, the differential file of the present invention can be a bin file or its compressed package extracted from the compiled ELF file only for the specific function (for example, the foo1 function in the above example). The differential file includes the binary code of the modified specific function (the new foo after filling the empty instruction), the offset value code (that is, foo offset value) and the length code (that is, foo size) of the binary code of the modified specific function. The above-mentioned offset value and code length (also referred to as code size) constitute offset-related instructions, which can be used to move the new foo to the position covering the original foo in the subsequent upgrade device.

[0063] In addition, when the firmware upgrade includes multiple function modifications, the differential file of the present invention may include multiple replacement instructions and their respective offset-related instructions, wherein each replacement instruction is for a specific function among the multiple modified specific functions. In addition to foo1 involving modification and including new foo1 and too_tmp, for example, foo3 also involves modification and includes new foo3 and too_tmp3. At this time, the differential file may include new foo1 and too_tmp, new foo3 and too_tmp3, and their respective offset-related instructions. After obtaining the differential file, the upgrade device can use the new foo1 and foo3 to replace the original foo1 and foo3 respectively, attach too_tmp to the end of the code segment, and attach too_tmp3 to after too_tmp. Of course, updates involving multiple functions can also be implemented one by one in multiple upgrades via different differential files.

[0064] In addition, the difference and upgrade method of the present invention is also applicable to multiple successive updates. For example, in the first upgrade, the original foo1 is replaced with a new foo1 with empty instructions at the end. In the second upgrade, the new foo1 can be further replaced with the updated foo1 and too_tmp. In the second upgrade, the binary code of the specific function before modification actually already contains the empty instructions filled in the first upgrade, but it is obvious that the above filling does not affect the subsequent operation of the second upgrade.

[0065] After the above differential file is generated, the present invention also relates to a FOTA (Firmware Online Upgrade) method. Fig. 9 A schematic flow chart of a FOTA method according to an embodiment of the present invention is shown.

[0066] In step S910, the differential file generated as above is obtained. In step S920, the replacement code recovered from the differential file is used to overwrite the physical storage space occupied by the binary code of the specific function before modification.

[0067] In the case where the updated function code is larger than the original code, the differential file includes a replacement code corresponding to the main function binary code, additional code of the additional function referenced by the main function, and offset-related instructions for appending the additional code to a specified position, wherein the main function and the additional function are used together to implement the functionality of the modified specific function, and the method further includes: based on the offset-related instructions contained in the differential file, appending the additional code after the firmware code segment.

[0068] In one embodiment, the differential file is a bin file extracted from the ELF file, and using the replacement code recovered from the differential file to overwrite the physical storage space occupied by the binary code of the specific function before modification includes: overwriting the physical storage space occupied by the binary code of the specific function before modification with the bin file to form a complete ELF file in the physical storage of the upgrade device. Specifically, the bin file includes the binary code of the modified specific function, the offset value code and the length code of the binary code of the modified specific function, and overwriting the physical storage space occupied by the binary code of the specific function before modification with the bin file to form a complete ELF file in the physical storage of the upgrade device includes: moving the binary code of the modified specific function of the length corresponding to the length code to the position corresponding to the offset value code. Fig.10 The schematic diagram of the device end upgrade process is shown. As shown in the figure, the Bin file overwrites the corresponding new foo binary code to the specified position in the ELF file before modification based on the offset related instructions included therein, thereby obtaining the modified ELF file. The ELF file can then be directly run as the update firmware for the upgraded device.

[0069] Fig.11 A schematic block diagram of a differential file generation device according to an embodiment of the present disclosure is shown. The functional modules of the differential file generation device can be implemented by hardware, software, or a combination of hardware and software that implements the principles of the present disclosure. It can be understood by those skilled in the art that Fig.11 The functional modules described can be combined or divided into sub-modules to implement the principles of the above invention. Therefore, the description herein can support any possible combination, division, or further limitation of the functional modules described herein.

[0070] The following is a brief description of the functional modules that the differential file generation device may have and the operations that each functional module may perform. For the details involved, please refer to the relevant description above and will not be repeated here.

[0071] like Fig.11 As shown, the differential file generating apparatus 1100 may include a source code modifying unit 1110, a compiling unit 1120, and a differential file generating unit 1130. The source code modifying unit 1110 may perform code modification on a specific function in the source code.

[0072] The compiling unit 1120 may compile the modified code to generate a binary code.

[0073] The differential file generating unit 1130 can generate a differential file based on the modified binary code of the specific function, wherein the replacement code recovered from the differential file has the same size as the binary code of the specific function before modification. Thus, the recovered replacement code can be directly used to overwrite the physical storage space occupied by the binary code of the specific function before modification on the upgraded device.

[0074] Optionally, the differential file generating unit may be used to generate a differential file including a replacement code having the same size as the binary code of the specific function before modification, wherein the replacement code can execute at least part or all of the functions of the modified specific function.

[0075] Optionally, the differential file generation unit can be used to: compare the length of the modified binary code of the specific function with the length of the binary code of the specific function before modification; when the length of the modified binary code of the specific function is less than the length of the binary code of the specific function before modification, perform an empty instruction filling operation so that the replacement code recovered from the differential file is the same as the length of the binary code of the specific function before modification; and generate a differential file based on the modified binary code of the specific function after the empty instruction filling operation.

[0076] Optionally, the differential file generation unit can be further used to: fill empty instructions after the source code of the modified specific function so that the filled binary code compiled is the same length as the binary code of the specific function before modification; fill empty instructions after the modified binary code of the specific function until it is the same length as the binary code of the specific function before modification; fill empty instructions for the intermediate code in the compilation process so that the filled binary code compiled is the same length as the binary code of the specific function before modification; and add instructions for filling empty instructions to the source code of the modified specific function, the intermediate code in the compilation process or the modified binary code of the specific function, so that the modified binary code of the specific function after the empty instruction filling operation is filled to the same length as the binary code of the specific function before modification on the upgrade device based on the instructions for filling empty instructions.

[0077] Optionally, the differential file generating unit can be further used for: when the modified binary code length of the specific function is greater than the binary code length of the specific function before modification, further dividing the modified specific function into a main function and an additional function called by the main function, wherein the main function and the additional function are divided so that the binary code length compiled by the main function is less than or equal to the binary code length of the specific function before modification; when the binary code length of the main function is less than the binary code length of the specific function before modification, filling the main function with empty instructions so that the filled binary code length of the main function is the same as the binary code length of the specific function before modification; and generating a differential file using the filled binary code length of the main function as the replacement code and the binary code of the additional function as the additional code.

[0078] Fig.12 A schematic diagram of the structure of a computing device according to an embodiment of the present invention is shown.

[0079] See also Fig.12 , the computing device 1200 includes a memory 1210 and a processor 1220 .

[0080] Processor 1220 may be a multi-core processor or may include multiple processors. In some embodiments, processor 1220 may include a general-purpose main processor and one or more special coprocessors, such as a graphics processing unit (GPU), a digital signal processor (DSP), etc. In some embodiments, processor 1220 may be implemented using a customized circuit, such as an application-specific integrated circuit (ASIC) or a field programmable gate array (FPGA).

[0081] The memory 1210 may include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage devices. Among them, ROM can store static data or instructions required by the processor 1220 or other modules of the computer. The permanent storage device may be a readable and writable storage device. The permanent storage device may be a non-volatile storage device that does not lose the stored instructions and data even after the computer is powered off. In some embodiments, the permanent storage device uses a large-capacity storage device (such as a magnetic or optical disk, flash memory) as a permanent storage device. In some other embodiments, the permanent storage device may be a removable storage device (such as a floppy disk, optical drive). The system memory may be a readable and writable storage device or a volatile readable and writable storage device, such as a dynamic random access memory. The system memory may store some or all instructions and data required by the processor at run time. In addition, the memory 1210 may include any combination of computer-readable storage media, including various types of semiconductor memory chips (DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and disks and / or optical disks may also be used. In some embodiments, the memory 1210 may include a readable and / or writable removable storage device, such as a laser disc (CD), a read-only digital versatile disc (e.g., DVD-ROM, double-layer DVD-ROM), a read-only Blu-ray disc, an ultra-density optical disc, a flash memory card (e.g., SD card, mini SD card, Micro-SD card, etc.), a magnetic floppy disk, etc. The computer-readable storage medium does not include carrier waves and transient electronic signals transmitted wirelessly or wired.

[0082] The memory 1210 stores executable codes, and when the executable codes are processed by the processor 1220 , the processor 1220 can execute the differential file generation method mentioned above.

[0083] Fig.13 A schematic diagram of the structure of an Internet of Things device that can be used to implement the above-mentioned FOTA method according to an embodiment of the present invention is shown.

[0084] See also Fig.13 The IoT device 1300 includes a memory 1310 and a processor 1320, and is preferably implemented as a single-chip embedded system. The memory 1310 may include various types of storage units, such as system memory and permanent storage devices. The permanent storage device may be implemented as the FLASH storage space in the present invention, and is a non-volatile storage device that does not lose the stored instructions and data even after the device is powered off.

[0085] The memory 1310 stores executable codes, and when the executable codes are processed by the processor 1320 , the processor 1320 can execute the differential file generation method mentioned above.

[0086] The differential file generation method and device according to the present invention have been described in detail above with reference to the accompanying drawings.

[0087] This solution addresses the problem that source code modification causes the size of the function to change after compilation, thereby affecting address-related instructions. By making the length of the compiled binary code of the modified function consistent with the original function, the impact on other instructions is eliminated, thereby further reducing the size of the differential file and effectively improving the upgrade success rate.

[0088] In addition, the method according to the present invention may also be implemented as a computer program or a computer program product, which includes computer program code instructions for executing the above steps defined in the above method of the present invention.

[0089] Alternatively, the present invention may also be implemented as a non-temporary machine-readable storage medium (or computer-readable storage medium, or machine-readable storage medium) on which executable code (or computer program, or computer instruction code) is stored. When the executable code (or computer program, or computer instruction code) is executed by a processor of an electronic device (or computing device, server, etc.), the processor executes the various steps of the above-mentioned method according to the present invention.

[0090] Those skilled in the art will further appreciate that the various illustrative logical blocks, modules, circuits, and algorithm steps described in connection with the disclosure herein may be implemented as electronic hardware, computer software, or a combination of both.

[0091] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system and method according to multiple embodiments of the present invention. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or code, and the part of the module, program segment or code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0092] The embodiments of the present invention have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The terms used herein are selected to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.

Claims

1. A differential file generation method, comprising: Make code modifications to specific functions in the source code; Compiling the modified code to generate binary code; Comparing the lengths of the modified binary code of the specific function with the lengths of the binary code of the specific function before the modification; In the case where the length of the binary code after modification of the specific function is less than the length of the binary code before modification of the specific function, performing a null instruction filling operation so that the replacement code restored from the differential file has the same length as the binary code before modification of the specific function; and A differential file is generated based on the modified binary code of the specific function after the null instruction filling operation; wherein the replacement code restored from the differential file has the same size as the binary code of the specific function before modification.

2. The method of claim 1, wherein: Performing a null instruction filling operation so that the replacement code recovered from the differential file has the same length as the binary code of the specific function before modification includes at least one of the following: Filling empty instructions after the modified source code of the specific function so that the compiled binary code after filling has the same length as the binary code before modification of the specific function; Filling empty instructions after the modified binary code of the specific function until the length is the same as the length of the binary code before modification of the specific function; Filling empty instructions for the intermediate code in the compilation process so that the compiled binary code after filling has the same length as the binary code before modification of the specific function; as well as Instructions for filling empty instructions are added to the source code of the modified specific function, the intermediate code in the compilation process, or the modified binary code of the specific function, so that the modified binary code of the specific function after the empty instruction filling operation is filled to the same length as the binary code of the specific function before modification on the upgraded device based on the instructions for filling empty instructions.

3. The method of claim 1, wherein: Based on the modified binary code of the specific function, generating a differential file further includes: In a case where the modified binary code length of the specific function is greater than the binary code length of the specific function before modification, further dividing the modified specific function into a main function and an additional function called by the main function, wherein the main function and the additional function are divided so that the binary code length obtained by compiling the main function is less than or equal to the binary code length of the specific function before modification; In the case where the binary code length of the main function is less than the binary code length of the specific function before modification, padding the main function with empty instructions so that the binary code length of the main function after padding is the same as the binary code length of the specific function before modification; A differential file is generated using the padded binary code length of the main function as the replacement code and the binary code of the additional function as the additional code.

4. The method of claim 3, wherein: The differential file also includes offset-related instructions for appending the additional code to the code segment after the upgraded device.

5. The method of claim 1, wherein: The differential file is a bin file or a compressed package thereof that is extracted from the compiled ELF file and is only for the specific function.

6. The method of claim 5, wherein: The differential file includes a plurality of replacement instructions and their respective offset-related instructions, wherein each replacement instruction is directed to a specific function among a plurality of modified specific functions.

7. A FOTA (Firmware Online Upgrade) method, comprising: Obtain a differential file as described in any one of claims 1 to 6; as well as The same physical storage space occupied by the pre-modification binary code of the specific function is overwritten with the replacement code recovered from the differential file.

8. The method of claim 7, wherein: The differential file includes replacement code corresponding to the binary code of the main function, additional code of the additional function referenced by the main function, and offset-related instructions for appending the additional code to a specified position, wherein the main function and the additional function are used together to implement the function of the modified specific function, and the method further includes: The additional code is appended to the firmware code segment based on the offset-related instructions contained in the differential file.

9. The method of claim 7, wherein: The differential file is a bin file extracted from the ELF file, and the physical storage space occupied by the pre-modification binary code of the specific function is covered by the replacement code recovered from the differential file, including: The bin file is used to overwrite the physical storage space occupied by the binary code of the specific function before modification to form a complete ELF file in the physical storage of the upgraded device.

10. The method of claim 9, wherein: The bin file includes the binary code of the modified specific function, the offset value code and the length code of the binary code of the modified specific function, and the bin file is used to overwrite the physical storage space occupied by the binary code of the specific function before modification to form a complete ELF file in the physical storage of the upgraded device, including: The binary code of the modified specific function having a length corresponding to the length code is moved to a position corresponding to the offset value code.

11. A differential file generating device, comprising: A source code modification unit, used for modifying a specific function in the source code; A compilation unit, used for compiling the modified code to generate binary code; A differential file generating unit, configured to generate a differential file based on the modified binary code of the specific function, wherein the replacement code recovered from the differential file has the same size as the binary code of the specific function before modification; The differential file generating unit is used for: Comparing the lengths of the modified binary code of the specific function with the lengths of the binary code of the specific function before the modification; In the case where the length of the binary code after modification of the specific function is less than the length of the binary code before modification of the specific function, performing a null instruction filling operation so that the replacement code restored from the differential file has the same length as the binary code before modification of the specific function; and A differential file is generated based on the modified binary code of the specific function after the null instruction filling operation.

12. The device of claim 11, wherein: The differential file generating unit is further used for: Filling empty instructions after the modified source code of the specific function so that the compiled binary code after filling has the same length as the binary code before modification of the specific function; Filling empty instructions after the modified binary code of the specific function until the length is the same as the length of the binary code before modification of the specific function; Filling empty instructions for the intermediate code in the compilation process so that the compiled binary code after filling has the same length as the binary code before modification of the specific function; as well as Instructions for filling empty instructions are added to the source code of the modified specific function, the intermediate code in the compilation process, or the modified binary code of the specific function, so that the modified binary code of the specific function after the empty instruction filling operation is filled to the same length as the binary code of the specific function before modification on the upgraded device based on the instructions for filling empty instructions.

13. The device of claim 11, wherein: The differential file generating unit is further used for: In a case where the modified binary code length of the specific function is greater than the binary code length of the specific function before modification, further dividing the modified specific function into a main function and an additional function called by the main function, wherein the main function and the additional function are divided so that the binary code length obtained by compiling the main function is less than or equal to the binary code length of the specific function before modification; In the case where the binary code length of the main function is less than the binary code length of the specific function before modification, padding the main function with empty instructions so that the binary code length of the main function after padding is the same as the binary code length of the specific function before modification; A differential file is generated using the padded binary code length of the main function as the replacement code and the binary code of the additional function as the additional code.

14. A computing device comprising: processor; as well as A memory having executable codes stored thereon, which, when executed by the processor, causes the processor to execute the method according to any one of claims 1 to 9.

15. An Internet of Things device, comprising: A memory having executable codes stored thereon, which, when executed by a processor, causes the processor to execute the method according to any one of claims 7 to 10.

16. The device of claim 15, wherein: The memory includes a FLASH storage device.

17. A non-transitory machine-readable storage medium having executable codes stored thereon, which, when executed by a processor of an electronic device, causes the processor to execute the method according to any one of claims 1 to 10.