Adaptation method and device of equipment tree, equipment and readable storage medium

By automatically obtaining device information and verifying it in a simulated environment, the problem of device tree construction and verification relying on manual operations is solved, and the accuracy and efficiency of adaptation are improved.

CN120163099APending Publication Date: 2025-06-17龙芯中科(成都)技术有限公司
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510213156.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-25
Publication Date
2025-06-17

AI Technical Summary

Technical Problem

The construction and verification of existing device trees rely on manual operations, resulting in poor adaptation accuracy and low efficiency, and need to be deployed to actual boards for verification.

Method used

By obtaining the device information of the device, building the device tree file according to the preset device tree syntax format, and running related files in the simulated device operation environment, automatically generating and verifying the device tree.

Benefits of technology

Reliance on human resources is reduced, and the adaptability accuracy and efficiency of the device tree is improved, without burning the device tree to a physical board card for verification.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120163099A_ABST
    Figure CN120163099A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides an equipment tree adaptation method and device, equipment and a readable storage medium. Relates to the technical field of computers. The method comprises the following steps: respectively acquiring equipment information corresponding to equipment; according to the equipment information and a preset equipment tree grammar format, constructing and obtaining an equipment tree file; according to the device tree file, constructing a device operation environment and an operation file corresponding to each device, and operating all the operation files in the device operation environment to obtain an operation result; and analyzing according to the operation result, and determining a verification result of the equipment tree file. According to the method and the device, the device tree can be quickly and automatically generated based on the device information of the device, the dependence on human resources is reduced, the accuracy is improved, in addition, the verification of the device tree can be realized in a simulated operation environment, the device tree does not need to be burnt to an entity board card for verification, the cost is saved, and the efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of computer technology, and particularly relates to a method, apparatus, electronic device and readable storage medium for adapting a device tree. Background Art

[0002] A device tree is a data structure for describing computer hardware resources, mainly used to describe the hardware information of computer hardware devices, reduce the description code of hardware resources in the kernel source code, and make the description of the kernel source code relatively independent of the hardware resources.

[0003] Currently, the construction of a device tree can be achieved manually, and the finally completed device tree file can be deployed in a board for running verification after compilation. Therefore, the modification and attribute configuration of the device tree rely highly on personnel experience, often resulting in poor adaptation accuracy. In addition, each verification of the device tree needs to be deployed to an actual board, leading to a significant reduction in the adaptation efficiency. Summary of the Invention

[0004] The present invention aims to provide a method, apparatus, electronic device and readable storage medium for adapting a device tree, at least solving the problems in the prior art.

[0005] To solve the above technical problems, the present invention is implemented as follows:

[0006] In a first aspect, an embodiment of the present invention provides a method for adapting a device tree, the method including:

[0007] Obtaining the device information corresponding to each device respectively;

[0008] Constructing a device tree file according to the device information and a preset device tree syntax format; the device tree file is a tree-shaped data structure for describing device information;

[0009] Constructing a device operating environment and a running file corresponding to each device according to the device tree file, and running all the running files in the device operating environment to obtain a running result;

[0010] Analyzing according to the running result to determine the verification result of the device tree file.

[0011] In a second aspect, an embodiment of the present invention further provides an apparatus for adapting a device tree, the apparatus including:

[0012] An obtaining module, configured to obtain the device information corresponding to each device respectively;

[0013] A building module, configured to build a device tree file according to the device information and a preset device tree syntax format; the device tree file is a tree-shaped data structure representing the device information of a device.

[0014] An operating module, configured to build a device operating environment and a corresponding operating file for each device according to the device tree file, and run all the operating files in the device operating environment to obtain an operation result.

[0015] A verification module, configured to analyze according to the operation result to determine the verification result of the device tree file.

[0016] In a third aspect, an embodiment of the present invention further provides an electronic device, which includes a processor, a memory, and a program or instruction stored on the memory and executable on the processor. When the program or instruction is executed by the processor, the steps of the method described in the first aspect are implemented.

[0017] In a fourth aspect, an embodiment of the present invention further provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the steps of the method described in the first aspect are implemented.

[0018] In the embodiment of the present invention, the device information corresponding to each device can be obtained respectively; a device tree file is built according to the device information and a preset device tree syntax format; a device operating environment and a corresponding operating file for each device are built according to the device tree file, and all the operating files are run in the device operating environment to obtain an operation result; the verification result of the device tree file is determined according to the operation result. The present invention can automatically generate a device tree according to the device information of a device, and perform quick verification in a simulated operating environment, reducing the dependence on human resources, improving accuracy, and eliminating the need to burn the device tree into a physical board for verification, thereby improving the adaptation efficiency of hardware devices. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] Figure 1 is a flowchart of the steps of a method for adapting a device tree provided by an embodiment of the present invention;

[0020] Figure 2 is an overall flowchart of the steps of a method for adapting a device tree provided by an embodiment of the present invention;

