In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to create Linux kernel Device Tree". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to create Linux kernel Device Tree.
When the Linux kernel starts, the kernel creates the device node in dts as platform device through the of_platform_populate () function. Prepare for platform driver matching of follow-up and various drivers.
The of_platform_populate () function is implemented in the file drivers/of/platform.c. The following is based on the RockPI 4A veneer kernel code to introduce its call process and implementation process.
I. the process of function call
In the Linux kernel, you can use the dump_stack () function to view the call flow of the function.
/ * of_platform_populate ()-Populate platform_devices from device tree data... # omit some comments * / int of_platform_populate (struct device_node * root, const struct of_device_id * matches, const struct of_dev_auxdata * lookup, struct device * parent) {struct device_node * child; int rc = 0; dump_stack (); # print stack information of function calls / / 1. If root is NULL, look for root = root? through of_find_node_by_path (). Of_node_get (root): of_find_node_by_path ("/"); if (! root) return-EINVAL; / / 2. Traverse the node for_each_child_of_node (root, child) {/ / 3 in dts. Create platform device rc = of_platform_bus_create (child, matches, lookup, parent, true) for each node and child node;...} EXPORT_SYMBOL_GPL (of_platform_populate)
The dump_stack () stack information is as follows:
[0.311191] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.4.154-00036-gcef30e88a9f5-dirty # 36 [0.311198] Hardware name: ROCK PI 4A 2 (DT) [0.311206] Call trace: [0.311220] [] dump_backtrace+0x0/0x220 [0.311232] [] show_stack+0x24/0x30 [0.311244] [] dump_stack+0x98/0xc0 [0.311258] [] of_platform_populate+0x30 / 0xb8 [0.311268] [] arm64_device_init+0x30/0x4c [0.311278] [] do_one_initcall+0x18c/0x194 [0.311290] [] kernel_init_freeable+0x228/0x22c [0.311301] [] kernel_init+0x18/0x100 [0.311311] [] ret_from_fork+0x10/0x20
From the stack information, you can see that the call to the of_platform_populate () function is implemented in the arm64_device_init () function. Following the introduction of the kernel_init () function, leave a moment to think about it.
Note:
The arm64_device_init () function is implemented in the arch/arm64/kernel/setup.c file. At this point, the serial driver has not been loaded and the serial log is saved in the buffer. Because RK3399 is multicore, stack information or other logs may be lost when the Linux kernel starts. When the system starts, you can increase the nosmp configuration, turn off the loading of other CPU, and ensure as much log output as possible. At the end of the configuration file / boot/extlinux/extlinux.conf, add:
Label kernel-debug kernel / debug/Image fdt / debug/rk3399-rock-pi-4a.dtb append earlyprintk console=ttyFIQ0,1500000n8 init=/sbin/init root=PARTUUID=b921b045-1D rw rootwait rootfstype=ext4 nosmp II, function realization process
The of_platform_populate () function creates the platform device mainly through the of_platform_bus_create () function. In order to understand the implementation process, some debugging logs are added through printk. The code is as follows:
/ * of_platform_bus_create ()-Create a device for a node and its children. * @ bus: device node of the bus to instantiate * @ matches: match table for bus nodes * @ lookup: auxdata table for matching id and platform_data with device nodes * @ parent: parent for new device, or NULL for top level. * @ strict: require compatible property * Creates a platform_device for the provided device_node, and optionally * recursively create devices for all the child nodes. * / static int of_platform_bus_create (struct device_node * bus, const struct of_device_id * matches, const struct of_dev_auxdata * lookup, struct device * parent, bool strict) {. Printk (KERN_ERR "--name% s\ n", bus- > name); / / 1. To determine whether there is a compatible attribute, return / * Make sure it has a compatible property * / if (strict & & (! of_get_property (bus, "compatible", NULL)) {printk (KERN_ERR "-% s ()-skipping% s, no compatible prop\ n", _ _ func__, bus- > full_name); return 0;}. / / 2. Create platform device dev = of_platform_device_create_pdata (bus, bus_id, platform_data, parent); if (! dev | |! of_match_node (matches, bus)) {printk (KERN_ERR "--no match node\ n"); return 0;} / / 3. Traverse the child nodes. If present, create platform device for_each_child_of_node (bus, child) {printk (KERN_ERR "--create child:% s\ n", child- > full_name); rc = of_platform_bus_create (child, matches, lookup, & dev- > dev, strict); if (rc) {of_node_put (child); break }} of_node_set_flag (bus, OF_POPULATED_BUS); return rc;}
After updating the kernel image, part of the kernel startup log is intercepted, as follows:
[0.326151]-name syscon [0.326311]-create child: / syscon@ff770000/io-domains [0.326318]-name io-domains [0.326458]-no match node [0.326466]-create child: / syscon@ff770000/usb2-phy@e450 [0.326472]-name usb2-phy [0.326627]-- no match Node [0.326635]-create child: / syscon@ff770000/usb2-phy@e460 [0.326641]-name usb2-phy [0.326791]-no match node [0.326798]-- create child: / syscon@ff770000/phy@f780 [0.326804]-name phy [0.326958]-no match node [0.326965]-- create Child: / syscon@ff770000/mipi-dphy-rx0 [0.326972]-name mipi-dphy-rx0 [0.327113]-no match node [0.327120]-create child: / syscon@ff770000/pvtm [0.327126]-name pvtm [0.327291]-no match node... # # omitting part of log [0.330604]-name display-subsystem # # drm [0.330742]-no match node...
The node name bus- > name and child node name child- > full_name in the above log can be found in the arch/arm64/boot/dts/rockchip/rk3399.dtsi file:
Grf: syscon@ff770000 {# # syscon corresponding node name compatible = "rockchip,rk3399-grf", "syscon", "simple-mfd"; reg =; # address-cells =; # size-cells =; io_domains: io-domains {compatible = "rockchip,rk3399-io-voltage-domain"; status = "disabled";} U2phy0: usb2-phy@e450 {# # usb2-phy@e450 corresponding node name compatible = "rockchip,rk3399-usb2phy"; reg =; clocks =; clock-names = "phyclk"; # clock-cells =; clock-output-names = "clk_usbphy0_480m"; status = "disabled" ...}}... Display_subsystem: display-subsystem {# # display-subsystem corresponds to node name compatible = "rockchip,display-subsystem"; ports =,; clocks =,; clock-names = "hdmi-tmds-pll", "default-vop-pll"; devfreq =; status = "disabled";}
After the system boots, you can view the dts file node under the / sys/firmware/devicetree/base path and the platform device under the / sys/devices/platform path.
Root@linaro-alip:/sys/firmware/devicetree/base# ls syscon@ff770000/#address-cells compatible mipi-dphy-rx0 phandle pvtm usb2-phy@e450#size-cells io-domains name phy@f780 reg usb2-phy@e460root@linaro-alip:/sys/firmware/devicetree/base# ls display-subsystem/clock-names compatible logo-memory-region phandle routeclocks devfreq name ports statusroot@linaro-alip:/sys/firmware/ Devicetree/base#root@linaro-alip:/sys/devices/platform# ls ff770000.syscon/driver_override ff770000.syscon:usb2-phy@e460/ff770000.syscon:io-domains/ modaliasff770000.syscon:mipi-dphy-rx0/ of_node/ff770000.syscon:phy@f780/ power/ff770000.syscon:pvtm/ subsystem/ff770000.syscon:usb2-phy@e450/ ueventroot@linaro-alip:/sys/devices/platform# ls display-subsystem/ Driver drm modalias power ueventdriver_override graphics of_node subsyste, thank you for your reading. The above is the content of "how to create Linux kernel Device Tree". After the study of this article, I believe you have a deeper understanding of how to create Linux kernel Device Tree, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.