跳转到主要内容

zynq开发中的设备树

本文转载自:<span id="profileBt"><a href="https://mp.weixin.qq.com/s/n_-zEt74iJnL35LwRWkfww"&gt; 硬码农二毛哥微信公众号</a></span>

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

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

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

<strong>DTS语法介绍</strong>
每个module在设备树中被定义成node。在dts文件中,一个node被定义成

[label:]node-name[@unit-address]{
[properties definitions]
[child nodes]
}

<li>[lable:]: 设备树文件允许标签附加在任何节点或者属性上。</li>

<li>node-name:是指节点的名字。</li>

<li>[@unit-address]:是指节点所在的基地址。</li>

<li>[properties definitions]:是指相关属性的定义。</li>

<li>[child nodes]:是指相关的子节点 </li>

以如下设备树为例:

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

<li>“/”代表根节点;</li>

<li>“compatible”为平台兼容;</li>

<li>#address-cells是address的单板(32bit)</li>

<li>#size-cells”是length的单位(32bit)</li>

<li>”chosen“是板级启动参数</li>

<li>"memory"是板级内存的信息。</li>

<li>“device_type":设备类型,寻找节点可以依据这个属性;</li>

<strong>KV260中的设备树文件</strong>

在petalinux工程中设备主要在三个地方,其中<plnx-proj-root>为工程目录名。

1、<plnx-proj-root>/project-spec/meta-user/recipes-bsp/devicetree/files/:

<li>system-user.dtsi</li>

<li>xen.dtsi</li>

<li>pl-custom.dtsi</li>

<li>openamp.dtsi</li>

<li>xen-qemu.dtsi </li>

其中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、<plnx-proj-root>/project-spec/dts_dir/
<center><img src="https://cdn.eetrend.com/files/2022-11/wen_zhang_/100565430-277566-1.png…; alt=""></center>

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

3、<plnx-proj-root>/components/plnx_workspace/device-tree/device-tree/

文件夹的内容不建议修改。
<center><img src="https://cdn.eetrend.com/files/2022-11/wen_zhang_/100565430-277568-2.png…; alt=""></center>

重点看以下文件:

<li>pl.dtsi: This is a file where all the memory mapped peripheral logic(PL) IP nodes will be available.</li>

<li>pcw.dtsi: This is a file where the dynamic properties where the PS peripheral needs.</li>

<li>system-top.dts: This is a file where it contains the memory information, early console and the boot arguments.</li>

<li>zynqmp.dtsi: This file contains all the PS peripheral information and also the cpu info.</li>

<li>zynqmp-clk-ccf.dtsi: This file contains all the clock information for the peripheral IPs.</li>

<li>zynqmp-smk-k26-reva.dtsi:It contains all the board specific properties。</li>

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中内容优先级最高。该文件夹中没有调用<plnx-proj-root>/project-spec/dts_dir/中的文件,所以dts_dir文件夹中内容没有起作用。

<strong>Devicetree Generator (DTG)</strong>

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

<strong>Kernel Bootargs </strong>

“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