[0021] Figure 3 is a flowchart of the process of adapting a device tree provided by an embodiment of the present invention;

[0022] Figure 4 is a block diagram of an apparatus for adapting a device tree provided by an embodiment of the present invention;

[0023] Figure 5 It is a schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present invention. Specific implementation manners

[0024] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention.

[0025] Figure 1 It is a flowchart of the steps of a method for adapting a device tree provided by an embodiment of the present invention. As Figure 1 shown, the method may include:

[0026] Step 101, respectively obtain the device information corresponding to each device.

[0027] In the embodiments of the present invention, the device may be hardware in a computer with specific function implementation. These devices are usually deployed on a board for work, such as a central processing unit (CPU, Central Processing Unit), a controller (microcontroller unit (MCU, Microcontroller Unit), proportional, integral, derivative controller (PID, Proportional Integral Derivative)), and other hardware.

[0028] Exemplarily, the device information of the device is relevant parameters corresponding to the device, and may include relevant parameter information such as the device name, device model, board model adapted, data types of input and output, and memory size of the device.

[0029] Specifically, the embodiments of the present application may download the development document of the device from the Internet, so as to obtain the device information of the device from the development document of the device. Of course, the embodiments of the present application may also call relevant commands in the computer where the device is deployed to retrieve and view the device information of the device. For example, in a Windows operating system, in one way, the Run dialog box can be called up by pressing the Win+R combination keys, and the command: msinfo32 can be entered to obtain the device information of the hardware devices deployed in the computer; in another way, the device manager application of the computer can be opened, and the device information of each device can be viewed in the device manager application; in yet another way, when the computer is powered on, enter the Basic Input Output System (BIOS), and more detailed device information can be found in the BIOS.

[0030] For another example, under the Linux system, the lshw command can be executed to list the hardware configuration information corresponding to each device in the computer. After capturing this hardware configuration information, it can be structurally integrated into the device information corresponding to each device. For a specific device, the device information can also be obtained by executing a specific instruction. For example, the device information of the CPU can be obtained by executing the lscpu command. The information of the motherboard and the like can also be viewed by executing the dmidecode command.

[0031] Step 102: Construct a device tree file according to the device information and a preset device tree syntax format.

[0032] The device tree file is a tree-shaped data structure for describing device information. In the embodiments of the present invention, the device tree is a data structure for providing hardware information and is the product of the idea of layering and separation of the kernel. The device tree is mainly used to describe the hardware information of the hardware devices deployed on the board.

[0033] The device tree can be a tree-shaped data structure. Each node in the device tree is a device node (devnode), and a node corresponds to a device object of a device driver and the device information of the device object. The device tree file can be deployed in the device for use. When the system kernel of the device starts, it can parse the information of each node in the device tree, and the parsed device information can be used to help the kernel boot and manage the corresponding device.

[0034] Among them, the device tree can have files corresponding to different stages in the device. The.DTS is the source code file of the device tree, and the.DTB is the binary executable file obtained after compiling the source code file of the device tree (i.e., the device tree file in step 102). According to the device information and the preset device tree syntax format, the embodiments of the present invention can first construct the source code file of the device tree, and then compile the source code file of the device tree to obtain the binary executable file of the device tree.

[0035] Specifically, the device tree syntax format defines that the device tree consists of a series of named nodes and the properties corresponding to the nodes. The properties of the nodes can include device information such as the name, type, and model of the device. In addition, there may be a subordination relationship between devices. In the embodiments of the present invention, this subordination relationship between devices can be converted into the relationship between the parent node and the child node in the device tree, so that the properties of each node can include the parent node information, that is, the parent node is used to represent the device to which the device corresponding to the node belongs. Through the parent node information, a tree-shaped device tree can be constructed.

[0036] For example, an Inter-Integrated Circuit (ICC) controller specifically includes an ICC1 device and an ICC2 device. The FT5206 (a capacitive touch screen control chip) is connected to the ICC1 device. Therefore, the ICC controller has a subordinate relationship with the ICC1 device and the ICC2 device (the ICC controller includes the ICC1 device and the ICC2 device), and the ICC1 device has a subordinate relationship with the FT5206 chip (the ICC1 device includes the FT5206 chip). Then, the ICC controller is the parent node device of the ICC1 device and the ICC2 device respectively, and the ICC1 device is the parent node device of the FT5206 chip.

[0037] Among them, the tree structure starts from the root node. The path of the root node is / , and the root node does not require a node name. All child nodes are attached to the root node. To append a child node to the root node, the following form can be used:

[0038] / {

[0039] / / Content to be added

[0040] };

[0041] To append a child node to a child node, the following form can be used:

[0042] &node-label{

[0043] / / Added content

[0044] };

[0045] The node-name field of a node specifies the name of the node. The length of the node-name field is 1 - 31 characters, and the naming should start with a lowercase or uppercase letter; the unit-address field represents the device address or the starting address of a register.

