如何在设备树中读取子节点属性 [英] How to read child node property in a device tree

查看:324
本文介绍了如何在设备树中读取子节点属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试读取设备树中的子节点属性. 无法弄清楚,这里有谁可以帮忙.

I been trying to read child node property in a device tree.. Could not figured it out, can any one help here.

我有一个dts

  AA{
    child 1: {
                property 1 : XXX
                property 2 : XXX
       }
   child 2 :{
                property 1 : XXX
                property 2 : XXX
       }

 BB{
    child 1: {
                property 1 : XXX
                property 2 : XXX
       }
   child 2 :{
                property 1 : XXX
                property 2 : XXX
       }

在给定dts的AA节点中,有什么方法可以读取子代2的属性吗?

Is there any way of reading properies of child 2 in AA node of given dts ?

推荐答案

是的,您可以这样做.只需编写如下类似的函数,并在AA中使用BB子节点的路径调用它.

Yes, you can do it. Just write a similar function as below and call it in AA with the path of the child node of BB.

例如,如果需要访问BB/child_2属性,则从AA中获取绝对路径,然后将绝对路径传递给of_find_node_by_path()函数.

For example, From AA if you need to access BB/child_2 property then pass the absolute path to of_find_node_by_path() function.

还要检查内核中可能有用的of_ *函数族.

Also, check of_* family of function in the kernel that might be useful.

static void access_dt(void)                                                      
{                                                                                
    /* device node path - check it from /proc/device-tree/ */                    
    char *path = "/path/to/BB/child_2";                                            
    struct device_node *dt_node;                                                 
    const u8 *prop = NULL;                                                       
    int ret;                                                                     

    dt_node = of_find_node_by_path(path);                                        
    if (!dt_node) {                                                              
        printk(KERN_ERR "Failed to find node by path: %s.\n");                   
    } else {                                                                     
        printk(KERN_INFO "Found the node for %s.\n", path);                      
        prop = of_get_property(dt_node, "property 2", &ret);                      
        if(!prop) {
             //You are still in trouble!
        } else {
            //You have got property 2 of BB!
        }                                                                        
    }                                                                            
}

这篇关于如何在设备树中读取子节点属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