Dynamic loading method and system for embedded device
By storing dynamic library file information in the firmware of embedded devices and mapping it to RAM, generating dynamic symbol tables, the compatibility and applicability of dynamic loading modules in the existing technology are solved, and efficient memory resource utilization and fast Dynamic library calls.
Patent Information
- Application Number
- CN202411238726.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-05
- Publication Date
- 2025-01-10
- Estimated Expiration
- 2044-09-05
AI Technical Summary
The prior art requires file system support when dynamically loading modules in embedded devices, resulting in compatibility and applicability issues. The hardware platform dependency is present in loading dynamic libraries directly from FLASH, making it difficult to widely apply in all devices.
Store relevant information of dynamic library files in the firmware and map them to RAM at runtime to generate dynamic symbol tables, access only symbol tables to call library functions, free memory resources, and use dynamic loading modules of RT-Thread operating system To implement the loading and calling of dynamic libraries.
Improves the speed of dynamic library calls, reduces memory footprint and data leakage risks, is suitable for any storage medium, simplifies memory resource management, and reduces dependence on operating systems and file systems.
Smart Images

Figure CN119292690A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of computer embedded software development and hardware interaction, and in particular relates to a dynamic loading method and system for embedded devices. Background Art
[0002] Dynamic library loading technology originated from the development of operating systems and programming languages, and is designed to address the limitations of static link libraries in large software systems. Static link libraries statically integrate code into applications at compile time, which increases the size of applications. In contrast, dynamic libraries allow programs to load and close library files at runtime, thereby reducing memory usage. For firmware developers, using static link libraries can improve the reliability of firmware, but from the perspective of memory resource utilization, dynamic libraries are more flexible and occupy less memory space than static libraries. Dynamic loading module technology allows programs to load and unload modules without restarting. This technology is implemented using specific APIs, allowing programs to query and call functions and variables in dynamic libraries. Dynamic library and dynamic loading module technologies play an important role in embedded systems, desktop applications, web servers, and mobile devices. They not only improve the flexibility and scalability of software, but also bring higher efficiency and better user experience to software development. With the continuous development of technology, dynamic libraries and dynamic loading modules are expected to continue to play an important role in software engineering.
[0003] In the prior art, many methods for dynamically loading modules in embedded devices use file systems, such as mounting the file system to an SD card or flash, transferring the dynamic library to the file system, and calling the dynamic library directly from the file system when it is needed. Although mounting a file system is a relatively standardized process, there are some challenges in actual operation, such as the need to ensure that the file system is compatible with the target hardware (such as storage media and processors), the need to select a file system type that suits application requirements, driver support, and multiple file system dependencies.
[0004] At the same time, the prior art also proposes a local dynamic loading method that does not use a file system but directly reads and writes the flash. When the embedded system is dynamically loaded locally, it is directly read from the FLASH. However, it depends on the design and requirements of the hardware platform and is difficult to be widely used in all embedded devices. This is because the firmware can run on many different types of storage media, such as eMMc, SD card, solid state drive, etc.
[0005] Therefore, in view of the defects of the prior art, it is necessary to propose a technical solution to solve the technical problems existing in the prior art. Summary of the invention
[0006] In view of this, it is indeed necessary to provide a dynamic loading method and system for embedded devices. By storing the relevant information of the library file in the firmware, the dynamic library file stored in the storage medium is directly mapped to the RAM when the firmware is running, and a dynamic symbol table is generated from all dynamic symbols in the library file in the RAM and stored in a new memory space. When the firmware is running and called, only the dynamic symbol table needs to be accessed instead of the library file. Since the library function is mapped to the RAM, the calling speed of the dynamic library can be greatly improved. At the same time, the memory resources applied in the RAM are released immediately after the library file is called, reducing the risk of data leakage and improving the utilization of memory resources.
[0007] In order to solve the technical problems existing in the prior art, the technical solution of the present invention is as follows:
[0008] A dynamic loading method for an embedded device comprises the following steps:
[0009] Step S1: The host burns the firmware and dynamic library files to the storage medium of the embedded device;
[0010] Step S2: running the firmware in the embedded device memory;
[0011] In step S1, the dynamic library generation module generates corresponding dynamic library files according to the functions of the dynamic library source code, and the firmware source code integrates the dynamic loading module and compiles to generate a firmware file; wherein the firmware file stores information of the corresponding dynamic library file, and the information at least includes the dynamic library name, the starting address of the dynamic library file in the storage medium, and the memory size occupied by the dynamic library file in the storage medium;
[0012] In step S2, when the firmware runs to load a certain library function, the corresponding dynamic library file is found in the storage medium according to the information of the corresponding dynamic library file saved in the firmware file, and the dynamic library file is mapped to the memory and the global dynamic symbol table of the dynamic library is constructed to call the library function.
[0013] As a further improvement, in step S1, a structure array is defined in the firmware file to save relevant information of the corresponding dynamic library file.
[0014] As a further improvement, step S2 further includes:
[0015] Map the called dynamic library file to the memory according to its address and occupied size in the storage medium;
[0016] Parse the dynamic library in memory and count the global function symbols;
[0017] Apply for corresponding memory space in memory according to the statistical global function symbols and build a global dynamic symbol table;
[0018] Call the corresponding library function according to the memory address corresponding to each symbol in the global dynamic symbol table;
[0019] After completing the call to the library file, close the dynamic library and directly release the space applied for in the memory.
[0020] As a further improvement, in step S1, a dynamic loading module of the RT-Thread operating system is used and integrated into the firmware.
[0021] As a further improvement, the dynamic library generation module manages the dependencies between the dynamic libraries so that each dynamic library generates a dynamic library file independently.
[0022] As a further improvement, the firmware and the dynamic library files are stored continuously in the storage medium or stored in different locations in the storage medium.
[0023] As a further improvement, in step S2, a call history table is stored in the memory to record the call information left after the initial call to the dynamic library; when different library functions called in different threads enter a certain thread again, the call history table is used to load the corresponding dynamic library into the memory in advance.
[0024] As a further improvement, when the firmware runs to load a certain library function, the interface of the dynamic loading module of the RT-Thread operating system is used to load the corresponding dynamic library file;
[0025] After building the global dynamic symbol table, a library handle is returned through the dlopen interface to indicate the address of the symbol table.
[0026] When the firmware runs and calls a library function, the dlsym interface is used to obtain the dynamic library function address. The dlsym interface contains two input parameters. The first is the library handle of the calling library file, which is the return value of dlopen. The second input parameter is the dynamic function name to be called. According to the function name to be called in dlsym, the required function address is found in the global dynamic symbol table in the memory.
[0027] After completing the call to the library file, use the dlclose interface to close or unload the dynamic link library opened by the dlopen interface before, and release the space applied for the library file in the memory.
[0028] As a further improvement, in step S1, the storage medium is any one of flash, eMMC or SD card.
[0029] The present invention also discloses a dynamic loading system for embedded devices, including a host and an embedded device, wherein the host is used to generate firmware and dynamic library files and burn them to a storage medium of the embedded device: wherein the host includes:
[0030] The dynamic library generation module is used to compile each dynamic library source code into different dynamic library files according to functional blocks;
[0031] A firmware generation module, used for compiling the firmware source code into firmware, wherein a dynamic loading module is integrated in the firmware, and the dynamic loading module is used for dynamically loading a corresponding dynamic library file;
[0032] A dynamic library burning module is used to burn the generated firmware and dynamic library files to the storage medium of the embedded device;
[0033] The embedded device is used to run firmware in memory and realize dynamic loading of dynamic library files, wherein the loading call of the dynamic library is realized through the dynamic loading module in the firmware; the information of the corresponding dynamic library file is saved in the firmware file, and the information at least includes the dynamic library name, the starting address of the dynamic library file in the storage medium and the memory size occupied by the dynamic library file in the storage medium; when the firmware runs to load a certain library function, the corresponding dynamic library file is found in the storage medium according to the information of the corresponding dynamic library file saved in the firmware file, and the dynamic library file is mapped to the memory and the global dynamic symbol table of the dynamic library is constructed to call the library function.
[0034] Compared with the prior art, the technical solution of the present invention has the following technical effects:
[0035] 1. Make full use of the flexibility of RAM and the advantages of fast CPU reading, map dynamic library files in other storage media to RAM, and integrate all dynamic symbols in the library files in RAM into a new memory space, that is, the dynamic symbol table in RAM. When the firmware is running and calling, only the dynamic symbol table needs to be accessed instead of the library file. In comparison, the dynamic symbol table is smaller and the indexing of specified library functions is faster.
[0036] 2. It can be applied to any storage medium. For example, the actual storage library function in the storage medium such as eMMc or flash, only when the call is required, the memory resources are applied on the RAM, and the library function is mapped to the RAM, which takes advantage of the fast reading speed of RAM on the CPU, and immediately releases the memory resources applied in the RAM after calling the library file, reducing the risk of data leakage and improving the utilization of memory resources.
[0037] 3. Use structure arrays to manage repository file related information, which is simple and efficient. Based on the consideration of memory resource utilization and data leakage,
[0038] 4. Based on the highly scalable software architecture of RT-Thread and its advantages of being lightweight and low in resource usage, the dynamic loading module of RT-Thread was ported, and only a few of its interfaces were used. The overall resource usage is very small, and it is relatively easy to port this module to the firmware, which is convenient for porting and has wide practicality. The overall calling speed is fast, and the embedded device does not need to be equipped with an operating system or file system, and there are fewer restrictions. The utilization of memory resources and data security issues are taken into consideration, and the memory resource utilization rate is high. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 The present invention is a flowchart of a dynamic loading method for embedded devices.
[0040] Figure 2 The figure is a schematic diagram of the structure of the dynamic loading system for embedded devices according to the present invention.
[0041] Figure 3 Generate an execution effect diagram of a module for a prior art dynamic library.
[0042] Figure 4 This is a diagram showing the execution effect of the dynamic library generation module in the present invention.
[0043] Figure 5 It is a schematic diagram of the burning position of the firmware and dynamic library files in the storage medium in the present invention.
[0044] Figure 6 This is a schematic diagram of the entire process of the firmware calling the library function of the present invention.
[0045] Figure 7 The present invention is a method flow chart of a preferred embodiment of the present invention. DETAILED DESCRIPTION
[0046] The technical solution provided by the present invention will be further described below in conjunction with the accompanying drawings.
[0047] Dynamic loading module is an important technology used in software engineering to improve code flexibility, reusability and maintainability. Dynamic library is a binary file containing code and resources that can be shared by multiple applications and is widely used in operating systems. The present invention uses dynamic loading module to realize firmware directly reading and writing dynamic library files of embedded system storage media. The firmware can run in different types of storage media, which greatly reduces the limitation of hardware platform and has wide applicability.
[0048] See also Figure 1 , which is a flowchart of a dynamic loading method for an embedded device according to the present invention, comprising the following steps:
[0049] Step S1: The host burns the firmware and dynamic library files to the storage medium of the embedded device;
[0050] Step S2: running the firmware in the embedded device memory;
[0051] In step S1, the dynamic library generation module generates corresponding dynamic library files according to the functions of the dynamic library source code, and the firmware source code integrates the dynamic loading module and compiles to generate a firmware file; wherein the firmware file stores information of the corresponding dynamic library file, and the information at least includes the dynamic library name, the starting address of the dynamic library file in the storage medium, and the memory size occupied by the dynamic library file in the storage medium;
[0052] In step S2, when the firmware runs to load a certain library function, the corresponding dynamic library file is found in the storage medium according to the information of the corresponding dynamic library file saved in the firmware file, and the dynamic library file is mapped to the memory and the global dynamic symbol table of the dynamic library is constructed to call the library function.
[0053] As a preferred implementation, step S2 further includes:
[0054] Map the called dynamic library file to the memory according to its address and occupied size in the storage medium;
[0055] Parse the dynamic library in memory and count the global function symbols;
[0056] Apply for corresponding memory space in memory according to the statistical global function symbols and build a global dynamic symbol table;
[0057] Call the corresponding library function according to the memory address corresponding to each symbol in the global dynamic symbol table;
[0058] After completing the call to the library file, close the dynamic library and directly release the space applied for in the memory.
[0059] See also Figure 2 , shown is a structural block diagram of a dynamic loading system for embedded devices in the present invention, including a host and an embedded device, the host is used to generate firmware and dynamic library files and burn them to the storage medium of the embedded device, and the storage medium is any one of flash, eMMC or SD card.
[0060] The host includes:
[0061] The dynamic library generation module is used to compile each dynamic library source code into different dynamic library files according to functional blocks;
[0062] A firmware generation module, used for compiling the firmware source code into firmware, wherein a dynamic loading module is integrated in the firmware, and the dynamic loading module is used for dynamically loading a corresponding dynamic library file;
[0063] A dynamic library burning module is used to burn the generated firmware and dynamic library files to the storage medium of the embedded device;
[0064] The embedded device is used to run firmware in memory and realize dynamic loading of dynamic library files, wherein the loading call of the dynamic library is realized through the dynamic loading module in the firmware; the information of the corresponding dynamic library file is saved in the firmware file, and the information at least includes the dynamic library name, the starting address of the dynamic library file in the storage medium and the memory size occupied by the dynamic library file in the storage medium; when the firmware runs to load a certain library function, the corresponding dynamic library file is found in the storage medium according to the information of the corresponding dynamic library file saved in the firmware file, and the dynamic library file is mapped to the memory and the global dynamic symbol table of the dynamic library is constructed to call the library function.
[0065] In a preferred embodiment, the dynamic loading module adopts the dynamic loading module of the RT-Thread operating system and integrates it into the firmware. RT-Thread is an open source real-time operating system (Real-Time Operating System, RTOS), designed for embedded devices, with the characteristics of lightweight, flexible, efficient and modular, and is widely used in the fields of Internet of Things, industrial control, smart home, etc. Since the minimum resource occupancy of RT-Thread is very low and it has a highly scalable software architecture, the present invention adopts the dynamic loading module of the RT-Thread real-time operating system, and performs compatibility modification according to the firmware. The module includes POSIX standard dynamic loading APIs such as dlopen, dlsym, and dlclose, which provide standard and unified interfaces for the loading and use of dynamic libraries, occupying few memory resources and having wide portability.
[0066] Specifically, the host includes a dynamic library generation module running on the host, a dynamic loading module integrated with the firmware and transplanted from the RT-Thread operating system, a firmware and dynamic library file burning module; and an embedded device that runs the firmware and implements dynamic library calls, such as a demo board and an EVB board. The embedded device has a storage medium for storing firmware and dynamic library files, such as eMMc, flash memory, etc. The dynamic library generation module divides the dynamic library source code into blocks according to functions, and compiles them into different dynamic library files using the riscv-linux-gnu-gcc cross-compilation chain, so that when calling a library file, the dynamic library files of specific functions can be called according to the functions without calling all the dynamic library files, or all the dynamic library files are not integrated and compiled to generate a dynamic library file, so as to reduce the loading time when calling the library, improve the efficiency of loading the library, and facilitate the management of the library files. The main firmware source code integrates the dynamic loading module content of the RT-Thread operating system. The integrated part only involves the relevant interfaces and dependencies for dynamic loading without porting the entire RT-Thread operating system. The porting restrictions are relatively few and the memory space occupied is small. The dynamic loading module contains several interfaces such as dlopen, dlsym, dlclose and related dependencies, which are flexible to use. The dynamic library burning module realizes the communication interaction between the embedded device and the host through the serial port tool. The firmware and dynamic library files are burned to the storage medium of the embedded device such as eMMc through the serial port tool. Under the condition that data is not lost, the library file can be stored at any location of the storage medium without being continuous in the memory. After the firmware and dynamic library files are successfully stored in the storage medium of the embedded device, the firmware can be run, and the dynamic library loading call is realized through the dynamic loading module in the firmware.
[0067] In the above technical solution, in step S1, a structure array is defined in the firmware file to save the relevant information of the corresponding dynamic library file, so as to realize the management of the dynamic library file in a simple way. Specifically, a structure array shared_library_struct[] is defined in the firmware to save the relevant information of the library file, as shown in Table 1 below. The relevant elements of the shared_library_struct structure, among which, the dynamic library name and the memory size occupied by the dynamic library file in the storage medium can be known when the dynamic library file is generated, and the starting address of the dynamic library file in the storage medium can also be known when it is burned to the storage medium.
[0068] Table 1 shared_library_struct structure
[0069]
[0070] In a preferred embodiment, the dynamic library generation module manages the dependencies between the dynamic libraries so that each dynamic library generates a dynamic library file independently. Assuming that the dynamic library source code is composed of two functional module projects A and B, where there is a common dependency C in modules A and B, if the dependencies between the dynamic libraries are not managed, multiple copies of the same C part will be stored in the memory, resulting in redundant storage and wasting memory resources. Figure 3 As shown. Therefore, considering that the firmware needs to use multiple dynamic libraries, the dependencies between these libraries must be managed. This problem can be handled when compiling and generating dynamic library files and when actually calling. A dynamic library file C can be compiled separately based on the common dependency files of modules A and B. In this way, there is no need to add dependency source code to the source code of modules A and B. See Figure 4 When the library file is actually stored in the memory, the memory will only contain one copy of the C file. In the actual call, if there is a call to the dynamic library A and B, the dynamic library C must be called first.
[0071] In a preferred embodiment, the firmware and the dynamic library files are stored continuously in the storage medium or stored in different locations in the storage medium. Figure 5 , shown is a schematic diagram of the burning position of the firmware and dynamic library files in the storage medium of the present invention. If memory resources permit and it is ensured that no data loss occurs when the firmware and dynamic library files are stored in the storage medium, the firmware and dynamic library files can be stored in different locations in the storage medium and do not have to be continuous in the memory.
[0072] In a preferred embodiment, when the firmware runs to load a certain library function, the interface of the dynamic loading module of the RT-Thread operating system is used to load the corresponding dynamic library file;
[0073] After building the global dynamic symbol table, a library handle is returned through the dlopen interface to indicate the address of the symbol table.
[0074] When the firmware runs and calls a library function, the dlsym interface is used to obtain the dynamic library function address. The dlsym interface contains two input parameters. The first is the library handle of the calling library file, which is the return value of dlopen. The second input parameter is the dynamic function name to be called. According to the function name to be called in dlsym, the required function address is found in the global dynamic symbol table in the memory.
[0075] After completing the call to the library file, use the dlclose interface to close or unload the dynamic link library opened by the dlopen interface before, and release the space applied for the library file in the memory.
[0076] Usually in the RT-Thread operating system, the struct rt_dlmodule*dlmodule_load(constchar*pgname) function is used to load dynamic library files, where pgname is the dynamic module path. The function of this interface is to load the dynamic module from the file system into the memory. If the load is correct, the pointer to the module will be returned.
[0077] Since the present invention does not adopt a file system, but directly loads the dynamic library file from the storage medium, modifications are made to this interface. During the running of the firmware, if the firmware runs to the dynamic function part in the dynamic library, the dynamic library file is retrieved by the storage location of the dynamic library file in the storage medium instead of retrieving the dynamic library file by the dynamic module path. The above-mentioned structure for storing information related to the dynamic library file will be used here. For calling different dynamic library contents, the dynamic library file can be found in the storage medium according to the elements in the structure, that is, the starting address of the library file in the storage medium.
[0078] Since the CPU accesses RAM much faster than the disk or other storage media, and in order to quickly provide the required function or variable address when the program requests it, the parsing of library files is usually performed in RAM. Therefore, in the present invention, for the call to the dynamic library content in the firmware, after the corresponding dynamic library is indexed in the eMMc or other storage medium, it will be copied to the RAM for parsing. For the dynamic library file in the storage medium, the malloc function is used to apply for the corresponding memory size in the RAM according to the memory space it occupies, and then the library file in other storage media is mapped to the RAM, so that the code is actually stored in the flash or eMMc, and the CPU can also execute it like accessing RAM. See Figure 6 , which is a schematic diagram of the entire process of firmware calling library functions.
[0079] See also Figure 7, shown is a method flow chart of a preferred embodiment of the present invention. For the library file mapped in the RAM, in order to facilitate dynamic calling and reduce calling time, the symbol table of the library file will be traversed, and the symbols with STB_GLOBAL and STB_FUNC attributes will be counted. These symbols are dynamic library functions called in the firmware. According to the number of these symbols counted, the malloc function is used to apply for memory for these symbols in the RAM to build a dynamic symbol table. The dynamic symbol table contains the address information of these symbols, and these symbols can be found through the address information. After successfully building the dynamic symbol table, a library handle handle will be returned to the dlopen interface to indicate the address of the symbol table. When the firmware runs the part that calls the library function, the dlsym interface will be used. The dlsym interface contains two input parameters. The first is the library handle of the calling library file, which is the return value of dlopen. The second input parameter is the dynamic function name to be called. According to the function name to be called in dlsym, the CPU can find the required function address in the dynamic symbol table in RAM. When the firmware runs to this point, it will jump to the RAM to execute the calling function part. After the call is completed, it will return to the address where the firmware is located to continue running the firmware. After completing the call to the library file, use the dlclose interface to close or uninstall the dynamic link library opened by the previous dlopen interface, and release the space requested by malloc for the library file in RAM, which can avoid potential memory leaks and improve the utilization of memory resources.
[0080] In a preferred embodiment, in step S2, a call history table is stored in the memory to record the call information left after the initial call to the dynamic library; different library functions called in different threads, when entering a thread again, use the call history table to load the corresponding dynamic library into the memory in advance.
[0081] Specifically, for different library functions called in different threads, in order to improve the calling efficiency, a call history table is stored in RAM. For example, thread A calls dynamic library 1. It will be relatively slow to perform the above operation from flash during the first call. After the first call, the information of the calling library is left. When entering this thread next time, the library file can be loaded into RAM before waiting for the calling part, so that the loading time can be saved and released at the end.
[0082] The above embodiments are only used to help understand the method and core idea of the present invention. It should be noted that, for those skilled in the art, several improvements and modifications can be made to the present invention without departing from the principles of the present invention, and these improvements and modifications also fall within the scope of protection of the claims of the present invention.
[0083] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A dynamic loading method for an embedded device, characterized in that: The steps include: Step S1: The host burns the firmware and dynamic library files to the storage medium of the embedded device; Step S2: running the firmware in the embedded device memory; In step S1, the dynamic library generation module generates corresponding dynamic library files according to the functions of the dynamic library source code, and the firmware source code integrates the dynamic loading module and compiles to generate a firmware file; wherein the firmware file stores information of the corresponding dynamic library file, and the information at least includes the dynamic library name, the starting address of the dynamic library file in the storage medium, and the memory size occupied by the dynamic library file in the storage medium; In step S2, when the firmware runs to load a certain library function, the corresponding dynamic library file is found in the storage medium according to the information of the corresponding dynamic library file saved in the firmware file, and the dynamic library file is mapped to the memory and the global dynamic symbol table of the dynamic library is constructed to call the library function.
2. The dynamic loading method for embedded devices according to claim 1, characterized in that: In step S1, a structure array is defined in the firmware file to store relevant information of the corresponding dynamic library file.
3. The dynamic loading method for embedded devices according to claim 2, characterized in that: Step S2 also includes: Map the called dynamic library file to the memory according to its address and occupied size in the storage medium; Parse the dynamic library in memory and count the global function symbols; Apply for corresponding memory space in memory according to the statistical global function symbols and build a global dynamic symbol table; Call the corresponding library function according to the memory address corresponding to each symbol in the global dynamic symbol table; After completing the call to the library file, close the dynamic library and directly release the space applied for in the memory.
4. The dynamic loading method for embedded devices according to claim 3, characterized in that: In step S1, a dynamic loading module of the RT-Thread operating system is used and integrated into the firmware.
5. The dynamic loading method for embedded devices according to claim 4, characterized in that: The dynamic library generation module manages the dependencies between the dynamic libraries, so that each dynamic library generates a dynamic library file independently.
6. The dynamic loading method for embedded devices according to claim 4, characterized in that: The firmware and dynamic library files are stored consecutively in the storage medium or stored in different locations in the storage medium.
7. The dynamic loading method for embedded devices according to claim 4, characterized in that: In step S2, a call history table is stored in the memory to record the call information left after the initial call to the dynamic library; different library functions called in different threads, when entering a thread again, the call history table is used to load the corresponding dynamic library into the memory in advance.
8. The dynamic loading method for embedded devices according to claim 4, characterized in that: When the firmware runs to load a certain library function, the corresponding dynamic library file is loaded using the interface of the dynamic loading module of the RT-Thread operating system; After building the global dynamic symbol table, a library handle is returned through the dlopen interface to indicate the address of the symbol table. When the firmware runs and calls a library function, the dlsym interface is used to obtain the dynamic library function address. The dlsym interface contains two input parameters. The first is the library handle of the calling library file, which is the return value of dlopen. The second input parameter is the dynamic function name to be called. According to the function name to be called in dlsym, the required function address is found in the global dynamic symbol table in the memory. After completing the call to the library file, use the dlclose interface to close or unload the dynamic link library opened by the dlopen interface before, and release the space applied for the library file in the memory.
9. The dynamic loading method for embedded devices according to claim 4, characterized in that: In step S1, the storage medium is any one of flash, eMMC or SD card.
10. A dynamic loading system for embedded devices, characterized in that: The host includes a host and an embedded device, wherein the host is used to generate firmware and dynamic library files and burn them to the storage medium of the embedded device: wherein the host includes: The dynamic library generation module is used to compile each dynamic library source code into different dynamic library files according to functional blocks; A firmware generation module, used for compiling the firmware source code into firmware, wherein a dynamic loading module is integrated in the firmware, and the dynamic loading module is used for dynamically loading a corresponding dynamic library file; A dynamic library burning module is used to burn the generated firmware and dynamic library files to the storage medium of the embedded device; The embedded device is used to run firmware in memory and realize dynamic loading of dynamic library files, wherein the loading call of the dynamic library is realized through the dynamic loading module in the firmware; the information of the corresponding dynamic library file is saved in the firmware file, and the information at least includes the dynamic library name, the starting address of the dynamic library file in the storage medium and the memory size occupied by the dynamic library file in the storage medium; when the firmware runs to load a certain library function, the corresponding dynamic library file is found in the storage medium according to the information of the corresponding dynamic library file saved in the firmware file, and the dynamic library file is mapped to the memory and the global dynamic symbol table of the dynamic library is constructed to call the library function.
Citation Information
Patent Citations
Local dynamic loading system and method based on direct reading and writing FLASH
CN108829465A
DSP dynamic loading method for reserving running memory space
CN111913762A
Domestic operating system starting optimization method based on dynamic loading mechanism
CN117311821A
Dynamic loading method, and target file producing method and apparatus
WO2019095968A1
Cited By
RISC-V chip dynamic library mechanism implementation system, chip and related method
CN119938175A
Implementation method of one-to-many dynamic upper computer software
CN119960851A