[0046] The attributes of a node consist of a name and an attribute value. The attribute value is an array composed of bytes, which contains information associated with the attribute. The compatible attribute in the attributes of a node is also called the compatibility attribute, which is in the form of a string list and is used to bind a device and a driver to define the compatibility of the device. The recommended format is manufacturer, model. The manufacturer describes the producer, and the model describes the model; the compatible attribute of the root node can be used to locate the device in use.

[0047] The phandle attribute value assigns a digital identifier to a unique node in the device tree, which is used to indicate the relationship for other nodes;

[0048] The status attribute value represents the operating status of the device;

[0049] Both the #address-cells and #size-cells attributes are unsigned 32-bit integer data and can be used in any device with child nodes, and describe how the child device nodes should be addressed. Among them, the #address-cells attribute defines the word length occupied by the address field in the reg attribute of the child node, that is, the number of u32 cells occupied. The #size-cells attribute defines the number of u32 cells occupied by the length of the reg attribute value of the child node.

[0050] Among them, the reg attribute value is used to describe the device address space resource information, generally the register address range information of a certain peripheral, including the start address and the address length.

[0051] Step 103: Construct a device operating environment and corresponding operating files for each device according to the device tree file, and run all the operating files in the device operating environment to obtain a running result.

[0052] In the embodiment of the present invention, the verification of the device tree is realized through a simulated device operating environment. The embodiment of the present invention does not use a physical board to verify the device tree, saving the process of repeatedly burning the board, thereby saving costs and improving efficiency.

[0053] Specifically, the embodiment of the present invention can use container technology as the basis of the simulated device operating environment. A container is a virtualization technology used to encapsulate an application program and all its dependencies and configurations so that it can run in different computer environments. Software containers provide a lightweight and consistent operating environment, making application programs more portable and reliable during development, testing, and deployment. Containers can be selected as virtual machines or docker containers. The embodiment of the present invention can parse the device information of the device from the device tree and pass the device information as a parameter to a preset container to establish dependencies and related configurations in the container, thereby obtaining a device operating environment. The device operating environment, as a simulated board operating environment, can run the binary executable file of the device.

[0054] Furthermore, based on the device information of the device parsed from the device tree, it can be further compiled in combination with the kernel file matching the device to obtain the running file of the device. The running file of the device can simulate the operation of the device. Thus, the embodiment of the present invention can run all the running files in the device operating environment, thereby realizing the process of simulating the board to run the board device and obtaining a running result.

[0055] Among them, the device operating environment first loads the operating file of the device into the memory, and then the device operating environment parses the format of the operating file (by parsing the file header of the operating file). After determining that the operating file is in an executable binary format, the device operating environment performs initialization configuration, including setting the hardware parameters of the device operating environment (such as virtual processor parameters, peripheral driver parameters, etc.), configuring the software environment (such as allocating process control blocks for the kernel of the device operating environment, runtime libraries, etc.). After the initialization configuration is completed, the device operating environment can execute the operating file. The virtual processor of the device operating environment executes the instructions in the operating file, that is, performs operations such as fetching, decoding, and executing in sequence to complete the execution of the operating file.

[0056] Step 104: Analyze according to the operation result to determine the verification result of the device tree file.

[0057] In the embodiment of the present invention, the operation result reflects the operation situation of the device on the simulated board. When no error occurs in the operation result, it indicates that the operation of the device is normal, and the verification of the device tree passes; when an error occurs in the operation result, it indicates that there may be a problem with the operation of the device, and the verification of the device tree fails.

[0058] In summary, in the embodiment of the present invention, the device information corresponding to each device can be obtained respectively; according to the device information and the preset device tree syntax format, a device tree file can be constructed; according to the device tree file, a device operating environment and an operating file corresponding to each device can be constructed, and all operating files are run in the device operating environment to obtain an operation result; according to the operation result, the verification result of the device tree file can be determined. The present invention can automatically generate a device tree according to the device information of the device, and perform rapid verification in the simulated operating environment, reducing the dependence on human resources, improving accuracy, and eliminating the need to burn the device tree into a physical board for verification, thereby improving the adaptation efficiency of hardware devices.

[0059] Figure 2 It is a flowchart of the steps of another device tree adaptation method provided by the embodiment of the present invention. Figure 2 Including:

[0060] Step 201: Obtain the device information corresponding to each device respectively.

[0061] This step can specifically refer to step 101 above and will not be elaborated here.

[0062] Step 202: Record the device information of the device in a preset text format file respectively.

[0063] In an embodiment of the present invention, the device information of a device can be persistently stored in a text format file (such as a txt or excel file), so that when performing the device tree adaptation method, the device information of the device can be obtained from the text format file. In addition, the content in the text format file can be conveniently modified, so that the configuration of the device information of the device can be conveniently implemented.

[0064] For example, as shown in Table 1 below, the device information of the CPU device is recorded in a text format file (specifically in a table form):

