獨立編譯設備樹的方法 多文件 多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

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