מחיצות 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 הם זיהויי חומרה אופציונליים של עץ ההתקן שבו טוען האתחול יכול להשתמש כדי לזהות ביעילות את ה-DTB/DTBO לטעינה. אם טוען האתחול דורש מידע נוסף, שים אותו ב-DTB/DTBO שבו טוען האתחול יכול לקרוא אותו על ידי ניתוח 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) או מספר hex (כגון 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
  • id הראשון dt_table_entry ( board1.dtbo ) הוא 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 . זה שימושי בעת שימוש בחומרה שונה עם DTs זהים.

מזבלה

עבור תמונות 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
...