WO2019047142A1 - Method for program patching, device, micro control unit, and terminal device - Google Patents

Method for program patching, device, micro control unit, and terminal device Download PDF

Info

Publication number
WO2019047142A1
WO2019047142A1 PCT/CN2017/100987 CN2017100987W WO2019047142A1 WO 2019047142 A1 WO2019047142 A1 WO 2019047142A1 CN 2017100987 W CN2017100987 W CN 2017100987W WO 2019047142 A1 WO2019047142 A1 WO 2019047142A1
Authority
WO
WIPO (PCT)
Prior art keywords
function
patch
memory
parameter
current
Prior art date
Application number
PCT/CN2017/100987
Other languages
French (fr)
Chinese (zh)
Inventor
杨柯
周永林
邹景华
Original Assignee
深圳市汇顶科技股份有限公司
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 深圳市汇顶科技股份有限公司 filed Critical 深圳市汇顶科技股份有限公司
Priority to PCT/CN2017/100987 priority Critical patent/WO2019047142A1/en
Priority to CN201780001062.6A priority patent/CN110192178B/en
Publication of WO2019047142A1 publication Critical patent/WO2019047142A1/en

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

Definitions

  • Embodiments of the present invention relate to the field of computers, and, more particularly, to a method, an apparatus, a micro control unit, and a terminal device for patching a program.
  • MASK ROM Mask Read Only Memory
  • OTP ROM One Time Programable Read Only Memory
  • Multi Time Multiple-time read-only memory
  • Programable Read Only Memory MTP ROM
  • FLASH ROM Erasable Programmable Read Only Memory
  • MASK ROM has low manufacturing cost, the program has been solidified in the chip generation stage, and cannot be modified after shipment. Therefore, for the sake of cost and power consumption, in the case that the program has been repeatedly modified and tested to be very stable, it can be considered to write the program into the MASK ROM during the chip production process, and then, once the program is written In the MASK ROM, no modifications can be made afterwards, resulting in insufficient flexibility of the program and low user experience.
  • the embodiment of the invention provides a method, a device, a micro control unit and a terminal device for program patching, which can improve the flexibility of the program and improve the user experience.
  • a method of program patching is provided, the program being stored in a mask read-only memory MASK ROM, the method comprising:
  • the first correspondence is a patch function corresponding to the current function
  • the first identifier is used to identify the current function; and in the case that the current function needs to be patched, according to the start address, the first a patch function, the first patch function being a patch function corresponding to the current function.
  • the patch function is stored in the extended read-only memory, and when the current function in the MASK ROM is patched, the first patch function storage address corresponding to the current function is determined by the first correspondence relationship, and The first patch function is run to improve the spirit of the program. Activity, improve user experience.
  • determining whether the current function in the program needs to be patched according to the first correspondence includes: Determining, according to the first correspondence, whether a starting address of the patch function corresponding to the current function is located in an address space of the extended read-only memory; a starting address of the patch function corresponding to the current function is located in the In the case of expanding the address space of the read only memory, it is determined that the current function needs to be patched.
  • the patch function is stored in the extended read-only memory, it is easy to determine whether the current function needs to be played by determining whether the start address of the patch function corresponding to the current function is located in the extended read-only memory. patch.
  • the performing, according to the starting address, in the case that the current function needs to be patched a first patch function comprising: a parameter of the current function as a parameter of the first patch function; a starting address in the extended read-only memory according to the first patch function and the first patch function
  • the parameter executes the first patch function.
  • the extended read only memory is further configured to store a patch function structure
  • the patch function structure includes a parameter variable, a return value variable, and an array of function pointers, the parameter variable is used to pass parameters of the current function, and the return value variable is used to pass after executing any one of the patch functions.
  • each function pointer in the function pointer array is used to indicate a starting address of each patch function in the extended read-only memory, and the patch function structure is located at the lowest address in the extended read-only memory Within the space.
  • the parameter of the current function is used as the first patch
  • the parameter of the function includes: assigning a parameter of the current function to the parameter variable in the patch function structure; acquiring a parameter of the current function from the parameter variable in the patch function structure as The parameters of the first patch function.
  • the method further includes: determining whether the current function is required Returning a value; if 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; from the patch The return value is obtained from the return value variable in the function structure as a return value of the current function.
  • the method further includes: before executing the program, An instance of the patch function structure is copied into the random access memory RAM.
  • the extended read only memory includes a one-time burning read-only memory At least one of an OTP ROM, a multiple-shot read-only memory MTP ROM, and an erasable programmable read-only memory FLASH ROM.
  • an apparatus for patching a program comprising one or more components for performing the method embodiments of the first aspect.
  • a micro control unit comprising any of the optional program patching devices of the second aspect or the second aspect.
  • a terminal device comprising any of the optional program patching devices of the second aspect or the second aspect.
  • a computer readable medium for storing program code executed by a device for data analysis, the program code comprising each of the first aspect and the first aspect described above The instructions of the method in the implementation.
  • a system chip includes an input/output interface, at least one processor, at least one memory, and a bus, the at least one memory is configured to store code, and the at least one processor is configured to invoke the at least one memory Code to perform the operations of the methods of the various aspects above.
  • FIG. 1 is a system frame diagram of a micro control unit in accordance with an embodiment of the present invention.
  • FIG. 2 is a diagram showing a mapping relationship of a memory address space in an embodiment of the present invention.
  • FIG. 3 is a schematic flowchart of a method for patching a program according to an embodiment of the present invention.
  • FIG. 4 is another schematic flowchart of a method for patching a program according to an embodiment of the present invention.
  • FIG. 5 is a schematic block diagram of an apparatus for patching a program according to an embodiment of the present invention.
  • FIG. 6 is a schematic block diagram of an apparatus for patching a program according to an embodiment of the present invention.
  • the program stored in the Mask Read Only Memory (MASK ROM) in the Microcontroller Unit (MCU) needs to be patched as an example to perform the method of patching the program in the embodiment of the present invention. It should be noted that the embodiments of the present invention are not limited thereto.
  • FIG. 1 shows the MCU system framework.
  • the MASK ROM stores the firmware. After the central processing unit (CPU) is powered on, the program starts running from the start address of the MASK ROM.
  • One Time Programable Read Only Memory (OTP ROM), Multi Time Programable Read Only Memory (MTP ROM), and Erasable Programmable Read Only Memory (FLASH ROM) are Optional read-only memory, in the actual system, one or more optional read-only memories can be selected according to the application scenario, cost and architecture design of the MCU, and a random access memory (RAM) is used for random access memory (RAM). Store variables, program data, etc. during program execution.
  • the patch function is stored in the extended read-only memory (OTP ROM, MTP ROM, FLASH ROM), and after determining that the current function needs to be patched, according to the corresponding patch.
  • the function expands the address in the read-only memory and executes the patch function, thereby patching the functions in the MASK ROM, improving the flexibility of the program and improving the user experience.
  • the processor used in the embodiment of the present invention is a 16-bit processor, and the address space of the memory is 0x0000-0xFFFF.
  • the mapping relationship of a memory address space is as shown in FIG. 2, where 0x0000-0x4000 is a register and random. Accessing the address space of the memory, 0x4000-0x8000 is the storage space of the extended memory, and 0x8000-0xFFFF is the storage space of the MASK ROM.
  • the embodiment of the present invention stores the patch function corresponding to the program in the MASK ROM in the extension. Within the address space 0x4000-0x8000 of the read-only memory, the patch function structure is stored in the lowest address space in the extended read-only memory.
  • FIG. 3 is a schematic flowchart of a method 300 for program patching according to an embodiment of the present invention. As shown in FIG. 3, the method 300 includes some or all of the following steps.
  • the 310 Determine, according to the first correspondence relationship, whether the current function in the program needs to be patched according to the first correspondence relationship when the program in the MASK ROM is executed, where the first correspondence relationship is a complement corresponding to the current identifier and the current function.
  • the first patch function is executed, and the first patch function is a patch function corresponding to the current function.
  • the first patch function is invoked to patch the current function, thereby improving the flexibility of the program and improving the user experience.
  • 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 the program stored in the MASK ROM.
  • the patch function corresponding to the current function is stored in the extended read-only memory.
  • the extended read only memory may include at least one of an OTP ROM, an MTP ROM, and a FLASH ROM.
  • the first identifier is a flag that the user may need to patch the function in the program in the MASK ROM according to a preset rule, and the first identifier may have multiple.
  • the user numbers the commonly used key functions or commonly used important functions in the program stored in the MASK ROM, and any number in the number can be used as the first identifier, and the key function or the important function can be the user according to different evaluation rules. definite.
  • the first correspondence relationship is a correspondence between the first identifier and a start function of the patch function corresponding to the current function in the extended read-only memory.
  • the current function may be any one of the programs stored in the MASK ROM, and the first identifier is used to identify that the current function can be understood as being used to identify the current function when the current function is any function in the MASK ROM.
  • the identifier of the function is the first identifier. For example, there are 5 functions in the program stored in the MASK ROM.
  • the third function has a number. When the program runs to the third function, the third function is used as the current function. Function, the number of the third function can be regarded as the first identifier.
  • 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 needs to be patched needs to be determined according to the first correspondence.
  • the corresponding identifier of the function can be used as the first identifier.
  • the second function, the third function, the fifth function, the seventh function, and the tenth function respectively correspond to numbers 1, 2, and 2. 3, 4, 5, in this case, when the program runs to the second function, the second function can be used as the current function, and the number 1 of the corresponding second function is used as the first identifier to determine the second Whether the function needs to be patched; when the program runs to the fifth function, the fifth function can be used as the current function, and the number 5 of the corresponding fifth function is used as the first identifier to determine whether the fifth function needs to be patched. , and so on, when the program runs to which numbered function, the numbered function can be used as the current function, and the number is used as the first identifier.
  • the first patch function corresponding to the current function may be determined, and after obtaining the parameter of the first patch function, the first patch function is executed.
  • 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 run to patch the current function,
  • the parameters of the current function are the parameters of the first patch function.
  • the embodiment of the present invention provides a patch function structure, and the patch function structure may be stored in a lowest address space of the extended read-only memory, where the patch function structure includes a parameter variable, a return value variable, and an array of function pointers, where The parameter variable is used to pass at least one parameter of the current function in the current function.
  • the return value variable is used to pass the return value obtained after executing any patch function.
  • Each function pointer in the function pointer array is used to indicate each patch function. The starting address in the extended read-only memory.
  • the program described below is a patch function structure.
  • this patch function structure defines 64 patch functions, where parameter[] is a parameter variable, ret_val[] is a return value variable, func_patch_addr[] is an array of function pointers, and the function structure In the body, the func_patch_addr[] function pointer array includes 64 Function pointers, each function pointer indicating the starting address of a patch function.
  • the function pointer can be used to indicate the start address of the patch function
  • the first correspondence relationship can be understood as a correspondence between the first identifier and the first function pointer, and the first function pointer is used to indicate the start of the patch function corresponding to the current function. address.
  • the first correspondence may be stored in a patch function structure.
  • the parameter of the current function can be assigned to the parameter variable parameter[] in the patch function structure.
  • the current function can be extracted from the parameter variable parameter[]. The parameters are used as parameters of the first patch function.
  • 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 executed, and when the first patch function is finished, whether the current function needs a return value determines whether the first function will be run.
  • the return value after the patch function is assigned to the return value variable ret_val[] in the patch function structure, that is, in the case that the current D function needs a return value, after running the first patch function, the first patch function will be executed.
  • the return value is assigned to the return value variable ret_val[] in the patch function structure.
  • the patch function structure has one and only one, that is, there is only one patch function structure regardless of the number of patch functions, and the function pointer array in the patch function structure includes the addresses of all current patch functions, parameters.
  • the variable parameter[] and the return value variable ret_val[] are empty at the initial stage. When a function is patched, the parameter of the function is assigned to the parameter variable parameter[], and after running the patch function corresponding to the function, it will run. The obtained value is assigned to the return value variable ret_val[].
  • the value in the parameter variable parameter[] is the parameter of the function to be patched, and the return value variable ret_val[]
  • the value is the return value obtained by running the patch function corresponding to the function that needs to be patched. Therefore, the parameter variable parameter[] and the return value variable ret_val[] in the patch function structure vary with the current function. However, the function pointer array func_patch_addr[] remains unchanged.
  • FIG. 4 is a schematic flowchart of a method 400 for patching a program according to an embodiment of the present invention. As shown in FIG. 4, the method 400 includes some or all of the following steps.
  • step 405. Determine, according to the first identifier and the first correspondence, whether an address indicated by the first function pointer corresponding to the first identifier is an empty address, and the address indicated by the first function pointer is empty. Then, in step 410, if the address indicated by the first function pointer is not empty, step 415 is performed.
  • the first identifier is used to identify the current function.
  • the first function pointer is used to indicate a starting address of the patch function corresponding to the current function.
  • 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 extended read-only memory, that is, a correspondence between the first identifier and the first function pointer.
  • the first correspondence is stored in an array of pointer functions of the patch function structure.
  • the patch function corresponding to the current function is also stored in the extended read-only memory.
  • step 415 according to whether the address indicated by the first function pointer is located in the storage space of the extended read-only memory, determining whether the current function needs to be patched, and performing the step in the storage space indicated by the first function pointer is not located in the extended read-only memory. 420. When the current function needs to be patched, step 425 is performed.
  • the patch function is stored in the extended read-only memory in the embodiment of the present invention, it is determined whether the address indicated by the first function pointer is located in the extended read-only memory, and whether the current function needs to be patched may be determined.
  • the program jumps to the first patch function corresponding to the current function, and executes the first patch function.
  • the parameter of the first patch function parameter variable parameter[] is the parameter of the current function, that is, the parameter of the current function is assigned to the patch parameter variable parameter[] in the patch function structure in step 425.
  • step 440 After the execution of the first patch function ends, according to whether the current function needs a return value, determine whether to assign the return value to the return value variable ret_val[] in the patch function structure, in the current function.
  • step 445 is executed, and when the current function does not need to return a value, step 450 is performed.
  • the first patch function ends, continues to execute the function after the current function, and continues to determine whether the function after the current function needs to be patched, after the current function.
  • Method 400 is repeated when there is a function that needs to be patched in the function.
  • the first patch function ends and continues to execute the function after the current function.
  • the first patch function is invoked to patch the current function, thereby improving the flexibility of the program and improving the user experience.
  • FIG. 5 is a schematic block diagram of a program patching apparatus 500 according to an embodiment of the present invention. 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 is used to store the program.
  • the extended read only memory 520 is configured to store a corresponding patch function in the program.
  • the processor 530 is configured to determine, according to the first correspondence, whether the current function in the program needs to be patched when the program in the MASK ROM is executed, where the first correspondence is that the first identifier and the patch function corresponding to the current function are in the extended read-only manner.
  • the correspondence between the starting addresses in the memory, the first identifier is used to identify the current function.
  • the processor 530 is further configured to: when the current function needs to be patched, execute the first patch function according to the starting address, where the first patch function is a patch function corresponding to the current function.
  • the current function can be a function or multiple functions.
  • the extended read only memory 520 can be at least one of an OTP ROM, an MTP ROM, and a FLASH ROM.
  • the first identifier is a flag that the user may need to patch the function in the program in the MASK ROM according to a preset rule, and the first identifier may have multiple.
  • the user numbers the commonly used key functions or commonly used important functions in the program stored in the MASK ROM, and any one of the numbers can be used as the first identifier, and the key function or the important function can be The user is determined according to different evaluation rules.
  • the processor 530 is further configured to determine, according to the first correspondence, whether a starting address of the first patch function is located in an address space of the extended read-only memory.
  • 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 an address space of the extended read-only memory.
  • the current function is a function that needs to be patched, where the start address of the first patch function is located in the extended read-only memory.
  • the processor 530 is further configured to determine, according to the storage address in the extended read-only memory of the first patch function, the first patch function corresponding to the current function.
  • the processor 530 is further configured to execute the first patch function according to the parameter of the first patch function.
  • the processor 530 is further configured to obtain parameters of the current function.
  • the processor 530 is further configured to use a parameter of the current function as a parameter of the first patch function.
  • the embodiment of the present invention provides a patch function structure, and the patch function structure may be stored in a lowest address space of the extended read-only memory, where the patch function structure includes a parameter variable, a return value variable, and an array of function pointers, where The parameter variable is used to pass the parameters of the current function.
  • the return value variable is used to pass the return value obtained after executing any patch function.
  • Each function pointer in the function pointer array is used to indicate that each patch function is in the extended read-only memory. starting address.
  • the first correspondence relationship can be understood as a correspondence between the first identifier and the function pointer, and the function pointer is used to indicate the start address of the patch function corresponding to the current function.
  • the first correspondence may be stored in a patch function structure.
  • the processor 530 is further configured to determine whether the current function needs a return value.
  • the processor 530 is further configured to: when the current function needs a return value, 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.
  • the processor 530 is further configured to copy an instance of the patch function structure into the random access memory RAM.
  • program patching apparatus 500 in the embodiment of the present invention may correspond to the program patching apparatus in the method embodiment, and the above-mentioned and other operations and/or functions of the respective components in the patching apparatus 500 are respectively Corresponding processes in the respective methods in FIG. 3 and FIG. 4 are implemented, and are not described herein again for brevity.
  • FIG. 6 is a schematic block diagram of an apparatus 600 for program patching in accordance with an embodiment of the present invention.
  • the program patched device 600 includes a memory 610 and a processor 620 that communicate with one another via internal connection paths to communicate control and/or data signals.
  • the memory 610 is configured to store program code
  • the processor 620 is configured to invoke the program code to implement the methods in the foregoing embodiments of the embodiments of the present invention.
  • the processor 620 may be a central processing unit (CPU), a network processor (NP), or a combination of a CPU and an 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 comprising instructions for performing the method of patching a program of the embodiment of the present invention in FIGS. 3 and 4.
  • the readable medium may be a read-only memory (ROM) or a random access memory (RAM), which is not limited in the embodiment of the present invention.
  • program patching apparatus 600 in accordance with an embodiment of the present invention may correspond to the program patching apparatus in the method embodiment, and that the above and other operations and/or functions of the various components in the program patching apparatus 600 are respectively The corresponding processes of the various methods in FIG. 3 and FIG. 4 are implemented, and are not described herein for brevity.
  • An embodiment of the present invention further provides a system chip, the system chip includes an input and output interface, at least one processor, at least one memory, and a bus, the at least one memory is configured to store an instruction, and the at least one processor is configured to invoke the at least one The instructions of the memory perform the operations of the methods of the various aspects described above.
  • the embodiment of the present invention further provides an MCU, which includes the device 600 for patching the program described above.
  • the embodiment of the invention further provides a terminal device, which comprises the device 600 for patching the program described above.
  • the disclosed systems, devices, and methods may be implemented in other manners.
  • the device embodiments described above are merely illustrative.
  • the division of the unit is only a logical function division.
  • there may be another division manner for example, multiple units or components may be combined or Can be integrated into another system, or some features can be ignored or not executed.
  • the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, and may be in an electrical, mechanical or other form.
  • the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of the embodiment.
  • each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
  • the computer program product includes one or more computer instructions.
  • the computer can be a general purpose computer, a special purpose computer, a computer network, or other programmable device.
  • the computer instructions can be stored in a computer readable storage medium or transferred from one computer readable storage medium to another computer readable storage medium, for example, the computer instructions can be from a website site, computer, server or data center Transmission to another website site, computer, server or data center via wired (eg coaxial cable, fiber optic, digital subscriber line DSL) or wireless (eg infrared, wireless, microwave, etc.).
  • the computer readable storage medium can be any available media that can be accessed by a computer or a data storage device such as a server, data center, or the like that includes one or more available media.
  • the usable medium may be a magnetic medium, such as a floppy disk, a hard disk, a magnetic tape, an optical medium such as a DVD, or a semiconductor medium such as a Solid State Disk (SSD).
  • SSD Solid State Disk

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 for program patching, a device, a micro control unit, and a terminal device. The method comprises: when executing a program in a MASK ROM, determining, on the basis of a first correlation, whether a current function in the program needs to be patched, the first correlation being a correlation between a first identifier and the starting address of a patch function corresponding to the current function in an extended read-only memory, and the first identifier being used for identifying the current function (310); and insofar as the current function needs to be patched, executing the first patch function on the basis of the starting address, the first patch function being a patch function corresponding to the current function (320). The method increases the flexibility of the program and increases user experience.

