CN110192178B - Program patching method and device, micro control unit and terminal equipment - Google Patents

Program patching method and device, micro control unit and terminal equipment Download PDF

Info

Publication number
CN110192178B
CN110192178B CN201780001062.6A CN201780001062A CN110192178B CN 110192178 B CN110192178 B CN 110192178B CN 201780001062 A CN201780001062 A CN 201780001062A CN 110192178 B CN110192178 B CN 110192178B
Authority
CN
China
Prior art keywords
function
patch
memory
current
patch function
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201780001062.6A
Other languages
Chinese (zh)
Other versions
CN110192178A (en
Inventor
杨柯
周永林
邹景华
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Goodix Technology Co Ltd
Original Assignee
Shenzhen Goodix Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Goodix Technology Co Ltd filed Critical Shenzhen Goodix Technology Co Ltd
Publication of CN110192178A publication Critical patent/CN110192178A/en
Application granted granted Critical
Publication of CN110192178B publication Critical patent/CN110192178B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

A method, a device, a micro control unit and a terminal device for program patching are provided, wherein the method comprises the following steps: when a program in a MASK ROM is executed, whether a current function in the program needs to be patched or not is determined according to a first corresponding relation, the first corresponding relation is a corresponding relation between a first identifier and a starting address of a patch function corresponding to the current function in an expansion read only memory, and the first identifier is used for identifying the current function (310); and under the condition that the current function needs to be patched, executing a first patch function according to the initial address, wherein the first patch function is a patch function corresponding to the current function (320). The method can improve the flexibility of the program and improve the user experience.

Description

Program patching method and device, micro control unit and terminal equipment
Technical Field
The embodiment of the invention relates to the field of computers, in particular to a method and a device for patching a program, a micro control unit and terminal equipment.
Background
The ROM can be roughly divided into a Mask Read Only Memory (Mask ROM), a One Time programming Read Only Memory (OTP ROM), a Multi Time programming Read Only Memory (MTP ROM), an erasable programmable Read Only Memory (FLASH ROM), and the like, where the Mask ROM has a low manufacturing cost, and the program is already cured in the chip generation stage and cannot be modified after leaving the factory, and meets the fixed occasion of the program, so that considering cost and power consumption, in the case that the program is already very stable through repeated modification and testing, it may be considered to write the program into the Mask ROM in the chip production process, and then once the program is written into the Mask ROM, no modification can be performed afterwards, which causes insufficient flexibility of the program and low user experience.
Disclosure of Invention
The embodiment of the invention provides a method and a device for patching a program, a micro control unit and terminal equipment, which can improve the flexibility of the program and improve the experience of a user.
In a first aspect, a method for patching a program, where the program is stored in a MASK read only memory MASK ROM, includes:
determining whether a current function in the program needs to be patched or not according to a first corresponding relation when the program in the MASK ROM is executed, wherein the first corresponding relation is a corresponding relation between a first identifier and a starting address of a patch function corresponding to the current function in an expansion read only memory, and the first identifier is used for identifying the current function; and executing a first patch function according to the starting address under the condition that the current function needs to be patched, wherein the first patch function is a patch function corresponding to the current function.
In the embodiment of the invention, the patch function is stored in the expansion read-only memory, when the current function in the MASK ROM is patched, the first patch function storage address corresponding to the current function is determined through the first corresponding relation, and the first patch function is operated, so that the flexibility of the program can be improved, and the experience degree of a user is improved.
With reference to the first aspect, in a first implementation manner of the first aspect, determining whether a current function in the program needs to be patched according to a first corresponding relationship when the program in the MASK ROM is executed includes: determining whether the starting address of the patch function corresponding to the current function is located in the address space of the extended read-only memory or not according to the first corresponding relation; and under the condition that the initial address of the patch function corresponding to the current function is located in the address space of the extended read-only memory, determining that the current function needs to be patched.
In the embodiment of the invention, because the patch function is stored in the expansion read-only memory, whether the current function needs to be patched or not can be simply and conveniently determined by determining whether the starting address of the patch function corresponding to the current function is located in the expansion read-only memory or not.
With reference to the first aspect or the first implementation of the first aspect, in a second implementation of the first aspect, the executing a first patch function according to the start address when the current function needs to be patched includes: taking the parameter of the current function as the parameter of the first patch function; and executing the first patch function according to the starting address of the first patch function in the expansion read-only memory and the parameters of the first patch function.
With reference to the first aspect or any one of the first and second implementation manners of the first aspect, in a third implementation manner of the first aspect, the expansion rom is further configured to store a patch function structure, where the patch function structure includes a parameter variable, a return value variable, and a function pointer array, the parameter variable is used to transfer a parameter of the current function, the return value variable is used to transfer a return value obtained after any one patch function is executed, each function pointer in the function pointer array is used to indicate a start address of each patch function in the expansion rom, and the function structure is located in a lowest address space in the expansion rom.
With reference to the first aspect or any one of the first to third implementation manners of the first aspect, in a fourth implementation manner of the first aspect, the determining that the parameter of the current function is a parameter of the first patch function includes: assigning the parameters of the current function to the parameter variables in the patch function structure; and acquiring the parameter of the current function from the parameter variable in the patch function structure as the parameter of the first patch function.
With reference to the first aspect or any one of the first to fourth implementation manners of the first aspect, in a fifth implementation manner of the first aspect, the method further includes: determining whether the current function requires a return value; assigning a return value obtained by executing the first patch function to the return value variable in the patch function structure under the condition that the current function needs the return value; and acquiring the return value from the return value variable in the patch function structure as the return value of the current function.
With reference to the first aspect or any one of the first to fifth implementation manners of the first aspect, in a sixth implementation manner of the first aspect, the method further includes: copying the instance of the patch function structure into a Random Access Memory (RAM) before executing the program.
With reference to the first aspect or any one of the first to sixth implementation manners of the first aspect, in a seventh implementation manner of the first aspect, the extended ROM includes at least one of a one-time-programming ROM OTP ROM, a multi-time-programming ROM MTP ROM, and an erasable programmable ROM FLASH ROM.
In a second aspect, an apparatus for patching a program is provided, comprising one or more components for performing the method embodiments of the first aspect.
In a third aspect, there is provided a micro-control unit comprising means for optional program patching of the second aspect or any of the second aspects.
In a fourth aspect, there is provided a terminal device comprising the apparatus of the second aspect or any optional program patching of the second aspect.
In a fifth aspect, a computer-readable medium is provided, where the computer-readable medium is used for storing program code executed by an apparatus for data analysis, and the program code includes instructions for executing the method in the first aspect and the implementation manners of the first aspect.
In a sixth aspect, a system chip is provided, which includes an input/output interface, at least one processor, at least one memory, and a bus, where the at least one memory is used to store code, and the at least one processor is used to call the code of the at least one memory to perform the operations of the method of the above aspects.
Drawings
FIG. 1 is a system framework diagram of a micro control unit of an embodiment of the present invention.
FIG. 2 is a mapping relationship diagram of a memory address space according to an embodiment of the invention.
FIG. 3 is a schematic flow chart diagram of a method of program patching according to an embodiment of the present invention.
FIG. 4 is another schematic flow chart diagram of a method of program patching according to an embodiment of the present invention.
Fig. 5 is a schematic block diagram of an apparatus for program patching, according to an embodiment of the present invention.
Fig. 6 is a schematic block diagram of an apparatus for program patching according to an embodiment of the present invention.
Detailed Description
The following describes technical solutions of embodiments of the present invention with reference to the accompanying drawings.
In the embodiment of the present invention, a method for patching a program is described by taking an example that a program stored in a Mask Read Only Memory (Mask ROM) in a Micro Controller Unit (MCU) needs to be patched, but the embodiment of the present invention is not limited thereto.
Fig. 1 is a diagram showing an MCU system framework, in which a MASK ROM stores a solidified program, and a Central Processing Unit (CPU) is powered on to execute the program from a start address of the MASK ROM by default. One-Time programmable Read Only Memory (OTP ROM), multi-Time programmable Read Only Memory (MTP ROM), and erasable programmable Read Only Memory (FLASH ROM) are optional ROM, one or more optional ROM may be selected comprehensively in an actual system according to application scenarios, cost, and MCU architecture design, and Random Access Memory (RAM) is used to store variables and program data during program operation.
Based on the system framework of the MCU described above, in the embodiment of the present invention, the patch function is stored in the expansion read-only memory (OTP ROM, MTP ROM, FLASH ROM), and after the current function is determined to be required to be patched, the patch function is executed according to the address of the corresponding patch function in the expansion read-only memory, so that the function in the MASK ROM is patched, the flexibility of the program is improved, and the user experience is improved.
Assuming that the processor used in the embodiment of the present invention is a 16-bit processor, the address space of the memory is 0x0000-0xFFFF, and a mapping relationship of the memory address space is shown in fig. 2, where 0x0000-0x4000 is the address space of the register and the random access memory, 0x4000-0x8000 is the storage space of the expansion memory, and 0x8000-0xFFFF is the storage space of the MASK ROM, as shown in fig. 2, the embodiment of the present invention stores the patch function corresponding to the program in the MASK ROM in the address space 0x4000-0x8000 of the expansion read only memory, and the patch function structure is stored in the lowest address space in the expansion memory.
Fig. 3 is a schematic flow chart of a method 300 for patching a program according to an embodiment of the present invention, and as shown in fig. 3, the method 300 includes some or all of the following steps.
310, when executing a program in the MASK ROM, determining whether a current function in the program needs to be patched according to a first corresponding relationship, where the first corresponding relationship is a corresponding relationship between a first identifier and a starting address of a patch function corresponding to the current function in the expansion read only memory, and the first identifier is used to identify the current function.
And 320, under the condition that the current function needs to be patched, executing a first patch function according to the starting address, wherein the first patch function is a patch function corresponding to the current function.
In the embodiment of the invention, the first patch function is called according to the address of the first patch function in the extended read-only memory, and the current function is patched, so that the flexibility of a program is improved, and the user experience is improved.
Optionally, the current function in the embodiment of the present invention is stored in the MASK ROM, that is, the current function in the embodiment of the present invention is one or more functions in a program stored in the MASK ROM.
Optionally, the patch function corresponding to the current function is stored in the expansion read-only memory.
Optionally, the expansion read-only memory may include at least one of OTP ROM, MTP ROM, and FLASH ROM.
It should be understood that the first identifier is a user's mark according to a preset rule on a function that may need to be patched in a program in the MASK ROM, and the first identifier may be multiple. For example, a user numbers a commonly used key function or a commonly used important function in a program stored in the MASK ROM, any number of the numbers may be used as the first identifier, and the key function or the important function may be determined by the user according to different evaluation rules.
Optionally, the first correspondence is a correspondence between the first identifier and a starting address of the patch function corresponding to the current function in the expansion read-only memory.
It should be understood that the current function may be any one of the functions in the program stored in the MASK ROM, and the first identifier for identifying the current function may be understood as a first identifier when the current function is any one of the functions in the MASK ROM, for example, there are 5 functions in the program stored in the MASK ROM, where the third function has a number, and when the program runs to the third function, the third function is taken as the current function, and the number of the third function may be regarded as the first identifier.
Optionally, the current function in the embodiment of the present invention may be understood as a function to be patched, and whether the function to be patched actually needs to be patched or not may also need to be determined according to the first corresponding relationship.
That is to say, there may be a plurality of functions to be patched in the program of the MASK ROM, and when it is determined that a certain function needs to be patched, the identifier of the corresponding function may be used as the first identifier.
For example, there are 10 functions in the program stored in the MASK ROM, where the numbers of the second function, the third function, the fifth function, the seventh function, and the tenth function are (1), (2), (3), (4), and (5), respectively, in this case, when the program runs to the second function, the second function may be used as the current function, and the number (1) of the corresponding second function is used as the first identifier, to determine whether the second function needs to be patched; when the program runs to a fifth function, the fifth function can be taken as the current function, the number (3) of the corresponding fifth function is taken as the first identifier, whether the fifth function needs to be patched or not is determined, and the like, and when the program runs to which numbered function, the numbered function can be taken as the current function, and the number is taken as the first identifier.
Optionally, when the current function needs to be patched, according to the starting address, a first patch function corresponding to the current function may be determined, and after obtaining parameters of the first patch function, the first patch function is executed.
Optionally, after it is determined that the current function needs to be patched, the parameter of the current function may be obtained, and the parameter of the current function is used as a parameter of the first patch function, and when the first patch function is operated to patch the current function, the parameter of the current function is the parameter of the first patch function.
Specifically, the embodiment of the present invention sets a patch function structure, where the patch function structure may be stored in a lowest address space of the expansion rom, and the patch function structure includes a parameter variable, a return value variable, and a function pointer array, where the parameter variable is used to transfer a parameter of any current function in at least one current function, the return value variable is used to transfer a return value obtained after executing any patch function, and each function pointer in the function pointer array is used to indicate a start address of each patch function in the expansion rom.
The program described below is a patch function structure.
#define PARAMETER_LENGTH 5
#define PATCH_FUNC_NUM 64
Figure GWB0000003554040000081
As can be seen from the above program, this patch function structure defines 64 patch functions, where parameter [ ] is a parameter variable, ret _ val [ ] is a return value variable, and func _ patch _ addr [ ] is a function pointer array, and in this function structure, the function pointer array of func _ patch _ addr [ ] includes 64 function pointers, each function pointer indicating the start address of one patch function.
Since the function pointer may be used to indicate the start address of the patch function, the first corresponding relationship may be understood as a corresponding relationship between the first identifier and a first function pointer, where the first function pointer is used to indicate the start address of the patch function corresponding to the current function.
Optionally, the first corresponding relationship may be stored in the patch function structure.
After the patch function structure is defined, the parameter of the current function may be assigned to a parameter variable parameter [ ] in the patch function structure, and when the first patch function is executed, the parameter of the current function may be taken out from the parameter variable parameter [ ]asthe parameter of the first patch function.
After the first patch function obtains the parameter of the current function as the parameter of the first patch function, the first patch function is operated, when the first patch function is operated, whether the return value after the first patch function is operated is assigned to the return value variable ret _ val [ ] in the patch function structure is determined according to whether the current function needs the return value, namely under the condition that the current function needs the return value, the return value obtained after the first patch function is operated is assigned to the return value variable ret _ val [ ] in the patch function structure after the first patch function is operated.
It should be understood that there is only one patch function structure, that is, no matter how many patch functions exist, there is only one patch function structure, the function pointer array in the patch function structure includes addresses of all current patch functions, the parameter variable parameter [ ] and the return value variable ret _ val [ ] are empty in the initial stage, when one function is patched, the parameter of the function is assigned to the parameter variable parameter [ ], after the patch function corresponding to the function is run, the value obtained by the run is assigned to the return value variable ret _ val [ ], when another function is patched next time, the value in the parameter variable parameter [ ] is the parameter of the function that needs patching this time, the value in the return value variable ret _ val [ ] is the return value obtained by running the patch function corresponding to the function that needs patching this time, therefore, the parameter variable parameter [ ] and the return value variable ret _ val [ ] in the patch function structure are different with the current function, and the function pointer _ patch function pointer array does not hold the parameter variable.
Since the parameter variable parameter and the return value variable ret _ val in the patch function structure vary with the operation of the program, in the initialization phase, an instance of the patch function structure needs to be copied into a RAM, and all subsequent operations on the patch function structure are executed in the RAM.
Fig. 4 is a schematic flow chart of a method 400 for patching a program according to an embodiment of the present invention, and as shown in fig. 4, the method 400 includes some or all of the following steps.
405, it is determined whether the address indicated by the first function pointer corresponding to the first identifier is an empty address based on the first identifier and the first correspondence relationship, and if the address indicated by the first function pointer is empty, step 410 is executed, and if the address indicated by the first function pointer is not empty, step 415 is executed.
Optionally, the first identifier is used to identify the current function.
Optionally, the first function pointer is used to indicate a start address of a patch function corresponding to the current function.
Optionally, the first mapping relationship is a mapping relationship between the first identifier and a start address of the patch function corresponding to the current function in the expansion read-only memory, that is, a mapping relationship between the first identifier and the first function pointer.
Optionally, the first corresponding relationship is stored in a pointer function array of the patch function structure.
Optionally, the patch function corresponding to the current function is also stored in the expansion read-only memory.
The execution of the function following the current function in the MASK ROM continues 410.
415, determining whether the current function needs to be patched according to whether the address indicated by the first function pointer is located in the storage space of the expansion read only memory, executing step 420 when the address indicated by the first function pointer is not located in the storage space of the expansion read only memory, and executing step 425 when the current function needs to be patched.
Optionally, in the embodiment of the present invention, the patch function is stored in the expansion read-only memory, so that it is determined whether the address indicated by the first function pointer is located in the expansion read-only memory, and it can be determined whether the current function needs to be patched.
And 420, returning error information, and ending the program running.
It should be understood that, since the patch function is stored in the expansion read-only memory, when the address indicated by the first function pointer is not located in the storage space of the expansion read-only memory, it indicates that the current function does not have a corresponding patch function, the current function cannot be patched, and the program operation ends.
425, assign the parameters of the current function to the parameter variable parameter in the patch function structure.
430, the program jumps to the first patch function corresponding to the current function, and executes the first patch function.
The parameter is extracted from the parameter variable parameter [ ] in the patch function structure as the parameter of the first patch function 435.
It should be understood that, at this time, the parameter of the first patch function parameter variable parameter is the parameter of the current function, i.e., the parameter of the current function is assigned to the patch parameter variable parameter in the patch function structure in step 425.
440, after the execution of the first patch function is finished, according to whether the current function needs a return value, it is determined whether to assign the return value to a return value variable ret _ val [ ] in the patch function structure, when the current function needs a return value, step 445 is executed, and when the current function does not need a return value, step 450 is executed.
445, when the current function requires a return value, assigns the return value to a return value variable ret _ val [ ].
Optionally, after assigning the return value to the return value variable ret _ val [ ], the first patch function ends to run, continue to execute the functions after the current function, and continue to determine whether the functions after the current function need to be patched, and when there are functions that need to be patched in the functions after the current function, repeat the method 400.
And 450, when the current function does not need to return the value, the first patch function is finished running, and the functions after the current function are continuously executed.
In the embodiment of the invention, the first patch function is called according to the address of the first patch function in the extended read-only memory, and the current function is patched, so that the flexibility of the program is improved, and the user experience is improved.
Method embodiments of the present invention are described in detail above with reference to fig. 3 and 4, and apparatus embodiments of the present invention are described in detail below with reference to fig. 5 and 6, with the understanding that apparatus embodiments correspond to method embodiments, and similar descriptions may be had with reference to method embodiments.
Fig. 5 is a schematic block diagram of an apparatus 500 for patching a program according to an embodiment of the present invention, and as shown in fig. 5, the apparatus 500 includes some or all of the following component blocks.
A MASK read only memory (MASK ROM) 510 for storing programs.
And an expansion read only memory 520 for storing a corresponding patch function in the program.
The processor 530 is configured to determine whether a current function in the program needs to be patched according to a first corresponding relationship when the program in the MASK ROM is executed, where the first corresponding relationship is a corresponding relationship between a first identifier and a starting address of a patch function corresponding to the current function in the expansion read only memory, and the first identifier is used to identify the current function.
The processor 530 is further configured to execute a first patch function according to the start address when the current function needs to be patched, where the first patch function is a patch function corresponding to the current function.
It should be understood that the current function may be one function or may be multiple functions.
Optionally, the expansion read-only memory 520 may be at least one of OTP ROM, MTP ROM and FLASH ROM.
It should be understood that the first identifier is a user's mark according to a preset rule on a function that may need to be patched in a program in the MASK ROM, and the first identifier may be multiple. For example, the user numbers a commonly used key function or a commonly used important function in the program stored in the MASK ROM, any one of the numbers may be used as the first identifier, and the key function or the important function may be determined by the user according to different evaluation rules.
Optionally, the processor 530 is further configured to determine whether a start address of the first patch function is located in an address space of the extended read only memory according to the first corresponding relationship.
Optionally, the processor 530 is further configured to determine that the current function needs to be patched, if the start address of the first patch function is located in the address space of the expansion read-only memory.
It should be understood that, in the embodiment of the present invention, since the patch function is stored in the expansion read-only memory, when the starting address of the first patch function is located in the expansion read-only memory, the current function is the function to be patched.
Optionally, the processor 530 is further configured to determine, according to a storage address of the first patch function in the expander read only memory, a first patch function corresponding to the current function.
Optionally, the processor 530 is further configured to execute the first patch function according to a parameter of the first patch function.
Optionally, the processor 530 is further configured to obtain a parameter of the current function.
Optionally, the processor 530 is further configured to use a parameter of the current function as a parameter of the first patch function.
Specifically, the embodiment of the present invention sets a patch function structure, where the patch function structure may be stored in a lowest address space of the expansion rom, and the patch function structure includes a parameter variable, a return value variable, and a function pointer array, where the parameter variable is used to transfer a parameter of a current function, the return value variable is used to transfer a return value obtained after executing any one patch function, and each function pointer in the function pointer array is used to indicate a start address of each patch function in the expansion rom.
Since the start address of the patch function can be indicated by the function pointer, the first corresponding relationship can be understood as a corresponding relationship between the first identifier and the function pointer, where the function pointer is used for indicating the start address of the patch function corresponding to the current function.
Optionally, the first corresponding relationship may be stored in the patch function structure.
Therefore, the processor 530 may assign the parameter of the current function to a parameter variable in the patch function structure, and obtain the parameter of the current function from the parameter variable in the patch function structure as the parameter of the first patch function when the first patch function is executed.
Optionally, processor 530 is also configured to determine whether the current function requires a return value.
Optionally, the processor 530 is further configured to assign a return value obtained by running the patch function corresponding to the current function to a return value variable in the patch function structure, when the current function needs the return value.
Optionally, the processor 530 is further configured to copy the instance of the patch function structure into a random access memory RAM.
It should be understood that the apparatus 500 for program patching in the embodiment of the present invention may correspond to an apparatus for program patching in the method embodiment, and the above and other operations and/or functions of each component in the apparatus 500 for program patching implement the corresponding flows in each method in fig. 3 and fig. 4, respectively, and are not described herein again for brevity.
Fig. 6 is a schematic block diagram of an apparatus 600 for program patching according to an embodiment of the present invention. As shown in fig. 6, the program patching device 600 comprises a memory 610 and a processor 620, wherein the memory 610 and the processor 620 communicate with each other through internal connection paths to transfer control and/or data signals.
The memory 610 is used for storing program codes;
the processor 620 is configured to call the program code to implement the method in the above embodiments of the present invention.
In the embodiment of the present invention, the Processor 620 may be a Central Processing Unit (CPU), a Network Processor (NP), or a combination of the CPU and the NP. The processor may further include a hardware chip. The hardware chip may be an Application-Specific Integrated Circuit (ASIC), a Programmable Logic Device (PLD), or a combination thereof.
Embodiments of the present invention provide a computer readable medium for storing computer program code, the computer program including instructions for performing the method for patching a program of the embodiments of the present invention in fig. 3 and 4. The readable medium may be a Read-Only Memory (ROM) or a Random Access Memory (RAM), which is not limited in this embodiment of the present invention.
It should be understood that the apparatus 600 for program patching according to the embodiment of the present invention may correspond to an apparatus for program patching in the method embodiment, and the above and other operations and/or functions of each component in the apparatus 600 for program patching implement the corresponding flows of each method in fig. 3 and 4, respectively, and are not described herein again for brevity.
Embodiments of the present invention further provide a system chip, where the system chip includes an input/output interface, at least one processor, at least one memory, and a bus, where the at least one memory is used to store instructions, and the at least one processor is used to call the instructions of the at least one memory to perform the operations of the methods of the foregoing aspects.
An embodiment of the present invention further provides an MCU, which includes the apparatus 600 for program patching described above.
An embodiment of the present invention further provides a terminal device, where the terminal device includes the apparatus 600 for program patching described above.
It should be understood that the term "and/or" herein is only one kind of association relationship describing the association object, and means that there may be three kinds of relationships, for example, a and/or B, and may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" herein generally indicates that the former and latter related objects are in an "or" relationship.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present embodiments.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the invention to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line, DSL), or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that incorporates one or more of the available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid State Disk, SSD), among others.
The above description is only a specific implementation of the embodiments of the present invention, but the scope of the embodiments of the present invention is not limited thereto, and any person skilled in the art can easily conceive of changes or substitutions within the technical scope of the embodiments of the present invention, and all such changes or substitutions should be covered by the scope of the embodiments of the present invention. Therefore, the protection scope of the embodiments of the present invention shall be subject to the protection scope of the claims.

Claims (14)

1. A method of patching a program, wherein the program is stored in a MASK read only memory MASK ROM, the method comprising:
determining whether a current function in the program needs to be patched or not according to a first corresponding relation when the program in the MASK ROM is executed, wherein the first corresponding relation is a corresponding relation between a first identifier and a starting address of a patch function corresponding to the current function in an expansion read only memory, and the first identifier is used for identifying the current function;
executing a first patch function according to the starting address under the condition that the current function needs to be patched, wherein the first patch function is a patch function corresponding to the current function;
wherein, when the current function needs to be patched, executing a first patch function according to the starting address, including:
taking the parameter of the current function as the parameter of a first patch function;
executing the first patch function according to the initial address of the first patch function in the expansion read-only memory and the parameter of the first patch function;
the extended read-only memory is further used for storing a patch function structure, the patch function structure comprises parameter variables, return value variables and a function pointer array, the parameter variables are used for transmitting parameters of the current function, the return value variables are used for transmitting return values obtained after any patch function is executed, each function pointer in the function pointer array is used for indicating a start address of each patch function in the extended read-only memory, and the patch function structure is located in the lowest address space in the extended read-only memory.
2. The method according to claim 1, wherein determining whether a current function in the program needs to be patched according to a first correspondence when executing the program in the MASK ROM comprises:
determining whether the initial address of the patch function corresponding to the current function is located in the address space of the extended read-only memory or not according to the first corresponding relation;
and under the condition that the starting address of the patch function corresponding to the current function is located in the address space of the extended read-only memory, determining that the current function needs to be patched.
3. The method according to claim 1 or 2, wherein the taking the parameter of the current function as the parameter of the first patch function comprises:
assigning the parameters of the current function to the parameter variables in the patch function structure;
and acquiring the parameter of the current function from the parameter variable in the patch function structure as the parameter of the first patch function.
4. The method according to claim 1 or 2, characterized in that the method further comprises:
determining whether the current function requires a return value;
assigning a return value obtained by executing the first patch function to the return value variable in the patch function structure under the condition that the current function needs the return value;
and acquiring the return value from the return value variable in the patch function structure as the return value of the current function.
5. The method according to claim 1 or 2, characterized in that the method further comprises:
copying the instance of the patch function structure into a Random Access Memory (RAM) before executing the program.
6. The method according to claim 1 or 2, wherein the extended read-only memory comprises at least one of a one-time-burning read-only memory (OTP ROM), a multi-time-burning read-only memory (MTP ROM) and an erasable programmable read-only memory (FLASH ROM).
7. An apparatus for program patching, the apparatus comprising:
a MASK read only memory MASK ROM for storing the program;
the expansion read-only memory is used for storing the corresponding patch function in the program;
the processor is configured to determine whether a current function in the program needs to be patched according to a first corresponding relationship when the program in the MASK ROM is executed, where the first corresponding relationship is a corresponding relationship between a first identifier and a starting address of a patch function corresponding to the current function in the extended read only memory, and the first identifier is used to identify the current function;
the processor is further configured to execute a first patch function according to the start address under the condition that the current function needs to be patched, where the first patch function is a patch function corresponding to the current function;
the processor is further configured to use a parameter of the current function as a parameter of a first patch function;
the processor is further configured to execute the first patch function according to a start address of the first patch function in the expansion read only memory and a parameter of the first patch function;
the extended read-only memory is further used for storing a patch function structure, the patch function structure comprises parameter variables, return value variables and a function pointer array, the parameter variables are used for transmitting parameters of the current function, the return value variables are used for transmitting return values obtained after any one patch function is executed, each function pointer in the function pointer array is used for indicating a start address of each patch function in the extended read-only memory, and the patch function structure is located in the lowest address space in the extended read-only memory.
8. The apparatus of claim 7, wherein the processor is further configured to determine whether a start address of a patch function corresponding to the current function is located in an address space of the extended read-only memory according to the first correspondence;
the processor is further configured to determine that the current function needs to be patched when an initial address of a patch function corresponding to the current function is located in the address space of the extended read-only memory.
9. The apparatus according to claim 7 or 8, wherein the processor is further configured to assign parameters of the current function to the parameter variables in the patch function structure;
the processor is further configured to obtain a parameter of the current function from the parameter variable in the patch function structure as a parameter of a first patch function.
10. The apparatus of claim 7 or 8, wherein the processor is further configured to determine whether the current function requires a return value;
the processor is further configured to assign a return value obtained by executing the first patch function to the return value variable in the patch function structure under the condition that the current function needs the return value;
the processor is further configured to obtain the return value from the return value variable in the patch function structure as the return value of the current function.
11. The apparatus of claim 7 or 8, wherein the processor is further configured to copy the instance of the patch function structure into Random Access Memory (RAM).
12. The apparatus of claim 7 or 8, wherein the extended ROM comprises at least one of a one-time-read-only memory OTP ROM, a multi-time-read-only memory MTP ROM, and an erasable programmable ROM FLASH ROM.
13. A micro control unit MCU, characterized in that it comprises means for patching a program according to any of claims 7 to 12.
14. A terminal device, characterized in that it comprises means for patching a program according to any one of claims 7 to 12.
CN201780001062.6A 2017-09-08 2017-09-08 Program patching method and device, micro control unit and terminal equipment Active CN110192178B (en)

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2017/100987 WO2019047142A1 (en) 2017-09-08 2017-09-08 Method for program patching, device, micro control unit, and terminal device

Publications (2)

Publication Number Publication Date
CN110192178A CN110192178A (en) 2019-08-30
CN110192178B true CN110192178B (en) 2023-03-10

Family

ID=65635137

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201780001062.6A Active CN110192178B (en) 2017-09-08 2017-09-08 Program patching method and device, micro control unit and terminal equipment

Country Status (2)

Country Link
CN (1) CN110192178B (en)
WO (1) WO2019047142A1 (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111399892A (en) * 2020-03-18 2020-07-10 深圳Tcl数字技术有限公司 Middleware program repairing method and device and computer readable storage medium
CN112084112B (en) * 2020-09-11 2024-04-26 北京金山云网络技术有限公司 Thermal patch testing method, device and server
CN113094071B (en) * 2021-04-25 2023-06-09 珠海市一微星科技有限公司 Micro control unit, control method thereof and firmware upgrading method thereof

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101561764A (en) * 2009-05-18 2009-10-21 华为技术有限公司 Patching method and patching device under multi-core environment
CN102479265A (en) * 2010-11-25 2012-05-30 上海华虹集成电路有限责任公司 Method for modifying wrong function of firmware of hard mask product
CN106598667A (en) * 2016-12-12 2017-04-26 百度在线网络技术(北京)有限公司 Method and device used for restoring kernel vulnerability

Family Cites Families (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8539469B2 (en) * 2004-05-11 2013-09-17 Microsoft Corporation Efficient patching
US20060174226A1 (en) * 2005-02-03 2006-08-03 Sytex, Inc. Methods, Test Systems And Computer-Readable Medium For Dynamically Modifying Flow Of Executable Code
CN101334734B (en) * 2007-06-27 2012-01-11 北京中电华大电子设计有限责任公司 Method for electric communication card dynamically downloading patch program
CN103309683B (en) * 2012-03-07 2016-08-03 京信通信系统(中国)有限公司 The software patch embedding grammar of hardware device and device
CN103927189B (en) * 2013-01-11 2017-10-31 上海华虹集成电路有限责任公司 The implementation method of intelligent cards internal operating system patch
CN106484369B (en) * 2013-10-24 2019-11-29 华为技术有限公司 A kind of method and device of online patch activation
CN104636161B (en) * 2013-11-15 2018-06-19 华为技术有限公司 The online patch method and system of a kind of multiple nucleus system
CN103677933A (en) * 2013-12-19 2014-03-26 大唐微电子技术有限公司 Patching method and system for smart card
CN110110522B (en) * 2016-05-24 2021-05-07 百度在线网络技术(北京)有限公司 Kernel repairing method and device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101561764A (en) * 2009-05-18 2009-10-21 华为技术有限公司 Patching method and patching device under multi-core environment
CN102479265A (en) * 2010-11-25 2012-05-30 上海华虹集成电路有限责任公司 Method for modifying wrong function of firmware of hard mask product
CN106598667A (en) * 2016-12-12 2017-04-26 百度在线网络技术(北京)有限公司 Method and device used for restoring kernel vulnerability

Also Published As

Publication number Publication date
WO2019047142A1 (en) 2019-03-14
CN110192178A (en) 2019-08-30

Similar Documents

Publication Publication Date Title
CN107516038B (en) Method and device for determining device fingerprint
CN109814524B (en) Vehicle diagnosis method, device and system
US7117348B2 (en) Method and system for detecting the validity of configuration data
CN110192178B (en) Program patching method and device, micro control unit and terminal equipment
CN110830234B (en) User traffic distribution method and device
CN112445729B (en) Operation address determination method, PCIe system, electronic device and storage medium
CN108776587B (en) Data acquisition method and device, computer equipment and storage medium
CN111782339A (en) Container creation method and device, electronic equipment and storage medium
CN116048643B (en) Equipment operation method, system, device, storage medium and electronic equipment
CN110851154B (en) Computer-implemented method, system, and medium for updating read-only memory code
CN113504918A (en) Equipment tree configuration optimization method and device, computer equipment and storage medium
CN114003538A (en) Intelligent network card and identification method thereof
CN106843947B (en) Method and device for processing code defects
CN112052144B (en) Information management method, device, electronic equipment and storage medium
CN109491951B (en) Data configuration method and computing equipment
CN113158177A (en) Dynamic measurement method, device, equipment and storage medium
CN116049000A (en) Environment parameter configuration method, device, equipment, storage medium and product
CN112269665B (en) Memory processing method and device, electronic equipment and storage medium
CN107911816A (en) Startup method, multimode IoT equipment and storage medium for multimode IoT equipment
CN108829574B (en) Test data laying method, test server and computer readable storage medium
CN114258012A (en) ESIM number prefabricating method, ESIM virtual system, ESIM virtual equipment and storage medium
CN114579499A (en) Control method, device, equipment and storage medium of processor communication interface
CN113343319A (en) FLASH type identification method and FLASH type identification system
CN112328288A (en) Method, system, equipment and storage medium for updating server component
CN117687704B (en) Display card initialization method, device, equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant