如果您的 DTB/DTBO 位於唯一分割區中,例如dtb
和dtbo
分割區,請使用下列表格結構和標頭格式:
dtb
/ dtbo
分區佈局範例(有關 AVB 簽名,請參閱安全性)。資料結構
dt_table_header
僅針對dtb
/ dtbo
分區;您不能在image.gz
末尾附加此格式。如果您有單一 DTB/DTBO,則仍必須使用此格式(且dt_table_header
中的dt_entry_count
為 1)。
#define DT_TABLE_MAGIC 0xd7b7ab1e struct dt_table_header { uint32_t magic; // DT_TABLE_MAGIC uint32_t total_size; // includes dt_table_header + all dt_table_entry // and all dtb/dtbo uint32_t header_size; // sizeof(dt_table_header) uint32_t dt_entry_size; // sizeof(dt_table_entry) uint32_t dt_entry_count; // number of dt_table_entry uint32_t dt_entries_offset; // offset to the first dt_table_entry // from head of dt_table_header uint32_t page_size; // flash page size we assume uint32_t version; // DTBO image version, the current version is 0. // The version will be incremented when the // dt_table_header struct is updated. }; struct dt_table_entry { uint32_t dt_size; uint32_t dt_offset; // offset from head of dt_table_header uint32_t id; // optional, must be zero if unused uint32_t rev; // optional, must be zero if unused uint32_t custom[4]; // optional, must be zero if unused };
若要讀取所有dt_table_entry
,請使用dt_entry_size
、 dt_entry_count
和dt_entries_offset
。例子:
my_read(entries_buf, header_addr + header->dt_entries_offset, header->dt_entry_size * header->dt_entry_count);
dt_table_entry
中的id
、 rev
、 custom
是設備樹的可選硬體標識,引導程式可以使用它來有效地識別要載入的 DTB/DTBO。如果引導程式需要其他信息,請將其放入 DTB/DTBO 中,引導程式可以透過解析 DTB/DTBO 來讀取它(請參閱下面的範例程式碼)。
範例程式碼
以下範例程式碼檢查引導程式中的硬體標識。
-
check_dtbo()
函數檢查硬體標識。它首先檢查 structdt_table_entry
中的資料(id
、rev
等)。如果此資料不夠,它將dtb
資料載入到記憶體中並檢查dtb
中的值。 -
my_hw_information
和soc_id
屬性的值在根節點中解析(範例在my_dtbo_1.dts
中)。[my_dtbo_1.dts] /dts-v1/; /plugin/; / { /* As DTS design, these properties only for loader, won't overlay */ compatible = "board_manufacturer,board_model"; /* These properties are examples */ board_id = <0x00010000>; board_rev = <0x00010001>; another_hw_information = "some_data"; soc_id = <0x68000000>; ... }; &device@0 { value = <0x1>; status = "okay"; }; [my_bootloader.c] int check_dtbo(const dt_table_entry *entry, uint32_t header_addr) { ... if (entry->id != ... || entry->rev != ...) { ... } ... void * fdt_buf = my_load_dtb(header_addr + entry->dt_offset, entry->dt_size); int root_node_off = fdt_path_offset(fdt_buf, "/"); ... const char *my_hw_information = (const char *)fdt_getprop(fdt_buf, root_node_off, "my_hw_information", NULL); if (my_hw_information != NULL && strcmp(my_hw_information, ...) != 0) { ... } const fdt32_t *soc_id = fdt_getprop(fdt_buf, root_node_off, "soc_id", NULL); if (soc_id != NULL && *soc_id != ...) { ... } ... }
馬克迪姆格
mkdtimg
是用來建立dtb
/ dtbo
影像的工具(原始碼位於 AOSP 中的system/libufdt
)。 mkdtimg
支援多個指令,包括create
、 cfg_create
和dump
。
創造
使用create
指令建立dtb
/ dtbo
鏡像:
mkdtimg create <image_filename> (<global-option>...) \
<ftb1_filename> (<entry1_option>...) \
<ftb2_filename> (<entry2_option>...) \
...
ftbX_filename
在映像中產生dt_table_entry
。 entryX_option
是指派給dt_table_entry
的值。這些值可以是下列任意值:
--id=<number|path> --rev=<number|path> --custom0=<number|path> --custom1=<number|path> --custom2=<number|path> --custom3=<number|path>
數值可以是 32 位數字(例如 68000)或十六進位數字(例如 0x6800)。或者,您可以使用下列格式指定路徑:
<full_node_path>:<property_name>
例如, /board/:id
。 mkdtimg
從 DTB/DTBO 檔案中的路徑讀取值,並將該值(32 位元)指派給dt_table_entry
中的相對屬性。或者,您可以將global_option
作為所有條目的預設選項。 dt_table_header
中page_size
的預設值為2048;使用global_option --page_size=<number>
指派不同的值。
例子:
[board1.dts]
/dts-v1/;
/plugin/;
/ {
compatible = "board_manufacturer,board_model";
board_id = <0x00010000>;
board_rev = <0x00010001>;
another_hw_information = "some_data";
...
};
&device@0 {
value = <0x1>;
status = "okay";
};
mkdtimg create dtbo.img --id=/:board_id --custom0=0xabc \
board1.dtbo \
board2.dtbo --id=0x6800 \
board3.dtbo --id=0x6801 --custom0=0x123
- 第一個
dt_table_entry
(board1.dtbo
)id
是0x00010000
,custom[0]
是0x00000abc
。 - 第二個
id
是0x00006800
,custom[0]
是0x00000abc
。 - 第三個
id
是0x00006801
,custom[0]
是0x00000123
。 - 所有其他都使用預設值 (
0
)。
cfg_創建
cfg_create
指令使用下列格式的設定檔建立映像:
# global options <global_option> ... # entries <ftb1_filename> # comment <entry1_option> # comment ... <ftb2_filename> <entry2_option> ... ...
選項global_option
和entryX_option
必須以一個或多個空格字元開頭(這些選項與create
選項相同,沒有--
前綴)。空白行或以#
開頭的行將被忽略。
例子:
[dtboimg.cfg]
# global options
id=/:board_id
rev=/:board_rev
custom0=0xabc
board1.dtbo
board2.dtbo
id=0x6800 # override the value of id in global options
board2.dtbo
id=0x6801 # override the value of id in global options
custom0=0x123 # override the value of custom0 in global options
mkdtimg cfg_create dtbo.img dtboimg.cfg
mkdtimg
不處理.dtb
/ .dtbo
檔案的對齊,而是將它們附加到圖像中。當您使用dtc
將.dts
編譯為.dtb
/ .dtbo
時,必須新增選項-a
。例如,新增選項-a 4
會新增填充,以便.dtb
/ .dtbo
的大小對齊到 4 個位元組。
多個 DT 表條目可以共享.dtb
/ .dtbo
。如果對不同條目使用相同的檔案名,則它僅在映像中儲存具有相同dt_offset
和dt_size
的一項內容。當使用具有相同設備標識符的不同硬體時,這非常有用。
傾倒
對於dtb
/ dtbo
鏡像,使用dump
指令列印鏡像中的資訊。例子:
mkdtimg dump dtbo.img
dt_table_header:
magic = d7b7ab1e
total_size = 1300
header_size = 32
dt_entry_size = 32
dt_entry_count = 3
dt_entries_offset = 32
page_size = 2048
version = 0
dt_table_entry[0]:
dt_size = 380
dt_offset = 128
id = 00010000
rev = 00010001
custom[0] = 00000abc
custom[1] = 00000000
custom[2] = 00000000
custom[3] = 00000000
(FDT)size = 380
(FDT)compatible = board_manufacturer,board_model
...