设备树中ranges属性理解[通俗易懂]

设备树中ranges属性理解[通俗易懂]作者彭东林pengdonglin137@163.com文章来源http://www.cnblogs.com/pengdonglin137/p/7401049.html正文一、设备树下面是我们将要实验的设备树的例子:/{#address-cells=<1>;#size-cells=<1&g…

大家好,又见面了,我是你们的朋友全栈君。

作者

彭东林
pengdonglin137@163.com

文章来源

http://www.cnblogs.com/pengdonglin137/p/7401049.html

正文

一、设备树
  • 下面是我们将要实验的设备树的例子:
/ {
    #address-cells = <1>;
    #size-cells = <1>;

    demo_level0 {
        compatible = "simple-bus";
        ranges = <0x0 0x3000000 0x3000>;
        #address-cells = <1>;
        #size-cells = <1>;

        range@0 {
            compatible = "range";
            reg = <0x100 0x200>;
            reg-names = "range0";
        };

        range@1 {
            compatible = "range";
            reg = <0x300 0x200>;
            reg-names = "range1";
        };

        range@2 {
            compatible = "range";
            reg = <0x600 0x200>;
            reg-names = "range2";
        };

        demo_level1 {
            compatible = "simple-bus";
            ranges = <0x0 0x1000 0x1000>;
            #address-cells = <1>;
            #size-cells = <1>;

            range@3 {
                compatible = "range";
                reg = <0x100 0x200>;
                reg-names = "range3";
            };

            demo_level1-1 {
                compatible = "simple-bus";
                ranges = <0x0 0x300 0x500>;
                #address-cells = <1>;
                #size-cells = <1>;

                range@4 {
                    compatible = "range";
                    reg = <0x100 0x200>;
                    reg-names = "range4";
                };

                range@5 {
                    compatible = "range";
                    reg = <0x300 0x100>;
                    reg-names = "range5";
                };

                demo_level1-1-1 {
                    compatible = "simple-bus";
                    ranges = <0x0 0x400 0x100>;
                    #address-cells = <1>;
                    #size-cells = <1>;

                    range@6 {
                        compatible = "range";
                        reg = <0x50 0x30>;
                        reg-names = "range6";
                    };

                    demo_level1-1-1-1 {
                        compatible = "simple-bus";
                        ranges = <0x0 0x20 0x20>;
                        #address-cells = <1>;
                        #size-cells = <1>;

                        range@7 {
                            compatible = "range";
                            reg = <0x10 0x10>;
                            reg-names = "range7";
                        };

                        range@8 {
                            compatible = "range";
                            reg = <0x0 0x10>;
                            reg-names = "range8";
                        };
                    };
                };
            };

            range@9 {
                compatible = "range";
                reg = <0x800 0x50>;
                reg-names = "range9";
            };

            demo_level1-2 {
                compatible = "simple-bus";
                ranges = <0x0 0x900 0x100>;
                #address-cells = <1>;
                #size-cells = <1>;

                range@10 {
                    compatible = "range";
                    reg = <0x0 0x50>;
                    reg-names = "range10";
                };

                demo_level1-2-1 {
                    compatible = "simple-bus";
                    ranges;
                    #address-cells = <1>;
                    #size-cells = <1>;

                    range@11 {
                        compatible = "range";
                        reg = <0x50 0x30>;
                        reg-names = "range11";
                    };
                };
            };
        };

        demo_level2 {
            compatible = "simple-bus";
            ranges;
            #address-cells = <1>;
            #size-cells = <1>;

            range@12 {
                compatible = "range";
                reg = <0x2000 0x1000>;
                reg-names = "range12";
            };
        };
    }
};
二、驱动
  • 下面是一个简单的驱动,功能很简单,只是在probe函数中将memory资源的start和(end+1)打印出来.
demo_range.c:

#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/of.h>

static int demo_range_probe(struct platform_device *pdev)
{
    struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);

    printk(KERN_INFO "%s start: 0x%x, end: 0x%x\n",
        res->name, res->start, res->end + 1);

    return 0;
}

static int demo_range_remove(struct platform_device *pdev)
{
    return 0;
}

