设备树覆盖模型 [英] device tree overlay phandle

查看:238
本文介绍了设备树覆盖模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用双Cortex-A9处理器开发Altera的Cyclone V SOC FPGA.嵌入式系统(linux-socfpga 4.16)使用Buildroot-2018.05创建.

I'm working on a Cyclone V SOC FPGA from Altera with a double Cortex-A9 processor. The embedded system (linux-socfpga 4.16) is created with Buildroot-2018.05.

我在引导时使用顶部"设备树作为处理器组件,并使用设备树覆盖来配置组件的FPGA部分并加载相关的驱动程序.叠加层将附加到顶部DT的base_fpga_region.

I use a "top" device tree at boot time for processor component and a device-tree overlay to configure the FPGA part of the component and load the associated drivers. The overlay will be attach to the base_fpga_region of the top DT.

/dts-v1/;

/ {
    model = "MY_PROJECT";   /* appended from boardinfo */
    compatible = "altr,socfpga-cyclone5", "altr,socfpga";   /* appended from boardinfo */
    #address-cells = <1>;
    #size-cells = <1>;

    cpus {
        [...]
    }; //end cpus

    memory {
        device_type = "memory";
        reg = <0xffff0000 0x00010000>,
            <0x00000000 0x80000000>;
    }; //end memory

    reserved-memory {
        #address-cells = <1>;
        #size-cells = <1>;
        ranges;

        mem_dma_reserved {
            compatible = "shared-dma-pool";
            no-map;
            reg = <0x78000000 0x8000000>;
        };
    };

    soc: soc {
        device_type = "soc";
        ranges;
        #address-cells = <1>;
        #size-cells = <1>;
        compatible = "altr,avalon", "simple-bus";
        bus-frequency = <0>;

        fpgabridge1: fpgabridge@1 {
            compatible = "altr,socfpga-lwhps2fpga-bridge";
            resets = <&hps_rstmgr 97>;  /* appended from boardinfo */
            clocks = <&l4_main_clk>;    /* appended from boardinfo */           
            #address-cells = <1>;
            #size-cells = <1>;
            ranges;
            bridge-enable = <1>;

            label = "lwhps2fpga";
            reset-names = "lwhps2fpga";
            reg = <0xff200000 0x200000>;
            reg-names = "axi_h2f_lw";
        }; //end fpgabridge@1 (fpgabridge1)

        base_fpga_region: base_fpga_region  {
            compatible = "fpga-region";
            #address-cells = <0x2>;
            #size-cells = <0x1>;
            fpga-mgr = <&hps_fpgamgr>;
            fpga-bridges = <&fpgabridge1>;          
            ranges = <0x0 0x0 0xff200000 0x200000>;
        }; //end base_fpga_region (base_fpga_region)

etc......

设备树覆盖

/dts-v1/ /plugin/; 

/{ 
    fragment@0 { 
        target-path = "/soc/base_fpga_region"; 
        #address-cells = <2>; 
        #size-cells = <1>; 
        __overlay__ { 
            #address-cells = <2>; 
            #size-cells = <1>; 

            firmware-name = "my_project.rbf";

            my_dma_0: dma@0x000000000 {
                compatible = "my_company,my_dma-0.1";
                reg = <0x00000000 0x0000000 0x00000014>;
                memory-region = <&mem_dma_reserved>;
            }; //end dma@0x000000000 (my_dma_0)      
        }; 
    }; 
};


我的问题是将mem_dma_reserved从顶部DT链接到叠加层中的memory-region.


my problem is to link the mem_dma_reserved from the top DT to the memory-region in the overlay.

我假设在通过-@选项将dts转换为dtbo时,覆盖层应通过__fixups__选项获得mem_dma_reserved的模型.我已经创建了dtbo文件,并再次在dts中对其进行了转换,以查看在编译过程中做了什么:

I assume that while converting dts to dtbo with the -@ option, the overlay shall get the phandle for mem_dma_reserved with the __fixups__ option. I've created the dtbo file and converted it again in dts to see what is done during the compilation :

dtc -@ -I dts -O dtb -o overlay.dtbo overlay.dts
dtc -I dtb -O dts -o overlay_recovery.dts overlay.dtbo


设备树覆盖已重新生成

/dts-v1/;    
/ {

    fragment@0 {
        target-path = "/soc/base_fpga_region";
        #address-cells = <0x2>;
        #size-cells = <0x1>;

        __overlay__ {
            #address-cells = <0x2>;
            #size-cells = <0x1>;
            firmware-name = "my_project.rbf";

            dma@0x000000000 {
                compatible = "my_company,my_dma-0.1";
                reg = <0x0 0x0 0x14>;
                memory-region = <0xffffffff>;  // phandle converted to 0xffffffff, cannot resolve unless the __fixup__ function does it.
                linux,phandle = <0x2>;
                phandle = <0x2>;
            };
        };
    };

    __symbols__ {
        my_dma_0 = "/fragment@0/__overlay__/dma@0x000000000";
    };

    __fixups__ {
        mem_dma_reserved = "/fragment@0/__overlay__/dma@0x000000000:memory-region:0";
    };
};


我们可以看到内存区域的模数是0xFFFFFFFF,因为覆盖不知道<& mem_dma_reserved>节点.修复程序部分应该能够在加载时恢复原状,但它不起作用,并且出现此错误:


We can see that the phandle for the memory-region is 0xFFFFFFFF because the overlay doesn't know about the <&mem_dma_reserved> node. the fixup part shall be able to get back the phandle at loading time, but it isn't working and I get this error :

[27.434730] OF:解析程序:of_resolve_phandles:设备树的根中没有符号.
[27.440401] OF:解析器:叠加phandle修复失败:-22
[27.445993] create_overlay:无法解析树

[ 27.434730] OF: resolver: of_resolve_phandles: no symbols in root of device tree.
[ 27.440401] OF: resolver: overlay phandle fixup failed: -22
[ 27.445993] create_overlay: Failed to resolve tree

我在DT顶部从dtb到dts进行了相同的再生.我已经看到,保留内存的虚拟内存实际上是0x6.我已经在设备树覆盖中写了< 0x6>而不是<& mem_dma_reserved>,并且使用此配置,一切都加载了!

I have made the same regeneration from dtb to dts on the top DT. I have seen that the phandle of the reserved memory is actually 0x6. I have written <0x6> instead of <&mem_dma_reserved> in the device tree overlay and with this configuration, everything loads !

如何使覆盖图自动找到<& mem_dma_reserved>而不需要手动进行?

How can I make the overlay find the <&mem_dma_reserved> automatically without doing it by hand ?

正如 ikwzm 所指出的,我在顶部设备树中添加了以下几行:

As pointed by ikwzm I have added in the top device tree the following lines :

reserved-memory {
    #address-cells = <1>;
    #size-cells = <1>;
    ranges;

    mem_dma_reserved: mem_dma_reserved { // add a label
        compatible = "shared-dma-pool";
        no-map;
        reg = <0x78000000 0x8000000>;
    };
};    

[...]    

// add the whole symbol block
__symbols__ { 
    mem_dma_reserved = "/reserved-memory/mem_dma_reserved ";
};

错误现在消失了,但是:

The errors are now gone, but :

我希望在操作期间加载my_dma的驱动程序.

I was expecting the driver for my_dma to be loaded during the operation.

我检查了设备树覆盖是否已被适当考虑:

I checked that the device tree overlay is well taken into account with :

ls/sys/firmware/devicetree/base/soc/base_fpga_region/
my_dma_0
other_stuff

ls /sys/firmware/devicetree/base/soc/base_fpga_region/
my_dma_0
other_stuff

猫/sys/firmware/devicetree/base/soc/base_fpga_region/my_dma_0/memory-region
//什么都没有//

cat /sys/firmware/devicetree/base/soc/base_fpga_region/my_dma_0/memory-region
//nothing//

似乎没有附加内存区域.

The memory region doesn't seem to be attached.

我错过了什么?

推荐答案

制作顶部dtb时,是否在dtc命令上附加了--symbol选项(或-@)?

When making the top dtb, did you attach the option --symbol (or -@) to the dtc command?

按如下所示向mem_dma_reserved添加标签(符号).

Add a label (symbol) to mem_dma_reserved as follows.

reserved-memory {
    #address-cells = <1>;
    #size-cells = <1>;
    ranges;

    mem_dma_reserved: mem_dma_reserved {
        compatible = "shared-dma-pool";
        no-map;
        reg = <0x78000000 0x8000000>;
    };
};

使用--symbol选项dtc命令创建dtb时,将按以下方式添加__symbols__{...};,并且应在其中找到mem_dma_reserved = "/reserved-memory/ mem_dma_reserved";.

When dtb is created with the --symbol option dtc command, __symbols__{...}; is added as follows, and mem_dma_reserved = "/reserved-memory/ mem_dma_reserved"; should be found in it.

__symbols__ {
    :
    :
    :
    mem_dma_reserved = "/reserved-memory/mem_dma_reserved";
    usb_phy0 = "/phy0";
};

这篇关于设备树覆盖模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