Cross-partition function calling method and device for embedded system

By using function pointer arrays and assembly files indirectly cross-region calls in embedded systems, the problem of cumbersome and security risks of cross-partition function calling process in embedded systems is solved, and more efficient, flexible and secure function calls are achieved, improving the stability and security of the system.

CN120523458APending Publication Date: 2025-08-22ASR MICROELECTRONICS CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510420537.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-05
Publication Date
2025-08-22

AI Technical Summary

Technical Problem

The cross-partition function call method process of existing embedded systems is cumbersome, lacks flexibility and has security risks, especially the exposure of function address lists may lead to system attacks.

Method used

The function pointer array is used to record the function name and actual address, and indirectly cross-region calls are made through assembly files, library files are generated and recorded in the called partition. The calling partition realizes function calls through assembly file links, reducing the coupling degree and hiding function address information.

Benefits of technology

It improves firmware maintainability, scalability and security of embedded systems, reduces code maintenance complexity and attack risks, and enhances system flexibility and stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120523458A_ABST
    Figure CN120523458A_ABST
Patent Text Reader

Abstract

The invention discloses a cross-partition function calling method of an embedded system. Creating a function pointer array to record the function name and the actual address of each called function; and assigning an address of the function pointer array to a fixed address through a link script, and when the function pointer array is compiled and a library file is generated, obtaining a function name of each called function and an index in the function pointer array. Creating a homonymous assembly function according to the function name of each called function, and generating an assembly file according to all the assembly functions. And placing a library file of the assembly file in the called partition, and compiling to generate a burning program of the called partition. And enabling a binary file generated by the assembly file to participate in the link of the calling partition, and generating a burning program of the calling partition. According to the method and the device, the coupling degree between the firmware of each partition of the embedded system is reduced, and the maintainability, the expansibility and the safety of the firmware of the embedded system are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to a method for calling a cross-region function of an embedded system. Background Art

[0002] To improve code (i.e., firmware) manageability and system stability, embedded systems typically use multi-partition storage, storing different functional modules such as the operating system, application programs, and function-specific code libraries in different physical or logical partitions. Partitioned storage helps improve the stability and security of embedded systems while also facilitating firmware maintenance and upgrades. In some cases, partition A (e.g., the system partition) may have embedded non-open-source algorithm library functions, while another partition B (e.g., the application partition) needs to call these algorithm library functions, which involves cross-partition function calls in the embedded system.

[0003] An existing method for cross-partition function calls in embedded systems involves including the function address list of partition A (the called partition) in the compilation of partition B (the calling partition) during the firmware compilation phase. This method is not only cumbersome but also lacks flexibility. If the code in partition A is adjusted, the function address list in partition A will change, and partition B will need to be recompiled based on the new function address list. This method also poses a security risk: partition A's function address list exposes the function interface names and address information. Once an attacker obtains partition A's function address list, they could use this information to inject malicious code or perform other attacks, thereby compromising system security. Summary of the Invention

[0004] The technical problem to be solved by this application is: how to make cross-partition function calls of embedded systems more flexible, efficient and secure.

[0005] To address the above-mentioned technical problems, the present application proposes a method for calling functions across partitions in an embedded system, comprising the following steps: "Callee function" represents a function that may be called across partitions by the embedded system. Step S1: Creating a function pointer array to record the function name and actual address of each "Callee function"; assigning the address of the function pointer array to a fixed address via a linker script. Step S2: When compiling the function pointer array and generating a library file, obtaining the function name and index of each "Callee function" within the function pointer array. Step S3: Creating an assembly function with the same name based on the function name of each "Callee function." The contents of each assembly function are as follows: obtaining the address of the function pointer array, adding the index of the "Callee function" with the same name within the function pointer array to the address of the function pointer array to obtain the actual address of the "Callee function" with the same name, and jumping to the actual address to execute the "Callee function" with the same name. An assembly file is generated based on all assembly functions, which is then compiled into a binary file for linking, and a library file for the assembly file is simultaneously compiled. Step S4: Place the library file of the assembly file in the called partition and compile to generate a burning program for the called partition. Step S5: Link the binary file generated by the assembly file to the calling partition to generate a burning program for the calling partition. Steps S4 and S5 can be performed in either the reverse order or simultaneously.

