ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2022-01-26 02:33:14  阅读:157  来源: 互联网

标签:依赖 dtb tree 编译 device file dts include


转自: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

标签:依赖,dtb,tree,编译,device,file,dts,include
来源: https://www.cnblogs.com/sky-heaven/p/15845253.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有