static const struct of_device_id demo_range_of_match[]  = {
    { .compatible = "range"},
    {},
};

static struct platform_driver demo_range_driver = {
    .driver = {
        .name = "demo_range",
        .owner = THIS_MODULE,
        .of_match_table = demo_range_of_match,
    },
    .probe = demo_range_probe,
    .remove = demo_range_remove,
};
module_platform_driver(demo_range_driver);

MODULE_LICENSE("GPL v2");
  • 在驱动中会获得memory资源,然后将start和(end+1)打印出来,之所以这里用(end+1),仅仅是为了便于理解下面的kernel log。
三、验证
  • 编译驱动,然后加载,可以看到下面的打印信息:
[root@vexpress mnt]# insmod demo_range.ko 
[ 382.940402] range0 start: 0x3000100, end: 0x3000300
[ 382.940697] range1 start: 0x3000300, end: 0x3000500
[ 382.941448] range2 start: 0x3000600, end: 0x3000800
[ 382.941657] range3 start: 0x3001100, end: 0x3001300
[ 382.941855] range4 start: 0x3001400, end: 0x3001600
[ 382.942057] range5 start: 0x3001600, end: 0x3001700
[ 382.942262] range6 start: 0x3001750, end: 0x3001780
[ 382.942470] range7 start: 0x3001730, end: 0x3001740
[ 382.942684] range8 start: 0x3001720, end: 0x3001730
[ 382.949796] range9 start: 0x3001800, end: 0x3001850
[ 382.950023] range10 start: 0x3001900, end: 0x3001950
[ 382.950603] range11 start: 0x3001950, end: 0x3001980
[ 382.950805] range12 start: 0x3002000, end: 0x3003000
总结:
  • 1、ranges属性值的格式
四、示意图
  • 对照上面的log理解下面的框图
    image
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/151116.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 最小二乘法 原理_高斯最小二乘法原理

    最小二乘法 原理_高斯最小二乘法原理概念:最小二乘法是一种熟悉而优化的方法。主要是通过最小化误差的平方以及最合适数据的匹配函数。作用:(1)利用最小二乘法可以得到位置数据(这些数据与实际数据之间误差平方和最小)(2)也可以用来曲线拟合实例讲解:有一组数据(1,6),(3,5),(5,7),(6,12),要找出一条与这几个点最为匹配的直线:y=A+Bx有如下方程:6=A+B5=A+3B…

    2022年10月24日
    0
  • Zato入门part2

    Zato入门part2

    2022年3月12日
    42
  • ftp上传工具如何下载和使用像详细教程

    ftp上传工具如何下载和使用像详细教程在学习网站搭建的过程中,我们必定会用到ftp上传工具,那么ftp工具是什么呢,我们该如何下载和使用呢?FTP(FileTransferProtocol),简称是文件传输的协议,我们可以用这个协议在互联网上做文件的双向传输,让我们用自己的计算机,可以链接到世界各地具有文件传输协议的ftp服务器进行连接,从而可以访问,传输下载大量的共享文件。同样我们可以从网站空间服务器中下载拷贝需要的文件到自己的…

    2022年5月22日
    37
  • linux双网卡架设FTP,LINUX系统上架设FTP服务器[通俗易懂]

    linux双网卡架设FTP,LINUX系统上架设FTP服务器[通俗易懂]CentOS上搭建FTP服务器服务器软件:vsftpd简要说明:vsftpd是linux下的一款小巧轻快,安全易用的FTP服务器软件,是一款在各个LINUX发行版中最受推崇的FTP服务器软件。至于它的安装教程,网络上也是数不胜数,每个教程都有各自的优缺点,祥哥特意做了个总结,取别人之长处,尽量做到菜鸟级别的教程。当你看见祥哥的这篇文章,能更好的使用和运用VSFTPD。下面正题开始。安装vsftpd…

    2022年7月21日
    9
  • js split 用法「建议收藏」

    js split 用法「建议收藏」split使用方法

    2025年5月30日
    0
  • 心灵鸡汤【5】

    心灵鸡汤【5】

    2021年8月20日
    56

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号