设备树覆盖模型

时间:2018-06-20 13:02:36

标签: linux-kernel device-tree

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

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


顶级设备树

/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)      
        }; 
    }; 
};

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

我假设在使用-@选项将dts转换为dtbo时,覆盖层应该使用mem_dma_reserved选项获得__fixups__的虚拟空间。我已经创建了dtbo文件,并再次在dts中对其进行了转换,以查看编译过程中完成了什么:

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>节点。修复程序部分应该能够在加载时恢复原来的状态,但是它不起作用,并且出现此错误:

  

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

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

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

编辑

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

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 ";
};

错误现在消失了,但是:

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

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

  

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
   //什么都没有//

似乎没有附加存储区域。

我错过了什么?

1 个答案:

答案 0 :(得分:2)

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

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

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";

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