UBOOT Device Tree

來源:互聯網
上載者:User

介紹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>

1.2.  修改字串配置

命令格式: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查詢命令看所修改的內容是否已永久生效。

說明:如果修改的內容只需要當次啟動有效,則不需要運行該命令儲存配置

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.