介绍uboot中,在控制台修改device tree配置的方法,为uboot和内核的使用者提供参考。
1. uboot FDT命令说明
FDT:flattened device tree的缩写
在UBOOT控制台停下后,输入fdt,可以查看fdt命令帮助
xxx#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> andstore in <var>
fdt get name <var> <path> <index> - Get name of node <index> and storein <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 inthe tree
<start>/<end> - initrd start/end addr
fdt save - write fdt to flash
NOTE: Dereference aliases by omiting theleading '/', e.g. fdt print ethernet0.
sunxi#
注:
其中常用的命令就是fdt list 和 fdt set
Fdt list用来查询节点配置
Fdt set 用来修改节点配置
查询配置
首先确定要查询的字段在device tree的路径,如果不知道路径,则需要用fdt命令查询:
2.1第一步根目录下查找
xxx#fdtlist /
如果找到需要的配置,比如wlan的配置,运行如下命令即可
xxx#fdtlist /wlan //注意路径中的 /
2.2第二步soc目录查找fdtlist /soc
2.3第三步使用别名查找
别名是device tree中完整路径的一个简写,有一个专门的节点( /aliases )来表示别名的相关信息,用如下命令可以查看系统中别名的配置情况:
sunxi#fdtlist /aliases
aliases{
serial0 ="/soc@01c00000/uart@01c28000";
..............
mmc0 ="/soc@01c00000/sdmmc@01c0f000";
mmc2 ="/soc@01c00000/sdmmc@01C11000";
nand0 ="/soc@01c00000/nand0@01c03000";
disp ="/soc@01c00000/disp@01000000";
lcd0 ="/soc@01c00000/lcd0@01c0c000";
hdmi = "/soc@01c00000/hdmi@01ee0000";
pwm ="/soc@01c00000/pwm@01c21400";
boot_disp ="/soc@01c00000/boot_disp";
};
xxx#
由于配置了nand0节点的路径别名,因此可以用如下命令来显示nand0的配置信息
sunxi#fdtlist nand0
nand0@01c03000{
compatible ="xxx,xxxi-nand";
device_type = "nand0";
reg = <0x00000000 0x01c030000x00000000 0x00001000>;
..................
pinctrl-names = "default","sleep";
pinctrl-1 = <0x00000081>;
};
注:在fdt的所有命令中,别名可用path 字段
fdt list <path> [<prop>] - Print one level starting at <path>
fdt set <path> <prop> [<val>] - Set <property> [to <val>]
3.修改配置
命令格式:fdt set path prop <xxx>
示例: fdt set /wlan wlan_busnum <0x2>
sunxi#fdt list /wlan
wlan {
compatible = "xxx,xxx-wlan";
clocks = <0x00000096>;
wlan_power = "vcc-wifi";
wlan_io_regulator = "vcc-wifi-io";
wlan_busnum = <0x00000001>;
status = "disable";
device_type = "wlan";
};
sunxi#fdt set /wlan wlan_busnum<0x2>
sunxi#fdt list /wlan
wlan {
compatible = "xxxx,sunxi-wlan";
clocks = <0x00000096>;
wlan_power = "vcc-wifi";
wlan_io_regulator = "vcc-wifi-io";
wlan_busnum = <0x00000002>; //修改后
status = "disable";
device_type = "wlan";
};
注:修改整数时,根据需要也可配置为数组形式,需要用空格来分隔
命令格式:fdt set path prop <0x1 0x2 0x3>
命令格式:fdt set path prop "xxxxx"
示例: fdt set /wlan status "disable"
sunxi#fdt list /wlan
wlan {
compatible = "xxxx,xxx-wlan";
clocks = <0x00000096>;
wlan_power = "vcc-wifi";
wlan_io_regulator = "vcc-wifi-io";
wlan_busnum = <0x00000001>;
status = "okay";
device_type = "wlan";
};
sunxi#fdt set /wlan status"disable"
sunxi#fdt list /wlan
wlan {
compatible = "xxxx,xxx-wlan";
clocks = <0x00000096>;
wlan_power = "vcc-wifi";
wlan_io_regulator = "vcc-wifi-io";
wlan_busnum = <0x00000001>;
status = "disable"; //修改后
device_type = "wlan";
};
sunxi#
注:修改字符串时,根据需要也可配置为数组形式,需要用空格来分隔
命令格式:fdt set path prop "string1" "string2"
2. GPIO或者PIN配置特殊说明
2.1.port接口对应的数字编号说明
#define PA 0
#define PB 1
#define PC 2
#define PD 3
#define PE 4
#define PF 5
#define PG 6
#define PH 7
#define PI 8
#define PJ 9
#define PK 10
#define PL 11
#define PM 12
#define PN 13
#define PO 14
#define PP 15
#define default 0xffffffff
2.2.Sysconfig中描述gpio的形式
Sysconfig中描述gpio的形式:
Port:端口+组内序号<功能分配><内部电阻状态><驱动能力><输出电平状态>
2.3.Pin配置说明:
2.3.1.查看PIN配置
2.3.1.1. PIN配置属性字段说明
<xxx,function>对应于sysconfig中的主键名
<xxxr,pins>对应于sysconfig中每个gpio配置中的端口名.
<xxx,pname>对应于sysconfig中主键下面子键名字
<xxxr,muxsel>, <xxxx,pull>,<xxx,drive>,<xxx,data>这些属性分别表示<功能分配><内部电阻状态><驱动能力><输出电平状态>,其中值为0xffffffff表示使用默认值。
2.3.2.修改PIN配置
使用fdt set命令可以修改PIN中相关属性字段
sunxi#fdtset /soc/pinctrl@01c20800/lcd0 xxx,drive <0x1>
sunxi#fdtlist /soc/pinctrl@01c20800/lcd0
注意:示例中该处修改会影响xxx,pins表示的所有端口的驱动能力配置,修改muxsel pull data的值也会产生类似效果。
2.4.1.Devicetree和sysconfig.fex中GPIO对应关系
以usb中usb_id_gpio为例
sunxi#fdtlist /soc/usbc0
usbc0@0{
test = <0x00000002 0x000000030x12345678>;
device_type = "usbc0";
........
usb_serial_unique = <0x00000000>;
usb_serial_number ="20080411";
rndis_wceis = <0x00000001>;
status = "okay";
usb_id_gpio =<0x00000030 0x00000007 0x00000009 0x00000000 0x00000001 0xffffffff0xffffffff>;
};
usb_id_gpio =port:PH09<0><1><default><default>
对应于device tree中
usb_id_gpio= <0x00000030 0x00000007 0x00000009 0x00000000 0x00000001 0xffffffff 0xffffffff>
由5.1节描述, 端口PH 组内序号 功能分配 内部电阻状态 驱动能力输出电平
其中首个0x00000030是device tree内部一个节点相关信息,这里可以略过。
如果需要修改 usb_id_gpio的配置,可按如下方式(示例修改了驱动能力,输出电平两项):
sunxi#fdtset /soc/usbc0 usb_id_gpio <0x00000030 0x00000007 0x00000009 0x000000000x00000001 0x2 0x1>
sunxi#fdtlist
usbc0@0{
test = <0x00000002 0x000000030x12345678>;
device_type = "usbc0";
compatible ="xxxx,xxx-manager";
........
usb_serial_unique = <0x00000000>;
usb_serial_number ="20080411";
rndis_wceis = <0x00000001>;
status = "okay";
usb_id_gpio = <0x00000030 0x000000070x00000009 0x00000000 0x00000001 0x00000002 0x00000001>; //修改ok
};
sunxi#
命令格式:fdt save
作用:保存配置到存储介质上,掉电不会丢失。
运行该命令后,可以接着运行 reset命令重启系统,然后用fdt查询命令看所修改的内容是否已永久生效。
说明:如果修改的内容只需要当次启动有效,则不需要运行该命令保存配置