Description

程序打补丁的方法、装置、微控制单元和终端设备Program patching method, device, micro control unit and terminal device 技术领域Technical field
本发明实施例涉及计算机领域,并且更加具体的,涉及一种程序打补丁的方法、装置、微控制单元和终端设备。Embodiments of the present invention relate to the field of computers, and, more particularly, to a method, an apparatus, a micro control unit, and a terminal device for patching a program.
背景技术Background technique
只读存储器大致可以分为掩模只读存储器(Mask Read Only Memory,MASK ROM)、一次烧录只读存储器(One Time Programable Read Only Memory,OTP ROM)、多次烧录只读存储器(Multi Time Programable Read Only Memory,MTP ROM)以及可擦除可编程只读存储器(FLASH ROM)等,其中MASK ROM由于其制造成本低、程序在芯片生成阶段已经固化,出厂后无法修改,符合程序固定的场合,因此,出于对成本和功耗的考虑,在程序经过反复的修改和测试已经非常稳定的情况下,可以考虑在芯片生产过程中将程序写入MASK ROM中,然后,程序一旦被写入MASK ROM中,之后不能进行任何修改,因此造成程序的灵活性不足,用户体验度不高。Read-only memory can be roughly divided into Mask Read Only Memory (MASK ROM), One Time Programable Read Only Memory (OTP ROM), and multiple-time read-only memory (Multi Time). Programable Read Only Memory (MTP ROM) and Erasable Programmable Read Only Memory (FLASH ROM). Among them, MASK ROM has low manufacturing cost, the program has been solidified in the chip generation stage, and cannot be modified after shipment. Therefore, for the sake of cost and power consumption, in the case that the program has been repeatedly modified and tested to be very stable, it can be considered to write the program into the MASK ROM during the chip production process, and then, once the program is written In the MASK ROM, no modifications can be made afterwards, resulting in insufficient flexibility of the program and low user experience.
发明内容Summary of the invention
本发明实施例提供一种程序打补丁的方法、装置、微控制单元和终端设备,能够提高程序的灵活性,提高用户的体验度。The embodiment of the invention provides a method, a device, a micro control unit and a terminal device for program patching, which can improve the flexibility of the program and improve the user experience.
第一方面,提供一种程序打补丁的方法,所述程序存储于掩模只读存储器MASK ROM中,所述方法包括:In a first aspect, a method of program patching is provided, the program being stored in a mask read-only memory MASK ROM, the method comprising:
在执行所述MASK ROM中的所述程序时根据第一对应关系,确定所述程序中的当前函数是否需要打补丁,所述第一对应关系为第一标识与所述当前函数对应的补丁函数在扩展只读存储器中的起始地址之间的对应关系,所述第一标识用于标识所述当前函数;在所述当前函数需要打补丁的情况下,根据所述起始地址,执行第一补丁函数,所述第一补丁函数为所述当前函数对应的补丁函数。Determining, according to the first correspondence, whether the current function in the program needs to be patched, when the program in the MASK ROM is executed, where the first correspondence is a patch function corresponding to the current function Corresponding relationship between the start addresses in the extended read-only memory, the first identifier is used to identify the current function; and in the case that the current function needs to be patched, according to the start address, the first a patch function, the first patch function being a patch function corresponding to the current function.
在本发明实施例中,将补丁函数存储于扩展只读存储器中,在对MASK ROM中的当前函数进行打补丁时,通过第一对应关系确定当前函数对应的第一补丁函数存储地址,并对第一补丁函数进行运行,可以提高程序的灵 活性,提高用户的体验度。In the embodiment of the present invention, the patch function is stored in the extended read-only memory, and when the current function in the MASK ROM is patched, the first patch function storage address corresponding to the current function is determined by the first correspondence relationship, and The first patch function is run to improve the spirit of the program. Activity, improve user experience.
结合第一方面,在第一方面的第一种实现方式中,在执行所述MASK ROM中的所述程序时根据第一对应关系,确定所述程序中的当前函数是否需要打补丁,包括:根据所述第一对应关系,确定所述当前函数对应的补丁函数的起始地址是否位于所述扩展只读存储器的地址空间内;在所述当前函数对应的补丁函数的起始地址位于所述扩展只读存储器的地址空间的情况下,确定所述当前函数需要打补丁。With reference to the first aspect, in a first implementation manner of the first aspect, when the program in the MASK ROM is executed, determining whether the current function in the program needs to be patched according to the first correspondence, includes: Determining, according to the first correspondence, whether a starting address of the patch function corresponding to the current function is located in an address space of the extended read-only memory; a starting address of the patch function corresponding to the current function is located in the In the case of expanding the address space of the read only memory, it is determined that the current function needs to be patched.
在本发明实施例中,由于补丁函数存储于扩展只读存储器中,因此,通过确定当前函数对应的补丁函数的起始地址是否位于扩展只读存储器中,即可以简便的确定当前函数是否需要打补丁。In the embodiment of the present invention, since the patch function is stored in the extended read-only memory, it is easy to determine whether the current function needs to be played by determining whether the start address of the patch function corresponding to the current function is located in the extended read-only memory. patch.
结合第一方面,或第一方面的第一种实现方式,在第一方面的第二种实现方式中,所述在所述当前函数需要打补丁的情况下,根据所述起始地址,执行第一补丁函数,包括:将所述当前函数的参数作为所述第一补丁函数的参数;根据所述第一补丁函数在所述扩展只读存储器中的起始地址和所述第一补丁函数的参数,执行所述第一补丁函数。With reference to the first aspect, or the first implementation manner of the first aspect, in a second implementation manner of the first aspect, the performing, according to the starting address, in the case that the current function needs to be patched a first patch function, comprising: a parameter of the current function as a parameter of the first patch function; a starting address in the extended read-only memory according to the first patch function and the first patch function The parameter executes 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 extended read only memory is further configured to store a patch function structure The patch function structure includes a parameter variable, a return value variable, and an array of function pointers, the parameter variable is used to pass parameters of the current function, and the return value variable is used to pass after executing any one of the patch functions. Return value, each function pointer in the function pointer array is used to indicate a starting address of each patch function in the extended read-only memory, and the patch function structure is located at the lowest address in the extended read-only memory Within the space.
结合第一方面,或第一方面的第一种至第三种实现方式中的任一种,在第一方面的第四种实现方式中,所述将所述当前函数的参数作为第一补丁函数的参数,包括:将所述当前函数的参数赋值给所述补丁函数结构体中的所述参数变量;从所述补丁函数结构体中的所述参数变量中获取所述当前函数的参数作为第一补丁函数的参数。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 parameter of the current function is used as the first patch The parameter of the function includes: assigning a parameter of the current function to the parameter variable in the patch function structure; acquiring a parameter of the current function from the parameter variable in the patch function structure as The parameters 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 is required Returning a value; if 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; from the patch The return value is obtained from the return value variable in the function structure as a return value of the current function.
结合第一方面,或第一方面的第一种至第五种实现方式中的任一种,在第一方面的第六种实现方式中,所述方法还包括:在执行所述程序之前,将所述补丁函数结构体的实例复制到随机存储器RAM中。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: before executing the program, An instance of the patch function structure is copied into the random access memory RAM.
结合第一方面,或第一方面的第一种至第六种实现方式中的任一种,在第一方面的第七种实现方式中,所述扩展只读存储器包括一次烧录只读存储器OTP ROM、多次烧录只读存储器MTP ROM和可擦除可编程只读存储器FLASH ROM中的至少一种。With reference to the first aspect, or any one of the first to sixth implementation manners of the first aspect, in the seventh implementation manner of the first aspect, the extended read only memory includes a one-time burning read-only memory At least one of an OTP ROM, a multiple-shot read-only memory MTP ROM, and an erasable programmable read-only memory 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, a micro control unit is provided, comprising any of the optional program patching devices of the second aspect or the second aspect.
第四方面,提供一种终端设备,包括第二方面或第二方面的任意可选的程序打补丁的装置。In a fourth aspect, a terminal device is provided, comprising any of the optional program patching devices of the second aspect or the second aspect.
第五方面,提供一种计算机可读介质,所述计算机可读介质用于存储数据分析的装置执行的程序代码,所述程序代码包括用于执行上述第一方面及所述第一方面的各实现方式中的方法的指令。In a fifth aspect, a computer readable medium is provided for storing program code executed by a device for data analysis, the program code comprising each of the first aspect and the first aspect described above The instructions of the method in the implementation.
第六方面,提供一种系统芯片,该系统芯片包括输入输出接口、至少一个处理器、至少一个存储器和总线,该至少一个存储器用于存储代码,该至少一个处理器用于调用该至少一个存储器的代码,以进行上述各个方面的方法的操作。According to a sixth aspect, a system chip is provided, the system chip includes an input/output interface, at least one processor, at least one memory, and a bus, the at least one memory is configured to store code, and the at least one processor is configured to invoke the at least one memory Code to perform the operations of the methods of the various aspects above.
附图说明DRAWINGS
图1是本发明实施例的微控制单元的系统框架图。1 is a system frame diagram of a micro control unit in accordance with an embodiment of the present invention.
图2是本发明实施例的存储器地址空间的映射关系图。2 is a diagram showing a mapping relationship of a memory address space in an embodiment of the present invention.
图3是本发明实施例的程序打补丁的方法的示意性流程图。FIG. 3 is a schematic flowchart of a method for patching a program according to an embodiment of the present invention.
图4是本发明实施例的程序打补丁的方法的另一示意性流程图。FIG. 4 is another schematic flowchart of a method for patching a program according to an embodiment of the present invention.
图5是本发明实施例的程序打补丁的装置的示意性框图。FIG. 5 is a schematic block diagram of an apparatus for patching a program according to an embodiment of the present invention.
图6是本发明实施例的程序打补丁的装置的示意性框图。 FIG. 6 is a schematic block diagram of an apparatus for patching a program according to an embodiment of the present invention.
具体实施方式Detailed ways
下文将结合附图,对本发明实施例的技术方案进行描述。The technical solutions of the embodiments of the present invention will be described below with reference to the accompanying drawings.
本发明实施例以微控制单元(Microcontroller Unit,MCU)中的掩模只读存储器(Mask Read Only Memory,MASK ROM)中存储的程序需要打补丁为例对本发明实施例的程序打补丁的方法进行说明,但本发明实施例并不限定于此。In the embodiment of the present invention, the program stored in the Mask Read Only Memory (MASK ROM) in the Microcontroller Unit (MCU) needs to be patched as an example to perform the method of patching the program in the embodiment of the present invention. It should be noted that the embodiments of the present invention are not limited thereto.
图1所示为MCU系统框架图,其中MASK ROM中存储有固化的程序,中央处理器(Central Processing Unit,CPU)上电后默认从MASK ROM的起始地址开始运行程序。一次烧录只读存储器(One Time Programable Read Only Memory,OTP ROM)、多次烧录只读存储器(Multi Time Programable Read Only Memory,MTP ROM)以及可擦除可编程只读存储器(FLASH ROM)为可选的只读存储器,实际系统中可以根据应用场景、成本和MCU的架构设计等因素综合选择一个或多个上述可选的只读存储器,随机存取存储器(Random Access Memory,RAM)用于存储程序运行过程中的变量和程序数据等。Figure 1 shows the MCU system framework. The MASK ROM stores the firmware. After the central processing unit (CPU) is powered on, the program starts running from the start address of the MASK ROM. One Time Programable Read Only Memory (OTP ROM), Multi Time Programable Read Only Memory (MTP ROM), and Erasable Programmable Read Only Memory (FLASH ROM) are Optional read-only memory, in the actual system, one or more optional read-only memories can be selected according to the application scenario, cost and architecture design of the MCU, and a random access memory (RAM) is used for random access memory (RAM). Store variables, program data, etc. during program execution.
基于上述描述的MCU的系统框架,本发明实施例中将补丁函数存储于扩展只读存储器中(OTP ROM、MTP ROM、FLASH ROM),在确定当前函数为需要打补丁后,根据其对应的补丁函数在扩展只读存储器中的地址,执行补丁函数,从而实现对MASK ROM中的函数进行打补丁,提高了程序的灵活性,提高了用户体验度。Based on the system framework of the MCU described above, in the embodiment of the present invention, the patch function is stored in the extended read-only memory (OTP ROM, MTP ROM, FLASH ROM), and after determining that the current function needs to be patched, according to the corresponding patch. The function expands the address in the read-only memory and executes the patch function, thereby patching the functions in the MASK ROM, improving the flexibility of the program and improving the user experience.
假设本发明实施例中用到的处理器为16位的处理器,存储器的地址空间为0x0000-0xFFFF,一种存储器地址空间的映射关系如图2所示,其中,0x0000-0x4000为寄存器和随机存取存储器的地址空间,0x4000-0x8000为扩展存储器的存储空间,0x8000-0xFFFF为MASK ROM的存储空间,如图2所示,本发明实施例将MASK ROM中的程序对应的补丁函数存储在扩展只读存储器的地址空间0x4000-0x8000内,补丁函数结构体存储于扩展只读存储器中的最低地址空间。It is assumed that the processor used in the embodiment of the present invention is a 16-bit processor, and the address space of the memory is 0x0000-0xFFFF. The mapping relationship of a memory address space is as shown in FIG. 2, where 0x0000-0x4000 is a register and random. Accessing the address space of the memory, 0x4000-0x8000 is the storage space of the extended 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 extension. Within the address space 0x4000-0x8000 of the read-only memory, the patch function structure is stored in the lowest address space in the extended read-only memory.
图3所示为本发明实施例的一种程序打补丁的方法300的示意性流程图,如图3所示,该方法300包括以下步骤中的部分或全部。FIG. 3 is a schematic flowchart of a method 300 for program patching according to an embodiment of the present invention. As shown in FIG. 3, the method 300 includes some or all of the following steps.
310,在执行MASK ROM中的程序时根据第一对应关系,确定程序中的当前函数是否需要打补丁,第一对应关系为第一标识与当前函数对应的补 丁函数在扩展只读存储器中的起始地址之间的对应关系,该第一标识用于标识当前函数。310. Determine, according to the first correspondence relationship, whether the current function in the program needs to be patched according to the first correspondence relationship when the program in the MASK ROM is executed, where the first correspondence relationship is a complement corresponding to the current identifier and the current function. The correspondence between the starting addresses of the functions in the extended read-only memory, the first identifier being used to identify the current function.
320,在当前函数需要打补丁的情况下,根据起始地址,执行第一补丁函数,该第一补丁函数为当前函数对应的补丁函数。320. In the case that the current function needs to be patched, according to the starting address, the first patch function is executed, and the first patch function is a patch function corresponding to the current function.
在本发明实施例中,根据第一补丁函数在扩展只读存储器中的地址,调用第一补丁函数,对当前函数进行打补丁,提高了程序的灵活性,提高了用户体验度。In the embodiment of the present invention, according to the address of the first patch function in the extended read-only memory, the first patch function is invoked to patch the current function, thereby improving the flexibility of the program and improving the user experience.
可选的,本发明实施例中当前函数存储于MASK ROM中,即本发明实施例中的当前函数为MASK ROM中存储的程序中的一个或多个函数。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 the program stored in the MASK ROM.
可选的,当前函数对应的补丁函数存储于扩展只读存储器中。Optionally, the patch function corresponding to the current function is stored in the extended read-only memory.
可选的,该扩展只读存储器可以包括OTP ROM、MTP ROM和FLASH ROM中的至少一种。Optionally, the extended read only memory may include at least one of an OTP ROM, an MTP ROM, and a FLASH ROM.
应理解,第一标识为用户根据预设规则对MASK ROM中的程序中的可能需要打补丁的函数进行的标记,该第一标识可以有多个。例如,用户将MASK ROM中存储的程序中的常用的关键函数或常用的重要函数进行编号,编号中的任意一个编号都可以作为第一标识,关键函数或者重要函数可以是用户根据不同的评估规则确定的。It should be understood that the first identifier is a flag that the user may need to patch the function in the program in the MASK ROM according to a preset rule, and the first identifier may have multiple. For example, the user numbers the commonly used key functions or commonly used important functions in the program stored in the MASK ROM, and any number in the number can be used as the first identifier, and the key function or the important function can be the user according to different evaluation rules. definite.
可选的,第一对应关系为第一标识与当前函数对应的补丁函数在扩展只读存储器中的起始地址之间的对应关系。Optionally, the first correspondence relationship is a correspondence between the first identifier and a start function of the patch function corresponding to the current function in the extended read-only memory.
应理解,该当前函数可以是MASK ROM中存储的程序中的任意一个函数,该第一标识用于标识当前函数可以理解为在当前函数为MASK ROM中的任意一个函数时,用于标识该当前函数的标识符为第一标识,例如,MASK ROM中存储的程序中有5个函数,其中,第三个函数具有一个编号,在程序运行到第三个函数时,将第三个函数作为当前函数,第三个函数的编号可以看作第一标识。It should be understood that the current function may be any one of the programs stored in the MASK ROM, and the first identifier is used to identify that the current function can be understood as being used to identify the current function when the current function is any function in the MASK ROM. The identifier of the function is the first identifier. For example, there are 5 functions in the program stored in the MASK ROM. The third function has a number. When the program runs to the third function, the third function is used as the current function. Function, the number of the third function can 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 needs to be patched needs to be determined according to the first correspondence.
也就是说,MASK ROM的程序中待打补丁的函数可以有多个,在确定某一个函数需要打补丁时,相应的这个函数的标识就可以作为第一标识。That is to say, there may be multiple functions to be patched in the MASK ROM program. When determining that a function needs to be patched, the corresponding identifier of the function can be used as the first identifier.
例如,MASK ROM中存储的程序中有10个函数,其中第二个函数、第三个函数、第五个函数、第七个函数和第十个函数分别对应的编号为①、②、 ③、④、⑤,在这种情况下,当程序运行到第二个函数时,可以将第二个函数作为当前函数,相应的第二个函数的编号①作为第一标识,确定该第二个函数是否需要打补丁;在程序运行到第五个函数时,可以将第五个函数作为当前函数,相应的第五个函数的编号③作为第一标识,确定第五个函数是否需要打补丁,依次类推,当程序运行到哪个带有编号的函数时,既可以将该带有编号的函数作为当前函数,该编号作为第一标识。For example, there are 10 functions in the program stored in the MASK ROM, and the second function, the third function, the fifth function, the seventh function, and the tenth function respectively correspond to numbers 1, 2, and 2. 3, 4, 5, in this case, when the program runs to the second function, the second function can be used as the current function, and the number 1 of the corresponding second function is used as the first identifier to determine the second Whether the function needs to be patched; when the program runs to the fifth function, the fifth function can be used as the current function, and the number 5 of the corresponding fifth function is used as the first identifier to determine whether the fifth function needs to be patched. , and so on, when the program runs to which numbered function, the numbered function can be used as the current function, and the number is used as the first identifier.
可选的,在当前函数需要打补丁时,根据起始地址,可以确定该当前函数对应的第一补丁函数,在获取第一补丁函数的参数之后,执行该第一补丁函数。Optionally, when the current function needs to be patched, according to the starting address, the first patch function corresponding to the current function may be determined, and after obtaining the parameter of the first patch function, the first patch function is executed.
可选的,在确定当前函数需要打补丁之后,可以获取该当前函数的参数,并将该当前函数的参数作为第一补丁函数的参数,在运行第一补丁函数对当前函数进行打补丁时,当前函数的参数即为第一补丁函数的参数。Optionally, after determining 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 run to patch the current function, The parameters of the current function are the parameters of the first patch function.
具体的,本发明实施例设置一个补丁函数结构体,该补丁函数结构体可以存储于扩展只读存储器的最低地址空间,该补丁函数结构体包括参数变量、返回值变量以及函数指针数组,其中,参数变量用于传递至少一个当前函数中任意一个当前函数的参数,返回值变量用于传递执行任意一个补丁函数之后得到的返回值,函数指针数组中的每一个函数指针用于指示每一个补丁函数在扩展只读存储器中的起始地址。Specifically, the embodiment of the present invention provides a patch function structure, and the patch function structure may be stored in a lowest address space of the extended read-only memory, where the patch function structure includes a parameter variable, a return value variable, and an array of function pointers, where The parameter variable is used to pass at least one parameter of the current function in the current function. The return value variable is used to pass the return value obtained after executing any patch function. Each function pointer in the function pointer array is used to indicate each patch function. The starting address in the extended read-only memory.
下文所述的程序即为一种补丁函数结构体。The program described below is a patch function structure.
Figure PCTCN2017100987-appb-000001
Figure PCTCN2017100987-appb-000001
从以上程序中可以看出,这一个补丁函数结构体定义了64个补丁函数,其中,parameter[]为参数变量,ret_val[]为返回值变量,func_patch_addr[]为函数指针数组,在该函数结构体中,func_patch_addr[]函数指针数组包括64 个函数指针,每个函数指针指示一个补丁函数的起始地址。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, func_patch_addr[] is an array of function pointers, and the function structure In the body, the func_patch_addr[] function pointer array includes 64 Function pointers, each function pointer indicating the starting address of a patch function.
由于可以用函数指针指示补丁函数的起始地址,则第一对应关系可以理解为第一标识与第一函数指针的对应关系,该第一函数指针用于指示当前函数对应的补丁函数的起始地址。Since the function pointer can be used to indicate the start address of the patch function, the first correspondence relationship can be understood as a correspondence between the first identifier and the first function pointer, and the first function pointer is used to indicate the start of the patch function corresponding to the current function. address.
可选的,该第一对应关系可以存储于补丁函数结构体中。Optionally, the first correspondence may be stored in a patch function structure.
在定义了补丁函数结构体之后,可以将当前函数的参数赋值给补丁函数结构体中的参数变量parameter[],在运行第一补丁函数的时候,可以从该参数变量parameter[]中取出当前函数的参数作为第一补丁函数的参数。After the patch function structure is defined, the parameter of the current function can be assigned to the parameter variable parameter[] in the patch function structure. When the first patch function is run, the current function can be extracted from the parameter variable parameter[]. The parameters are used as parameters of the first patch function.
在第一补丁函数获取当前函数的参数作为该第一补丁函数的参数之后,运行该第一补丁函数,在运行第一补丁函数结束时,根据当前函数是否需要返回值,确定是否将运行第一补丁函数之后的返回值赋值给补丁函数结构体中的返回值变量ret_val[],即在当前丁函数需要返回值的情况下,在运行完第一补丁函数之后,将运行第一补丁函数之后得到的返回值赋值给补丁函数结构体中的返回值变量ret_val[]。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 executed, and when the first patch function is finished, whether the current function needs a return value determines whether the first function will be run. The return value after the patch function is assigned to the return value variable ret_val[] in the patch function structure, that is, in the case that the current D function needs a return value, after running the first patch function, the first patch function will be executed. The return value is assigned to the return value variable ret_val[] in the patch function structure.
应理解,该补丁函数结构体有且仅有一个,即无论有多少个补丁函数,该补丁函数结构体只有一个,补丁函数结构体中的函数指针数组中包括当前所有的补丁函数的地址,参数变量parameter[]和返回值变量ret_val[]在初始阶段为空,当对一个函数进行打补丁时,将该函数的参数赋值给参数变量parameter[],运行该函数对应的补丁函数之后,将运行得到的数值赋值给返回值变量ret_val[],在下次对另一个函数进行打补丁时,参数变量parameter[]中的数值即为本次需要打补丁的函数的参数,返回值变量ret_val[]中的数值即为运行本次需要打补丁的函数对应的补丁函数得到的返回值,因此,补丁函数结构体中的参数变量parameter[]和返回值变量ret_val[]是随着当前函数的不同而变化的,然而函数指针数组func_patch_addr[]则保持不变。It should be understood that the patch function structure has one and only one, that is, there is only one patch function structure regardless of the number of patch functions, and the function pointer array in the patch function structure includes the addresses of all current patch functions, parameters. The variable parameter[] and the return value variable ret_val[] are empty at the initial stage. When a function is patched, the parameter of the function is assigned to the parameter variable parameter[], and after running the patch function corresponding to the function, it will run. The obtained value is assigned to the return value variable ret_val[]. The next time the other function is patched, the value in the parameter variable parameter[] is the parameter of the function to be patched, and the return value variable ret_val[] The value is the return value obtained by running the patch function corresponding to the function that needs to be patched. Therefore, the parameter variable parameter[] and the return value variable ret_val[] in the patch function structure vary with the current function. However, the function pointer array func_patch_addr[] remains unchanged.
由于补丁函数结构体中的参数变量parameter[]和返回值变量ret_val[]随着程序的运行而变化,所以在初始化阶段,需要将该补丁函数结构体的实例复制一份到RAM中,后续关于补丁函数结构体的所有操作在RAM中运行。Since the parameter variable parameter[] and the return value variable ret_val[] in the patch function structure change with the running of the program, in the initialization phase, an instance of the patch function structure needs to be copied into the RAM, and subsequently All operations of the patch function structure run in RAM.
图4所示为本发明实施例的程序打补丁的方法400的示意性流程图,如图4所示,该方法400包括以下步骤中的部分或全部。FIG. 4 is a schematic flowchart of a method 400 for patching a program according to an embodiment of the present invention. As shown in FIG. 4, the method 400 includes some or all of the following steps.
405,根据第一标识以及第一对应关系,确定与第一标识对应的第一函数指针指示的地址是否为空地址,在第一函数指针指示的地址为空的情况 下,执行步骤410,在第一函数指针指示的地址不为空的情况下,执行步骤415。405. Determine, according to the first identifier and the first correspondence, whether an address indicated by the first function pointer corresponding to the first identifier is an empty address, and the address indicated by the first function pointer is empty. Then, in step 410, if the address indicated by the first function pointer is not empty, step 415 is performed.
可选的,第一标识用于标识当前函数。Optionally, the first identifier is used to identify the current function.
可选的,第一函数指针用于指示当前函数对应的补丁函数的起始地址。Optionally, the first function pointer is used to indicate a starting address of the patch function corresponding to the current function.
可选的,第一对应关系为第一标识与当前函数对应的补丁函数在扩展只读存储器中的起始地址的对应关系,即第一标识与第一函数指针的对应关系。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 extended read-only memory, that is, a correspondence between the first identifier and the first function pointer.
可选的,该第一对应关系存储于补丁函数结构体的指针函数数组中。Optionally, the first correspondence is stored in an array of pointer functions of the patch function structure.
可选的,当前函数对应的补丁函数也存储于扩展只读存储器中。Optionally, the patch function corresponding to the current function is also stored in the extended read-only memory.
410,继续执行MASK ROM中当前函数之后的函数。410, continue to execute the function after the current function in the MASK ROM.
415,根据第一函数指针指示的地址是否位于扩展只读存储器的存储空间内,确定当前函数是否需要打补丁,在第一函数指针指示的地址不位于扩展只读存储器的存储空间内,执行步骤420,在当前函数需要打补丁时,执行步骤425。415, according to whether the address indicated by the first function pointer is located in the storage space of the extended read-only memory, determining whether the current function needs to be patched, and performing the step in the storage space indicated by the first function pointer is not located in the extended read-only memory. 420. When the current function needs to be patched, step 425 is performed.
可选的,由于本发明实施例中将补丁函数存储于扩展只读存储器中,所以确定第一函数指针指示的地址是否位于扩展只读存储器中,可以确定当前函数是否需要打补丁。Optionally, since the patch function is stored in the extended read-only memory in the embodiment of the present invention, it is determined whether the address indicated by the first function pointer is located in the extended read-only memory, and whether the current function needs to be patched may be determined.
420,返回错误信息,程序运行结束。420, an error message is returned, and the program operation ends.
应理解,由于补丁函数存储于扩展只读存储器中,在第一函数指针指示的地址不位于扩展只读存储器的存储空间时,表明该当前函数没有对应的补丁函数,则不能对该当前函数进行打补丁,则程序运行结束。It should be understood that since the patch function is stored in the extended read-only memory, when the address indicated by the first function pointer is not located in the storage space of the extended read-only memory, indicating that the current function does not have a corresponding patch function, the current function cannot be performed on the current function. After patching, the program runs.
425,将该当前函数的参数赋值给补丁函数结构体中的参数变量parameter[]。425. Assign the parameter of the current function to the parameter variable parameter[] in the patch function structure.
430,程序跳转到当前函数对应的第一补丁函数上,执行第一补丁函数。430. The program jumps to the first patch function corresponding to the current function, and executes the first patch function.
435,从补丁函数结构体中的参数变量parameter[]取出参数作为第一补丁函数的参数。435. Extract the parameter as a parameter of the first patch function from the parameter variable parameter[] in the patch function structure.
应理解,此时,第一补丁函数参数变量parameter[]的参数为当前函数的参数,即步骤425中将当前函数的参数赋值给了补丁函数结构体中的补丁参数变量parameter[]中。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, that is, the parameter of the current function is assigned to the patch parameter variable parameter[] in the patch function structure in step 425.
440,第一补丁函数执行结束之后,根据当前函数是否需要返回值,确定是否将返回值赋值给补丁函数结构体中的返回值变量ret_val[],在当前函 数需要返回值时,执行步骤445,在当前函数不需要返回值时,执行步骤450。440. After the execution of the first patch function ends, according to whether the current function needs a return value, determine whether to assign the return value to the return value variable ret_val[] in the patch function structure, in the current function. When the number needs to return a value, step 445 is executed, and when the current function does not need to return a value, step 450 is performed.
445,在当前函数需要返回值时,将返回值赋值给返回值变量ret_val[]。445, when the current function needs to return a value, assign the return value to the return value variable ret_val[].
可选的,在将返回值赋值给返回值变量ret_val[]之后,第一补丁函数运行结束,继续执行当前函数之后的函数,并且继续确定当前函数之后的函数是否需要打补丁,在当前函数之后的函数中有需要打补丁的函数时,重复执行方法400。Optionally, after assigning the return value to the return value variable ret_val[], the first patch function ends, continues to execute the function after the current function, and continues to determine whether the function after the current function needs to be patched, after the current function. Method 400 is repeated when there is a function that needs to be patched in the function.
450,在当前函数不需要返回值时,第一补丁函数运行结束,继续执行当前函数之后的函数。450. When the current function does not need a return value, the first patch function ends and continues to execute the function after the current function.
在本发明实施例中,根据第一补丁函数在扩展只读存储器中的地址,调用第一补丁函数,对当前函数进行打补丁,提高了程序的灵活性,提高了用户体验度。In the embodiment of the present invention, according to the address of the first patch function in the extended read-only memory, the first patch function is invoked to patch the current function, thereby improving the flexibility of the program and improving the user experience.
上文结合图3和图4详细描述了本发明实施例的方法实施例,下文将结合图5和图6,详细描述本发明实施例的装置实施例,应理解,装置实施例与方法实施例相互对应,类似的描述可以参照方法实施例。The embodiment of the method of the present invention is described in detail with reference to FIG. 3 and FIG. 4, and the device embodiment of the embodiment of the present invention will be described in detail below with reference to FIG. 5 and FIG. 6. It should be understood that the device embodiment and the method embodiment are described. Corresponding to each other, a similar description can be referred to the method embodiment.
图5所示为本发明实施例的一种程序打补丁的装置500的示意性框图,如图5所示,该装置500包括以下部件块中的部分或全部。FIG. 5 is a schematic block diagram of a program patching apparatus 500 according to an embodiment of the present invention. As shown in FIG. 5, the apparatus 500 includes some or all of the following component blocks.
掩膜只读存储器(MASK ROM)510,用于存储程序。A mask read only memory (MASK ROM) 510 is used to store the program.
扩展只读存储器520,用于存储程序中对应的补丁函数。The extended read only memory 520 is configured to store a corresponding patch function in the program.
处理器530,用于在执行MASK ROM中的程序时根据第一对应关系,确定程序中的当前函数是否需要打补丁,第一对应关系为第一标识与当前函数对应的补丁函数在扩展只读存储器中的起始地址之间的对应关系,第一标识用于标识当前函数。The processor 530 is configured to determine, according to the first correspondence, whether the current function in the program needs to be patched when the program in the MASK ROM is executed, where the first correspondence is that the first identifier and the patch function corresponding to the current function are in the extended read-only manner. The correspondence between the starting addresses in the memory, the first identifier is used to identify the current function.
处理器530还用于在当前函数需要打补丁的情况下,根据起始地址,执行第一补丁函数,第一补丁函数为当前函数对应的补丁函数。The processor 530 is further configured to: when the current function needs to be patched, execute the first patch function according to the starting address, where the first patch function is a patch function corresponding to the current function.
应理解,当前函数可以为一个函数,也可为多个函数。It should be understood that the current function can be a function or multiple functions.
可选的,该扩展只读存储器520可以为OTP ROM、MTP ROM和FLASH ROM中的至少一种。Optionally, the extended read only memory 520 can be at least one of an OTP ROM, an MTP ROM, and a FLASH ROM.
应理解,第一标识为用户根据预设规则对MASK ROM中的程序中的可能需要打补丁的函数进行的标记,该第一标识可以有多个。例如,用户将MASK ROM中存储的程序中的常用的关键函数或常用的重要函数进行编号,编号中的任意一个都可以作为第一标识,关键函数或者重要函数可以是 用户根据不同的评估规则确定的。It should be understood that the first identifier is a flag that the user may need to patch the function in the program in the MASK ROM according to a preset rule, and the first identifier may have multiple. For example, the user numbers the commonly used key functions or commonly used important functions in the program stored in the MASK ROM, and any one of the numbers can be used as the first identifier, and the key function or the important function can be The user is determined according to different evaluation rules.
可选的,处理器530还用于根据第一对应关系,确定第一补丁函数的起始地址是否位于所述扩展只读存储器的地址空间内。Optionally, the processor 530 is further configured to determine, according to the first correspondence, whether a starting address of the first patch function is located in an address space of the extended read-only memory.
可选的,处理器530还用于在第一补丁函数的起始地址位于扩展只读存储器的地址空间的情况下,确定当前函数需要打补丁。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 an address space of the extended read-only memory.
应理解,在本发明实施例中,由于补丁函数存储于扩展只读存储器中,因此,在第一补丁函数的起始地址位于扩展只读存储器中,当前函数为需要打补丁的函数。It should be understood that, in the embodiment of the present invention, since the patch function is stored in the extended read-only memory, the current function is a function that needs to be patched, where the start address of the first patch function is located in the extended read-only memory.
可选的,处理器530还用于根据第一补丁函数在扩展只读存储器中的存储地址,确定当前函数对应的第一补丁函数。Optionally, the processor 530 is further configured to determine, according to the storage address in the extended read-only memory of the first patch function, the first patch function corresponding to the current function.
可选的,处理器530还用于根据第一补丁函数的参数,执行第一补丁函数。Optionally, the processor 530 is further configured to execute the first patch function according to the parameter of the first patch function.
可选的,处理器530还用于获取当前函数的参数。Optionally, the processor 530 is further configured to obtain parameters of the current function.
可选的,处理器530还用于将当前函数的参数作为第一补丁函数的参数。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 provides a patch function structure, and the patch function structure may be stored in a lowest address space of the extended read-only memory, where the patch function structure includes a parameter variable, a return value variable, and an array of function pointers, where The parameter variable is used to pass the parameters of the current function. The return value variable is used to pass the return value obtained after executing any patch function. Each function pointer in the function pointer array is used to indicate that each patch function is in the extended read-only memory. starting address.
由于可以用函数指针指示补丁函数的起始地址,则第一对应关系可以理解为第一标识与函数指针的对应关系,该函数指针用于指示当前函数对应的补丁函数的起始地址。Since the function pointer can be used to indicate the start address of the patch function, the first correspondence relationship can be understood as a correspondence between the first identifier and the function pointer, and the function pointer is used to indicate the start address of the patch function corresponding to the current function.
可选的,该第一对应关系可以存储于补丁函数结构体中。Optionally, the first correspondence may be stored in a patch function structure.
因此,处理器530可以将当前函数的参数赋值给补丁函数结构体中的参数变量,在运行第一补丁函数时,从补丁函数结构体中的参数变量中获取当前函数的参数作为第一补丁函数的参数。Therefore, the processor 530 can assign the parameter of the current function to the parameter variable in the patch function structure. When the first patch function is run, the parameter of the current function is obtained from the parameter variable in the patch function structure as the first patch function. Parameters.
可选的,处理器530还用于确定当前函数是否需要返回值。Optionally, the processor 530 is further configured to determine whether the current function needs a return value.
可选的,处理器530还用于在当前函数需要返回值的情况下,将运行当前函数对应的补丁函数得到的返回值赋值给补丁函数结构体中的返回值变量中。 Optionally, the processor 530 is further configured to: when the current function needs a return value, 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.
可选的,处理器530还用于将补丁函数结构体的实例复制到随机存储器RAM中。Optionally, the processor 530 is further configured to copy an instance of the patch function structure into the random access memory RAM.
应理解,本发明实施例中的程序打补丁的装置500可对应于方法实施例中的程序打补丁的装置,该程序打补丁的装置500中的各个部件的上述和其他操作和/或功能分别实现图3和图4中的各个方法中的相应流程,为了简洁,在此不再赘述。It should be understood that the program patching apparatus 500 in the embodiment of the present invention may correspond to the program patching apparatus in the method embodiment, and the above-mentioned and other operations and/or functions of the respective components in the patching apparatus 500 are respectively Corresponding processes in the respective methods in FIG. 3 and FIG. 4 are implemented, and are not described herein again for brevity.
图6是根据本发明实施例的程序打补丁的装置600的示意性结构图。如图6所示,该程序打补丁的装置600包括存储器610和处理器620,所述存储器610和处理器620之间通过内部连接通路互相通信,传递控制和/或数据信号。FIG. 6 is a schematic block diagram of an apparatus 600 for program patching in accordance with an embodiment of the present invention. As shown in FIG. 6, the program patched device 600 includes a memory 610 and a processor 620 that communicate with one another via internal connection paths to communicate control and/or data signals.
所述存储器610用于存储程序代码;The memory 610 is configured to store program code;
所述处理器620用于调用所述程序代码以实现本发明实施例上述各实施例中的方法。The processor 620 is configured to invoke the program code to implement the methods in the foregoing embodiments of the embodiments of the present invention.
在本发明实施例中,处理器620可以是中央处理器(Central Processing Unit,CPU),网络处理器(Network Processor,NP)或者CPU和NP的组合。处理器还可以进一步包括硬件芯片。上述硬件芯片可以是专用集成电路(Application-Specific Integrated Circuit,ASIC),可编程逻辑器件(Programmable Logic Device,PLD)或其组合。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 a CPU and an 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.
本发明实施例提供了一种计算机可读介质,用于存储计算机程序代码,该计算机程序包括用于执行上述图3和图4中本发明实施例的程序打补丁的方法的指令。该可读介质可以是只读存储器(Read-Only Memory,ROM)或随机存取存储器(Random Access Memory,RAM),本发明实施例对此不做限制。Embodiments of the present invention provide a computer readable medium for storing computer program code, the computer program comprising instructions for performing the method of patching a program of the embodiment of the present invention in FIGS. 3 and 4. The readable medium may be a read-only memory (ROM) or a random access memory (RAM), which is not limited in the embodiment of the present invention.
应理解,根据本发明实施例的程序打补丁的装置600可对应于方法实施例中的程序打补丁的装置,并且程序打补丁的装置600中的各个部件的上述和其他操作和/或功能分别实现图3和图4中的各个方法的相应流程,为了简洁,在此不再赘述。It should be understood that the program patching apparatus 600 in accordance with an embodiment of the present invention may correspond to the program patching apparatus in the method embodiment, and that the above and other operations and/or functions of the various components in the program patching apparatus 600 are respectively The corresponding processes of the various methods in FIG. 3 and FIG. 4 are implemented, and are not described herein for brevity.
本发明实施例还提供了一种系统芯片,该系统芯片包括输入输出接口、至少一个处理器、至少一个存储器和总线,该至少一个存储器用于存储指令,该至少一个处理器用于调用该至少一个存储器的指令,以进行上述各个方面的方法的操作。 An embodiment of the present invention further provides a system chip, the system chip includes an input and output interface, at least one processor, at least one memory, and a bus, the at least one memory is configured to store an instruction, and the at least one processor is configured to invoke the at least one The instructions of the memory perform the operations of the methods of the various aspects described above.
本发明实施例还提供一种MCU,该MCU包括上文所述的程序打补丁的装置600。The embodiment of the present invention further provides an MCU, which includes the device 600 for patching the program described above.
本发明实施例还提供一种终端设备,该终端设备包括上文所述的程序打补丁的装置600。The embodiment of the invention further provides a terminal device, which comprises the device 600 for patching the program described above.
应理解,本文中术语“和/或”仅仅是一种描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。另外,本文中字符“/”,一般表示前后关联对象是一种“或”的关系。It should be understood that the term "and/or" herein is merely an association describing the associated object, indicating that there may be three relationships, for example, A and/or B, which may indicate that A exists separately, and A and B exist at the same time. There are three cases of B alone. In addition, the character "/" in this article generally indicates that the contextual object is an "or" relationship.
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、或者计算机软件和电子硬件的结合来实现。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本发明实施例的范围。Those of ordinary skill in the art will appreciate that the elements and algorithm steps of the various examples described in connection with the embodiments disclosed herein can be implemented in electronic hardware or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the solution. A person skilled in the art can use different methods to implement the described functions for each particular application, but such implementation should not be considered to be beyond the scope of the embodiments of the invention.
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。A person skilled in the art can clearly understand that for the convenience and brevity of the description, the specific working process of the system, the device and the unit described above can refer to the corresponding process in the foregoing method embodiment, and details are not described herein again.
在本申请所提供的几个实施例中,应该理解到,所揭露的系统、装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided by the present application, it should be understood that the disclosed systems, devices, and methods may be implemented in other manners. For example, the device embodiments described above are merely illustrative. For example, the division of the unit is only a logical function division. In actual implementation, there may be another division manner, for example, multiple units or components may be combined or Can be integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, and may be in an electrical, mechanical or other form.
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of the embodiment.
另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意 组合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。所述计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行所述计算机程序指令时,全部或部分地产生按照本发明实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、服务器或数据中心通过有线(例如同轴电缆、光纤、数字用户线DSL)或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质或者是包含一个或多个可用介质集成的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质,(例如,软盘、硬盘、磁带)、光介质(例如,DVD)、或者半导体介质(例如固态硬盘Solid State Disk,SSD)等。In the above embodiments, all or part of the software, hardware, firmware or any of them may be Combined to achieve. When implemented in software, it 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 the computer program instructions are loaded and executed on a computer, the processes or functions described in accordance with embodiments of the present invention are generated in whole or in part. The computer can be a general purpose computer, a special purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer readable storage medium or transferred from one computer readable storage medium to another computer readable storage medium, for example, the computer instructions can be from a website site, computer, server or data center Transmission to another website site, computer, server or data center via wired (eg coaxial cable, fiber optic, digital subscriber line DSL) or wireless (eg infrared, wireless, microwave, etc.). The computer readable storage medium can be any available media that can be accessed by a computer or a data storage device such as a server, data center, or the like that includes one or more available media. The usable medium may be a magnetic medium, such as a floppy disk, a hard disk, a magnetic tape, an optical medium such as a DVD, or a semiconductor medium such as a Solid State Disk (SSD).
以上所述,仅为本发明实施例的具体实施方式,但本发明实施例的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明实施例揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明实施例的保护范围之内。因此,本发明实施例的保护范围应所述以权利要求的保护范围为准。 The foregoing is only a specific embodiment of the embodiments of the present invention, but the scope of protection of the embodiments of the present invention is not limited thereto, and any person skilled in the art can easily use the technical scope disclosed in the embodiments of the present invention. All changes or substitutions are contemplated to be within the scope of the embodiments of the invention. Therefore, the scope of protection of the embodiments of the present invention should be determined by the scope of the claims.

