zynq开发中的设备树

在zynq开发中经常会修改设备树,每次遇到这种情况都有点发愁,今天把设备树相关的知识点总结一下,希望以后遇到设备树时,能够自如应对。

什么是设备树

设备树时描述硬件的数据结构,Linux系统可以通过设备树了解硬件结构,不需要进行编码。

设备树文件类型

  • DTSI: 设备树头文件,类似C语言中的.h文件,供DTS文件调用。
  • DTS:.dts文件是设备树的源文件。相当于C语言的.c文件。
  • DTC:DTC是将.dts编译为.dtb的工具,相当于gcc。
  • DTG:Xilinx设备树编译工具。
  • DTB:.dtb文件是 .dts 被 DTC 编译后的二进制格式的设备树文件,它可以被linux内核解析。

DTS语法介绍

每个module在设备树中被定义成node。在dts文件中,一个node被定义成

[label:]node-name[@unit-address]{
    [properties definitions]
    [child nodes]
}
  • [lable:]: 设备树文件允许标签附加在任何节点或者属性上。
  • node-name:是指节点的名字。
  • [@unit-address]:是指节点所在的基地址。
  • [properties definitions]:是指相关属性的定义。
  • [child nodes]:是指相关的子节点

以如下设备树为例:

/ {
    compatible = "xlnx,zynqmp";
    #address-cells = <2>;
    #size-cells = <2>;
  
    cpus {
       #address-cells = <1>;
       #size-cells = <0>;
  
       cpu0: cpu@0 {
                compatible = "arm,cortexa53", "arm,armv8";
                device-type = "cpu";
                enable-method = "psci";
                operating-points-v2 = <&cpu_opp_table>;
                reg = <0x0>;
                cpu-idle-states = <&CPU_SLEEP_0>;
        };
  
        cpu1: cpu@1 {
               compatible = "arm,cortexa53", "arm,armv8";
               device-type = "cpu";
               enable-method = "psci";
               operating-points-v2 = <&cpu_opp_table>;
               reg = <0x1>;
               cpu-idle-states = <&CPU_SLEEP_0>;
        };
  };
  
  chosen {
           bootargs = "earlycon clk_ignore_unused";
  };
  
  memory {
          device-type = "memory";
          reg = <0x0 0x0 0x0 0x80000000>, <0x00000008 0x0 0x0 0x80000000>;
  };
  • “/”代表根节点;
  • “compatible”为平台兼容;
  • #address-cells是address的单板(32bit)
  • #size-cells”是length的单位(32bit)
  • ”chosen“是板级启动参数
  • "memory"是板级内存的信息。
  • “device_type":设备类型,寻找节点可以依据这个属性;

KV260中的设备树文件

在petalinux工程中设备主要在三个地方,其中为工程目录名。

1、/project-spec/meta-user/recipes-bsp/devicetree/files/:

  • system-user.dtsi
  • xen.dtsi
  • pl-custom.dtsi
  • openamp.dtsi
  • xen-qemu.dtsi

其中system-user.dtsi是主要修改的文件,该文件中的内容具有更好优先级。

例如要增加phy芯片信息,可以在system-user.dtsi增加如下内容。

/dts-v1/;
/include/ "system-conf.dtsi"
/ {
};
&gem0 {
    phy-handle = <&phy0>;
    ps7_ethernet_0_mdio: mdio {
    phy0: phy@7 {
    compatible = "marvell,88e1116r";
    device_type = "ethernet-phy";
    reg = <7>;
		};
	};
};

2、/project-spec/dts_dir/

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-DDrEaips-1667710784263)(./pic/2.png)]

我理解这个文件夹中的内容,需要添加到system-user.dtsi才会起作用。

3、/components/plnx_workspace/device-tree/device-tree/

文件夹的内容不建议修改。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-l8SBE92P-1667710784265)(./pic/1.png)]

重点看以下文件:

  • pl.dtsi: This is a file where all the memory mapped peripheral logic(PL) IP nodes will be available.
  • pcw.dtsi: This is a file where the dynamic properties where the PS peripheral needs.
  • system-top.dts: This is a file where it contains the memory information, early console and the boot arguments.
  • zynqmp.dtsi: This file contains all the PS peripheral information and also the cpu info.
  • zynqmp-clk-ccf.dtsi: This file contains all the clock information for the peripheral IPs.
  • zynqmp-smk-k26-reva.dtsi:It contains all the board specific properties。

system-top.dts中文件内容如下:

/dts-v1/;
#include "zynqmp.dtsi"
#include "zynqmp-smk-k26-reva.dtsi"
#include "zynqmp-clk-ccf.dtsi"
#include "pcw.dtsi"
/ {
	chosen {
		bootargs = "earlycon";
		stdout-path = "serial0:115200n8";
	};
	aliases {
	};
	memory {
		device_type = "memory";
		reg = <0x0 0x0 0x0 0x7ff00000>, <0x00000008 0x00000000 0x0 0x80000000>;
	};
};
#include "system-user.dtsi"

由文件内容可知,该文件为顶层文件,调用各个模块,最后调用system-user.dtsi,所以system-user.dtsi中内容优先级最高。该文件夹中没有调用/project-spec/dts_dir/中的文件,所以dts_dir文件夹中内容没有起作用。

Devicetree Generator (DTG)

Xilinx设备树生成工具DTG,帮助用户构建特定硬件的设备树。不用使用手动编译过程,直接从XSA文件获取和硬件信息。

Kernel Bootargs

“Kernel Bootargs”子菜单允许 PetaLinux 在 DTS 中自动生成内核启动命令行设置,或者传递 PetaLinux 用户定义的内核启动命令行设置。 以下是默认的 bootargs。

zynqmp -- earlycon clk_ignore_unused root=/dev/ram0 rw

如果希望在控制台上看到内核错误打印信息,system_user.dtsi 中添加

earlycon console=<device>,<baud rate> clk_ignore_unused root=/dev/ram rw
earlycon console=/dev/ttyPS0,115200 clk_ignore_unused root=/dev/ram rw
  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

硬码农二毛哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值