Se il tuo blob dell'albero del dispositivo (DTB) o il blob dell'albero del dispositivo per l'overlay (DTBO) si trova in una partizione univoca,
ad esempio la partizione dtb
e dtbo
, utilizza la seguente struttura della tabella
e il formato dell'intestazione:
Figura 1. Esempio di layout della partizione DTB e DTBO.
Strutture di 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 o DTBO, devi
ancora utilizzare questo formato (e 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 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
};
Per leggere tutti i dt_table_entry
, utilizza 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 facoltative dell'albero del dispositivo
che il bootloader può utilizzare per identificare in modo efficiente il DTB o il DTBO da caricare. Se il bootloader richiede informazioni aggiuntive, inseriscile nel DTB o nel DTBO, dove il bootloader può leggerle analizzando il DTB o il DTBO (vedi il codice di esempio di seguito).
Codice di esempio
Il seguente codice di esempio controlla l'identificazione dell'hardware nel bootloader.
- La funzione
check_dtbo()
controlla l'identificazione dell'hardware. Controlla innanzitutto i dati nella strutturadt_table_entry
(id
,rev
e così via). Se questi dati non sono sufficienti, carica i datidtb
nella memoria e controlla il valore indtb
. - I valori delle proprietà
my_hw_information
esoc_id
vengono analizzati nel nodo principale (esempio inmy_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 la creazione di immagini dtb
/dtbo
(codice sorgente in system/libufdt
in AOSP). mkdtimg
supporta diversi comandi, tra cui create
, cfg_create
e dump
.
crea
Usa 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 un dt_table_entry
nell'immagine. I entryX_option
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 un numero a 32 bit (ad es. 68000) o un numero esadecimale (ad es. 0x6800). In alternativa, puoi specificare un percorso utilizzando il formato:
<full_node_path>:<property_name>
Ad esempio, /board/:id
. mkdtimg
legge il valore
dal percorso nel file DTB o DTBO e lo assegna (32 bit) a una proprietà
relativa in dt_table_entry
. In alternativa, puoi specificare un valore global_option
come opzione predefinita per tutte le voci. Il valore predefinito di page_size
in dt_table_header
è 2048; utilizza 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
dt_table_entry
(board1.dtbo
)id
è0x00010000
ecustom[0]
è0x00000abc
. - Il secondo
id
è0x00006800
ecustom[0]
è0x00000abc
. - Il terzo
id
è0x00006801
ecustom[0]
è0x00000123
. - Per tutti gli altri viene utilizzato il valore predefinito (
0
).
cfg_create
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 (sono le stesse opzioni di create
, senza il prefisso --
). Le righe vuote o quelle 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 per i file .dtb
/.dtbo
, ma li aggiunge all'immagine.
Quando utilizzi dtc
per compilare .dts
in .dtb
/.dtbo
, devi aggiungere l'opzione -a
. Ad esempio, l'aggiunta dell'opzione -a 4
aggiunge spaziatura in modo che le dimensioni di .dtb
/.dtbo
siano allineate a 4 byte.
Diverse voci della tabella DT possono condividere un .dtb
/.dtbo
. Se utilizzi lo stesso nome file per voci diverse, nell'immagine vengono memorizzati un solo contenuto con gli stessi dt_offset
e dt_size
. Questo è utile quando si utilizza hardware diverso con DT identici.
dump
Per le immagini dtb
/dtbo
, utilizza 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
...