Claims (18)

  1. 一种程序打补丁的方法,其特征在于,所述程序存储于掩模只读存储器MASK ROM中,所述方法包括:A method for patching a program, wherein the program is stored in a mask read-only memory MASK ROM, the method comprising:
    在执行所述MASK ROM中的所述程序时根据第一对应关系,确定所述程序中的当前函数是否需要打补丁,所述第一对应关系为第一标识与所述当前函数对应的补丁函数在扩展只读存储器中的起始地址之间的对应关系,所述第一标识用于标识所述当前函数;Determining, according to the first correspondence, whether the current function in the program needs to be patched, when the program in the MASK ROM is executed, where the first correspondence is a patch function corresponding to the current function a correspondence between start addresses in the extended read only memory, the first identifier being used to identify the current function;
    在所述当前函数需要打补丁的情况下,根据所述起始地址,执行第一补丁函数,所述第一补丁函数为所述当前函数对应的补丁函数。In the case that the current function needs to be patched, the first patch function is executed according to the start address, and the first patch function is a patch function corresponding to the current function.
  2. 根据权利要求1所述的方法,其特征在于,在执行所述MASK ROM中的所述程序时根据第一对应关系,确定所述程序中的当前函数是否需要打补丁,包括:The method according to claim 1, wherein when the program in the MASK ROM is executed, determining whether the current function in the program needs to be patched according to the first correspondence, includes:
    根据所述第一对应关系,确定所述当前函数对应的补丁函数的起始地址是否位于所述扩展只读存储器的地址空间内;Determining, according to the first correspondence, whether a starting address of the patch function corresponding to the current function is located in an address space of the extended read-only memory;
    在所述当前函数对应的补丁函数的起始地址位于所述扩展只读存储器的地址空间的情况下,确定所述当前函数需要打补丁。In a case where the start address of the patch function corresponding to the current function is located in the address space of the extended read-only memory, it is determined that the current function needs to be patched.
  3. 根据权利要求1或2所述的方法,其特征在于,所述在所述当前函数需要打补丁的情况下,根据所述起始地址,执行第一补丁函数,包括:The method according to claim 1 or 2, wherein in the case that the current function needs to be patched, the first patch function is executed according to the starting address, including:
    将所述当前函数的参数作为第一补丁函数的参数;Taking the parameter of the current function as a parameter of the first patch function;
    根据所述第一补丁函数在所述扩展只读存储器中的起始地址和所述第一补丁函数的参数,执行所述第一补丁函数。The first patch function is executed according to a start address of the first patch function in the extended read-only memory and a parameter of the first patch function.
  4. 根据权利要求3所述的方法,其特征在于,所述扩展只读存储器还用于存储补丁函数结构体,所述补丁函数结构体中包括参数变量、返回值变量以及函数指针数组,所述参数变量用于传递所述当前函数的参数,所述返回值变量用于传递执行任意一个补丁函数之后得到的返回值,所述函数指针数组中的每一个函数指针用于指示每一个补丁函数在扩展只读存储器中的起始地址,所述补丁函数结构体位于所述扩展只读存储器中的最低地址空间内。The method according to claim 3, wherein the extended read only memory is further configured to store a patch function structure, wherein the patch function structure includes a parameter variable, a return value variable, and an array of function pointers, the parameter The variable is used to pass a parameter of the current function, and the return value variable is used to pass a return value obtained after executing any one of the patch functions, and each function pointer in the function pointer array is used to indicate that each patch function is expanded. A starting address in a read only memory, the patch function structure being located in a lowest address space in the extended read only memory.
  5. 根据权利要求4所述的方法,其特征在于,所述将所述当前函数的参数作为第一补丁函数的参数,包括:The method according to claim 4, wherein the parameter of the current function is used as a parameter of the first patch function, including:
    将所述当前函数的参数赋值给所述补丁函数结构体中的所述参数变量; Assigning a parameter of the current function to the parameter variable in the patch function structure;
    从所述补丁函数结构体中的所述参数变量中获取所述当前函数的参数作为第一补丁函数的参数。Obtaining a parameter of the current function as a parameter of the first patch function from the parameter variable in the patch function structure.
  6. 根据权利要求4或5所述的方法,其特征在于,所述方法还包括:The method according to claim 4 or 5, wherein the method further comprises:
    确定所述当前函数是否需要返回值;Determining whether the current function requires a return value;
    在所述当前函数需要返回值的情况下,将执行所述第一补丁函数得到的返回值赋值给所述补丁函数结构体中的所述返回值变量;And in a case that the current function needs a return value, assigning a return value obtained by executing the first patch function to the return value variable in the patch function structure;
    从所述补丁函数结构体中的所述返回值变量中获取所述返回值作为所述当前函数的返回值。The return value is obtained from the return value variable in the patch function structure as a return value of the current function.
  7. 根据权利要求4至6中任一项所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 4 to 6, wherein the method further comprises:
    在执行所述程序之前,将所述补丁函数结构体的实例复制到随机存取存储器RAM中。An instance of the patch function structure is copied into the random access memory RAM prior to execution of the program.
  8. 根据权利要求1至7中任一项所述的方法,其特征在于,所述扩展只读存储器包括一次烧录只读存储器OTP ROM、多次烧录只读存储器MTP ROM和可擦除可编程只读存储器FLASH ROM中的至少一种。The method according to any one of claims 1 to 7, wherein the extended read only memory comprises a once-read ROM read only memory OTP ROM, a multi-burn ROM memory read-only memory MTP ROM, and an erasable programmable At least one of read-only memory FLASH ROMs.
  9. 一种程序打补丁的装置,其特征在于,所述装置包括:A program patching device, characterized in that the device comprises:
    掩模只读存储器MASK ROM,用于存储所述程序;a mask read only memory MASK ROM for storing the program;
    扩展只读存储器,用于存储所述程序中对应的补丁函数;An extended read only memory for storing a corresponding patch function in the program;
    处理器,用于在执行所述MASK ROM中的所述程序时根据第一对应关系,确定所述程序中的当前函数是否需要打补丁,所述第一对应关系为第一标识与所述当前函数对应的补丁函数在所述扩展只读存储器中的起始地址之间的对应关系,所述第一标识用于标识所述当前函数;a processor, configured to determine, according to the first correspondence, whether the current function in the program needs to be patched when the program in the MASK ROM is executed, where the first correspondence is a first identifier and the current Corresponding relationship between the start function of the patch function corresponding to the function in the extended read-only memory, 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, where the current function needs to be patched, where the first patch function is a patch function corresponding to the current function.
  10. 根据权利要求9所述的装置,其特征在于,所述处理器还用于根据所述第一对应关系,确定所述当前函数对应的补丁函数的起始地址是否位于所述扩展只读存储器的地址空间内;The device according to claim 9, wherein the processor is further configured to determine, according to the first correspondence, whether a starting address of a patch function corresponding to the current function is located in the extended read only memory Within the address space;
    所述处理器还用于在所述当前函数对应的补丁函数的起始地址位于所述扩展只读存储器的地址空间的情况下,确定所述当前函数需要打补丁。The processor is further configured to determine that the current function needs to be patched if a start address of the patch function corresponding to the current function is located in an address space of the extended read-only memory.
  11. 根据权利要求9或10所述的装置,其特征在于,所述处理器还用 于将所述当前函数的参数作为第一补丁函数的参数;The apparatus according to claim 9 or 10, wherein said processor is further Taking the parameter of the current function as a parameter of the 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 extended read-only memory and a parameter of the first patch function.
  12. 根据权利要求11所述的装置,其特征在于,所述扩展只读存储器还用于存储补丁函数结构体,所述补丁函数结构体中包括参数变量、返回值变量以及函数指针数组,所述参数变量用于传递所述当前函数的参数,所述返回值变量用于传递执行任意一个补丁函数之后得到的返回值,所述函数指针数组中的每一个函数指针用于指示每一个补丁函数在扩展只读存储器中的起始地址,所述补丁函数结构体位于所述扩展只读存储器中的最低地址空间内。The apparatus according to claim 11, wherein the extended read only memory is further configured to store a patch function structure, wherein the patch function structure includes a parameter variable, a return value variable, and an array of function pointers, wherein the parameter The variable is used to pass a parameter of the current function, and the return value variable is used to pass a return value obtained after executing any one of the patch functions, and each function pointer in the function pointer array is used to indicate that each patch function is expanded. A starting address in a read only memory, the patch function structure being located in a lowest address space in the extended read only memory.
  13. 根据权利要求12所述的装置,其特征在于,所述处理器还用于将所述当前函数的参数赋值给所述补丁函数结构体中的所述参数变量;The apparatus according to claim 12, wherein the processor is further configured to assign a parameter of the current function to the parameter variable in the patch function structure;
    所述处理器还用于从所述补丁函数结构体中的所述参数变量中获取所述当前函数的参数作为第一补丁函数的参数。The processor is further configured to obtain, as the parameter of the first patch function, a parameter of the current function from the parameter variable in the patch function structure.
  14. 根据权利要求12或13所述的装置,其特征在于,所述处理器还用于确定所述当前函数是否需要返回值;The apparatus according to claim 12 or 13, wherein the processor is further configured to determine whether the current function requires a return value;
    所述处理器还用于在所述当前函数需要返回值的情况下,将执行所述第一补丁函数得到的返回值赋值给所述补丁函数结构体中的所述返回值变量;The processor is further configured to: when the current function needs a return value, assign a return value obtained by executing the first patch function to the return value variable in the patch function structure;
    所述处理器还用于从所述补丁函数结构体中的所述返回值变量中获取所述返回值作为所述当前函数的返回值。The processor is further configured to obtain the return value from the return value variable in the patch function structure as a return value of the current function.
  15. 根据权利要求12至14中任一项所述的装置,其特征在于,所述处理器还用于将所述补丁函数结构体的实例复制到随机存取存储器RAM中。The apparatus according to any one of claims 12 to 14, wherein the processor is further configured to copy an instance of the patch function structure into a random access memory RAM.
  16. 根据权利要求9至15中任一项所述的装置,其特征在于,所述扩展只读存储器包括一次烧录只读存储器OTP ROM、多次烧录只读存储器MTP ROM和可擦除可编程只读存储器FLASH ROM中的至少一种。The apparatus according to any one of claims 9 to 15, wherein the extended read only memory comprises a one-time read-only memory OTP ROM, a multi-program ROM, and an erasable programmable At least one of read-only memory FLASH ROMs.
  17. 一种微控制单元MCU,其特征在于,所述MCU包括如权利要求9至16中任一项所述的程序打补丁的装置。A micro-control unit MCU, characterized in that the MCU comprises a program patching device according to any one of claims 9 to 16.
  18. 一种终端设备,其特征在于,所述终端设备包括如权利要求9至16中任一项所述的程序打补丁的装置。 A terminal device, characterized in that the terminal device comprises a program patching device according to any one of claims 9 to 16.
