หาก Blob ต้นไม้อุปกรณ์ (DTB) หรือ Blob ต้นไม้อุปกรณ์สำหรับการวางซ้อน (DTBO) อยู่ในพาร์ติชันที่ไม่ซ้ำกัน เช่น พาร์ติชัน dtb
และ dtbo
ให้ใช้โครงสร้างตารางและรูปแบบส่วนหัวต่อไปนี้
รูปที่ 1 ตัวอย่างเลย์เอาต์พาร์ติชัน DTB และ DTBO
โครงสร้างข้อมูล
dt_table_header
มีไว้สำหรับพาร์ติชัน dtb
/dtbo
เท่านั้น คุณไม่สามารถเพิ่มรูปแบบนี้ต่อท้ายimage.gz
หากมี DTB หรือ DTBO รายการเดียว คุณยังคงต้องใช้รูปแบบนี้ (และ dt_entry_count
ใน dt_table_header
คือ 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 is 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);
id
, rev
, custom
ใน dt_table_entry
คือตัวระบุฮาร์ดแวร์ของอุปกรณ์แบบไม่บังคับ ซึ่งบูตโหลดเดอร์สามารถใช้เพื่อระบุ DTB หรือ DTBO ที่จะโหลดได้อย่างมีประสิทธิภาพ หาก bootloader ต้องการข้อมูลเพิ่มเติม ให้ใส่ข้อมูลดังกล่าวใน DTB หรือ DTBO ที่ bootloader อ่านได้โดยการแยกวิเคราะห์ DTB หรือ DTBO (ดูตัวอย่างโค้ดด้านล่าง)
โค้ดตัวอย่าง
โค้ดตัวอย่างต่อไปนี้จะตรวจสอบการระบุฮาร์ดแวร์ในบูตโหลดเดอร์
- ฟังก์ชัน
check_dtbo()
จะตรวจสอบการระบุฮาร์ดแวร์ โดยระบบจะตรวจสอบข้อมูลในโครงสร้างdt_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
mkdtimg
เป็นเครื่องมือสำหรับสร้างรูปภาพ dtb
/dtbo
(ซอร์สโค้ดที่ system/libufdt
ใน AOSP) 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) หรือตัวเลขฐาน 16 (เช่น 0x6800) หรือจะระบุเส้นทางโดยใช้รูปแบบต่อไปนี้ก็ได้
<full_node_path>:<property_name>
เช่น /board/:id
mkdtimg
จะอ่านค่าจากเส้นทางในไฟล์ DTB หรือ DTBO และกำหนดค่า (32 บิต) ให้กับพร็อพเพอร์ตี้แบบสัมพัทธ์ใน dt_table_entry
หรือจะให้ global_option
เป็นตัวเลือกเริ่มต้นสำหรับรายการทั้งหมดก็ได้ ค่าเริ่มต้นของ page_size
ใน dt_table_header
คือ 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
ที่ 2 คือ0x00006800
และcustom[0]
คือ0x00000abc
id
ลำดับที่ 3 คือ0x00006801
และcustom[0]
คือ0x00000123
- ส่วนรายการอื่นๆ ทั้งหมดจะใช้ค่าเริ่มต้น (
0
)
cfg_create
คำสั่ง cfg_create
จะสร้างรูปภาพที่มีไฟล์การกําหนดค่าในรูปแบบต่อไปนี้
# global options <global_option> ... # entries <ftb1_filename> # comment <entry1_option> # comment ... <ftb2_filename> <entry2_option> ... ...
ตัวเลือก global_option
และ entryX_option
ต้องขึ้นต้นด้วยอักขระเว้นวรรคอย่างน้อย 1 ตัว (ตัวเลือกเหล่านี้เหมือนกับตัวเลือก 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
เดียวกัน ซึ่งมีประโยชน์เมื่อใช้ฮาร์ดแวร์ที่แตกต่างกันซึ่งมี DT เหมือนกัน
ดัมพ์
สำหรับรูปภาพ 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
...