[0065]

[0066]

[0067] Table 1

[0068] Among them, Address-cells indicates how many cells are used to represent the address, and Size-cells indicates how many cells are used to represent the address length. In addition, the content in Table 1 can be selected, viewed, and modified through a drop-down menu.

[0069] In the related art, since the device information of devices from different manufacturers is different, many users do not know how to modify the corresponding attributes when using the device tree files of the manufacturers, resulting in a large number of incomplete configurations, incorrect configurations, or repeated configurations of certain attributes, so that the board cannot run normally and the development work cannot continue. In addition, modifying the attributes of the device tree requires the modifier to be familiar with the kernel source code, resulting in a relatively high learning cost.

[0070] Specifically, in an embodiment of the present invention, when it is necessary to configure and modify the device tree, the text format file can be conveniently configured and modified, and then the modified text format file is used to automatically generate the device tree again, so as to achieve the purpose of configuring and modifying the content in the device tree. Due to the intuitive display of the content and the convenient editing of the text format file, the configuration and modification process is simpler and more intuitive, improving the accuracy of the configuration and reducing the learning cost.

[0071] For example, assume that under the Windows operating system, by entering the command: msinfo32, the device information of the hardware devices deployed in the computer is read. For the CPU hardware device, the main frequency read is 1.8 GHz, but the main frequency of this CPU recorded in the text format file is 2.4 GHz. This deviation will cause an error in the main frequency inconsistency in the subsequent operation of the device tree. Therefore, in an embodiment of the present invention, the main frequency of the CPU hardware device in the text format file can be corrected from 2.4 GHz to 1.8 GHz.

[0072] Step 203: Generate a device tree file according to the text format file and the preset device tree syntax format.

[0073] In the embodiment of the present invention, the device tree syntax format defines that the device tree consists of a series of named nodes and the attributes corresponding to the nodes. The attributes of the nodes may include device information such as the name, type, and model of the device. The attributes of the nodes can be specifically filled with the device information recorded in the text format file. In addition, there may be a belonging relationship between various devices. In the embodiment of the present invention, this belonging relationship between devices can be converted into the relationship between the parent node and the child node in the device tree, so that the attributes of each node can include the parent node information, that is, the parent node is used to represent the device to which the device corresponding to the node belongs. Through the parent node information, a syntax tree with a tree structure can be constructed.

[0074] For example, assume that the belonging relationship between devices such as the ICC controller, ICC1 device, ICC2 device, and FT5206 chip is: the ICC controller includes the ICC1 device and the ICC2 device, and the ICC1 device includes the FT5206 chip. Then the ICC controller is the parent node device of the ICC1 device and the ICC2 device, and the ICC1 device is the parent node device of the FT5206 chip. For the nodes corresponding to the ICC1 device and the ICC2 device respectively, it is recorded that parentNode (parent node attribute, used to indicate the parent node of the current node) = ICC controller; for the node corresponding to the FT5206 chip, it is recorded that parentNode = ICC1.

[0075] Optionally, the method further includes: Step A1: Display the device information recorded in the text format file in a visual interface, and in response to a given configuration operation, perform one or more of the following operations: adding the device information of a new device to the text format file, deleting the device information of a target device from the text format file, and modifying the device information of the target device in the text format file.

[0076] In an embodiment of the present invention, the text format file can be displayed in the visualization interface of the device. After the user opens the text format file, the user can view the device information of the device recorded in the text format file and manually configure the information recorded therein, including but not limited to adding the device information of a new device to the text format file, deleting the device information of a target device in the text format file, and modifying the device information of the target device in the text format file. The embodiment of the present invention can use the configured text format file to automatically generate a device tree again to achieve the purpose of configuring and modifying the content in the device tree. Due to the intuitiveness of the content display of the text format file and the convenience of content editing, the configuration and modification processes are simpler and more intuitive, improving the accuracy of configuration and reducing the learning cost.

[0077] Step 204: Use the device information of the target device read from the device tree file as an incoming parameter, and the incoming parameter has a format matching that of the device tree file.

[0078] Step 205: Pass the incoming parameter into a preset container to obtain the device running environment.

[0079] In an embodiment of the present invention, for steps 204-205, based on the above embodiment, it can be known that the data in the device tree has a corresponding format, that is, one function of the device tree is to process and store the original device information of each device in a unified format, realizing the standardized processing of the device information, so that the device running environment and running files can be constructed according to the standardized data processing requirements subsequently.

[0080] After constructing the device tree file according to the device tree syntax format, subsequent traversal can be performed sequentially from the root node of the device tree file downward to achieve traversal of each node in the device tree file. Traversing to a node is equivalent to obtaining the device information of the device corresponding to the node (the device information has a format matching that of the device tree file). The device information traversed can be used as an incoming parameter and passed into a preset container to establish dependencies and related configurations in the container, thereby obtaining the device running environment. The device running environment, as a simulated board running environment, can run the binary executable file of the device.

