1*cd60bc56SAndroid Build Coastguard Worker /* SPDX-License-Identifier: GPL-2.0-or-later */
2*cd60bc56SAndroid Build Coastguard Worker #ifndef DTC_H
3*cd60bc56SAndroid Build Coastguard Worker #define DTC_H
4*cd60bc56SAndroid Build Coastguard Worker
5*cd60bc56SAndroid Build Coastguard Worker /*
6*cd60bc56SAndroid Build Coastguard Worker * (C) Copyright David Gibson <[email protected]>, IBM Corporation. 2005.
7*cd60bc56SAndroid Build Coastguard Worker */
8*cd60bc56SAndroid Build Coastguard Worker
9*cd60bc56SAndroid Build Coastguard Worker #include <stdio.h>
10*cd60bc56SAndroid Build Coastguard Worker #include <string.h>
11*cd60bc56SAndroid Build Coastguard Worker #include <stdlib.h>
12*cd60bc56SAndroid Build Coastguard Worker #include <stdint.h>
13*cd60bc56SAndroid Build Coastguard Worker #include <stdbool.h>
14*cd60bc56SAndroid Build Coastguard Worker #include <stdarg.h>
15*cd60bc56SAndroid Build Coastguard Worker #include <assert.h>
16*cd60bc56SAndroid Build Coastguard Worker #include <ctype.h>
17*cd60bc56SAndroid Build Coastguard Worker #include <errno.h>
18*cd60bc56SAndroid Build Coastguard Worker #include <unistd.h>
19*cd60bc56SAndroid Build Coastguard Worker #include <inttypes.h>
20*cd60bc56SAndroid Build Coastguard Worker
21*cd60bc56SAndroid Build Coastguard Worker #include <libfdt_env.h>
22*cd60bc56SAndroid Build Coastguard Worker #include <fdt.h>
23*cd60bc56SAndroid Build Coastguard Worker
24*cd60bc56SAndroid Build Coastguard Worker #include "util.h"
25*cd60bc56SAndroid Build Coastguard Worker
26*cd60bc56SAndroid Build Coastguard Worker #ifdef DEBUG
27*cd60bc56SAndroid Build Coastguard Worker #define debug(...) printf(__VA_ARGS__)
28*cd60bc56SAndroid Build Coastguard Worker #else
29*cd60bc56SAndroid Build Coastguard Worker #define debug(...)
30*cd60bc56SAndroid Build Coastguard Worker #endif
31*cd60bc56SAndroid Build Coastguard Worker
32*cd60bc56SAndroid Build Coastguard Worker #define DEFAULT_FDT_VERSION 17
33*cd60bc56SAndroid Build Coastguard Worker
34*cd60bc56SAndroid Build Coastguard Worker /*
35*cd60bc56SAndroid Build Coastguard Worker * Command line options
36*cd60bc56SAndroid Build Coastguard Worker */
37*cd60bc56SAndroid Build Coastguard Worker extern int quiet; /* Level of quietness */
38*cd60bc56SAndroid Build Coastguard Worker extern unsigned int reservenum; /* Number of memory reservation slots */
39*cd60bc56SAndroid Build Coastguard Worker extern int minsize; /* Minimum blob size */
40*cd60bc56SAndroid Build Coastguard Worker extern int padsize; /* Additional padding to blob */
41*cd60bc56SAndroid Build Coastguard Worker extern int alignsize; /* Additional padding to blob accroding to the alignsize */
42*cd60bc56SAndroid Build Coastguard Worker extern int phandle_format; /* Use linux,phandle or phandle properties */
43*cd60bc56SAndroid Build Coastguard Worker extern int generate_symbols; /* generate symbols for nodes with labels */
44*cd60bc56SAndroid Build Coastguard Worker extern int generate_fixups; /* generate fixups */
45*cd60bc56SAndroid Build Coastguard Worker extern int auto_label_aliases; /* auto generate labels -> aliases */
46*cd60bc56SAndroid Build Coastguard Worker extern int annotate; /* annotate .dts with input source location */
47*cd60bc56SAndroid Build Coastguard Worker
48*cd60bc56SAndroid Build Coastguard Worker #define PHANDLE_LEGACY 0x1
49*cd60bc56SAndroid Build Coastguard Worker #define PHANDLE_EPAPR 0x2
50*cd60bc56SAndroid Build Coastguard Worker #define PHANDLE_BOTH 0x3
51*cd60bc56SAndroid Build Coastguard Worker
52*cd60bc56SAndroid Build Coastguard Worker typedef uint32_t cell_t;
53*cd60bc56SAndroid Build Coastguard Worker
phandle_is_valid(cell_t phandle)54*cd60bc56SAndroid Build Coastguard Worker static inline bool phandle_is_valid(cell_t phandle)
55*cd60bc56SAndroid Build Coastguard Worker {
56*cd60bc56SAndroid Build Coastguard Worker return phandle != 0 && phandle != ~0U;
57*cd60bc56SAndroid Build Coastguard Worker }
58*cd60bc56SAndroid Build Coastguard Worker
dtb_ld16(const void * p)59*cd60bc56SAndroid Build Coastguard Worker static inline uint16_t dtb_ld16(const void *p)
60*cd60bc56SAndroid Build Coastguard Worker {
61*cd60bc56SAndroid Build Coastguard Worker const uint8_t *bp = (const uint8_t *)p;
62*cd60bc56SAndroid Build Coastguard Worker
63*cd60bc56SAndroid Build Coastguard Worker return ((uint16_t)bp[0] << 8)
64*cd60bc56SAndroid Build Coastguard Worker | bp[1];
65*cd60bc56SAndroid Build Coastguard Worker }
66*cd60bc56SAndroid Build Coastguard Worker
dtb_ld32(const void * p)67*cd60bc56SAndroid Build Coastguard Worker static inline uint32_t dtb_ld32(const void *p)
68*cd60bc56SAndroid Build Coastguard Worker {
69*cd60bc56SAndroid Build Coastguard Worker const uint8_t *bp = (const uint8_t *)p;
70*cd60bc56SAndroid Build Coastguard Worker
71*cd60bc56SAndroid Build Coastguard Worker return ((uint32_t)bp[0] << 24)
72*cd60bc56SAndroid Build Coastguard Worker | ((uint32_t)bp[1] << 16)
73*cd60bc56SAndroid Build Coastguard Worker | ((uint32_t)bp[2] << 8)
74*cd60bc56SAndroid Build Coastguard Worker | bp[3];
75*cd60bc56SAndroid Build Coastguard Worker }
76*cd60bc56SAndroid Build Coastguard Worker
dtb_ld64(const void * p)77*cd60bc56SAndroid Build Coastguard Worker static inline uint64_t dtb_ld64(const void *p)
78*cd60bc56SAndroid Build Coastguard Worker {
79*cd60bc56SAndroid Build Coastguard Worker const uint8_t *bp = (const uint8_t *)p;
80*cd60bc56SAndroid Build Coastguard Worker
81*cd60bc56SAndroid Build Coastguard Worker return ((uint64_t)bp[0] << 56)
82*cd60bc56SAndroid Build Coastguard Worker | ((uint64_t)bp[1] << 48)
83*cd60bc56SAndroid Build Coastguard Worker | ((uint64_t)bp[2] << 40)
84*cd60bc56SAndroid Build Coastguard Worker | ((uint64_t)bp[3] << 32)
85*cd60bc56SAndroid Build Coastguard Worker | ((uint64_t)bp[4] << 24)
86*cd60bc56SAndroid Build Coastguard Worker | ((uint64_t)bp[5] << 16)
87*cd60bc56SAndroid Build Coastguard Worker | ((uint64_t)bp[6] << 8)
88*cd60bc56SAndroid Build Coastguard Worker | bp[7];
89*cd60bc56SAndroid Build Coastguard Worker }
90*cd60bc56SAndroid Build Coastguard Worker
91*cd60bc56SAndroid Build Coastguard Worker #define streq(a, b) (strcmp((a), (b)) == 0)
92*cd60bc56SAndroid Build Coastguard Worker #define strstarts(s, prefix) (strncmp((s), (prefix), strlen(prefix)) == 0)
93*cd60bc56SAndroid Build Coastguard Worker #define strprefixeq(a, n, b) (strlen(b) == (n) && (memcmp(a, b, n) == 0))
strends(const char * str,const char * suffix)94*cd60bc56SAndroid Build Coastguard Worker static inline bool strends(const char *str, const char *suffix)
95*cd60bc56SAndroid Build Coastguard Worker {
96*cd60bc56SAndroid Build Coastguard Worker unsigned int len, suffix_len;
97*cd60bc56SAndroid Build Coastguard Worker
98*cd60bc56SAndroid Build Coastguard Worker len = strlen(str);
99*cd60bc56SAndroid Build Coastguard Worker suffix_len = strlen(suffix);
100*cd60bc56SAndroid Build Coastguard Worker if (len < suffix_len)
101*cd60bc56SAndroid Build Coastguard Worker return false;
102*cd60bc56SAndroid Build Coastguard Worker return streq(str + len - suffix_len, suffix);
103*cd60bc56SAndroid Build Coastguard Worker }
104*cd60bc56SAndroid Build Coastguard Worker
105*cd60bc56SAndroid Build Coastguard Worker #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
106*cd60bc56SAndroid Build Coastguard Worker
107*cd60bc56SAndroid Build Coastguard Worker /* Data blobs */
108*cd60bc56SAndroid Build Coastguard Worker enum markertype {
109*cd60bc56SAndroid Build Coastguard Worker TYPE_NONE,
110*cd60bc56SAndroid Build Coastguard Worker REF_PHANDLE,
111*cd60bc56SAndroid Build Coastguard Worker REF_PATH,
112*cd60bc56SAndroid Build Coastguard Worker LABEL,
113*cd60bc56SAndroid Build Coastguard Worker TYPE_UINT8,
114*cd60bc56SAndroid Build Coastguard Worker TYPE_UINT16,
115*cd60bc56SAndroid Build Coastguard Worker TYPE_UINT32,
116*cd60bc56SAndroid Build Coastguard Worker TYPE_UINT64,
117*cd60bc56SAndroid Build Coastguard Worker TYPE_STRING,
118*cd60bc56SAndroid Build Coastguard Worker };
119*cd60bc56SAndroid Build Coastguard Worker
is_type_marker(enum markertype type)120*cd60bc56SAndroid Build Coastguard Worker static inline bool is_type_marker(enum markertype type)
121*cd60bc56SAndroid Build Coastguard Worker {
122*cd60bc56SAndroid Build Coastguard Worker return type >= TYPE_UINT8;
123*cd60bc56SAndroid Build Coastguard Worker }
124*cd60bc56SAndroid Build Coastguard Worker
125*cd60bc56SAndroid Build Coastguard Worker extern const char *markername(enum markertype markertype);
126*cd60bc56SAndroid Build Coastguard Worker
127*cd60bc56SAndroid Build Coastguard Worker struct marker {
128*cd60bc56SAndroid Build Coastguard Worker enum markertype type;
129*cd60bc56SAndroid Build Coastguard Worker unsigned int offset;
130*cd60bc56SAndroid Build Coastguard Worker char *ref;
131*cd60bc56SAndroid Build Coastguard Worker struct marker *next;
132*cd60bc56SAndroid Build Coastguard Worker };
133*cd60bc56SAndroid Build Coastguard Worker
134*cd60bc56SAndroid Build Coastguard Worker struct data {
135*cd60bc56SAndroid Build Coastguard Worker unsigned int len;
136*cd60bc56SAndroid Build Coastguard Worker char *val;
137*cd60bc56SAndroid Build Coastguard Worker struct marker *markers;
138*cd60bc56SAndroid Build Coastguard Worker };
139*cd60bc56SAndroid Build Coastguard Worker
140*cd60bc56SAndroid Build Coastguard Worker
141*cd60bc56SAndroid Build Coastguard Worker #define empty_data ((struct data){ 0 /* all .members = 0 or NULL */ })
142*cd60bc56SAndroid Build Coastguard Worker
143*cd60bc56SAndroid Build Coastguard Worker #define for_each_marker(m) \
144*cd60bc56SAndroid Build Coastguard Worker for (; (m); (m) = (m)->next)
145*cd60bc56SAndroid Build Coastguard Worker #define for_each_marker_of_type(m, t) \
146*cd60bc56SAndroid Build Coastguard Worker for_each_marker(m) \
147*cd60bc56SAndroid Build Coastguard Worker if ((m)->type == (t))
148*cd60bc56SAndroid Build Coastguard Worker
next_type_marker(struct marker * m)149*cd60bc56SAndroid Build Coastguard Worker static inline struct marker *next_type_marker(struct marker *m)
150*cd60bc56SAndroid Build Coastguard Worker {
151*cd60bc56SAndroid Build Coastguard Worker for_each_marker(m)
152*cd60bc56SAndroid Build Coastguard Worker if (is_type_marker(m->type))
153*cd60bc56SAndroid Build Coastguard Worker break;
154*cd60bc56SAndroid Build Coastguard Worker return m;
155*cd60bc56SAndroid Build Coastguard Worker }
156*cd60bc56SAndroid Build Coastguard Worker
type_marker_length(struct marker * m)157*cd60bc56SAndroid Build Coastguard Worker static inline size_t type_marker_length(struct marker *m)
158*cd60bc56SAndroid Build Coastguard Worker {
159*cd60bc56SAndroid Build Coastguard Worker struct marker *next = next_type_marker(m->next);
160*cd60bc56SAndroid Build Coastguard Worker
161*cd60bc56SAndroid Build Coastguard Worker if (next)
162*cd60bc56SAndroid Build Coastguard Worker return next->offset - m->offset;
163*cd60bc56SAndroid Build Coastguard Worker return 0;
164*cd60bc56SAndroid Build Coastguard Worker }
165*cd60bc56SAndroid Build Coastguard Worker
166*cd60bc56SAndroid Build Coastguard Worker void data_free(struct data d);
167*cd60bc56SAndroid Build Coastguard Worker
168*cd60bc56SAndroid Build Coastguard Worker struct data data_grow_for(struct data d, unsigned int xlen);
169*cd60bc56SAndroid Build Coastguard Worker
170*cd60bc56SAndroid Build Coastguard Worker struct data data_copy_mem(const char *mem, int len);
171*cd60bc56SAndroid Build Coastguard Worker struct data data_copy_escape_string(const char *s, int len);
172*cd60bc56SAndroid Build Coastguard Worker struct data data_copy_file(FILE *f, size_t len);
173*cd60bc56SAndroid Build Coastguard Worker
174*cd60bc56SAndroid Build Coastguard Worker struct data data_append_data(struct data d, const void *p, int len);
175*cd60bc56SAndroid Build Coastguard Worker struct data data_insert_at_marker(struct data d, struct marker *m,
176*cd60bc56SAndroid Build Coastguard Worker const void *p, int len);
177*cd60bc56SAndroid Build Coastguard Worker struct data data_merge(struct data d1, struct data d2);
178*cd60bc56SAndroid Build Coastguard Worker struct data data_append_cell(struct data d, cell_t word);
179*cd60bc56SAndroid Build Coastguard Worker struct data data_append_integer(struct data d, uint64_t word, int bits);
180*cd60bc56SAndroid Build Coastguard Worker struct data data_append_re(struct data d, uint64_t address, uint64_t size);
181*cd60bc56SAndroid Build Coastguard Worker struct data data_append_addr(struct data d, uint64_t addr);
182*cd60bc56SAndroid Build Coastguard Worker struct data data_append_byte(struct data d, uint8_t byte);
183*cd60bc56SAndroid Build Coastguard Worker struct data data_append_zeroes(struct data d, int len);
184*cd60bc56SAndroid Build Coastguard Worker struct data data_append_align(struct data d, int align);
185*cd60bc56SAndroid Build Coastguard Worker
186*cd60bc56SAndroid Build Coastguard Worker struct data data_add_marker(struct data d, enum markertype type, char *ref);
187*cd60bc56SAndroid Build Coastguard Worker
188*cd60bc56SAndroid Build Coastguard Worker bool data_is_one_string(struct data d);
189*cd60bc56SAndroid Build Coastguard Worker
190*cd60bc56SAndroid Build Coastguard Worker /* DT constraints */
191*cd60bc56SAndroid Build Coastguard Worker
192*cd60bc56SAndroid Build Coastguard Worker #define MAX_PROPNAME_LEN 31
193*cd60bc56SAndroid Build Coastguard Worker #define MAX_NODENAME_LEN 31
194*cd60bc56SAndroid Build Coastguard Worker
195*cd60bc56SAndroid Build Coastguard Worker /* Live trees */
196*cd60bc56SAndroid Build Coastguard Worker struct label {
197*cd60bc56SAndroid Build Coastguard Worker bool deleted;
198*cd60bc56SAndroid Build Coastguard Worker char *label;
199*cd60bc56SAndroid Build Coastguard Worker struct label *next;
200*cd60bc56SAndroid Build Coastguard Worker };
201*cd60bc56SAndroid Build Coastguard Worker
202*cd60bc56SAndroid Build Coastguard Worker struct bus_type {
203*cd60bc56SAndroid Build Coastguard Worker const char *name;
204*cd60bc56SAndroid Build Coastguard Worker };
205*cd60bc56SAndroid Build Coastguard Worker
206*cd60bc56SAndroid Build Coastguard Worker struct property {
207*cd60bc56SAndroid Build Coastguard Worker bool deleted;
208*cd60bc56SAndroid Build Coastguard Worker char *name;
209*cd60bc56SAndroid Build Coastguard Worker struct data val;
210*cd60bc56SAndroid Build Coastguard Worker
211*cd60bc56SAndroid Build Coastguard Worker struct property *next;
212*cd60bc56SAndroid Build Coastguard Worker
213*cd60bc56SAndroid Build Coastguard Worker struct label *labels;
214*cd60bc56SAndroid Build Coastguard Worker struct srcpos *srcpos;
215*cd60bc56SAndroid Build Coastguard Worker };
216*cd60bc56SAndroid Build Coastguard Worker
217*cd60bc56SAndroid Build Coastguard Worker struct node {
218*cd60bc56SAndroid Build Coastguard Worker bool deleted;
219*cd60bc56SAndroid Build Coastguard Worker char *name;
220*cd60bc56SAndroid Build Coastguard Worker struct property *proplist;
221*cd60bc56SAndroid Build Coastguard Worker struct node *children;
222*cd60bc56SAndroid Build Coastguard Worker
223*cd60bc56SAndroid Build Coastguard Worker struct node *parent;
224*cd60bc56SAndroid Build Coastguard Worker struct node *next_sibling;
225*cd60bc56SAndroid Build Coastguard Worker
226*cd60bc56SAndroid Build Coastguard Worker char *fullpath;
227*cd60bc56SAndroid Build Coastguard Worker int basenamelen;
228*cd60bc56SAndroid Build Coastguard Worker
229*cd60bc56SAndroid Build Coastguard Worker cell_t phandle;
230*cd60bc56SAndroid Build Coastguard Worker int addr_cells, size_cells;
231*cd60bc56SAndroid Build Coastguard Worker
232*cd60bc56SAndroid Build Coastguard Worker struct label *labels;
233*cd60bc56SAndroid Build Coastguard Worker const struct bus_type *bus;
234*cd60bc56SAndroid Build Coastguard Worker struct srcpos *srcpos;
235*cd60bc56SAndroid Build Coastguard Worker
236*cd60bc56SAndroid Build Coastguard Worker bool omit_if_unused, is_referenced;
237*cd60bc56SAndroid Build Coastguard Worker };
238*cd60bc56SAndroid Build Coastguard Worker
239*cd60bc56SAndroid Build Coastguard Worker #define for_each_label_withdel(l0, l) \
240*cd60bc56SAndroid Build Coastguard Worker for ((l) = (l0); (l); (l) = (l)->next)
241*cd60bc56SAndroid Build Coastguard Worker
242*cd60bc56SAndroid Build Coastguard Worker #define for_each_label(l0, l) \
243*cd60bc56SAndroid Build Coastguard Worker for_each_label_withdel(l0, l) \
244*cd60bc56SAndroid Build Coastguard Worker if (!(l)->deleted)
245*cd60bc56SAndroid Build Coastguard Worker
246*cd60bc56SAndroid Build Coastguard Worker #define for_each_property_withdel(n, p) \
247*cd60bc56SAndroid Build Coastguard Worker for ((p) = (n)->proplist; (p); (p) = (p)->next)
248*cd60bc56SAndroid Build Coastguard Worker
249*cd60bc56SAndroid Build Coastguard Worker #define for_each_property(n, p) \
250*cd60bc56SAndroid Build Coastguard Worker for_each_property_withdel(n, p) \
251*cd60bc56SAndroid Build Coastguard Worker if (!(p)->deleted)
252*cd60bc56SAndroid Build Coastguard Worker
253*cd60bc56SAndroid Build Coastguard Worker #define for_each_child_withdel(n, c) \
254*cd60bc56SAndroid Build Coastguard Worker for ((c) = (n)->children; (c); (c) = (c)->next_sibling)
255*cd60bc56SAndroid Build Coastguard Worker
256*cd60bc56SAndroid Build Coastguard Worker #define for_each_child(n, c) \
257*cd60bc56SAndroid Build Coastguard Worker for_each_child_withdel(n, c) \
258*cd60bc56SAndroid Build Coastguard Worker if (!(c)->deleted)
259*cd60bc56SAndroid Build Coastguard Worker
260*cd60bc56SAndroid Build Coastguard Worker void add_label(struct label **labels, char *label);
261*cd60bc56SAndroid Build Coastguard Worker void delete_labels(struct label **labels);
262*cd60bc56SAndroid Build Coastguard Worker
263*cd60bc56SAndroid Build Coastguard Worker struct property *build_property(char *name, struct data val,
264*cd60bc56SAndroid Build Coastguard Worker struct srcpos *srcpos);
265*cd60bc56SAndroid Build Coastguard Worker struct property *build_property_delete(char *name);
266*cd60bc56SAndroid Build Coastguard Worker struct property *chain_property(struct property *first, struct property *list);
267*cd60bc56SAndroid Build Coastguard Worker struct property *reverse_properties(struct property *first);
268*cd60bc56SAndroid Build Coastguard Worker
269*cd60bc56SAndroid Build Coastguard Worker struct node *build_node(struct property *proplist, struct node *children,
270*cd60bc56SAndroid Build Coastguard Worker struct srcpos *srcpos);
271*cd60bc56SAndroid Build Coastguard Worker struct node *build_node_delete(struct srcpos *srcpos);
272*cd60bc56SAndroid Build Coastguard Worker struct node *name_node(struct node *node, char *name);
273*cd60bc56SAndroid Build Coastguard Worker struct node *omit_node_if_unused(struct node *node);
274*cd60bc56SAndroid Build Coastguard Worker struct node *reference_node(struct node *node);
275*cd60bc56SAndroid Build Coastguard Worker struct node *chain_node(struct node *first, struct node *list);
276*cd60bc56SAndroid Build Coastguard Worker struct node *merge_nodes(struct node *old_node, struct node *new_node);
277*cd60bc56SAndroid Build Coastguard Worker struct node *add_orphan_node(struct node *old_node, struct node *new_node, char *ref);
278*cd60bc56SAndroid Build Coastguard Worker
279*cd60bc56SAndroid Build Coastguard Worker void add_property(struct node *node, struct property *prop);
280*cd60bc56SAndroid Build Coastguard Worker void delete_property_by_name(struct node *node, char *name);
281*cd60bc56SAndroid Build Coastguard Worker void delete_property(struct property *prop);
282*cd60bc56SAndroid Build Coastguard Worker void add_child(struct node *parent, struct node *child);
283*cd60bc56SAndroid Build Coastguard Worker void delete_node_by_name(struct node *parent, char *name);
284*cd60bc56SAndroid Build Coastguard Worker void delete_node(struct node *node);
285*cd60bc56SAndroid Build Coastguard Worker void append_to_property(struct node *node,
286*cd60bc56SAndroid Build Coastguard Worker char *name, const void *data, int len,
287*cd60bc56SAndroid Build Coastguard Worker enum markertype type);
288*cd60bc56SAndroid Build Coastguard Worker
289*cd60bc56SAndroid Build Coastguard Worker const char *get_unitname(struct node *node);
290*cd60bc56SAndroid Build Coastguard Worker struct property *get_property(struct node *node, const char *propname);
291*cd60bc56SAndroid Build Coastguard Worker cell_t propval_cell(struct property *prop);
292*cd60bc56SAndroid Build Coastguard Worker cell_t propval_cell_n(struct property *prop, unsigned int n);
293*cd60bc56SAndroid Build Coastguard Worker struct property *get_property_by_label(struct node *tree, const char *label,
294*cd60bc56SAndroid Build Coastguard Worker struct node **node);
295*cd60bc56SAndroid Build Coastguard Worker struct marker *get_marker_label(struct node *tree, const char *label,
296*cd60bc56SAndroid Build Coastguard Worker struct node **node, struct property **prop);
297*cd60bc56SAndroid Build Coastguard Worker struct node *get_subnode(struct node *node, const char *nodename);
298*cd60bc56SAndroid Build Coastguard Worker struct node *get_node_by_path(struct node *tree, const char *path);
299*cd60bc56SAndroid Build Coastguard Worker struct node *get_node_by_label(struct node *tree, const char *label);
300*cd60bc56SAndroid Build Coastguard Worker struct node *get_node_by_phandle(struct node *tree, cell_t phandle);
301*cd60bc56SAndroid Build Coastguard Worker struct node *get_node_by_ref(struct node *tree, const char *ref);
302*cd60bc56SAndroid Build Coastguard Worker cell_t get_node_phandle(struct node *root, struct node *node);
303*cd60bc56SAndroid Build Coastguard Worker
304*cd60bc56SAndroid Build Coastguard Worker uint32_t guess_boot_cpuid(struct node *tree);
305*cd60bc56SAndroid Build Coastguard Worker
306*cd60bc56SAndroid Build Coastguard Worker /* Boot info (tree plus memreserve information */
307*cd60bc56SAndroid Build Coastguard Worker
308*cd60bc56SAndroid Build Coastguard Worker struct reserve_info {
309*cd60bc56SAndroid Build Coastguard Worker uint64_t address, size;
310*cd60bc56SAndroid Build Coastguard Worker
311*cd60bc56SAndroid Build Coastguard Worker struct reserve_info *next;
312*cd60bc56SAndroid Build Coastguard Worker
313*cd60bc56SAndroid Build Coastguard Worker struct label *labels;
314*cd60bc56SAndroid Build Coastguard Worker };
315*cd60bc56SAndroid Build Coastguard Worker
316*cd60bc56SAndroid Build Coastguard Worker struct reserve_info *build_reserve_entry(uint64_t start, uint64_t len);
317*cd60bc56SAndroid Build Coastguard Worker struct reserve_info *chain_reserve_entry(struct reserve_info *first,
318*cd60bc56SAndroid Build Coastguard Worker struct reserve_info *list);
319*cd60bc56SAndroid Build Coastguard Worker struct reserve_info *add_reserve_entry(struct reserve_info *list,
320*cd60bc56SAndroid Build Coastguard Worker struct reserve_info *new);
321*cd60bc56SAndroid Build Coastguard Worker
322*cd60bc56SAndroid Build Coastguard Worker
323*cd60bc56SAndroid Build Coastguard Worker struct dt_info {
324*cd60bc56SAndroid Build Coastguard Worker unsigned int dtsflags;
325*cd60bc56SAndroid Build Coastguard Worker struct reserve_info *reservelist;
326*cd60bc56SAndroid Build Coastguard Worker uint32_t boot_cpuid_phys;
327*cd60bc56SAndroid Build Coastguard Worker struct node *dt; /* the device tree */
328*cd60bc56SAndroid Build Coastguard Worker const char *outname; /* filename being written to, "-" for stdout */
329*cd60bc56SAndroid Build Coastguard Worker };
330*cd60bc56SAndroid Build Coastguard Worker
331*cd60bc56SAndroid Build Coastguard Worker /* DTS version flags definitions */
332*cd60bc56SAndroid Build Coastguard Worker #define DTSF_V1 0x0001 /* /dts-v1/ */
333*cd60bc56SAndroid Build Coastguard Worker #define DTSF_PLUGIN 0x0002 /* /plugin/ */
334*cd60bc56SAndroid Build Coastguard Worker
335*cd60bc56SAndroid Build Coastguard Worker struct dt_info *build_dt_info(unsigned int dtsflags,
336*cd60bc56SAndroid Build Coastguard Worker struct reserve_info *reservelist,
337*cd60bc56SAndroid Build Coastguard Worker struct node *tree, uint32_t boot_cpuid_phys);
338*cd60bc56SAndroid Build Coastguard Worker void sort_tree(struct dt_info *dti);
339*cd60bc56SAndroid Build Coastguard Worker void generate_label_tree(struct dt_info *dti, char *name, bool allocph);
340*cd60bc56SAndroid Build Coastguard Worker void generate_fixups_tree(struct dt_info *dti, char *name);
341*cd60bc56SAndroid Build Coastguard Worker void generate_local_fixups_tree(struct dt_info *dti, char *name);
342*cd60bc56SAndroid Build Coastguard Worker
343*cd60bc56SAndroid Build Coastguard Worker /* Checks */
344*cd60bc56SAndroid Build Coastguard Worker
345*cd60bc56SAndroid Build Coastguard Worker void parse_checks_option(bool warn, bool error, const char *arg);
346*cd60bc56SAndroid Build Coastguard Worker void process_checks(bool force, struct dt_info *dti);
347*cd60bc56SAndroid Build Coastguard Worker
348*cd60bc56SAndroid Build Coastguard Worker /* Flattened trees */
349*cd60bc56SAndroid Build Coastguard Worker
350*cd60bc56SAndroid Build Coastguard Worker void dt_to_blob(FILE *f, struct dt_info *dti, int version);
351*cd60bc56SAndroid Build Coastguard Worker void dt_to_asm(FILE *f, struct dt_info *dti, int version);
352*cd60bc56SAndroid Build Coastguard Worker
353*cd60bc56SAndroid Build Coastguard Worker struct dt_info *dt_from_blob(const char *fname);
354*cd60bc56SAndroid Build Coastguard Worker
355*cd60bc56SAndroid Build Coastguard Worker /* Tree source */
356*cd60bc56SAndroid Build Coastguard Worker
357*cd60bc56SAndroid Build Coastguard Worker void dt_to_source(FILE *f, struct dt_info *dti);
358*cd60bc56SAndroid Build Coastguard Worker struct dt_info *dt_from_source(const char *f);
359*cd60bc56SAndroid Build Coastguard Worker
360*cd60bc56SAndroid Build Coastguard Worker /* YAML source */
361*cd60bc56SAndroid Build Coastguard Worker
362*cd60bc56SAndroid Build Coastguard Worker void dt_to_yaml(FILE *f, struct dt_info *dti);
363*cd60bc56SAndroid Build Coastguard Worker
364*cd60bc56SAndroid Build Coastguard Worker /* FS trees */
365*cd60bc56SAndroid Build Coastguard Worker
366*cd60bc56SAndroid Build Coastguard Worker struct dt_info *dt_from_fs(const char *dirname);
367*cd60bc56SAndroid Build Coastguard Worker
368*cd60bc56SAndroid Build Coastguard Worker #endif /* DTC_H */
369