[0006] Furthermore, in step S1, the actual address of each "called function" is recorded by addressing the function, which means finding the function address through the function name in the code instead of directly writing the address value.

[0007] Furthermore, in step S1, the address of the function pointer array is assigned to a fixed address of the code of the partition where it is located, or assigned to a specified location of other memory and the function pointer array is copied to the specified address of the partition where it is located when the embedded system starts.

[0008] Furthermore, step S2 is achieved by modifying the compilation script and adding a script code to the compilation script; or by calling another compilation script or software program with the same function.

[0009] Furthermore, in step S2, the information in the library file is parsed through a library file analysis tool to obtain the function name of each "called function" and its index in the function pointer array, or the function name of each "called function" and its index in the function pointer array are obtained by directly analyzing the library file.

[0010] Furthermore, in step S4, the library file of the assembly file is converted into an array by a binary to array tool and then added to the code of the called partition, or the library file of the assembly file is directly linked into the code of the called partition and its storage address is specified by a link script.

[0011] Furthermore, in step S5, the inclusion of the binary file generated by the assembly file in the link of the calling partition refers to adding a link to the binary file generated by the assembly file in the compilation script of the calling partition.

[0012] Furthermore, after step S5 is completed, when the calling partition calls a function across partitions, it first finds the assembly function from the assembly file, then finds the actual address of the function with the same name in the function pointer array and executes the function with the same name.

[0013] The present application also proposes a cross-partition function calling device for an embedded system, comprising an array setting unit, an array compilation unit, an assembly file generation unit, a called partition processing unit, and a calling partition processing unit. The array setting unit is used to create a new function pointer array to record the function name and actual address of each "called function", and to assign the address of the function pointer array to a fixed address through a link script. The array compilation unit is used to obtain the function name of each "called function" and its index in the function pointer array when compiling the function pointer array and generating a library file. The assembly file generation unit is used to create a new assembly function with the same name based on the function name of each "called function". The content of each assembly function is: obtaining the address of the function pointer array, adding the index of the "called function" with the same name in the function pointer array to the address of the function pointer array to obtain the actual address of the "called function" with the same name, and jumping to the actual address to execute the "called function" with the same name; generating an assembly file based on all assembly functions, compiling the assembly file into a binary file for linking, and compiling and generating a library file for the assembly file at the same time. The called partition processing unit is used to place the library file of the assembly file in the called partition and compile to generate the burning program of the called partition. The calling partition processing unit is used to link the binary file generated by the assembly file to the calling partition and generate the burning program of the calling partition.

[0014] The technical effect achieved by this application is: reducing the coupling between the firmware of each partition of the embedded system, and improving the maintainability, scalability and security of the firmware of the embedded system. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] Figure 1 This is a flow chart of the cross-partition function calling method for the embedded system proposed in this application.

[0016] Figure 2 This is a structural diagram of the cross-partition function calling device of the embedded system proposed in this application.

[0017] Explanation of the reference numerals in the figure: array setting unit 1, array compiling unit 2, assembly file generating unit 3, called partition processing unit 4, calling partition processing unit 5. DETAILED DESCRIPTION

[0018] See also Figure 1 The method for calling a function across partitions of an embedded system proposed in this application includes the following steps: "Called function" refers to a function that may be called across partitions by the embedded system.

[0019] Step S1: Create a function pointer array to record the function name and actual address of each "called function". Use a link script to assign the address of the function pointer array to a fixed address.

[0020] This step records the actual address of each "called function" by using the function addressing method, that is, finding the function address in the code by the function name, rather than directly writing the address value. This function addressing method can include the function name when the library file is compiled in step S2.

[0021] This step assigns the address of the function pointer array to a fixed address, such as the start or end position of the code in the partition, or to a custom fixed address in the partition, or to a specified location in other memory (such as the start address of PSRAM memory), and copies the data content to the specified address in the partition when the embedded system starts. PSRAM stands for pseudo-static random access memory.

