#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/of.h>
//设备节点类型
static struct device_node *devnode;
//节点属性类型
static struct property *prop;
static int len = 0;
static u32 value[2];
static const char *str;
static int __init test_init(void)
{
int ret = 0;
printk("test_init.....\n");
//根据节点路径寻找节点函数
devnode = of_find_node_by_path("/test1");
if (NULL == devnode)
{
printk("of_find_node_by_path failed....\n");
return 1;
}
printk("name: %s full_name: %s\n", devnode->name, devnode->full_name);
//获取节点属性
prop = of_find_property(devnode, "compatible", &len);
if (NULL == prop)
{
printk("of_find_property failed....\n");
return 1;
}
printk("property name: %s value: %s\n", prop->name, (char *)prop->value);
//获取reg的值
ret = of_property_read_u32_array(devnode, "reg", value, 2);
if (ret < 0)
{
printk("of_property_read_u32_array failed...\n");
return 1;
}
printk("value[0]: 0x%8x value[1]: 0x%8x\n", value[0], value[1]);
//获取status属性值
ret = of_property_read_string(devnode, "status", &str);
if (ret < 0)
{
printk("of_property_read_string failed....\n");
return 1;
}
printk("status = %s\n", str);
return 0;
}
static void __exit test_exit(void)
{
printk("test_exit......\n");
}
module_init(test_init);
module_exit(test_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Jin.Deng");
MODULE_INFO(intree, "Y");
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Linux3.x以后的版本才引入了设备树,设备树用于描述一个硬件平台的板级细节。 在早些的linux内核,这些“硬件平台的板级细节”保存在linux内核目录“/arch”, 以ARM平台为例“硬件平台的板级细节”保存在“/arch/arm/plat-xxx”和“/arch/arm/mach-xxx”目录下。 随着处理器数量的增多用于描述“硬件平台板级细节”的文件越来越多导致Linux内核非常臃肿, Linux之父发现这个问题之后决定使用设备树解决这个问题。设备树简单、易用、可重用性强, linux3.x之后大多采用设备树编写驱动。 ———————————————— 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 原文链接:https://blog.csdn.net/dengjin20104042056/article/details/134435020
资源推荐
资源详情
资源评论
收起资源包目录
4of_property_read_string.rar (2个子文件)
4of_property_read_string
test.c 2KB
Makefile 201B
共 2 条
- 1
资源评论
沧海一笑-dj
- 粉丝: 3w+
- 资源: 338
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功