设备树中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)
上一篇 2022年6月19日 下午11:00
下一篇 2022年6月19日 下午11:16


相关推荐

  • C语言const关键字详解

    C语言const关键字详解const 在实际编程中用得并不多 const 是 constant 的缩写 意思是 恒定不变的 它是定义只读变量的关键字 或者说 const 是定义常变量的关键字 说 const 定义的是变量 但又相当于常量 说它定义的是常量 但又有变量的属性 所以叫常变量 用 const 定义常变量的方法很简单 就在通常定义变量时前面加 const 即可 如 constinta 10 con

    2026年3月17日
    2
  • OpenClaw 专题总览:从安装上手到生产落地的完整内容地图

    OpenClaw 专题总览:从安装上手到生产落地的完整内容地图

    2026年3月13日
    2
  • Python:将列表转为字符串的3种方法「建议收藏」

    Python:将列表转为字符串的3种方法「建议收藏」#一天一个Python小技巧#将列表转为字符串:1、使用for循环testlist=[‘h’,’e’,’l’,’l’,’o’]teststr=”foriintestlist:teststr+=iprint(teststr)2、join方法:testlist=[‘h’,’e’,’l’,’l’,’o’]teststr=””.join(testlist)print(teststr)3、reduce方法:fromfunctools

    2022年5月9日
    58
  • Stata:面板数据模型的完整步骤(NPL与企业绿色创新)

    Stata:面板数据模型的完整步骤(NPL与企业绿色创新)有两种步骤可以选择 第一种 第一步 设定面板数据格式第二步 对主要变量做描述性分析第三步 做基准回归第四步 做中介效应 也称机制检验 找中介变量第五步 做异质性分析 将样本分组 第六步 内生性检验第七步 稳健性检验 包括替换主要变量 更改模型方法等 第八步 调节效应可做可不做第二种 1 基准回归 包括用 OLS WLS 以及 FE 等多个模型算出回归结果放在一起 2 内生性检验 3 稳健性检验 更换被解释变量 更换解释变量等 4 异质性检验 或称

    2026年3月26日
    2
  • 关于 Sensor flicker/banding现象的解释「建议收藏」

    关于 Sensor flicker/banding现象的解释「建议收藏」目录1、基本概念2、30fps,1帧内banding过程演示3、30fps,帧与帧之间banding过程演示4、25fps,帧与帧之间banding过程演示5、总结flicker交流电网中的传输的能量并不是稳定不变的,而是随着一个固定频率变化的,这个频率一般被称为工频,例如中国是50Hz,美国是60Hz。工频由电力系统决定。工频的带来的这种能量变化称为flicker。下面以50HZ为例进行解释,交流电以1/50s,即20ms的周期进行变化,其变化规律如图所示:而对于能量来说,并没有正负之分,因此能量

    2022年10月13日
    3
  • MP3文件结构解析(超详细)

    MP3文件结构解析(超详细)MP3 音频文件结构解析 包括文件首部的 ID3V2 数据帧 以及位于文件末尾 128 字节的 ID3V1 等信息

    2026年3月18日
    1

发表回复

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

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