Method and system for quickly upgrading software of electric energy meter
By building an upgrade framework for programs in the power meter and generating incremental upgrade files, the rapid upgrade of the power meter software is achieved, and the problems of large resource consumption and long upgrade time are solved, the upgrade efficiency is improved and the hardware resource requirements are reduced.
Patent Information
- Application Number
- CN202510469289.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-15
- Publication Date
- 2025-07-18
AI Technical Summary
In the prior art, the power meter software is greatly consumed during the upgrade process and the upgrade time is long, resulting in low upgrade efficiency.
Build an upgrade framework for programs in the power meter, generate incremental upgrade files, transmit them through communication software and perform program replacement on the power meter, use the upgrade information header to achieve function or binary replacement, reduce the upgrade transmission content, and optimize program space and RAM usage.
It improves the efficiency of power meter software upgrade, reduces the upgrade time, reduces the requirements for chip hardware resources, and the upgrade process is stable and reliable.
Smart Images

Figure CN120335847A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of smart meters, and particularly relates to a method and system for rapid software upgrade of electric energy meters. Background Technique
[0002] The number of on-line electric energy meters is huge, and the current networking communication rate is slow. If full-scale upgrade is used, the bandwidth of other collection tasks will also be affected, affecting other services, and the upgrade time is long. The main cost is in the upgrade file transmission stage; in addition, the hardware resources of the electric energy meter are also small, and the existing technology has high requirements for the hardware resources of the chip. The above reasons lead to low upgrade efficiency of the electric energy meter.
[0003] The patent application with the publication number CN117055938A provides a method, system and device for automatic extraction and on-orbit injection of function-level hot patches, including the following steps: S1. Reserve and divide patch memory space for on-board software, and locate, extract and upload the patch program; S2. In the form of macro functions, splice the patch function and its corresponding original function name into a special string, and define a global structure variable with the special string. The compiler generates corresponding symbol table entries according to the global structure variable; scan the symbol table, extract the patch function and its corresponding original function address information, and generate function redirection instructions; S3. After the on-board patch program and function redirection instructions pass the legality check, redirect the old function to the patch function to start execution, and complete the patching operation. In this patent application, the patch injection method directly rewrites the program running area during the program operation process, which may cause other programs to be abnormal or lost, affecting other services. In addition, it needs to divide multiple reserved areas, which also causes waste of program storage resources and has the same drawbacks as the existing technology.
[0004] Therefore, how to reduce the resource consumption and upgrade duration in the process of electric energy meter software upgrade to improve the upgrade efficiency of electric energy meter software is an urgent problem to be solved by those skilled in the art. Summary of the Invention
[0005] Aiming at the deficiencies of the prior art, the purpose of the present invention is to provide a method for rapid software upgrade of electric energy meters to solve the problems of long upgrade time and large resource waste in the process of electric energy meter software upgrade in the prior art, resulting in low upgrade efficiency; in addition, the present invention also provides a system for rapid software upgrade of electric energy meters.
[0006] To solve the above technical problems, the present invention adopts the following technical solutions:
[0007] In the first aspect, the present invention provides a method for rapid software upgrade of electric energy meters, including the following steps:
[0008] S10. Build the upgrade framework for the program in the electric energy meter: The program space includes the bootloader, the App program area, and the upgrade reserved area, and the RAM space area includes the APP area and the upgrade reserved RAM area;
[0009] S20. Generate the incremental upgrade file: Write the upgrade program, add the upgrade code and the upgrade information header auxiliary information code and compile it to generate the incremental upgrade.bin file;
[0010] S30. Generate the upgrade transfer file: Transfer the incremental upgrade.bin file to the upgrade host computer, generate the upgrade information header and fill it in the head of the upgrade reserved area, and after cropping according to the actual valid area, name it the upgrade transfer file.bin;
[0011] S40. Upgrade file transfer: Use the communication software to transfer the upgrade transfer file.bin to the electric energy meter;
[0012] S50. The electric energy meter is upgraded: After the electric energy meter is reset, it enters the bootloader, parses the content of the upgrade information header area, replaces the program content of the corresponding area according to the content of the information header, resets and runs, and the program upgrade is completed.
[0013] Further, in the step S10, a section of space is reserved for upgrade in both the program space area and the RAM space area. The compiler tool is used to specify that the code segment and the variable segment are generated into the reserved space. The bootloader is used to boot the program and upgrade, and the App program area is the application program area.
[0014] Further, the upgrade reserved area includes an upgrade information header area and an incremental code area. The incremental code area includes upgrade information header auxiliary information and a new function area. The upgrade host computer parses the upgrade information header auxiliary information to generate the upgrade information header, and the new function area is used to store the binary machine code compiled from the new functions written to replace the old functions.
[0015] Further, the definition of the upgrade information header auxiliary information includes the total number of update information and the update information block type. Among them, the total number of update information indicates how many update block units there are in total, and the update information block type is used to indicate whether the next update content is function replacement or binary replacement. If it is function replacement, the content included is the starting address of the old function program, the starting address of the new function program, and the replacement description information in sequence; if it is binary replacement, the content included is the binary replacement address, the binary replacement length, and the binary replacement content in sequence.
[0016] Further, in the step S30, the specific steps for generating the content of the upgrade information header area according to the incremental upgrade file are as follows:
[0017] S301. The host computer parses the power meter program space configuration file. For the IAR programming environment, it parses the icf file of the project to obtain the location information of the upgrade information header area and the upgrade information header auxiliary information area, and obtains the corresponding architecture of the target transfer file through the configuration information of the host computer software.
[0018] S302. Parse the content of the upgrade information header auxiliary information, and generate and fill the corresponding information into the upgrade information header area.
[0019] Among them, the definition of the upgrade information header includes: upgrade information header identifier, total length, number of rewritten information blocks, rewritten information blocks, rewrite address, rewrite length, content before rewrite, content after rewrite, rewrite checksum, and upgrade header information check.
[0020] Furthermore, the host computer for upgrade parses the upgrade information header auxiliary information, and determines whether it is a function replacement or a binary replacement. If it is a function replacement, then by passing the old function address and the new function address to the machine code generation function, combined with the chip architecture information, the rewritten content and the rewritten length area in the rewritten information block are generated by the function. The rewrite address is generated by the old function address in the update information block, and the content before rewrite is copied and filled from the program file before upgrade according to the rewrite address and the rewrite length. If it is a binary replacement, then the rewrite address, the rewrite length, and the rewritten content are generated by the replacement address, the replacement length, and the replacement content respectively, and the generation method of the content before rewrite is the same as that of the function replacement.
[0021] Furthermore, in step S40, the upgrade file uses the power meter general transmission protocol. After the power meter receives the complete upgrade transmission packet, it checks the integrity of the upgrade transmission packet, resets and enters the bootloader, and enters the program upgrade process. When the upgrade file is sent, the checksum of the program to be upgraded and the expected program checksum after upgrade are sent synchronously.
[0022] Furthermore, the specific steps in step S50 are as follows:
[0023] S501. Check the validity of the upgrade package.
[0024] S502. Back up and replace the upgrade information area: Save the information in the upgrade reserved area to an external storage device, and overwrite the upgrade transfer file to the upgrade reserved area.
[0025] S503. Rewrite the original program running area according to the information in the upgrade information header area: Parse the information in the upgrade information header area and replace the corresponding position in the original program area.
[0026] S504. After the replacement is completed, perform a check: Compare whether the expected program checksum after upgrade is consistent with the program checksum after upgrade. If they are consistent, set the upgrade success flag to completed; if they are inconsistent, return to step S503.
[0027] S505, Operation after reset: After reset, the electricity meter checks the upgrade success flag. If successful, it enters normal operation; if not, it repeats steps S501 to S505.
[0028] Furthermore, the verification content in step S501 includes:
[0029] Whether the verification code of the program to be upgraded is consistent with the currently running program. If not, the upgrade exits; whether the content of the upgrade package is consistent with the upgrade package verification code. If not, whether to exit; whether the content of the rewritten information block in this upgrade package meets the requirements of multiple upgrades; after the upgrade is completed, whether the CRC of the overall image is consistent with the expected program verification code after the upgrade.
[0030] In a second aspect, the present invention also provides a system using the above method, including:
[0031] An upgrade host computer for generating an upgrade file package;
[0032] The upgrade program and storage device in the electricity meter for constructing the program upgrade framework, generating auxiliary information of the upgrade file package, receiving the upgrade file package, parsing the upgrade file package, and executing the upgrade action.
[0033] Compared with the prior art, the electricity meter software rapid upgrade method and system provided by the present invention have at least the following beneficial effects:
[0034] In the prior art, during the upgrade process of the electricity meter, there is a large amount of resource waste and a long upgrade time, resulting in low upgrade efficiency of the electricity meter. The process of the present invention is simple and the operation is convenient. By reducing the content of the upgrade transmission, minimizing the use of program space and RAM, the upgrade speed is improved. The upgrade process is stable and reliable, with less resource consumption, reducing the time required for software upgrade of the electricity meter chip, effectively improving the software upgrade efficiency of the electricity meter, and reducing the requirements for the hardware resources of the electricity meter chip to implement the upgrade function. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the solution of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0036] Figure 1 It is a flowchart of a method for rapidly upgrading the software of an electricity meter provided by an embodiment of the present invention;
[0037] Figure 2 It is a schematic diagram of the program space before and after the upgrade during the rewriting process of the fun_a function;
[0038] Figure 3 Schematic diagram of constructing the power meter program upgrade framework in a method for rapid software upgrade of a power meter provided by an embodiment of the present invention;
[0039] Figure 4 Schematic diagram of the process of generating an incremental upgrade file from the original program in a method for rapid software upgrade of a power meter provided by an embodiment of the present invention;
[0040] Figure 5 Schematic diagram of the incremental upgrade file generated in a method for rapid software upgrade of a power meter provided by an embodiment of the present invention;
[0041] Figure 6 Schematic diagram of defining the upgrade information header in a method for rapid software upgrade of a power meter provided by an embodiment of the present invention;
[0042] Figure 7 Schematic diagram of the process from the auxiliary information of the upgrade information header to generating the upgrade information header in a method for rapid software upgrade of a power meter provided by an embodiment of the present invention;
[0043] Figure 8 Schematic diagram after cropping the program space area in a method for rapid software upgrade of a power meter provided by an embodiment of the present invention;
[0044] Figure 9 Schematic diagram of using an upgrade reserved area to support multiple upgrades in a method for rapid software upgrade of a power meter provided by an embodiment of the present invention;
[0045] Figure 10 Schematic diagram of the process of parsing the information in the upgrade information header area and replacing the corresponding positions in the original program area in a method for rapid software upgrade of a power meter provided by an embodiment of the present invention. Detailed implementation manners
[0046] To facilitate the understanding of the present invention, the present invention will be described more comprehensively below with reference to the relevant drawings. The preferred embodiments of the present invention are shown in the drawings. However, the present invention can be implemented in many different forms and is not limited to the embodiments described herein. On the contrary, these embodiments are provided to make the understanding of the disclosure of the present invention more thorough and comprehensive.
[0047] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the technical field to which the present invention belongs. The terms used in the specification of the present invention herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention.
[0048] The present invention provides a method for rapid software upgrade of a power meter, which is applied to the software upgrade process of an intelligent power meter. The method for rapid software upgrade of a power meter includes the following steps:
[0049] S10. Build the upgrade framework for the program inside the electric energy meter: The program space includes the bootloader, the App program area, and the upgrade reserved area; the RAM space area includes the APP area and the upgrade reserved RAM area; S20. Generate the incremental upgrade file: Write the upgrade program, add the upgrade code and the upgrade information header auxiliary information code and compile it to generate the incremental upgrade.bin file; S30. Generate the upgrade transfer file: Transfer the incremental upgrade.bin file to the upgrade host computer, generate the upgrade information header and fill it at the head of the upgrade reserved area, and after trimming according to the actual valid area, name it the upgrade transfer file.bin; S40. Transfer the upgrade file: Use the communication software to transfer the upgrade transfer file.bin to the electric energy meter; S50. Upgrade the electric energy meter: After the electric energy meter is reset, it enters the bootloader, parses the content of the upgrade information header area, replaces the program content of the corresponding area according to the content of the information header, resets and runs, and the program upgrade is completed.
[0050] The present invention reduces the duration of the software upgrade of the electric energy meter, improves the software upgrade efficiency of the electric energy meter, and reduces the requirements for the hardware resources of the electric energy meter chip to implement the upgrade function.
[0051] In order to enable the personnel in the technical field to better understand the solution of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings.
[0052] The present invention provides a method for quickly upgrading the software of an electric energy meter, which is applied to the software upgrade process of an intelligent electric meter, and the idea is as follows:
[0053] During the normal program upgrade process, for example, if the fun_a function needs to be rewritten, generally, after modifying the fun_a function, the entire project is directly compiled, and then the new program.bin is obtained. This method is relatively simple, but due to the compiler, whether the volume of the fun_a function increases or decreases, it will affect the binary code generated by other adjacent functions, resulting in an offset, and the entire binary file will change accordingly. Therefore, even a very small change may cause a large difference between the binary files of the new program.bin and the old program.bin, resulting in an increase in the transmission volume of the upgrade file. Therefore, as Figure 2As shown in the figure, in order to reduce the differences in the program binaries, a program space is reserved at the end of the program space. A new function fun_a_new is added, and several machine instructions starting from the original function fun_a are rewritten to jump to the fun_a_new function. Then, after the fun_a_new function is executed, a return is made. In this way, the upgrade of the fun_a function by the fun_a_new function is achieved. Only the part of the fun_a_new function is the part of the upgrade transmission, and the amount of data transmitted can be minimized. (It is necessary to ensure that the newly added upgrade program does not affect the original program and does not cause changes in the original program area).
[0054] Combined with Figures 1 to 10 , in this embodiment, the method for quickly upgrading the electric energy meter software includes the following steps:
[0055] S10. Build an upgrade framework for the program in the electric energy meter: The program space includes the bootloader, the App program area, and the upgrade reserved area. The RAM space area includes the APP area and the upgrade reserved RAM area.
[0056] Specifically, in this embodiment, as Figure 3 shown, a space is reserved in both the program space area and the RAM space area for upgrading. Through the compiler tool, the code segment and the variable segment can be specified to be generated into this reserved space. The other bootloader is used to boot the program and perform the upgrade, and the App area is the application program area.
[0057] In this embodiment, on the IAR compiler, the following statements are used to complete the specification of the corresponding areas:
[0058] #define __PLACE_IN_HOTFIX_RAM @".upgrade_ram"
[0059] #define __PLACE_IN_HOTFIX_SEG @".upgrade_seg"
[0060] S20. Generate an incremental upgrade file: Write an upgrade program, add upgrade code and upgrade information header auxiliary information code and compile it to generate an incremental upgrade.bin file.
[0061] Specifically, in this embodiment, as Figure 4As shown in the figure, the upgrade reserved area should be divided into two areas. The area in the front is the upgrade information header area that has not been used and reserved in step S20, and the area in the back is the incremental code area. The incremental code area includes: upgrade information header auxiliary information and new function area. The area in the front is the upgrade information header auxiliary information, and the upgrade host will parse the upgrade information header auxiliary information to generate the upgrade information header. Immediately following the upgrade information header auxiliary information is the new function area, which stores the compiled binary machine code of the new functions written to replace the old functions.
[0062] Furthermore, in this embodiment, the definition of the upgrade information header auxiliary information includes the total number of update information and the update information block type. The total number of update information indicates how many update block units there are in total, and the update information block type is used to indicate whether the next update content is function replacement or binary replacement. If it is function replacement, the content included is, in sequence, the starting address of the old function program, the starting address of the new function program, and the replacement description information. Refer to the program filling example. (INT32U)fun1_old represents the starting address of the fun1_old() function in the program area, and this address corresponds to a 4-byte hexadecimal code. The program interval is located in the App area of the program interval. The program interval corresponding to (INT32U)fun1_new is located in the upgrade reserved area of the program space area. The schematic diagram is as shown in Figure 5. If it is binary replacement, the content included is, in sequence, the binary replacement address, the binary replacement length, and the binary replacement content. It should be noted that the scenario where binary replacement is used is generally to rewrite the content of a const fixed array. If the value in the const fixed array needs to be modified, especially when this const is referenced by multiple functions, using binary replacement instead of function replacement can reduce the size of the upgrade file more effectively. After this step, by adding the corresponding code and compiling, the generated incremental upgrade file is as Figure 5 shown (function replacement type).
[0063] S30. Generate the upgrade transfer file: Transfer the incremental upgrade.bin file to the upgrade host, generate the upgrade information header and fill it in the head of the upgrade reserved area. After trimming according to the actual valid area, it is named the upgrade transfer file.bin.
[0064] Specifically, in this embodiment, in step S30, the specific steps for generating the content of the upgrade information header area according to the incremental upgrade file are as follows:
[0065] S301. The host parses the power meter program space configuration file. For the IAR programming environment, it parses the icf file of the project to obtain the location information of the upgrade information header area and the upgrade information header auxiliary information area. Through the configuration information of the host software, it obtains the corresponding architecture of the target transfer file, such as Arm cortex m0.
[0066] S302. Analyze the auxiliary information content of the upgrade information header, generate and fill the corresponding information into the upgrade information header area;
[0067] Among them, as Figure 6 shown, the definition of the upgrade information header includes: upgrade information header identifier, total length, number of rewrite information blocks, rewrite information blocks, rewrite address, rewrite length, content before rewrite, rewritten content, rewrite checksum, and upgrade header information check.
[0068] Specifically, the upgrade information header identifier is a special field, such as "upd_head", used to identify and locate special upgrade information; the total length is the total length of the upgrade information header area; the number of rewrite information blocks is the total number of rewrite information blocks; each rewrite information block contains N pieces of rewrite information, including rewrite address, rewrite length, content before rewrite, rewritten content, and rewrite check; the rewrite address indicates which address area of the program space needs to have its binary content rewritten; the rewrite length indicates the length to be rewritten; the content before rewrite represents the binary content of the program space starting from the rewrite address and with a length of the rewrite length, mainly used to back up the content before rewrite and to verify whether the rewrite positioning is correct during rewriting; the rewrite checksum is the check content of the rewrite information block; the upgrade header information check contains the content checksum of the upgrade header information area.
[0069] Furthermore, in this embodiment, the main process from the upgrade information header auxiliary information to generating the upgrade information header is as Figure 7 shown. The upgrade host computer analyzes the upgrade information header auxiliary information and determines whether it is a function replacement or a binary replacement. If it is a function replacement: by passing the old function address and the new function address to the machine code generation function, combined with the known chip architecture information, the rewritten content and the rewrite length area in the rewrite information block are generated by the function. The rewrite address is generated from the old function address in the update information block, and the content before rewrite is copied and filled from the pre-upgrade program file according to the rewrite address and the rewrite length. If it is a binary replacement, the rewrite address, rewrite length, and rewritten content are generated by the replacement address, replacement length, and replacement content respectively, and the generation method of the content before rewrite is the same as that of the function replacement.
[0070] Furthermore, in this embodiment, the function of generating machine code is further explained:
[0071] The main function of the machine code generation function is that after the MCU runs this section of binary machine code, it can jump to another function, execute and then return.
[0072] Taking the upgrade target as an Arm cortex m0 architecture chip as an example, the corresponding assembly code should be:
[0073] BL new_function
[0074] By referring to the relevant MCU architecture manual, a conversion function from assembly code to binary machine code for this section can be implemented, with an interface similar to the following. This function can return the machine code corresponding to the assembly instructions by inputting the addresses of the original function and the new function.
[0075] INT8U gen_relocate_machine_code(INT32U org_address,
[0076] INT32U new_address
[0077] INT8U*buf)
[0078] Input:
[0079] 1. INT32U org_address: The address of the first instruction of the original function (the function to be replaced)
[0080] 2. INT32U new_address: The entry address of the new function (the replacement function)
[0081] 3. INT8U*buf: A pointer to the buffer for returning the machine code
[0082] Output: Returns the length of the machine code.
[0083] Furthermore, in this embodiment, the generated upgrade information header is filled into the reserved program space area, and the valid part in the upgrade reserved area is cut out, including two parts: the upgrade information header area and the incremental code area, as the upgrade file. As Figure 8 shown, the size of the upgrade transmission file is only the newly modified program area and the upgrade information area, and the transmission content is very small, which is very effective for solving a small modification on site.
[0084] S40. Upgrade file transmission: Use the communication software to transmit the upgrade transmission file.bin to the electric energy meter.
[0085] Specifically, in this embodiment, the upgrade file uses the general transmission protocol of the electric energy meter, such as the DL / T 698 protocol, to transmit the upgrade file package to the internal storage space of the electric energy meter through the communication port. It can be the external FLASH or the unused internal program storage space. After the electric energy meter receives the complete upgrade transmission package, it checks the integrity of the package, resets, and enters the bootloader to enter the program upgrade process.
[0086] Further, in this embodiment, since this fast upgrade method is based on the existing running program, if there are differences between the program to be upgraded and the target program, the upgraded program will not be able to run after the upgrade. Therefore, when the upgrade file is sent, the verification code of the program to be upgraded and the expected program verification code after the upgrade are sent synchronously.
[0087] S50. The electricity meter is upgraded: After the electricity meter is reset, it enters the bootloader, parses the content of the upgrade information header area, replaces the program content in the corresponding area according to the content of the information header, and resets and runs, and the program upgrade is completed.
[0088] Specifically, in this embodiment, the specific steps in step S50 are as follows:
[0089] S501. Verify the validity of the upgrade package. The specific verification includes:
[0090] Whether the verification code of the program to be upgraded is consistent with the currently running program. If not, exit the upgrade.
[0091] Whether the content of the upgrade package is consistent with the upgrade package verification code. If not, whether to exit.
[0092] Whether the content of the rewritten information block of this upgrade package meets the requirements of multiple upgrades.
[0093] Whether the CRC of the overall image is consistent with the expected program verification code after the upgrade after the upgrade is completed.
[0094] Further, in this embodiment, only one upgrade reserved area is used to support multiple upgrades. As Figure 9 shown, a function in the original program upgrade reserved area has been rewritten and set to fun1_new. The starting address of fun1_new is 0x4321, and the starting address of the replaced fun_old is 0x1234.
[0095] In this embodiment, multiple upgrades are supported, and the new upgrade needs to have the characteristics of the previous upgrade. Therefore, it is necessary to determine that the new upgrade file should contain the functions replaced in the previous upgrade. The specific determination method is: the number of rewritten information blocks in the transmitted file should be greater than or equal to the number of rewritten information blocks in the program to be upgraded, and the starting address of the old function in the upgrade auxiliary information header in the rewritten information block in the program to be upgraded should be a subset of the "starting address of the old function" in the upgrade auxiliary information header in the rewritten information block in the upgrade transmission file.
[0096] S502. Back up and replace the upgrade information area: Save the information in the upgrade reserved area to an external storage device, and overwrite the upgrade transmission file to the upgrade reserved area.
[0097] S503. Rewrite the original program running area according to the information in the upgrade information header area: Parse the information in the upgrade information header area and replace the corresponding positions in the original program area, as Figure 10 shown.
[0098] S504. After replacement, perform verification: Compare whether the expected program check code after upgrade is consistent with the program check code after upgrade. If they are consistent, set the upgrade success flag to completed; if not, return to step S503.
[0099] S505. Run after reset: After reset, the electric energy meter detects the upgrade success flag. If successful, enter normal operation; if not, repeat steps S501 to S505.
[0100] The present invention also provides an electric energy meter rapid upgrade system, which is applied to the software upgrade process of smart electric meters. The electric energy meter software rapid upgrade system includes: an upgrade host computer for generating an upgrade file package; an in-electric energy meter upgrade program and storage device for constructing a program upgrade framework, generating auxiliary information of the upgrade file package, receiving the upgrade file package, parsing the upgrade file package, and executing upgrade actions.
[0101] Compared with the prior art, in the prior art, there is a large waste of resources and a long upgrade time during the upgrade process of the electric energy meter, resulting in a low upgrade efficiency of the electric energy meter. The process of the present invention is simple and convenient to operate. By reducing the content transmitted during the upgrade and minimizing the use of program space and RAM, the upgrade speed is improved. The upgrade process is stable and reliable, with less resource consumption, reducing the time required for software upgrade of the electric energy meter chip, effectively improving the software upgrade efficiency of the electric energy meter, and reducing the requirements for the hardware resources of the electric energy meter chip to implement the upgrade function.
[0102] Obviously, the above-described embodiments are only the preferred embodiments of the present invention, rather than all embodiments. The preferred embodiments of the present invention are given in the drawings, but do not limit the patent scope of the present invention. The present invention can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosed content of the present invention more thorough and comprehensive. Although the present invention has been described in detail with reference to the foregoing embodiments, for those skilled in the art, they can still modify the technical solutions described in the foregoing specific embodiments, or perform equivalent replacements for some of the technical features. Any equivalent structure made by using the specification and drawings of the present invention, directly or indirectly applied to other related technical fields, is equally within the scope of the patent protection of the present invention.
Claims
1. A method for rapid software upgrade of an electric energy meter, characterized in that It includes the following steps: S10. Build an upgrade framework for the program in the electricity meter: The program space includes a bootloader, an App program area, and an upgrade reserved area, and the RAM space area includes an APP area and an upgrade reserved RAM area; S20. Generate an incremental upgrade file: Write an upgrade program, add upgrade code and upgrade information header auxiliary information code and compile it to generate an incremental upgrade.bin file; S30. Generate an upgrade transfer file: Pass the incremental upgrade.bin file to the upgrade host computer, generate an upgrade information header and fill it in the head of the upgrade reserved area, and after cropping according to the actual effective area, name it the upgrade transfer file.bin; S40. Upgrade file transfer: Use communication software to transfer the upgrade transfer file.bin to the electricity meter; S50. Upgrade the electricity meter: After the electricity meter is reset, it enters the bootloader, parses the content of the upgrade information header area, replaces the program content of the corresponding area according to the content of the information header, resets and runs, and the program upgrade is completed.
2. A method for rapid software upgrade of an electric energy meter according to claim 1, characterized in that, In step S10, a section of space is reserved for upgrade in both the program space area and the RAM space area. The code segment and variable segment are specified by the compiler tool to be generated into the reserved space. The bootloader is used to boot the program and upgrade, and the App program area is the application program area.
3. A method for rapid software upgrade of an electric energy meter according to claim 2, characterized in that, The upgrade reserved area includes an upgrade information header area and an incremental code area. The incremental code area includes upgrade information header auxiliary information and a new function area. The upgrade host computer parses the upgrade information header auxiliary information to generate an upgrade information header, and the new function area is used to store the binary machine code compiled from the new functions written to replace the old functions.
4. A method for rapid software upgrade of an electric energy meter according to claim 3, characterized in that The definition of the upgrade information header auxiliary information includes the total number of update information and the update information block type. The total number of update information indicates how many update block units there are in total. The update information block type is used to indicate whether the next update content is function replacement or binary replacement. If it is function replacement, the content included is the starting address of the old function program, the starting address of the new function program, and the replacement description information in sequence; if it is binary replacement, the content included is the binary replacement address, the binary replacement length, and the binary replacement content in sequence.
5. A method for rapid software upgrade of an electric energy meter according to claim 4, characterized in that, In step S30, the specific steps for generating the content of the upgrade information header area according to the incremental upgrade file are as follows: S301. The host computer parses the electricity meter program space configuration file. For the IAR programming environment, parse the icf file of the project to obtain the position information of the upgrade information header area and the upgrade information header auxiliary information area, and obtain the corresponding architecture of the target transfer file through the configuration information of the host computer software; S302. Parse the content of the upgrade information header auxiliary information, generate and fill in the corresponding information into the upgrade information header area; Among them, the upgrade information header definition includes: upgrade information header identifier, total length, number of rewritten information blocks, rewritten information blocks, rewrite address, rewrite length, content before rewrite, content after rewrite, rewrite checksum, and upgrade header information check.
6. A method for rapid software upgrade of an electric energy meter according to claim 5, characterized in that, The host computer upgrades the parsing of the upgrade information header auxiliary information, determines it as function replacement or binary replacement. If it is function replacement, the old function address and the new function address are passed into the machine code generation function. Combining with the chip architecture information, the rewritten content and the rewritten length area in the rewritten information block are generated by the function. The rewrite address is generated from the old function address in the update information block. The content before rewriting is copied and filled from the program file before the upgrade according to the rewrite address and the rewrite length. If it is binary replacement, the rewrite address, the rewrite length, and the rewrite content are respectively generated from the replacement address, the replacement length, and the replacement content. The generation method of the content before rewriting is the same as that of function replacement.
7. A method for rapid software upgrade of an electric energy meter according to claim 1, characterized in that In step S40, the upgrade file uses the general transmission protocol of the electric energy meter. After the electric energy meter receives the complete upgrade transmission packet, it verifies the integrity of the upgrade transmission packet, enters the bootloader after reset, and enters the program upgrade process. When the upgrade file is sent, the checksum of the program to be upgraded and the expected program checksum after the upgrade are sent synchronously.
8. A method for rapid software upgrade of an electric energy meter according to claim 1, characterized in that, The specific steps in step S50 are as follows: S501. Verify the validity of the upgrade package; S502. Backup and replace the upgrade information area: Save the information in the upgrade reserved area to an external storage device, and overwrite the upgrade reserved area with the upgrade transmission file; S503. Rewrite the original program running area according to the information in the upgrade information header area: Parse the information in the upgrade information header area and replace the corresponding position in the original program area; S504. After the replacement is completed, perform verification: Compare whether the expected program checksum after the upgrade is consistent with the program checksum after the upgrade. If they are consistent, set the upgrade success flag to completed. If they are inconsistent, return to step S503; S505. Run after reset: After reset, the electric energy meter detects the upgrade success flag. If it is successful, it enters normal operation. If it is not successful, repeat steps S501 to S505.
9. A method for rapid software upgrade of an electric energy meter according to claim 8, characterized in that The verification content in step S501 includes: Whether the checksum of the program to be upgraded is consistent with the currently running program. If they are inconsistent, exit the upgrade; Whether the content of the upgrade package is consistent with the upgrade package checksum. If they are inconsistent, whether to exit; Whether the content of the rewritten information block of this upgrade package meets the requirements of multiple upgrades; After the upgrade is completed, whether the CRC of the overall image is consistent with the expected program checksum after the upgrade.
10. A system using the method according to any one of claims 1 to 9, characterized in that, It includes: The host computer for upgrading, which is used to generate the upgrade file package; The in - meter upgrade program and storage device, which are used for the construction of the program upgrade framework, the generation of auxiliary information of the upgrade file package, the reception of the upgrade file package, the parsing of the upgrade file package, and the execution of the upgrade action.
Citation Information
Patent Citations
Function level hot patch automatic extraction and on-orbit injection method, system and equipment
CN117055938A