Partizioni DTB/DTBO

Se il tuo DTB/DTBO si trova in una partizione univoca, ad esempio partizioni dtb e dtbo , utilizza la struttura della tabella e il formato dell'intestazione seguenti:

Figura 1. Esempio di layout della partizione dtb / dtbo (per la firma AVB, vedere Sicurezza ).

Strutture dati

dt_table_header è solo per la partizione dtb / dtbo ; NON PUOI aggiungere questo formato dopo la fine di image.gz . Se hai un singolo DTB/DTBO, devi comunque utilizzare questo formato (e il dt_entry_count in 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
};

Per leggere tutto dt_table_entry , utilizzare dt_entry_size , dt_entry_count e dt_entries_offset . Esempio:

my_read(entries_buf,
        header_addr + header->dt_entries_offset,
        header->dt_entry_size * header->dt_entry_count);

id , rev , custom in dt_table_entry sono identificazioni hardware opzionali dell'albero dei dispositivi che il bootloader può utilizzare per identificare in modo efficiente il DTB/DTBO da caricare. Se il bootloader richiede informazioni aggiuntive, inseriscile nel DTB/DTBO dove il bootloader può leggerle analizzando DTB/DTBO (vedi il codice di esempio di seguito).

Codice d'esempio

Il seguente codice di esempio controlla l'identificazione dell'hardware nel bootloader.

  • La funzione check_dtbo() controlla l'identificazione dell'hardware. Innanzitutto controlla i dati nella struttura dt_table_entry ( id , rev , ecc.). Se questi dati non sono sufficienti, carica i dati dtb in memoria e controlla il valore in dtb .
  • I valori delle proprietà my_hw_information e soc_id vengono analizzati nel nodo radice (esempio in 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 è uno strumento per creare immagini dtb / dtbo ( codice sorgente su system/libufdt in AOSP). mkdtimg supporta diversi comandi, inclusi create , cfg_create e dump .

creare

Utilizza il comando create per creare un'immagine dtb / dtbo :

mkdtimg create <image_filename> (<global-option>...) \
    <ftb1_filename> (<entry1_option>...) \
    <ftb2_filename> (<entry2_option>...) \
    ...

ftbX_filename genera una dt_table_entry nell'immagine. entryX_option s sono i valori da assegnare a dt_table_entry . Questi valori possono essere uno dei seguenti:

--id=<number|path>
--rev=<number|path>
--custom0=<number|path>
--custom1=<number|path>
--custom2=<number|path>
--custom3=<number|path>

I valori numerici possono essere cifre a 32 bit (come 68000) o un numero esadecimale (come 0x6800). In alternativa, è possibile specificare un percorso utilizzando il formato:

<full_node_path>:<property_name>

Ad esempio, /board/:id . mkdtimg legge il valore dal percorso nel file DTB/DTBO e assegna il valore (32 bit) a una proprietà relativa in dt_table_entry . In alternativa, puoi fornire global_option come opzione predefinita per tutte le voci. Il valore predefinito di page_size in dt_table_header è 2048; utilizzare global_option --page_size=<number> per assegnare un valore diverso.

Esempio:

[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
  • Il primo id dt_table_entry ( board1.dtbo ) è 0x00010000 e custom[0] è 0x00000abc .
  • Il secondo id è 0x00006800 e custom[0] è 0x00000abc .
  • Il terzo id è 0x00006801 e custom[0] è 0x00000123 .
  • Tutti gli altri utilizzano il valore predefinito ( 0 ).

cfg_crea

Il comando cfg_create crea un'immagine con un file di configurazione nel seguente formato:

# global options
  <global_option>
  ...
# entries
<ftb1_filename>     # comment
  <entry1_option>   # comment
  ...
<ftb2_filename>
  <entry2_option>
  ...
...

Le opzioni global_option e entryX_option devono iniziare con uno o più caratteri di spazio (queste opzioni sono le stesse delle opzioni create , senza il prefisso -- ). Le righe vuote o le righe che iniziano con # vengono ignorate.

Esempio:

[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 non gestisce l'allineamento dei file .dtb / .dtbo ma piuttosto li aggiunge all'immagine. Quando usi dtc per compilare .dts in .dtb / .dtbo , devi aggiungere l'opzione -a . Ad esempio, aggiungendo l'opzione -a 4 si aggiunge il riempimento in modo che la dimensione di .dtb / .dtbo sia allineata a 4 byte.

Diverse voci della tabella DT possono condividere un .dtb / .dtbo . Se utilizzi lo stesso nome file per voci diverse, memorizza un solo contenuto nell'immagine con gli stessi dt_offset e dt_size . Ciò è utile quando si utilizzano hardware diversi con SEF identiche.

scarico

Per le immagini dtb / dtbo , utilizzare il comando dump per stampare le informazioni nell'immagine. Esempio:

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
...