当前位置: 首页 > 工具软件 > FDT > 使用案例 >

uboot命令实践:fdt系列命令实践和在编程设备树中添加节点

杨彦君
2023-12-01

前言

uboot启动后,会将设备树传递给内核,本文将学习uboot中的设备树相关的命令的使用,最后将想通过实现一个命令,向设备树添加和者修改自定义的节点。

一 fdt命令族

fdt命令族概览

=> help fdt
fdt - flattened device tree utility commands

Usage:
fdt addr [-c]  <addr> [<length>]   - Set the [control] fdt location to <addr>
fdt move   <fdt> <newaddr> <length> - Copy the fdt to <addr> and make it active
fdt resize                          - Resize fdt to size + padding to 4k addr
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 omiting the leading '/', e.g. fdt print ethernet0.

通过help命令可知,fdt命令族真的很强大

加载设备树到内存

首先将设备树加载大都内存中80800000

=> tftp 80800000 emmc.dtb
FEC0 Waiting for PHY auto negotiation to complete.... done
Using FEC0 device
TFTP from server 192.168.0.11; our IP address is 192.168.0.3
Filename 'emmc.dtb'.
Load address: 0x80800000
Loading: ###
         2.1 MiB/s
done
Bytes transferred = 37884 (93fc hex)

将fdt命令族与设备树内存关联

这一步很重要,执行完这一步后,就可以使用fdt命令族操作设备树啦,fdt命令族是不能使用的

=> fdt addr 80800000

fdt header

fdt header                          - Display header info

这是设备树的信息,嗯,totalsize我认识,37884字节。

=> fdt header
magic:                  0xd00dfeed
totalsize:              0x93fc (37884)
off_dt_struct:          0x38
off_dt_strings:         0x8a2c
off_mem_rsvmap:         0x28
version:                17
last_comp_version:      16
boot_cpuid_phys:        0x0
size_dt_strings:        0x9d0
size_dt_struct:         0x89f4
number mem_rsv:         0x0

打印设备树--fdt print

打印全部

打印全部的设备树信息,且无法使用ctrlc中断。

=> fdt print
/ {
        #address-cells = <0x00000001>;
        #size-cells = <0x00000001>;
/*
略
*/
        sii902x-reset {
                compatible = "gpio-reset";
                reset-gpios = <0x00000023 0x00000009 0x00000001>;
                reset-delay-us = <0x000186a0>;
                #reset-cells = <0x00000000>;
                status = "disabled";
                linux,phandle = <0x00000033>;
                phandle = <0x00000033>;
        };
};
=>

打印指定节点

=> fdt print /myled
myled {
        compatible = "ws_led";
        pinctrl-names = "default";
        pinctrl-0 = <0x0000003b>;
        cam_lamp {
                label = "cam_lamp";
                blink-duration = <0x000000fa>;
                trigger = <0x00000000>;
                gpios = <0x0000000e 0x00000014 0x00000001>;
                default-state = "off";
        };
};

打印指定节点的属性

=> fdt print /myled compatible
compatible = "ws_led"

fdt list

fdt list   <path> [<prop>]          - Print one level starting at <path>

打印根节点的子节点 --fdt list

=> fdt list /
/ {
        #address-cells = <0x00000001>;
        #size-cells = <0x00000001>;
        model = "Freescale i.MX6 ULL 14x14 EVK Board";
        compatible = "fsl,imx6ull-14x14-evk", "fsl,imx6ull";
        chosen {
        };
        aliases {
        };
        memory {
        };
        cpus {
        };
        interrupt-controller@00a01000 {
        };
        clocks {
        };
        soc {
        };
        myled {
        };
        reserved-memory {
        };
        pxp_v4l2 {
        };
        regulators {
        };
        leds {
        };
        wskey {
        };
        wsinput {
        };
        spi4 {
        };
        sii902x-reset {
        };
};

也可以打印特定节点的子节点 --fdt list

=> fdt list /chosen
chosen {
        stdout-path = "/soc/aips-bus@02000000/spba-bus@02000000/serial@02020000";
};

打印子节点的属性

=> fdt list /chosen stdout-path
stdout-path = "/soc/aips-bus@02000000/spba-bus@02000000/serial@02020000"

真的是个超级强大的命令啊。

fdt list和fdt print的区别

1 fdt list只会打印子节点和该节点的属性,不会打印子节点的属性,就是一层遍历

2 fdt print会打印本节点属性和子节点以及子节点的属性,就是深度遍历

这个还没写完

 类似资料: