简介
dts文件描述了硬件每个模块的信息,我们嵌入式软件的调试很多时候都是在改dts文件,有时候我们不确定板子上的固件是否已经更新了我们的修改,这时候我们可以直接读取板子上的dts信息,下面来演示一下。
进入uboot命令行模式
RK的默认SDK中,如果想进入uboot命令行模式,开机的时候在调试串口界面按住键盘的CTRL+C,上电,这时候如果看到如下信息,就说明已经进入uboot命令行模式:
Hit key to stop autoboot('CTRL+C'): 0
=> <INTERRUPT>
=> <INTERRUPT>
=> <INTERRUPT>
fdt基本操作
FDT,flatted device tree,直接翻译过来是:扁平设备树,大概意思就是把设备信息结构存放到device tree文件中。这里我们可以通过帮助选项看其应用:
=> fdt
fdt - flattened device tree utility commandsUsage:
fdt addr [-c] <addr> [<length>] - Set the [control] fdt location to <addr>
fdt apply <addr> - Apply overlay to the DT
fdt move <fdt> <newaddr> <length> - Copy the fdt to <addr> and make it active
fdt resize [<extrasize>] - Resize fdt to size + padding to 4k addr + some optional <extrasize> if needed
fdt print <path> [<prop>] - Recursive print starting at <path>
fdt list <path> [<prop>] - Print one level starting at <path>
fdt get value <var> <path> <prop> - Get <property> and store in <var>
fdt get name <var> <path> <index> - Get name of node <index> and store in <var>
fdt get addr <var> <path> <prop> - Get start address of <property> and store in <var>
fdt get size <var> <path> [<prop>] - Get size of [<property>] or num nodes and store in <var>
fdt set <path> <prop> [<val>] - Set <property> [to <val>]
fdt mknode <path> <node> - Create a new node after <path>
fdt rm <path> [<prop>] - Delete the node or <property>
fdt header - Display header info
fdt bootcpu <id> - Set boot cpuid
fdt memory <addr> <size> - Add/Update memory node
fdt rsvmem print - Show current mem reserves
fdt rsvmem add <addr> <size> - Add a mem reserve
fdt rsvmem delete <index> - Delete a mem reserves
fdt chosen [<start> <end>] - Add/update the /chosen branch in the tree<start>/<end> - initrd start/end addr
NOTE: Dereference aliases by omitting the leading '/', e.g. fdt print ethernet0.
读dts信息
从上面的帮助选项我们可以看到,通过fdt list <path> [<prop>]
就可以读到某个模块的信息,那么,我们怎么知道对应模块的path呢?以RK3568的otg口usbdrd_dwc3控制器节点为例,这里有两种方法:
- 从源代码的dts配置获取
usbdrd30: usbdrd {compatible = "rockchip,rk3568-dwc3", "rockchip,rk3399-dwc3";clocks = <&cru CLK_USB3OTG0_REF>, <&cru CLK_USB3OTG0_SUSPEND>,┆<&cru ACLK_USB3OTG0>, <&cru PCLK_PIPE>;clock-names = "ref_clk", "suspend_clk",┆ "bus_clk", "pipe_clk";#address-cells = <2>; #size-cells = <2>; ranges;status = "disabled";usbdrd_dwc3: dwc3@fcc00000 {compatible = "snps,dwc3";reg = <0x0 0xfcc00000 0x0 0x400000>;interrupts = <GIC_SPI 169 IRQ_TYPE_LEVEL_HIGH>;dr_mode = "otg";phys = <&u2phy0_otg>, <&combphy0_us PHY_TYPE_USB3>;phy-names = "usb2-phy", "usb3-phy";phy_type = "utmi_wide";power-domains = <&power RK3568_PD_PIPE>;resets = <&cru SRST_USB3OTG0>;reset-names = "usb3-otg";snps,dis_enblslpm_quirk;snps,dis-u1u2-quirk;snps,dis-u2-freeclk-exists-quirk;snps,dis-del-phy-power-chg-quirk;snps,dis-tx-ipgap-linecheck-quirk;snps,dis_rxdet_inp3_quirk;snps,xhci-trb-ent-quirk;quirk-skip-phy-init;status = "disabled";}; };
从rk3568.dtsi可以看到,usbdrd_dwc3是在usbdrd30节点下面,usbdrd30是根节点,因此path应该是:/usbdrd/dwc3@fcc00000
- 打印所有节点信息
在uboot命令行模式下,执行fdt print
可以把dts所有的节点信息打印出来,然后查找到你想要的节点名字,如:
usbdrd_dwc3 = "/usbdrd/dwc3@fcc00000";
因此path应该是:/usbdrd/dwc3@fcc00000
确认path之后,执行指令,结果为:
=> fdt list /usbdrd/dwc3@fcc00000
dwc3@fcc00000 {compatible = "snps,dwc3";reg = <0x00000000 0xfcc00000 0x00000000 0x00400000>;interrupts = <0x00000000 0x000000a9 0x00000004>;dr_mode = "otg";phys = <0x00000024 0x00000020 0x00000004>;phy-names = "usb2-phy", "usb3-phy";phy_type = "utmi_wide";power-domains = <0x00000021 0x0000000f>;resets = <0x0000001f 0x00000094>;reset-names = "usb3-otg";snps,dis_enblslpm_quirk;snps,dis-u1u2-quirk;snps,dis-u2-freeclk-exists-quirk;snps,dis-del-phy-power-chg-quirk;snps,dis-tx-ipgap-linecheck-quirk;snps,dis_rxdet_inp3_quirk;snps,xhci-trb-ent-quirk;quirk-skip-phy-init;status = "okay";extcon = <0x00000025>;phandle = <0x0000016f>;
};