[0022] Step S2: when compiling the function pointer array and generating a library file, obtaining the function name of each "called function" and its index in the function pointer array.

[0023] This step is achieved, for example, by modifying the compilation script and adding a script code to the compilation script; or by calling another compilation script or software program with the same function.

[0024] This step obtains the function name of each "called function" and its index in the function pointer array, for example, by parsing the information in the library file through a library file analysis tool, or by directly analyzing the library file.

[0025] Step S3: Based on the function name of each "called function," a new assembly function with the same name is created. The contents of each assembly function are as follows: obtaining the address of the function pointer array, adding the index of the "called function" with the same name in the function pointer array to the address of the function pointer array to obtain the actual address of the "called function" with the same name, and then jumping to the actual address to execute the "called function" with the same name. An assembly file is generated based on all assembly functions, and the assembly file is compiled into a binary file for linking. At the same time, a library file for the assembly file is compiled. In this way, the assembly file indirectly finds the actual address of each "called function" through the function pointer array and implements the call and execution.

[0026] Step S4: placing the library file of the assembly file in the called partition (such as the system partition), and compiling to generate a burning program for the called partition.

[0027] In this step, the library file of the assembly file is placed in the partition containing the call, for example, the library file of the assembly file is converted into an array through a binary to array tool and then added to the code of the called partition, or the library file of the assembly file is directly linked to the code of the called partition and the storage address is specified through a link script.

[0028] Step S5: Link the binary file generated by the assembly file to the calling partition (e.g., application partition). That is, a link to the binary file generated by the assembly file is added to the compilation script of the calling partition to generate a burning program for the calling partition. In this way, when the calling partition calls a function across partitions, it first finds the assembly function in the assembly file, then finds the actual address of the function with the same name in the function pointer array and executes the function with the same name.

[0029] The order of step S4 and step S5 can be interchanged or performed simultaneously.

[0030] See also Figure 2 The cross-partition function calling device of the embedded system proposed in this application includes an array setting unit 1, an array compiling unit 2, an assembly file generating unit 3, a called partition processing unit 4, and a calling partition processing unit 5. Figure 2 The device shown corresponds to Figure 1 The method shown.

[0031] The array setting unit 1 is used to create a new function pointer array to record the function name and actual address of each "called function", and assign the address of the function pointer array to a fixed address through a link script.

[0032] The array compiling unit 2 is used to obtain the function name of each "called function" and its index in the function pointer array when compiling the function pointer array and generating a library file.

[0033] The assembly file generation unit 3 is used to create an assembly function with the same name based on the function name of each "called function". The content of each assembly function is as follows: obtaining the address of the function pointer array, adding the index of the "called function" with the same name in the function pointer array to the address of the function pointer array to obtain the actual address of the "called function" with the same name, and jumping to the actual address to execute the "called function" with the same name. An assembly file is generated based on all assembly functions, and the assembly file is compiled into a binary file for linking. At the same time, a library file of the assembly file is compiled.

[0034] The called partition processing unit 4 is used to place the library file of the assembly file in the called partition, and compile and generate the burning program of the called partition.

[0035] The calling partition processing unit 5 is used to link the binary file generated by the assembly file to the calling partition, and generate a burning program for the calling partition.

[0036] The technical effects of this application are mainly reflected in the following aspects.

[0037] First, this application uses assembly files as an intermediate layer to indirectly call functions across partitions, replacing a fixed function address list. When the code of the called partition changes, resulting in a change in the function address list, it does not affect the calling partition code, eliminating the need to recompile and re-burn the calling partition code. This makes this application more conducive to independent maintenance and upgrades of embedded system firmware, reducing the complexity of code maintenance.

[0038] Second, when the called partition contains non-open source code, the developer of the calling partition receives an assembly file without function address information, containing only the binary file of the assembly file. Compared to the traditional function address list method, the address of the called function is not exposed, thus reducing the risk of attack and providing higher security.

[0039] Third, for complex multi-partition and nested library function calls, this application uses a unified assembly file as an intermediate layer for management, which reduces the complexity of nested function access and improves flexibility.

