独立编译设备树的方法 多文件 多dts依赖【转】

转自:https://blog.csdn.net/vesamount/article/details/83350300

通常将设备树源码(dts/dtsi)编译成设备树二进制文件(dtb)可以使用DTC(Device Tree Compiler)工具编译。

单文件编译
对於单文件的dts,可以采用下面的命令:

# dtc命令使用方法见文末
dtc -O dtb -b 0 -o [dest_dtb_file] [src_dts_file]
1
2
将src_dts_file编译成dest_dtb_file设备树二进制文件。

多文件编译
对于有#include包含关系、宏定义的dts文件,直接采用以上的方法将会出现#include相关的语法错误。
DTC本身不支持#include语法,其正确语法为/include/。

如将以下dts(没有宏定义)

#include "child_file.dtsi"
#include "child_file_common.dtsi"
1
2
改为

/include/ "child_file.dtsi"
/include/ "child_file_common.dtsi"
1
2
即可通过编译。

对于以下稍微复杂一点(包含#include,宏,*.h等)的设备树,以上的方法不免有些笨拙。

 

由于“#include”“宏”等都是C的特征,因此可以使用CPP(C Preprocessor)命令对dts源文件进行处理,完成文件包含与宏置换的工作。

# cpp的使用方法较长就不列出来了,可以自己man一下。
cpp -nostdinc -I. -undef -x assembler-with-cpp [src_dts_file] > [tmp_dts_file]
# -nostdinc 不搜索标准目录
# -I. 搜索当前目录
# -undef 不预定义系统和gcc特定的宏
# -x assembler-with-cpp 指定语言c c++ objective-c assembler-with-cpp
1
2
3
4
5
6
使用以上命令将所有的*.dts、*.dtsi、*.h转换至临时*.dts中,然后再使用单文件编译的方法编译临时*.dts,生成最终的dtb。

将上面的操作写成脚本(dts2dtb.sh)如下:

#/bin/bash
#set -vx
device="your_device_name"
src_dts=$device.dts
tmp_dts=$device.tmp.dts
dst_dtb=$device.dtb

cpp -nostdinc -I. -undef -x assembler-with-cpp $src_dts > $tmp_dts
dtc -O dtb -b 0 -o $dst_dtb $tmp_dts
rm $tmp_dts

使用:

修改your_device_name为你要编译的设备树名称,拷贝所有相关的设备树源文件至脚本所在目录,运行。

dtc使用方法:

NAME
dtc - Device Tree Compiler

SYNOPSIS
/usr/bin/dtc [options] <input file>

DESCRIPTION
Device Tree Compiler, dtc, takes as input a device-tree in a given format and outputs a
device-tree in another format for booting kernels on embedded systems. Typically, the input
format is "dts", a human readable source format, and creates a "dtb", or binary format as
output.

OPTIONS
-h Display help text.

-q Quiet:

-q - Suppress warnings.
-qq - Suppress errors.
-qqq - Suppress all.

-I <input format>

Input formats are:

dts - device tree source text
dtb - device tree blob
fs - /proc/device-tree style directory

-o <output file>

Dump the result into a file, instead of stdout.

-O <output format>

Output formats are:

dts - device tree source text
dtb - device tree blob
asm - assembler source

-V <output version>

Blob version to produce. The default is 17 (only relevant for dtb and asm output).

-d <output dependency file>

-R <number>

Make space for <number> reserve map entries (only relevant for dtb and asm output).

-S <bytes>

Make the blob at least <bytes> long (extra space).

-p <bytes>

Add padding to the blob of <bytes> long (extra space)

-b <number>

Set the physical boot CPU.

-f

Force - try to produce output even if the input tree has errors.

-s

Sort nodes and properties before outputting (only useful for comparing trees)

-v Print DTC version and exit.

-H <phandle format>

phandle formats are:

legacy - "linux,phandle" properties only
epapr - "phandle" properties only
both - Both "linux,phandle" and "phandle" properties
————————————————
版权声明:本文为CSDN博主「VesaMount」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/vesamount/article/details/83350300

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章