• 华清远见上海中心22071班


    #include

    #include

    #include

    /*mynode@0x12345678{

        compatible = "hqyj,mynode";

        astring="hello 21091";

        uint  =<0xaabbccdd 0x11223344>;

        binarry=[00 0c 29 7b f9 be];

        mixed ="hello",[11 22],<0x12345678>;

     };*/

    //定义指针指向获取的设备树节点信息空间

     struct device_node *node;

     struct property *pr;

     int len,i,ret;

     u32 value;

     u32 values[2];

     const char *str;

    static int __init mycdev_init(void)

    {

        //通过路径获取设备树节点信息

        node=of_find_node_by_path("/mynode@0x12345678");

        if(node==NULL)

        {

            printk("通过路径解析设备树节点失败\n");

            return -EFAULT;

        }

        printk("成功解析到设备树节点\n");

        printk("name=%s,value=%s\n",node->properties->name,(char *)node->properties->value);

        printk("name=%s,value=%s\n",node->properties->next->name,(char *)node->properties->next->value);

        printk("name=%s,value=%#x,%#x\n",node->properties->next->next->name,__be32_to_cpup((int *)node->properties->next->next->value),__be32_to_cpup((int *)node->properties->next->next->value+1));

       

        //解析字符串

        pr=of_find_property(node,"astring",&len);

        if(pr==NULL)

        {

            printk("属性解析失败\n");

            return -EFAULT;

        }

        for(i=0;i

            printk("name=%s value=%#x\n",pr->name,*((char *)pr->value+i));

        }

        //通过键名获取32位无符号整型的值

        ret=of_property_read_u32_index(node,"uint",1,&value);

        if(ret!=0){

            printk("获取U32值失败\n");

            return -EFAULT;

        }

        printk("value=%#x\n",value);

        //获取一个U32位数组

        ret=of_property_read_variable_u32_array(node,"uint",values,2,2);

         if(ret<0){

            printk("获取U32组失败\n");

            return -EFAULT;

        }

        printk("value1=%#x %#x\n",values[0],values[1]);

        //读取字符串类型的值

        ret=of_property_read_string(node,"astring",&str);

         if(ret!=0){

            printk("读取字符串类型的值失败\n");

            return -EFAULT;

        }

        printk("str:%s\n",str);

        //获取一个U8位数组

        ret=of_property_read_variable_u32_array(node,"uint",values,2,2);

         if(ret<0){

            printk("获取U8组失败\n");

            return -EFAULT;

        }

        printk("value1=%#o %#o\n",values[0],values[1]);

       

        return 0;

    }

    static void __exit mycdev_exit(void)

    {


     

    }

    module_init(mycdev_init);

    module_exit(mycdev_exit);

    MODULE_LICENSE("GPL");

     

     

  • 相关阅读:
    苍穹外卖——项目搭建
    StripedFly恶意软件框架感染了100万台Windows和Linux主机
    Flink-水位线的设置以及传递
    Docker部署ActiveMQ消息中间件
    简单公式
    Mybatis和MybatisPlus:数据库操作工具的对比
    2023百度之星 题目详解 公园+糖果促销
    如何用手机号注册亚马逊买家账号
    微信小程序组件化开发
    Linux 主机数据拷贝与 Linux 服务器之间拷贝文件的方法
  • 原文地址:https://blog.csdn.net/qq_60135456/article/details/128006809