CN-115186271-B - Information writing method and terminal of MCU firmware
Abstract
The application provides an information writing method and a terminal of MCU firmware, which are used for acquiring characteristic data of an interrupt vector table of the MCU, determining an end address of the interrupt vector table according to the characteristic data, creating an array in a C language module of original firmware, mapping the address of the array to a physical address of an assembly module in the assembly module of the original firmware, acquiring a link script, defining the address after the end address as the physical address in the link script, creating an analysis tool, acquiring an information space of the original firmware in the analysis tool, writing customized information into the information space, and generating new firmware.
Inventors
- HU ZHIHAO
Assignees
- 福州创实讯联信息技术有限公司
Dates
- Publication Date
- 20260505
- Application Date
- 20220726
Claims (8)
- 1. An information writing method of MCU firmware is characterized by comprising the following steps: s1, acquiring characteristic data of an interrupt vector table of an MCU, and determining an end address of the interrupt vector table according to the characteristic data; s2, creating an array in a C language module of original firmware, and mapping an address of the array to a physical address of an assembly module of the original firmware; s3, acquiring a link script, wherein the address after the end address is defined in the link script as the physical address; s4, creating an analysis tool, acquiring an information space of the original firmware in the analysis tool, writing customized information into the information space, and generating new firmware; the step S4 specifically comprises the following steps: s41, importing the original firmware into the analysis tool, acquiring the end address of an interrupt vector table of the original firmware, and calculating an offset address according to the end address of the interrupt vector table; S42, determining the information space according to the offset address, writing the customized information into the information space, and generating new firmware.
- 2. The method for writing information into MCU firmware according to claim 1, wherein the characteristic data includes a maskable interrupt channel number and an interrupt thread number; The S1 specifically comprises the following steps: the number of the maskable interrupt channels and the number of the interrupt threads of the interrupt vector table are obtained, the total number of interrupts of the interrupt vector table is obtained according to the number of the maskable interrupt channels and the number of the interrupt threads, and the end address of the interrupt vector table is determined according to the total number of interrupts.
- 3. The method for writing information into MCU firmware according to claim 1, wherein S2 specifically comprises: S21, creating an array in a C language module of the original firmware; s22, calling the array in the assembly module, and mapping the address of the array to the physical address of the assembly module through a real address mode.
- 4. The method for writing information into MCU firmware according to claim 2, wherein S3 specifically comprises: S31, acquiring a link script, and acquiring a starting address of the interrupt vector table in the link script; s32, determining the end address of the interrupt vector table according to the total number of interrupts and the start address of the interrupt vector table; s33, defining the ending address of the interrupt vector table in the link script as the starting address of the assembly module of the original firmware.
- 5. An information writing terminal of MCU firmware, comprising a memory, a processor and a computer program stored on the memory and running on the processor, characterized in that the processor realizes the following steps when executing the computer program: s1, acquiring characteristic data of an interrupt vector table of an MCU, and determining an end address of the interrupt vector table according to the characteristic data; s2, creating an array in a C language module of original firmware, and mapping an address of the array to a physical address of an assembly module of the original firmware; s3, acquiring a link script, wherein the address after the end address is defined in the link script as the physical address; s4, creating an analysis tool, acquiring an information space of the original firmware in the analysis tool, writing customized information into the information space, and generating new firmware; the step S4 specifically comprises the following steps: s41, importing the original firmware into the analysis tool, acquiring the end address of an interrupt vector table of the original firmware, and calculating an offset address according to the end address of the interrupt vector table; S42, determining the information space according to the offset address, writing the customized information into the information space, and generating new firmware.
- 6. The information writing terminal of the MCU firmware of claim 5, wherein the characteristic data includes a number of maskable interrupt channels and a number of interrupt threads; The S1 specifically comprises the following steps: the number of the maskable interrupt channels and the number of the interrupt threads of the interrupt vector table are obtained, the total number of interrupts of the interrupt vector table is obtained according to the number of the maskable interrupt channels and the number of the interrupt threads, and the end address of the interrupt vector table is determined according to the total number of interrupts.
- 7. The information writing terminal of the MCU firmware of claim 5, wherein S2 is specifically: S21, creating an array in a C language module of the original firmware; s22, calling the array in the assembly module, and mapping the address of the array to the physical address of the assembly module through a real address mode.
- 8. The information writing terminal of the MCU firmware of claim 6, wherein S3 is specifically: S31, acquiring a link script, and acquiring a starting address of the interrupt vector table in the link script; s32, determining the end address of the interrupt vector table according to the total number of interrupts and the start address of the interrupt vector table; s33, defining the ending address of the interrupt vector table in the link script as the starting address of the assembly module of the original firmware.
Description
Information writing method and terminal of MCU firmware Technical Field The invention relates to the field of embedded systems, in particular to an information writing method and terminal of MCU firmware. Background The Cortex-M0 kernel is designed based on an ARMv6M core architecture by ARM company, the Cortex-M0 is different from other Cortex-M series designs in that the Cortex-M0 kernel is designed with low power consumption, and at present, MCU (Microcontroller Unit, micro control unit) can provide a technical means for identifying product information of the MCU on the MCU software, because the address of the pre-defined data information is changed after compiling operation when the MCU software is compiled and linked, namely, after any source code file is modified, the whole address space is changed. Therefore, in order to achieve information modification of the firmware file, the most commonly used technical means is to introduce identifiable fixed information, and then to find the fixed information to locate the "address" and then to write the located "address" when the information of the firmware file is modified, but this method has the problems that the fixed identifiable information is easily identified and tampered by a third party, and the fixed information is not convenient to be re-customized by an external tool because of the variation of the "address". In addition, if the on-chip flash resources of the MCU are sufficient, a block of flash space can be divided independently without accounting for cost, but the problem is that 1. The address and the size of information to be written later are fixed in the whole firmware file and are also easy to be tampered by a third party according to the information, 2. The division of the flash space is difficult to grasp, the space division is too large, the space waste exists, the space division is too small, the subsequent customization and the expansibility are poor, 3. Because the on-chip flash space division of the MCU is involved, if the address division is improper, the iteration of a software version needs careful wings, and the device becomes a brick once an error occurs. Disclosure of Invention The invention aims to solve the technical problem of providing an information writing method and a terminal of MCU firmware, which realize the customized modification of fixed information and improve the safety of the information. In order to solve the technical problems, the invention adopts the following technical scheme: an information writing method of MCU firmware includes the steps: s1, acquiring characteristic data of an interrupt vector table of an MCU, and determining an end address of the interrupt vector table according to the characteristic data; s2, creating an array in a C language module of original firmware, and mapping an address of the array to a physical address of an assembly module of the original firmware; s3, acquiring a link script, wherein the address after the end address is defined in the link script as the physical address; S4, creating an analysis tool, acquiring an information space of the original firmware in the analysis tool, writing customized information into the information space, and generating new firmware. In order to solve the technical problems, the invention adopts another technical scheme that: An information writing terminal of MCU firmware, comprising a memory, a processor and a computer program stored on the memory and running on the processor, wherein the processor realizes the following steps when executing the computer program: s1, acquiring characteristic data of an interrupt vector table of an MCU, and determining an end address of the interrupt vector table according to the characteristic data; s2, creating an array in a C language module of original firmware, and mapping an address of the array to a physical address of an assembly module of the original firmware; s3, acquiring a link script, wherein the address after the end address is defined in the link script as the physical address; S4, creating an analysis tool, acquiring an information space of the original firmware in the analysis tool, writing customized information into the information space, and generating new firmware. The method has the advantages that an array space is created in the original firmware for storing customized information of the MCU firmware, the array space is built at a physical address after the end address of the interrupt vector table, an analysis tool is created to analyze and acquire the physical address, the customized information is written into the MCU firmware in the physical address, therefore, the array space can be modified in an external mode, the modified array space information is read by the physical address, the customization and modification of the information in the MCU firmware are carried out under the condition that the original firmware code is not changed, and because the method needs to utilize the