PCT/CN2017/100987 2017-09-08 2017-09-08 Method for program patching, device, micro control unit, and terminal device WO2019047142A1 (en)

Priority Applications (2)

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
CN201780001062.6A CN110192178B (en) 2017-09-08 2017-09-08 Program patching method and device, micro control unit and terminal equipment

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 (1)

Publication Number Publication Date
WO2019047142A1 true WO2019047142A1 (en) 2019-03-14

Family

ID=65635137

Family Applications (1)

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

Country Status (2)

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

Cited By (2)

* 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
CN112084112A (en) * 2020-09-11 2020-12-15 北京金山云网络技术有限公司 Hot patch testing method and device and server

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113094071B (en) * 2021-04-25 2023-06-09 珠海市一微星科技有限公司 Micro control unit, control method thereof and firmware upgrading method thereof

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102479265A (en) * 2010-11-25 2012-05-30 上海华虹集成电路有限责任公司 Method for modifying wrong function of firmware of hard mask product
CN103927189A (en) * 2013-01-11 2014-07-16 上海华虹集成电路有限责任公司 Implementation method of chip operating system patch of smart card
CN104636161A (en) * 2013-11-15 2015-05-20 华为技术有限公司 Multi-core system on-line patch method and system
CN106484369A (en) * 2013-10-24 2017-03-08 华为技术有限公司 A kind of method and device of online patch activation

