Disclosure of Invention
In view of the above, the embodiments of the present application provide a method, an apparatus, a terminal device, and a storage medium for modifying a device tree content, so as to solve the technical problem of low convenience of the existing hardware configuration.
In a first aspect, an embodiment of the present application provides a method for modifying a device tree content, including:
acquiring a device tree source code file; the equipment tree source code file comprises equipment tree contents which need to be modified or added;
Compiling the equipment tree source code file to obtain a target equipment tree compiling file, and loading the target equipment tree compiling file into a specified file system;
And loading the target equipment tree compiling file into the original equipment tree compiling file from the appointed file system to obtain the equipment tree compiling file after updating the equipment tree content.
Optionally, the loading the target device tree compilation file into the original device tree compilation file from the specified file system to obtain the device tree compilation file after updating the device tree content includes:
Comparing the target equipment tree compiling file with the original equipment tree compiling file;
if the target equipment tree compiling file is different from the original equipment tree compiling file, a dynamic loading switch in a driving file is started, and the target equipment tree compiling file is loaded into the original equipment tree compiling file from the specified file system through a preset interface, so that the equipment tree compiling file after updating the equipment tree content is obtained.
Optionally, after loading the target device tree compiled file into the original device tree compiled file from the specified file system, the method further includes:
and closing the dynamic loading switch to delete the target equipment tree compiling file in the equipment tree compiling file after updating the equipment tree content.
Optionally, after the dynamic loading switch is turned off to delete the target device tree compiled file in the device tree compiled file after updating the device tree content, the method further includes:
And adjusting the function of a driving file for driving the device tree compiling file according to the device tree compiling file after deleting the target device tree compiling file.
Optionally, after the obtaining the device tree compiled file after updating the device tree content, the method further includes:
And analyzing and updating the equipment tree compiling file after the content of the equipment tree through the kernel.
Optionally, after the device tree compiling file after the device tree content is updated through kernel parsing, the method further includes:
And adjusting the function of a driving file for driving the equipment tree compiling file according to the equipment tree compiling file after updating the equipment tree content.
Optionally, compiling the device tree source code file to obtain a target device tree compiled file, including:
Converting the format of the equipment tree source code file into a preset format;
And compiling the equipment tree source code file in the preset format into a binary file to obtain the target equipment tree compiling file.
In a second aspect, an embodiment of the present application provides a device tree content modification apparatus, including:
The source code file acquisition unit is used for acquiring the equipment tree source code file; the equipment tree source code file comprises equipment tree contents which need to be modified or added;
The compiling unit is used for compiling the equipment tree source code file to obtain a target equipment tree compiling file, and loading the target equipment tree compiling file into a specified file system;
and the loading unit is used for loading the target equipment tree compiling file into the original equipment tree compiling file from the appointed file system to obtain the equipment tree compiling file after updating the equipment tree content.
In a third aspect, an embodiment of the present application provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor implements steps in a method for modifying a device tree content according to any one of the first aspects when the computer program is executed by the processor.
In a fourth aspect, an embodiment of the present application provides a computer readable storage medium storing a computer program, which when executed by a processor implements the steps of a method for modifying the content of a device tree according to any one of the first aspects above.
In a fifth aspect, an embodiment of the present application provides a computer program product for, when run on a terminal device, causing the terminal device to perform the steps of the method of modifying the content of a device tree as described in any one of the first aspects above.
The method, the device, the terminal equipment and the storage medium for modifying the equipment tree content provided by the embodiment of the application have the following beneficial effects:
In the method for modifying the equipment tree content provided by the embodiment of the application, firstly, the equipment tree source code file containing the equipment tree content to be modified or added is obtained, then the equipment tree source code file is compiled to obtain the target equipment tree compiling file, the target equipment tree compiling file is loaded into a designated file system, and finally, the target equipment tree compiling file is loaded into the original equipment tree compiling file from the designated file system to obtain the equipment tree compiling file after updating the equipment tree content. The method for modifying the equipment tree content provided by the embodiment of the application can be executed when the system is running, so that the equipment tree content can be dynamically modified when the system is running, and the convenience of the existing hardware configuration is improved.
Detailed Description
It is to be understood that the terminology used in the embodiments of the application is for the purpose of describing particular embodiments of the application only, and is not intended to be limiting of the application. In the description of the embodiments of the present application, unless otherwise indicated, "a plurality" means two or more, and "at least one", "one or more" means one, two or more. The terms "first," "second," and the like, are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a definition of "a first", "a second" feature may explicitly or implicitly include one or more of such features.
Reference in the specification to "one embodiment" or "some embodiments" or the like means that a particular feature, structure, or characteristic described in connection with the embodiment is included in one or more embodiments of the application. Thus, appearances of the phrases "in one embodiment," "in some embodiments," "in other embodiments," and the like in the specification are not necessarily all referring to the same embodiment, but mean "one or more but not all embodiments" unless expressly specified otherwise. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless expressly specified otherwise.
The execution main body of the device tree content modification method provided by the embodiment of the application can be terminal equipment. The terminal device may be included in an electronic device such as a mobile phone, a tablet computer, a notebook computer, and a desktop computer.
The method for modifying the equipment tree content provided by the embodiment of the application can be applied to a scene for modifying the equipment tree content, and particularly, when a user needs to dynamically modify the equipment tree content in the system operation, each step of the method for modifying the equipment tree content provided by the embodiment of the application can be executed through the terminal equipment, so that the equipment tree content can be dynamically modified in the system operation, and the convenience of the existing hardware configuration is further improved.
Referring to fig. 1, fig. 1 is a flowchart illustrating an implementation method of modifying equipment tree content according to an embodiment of the present application, where the method for modifying equipment tree content may include S101 to S103, which are described in detail as follows:
in S101, a device tree source code file is acquired.
The device tree source code file comprises device tree contents which need to be modified or added.
In the embodiment of the application, when the user needs to modify the equipment tree content, the equipment tree source code file can be written according to the equipment tree content which needs to be modified or added, and the equipment tree source code file comprising the equipment tree content which needs to be modified or added is input into the terminal equipment, so that the terminal equipment obtains the equipment tree source code file.
The device tree is a data structure and a method for describing a hardware platform and components thereof, and is mainly used in an embedded system; describing a hardware platform: ARM device tree is a structured data format that describes a hardware platform. The system comprises component information of a hardware platform, such as a processor, a peripheral device, an interrupt controller, a clock, a bus, a memory and the like, and connection and dependency relationship between the processor, the peripheral device, the interrupt controller, the clock, the bus, the memory and the like; the device tree source code file may be a dts format file.
In S102, the device tree source code file is compiled to obtain a target device tree compiled file, and the target device tree compiled file is loaded into a specified file system.
In the embodiment of the application, after the terminal equipment acquires the equipment tree source code file, the terminal equipment can compile the equipment tree source code file to obtain the target equipment tree compiled file.
Specifically, the DTC device tree compiling tool may be downloaded in the terminal device in advance, so that the terminal device may compile the device tree source code file through the DTC device tree compiling tool to obtain the target device tree compiling file.
In one possible implementation, the terminal device may compile the device tree source code file through steps a to b. The details are as follows:
in step a, the format of the equipment tree source code file is converted into a preset format.
In this implementation, before compiling the device tree source code file, the format of the device tree source code file needs to be converted into a preset format. The specific preset format can be set according to actual requirements.
The following is a schematic text of a preset format of a device tree source code file provided by the embodiment of the application:
/dts-v1/
/plugin/
{/} {// indicates loading into root node
overlay_id=0x888
overlay{
overlay_name=“overlay_test”;
};
}
As shown in the above text, {/}: the representation is loaded to the root node and may be added to other nodes. Other than the above points of attention, the other grammars are the same as the normal device tree writing grammar.
In the step b, compiling the device tree source code file in the preset format into a binary file to obtain a target device tree compiling file.
In this implementation manner, after the terminal device converts the format of the device tree source code file into the preset format, the device tree source code file in the preset format may be compiled into a binary file, so as to obtain the target device tree compiled file.
After obtaining the target device tree compiled file, the terminal device may load the target device tree compiled file into the specified file system.
In one possible implementation, the specified file system may be configfs file systems. configfs the file system is characterized in that: configfs can create and delete kernel objects in the user state. configfs is a ram-based file system, and configuration of kernel objects is implemented by operation of the file system.
Specifically, a memory buffer area can be opened up in the configfs file system in advance as an operation object, and the compiled file of the target device tree is loaded into the memory space reserved by the configfs file system.
In S103, the target device tree compilation file is loaded into the original device tree compilation file from the specified file system, and the device tree compilation file after updating the device tree content is obtained.
In the embodiment of the application, after the target equipment tree compiling file is loaded into the specified file system, the terminal equipment can compare the target equipment tree compiling file with the original equipment tree compiling file, if the target equipment tree compiling file is different from the original equipment tree compiling file, a dynamic loading switch in the driving file is started, and the target equipment tree compiling file is loaded into the original equipment tree compiling file from the specified file system through a preset interface, so that the equipment tree compiling file after updating the equipment tree content is obtained.
It can be seen from the foregoing that, in the method for modifying the equipment tree content provided in the embodiment of the present application, an equipment tree source code file including the equipment tree content to be modified or added is first obtained, then the equipment tree source code file is compiled to obtain a target equipment tree compiled file, the target equipment tree compiled file is loaded into a specified file system, and finally the target equipment tree compiled file is loaded into an original equipment tree compiled file from the specified file system, so as to obtain an equipment tree compiled file after updating the equipment tree content. The method for modifying the equipment tree content provided by the embodiment of the application can be executed when the system is running, so that the equipment tree content can be dynamically modified when the system is running, and the convenience of the existing hardware configuration is improved.
In an alternative implementation manner, after the target device tree compilation file is loaded into the original device tree compilation file from the specified file system, the terminal device may also close the dynamic loading switch to delete the target device tree compilation file in the device tree compilation file after updating the device tree content.
The above can be seen that, the user can instruct the terminal device to close the dynamic loading switch, so that the target device tree compiling file in the device tree compiling file after the device tree content is updated can be deleted, that is, the target device tree compiling file can be loaded into the original device tree compiling file by opening the dynamic loading switch, and the device tree compiling file after the device tree content is updated can be obtained. The dynamic loading switch can be closed to delete the target equipment tree compiling file in the equipment tree compiling file after the equipment tree content is updated, so that dynamic loading and dynamic modification can be realized, dynamic deletion can be realized, namely, the equipment tree content can be modified or added when the system is operated, and the modified content or added content in the equipment tree content can be deleted when the system is operated.
In one possible implementation, the functions of the driver may also need to be adjusted after the device tree compilation file is added, modified, or deleted.
Based on the above, after the terminal device turns off the dynamic loading switch to delete the target device tree compilation file in the device tree compilation file after updating the device tree content, the terminal device may further adjust a function of the driving file for driving the device tree compilation file according to the device tree compilation file after deleting the target device tree compilation file.
Based on the above, after obtaining the equipment tree compiling file after updating the equipment tree content, the terminal equipment can adjust the function of the driving file for driving the equipment tree compiling file according to the equipment tree compiling file after updating the equipment tree content.
In one possible implementation manner, after obtaining the device tree compiled file after updating the device tree content, the terminal device may also parse the device tree compiled file after updating the device tree content through the kernel.
Compared with the static equipment tree in the prior art, the method for modifying the equipment tree content provided by the embodiment of the application has the following innovation points:
Real-time response: the technology can detect hardware changes in real time and dynamically adjust the device tree to adapt to new hardware configurations. This real-time responsiveness enables the system to automatically identify and accommodate insertion, removal, or modification of hardware devices at runtime without restarting the system or user intervention. This flexibility makes the embedded system more suitable for dynamic environments and improves the adaptability and usability of the system.
And (3) ensuring safety: by means of authority control and audit mechanism for modifying the dynamic equipment tree, only authorized users or processes can be ensured to conduct modification operation on the equipment tree. The security guarantee ensures the stability and the security of the system and prevents malicious modification and potential security risks.
Extensibility and customization: the dynamic modification of the device tree allows for greater scalability and customization of the system. The user can dynamically add, delete or modify the device nodes as required, thereby flexibly configuring the hardware resources and the functional characteristics of the system. This flexibility makes the embedded system more suitable for a variety of different application scenarios and provides the possibility for further customization and optimization of the system.
By the technology, the expandability, maintainability and usability of the embedded system can be improved, the requirements under different application scenes are met, and a new technical breakthrough is brought to the development and deployment of the embedded system.
In an optional implementation manner, the method for modifying the device tree content provided by the embodiment of the application can be applied to an embedded Linux system, and has the following advantages when applied to the embedded Linux system:
1. hardware configuration flexibility: by dynamically modifying the device tree, hardware resources, including adding, deleting, or modifying device nodes, interrupt controllers, sensors, etc., can be dynamically configured at system runtime. This allows the system to flexibly configure and manage hardware resources as needed at run-time without restarting the system.
2. Hot plug support: dynamically modifying the device tree may enable hot plug support for hardware devices. When a hardware device is inserted or removed, the hardware configuration of the system may be dynamically updated by modifying the device tree so that the system can immediately identify and respond to the new hardware device.
3. Function expansion and customization: dynamic expansion and customization of system functions can be achieved by dynamically modifying the device tree. For example, new device nodes or functional modules may be added at system runtime to meet the needs of a particular application scenario without recompiling the kernel or restarting the system.
4. Debugging and troubleshooting: dynamically modifying the device tree may also be used for debugging and troubleshooting. By viewing and modifying the content of the device tree in real time, it is possible to help locate hardware configuration errors, device driving problems, etc., and make corresponding adjustments and repairs without having to shut down or restart the system.
5. Time and resources are saved: the dynamic modification of the device tree can save time and resources required by restarting the system and improve the availability and responsiveness of the system. Especially in a production environment or in a scenario where the availability of the system is high, dynamically modifying the plant tree can significantly reduce downtime of the system.
In general, the dynamic modification of the device tree can provide flexibility, expandability and debugging convenience in the embedded Linux system, so that the system can be more suitable for different application scenes, and the usability and maintainability of the system are improved.
Based on the method for modifying the equipment tree content provided by the above embodiment, the embodiment of the present application further provides a device for modifying the equipment tree content for implementing the method embodiment, please refer to fig. 2, fig. 2 shows a schematic structural diagram of a device for modifying the equipment tree content provided by the embodiment of the present application. As shown in fig. 2, the device tree content modifying apparatus 20 may include: a source code file acquisition unit 21, a compiling unit 22, and a loading unit 23. Wherein:
The source code file obtaining unit 21 is used for obtaining a device tree source code file; the device tree source code file includes device tree content that needs to be modified or added.
The compiling unit 22 is configured to compile the device tree source code file to obtain a target device tree compiled file, and load the target device tree compiled file into a specified file system.
The loading unit 23 is configured to load the target device tree compiled file into an original device tree compiled file from the specified file system, so as to obtain a device tree compiled file after updating the device tree content.
Optionally, the loading unit 23 is specifically configured to:
Comparing the target equipment tree compiling file with the original equipment tree compiling file;
if the target equipment tree compiling file is different from the original equipment tree compiling file, a dynamic loading switch in a driving file is started, and the target equipment tree compiling file is loaded into the original equipment tree compiling file from the specified file system through a preset interface, so that the equipment tree compiling file after updating the equipment tree content is obtained.
Optionally, the modification means 20 of the device tree content may further comprise a deletion unit. Wherein:
The deleting unit is used for closing the dynamic loading switch so as to delete the target equipment tree compiling file in the equipment tree compiling file after updating the equipment tree content.
Optionally, the device tree content modifying means 20 may further comprise a function adjusting unit. Wherein:
The function adjusting unit is used for adjusting the function of the driving file for driving the device tree compiling file according to the device tree compiling file after deleting the target device tree compiling file.
Optionally, the function adjusting unit is further configured to adjust a function of a driving file for driving the device tree compiling file according to the device tree compiling file after updating the device tree content.
Optionally, the device tree content modifying means 20 may further comprise an updating unit. Wherein:
and the updating unit is used for analyzing and updating the equipment tree compiling file after the content of the equipment tree through the kernel.
Optionally, the compiling unit 22 is specifically configured to:
Converting the format of the equipment tree source code file into a preset format;
And compiling the equipment tree source code file in the preset format into a binary file to obtain the target equipment tree compiling file.
Referring to fig. 3, fig. 3 is a schematic structural diagram of a terminal device according to an embodiment of the present application. As shown in fig. 3, the terminal device 3 provided in this embodiment may include: a processor 30, a memory 31 and a computer program 32 stored in the memory 31 and executable on the processor 30, such as a program corresponding to a method of modifying the content of a device tree. The steps in the above-described embodiment of the modification method applied to the device tree content are implemented when the processor 30 executes the computer program 32, for example, S101 to S103 shown in fig. 1. Or the processor 30, when executing the computer program 32, implements the functions of the modules/units of the above described embodiment of the device tree content modification apparatus, such as the functions of the units 21-23 shown in fig. 2.
By way of example, the computer program 32 may be partitioned into one or more modules/units that are stored in the memory 31 and executed by the processor 30 to complete the present application. One or more of the modules/units may be a series of computer program instruction segments capable of performing a specific function for describing the execution of the computer program 32 in the terminal device 3. For example, the computer program 32 may be partitioned into: the specific functions of the source code file obtaining unit 21, the compiling unit 22 and the loading unit 23 are described in the corresponding embodiment of fig. 2, and are not repeated here.
It will be appreciated by those skilled in the art that fig. 3 is merely an example of the terminal device 3 and does not constitute a limitation of the terminal device 3, and may include more or fewer components than shown, or may combine certain components, or different components.
The processor 30 may be a central processing unit (central processing unit, CPU), but may also be other general purpose processors, digital signal processors (DIGITAL SIGNAL processors, DSPs), application Specific Integrated Circuits (ASICs), off-the-shelf programmable gate arrays (FPGAs) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory 31 may be an internal storage unit of the terminal device 3, such as a hard disk or a memory of the terminal device 3. The memory 31 may also be an external storage device of the terminal device 3, such as a plug-in hard disk, a smart memory card (SMART MEDIA CARD, SMC), a Secure Digital (SD) card, or a flash memory card (FLASH CARD) provided on the terminal device 3. Further, the memory 31 may also include both an internal storage unit of the terminal device 3 and an external storage device. The memory 31 is used to store computer programs and other programs and data required by the terminal device. The memory 31 may also be used to temporarily store data that has been output or is to be output.
It will be clear to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units is illustrated, and in practical application, the above-mentioned functional allocation may be performed by different functional units according to needs, that is, the internal structure of the modification device of the device tree content is divided into different functional units, so as to perform all or part of the above-mentioned functions. The functional units in the embodiment may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit, where the integrated units may be implemented in a form of hardware or a form of a software functional unit. In addition, the specific names of the functional units are also only for distinguishing from each other, and are not used to limit the protection scope of the present application. The specific working process of the units in the above system may refer to the corresponding process in the foregoing method embodiment, which is not described herein again.
Embodiments of the present application also provide a computer readable storage medium having a computer program stored therein, which when executed by a processor, performs the steps of the respective method embodiments described above.
The embodiments of the present application provide a computer program product for causing a terminal device to carry out the steps of the respective method embodiments described above when the computer program product is run on the terminal device.
In the foregoing embodiments, the descriptions of the embodiments are emphasized, and in part, not described or illustrated in any particular embodiment, reference may be made to related descriptions of other embodiments.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
The above embodiments are only for illustrating the technical solution of the present application, and not for limiting the same; although the application has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present application, and are intended to be included in the scope of the present application.