พาร์ติชัน DTB/DTBO

หาก DTB/DTBO ของคุณอยู่ในพาร์ติชันเฉพาะ เช่น พาร์ติชัน dtb และ dtbo ให้ใช้โครงสร้างตารางและรูปแบบส่วนหัวต่อไปนี้:

รูปที่ 1 ตัวอย่างเค้าโครงพาร์ติชัน dtb / dtbo (สำหรับลายเซ็น AVB โปรดดูที่ ความปลอดภัย )

โครงสร้างข้อมูล

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 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);

id , rev , custom ใน dt_table_entry คือการระบุฮาร์ดแวร์เสริมของแผนผังอุปกรณ์ที่ bootloader สามารถใช้เพื่อระบุ DTB/DTBO ที่จะโหลดได้อย่างมีประสิทธิภาพ หาก bootloader ต้องการข้อมูลเพิ่มเติม ให้ใส่ไว้ใน DTB/DTBO โดยที่ bootloader สามารถอ่านได้โดยการแยกวิเคราะห์ DTB/DTBO (ดูโค้ดตัวอย่างด้านล่าง)

รหัสตัวอย่าง

โค้ดตัวอย่างต่อไปนี้จะตรวจสอบการระบุฮาร์ดแวร์ใน Bootloader

  • ฟังก์ชัน check_dtbo() ตรวจสอบการระบุฮาร์ดแวร์ ก่อนอื่นจะตรวจสอบข้อมูลใน struct 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 s คือค่าที่จะกำหนดให้กับ 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 เป็นตัวเลือกเริ่มต้นสำหรับรายการทั้งหมดได้ ค่าเริ่มต้นของ 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 ที่สองคือ 0x00006800 และ custom[0] คือ 0x00000abc
  • id ที่สามคือ 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 ต้องขึ้นต้นด้วยอักขระเว้นวรรคตั้งแต่หนึ่งตัวขึ้นไป (ตัวเลือกเหล่านี้เหมือนกับตัวเลือก 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
...