Family Cites Families (8)

* 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
CN101561764B (en) * 2009-05-18 2012-05-23 华为技术有限公司 Patching method and patching device under multi-core environment
CN103309683B (en) * 2012-03-07 2016-08-03 京信通信系统(中国)有限公司 The software patch embedding grammar of hardware device and device
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
CN109117169B (en) * 2016-12-12 2022-06-07 百度在线网络技术(北京)有限公司 Method and device for repairing kernel vulnerability

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102479265A (en) * 2010-11-25 2012-05-30 上海华虹集成电路有限责任公司 Method for modifying wrong function of firmware of hard mask product
CN103927189A (en) * 2013-01-11 2014-07-16 上海华虹集成电路有限责任公司 Implementation method of chip operating system patch of smart card
CN106484369A (en) * 2013-10-24 2017-03-08 华为技术有限公司 A kind of method and device of online patch activation
CN104636161A (en) * 2013-11-15 2015-05-20 华为技术有限公司 Multi-core system on-line patch method and system

Cited By (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
CN112084112A (en) * 2020-09-11 2020-12-15 北京金山云网络技术有限公司 Hot patch testing method and device and server
CN112084112B (en) * 2020-09-11 2024-04-26 北京金山云网络技术有限公司 Thermal patch testing method, device and server

Also Published As

Publication number Publication date
CN110192178A (en) 2019-08-30
CN110192178B (en) 2023-03-10

Similar Documents

Publication Publication Date Title
CN108898230B (en) Equipment management method and management server
CN107832062B (en) Program updating method and terminal equipment
US9652410B1 (en) Automated modification of configuration settings of an integrated circuit
US10929149B2 (en) Method and system for updating firmware
BR112016025249B1 (en) METHOD AND BUILT-IN DEVICE TO LOAD TRIGGER
WO2020052379A1 (en) Method and apparatus for processing metadata of object in distributed storage system
US8626959B2 (en) Discovery and configuration of new devices added via dynamic reconfiguration
US10996936B2 (en) Techniques for distributing code to components of a computing system
WO2019047142A1 (en) Method for program patching, device, micro control unit, and terminal device
WO2017128701A1 (en) Method and apparatus for storing data
CN112445729B (en) Operation address determination method, PCIe system, electronic device and storage medium
CN109828774B (en) Server system and starting method thereof
CN114580344A (en) Test excitation generation method, verification system and related equipment
CN113504918A (en) Equipment tree configuration optimization method and device, computer equipment and storage medium
JP2016503214A (en) Dynamic firmware update
CN112434278A (en) Bare computer authentication method, apparatus, device and medium
US10642623B1 (en) Preserving firmware settings during firmware updates
US9250828B2 (en) Writable clone data structure
CN107577775A (en) One kind reads data method, device, electronic equipment and readable storage medium storing program for executing
US9727390B1 (en) Invoking a firmware function
TWI601072B (en) A New Way to Create Unified Extensible Firmware Interfaces
CN112732427A (en) Data processing method, system and related device based on Redis cluster
US11200203B1 (en) Accessing files stored in a firmware volume from a pre-boot application
CN109491951B (en) Data configuration method and computing equipment
CN109254858B (en) Data sharing method, device and equipment of active window and storage medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 17924483

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 17924483

Country of ref document: EP

Kind code of ref document: A1