Firmware upgrade method, electric energy meter, computer device and storage medium
By optimizing the firmware upgrade method in the smart energy meter, the memory usage is reduced, the problem of limited memory resources is solved, the firmware upgrade is realized without interrupting the service, and the upgrade efficiency and reliability are improved.
Patent Information
- Application Number
- CN202210129315.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2021-12-27
- Filing Date
- 2022-02-11
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2042-02-11
AI Technical Summary
The existing incremental update method consumes a high amount of device memory resources, especially in smart energy meters with limited memory resources. As a result, the firmware upgrade process may not be sufficient to complete the patch process.
By reading the file blocks that do not belong to the file blocks to be deleted one by one from front to back in the storage space into the memory space, and processing them according to the file block type and offset information in the control information, merging and splicing the file blocks to generate new ones. Firmware files to reduce memory space usage.
It reduces the memory resource usage of incremental updates, ensures the successful completion of the firmware upgrade process, and performs firmware upgrades without interrupting device services, shortening service interruption time.
Smart Images

Figure CN114510256B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of program updating, and in particular to a firmware upgrading method, an electric energy meter, a computer device and a computer-readable storage medium. Background Art
[0002] The incremental update method for device firmware upgrade can reduce the amount of data transmitted between the server and the device and improve the upgrade efficiency.
[0003] The BSdiff algorithm is a widely used incremental update algorithm, which includes the diff process and the patch process. In the diff process, the server calculates the difference between the new version of the firmware and the old version of the firmware, encodes and compresses the difference, and generates a patch file. In the patch process, the device decompresses the data specified in the patch file, and applies the patch file and the old version of the firmware according to the corresponding decoding rules to build a new version of the firmware.
[0004] During the diff process, each time a file block of fixed or non-fixed length is processed, a set of data is obtained, which includes: diff string (difference file block), extra string (incremental file block) and corresponding control information. Therefore, the final patch file contains multiple sets of data. During the patch process on the device side, on the one hand, a set of data needs to be read into the memory space, and a certain fragment of the new version of the firmware file needs to be restored based on the control information; on the other hand, the offset information in the control information of each set of data is local offset information. To obtain the offset information of the file fragment in the new version of the firmware file, memory resources need to be occupied for additional calculations. On the other hand, a larger memory space needs to be applied for to store the fragments of the new version of the firmware file. After the complete new version of the firmware file is spliced, the new version of the firmware file is written into the storage space. The existing incremental update method occupies a high amount of memory resources of the device. Summary of the invention
[0005] The present application provides a firmware upgrade method, an electric energy meter, a computer device and a computer-readable storage medium to solve the problem that the existing incremental update method occupies a large amount of memory resources.
[0006] In a first aspect, an embodiment of the present application provides a firmware upgrade method, comprising:
[0007] Obtaining an upgrade compressed package for upgrading the first firmware file to a second firmware file;
[0008] Decompressing the upgrade compressed package, and storing the decompressed third firmware file and control information into a storage space, wherein the third firmware file includes a differential file block and an incremental file block, and the third firmware file is equal to the length of the second firmware file, and the control information includes the offset information of the incremental file block and the offset information of the file block to be deleted, and the first firmware file is also pre-stored in the storage space;
[0009] Reading file blocks that do not belong to the to-be-deleted file blocks in the first firmware file and the third firmware file from the front to the back one by one from the storage space to the memory space, and reading the control information to the memory space;
[0010] Processing the file block according to a processing method determined by the file block type and the offset information in the control information, wherein the processing method includes one of the following: merging two file blocks into a file block to be spliced, and selecting the file block of the third firmware file as the file block to be spliced;
[0011] An empty file is created in the storage space, and the file blocks to be spliced are sequentially spliced into the empty file to obtain a second firmware file.
[0012] In some embodiments, the memory space includes a first memory space, a second memory space and a third memory space, the first memory space is used to store the file blocks of the first firmware file, the second memory space is used to store the file blocks of the third firmware file, and the third memory space is used to store at least one offset information in the control information and the type information of the corresponding file blocks; wherein the first memory space is equal to the size of the second memory space and both are not less than the maximum value of the file blocks of the first firmware file and the third firmware file.
[0013] In some of the embodiments, the sizes of the two file blocks read into the memory space are equal and fixed.
[0014] In some of the embodiments, the sizes of the two file blocks read into the memory space are variable values, and the variable values are determined according to a preset maximum value of the file blocks or the offset information in the control information.
[0015] In some embodiments, processing the file block in a processing manner determined by the file block type and the offset information in the control information includes:
[0016] In the case where the file block type is a differential file block, merging two file blocks into a file block to be spliced;
[0017] In a case where the file block type is an incremental file block, the file block of the third firmware file is selected as the file block to be spliced.
[0018] In some of the embodiments, after sequentially splicing the file blocks to be spliced into the empty file to obtain the second firmware file, the method further includes:
[0019] storing the first firmware file and the second firmware file in different file directories in the storage space;
[0020] After the device is restarted, the firmware file is loaded from the file directory where the second firmware file is stored and executed.
[0021] In a second aspect, an embodiment of the present application provides a firmware upgrade method, including:
[0022] Obtaining a first firmware file and a second firmware file, wherein the second firmware file is an upgraded version of the first firmware file;
[0023] Comparing the first firmware file with the second firmware file to obtain differential file blocks, incremental file blocks, to-be-deleted file blocks, and control information, wherein the control information includes offset information of the incremental file blocks and offset information of the to-be-deleted file blocks;
[0024] Creating an empty file, and sequentially splicing the differential file block and the incremental file block into the empty file to obtain a third firmware file, wherein the third firmware file is equal to the second firmware file in length;
[0025] Compressing the third firmware file and the control information into an upgrade compressed package;
[0026] The upgrade compressed package is sent to the device to be updated, so that the device to be updated can perform firmware upgrade according to the upgrade compressed package.
[0027] In a third aspect, an embodiment of the present application provides an electric energy meter, which includes a memory and a processor, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the firmware upgrade method described in the first aspect is executed.
[0028] In a fourth aspect, an embodiment of the present application provides a computer device, comprising a memory and a processor, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the firmware upgrade method described in the second aspect is executed.
[0029] In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the firmware upgrade method described in the first aspect or the firmware upgrade method described in the second aspect is executed.
[0030] In summary, the firmware upgrade method, electric energy meter, computer device and computer-readable storage medium provided in the embodiments of the present application generate a third firmware file for updating the first firmware file on the server, and read the file blocks that do not belong to the file blocks to be deleted in the first firmware file and the third firmware file from the storage space to the memory space one by one from front to back when performing the firmware upgrade, and use the processing method corresponding to the type of the file block to obtain the file blocks to be spliced, and finally splice the file blocks to be spliced into the empty file in sequence to obtain the second firmware file, thereby solving the problem of large memory resource occupation by the existing incremental update method and reducing the memory resource occupation by the incremental update. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 is a flowchart of the firmware upgrade method provided in this embodiment.
[0032] Figure 2 It is a schematic diagram of the firmware upgrade method provided in this embodiment.
[0033] Figure 3 is a flowchart of another firmware upgrade method provided by this embodiment. DETAILED DESCRIPTION
[0034] In order to more clearly understand the purpose, technical solutions and advantages of the present application, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments.
[0035] To more clearly understand the purpose, technical solutions and advantages of the present application, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments. However, it should be understood by those of ordinary skill in the art that the present application can be implemented without these details. In some cases, in order to avoid unnecessary descriptions that make various aspects of the present application obscure, well-known methods, processes, systems, components and / or circuits that have been described at a higher level will not be described in detail. For those of ordinary skill in the art, it is obvious that various changes can be made to the embodiments disclosed in the present application, and without departing from the principles and scope of the present application, the general principles defined in the present application can be applied to other embodiments and application scenarios. Therefore, the present application is not limited to the embodiments shown, but conforms to the broadest scope consistent with the scope claimed for protection of the present application.
[0036] Unless otherwise defined, the technical terms or scientific terms involved in this application shall have the general meaning understood by people with general skills in the technical field to which this application belongs. The terms used in this application are only for the purpose of describing specific embodiments and are not intended to limit this application. Words such as "one", "a", "a", "the", "these" and the like used in this application do not represent quantitative restrictions, and they can be singular or plural. The terms "include", "comprise", "have" and any variants thereof involved in this application are intended to cover non-exclusive inclusions; for example, a process, method and system, product or device comprising a series of steps or modules (units) is not limited to the listed steps or modules (units), but may include unlisted steps or modules (units), or may include other steps or modules (units) inherent to these processes, methods, products or devices.
[0037] The term "plurality" used in this application refers to two or more than two. Generally, the character " / " indicates that the objects associated with each other are in an "or" relationship. The terms "first", "second", "third", etc. used in this application are only used to distinguish similar objects and do not represent a specific ordering of the objects.
[0038] The terms "system", "engine", "unit", "module" and / or "block" involved in the present application are a method for distinguishing different components, elements, parts, components, assemblies, or functions of different levels by level. These terms can be replaced by other expressions that can achieve the same purpose. Generally, the "module", "unit" or "block" involved in the present application refers to a collection of logic or software instructions embodied in hardware or firmware. The "module", "unit" or "block" described in the present application can be implemented as software and / or hardware, and in the case of being implemented as software, they can be stored in any type of non-volatile computer-readable storage medium or storage device.
[0039] In some embodiments, software modules / units / blocks can be compiled and linked into executable programs. It will be appreciated that software modules can be callable from other modules / units / blocks or from themselves, and / or can be called in response to detected events or interruptions. Software modules / units / blocks configured to be executed on a computing device can be arranged on a computer-readable storage medium, such as a compact disc, a digital video disc, a flash drive, a disk, or any other tangible media, or as a digital download (and can be initially stored in a compressed or installable format that requires installation, decompression or decryption before execution). Such software codes can be stored in part or in whole on the storage device of the computing device being executed, and applied to the operation of the computing device. Software instructions can be embedded in firmware, such as an EPROM. It will also be appreciated that hardware modules / units / blocks can be included in connected logical components, such as gates and triggers, and / or can be included in programmable units, such as programmable gate arrays or processors. The modules / units / blocks or computing device functions described herein can be implemented as software modules / units / blocks, and can also be represented in hardware or firmware. Generally, the modules / units / blocks described herein may be combined with other modules / units / blocks, or may be divided into sub-modules / sub-units / sub-blocks, although they are physically organized or stored. The description may apply to a system, an engine, or a portion thereof.
[0040] It will be understood that when a unit, engine, module, or block is referred to as being "on," "connected," or "coupled to" another unit, engine, module, or block, it may be directly on, connected, coupled, or in communication with the other unit, engine, module, or block, or there may be intermediate units, engines, modules, or blocks, unless the context clearly indicates otherwise. In this application, the term "and / or" may include any one or more of the relevant listed items or combinations thereof.
[0041] The communication between smart energy meters and servers usually adopts a communication method that is low-cost, slow in transmission speed and simple to deploy, such as power line carrier communication; therefore, smart energy meters usually adopt an incremental update method when performing firmware upgrades.
[0042] However, smart energy meters are usually embedded devices, which usually have weak computing power and limited memory resources. In addition, since the various system resources required by the programs running in smart energy meters are usually fixed, from the perspective of economic savings, there are not many available memory resources left in smart energy meters except for running their own programs, for example, the remaining available memory resources are tens of KB. However, when using the traditional BSdiff algorithm, the memory resources required for patching on the smart energy meter side are large, and the remaining memory resources of some smart energy meters are not even enough to complete the patch process.
[0043] To this end, in this embodiment, a firmware upgrade method applicable to a device with limited memory resources is provided, which can be applied to the above-mentioned smart energy meter. Figure 1 is a flowchart of the firmware upgrade method provided in this embodiment. Figure 1 As shown, the process includes the following steps:
[0044] Step S101: obtaining an upgrade compression package for upgrading a first firmware file to a second firmware file.
[0045] Step S102, decompress the upgrade compressed package, and store the decompressed third firmware file and control information into the storage space, wherein the third firmware file includes differential file blocks and incremental file blocks, and the length of the third firmware file is equal to that of the second firmware file, the control information includes offset information of the incremental file blocks and offset information of the file blocks to be deleted, and the first firmware file is also pre-stored in the storage space.
[0046] Step S103, reading file blocks that do not belong to the file blocks to be deleted in the first firmware file and the third firmware file from the storage space one by one from the front to the back into the memory space, and reading the control information into the memory space;
[0047] Step S104: Process the file block in a manner determined by the file block type and the offset information in the control information.
[0048] Step S105, creating an empty file in the storage space, and sequentially splicing the file blocks to be spliced into the empty file to obtain a second firmware file.
[0049] In the above embodiment, the first firmware file and the second firmware file refer to different versions of a certain firmware, wherein the version number of the first firmware file is lower than the version number of the second firmware file, that is, the second firmware file is a newer firmware file, and the first firmware file is an older firmware file. Generally speaking, the version numbers of the first firmware file and the second firmware file are adjacent, but they may not be adjacent.
[0050] The first firmware file is pre-stored in the storage space of the device to be updated, and can be either the firmware file currently loaded by the device to be updated or the firmware file that has been updated in the past by the device to be updated, which is not limited here. Generally speaking, the server and the device to be updated will communicate before performing a firmware upgrade, and the device to be updated will notify the server of the version number of the firmware file currently loaded or the version number of the firmware file stored in the storage space of the device to be updated; and the server notifies the device to be updated of the version numbers of the two firmware files corresponding to the upgrade compressed package to be sent, namely, the version numbers of the first firmware file and the second firmware file.
[0051] The third firmware file and control information obtained by decompressing the upgrade compressed package can be generated based on the BSdiff algorithm. Among them, the third firmware file includes a differential file block and an incremental file block, which are the diff string and the extra string generated by the diff process respectively. Among them, since the diff string contains many repeated characters, it can be compressed with a high compression rate. The difference from generating multiple groups of data in the related art is that the third firmware file of this embodiment has the same length as the second firmware file. For example, taking the string of the first firmware file as ABCDEFGHIJKLMN and the string of the second firmware file as ABCDFFGHIJKLMNabc as an example, the first 14 characters of the first firmware file and the second firmware file are similar, and these 14 characters are differentially processed to obtain 00001000000000, which is the diff string. The last 3 characters of the second firmware file are newly added relative to the first firmware file, namely abc, which is the extra string. Concatenate all the diff strings and extra strings in the original order of the characters, and the resulting 00001000000000abc is the third firmware file.
[0052] In order to distinguish the starting and ending positions of the diff string and the extra string in the third firmware file, the control information includes relevant offset information, for example, the offset information indicates the starting and ending positions of each extra string in the third firmware file, or the starting position where each extra string should be inserted into the first firmware file and the length of each extra string.
[0053] For example, the offset information in the control information includes: the starting offset and the ending offset of the first extra string; the starting offset and the ending offset of the second extra string, ..., and so on. Or, the starting offset and the length of the first extra string; the starting offset and the length of the second extra string, ..., and so on.
[0054] Assuming that the first firmware file is ABCDEFGHIJKLMN and the second firmware file is ACCDEFHIJKLMO, the third firmware file is 010000 and 0000001, which is the concatenation of the two diff strings 010000 and 0000001. In the prior art, the control information stores the offset information of the two diff strings in the first firmware file. Based on the offset information, the device to be updated can know that the character "G" in the first firmware file has been deleted. Therefore, the second firmware file can be restored based on the offset information.
[0055] Different from the prior art, in this embodiment, the control information may not include the offset information of the diff string, but stores the offset information of the file block to be deleted in the first firmware file, thereby saving the storage space of the offset information of the diff string. In comparison, in the two versions of the firmware file, it is usually the case that code segments are added and modified, while the case of deleting code segments is rare, which means that if the offset information of the diff string is not recorded and only the offset information of the file block to be deleted is recorded, the size of the control information can be reduced, thereby further reducing the file size of the upgrade compressed package and improving the upgrade efficiency.
[0056] The memory space applied for in this embodiment includes a first memory space, a second memory space and a third memory space. The first memory space is used to store the file block of the first firmware file, the second memory space is used to store the file block of the third firmware file, and the third memory space is used to store at least one offset information in the control information and the type information of the corresponding file block.
[0057] In the above step S103, when the file blocks that do not belong to the file blocks to be deleted in the first firmware file and the third firmware file are read from the storage space one by one from the front to the back into the memory space, the size of each file block read is determined according to the size of the memory space applied for storing the file blocks, and may not be a preset size. In this way, the device to be updated can apply for available memory space according to the size of its own available memory space, avoiding insufficient memory space caused by using a fixed file block size.
[0058] In order to simplify the calculation of the offset, the size of the first memory space is equal to that of the second memory space, and the size of the file blocks of the first firmware file and the third firmware file read from the memory space each time is also equal. This ensures that the offset and block size of the two file blocks read each time are corresponding, and when both file blocks are diff strings, it is convenient to merge the diff string with the file block of the first firmware file.
[0059] Furthermore, the size of the file blocks of the first firmware file and the third firmware file may be a fixed value or a variable value. When the size of the file blocks of the first firmware file and the third firmware file is a variable value, the maximum value thereof is equal to the size of the first memory space or the second memory space, and the variable value may be determined according to the preset maximum value of the file block or the offset information in the control information, that is, each file block may determine its start and end boundaries based on the offset information in the control information, so that each file block read into the memory space belongs to only one of the file block types, thereby simplifying the processing process.
[0060] In step S104, the processing method includes one of the following: (1) merging two file blocks into a file block to be spliced. (2) selecting a file block of the third firmware file as the file block to be spliced.
[0061] If the file block type is a differential file block, the two file blocks currently stored in the first memory space and the second memory space are merged into a file block to be spliced. If the file block type is an incremental file block, the file block of the third firmware file is selected as the file block to be spliced.
[0062] In some embodiments, when the sizes of two file blocks read into the memory space are equal and are fixed values, the file blocks read into the memory space from the third firmware file each time may also belong to two or more file block types. For example, among the file blocks read into the memory space from the third firmware file, the first part belongs to the differential file block, and the second part belongs to the incremental file block. At this time, the file block parts of the two file block types can be processed according to the above processing method (1) and processing method (2) respectively. The corresponding file block read from the first firmware file will be re-read, and the re-read position is the next offset of the part of the file block that has been merged and processed as the starting offset. Similarly, for the case where the first part of the file block read into the memory space from the third firmware file belongs to the incremental file block, and the second part belongs to the differential file block, the differential file block can be re-read after the incremental file block part is processed in accordance with the above method. The above processing method can ensure that the sizes of the two file blocks remain the same when the differential file block and the file block read from the third firmware file are merged and processed next time.
[0063] In this embodiment, the offset information stored in the third memory space and the current offset information of the pointer when reading the file block of the first firmware file from the storage space can be used to determine whether the file block pointed to by the current pointer belongs to the file block to be deleted and the incremental file block. If the current offset of the pointer falls within the position range represented by the offset information in the third memory space, the file block hits the file block type corresponding to the offset information in the third memory space. Otherwise, it means that the file block pointed to by the pointer belongs to a differential file block.
[0064] In this way, the file block types of the file blocks currently read into the first memory space and the second memory space can be identified, and then it is decided whether to merge to obtain the file block to be spliced or to designate one of them as the file block to be spliced.
[0065] Among them, the offset information representing the file block to be deleted is determined based on the offset of the first firmware file, which avoids the calculation of the offset. Instead, it can be directly judged whether the file block currently being read belongs to the file block to be deleted based on the offset of the pointer of the file block to be deleted in the first firmware file and the offset information of the file block to be deleted in the control information.
[0066] Figure 2 is a schematic diagram of the firmware upgrade method provided in this embodiment. Figure 2 The first firmware file, the second firmware file, the third firmware file and the control information are all stored in the storage space. When the firmware is upgraded, a part of the first firmware file and the third firmware file will be read into the memory space, and the offset information of the file blocks to be deleted and the incremental file blocks will be read from the control information. The file blocks to be spliced are finally spliced into the corresponding positions in the storage space to form the second firmware file.
[0067] Firmware upgrades often require restarting the device, and the firmware is upgraded through the bootloader program of the embedded device before entering the operating system. However, for devices such as smart energy meters that require uninterrupted operation, the firmware upgrade process will cause long-term service interruptions, resulting in inaccurate billing of smart energy meters or long power outages. In order to solve this problem, in this embodiment, since the firmware upgrade solution can occupy very little memory space, the firmware can be upgraded while the device is working normally to obtain a second firmware file. In addition, the first firmware file and the second firmware file will be stored in different file directories in the storage space to ensure that the service provided by the device will not be interrupted during the firmware upgrade process. Thereafter, the device is restarted, and during the restart process, the bootloader program loads the firmware file from the file directory where the second firmware file is stored and runs, thereby completing the firmware upgrade. In this way, the device service interruption time can be shortened to avoid affecting normal business.
[0068] In some embodiments, to ensure the success of the firmware upgrade, after obtaining the second firmware file, the second firmware file will be subjected to an MD5 check to ensure that the second firmware file is complete and correct. If the second firmware file fails to load after restarting, the device will restart again and load the firmware file from the file directory where the first firmware file is stored and run it, to avoid device failure caused by firmware upgrade failure.
[0069] This embodiment also provides a firmware upgrade method, which is applied to a server. Figure 3 FIG. 1 is a flowchart of another firmware upgrade method provided by this embodiment. Figure 3 As shown, the process includes the following steps:
[0070] Step S301, obtaining a first firmware file and a second firmware file, wherein the second firmware file is an upgraded version of the first firmware file.
[0071] Step S302, compare the first firmware file and the second firmware file to obtain differential file blocks, incremental file blocks, file blocks to be deleted and control information, wherein the control information includes offset information of incremental file blocks and offset information of file blocks to be deleted.
[0072] Step S303, creating an empty file, and sequentially splicing the differential file blocks and the incremental file blocks into the empty file to obtain a third firmware file, wherein the length of the third firmware file is equal to that of the second firmware file.
[0073] Step S304: compress the third firmware file and the control information into an upgrade compressed package.
[0074] Step S305: Send the upgrade compressed package to the device to be updated, so that the device to be updated can perform firmware upgrade according to the upgrade compressed package.
[0075] Among them, the firmware upgrade method of the device to be updated is Figure 1 and Figure 2 The firmware upgrade method shown is the same and will not be repeated here.
[0076] This embodiment further provides an electric energy meter, which includes a memory and a processor. The memory stores a computer program, and when the computer program is executed by the processor, the firmware upgrade method applied to the electric energy meter is executed.
[0077] This embodiment also provides a computer device, which includes a memory and a processor, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the above-mentioned firmware upgrade method applied to the server is executed. This embodiment also provides a computer-readable storage medium, which stores a computer program, and when the computer program is executed by the processor, any firmware upgrade method provided in this embodiment is implemented.
[0078] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0079] The above description is only a partial implementation method of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A firmware upgrade method, characterized in that: include: Obtaining an upgrade compressed package for upgrading the first firmware file to a second firmware file; Decompressing the upgrade compressed package, and storing the decompressed third firmware file and control information into a storage space, wherein the third firmware file includes a differential file block and an incremental file block, and the third firmware file is equal to the length of the second firmware file, and the control information includes the offset information of the incremental file block and the offset information of the file block to be deleted, and the first firmware file is also pre-stored in the storage space; Reading file blocks that do not belong to the to-be-deleted file blocks in the first firmware file and the third firmware file from the front to the back one by one from the storage space to the memory space, and reading the control information to the memory space; Processing the file block according to a processing method determined by the file block type and the offset information in the control information, wherein the processing method includes one of the following: merging two file blocks into a file block to be spliced, and selecting the file block of the third firmware file as the file block to be spliced; Create an empty file in the storage space, and sequentially splice the file blocks to be spliced into the empty file to obtain a second firmware file; The memory space includes a first memory space, a second memory space and a third memory space, the first memory space is used to store the file block of the first firmware file, the second memory space is used to store the file block of the third firmware file, and the third memory space is used to store at least one offset information in the control information and the type information of the corresponding file block; wherein the first memory space and the second memory space are equal in size and are not less than the maximum value of the file blocks of the first firmware file and the third firmware file; Processing the file block in a processing manner determined according to the file block type and the offset information in the control information includes: In the case where the file block type is a differential file block, merging two file blocks into a file block to be spliced; In a case where the file block type is an incremental file block, the file block of the third firmware file is selected as the file block to be spliced.
2. The method according to claim 1, characterized in that: The sizes of the two file blocks read into the memory space are equal and fixed.
3. The method according to claim 1, characterized in that: The sizes of the two file blocks read into the memory space are variable values, and the variable values are determined according to a preset maximum value of the file blocks or the offset information in the control information.
4. The method according to any one of claims 1 to 3, characterized in that After the file blocks to be spliced are sequentially spliced into the empty file to obtain the second firmware file, the method further includes: storing the first firmware file and the second firmware file in different file directories in the storage space; After the device is restarted, the firmware file is loaded from the file directory where the second firmware file is stored and executed.
5. A firmware upgrade method, characterized in that: include: Obtaining a first firmware file and a second firmware file, wherein the second firmware file is an upgraded version of the first firmware file; Comparing the first firmware file with the second firmware file to obtain differential file blocks, incremental file blocks, to-be-deleted file blocks, and control information, wherein the control information includes offset information of the incremental file blocks and offset information of the to-be-deleted file blocks; Creating an empty file, and sequentially splicing the differential file block and the incremental file block into the empty file to obtain a third firmware file, wherein the third firmware file is equal to the second firmware file in length; Compressing the third firmware file and the control information into an upgrade compressed package; The upgrade compressed package is sent to the device to be updated, so that the device to be updated can perform firmware upgrade according to the upgrade compressed package based on the firmware upgrade method according to any one of claims 1 to 4 above.
6. An electric energy meter, comprising a memory and a processor, wherein a computer program is stored in the memory, wherein: When the computer program is executed by the processor, the firmware upgrade method according to any one of claims 1 to 4 is executed.
7. A computer device, comprising a memory and a processor, wherein a computer program is stored in the memory, wherein: When the computer program is executed by the processor, the firmware upgrade method of claim 5 is executed.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the firmware upgrade method described in claims 1 to 4 or the firmware upgrade method described in claim 5 is executed.