[0081] Among them, simulating and constructing the device operating environment based on device information is a systematic process that requires the comprehensive configuration of hardware, software, network, and peripherals, including: after obtaining the device information of the device, first simulate the device operating environment through virtualization technology, that is, construct virtualization containers (virtual machines, Docker containers, cloud services, etc.) as the basis of the device operating environment. Then, according to the device information of the device, establish the operating system and software environment in the device operating environment, that is, specify the operating system compatible with the device information and modify the kernel parameters according to the device information to simulate specific kernel behaviors, and perform dependency management, that is, the dependency libraries of the version compatible with the device information. Then perform operations such as network environment configuration and peripheral configuration, and thus obtain a device operating environment.

[0082] Now, an example is used to illustrate how to obtain the device information of a device and how to build a device operating environment based on the obtained device information:

[0083] For example, in the case where the device tree includes an I2C (Inter-Integrated Circuit, a serial communication bus) controller, the following request function can be used to read the relevant information of the I2C device from the device tree:

[0084]

[0085] The relevant information of the I2C device obtained after reading can be constructed as parameters and passed into the container to build the device operating environment. These parameters include:

[0086] -device virtio-i2c-device,bus= / dev / i2c-0,addr=0x50

[0087] -device my-i2c-device,i2c-bus=i2c-0,i2c-addr=0x50

[0088] In the above example, -device virtio-i2c-device,bus= / dev / i2c-0,addr=0x50 is the I2C controller device. Among them, bus= / dev / i2c-0 specifies the name of the bus to which the I2C controller device is connected, and addr=0x50 is the device address of the I2C controller device.

[0089] -device my-i2c-device, i2c-bus = i2c-0, i2c-addr = 0x50 is the ic2 device to be simulated. my-i2c-device is the device name and needs to be replaced with the actual ic2 device model. i2c-bus = i2c-0 specifies the bus to which the ic2 device is connected, and i2c-addr = 0x50 is the device address of the ic2 device.

[0090] Step 206, identify the device information and device type of the target device read from the device tree file; each of the device types is respectively associated with its corresponding compilation method.

[0091] Step 207, compile the device information of the target device respectively according to the compilation method, obtain the running files of the device, and run all the running files in the device running environment to obtain the running result.

[0092] In the embodiment of the present invention, for steps 206 - 207, for devices deployed in different hardware environments, their corresponding compilation methods are also different. For example, for devices deployed in the Windows system environment, the running files of the device need to be generated according to the Windows compilation method. For devices deployed in the Linux environment, the running files of the device need to be generated according to the Linux compilation method.

[0093] Since the compilation method corresponding to the device is associated with the device type of the device, it is possible to find the compilation method matching the current device based on the preset correspondence between the device type and the compilation method, and compile the device information of the device according to the compilation method matching the current device to obtain the running files of the device, and run all the running files in the device running environment, so as to realize the process of simulating the board to run the board device and obtain the running result.

[0094] First, it is necessary to find the compilation method corresponding to the device according to the device type of the device. Specifically, the device type of the device reflects the development environment of the device (such as, processor architecture, operating system support, etc.). Different device types have different compilation methods, which can ensure that the generated code is compatible with the running environment. For example, for a device developed based on the ARM architecture, its corresponding compilation method can be a cross-compilation toolchain under the ARM architecture; for a device developed based on the X86 architecture, its corresponding compilation method can be GCC (GNU Compiler Collection) or Clang under the X86 architecture.

[0095] After that, a compilation tool matching the device type of the device can be configured and compilation can be started. During the compilation process, the compilation tool can integrate the device information into the code, that is, embed the device information into the compilation project in the form of code or a configuration file. Finally, after using the compiler and linker to execute the compilation command and the linking command (using a link script to merge the code, data, and startup file into an executable file), a binary executable file is generated.

[0096] Optionally, step 207 may specifically include:

[0097] Sub-step 2071: Obtain a kernel file matching the device type; the kernel file is used to provide the programs required by the system kernel.

[0098] Sub-step 2072: Perform overall compilation on the kernel file matching the device type and the device information of each target device to obtain the running file of each device.

[0099] In the embodiment of the present invention, for sub-steps 2071-2072, the device information of the device is compiled according to the matching compilation method. Specifically, a kernel file capable of providing the compilation method corresponding to the device can be obtained, and the kernel file matching the device type and the device information of the device are compiled as a whole to obtain the running file of the device. For example, for a device deployed in a Windows system environment, the running file of the device needs to be generated according to the Windows compilation method, and the required kernel file can be a Windows kernel file. For a device deployed in a Linux environment, the running file of the device needs to be generated according to the Linux compilation method, and the required kernel file can be a Linux kernel file.

[0100] For example, device a has a corresponding kernel file a1; device b has a corresponding kernel file b1.