[0040] The above are only preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should be included in the scope of protection of the present application.

Claims

1. A cross-partition function calling method for an embedded system, characterized in that: The following steps are included; "called function" refers to a function that may be called across partitions by the embedded system; Step S1: Create a function pointer array to record the function name and actual address of each "called function"; assign the address of the function pointer array to a fixed address through a link script; Step S2: when compiling the function pointer array and generating a library file, obtaining the function name of each "called function" and its index in the function pointer array; Step S3: creating a new assembly function with the same name according to the function name of each "called function", wherein the content of each assembly function is as follows: obtaining the address of the function pointer array, adding the index of the "called function" with the same name in the function pointer array to the address of the function pointer array to obtain the actual address of the "called function" with the same name, and jumping to the actual address to execute the "called function" with the same name; generating an assembly file according to all assembly functions, compiling the assembly file into a binary file for linking, and compiling to generate a library file of the assembly file at the same time; Step S4: placing the library file of the assembly file in the called partition, and compiling to generate a burning program for the called partition; Step S5: Linking the binary file generated by the assembly file to the calling partition to generate a burning program for the calling partition; The order of step S4 and step S5 can be interchanged or performed simultaneously.

2. The cross-partition function calling method of the embedded system according to claim 1, characterized in that: In step S1, the actual address of each "called function" is recorded by addressing the function, which means finding the function address by the function name in the code instead of directly writing the address value.

3. The cross-partition function calling method of the embedded system according to claim 1, characterized in that: In step S1, the address of the function pointer array is assigned to a fixed address of the code of the partition where it is located, or assigned to a specified location of other memory and the function pointer array is copied to the specified address of the partition where it is located when the embedded system starts.

4. The cross-partition function calling method of the embedded system according to claim 1, characterized in that: The step S2 is achieved by modifying the compilation script and adding a script code to the compilation script; or by calling another compilation script or software program with the same function.

5. The cross-partition function calling method of the embedded system according to claim 1, characterized in that: In step S2, the information in the library file is parsed by a library file analysis tool to obtain the function name of each "called function" and its index in the function pointer array, or the function name of each "called function" and its index in the function pointer array are obtained by directly analyzing the library file.

6. The method for calling a cross-partition function of an embedded system according to claim 1, wherein: In step S4, the library file of the assembly file is converted into an array by a binary to array tool and then added to the code of the called partition, or the library file of the assembly file is directly linked to the code of the called partition and its storage address is specified by a link script.

7. The cross-partition function calling method of the embedded system according to claim 1, characterized in that: In step S5, the binary file generated by the assembly file is included in the link of the calling partition, which means adding a link to the binary file generated by the assembly file in the compilation script of the calling partition.

8. The method for calling a function across partitions of an embedded system according to claim 1, wherein: After step S5 is completed, when the calling partition calls a function across partitions, it first finds the assembly function from the assembly file, then finds the actual address of the function with the same name in the function pointer array and executes the function with the same name.

9. A cross-partition function calling device for an embedded system, characterized in that: It includes an array setting unit, an array compilation unit, an assembly file generation unit, a called partition processing unit, and a calling partition processing unit; The array setting unit is used to create a function pointer array to record the function name and actual address of each "called function", and assign the address of the function pointer array to a fixed address through a link script; The array compilation unit is used to obtain the function name of each "called function" and its index in the function pointer array when compiling the function pointer array and generating a library file; The assembly file generation unit is used to create an assembly function with the same name according to the function name of each "called function", and the content of each assembly function is as follows: obtaining the address of the function pointer array, adding the index of the "called function" with the same name in the function pointer array to the address of the function pointer array to obtain the actual address of the "called function" with the same name, and jumping to the actual address to execute the "called function" with the same name; generating an assembly file according to all assembly functions, compiling the assembly file into a binary file for linking, and compiling to generate a library file of the assembly file; The called partition processing unit is used for placing the library file of the assembly file in the called partition, and compiling and generating a burning program of the called partition; The calling partition processing unit is used to link the binary file generated by the assembly file to the calling partition to generate a burning program for the calling partition.