Method, device and storage medium for loading initialization function of program module
By determining the dependencies and priorities of the initialization function and using a preset compiler to build an initialization function list, the problem that the computer system cannot automatically load the initialization function is solved, and automated initialization function loading is realized, which improves development efficiency.
Patent Information
- Application Number
- CN202211383154.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-07
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2042-11-07
AI Technical Summary
In the prior art, computer systems cannot automatically load the initialization functions of each program module, resulting in developers needing to manually add or delete the initialization functions in the main function entry, which is very labor-intensive and inefficient.
By determining the dependencies and priorities between initialization functions, build an initialization function list using a preset compiler and automatically load the initialization function according to the list order.
The automatic loading of initialization functions is realized, reducing the developer's manual operations in the main function, and improving development efficiency and module independence.
Smart Images

Figure CN115729651B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of single-chip microcomputer embedded software development, and in particular to a method, device and storage medium for loading an initialization function of a program module. Background Art
[0002] With the development of IT technology, product application requirements are constantly increasing. The tasks that electronic products need to handle are becoming more and more complex. A project may have multiple tasks with different priorities, and some functions and tasks may be deleted based on the different positioning of the product.
[0003] In the development of microcontroller programs, it is necessary to manually add hardware resources that need to be initialized, third-party component initialization functions, and create system task functions one by one through the main function entry. Every time a developer adds a new function, because it is impossible to determine the dependence of other subsequent applications on this module, it is generally a more common method to initialize all modules in the main function set. Developers need to distinguish the order of software and hardware initialization to prevent unpredictable results of the program.
[0004] Existing technologies require developers to add initialization functions for each functional module to the main function entry point in a specific order. Each time a module is added or removed, the initialization function for that module must be added or removed at the main function entry point, making it difficult for the program to achieve true module independence. Specifically, developers manually adding, adding, or removing initialization functions for each functional module at the main function entry point is labor-intensive and leads to low efficiency.
[0005] There is currently no effective solution to the problem that developers are required to manually add, increase or delete initialization functions of each program module in the main function entry, while the computer system is unable to automatically load the initialization functions of each program module. Summary of the Invention
[0006] The present invention provides a method, device and storage medium for loading an initialization function of a program module to solve the problem in the related art that a computer system cannot automatically load the initialization function of each program module.
[0007] In a first aspect, the present invention provides a method for loading an initialization function of a program module, the method comprising:
[0008] Determine the dependency relationship between a plurality of initialization functions; wherein the dependency relationship includes the startup order relationship between any two of the initialization functions;
[0009] Setting the priorities of the initialization functions according to the dependency relationship;
[0010] The preset compiler constructs an initialization function list according to the priorities of the plurality of initialization functions;
[0011] Several initialization functions are loaded in sequence according to the initialization function list.
[0012] In some of these embodiments, the priority includes a first priority, and the dependency includes a first dependency;
[0013] Determining the dependency relationship between the initialization functions includes:
[0014] Determining the types of the initialization functions;
[0015] Determining a first dependency relationship between the plurality of initialization functions according to the type; wherein the first dependency relationship includes a startup sequence relationship between any two initialization functions of different types;
[0016] The step of setting the priorities of the initialization functions according to the dependency relationship includes:
[0017] A first priority of the initialization function is set according to the first dependency relationship.
[0018] In some of these embodiments, the priority further includes a second priority, and the dependency further includes a second dependency;
[0019] Determining the dependency relationship between the multiple initialization functions also includes:
[0020] Determining the levels of a plurality of said initialization functions;
[0021] Determining a second dependency relationship between a plurality of the initialization functions according to the level; wherein the second dependency relationship includes a startup sequence relationship between any two initialization functions of different levels;
[0022] The step of setting the priorities of the initialization functions according to the dependency relationship further includes:
[0023] A second priority of the initialization function is set according to the second dependency relationship.
[0024] In some embodiments, the initialization function list includes a plurality of first data segments that are sequentially sorted, and the same first data segment is used to store the initialization functions with the same first priority.
[0025] In some embodiments, the initialization function list includes a plurality of second data segments that are sequentially sorted, and the same second data segment is used to store the initialization functions with the same first priority and the same second priority.
[0026] In some embodiments, the preset compiler constructs the initialization function list according to the priorities among the initialization functions, including:
[0027] Determining a first priority of the initialization function to be stored according to the type of the initialization function to be stored;
[0028] According to the first priority of the to-be-stored initialization function, the to-be-stored initialization function is stored in the corresponding first data segment.
[0029] In some embodiments, the preset compiler constructs the initialization function list according to the priorities among the initialization functions, including:
[0030] Determining a first priority of the initialization function to be stored according to the type of the initialization function to be stored;
[0031] Determining a second priority of the initialization function to be stored according to the level of the initialization function to be stored;
[0032] According to the first priority and the second priority of the initialization function to be stored, the initialization function to be stored is stored in the corresponding second data segment.
[0033] In some embodiments, the default compiler is an ARM compiler or a GCC compiler.
[0034] In a second aspect, the present invention provides an initialization function loading device for a program module, the device comprising:
[0035] A first relationship determination module is configured to determine a dependency relationship between a plurality of initialization functions; wherein the dependency relationship includes a startup order relationship between any two of the initialization functions;
[0036] A second relationship determination module, configured to set priorities of the initialization functions according to the dependency relationship;
[0037] A function list construction module, configured to use a preset compiler to construct an initialization function list according to the priorities of the plurality of initialization functions;
[0038] The function automatic loading module is used to load several initialization functions in sequence according to the initialization function list.
[0039] In a third aspect, the present invention provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method for loading the initialization function of the program module described in the first aspect above is implemented.
[0040] In a fourth aspect, the present invention provides a storage medium on which a computer program is stored, which, when executed by a processor, implements the initialization function loading method of the program module described in the first aspect above.
[0041] Compared to related technologies, the method, device, and storage medium for loading initialization functions for program modules provided in this embodiment first determine the priority of each initialization function based on their dependencies. A preset compiler then stores the initialization functions in corresponding locations according to their priority, thereby constructing an initialization function list. Finally, the computer system automatically loads the initialization functions sequentially according to the order in which the functions are stored in the initialization list, resolving the prior art issue of computer systems being unable to automatically load initialization functions for each program module.
[0042] The details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0044] Figure 1 It is a hardware structure block diagram of a terminal that executes the initialization function loading method of the program module in the present invention;
[0045] Figure 2 is a flowchart of a method for loading an initialization function of a program module in an embodiment of the present invention;
[0046] Figure 3 is a flow chart of a method for loading an initialization function of a program module in a preferred embodiment of the present invention;
[0047] Figure 4 It is a structural block diagram of an initialization function loading device for a program module in an embodiment of the present invention. DETAILED DESCRIPTION
[0048] In order to more clearly understand the purpose, technical solutions and advantages of the present application, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments.
[0049] Unless otherwise defined, the technical terms or scientific terms involved in this application should have the general meaning understood by people with ordinary skills in the technical field to which this application belongs. The words "one", "an", "a", "the", "these" and the like in this application do not indicate quantitative restrictions, and they can be singular or plural. The terms "include", "comprise", "have" and any variants thereof involved in this application are intended to cover non-exclusive inclusions; for example, a process, method and system, product or device comprising a series of steps or modules (units) is not limited to the listed steps or modules (units), but may include unlisted steps or modules (units), or may include other steps or modules (units) inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "plurality" involved in this application refers to two or more. "And / or" describes the relationship between related objects, indicating that three possible relationships exist. For example, "A and / or B" can represent: A exists alone, A and B exist simultaneously, and B exists alone. Generally, the character " / " indicates that the related objects are in an "or" relationship. The terms "first," "second," "third," etc. used in this application are only used to distinguish similar objects and do not represent a specific ordering of the objects.
[0050] The method embodiment provided in this embodiment can be executed in a terminal, a computer or a similar computing device. For example, running on a terminal, Figure 1 1 is a hardware structure diagram of a terminal that executes the initialization function loading method of the program module in the present invention. Figure 1 As shown, the terminal may include one or more ( Figure 1 Only one is shown) a processor 102 and a memory 104 for storing data, wherein the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA. The above terminal may also include a transmission device 106 and an input and output device 108 for communication functions. It will be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above terminal. Figure 1 More or fewer components than shown, or with Figure 1 Different configurations shown.
[0051] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the initialization function loading method of the program module in the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, implementing the above-mentioned method. The memory 104 may include a high-speed random access memory and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely located relative to the processor 102, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0052] The transmission device 106 is used to receive or send data via a network. The network may include a wireless network provided by the terminal's telecommunications provider. In one embodiment, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to enable communication with the Internet. In another embodiment, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0053] The present invention provides a method for loading an initialization function of a program module. Figure 2 FIG. 1 is a flow chart of a method for loading an initialization function of a program module in an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:
[0054] Step S210 , determining the dependency relationship between a plurality of initialization functions; wherein the dependency relationship includes the startup sequence relationship between any two initialization functions.
[0055] In this step, first of all, the dependency relationship between the initialization functions of each program module is required. Dependency refers to the startup order relationship between any two initialization functions. For example, when an initialization function needs to be started after another initialization function, it means that the initialization function started later depends on the initialization function started first. For another example, when an initialization function can be started after another initialization function or before another initialization function, it means that the two initialization functions are not dependent on each other, or the startup order relationship between the two initialization functions is arbitrary. Therefore, dependency relationships include two functions that are mutually dependent and two functions that are not mutually dependent.
[0056] Step S220: setting priorities of several initialization functions according to the dependency relationship.
[0057] When the dependency relationship between several initialization functions is determined, the startup order between the several initialization functions can be determined. Among them, since some initialization functions are not dependent on each other, the startup order between several initialization functions is not the same. Specifically, in this step, the priorities of several initialization functions are set according to the dependency relationship, and the priority refers to the loading priority of the initialization function. The higher the priority, the earlier the initialization function is loaded, and the lower the priority, the later the initialization function is loaded. For example, when an initialization function does not depend on any other initialization function, the initialization function can be set to the highest priority, and then the priority will be loaded first. It should be noted that there may be a situation where multiple initialization functions that are not dependent on each other have the same priority, and the loading order between these multiple initialization functions can be random.
[0058] In step S230 , the preset compiler constructs an initialization function list according to the priorities of the initialization functions.
[0059] In this step, after setting the priorities of several initialization functions, the initialization function list is constructed according to the priorities through the preset compiler. The initialization function list refers to a data structure that stores initialization functions in order. Specifically, according to the priority relationship of several initialization functions, the initialization functions are stored in order in the initialization function list. Among them, the initialization function with a higher priority is stored at the front, and the initialization function with a lower priority is stored at the back. Furthermore, the initialization function list includes multiple data segments, the order of the data segments is related to the priority, and the same data segment is used to store initialization functions of the same priority. For example, the data segment with the highest order is used for at least one initialization function with the highest priority, and the data segment with the last order is used for at least one initialization function with the lowest priority. Then, through multiple data segments, several initialization functions can be stored in the initialization function list in order of priority. It should be noted that in the same data segment, the storage order of initialization functions of the same priority is randomly determined by the compiler.
[0060] Step S240: Load several initialization functions in sequence according to the initialization function list.
[0061] Specifically, through the above steps, the preset compiler can store the initialization functions in the initialization function list in order. The storage order of the initialization functions is related to their priority. Therefore, when initializing various program modules, several initialization functions can be loaded sequentially according to the storage order according to the initialization function list.
[0062] Through the above steps, first, the priority of each initialization function is determined based on the dependency relationship between the initialization functions. Then, the preset compiler is used to store the initialization functions in the corresponding positions according to their priorities, thereby constructing an initialization function list. Among them, the function storage order in the initialization function list is related to the function priority. The higher the priority of the initialization function, the closer its storage position is, and the lower the priority of the initialization function, the closer its storage position is. Finally, the computer system automatically loads the initialization functions in sequence according to the function storage order in the initialization function list. Therefore, compared with the prior art, the present invention does not require developers to assign initialization functions to the main function in order. Instead, it only requires giving the priority of the initialization function, and then the preset compiler automatically generates the initialization function list based on the priority of the initialization function. Furthermore, when the initialization function changes (increase, decrease, or replace), it is only necessary to rebuild the initialization function list through the preset compiler, without the developer having to add, decrease, or replace the corresponding initialization function in a specific position in the main function set. This solves the problem in the prior art that the computer system cannot automatically load the initialization functions of each program module.
[0063] In some of these embodiments, the priority includes a first priority, and the dependency includes a first dependency.
[0064] Step S210, determining the dependency relationship between several initialization functions includes:
[0065] Step S211, determining the types of several initialization functions; Step S212, determining the first dependency relationship between the several initialization functions according to the types; wherein the first dependency relationship includes the startup sequence relationship between any two initialization functions of different types.
[0066] Step S220, setting the priorities of several initialization functions according to the dependency relationship includes:
[0067] Step S221: setting a first priority of the initialization function according to the first dependency relationship.
[0068] In this embodiment, considering that functions of the same type have the same or similar dependencies, the initialization functions can be graded according to the function type to determine the dependencies between functions of different types. The priorities of different types of initialization functions can be set according to the principle that the preceding type does not depend on the subsequent type, while the subsequent type can depend on the preceding type. For example, according to the possible dependencies, the initialization functions are divided into 7 types: kernel, peripheral, pure software, device, component, environment and application. Among them, the kernel type initialization function has the highest priority, and the peripheral type initialization function has the second highest priority. It only depends on the kernel type initialization function and does not depend on other types of initialization functions.
[0069] Accordingly, in one embodiment, the initialization function list includes a plurality of first data segments that are sequentially sorted, and the same first data segment is used to store initialization functions with the same first priority.
[0070] In this embodiment, the initialization function list includes multiple first data segments arranged in storage order. The first data segments correspond to the first priorities of the initialization functions. Specifically, the first first data segment is used to store the initialization function with the highest priority, the second first data segment is used to store the initialization function with the second highest priority, and so on. The initialization functions are then sorted and stored in the function list according to their first priority.
[0071] Accordingly, in one embodiment, in step S230, the preset compiler constructs an initialization function list according to the priorities among the multiple initialization functions, including:
[0072] Step S231 , determining the first priority of the initialization function to be stored according to its type; Step S232 , storing the initialization function to be stored in the corresponding first data segment according to the first priority of the initialization function to be stored.
[0073] Specifically, in the previous steps, the first priority of each type of initialization function was set based on the dependencies between different types of initialization functions. Therefore, when constructing the initialization function list, the compiler first determines the first priority of the initialization function to be stored based on its type. Since the first data segment in the initialization list corresponds to the first priority, the compiler can store the stored initialization function in the designated first data segment.
[0074] Furthermore, in some embodiments, the priority also includes a second priority, and the dependency also includes a second dependency.
[0075] Step S210, determining the dependency relationship between the initialization functions further includes:
[0076] Step S213, determining the levels of the plurality of initialization functions; Step S214, determining a second dependency relationship between the plurality of initialization functions based on the levels; wherein the second dependency relationship includes a startup order relationship between any two initialization functions of different levels;
[0077] Step S220, setting the priorities of several initialization functions according to the dependency relationship also includes:
[0078] Step S222: Setting a second priority of the initialization function according to the second dependency relationship.
[0079] In this embodiment, considering that dependencies may exist between initialization functions of the same type, in order to more accurately set the priority of the initialization function, in addition to determining the initialization function type, it is also necessary to determine the level of the initialization function. The priority of the initialization function is also related to its level. The higher the level of the initialization function, the higher its priority. For example, initialization functions can be divided into three levels: high, medium, and low. Low-level initialization functions depend on high-level initialization functions, while high-level initialization functions may not depend on low-level initialization functions. Therefore, in one specific embodiment, after the first priority of each type of initialization function is set according to the first dependency between different function types, the second priority of each level of initialization function of the same type is also set according to the second dependency between different function levels. Furthermore, initialization functions with the same first priority may also have different second priorities. Therefore, the specific priority of each initialization function is determined by the first priority and the second priority, with the first priority being the primary priority and the second priority being the secondary priority.
[0080] Accordingly, in one embodiment, the initialization function list includes a plurality of second data segments that are sequentially sorted, and the same second data segment is used to store initialization functions with the same first priority and the same second priority.
[0081] In this embodiment, the initialization function list includes multiple second data segments arranged in a storage order, and the second data segments correspond to the specific priorities of the initialization functions. Specifically, the first first data segment is used to store the initialization function with the highest priority (both the first and second priorities are the highest), the second first data segment is used to store the initialization function with the second highest priority (the first priority is the highest, the second priority is the second highest), and so on. The initialization functions are then stored in the function list according to their specific priorities.
[0082] Accordingly, in one embodiment, in step S230, the preset compiler constructs an initialization function list according to the priorities among the multiple initialization functions, including:
[0083] Step S233, determining the first priority of the initialization function to be stored according to the type of the initialization function to be stored; step S234, determining the second priority of the initialization function to be stored according to the level of the initialization function to be stored; step S235, storing the initialization function to be stored in the corresponding second data segment according to the first priority and second priority of the initialization function to be stored.
[0084] Specifically, in the previous step, the first priority of each type of initialization function and the second priority of each level of initialization function have been set according to the dependency relationship between initialization functions of different types and levels. The specific priority of the initialization function can be determined by the first priority and the second priority. Therefore, in the process of constructing the initialization function list, the compiler first determines the first priority of the initialization function to be stored according to the type of the initialization function to be stored, and then determines the second priority of the initialization function to be stored according to the level of the initialization function to be stored, and then determines the priority of the initialization function to be stored. The second data segment in the initialization list corresponds one-to-one to the specific priority, so the compiler can store the initialization function in the specified second data segment.
[0085] Furthermore, in some embodiments, the default compiler is an ARM compiler or a GCC compiler.
[0086] Specifically, in this embodiment, the ARM compiler or the GCC compiler is used to construct the initialization function list. Furthermore, __attribute__((section("name"))) is a compilation feature supported by the ARM compiler for placing a function and / or data into the data segment of name during compilation. In this embodiment, this compilation feature of the ARM compiler is utilized to construct the initialization function list.
[0087] The first is to construct the format of the initialization function list.
[0088] The format of the initialization list is as follows: __attribute__((section(".init_call.1.1"))).
[0089] init_call.1.1 indicates that one of the data segments in the list is initialized. Among them, init_call is a custom field name, the first number after the field name indicates the first priority corresponding to the data segment, and the second number after the field name indicates the second priority corresponding to the data segment. It should be noted that this compilation feature will automatically sort the data segments according to the numerical size of the field name. For example, init_call.1.1 is the data segment with the first sorting, and init_call.1.2 is the data segment with the second sorting. Therefore, in the process of constructing the initialization function list, the compiler can use numbers to represent the first and second priorities of the initialization function, and then assign them to the corresponding data segments.
[0090] For example, you can define multiple layers of macros with parameters as follows:
[0091] typedef os_err_t(*os_init_fn_t)(void);
[0092] #define OS_SECTION(x) __attribute__((section(x)))
[0093] #define OS_INIT_SUBLEVEL_HIGH "1"
[0094] #define OS_INIT_SUBLEVEL_MIDDLE "2"
[0095] #define OS_INIT_SUBLEVEL_LOW "3"
[0096] #define OS_SECTION(x) __attribute__((section(x)))
[0097] #define OS_INIT_EXPORT(fn,level,sublevel)
[0098] const os_init_fn_t_os_call_##fn OS_SECTION(".init_call."levelsublevel)=fn
[0099] #define OS_CORE_INIT(fn, sublevel) OS_INIT_EXPORT(fn, "1.", sublevel)
[0100] #define OS_POSTCORE_INIT(fn, sublevel) OS_INIT_EXPORT(fn, "2.", sublevel)
[0101] #define OS_PREV_INIT(fn, sublevel) OS_INIT_EXPORT(fn, "3.", sublevel)
[0102] #define OS_DEVICE_INIT(fn, sublevel) OS_INIT_EXPORT(fn, "4.", sublevel)
[0103] #define OS_CMPOENT_INIT(fn, sublevel) OS_INIT_EXPORT(fn, "5.", sublevel)
[0104] #define OS_ENV_INIT(fn, sublevel) OS_INIT_EXPORT(fn, "6.", sublevel)
[0105] #define OS_APP_INIT(fn, sublevel) OS_INIT_EXPORT(fn, "7.", sublevel)
[0106] The above macro can be used to quickly add the initialization function that needs to be initialized to the initialization function list. For example, for the core initialization function, it is assigned to the data segment with "1." in the segment name. When the kernel initialization function has a high level, it will be stored in the data segment init_call.1.1.
[0107] It should be further explained that, by utilizing the above-mentioned compilation features, an initialization function of the same level and without sub-priority can be specified to be automatically stored at the beginning of the priority segment; similarly, when the sub-priority of the initialization function ends with a non-number, the initialization function will be automatically stored in the segment of the data segment. For example, when the priority of an initialization function is expressed as "1." (only main priority, no sub-priority), the compiler will assign the initialization function to before the data segment init_call.1.1. When the priority of an initialization function is expressed as "1.a" (sub-priority is expressed by a number), the compiler will assign the initialization function to after the data segment init_call.1.3.
[0108] The technical solutions of the present invention are described below through preferred embodiments.
[0109] Figure 3 FIG. 1 is a flow chart of a method for loading a program module initialization function in a preferred embodiment of the present invention. Figure 3 As shown, the process includes the following steps:
[0110] Step S310: setting a first priority of the initialization function according to the first dependency relationship.
[0111] Specifically, the first dependency refers to the dependency between functions of different types. Based on the principle that the preceding type does not depend on the subsequent type, while the subsequent type can have a dependency on the preceding type, the possible dependencies are divided into seven types: kernel, peripherals, pure software, device, component, environment, and application.
[0112] Step S320: setting a second priority of the initialization function according to the second dependency relationship.
[0113] Specifically, the second dependency refers to the dependency between functions of different levels in the same type of function. To solve the problem that initialization functions of the same priority may have dependencies, each of the seven types of functions divided in step S310 is divided into three levels: high, medium, and low.
[0114] Step S330: The compiler constructs an initialization function list according to the priority of the initialization function.
[0115] Specifically, the initialization code of the program module constructs an initialization function table according to the format, and the format of constructing the initialization function table is as follows: attribute__((section(".init_call.1.1"))).
[0116] init_call.1.1 indicates that one of the data segments in the list has been initialized. init_call is a custom field name, the first number after the field name indicates the first priority (primary priority) corresponding to the data segment, and the second number after the field name indicates the second priority (secondary priority) corresponding to the data segment.
[0117] __attribute__((section("name"))) is a compilation feature supported by the ARM compiler to implement placing a function and / or data into the data segment of name at compile time.
[0118] Step S340: define a preset macro and assign it to a specific data segment according to the initialization function type.
[0119] Specifically, define multi-layer parameter macros as follows:
[0120] typedef os_err_t(*os_init_fn_t)(void);
[0121] #define OS_SECTION(x) __attribute__((section(x)))
[0122] #define OS_INIT_SUBLEVEL_HIGH "1"
[0123] #define OS_INIT_SUBLEVEL_MIDDLE "2"
[0124] #define OS_INIT_SUBLEVEL_LOW "3"
[0125] #define OS_SECTION(x) __attribute__((section(x)))
[0126] #define OS_INIT_EXPORT(fn,level,sublevel)
[0127] const os_init_fn_t_os_call_##fn OS_SECTION(".init_call."levelsublevel)=fn
[0128] #define OS_CORE_INIT(fn,sublevel)OS_INIT_EXPORT(fn,"1.",sublevel)
[0129] #define OS_POSTCORE_INIT(fn,sublevel)OS_INIT_EXPORT(fn,"2.",sublevel)
[0130] #define OS_PREV_INIT(fn,sublevel)OS_INIT_EXPORT(fn,"3.",sublevel)
[0131] #define OS_DEVICE_INIT(fn,sublevel)OS_INIT_EXPORT(fn,"4.",sublevel)
[0132] #define OS_CMPOENT_INIT(fn, sublevel)OS_INIT_EXPORT(fn, "5.", sublevel)
[0133] #define OS_ENV_INIT(fn, sublevel) OS_INIT_EXPORT(fn, "6.", sublevel)
[0134] #define OS_APP_INIT(fn, sublevel) OS_INIT_EXPORT(fn, "7.", sublevel)
[0135] The above macro can be used to quickly add the initialization function that needs to be initialized to the system's initialization function list.
[0136] Step S350: Determine the starting address and ending address of the initialization function at each level.
[0137] Specifically, through step S330, an initialization function of the same level and without sub-priority can be automatically stored at the beginning of the priority segment; similarly, when the sub-priority is filled in with an initialization function ending with a non-number, it is automatically stored at the end of the priority segment.
[0138] Step S360: Load several initialization functions in sequence according to the initialization function list.
[0139] Specifically, by traversing the first address of the initialization list found in step S350, the initialization list can be initialized in order of priority.
[0140] As can be seen from the above preferred embodiments, the initialization function loading method of the present invention is different from the prior art. The prior art requires developers to identify the initialization order of each functional module initialization code and manually add it to the main entry to complete the initialization. Each time a module is added or deleted, the initialization code needs to be modified, making it difficult for the program to achieve true module independence. However, the present invention allows users to automatically insert the initialization function into the initialization list through a macro; register it in any source file; and add or delete modules by simply removing the corresponding module from the existing project or commenting out the corresponding registration macro and recompiling. This is very convenient for multi-person collaborative development and modular programming.
[0141] In this embodiment, a device for loading an initialization function of a program module is also provided. The device is used to implement the above-mentioned embodiments and preferred embodiments. The details that have been described will not be repeated here. The terms "module," "unit," "subunit," etc. used below may refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation using hardware, or a combination of software and hardware, is also possible and contemplated.
[0142] Figure 4 It is a structural block diagram of an initialization function loading device for a program module in an embodiment of the present invention.
[0143] like Figure 4 As shown, the device includes:
[0144] A first relationship determination module 410 is configured to determine a dependency relationship between a plurality of initialization functions; wherein the dependency relationship includes a startup order relationship between any two initialization functions;
[0145] A second relationship determination module 420, configured to set priorities of a plurality of initialization functions according to dependency relationships;
[0146] A function list building module 430 is configured to build an initialization function list according to the priorities of the initialization functions using a preset compiler;
[0147] The function automatic loading module 440 is used to load several initialization functions in sequence according to the initialization function list.
[0148] It should be noted that the above modules can be functional modules or program modules, and can be implemented through software or hardware. For modules implemented through hardware, the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.
[0149] This embodiment further provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0150] It should be noted that, for specific examples in this embodiment, reference may be made to the examples described in the above embodiments and optional implementation modes, and will not be repeated in this embodiment.
[0151] In addition, in conjunction with the method for loading the initialization function of a program module provided in the above embodiments, a storage medium may also be provided in this embodiment to implement the method. The storage medium stores a computer program; when the computer program is executed by a processor, the method for loading the initialization function of a program module provided in any of the above embodiments is implemented.
[0152] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0153] It should be understood that the specific embodiments described herein are only used to explain this application and are not used to limit it. Based on the embodiments provided in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0154] Obviously, the accompanying drawings are merely examples or embodiments of the present application. A person skilled in the art can also apply the present application to other similar situations based on these drawings without inventive effort. Furthermore, it is understandable that, although the work involved in this development process may be complex and lengthy, certain design, manufacturing, or production changes based on the technical content disclosed in this application are merely routine technical means for a person skilled in the art and should not be considered to constitute a deficiency in the disclosure of the present application.
[0155] The term "embodiment" as used in this application refers to specific features, structures, or characteristics described in conjunction with the embodiment that can be included in at least one embodiment of this application. The appearance of this phrase in various places in the specification does not necessarily mean that the embodiment is the same, nor does it mean that it is mutually exclusive with other embodiments and is independent or optional. It is understood, either explicitly or implicitly, by those skilled in the art that the embodiments described in this application can be combined with other embodiments when there is no conflict.
[0156] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of patent protection. It should be noted that a person of ordinary skill in the art may make various modifications and improvements without departing from the spirit of the present application, and these modifications and improvements fall within the scope of protection of the present application. Therefore, the scope of protection of the present application shall be determined by the appended claims.
Claims
1. A method for loading an initialization function of a program module, characterized in that: The method comprises: Determining the types of the initialization functions; Determining a first dependency relationship between the plurality of initialization functions according to the type; wherein the first dependency relationship includes a startup sequence relationship between any two initialization functions of different types; Setting a first priority of the initialization function according to the first dependency relationship; The initialization function list includes a plurality of first data segments that are sequentially sorted, and the same first data segment is used to store the initialization functions with the same first priority; The preset compiler determines a first priority of the to-be-stored initialization function according to a type of the to-be-stored initialization function; storing the to-be-stored initialization function in the corresponding first data segment according to the first priority of the to-be-stored initialization function; Determining the levels of a plurality of said initialization functions; Determining a second dependency relationship between a plurality of the initialization functions according to the level; wherein the second dependency relationship includes a startup sequence relationship between any two initialization functions of different levels; Setting a second priority of the initialization function according to the second dependency relationship; wherein the specific priority of each of the initialization functions is determined by the first priority and the second priority, the first priority being the primary priority and the second priority being the secondary priority; Several initialization functions are loaded in sequence according to the initialization function list.
2. The method for loading an initialization function of a program module according to claim 1, wherein: The initialization function list includes a plurality of second data segments arranged in sequence, and the same second data segment is used to store the initialization functions with the same first priority and the same second priority.
3. The method for loading an initialization function of a program module according to claim 2, wherein: The preset compiler constructs an initialization function list according to the priorities of the initialization functions, including: Determining a first priority of the initialization function to be stored according to the type of the initialization function to be stored; Determining a second priority of the initialization function to be stored according to the level of the initialization function to be stored; According to the first priority and the second priority of the initialization function to be stored, the initialization function to be stored is stored in the corresponding second data segment.
4. The method for loading an initialization function of a program module according to claim 1, wherein: The preset compiler is an ARM compiler or a GCC compiler.
5. A program module initialization function loading device, characterized in that: The device comprises: a first relationship determination module, configured to determine types of the plurality of initialization functions; determine a first dependency relationship between the plurality of initialization functions based on the types; wherein the first dependency relationship includes a startup sequence relationship between any two initialization functions of different types; and further configured to determine levels of the plurality of initialization functions; and determine a second dependency relationship between the plurality of initialization functions based on the levels; wherein the second dependency relationship includes a startup sequence relationship between any two initialization functions of different levels; a second relationship determination module, configured to set a first priority of the initialization function according to the first dependency relationship; the initialization function list includes a plurality of first data segments sorted in sequence, the same first data segment being used to store the initialization functions having the same first priority; and further configured to set a second priority of the initialization function according to the second dependency relationship; wherein the specific priority of each initialization function is determined by the first priority and the second priority, the first priority being a primary priority and the second priority being a secondary priority; a function list construction module, configured to determine, using a preset compiler, a first priority of the to-be-stored initialization function according to its type; and store the to-be-stored initialization function into the corresponding first data segment according to the first priority of the to-be-stored initialization function; The function automatic loading module is used to load several initialization functions in sequence according to the initialization function list.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for loading the initialization function of the program module according to any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Module initialization sequence generation method and device, equipment and storage medium
CN114564254A
Method and device for module loading and electronic equipment
CN114741121A