[0101] By performing overall compilation on the device information of device a and the kernel file a1, the running file of device a can be obtained.

[0102] By performing overall compilation on the device information of device b and the kernel file b1, the running file of device b can be obtained.

[0103] The following shows some attribute information of a node in the device tree:

[0104]

[0105]

[0106] In the process of determining the compilation method matching the device, first, the compatible field in the attributes of the node corresponding to the device in the device tree can be scanned. This field is the field reflecting the device type of the device. Then, it can be compared with the fields of the Makefiles (describing the compilation rules of the entire project) of each different pre-set kernel file. If the two fields are exactly the same, it is determined that the kernel file with the consistent fields is the kernel file matching the device type of the current device. Subsequently, the kernel file and the device information of the device can be compiled as a whole to obtain the running file of the device.

[0107] Step 208, analyze according to the running result to determine the verification result of the device tree file.

[0108] This step can specifically refer to step 104 above and will not be elaborated here.

[0109] Optionally, step 208 can specifically include:

[0110] Sub-step 2081, when there is an error in the running result, determine that the verification result of the device tree file fails.

[0111] Sub-step 2082, when there is no error in the running result, determine that the verification result of the device tree file passes.

[0112] In the embodiment of the present invention, when there is an error in the running result, it indicates that at least some devices in the device tree have abnormal operation. In order to avoid subsequent deployment of the faulty device tree on the board card resulting in actual board card operation errors, it can be determined that the verification result of the device tree file fails. The developer needs to extract and analyze the corresponding abnormal information in the verification result, determine the device with the abnormality, and then re-debug and configure the device tree to try to correct the error.

[0113] For example, the possible errors in the running result may include: xx device parameter error, xx device missing parameter, missing xx device, etc.

[0114] When there is no error in the running result, it indicates that all devices in the device tree are operating normally, so it can be determined that the verification result of the device tree file passes. Subsequently, the device tree file can be burned into the board card for operation. When the system kernel of the device starts, it can parse the information of each node in the device tree, and the parsed device information can be used to help the kernel boot and manage the corresponding device.

[0115] Optionally, the method may further include:

[0116] Step 209. When it is determined that the verification result of the device tree file fails, correct the device information of the device and proceed to Step 203.

[0117] Step 210. When it is determined that the verification result of the device tree file passes, burn the device tree file to the board for operation.

[0118] In the embodiment of the present invention, for Steps 209-210, when it is determined that the verification result of the device tree file fails, it indicates that there are related defects in the device tree, which need to be corrected by the developer. At this time, the developer can conveniently configure and modify the text format file that records the device information of the device, and then proceed to Step 203, and use the modified text format file to automatically generate the device tree again to achieve the purpose of configuring and modifying the content in the device tree. Due to the intuitive display of the content and the convenient editing of the text format file, the configuration and modification process is simpler and more intuitive, improving the accuracy of the configuration and reducing the learning cost.

[0119] In addition, when there is no error in the operation result, it indicates that the verification result of the device tree file passes. At this time, the operation of the devices in the device tree is normal, and the device tree file and the kernel file (the kernel file matching the device type of the device in the device tree) can be burned to the board for operation. The system kernel of the device can parse the information of each node in the device tree at startup, and the parsed device information can be used to help the kernel boot and manage the corresponding device.

[0120] Refer to Figure 3 , the embodiment of the present invention provides a flowchart of the adaptation process of a device tree, including:

[0121] S1. Obtain the device information of the device.

[0122] S2. Generate a device tree file.

[0123] S3. Generate a device operating environment.

[0124] S4. Generate a running file corresponding to each device.

[0125] S5. Run the running file in the device operating environment.

[0126] S6. Determine whether the operation is normal.

[0127] If it is normal, end the process; if it is abnormal, the verification fails.

[0128] In summary, in the embodiments of the present invention, the device information corresponding to each device can be obtained respectively; according to the device information and the preset device tree syntax format, a device tree file is constructed; according to the device tree file, a device running environment and a running file corresponding to each device are constructed, and all the running files are run in the device running environment to obtain a running result; according to the running result, the verification result of the device tree file is determined. The present invention can automatically generate a device tree based on the device information of the device, and perform quick verification in a simulated running environment, reducing the dependence on human resources, improving the accuracy, and eliminating the need to burn the device tree into a physical board for verification, thereby improving the adaptation efficiency of the hardware device.

[0129] Figure 4 is a block diagram of an adaptation device for a device tree provided by an embodiment of the present invention. As Figure 4 shown, the device includes:

[0130] An obtaining module 301, configured to obtain the device information corresponding to each device respectively;

[0131] A constructing module 302, configured to construct a device tree file according to the device information and the preset device tree syntax format; the device tree file is a tree-shaped data structure describing the device information;

[0132] A running module 303, configured to construct a device running environment and a running file corresponding to each device according to the device tree file, and run all the running files in the device running environment to obtain a running result;

