《设备树 — dtb到device node的转换(三)》

1.内核中对一个设备节点的表示

struct device_node {
	const char *name;                    //节点的名字
	const char *type;                    //device_type属性的值
	phandle phandle;                     //对应该节点的phandle属性 
	const char *full_name;               //节点的名字, node-name[@unit-address]从“/”开始的,表示该node的full path 
	struct fwnode_handle fwnode;
 
	struct	property *properties;        // 节点的属性
	struct	property *deadprops;	/* removed properties 如果需要删除某些属性,kernel并非真的删除,而是挂入到deadprops的列表 */
	struct	device_node *parent;         // 节点的父亲
	struct	device_node *child;          // 节点的孩子(子节点)
	struct	device_node *sibling;        // 节点的兄弟(同级节点)
#if defined(CONFIG_OF_KOBJ)              // 在sys文件系统表示
	struct	kobject kobj;        
#endif
	unsigned long _flags;
	void	*data;
#if defined(CONFIG_SPARC)
	const char *path_component_name;
	unsigned int unique_id;
	struct of_irq_controller *irq_trans;
#endif
};

  从这里我们就可以看到一个设备节点的大概组织形式了。通过下面这三个组织成一个树形结构。

struct	device_node *parent;         // 节点的父亲
struct	device_node *child;          // 节点的孩子(子节点)
struct	device_node *sibling;        // 节点的兄弟(同级节点)

  device_node结构体中有properties, 用来表示该节点的属性

struct property {
	char	*name;                //属性名字
	int	length;                   //value的长度
	void	*value;               //属性值
	struct property *next;        //指向统一节点的下一个属性
#if defined(CONFIG_OF_DYNAMIC) || defined(CONFIG_SPARC)
	unsigned long _flags;
#endif
#if defined(CONFIG_OF_PROMTREE)
	unsigned int unique_id;
#endif
#if defined(CONFIG_OF_KOBJ)
	struct bin_attribute attr;
#endif
};

  

2.举例说明

/dts-v1/;
/memreserve/ 0x4ff00000 0x100000;
/ {
    model = "YIC System SMDKV210 based on S5PV210";
    compatible = "yic,smdkv210", "samsung,s5pv210";
 
    #address-cells = <1>;
    #size-cells = <1>;
        
    chosen {
        bootargs = "console=ttySAC2,115200n8 root=/dev/nfs nfsroot=192.168.0.101:/home/run/work/rootfs/";
    };  
 
    memory@30000000 {
        device_type = "memory";
        reg = <0x30000000 0x20000000>;
    };  
};

  下图表示上面的根节点和其里面的两个子节点。

   接下来向里面填充属性值

  首先是把根节点里的4个属性进行填充

  在添加上其它两个节点的属性后如下。

原文地址:https://www.cnblogs.com/zhuangquan/p/12876243.html