dtb和dtc文件淺析
[TOC]node
工具集
在以前的內核中,咱們編譯出來了可執行程序linux
linux-4.19-rc3/scripts/dtc/dtc # 複製到bin下 sudo cp dtc /usr/bin/
常規用法以下:shell
-
轉換到二進制 dtc>dtb工具
dtc -I dtb -O dts -o output.dts arch/arm/boot/dts/jz2440.dtb
-
轉換到可讀文件 dtb>dtcui
dtc -I dts -O dtb -o jz2440.dtb output.dts
能夠看下幫助this
dtc -h Usage: dtc [options] <input file> Options: -[qI:O:o:V:d:R:S:p:a:fb:i:H:sW:E:@Ahv] -q, --quiet Quiet: -q suppress warnings, -qq errors, -qqq all -I, --in-format <arg> Input formats are: dts - device tree source text dtb - device tree blob fs - /proc/device-tree style directory -o, --out <arg> Output file -O, --out-format <arg> Output formats are: dts - device tree source text dtb - device tree blob asm - assembler source -V, --out-version <arg> Blob version to produce, defaults to 17 (for dtb and asm output) -d, --out-dependency <arg> Output dependency file -R, --reserve <arg> Make space for <number> reserve map entries (for dtb and asm output) -S, --space <arg> Make the blob at least <bytes> long (extra space) -p, --pad <arg> Add padding to the blob of <bytes> long (extra space) -a, --align <arg> Make the blob align to the <bytes> (extra space) -b, --boot-cpu <arg> Set the physical boot cpu -f, --force Try to produce output even if the input tree has errors -i, --include <arg> Add a path to search for include files -s, --sort Sort nodes and properties before outputting (useful for comparing trees) -H, --phandle <arg> Valid phandle formats are: legacy - "linux,phandle" properties only epapr - "phandle" properties only both - Both "linux,phandle" and "phandle" properties -W, --warning <arg> Enable/disable warnings (prefix with "no-") -E, --error <arg> Enable/disable errors (prefix with "no-") -@, --symbols Enable generation of symbols -A, --auto-alias Enable auto-alias of labels -h, --help Print this help and exit -v, --version Print version and exit
dts格式
更多參考下這裏url
這個就放張圖好了,總結起來就是隻有一個根(root),子節點能夠有子節點spa
固然存在着一些保留的關鍵字.net
Standard Properties | |
---|---|
compatible | 定義一系列的字符串, 用來指定內核中哪一個 |
model | |
phandle | |
status | |
#address-cells | 在它的子節點的reg屬性中, 使用多少個u32整數來描述地址(address) |
#size-cells | 在它的子節點的reg屬性中, 使用多少個u32整數來描述大小(size) |
reg | |
virtual-reg | |
ranges | |
dma-ranges | |
name (deprecated) | |
device_type (deprecated) | |
dtb頭部結構
struct fdt_header { uint32_t magic; uint32_t totalsize; uint32_t off_dt_struct; uint32_t off_dt_strings; uint32_t off_mem_rsvmap; uint32_t version; uint32_t last_comp_version; uint32_t boot_cpuid_phys; uint32_t size_dt_strings; uint32_t size_dt_struct; };
dtb標識符
參見 5.4.1 Lexical structurecode
01 表示節點開始 02 節點結束 09 樹結束 03 屬性名字開始 04 nop
分析具體的文件
找到這裏的文件
/arch/arm/boot/dts/jz2440.dtb jz2440.dts
具體的文件以下
// SPDX-License-Identifier: GPL-2.0 /* * SAMSUNG SMDK2440 board device tree source * * Copyright (c) 2018 weidongshan@qq.com * dtc -I dtb -O dts -o jz2440.dts jz2440.dtb */ #define S3C2410_GPA(_nr) ((0<<16) + (_nr)) #define S3C2410_GPB(_nr) ((1<<16) + (_nr)) #define S3C2410_GPC(_nr) ((2<<16) + (_nr)) #define S3C2410_GPD(_nr) ((3<<16) + (_nr)) #define S3C2410_GPE(_nr) ((4<<16) + (_nr)) #define S3C2410_GPF(_nr) ((5<<16) + (_nr)) #define S3C2410_GPG(_nr) ((6<<16) + (_nr)) #define S3C2410_GPH(_nr) ((7<<16) + (_nr)) #define S3C2410_GPJ(_nr) ((8<<16) + (_nr)) #define S3C2410_GPK(_nr) ((9<<16) + (_nr)) #define S3C2410_GPL(_nr) ((10<<16) + (_nr)) #define S3C2410_GPM(_nr) ((11<<16) + (_nr)) /dts-v1/; / { model = "SMDK24440"; compatible = "samsung,smdk2440"; #address-cells = <1>; #size-cells = <1>; memory@30000000 { device_type = "memory"; reg = <0x30000000 0x4000000>; }; /* cpus { cpu { compatible = "arm,arm926ej-s"; }; }; */ chosen { bootargs = "noinitrd root=/dev/mtdblock4 rw init=/linuxrc console=ttySAC0,115200"; }; led { compatible = "jz2440_led"; pin = <S3C2410_GPF(6)>; }; };