[0133] A verifying module 304, configured to analyze according to the running result to determine the verification result of the device tree file.

[0134] Optionally, the running module 303 includes:

[0135] A parameter passing sub-module, configured to use the device information of the target device read from the device tree file as a passed-in parameter, and the passed-in parameter has a format matching the device tree file;

[0136] A container sub-module, configured to pass the passed-in parameter into a preset container to obtain the device running environment.

[0137] Optionally, the running module 303 includes:

[0138] An identification sub-module, configured to identify the device information and device type of the target device read from the device tree file; each device type is respectively associated with a corresponding compilation method;

[0139] A compilation sub-module, configured to compile the device information of the target device respectively according to the compilation method to obtain the running file of the device.

[0140] Optionally, each device type is associated with a corresponding kernel file; the compilation sub-module includes:

[0141] An acquisition unit, configured to acquire a kernel file that matches the device type; the kernel file is used to provide programs required by the system kernel.

[0142] A compilation unit, configured to perform overall compilation on the kernel file that matches the device type and the device information of each target device to obtain the running file of each device.

[0143] Optionally, the device further includes:

[0144] A recording module, configured to record the device information of the device in a preset text format file respectively.

[0145] The building module 302 includes:

[0146] A building sub-module, configured to generate a device tree file according to the text format file and a preset device tree syntax format.

[0147] The device further includes:

[0148] A modification module, configured to display the device information recorded in the text format file in a visual interface, and in response to a predefined configuration operation, perform one or more operations of: adding the device information of a new device to the text format file, deleting the device information of a target device from the text format file, and modifying the device information of a target device in the text format file.

[0149] Optionally, the verification module 304 includes:

[0150] A first verification sub-module, configured to determine that the verification result of the device tree file fails when there is an error in the running result.

[0151] A second verification sub-module, configured to determine that the verification result of the device tree file passes when there is no error in the running result.

[0152] Optionally, the device further includes:

[0153] A first processing module, configured to correct the device information of the device when the verification result fails, and enter the step of building a device tree file according to the device information and a preset device tree syntax format.

[0154] A second processing module, configured to burn the device tree file to a board for operation when it is determined that the verification result of the device tree file is passed.

[0155] In summary, in the embodiments of the present invention, device information corresponding to each device can be obtained respectively; a device tree file can be constructed according to the device information and a preset device tree syntax format; a device operating environment and a running file corresponding to each device can be constructed according to the device tree file, and all running files are run in the device operating environment to obtain a running result; and the verification result of the device tree file can be determined according to the running result. The present invention can automatically generate a device tree according to the device information of the device, and perform quick verification in a simulated running environment, reducing the dependence on human resources, improving accuracy, and eliminating the need to burn the device tree to a physical board for verification, thereby improving the adaptation efficiency of the hardware device.

[0156] The device tree adaptation device in the embodiments of the present invention can be a device, or a component, an integrated circuit, or a chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. Exemplarily, the mobile electronic device can be a mobile phone, a tablet computer, a laptop computer, a handheld computer, a vehicle-mounted electronic device, a wearable device, an ultra-mobile personal computer (UMPC), a netbook, or a personal digital assistant (PDA), etc., and the non-mobile electronic device can be a server, a network attached storage (NAS), a personal computer (PC), a television (TV), a teller machine, or a self-service machine, etc. The embodiments of the present invention do not make specific limitations.

[0157] The device tree adaptation device in the embodiments of the present invention can be a device with an operating system. The operating system can be an Android operating system, an iOS operating system, or other possible operating systems. The embodiments of the present invention do not make specific limitations.

[0158] The device tree adaptation device provided in the embodiments of the present invention can implement each process implemented by the device tree adaptation device in the method embodiments. To avoid repetition, it will not be elaborated here.

[0159] Optionally, the embodiments of the present invention further provide an electronic device, including a processor, a memory, a program or instruction stored on the memory and executable on the processor, where when the program or instruction is executed by the processor, it implements each process of the above-mentioned device tree adaptation method embodiments and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.

[0160] It should be noted that the electronic devices in the embodiments of the present invention include the above-mentioned mobile electronic devices and non-mobile electronic devices.

[0161] Figure 5 FIG. is a schematic diagram of the hardware structure of an electronic device according to an embodiment of the present invention.

[0162] The electronic device 1300 includes, but is not limited to: a radio frequency unit 1301, a network module 1302, an audio output unit 1303, an input unit 1304, a sensor 1305, a display unit 1306, a user input unit 1307, an interface unit 1308, a memory 1309, and a processor 1310 and other components.

[0163] Those skilled in the art can understand that the electronic device 1300 may further include a power supply (such as a battery) for supplying power to each component. The power supply can be logically connected to the processor 1310 through a power management system, so as to implement functions such as management of charging, discharging, and power consumption management through the power management system. Figure 5 The structure of the electronic device shown in does not limit the electronic device. The electronic device may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements, which will not be elaborated here.

[0164] It should be understood that in the embodiments of the present invention, the input unit 1304 may include a graphics processing unit (GPU) 13041 and a microphone 13042. The graphics processing unit 13041 processes the image data of static pictures or videos obtained by an image capture device (such as a camera) in a video capture mode or an image capture mode. The display unit 1306 may include a display panel 13061, and the display panel 13061 may be configured in the form of a liquid crystal display, an organic light-emitting diode, etc. The user input unit 1307 includes at least one of a touch panel 13071 and other input devices 13072. The touch panel 13071 is also called a touch screen. The touch panel 13071 may include two parts: a touch detection device and a touch controller. The other input devices 13072 may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and a joystick, which will not be elaborated here.

[0165] The memory 1309 can be used to store software programs and various data. The memory 1309 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data. Among them, the first storage area may store an operating system, application programs or instructions required for at least one function (such as a sound playback function, an image playback function, etc.). In addition, the memory 1309 may include a volatile memory or a non-volatile memory, or the memory 1309 may include both a volatile and a non-volatile memory. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDR SDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synch link dynamic random access memory (SLDRAM), and a direct rambus random access memory (DRRAM). The memory 1309 in the embodiments of the present invention includes but is not limited to these and any other suitable types of memories.

[0166] The processor 1310 may include one or more processing units; optionally, the processor 1310 integrates an application processor and a modem processor. Among them, the application processor mainly processes operations related to the operating system, user interface, and application programs, etc., and the modem processor mainly processes wireless communication signals, such as a baseband processor. It can be understood that the above-mentioned modem processor may not be integrated into the processor 1310 either.

[0167] The embodiments of the present invention also provide a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, it implements each process of the embodiment of the method for adapting the device tree as described above, and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.

[0168] The embodiments of the present invention have been described above in conjunction with the accompanying drawings. However, the present invention is not limited to the above specific embodiments. The above specific embodiments are merely illustrative rather than restrictive. Under the inspiration of the present invention, those of ordinary skill in the art can also make many forms without departing from the spirit of the present invention and the scope protected by the claims, and all of them fall within the protection scope of the present invention.

Claims

1. A device tree adaptation method, characterized in that: Methods include: Get the device information corresponding to each device respectively; Constructing a device tree file according to the device information and a preset device tree syntax format; The device tree file is a tree data structure that describes device information; According to the device tree file, a device operating environment and an operating file corresponding to each of the devices are constructed, and all the operating files are run in the device operating environment to obtain an operating result; An analysis is performed based on the running result to determine a verification result of the device tree file.

2. The method according to claim 1, characterized in that: The step of constructing a device operating environment according to the device tree file includes: Using device information of the target device read from the device tree file as an input parameter, wherein the input parameter has a format matching the device tree file; The input parameters are passed into a preset container to obtain the device operating environment.

3. The method according to claim 1, characterized in that The step of constructing operation files corresponding to the devices according to the device tree file includes: Identify the device information and device type of the target device read from the device tree file; each of the device types is associated with a corresponding compilation method; According to the compilation method, the device information of the target device is compiled respectively to obtain the operation file of the device.

4. The method according to claim 3, characterized in that Each of the device types is associated with a corresponding kernel file; Then, the device information of the target device is compiled according to the compilation method to obtain the operation file of the device, including: Obtain a kernel file that matches the device type; The kernel file matching the device type and the device information of each target device are compiled as a whole to obtain the running file of each device.

5. The method according to claim 1, characterized in that After respectively acquiring device information corresponding to each device, the method further includes: Recording the device information in preset text format files respectively; Then, the device tree file is constructed according to the device information and the preset device tree syntax format, including: Generate a device tree file according to the text format file and a preset device tree syntax format; The method further comprises: The device information is displayed in a visual interface and responds to predetermined configuration operations.

6. The method according to claim 1, characterized in that The method further comprises: When the verification result is failure, the device information of the device is corrected, and the step of constructing a device tree file according to the device information and a preset device tree syntax format is entered.

7. A device tree adaptation device, characterized in that: include: An acquisition module, used to respectively acquire device information corresponding to each device; A construction module, used to construct a device tree file according to the device information and a preset device tree syntax format; the device tree file is a tree data structure representing the device information of the device; An operation module, used to construct a device operation environment and an operation file corresponding to each of the devices according to the device tree file, and to run all the operation files in the device operation environment to obtain an operation result; The verification module is used to analyze the operation result and determine the verification result of the device tree file.

8. An electronic device, characterized in that: The device comprises a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps of the device tree adaptation method as described in any one of claims 1 to 6.

9. A readable storage medium, characterized in that: The readable storage medium stores a program or an instruction, and when the program or the instruction is executed by the processor, the steps of the device tree adaptation method according to any one of claims 1 to 6 are implemented.

Citation Information

Cited By

  • Automatic management method, device and equipment of switch equipment tree and storage medium

    CN121691004A