blob: 45642dcee08027971b3def97b370eeb2d3ebf193 [file] [log] [blame]
David Gibsonfc14dad2005-06-08 17:18:34 +10001/*
2 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
3 *
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
19 */
20
21#include "dtc.h"
22
23/*
24 * Tree building functions
25 */
26
David Gibson4102d842005-06-16 14:36:37 +100027struct property *build_property(char *name, struct data val, char *label)
David Gibsonfc14dad2005-06-08 17:18:34 +100028{
29 struct property *new = xmalloc(sizeof(*new));
30
31 new->name = name;
32 new->val = val;
33
34 new->next = NULL;
35
David Gibson4102d842005-06-16 14:36:37 +100036 new->label = label;
37
David Gibsonfc14dad2005-06-08 17:18:34 +100038 return new;
39}
40
David Gibsonfc14dad2005-06-08 17:18:34 +100041struct property *chain_property(struct property *first, struct property *list)
42{
43 assert(first->next == NULL);
44
45 first->next = list;
46 return first;
47}
48
49struct node *build_node(struct property *proplist, struct node *children)
50{
51 struct node *new = xmalloc(sizeof(*new));
52 struct node *child;
53
54 memset(new, 0, sizeof(*new));
55
56 new->proplist = proplist;
57 new->children = children;
58
59 for_each_child(new, child) {
60 child->parent = new;
61 }
62
63 return new;
64}
65
David Gibson4102d842005-06-16 14:36:37 +100066struct node *name_node(struct node *node, char *name, char * label)
David Gibsonfc14dad2005-06-08 17:18:34 +100067{
68 assert(node->name == NULL);
69
70 node->name = name;
David Gibson4102d842005-06-16 14:36:37 +100071
72 node->label = label;
73
David Gibsonfc14dad2005-06-08 17:18:34 +100074 return node;
75}
76
77struct node *chain_node(struct node *first, struct node *list)
78{
79 assert(first->next_sibling == NULL);
80
81 first->next_sibling = list;
82 return first;
83}
84
85void add_property(struct node *node, struct property *prop)
86{
David Gibson740a19a2005-10-21 17:26:45 +100087 struct property **p;
88
89 prop->next = NULL;
90
91 p = &node->proplist;
92 while (*p)
93 p = &((*p)->next);
94
95 *p = prop;
David Gibsonfc14dad2005-06-08 17:18:34 +100096}
97
98void add_child(struct node *parent, struct node *child)
99{
David Gibson740a19a2005-10-21 17:26:45 +1000100 struct node **p;
101
102 child->next_sibling = NULL;
103
104 p = &parent->children;
105 while (*p)
106 p = &((*p)->next_sibling);
107
108 *p = child;
David Gibsonfc14dad2005-06-08 17:18:34 +1000109}
110
David Gibsonf040d952005-10-24 18:18:38 +1000111struct reserve_info *build_reserve_entry(u64 address, u64 size, char *label)
112{
113 struct reserve_info *new = xmalloc(sizeof(*new));
114
115 new->re.address = address;
116 new->re.size = size;
117
118 new->next = NULL;
119
120 new->label = label;
121
122 return new;
123}
124
125struct reserve_info *chain_reserve_entry(struct reserve_info *first,
126 struct reserve_info *list)
127{
128 assert(first->next == NULL);
129
130 first->next = list;
131 return first;
132}
133
134struct reserve_info *add_reserve_entry(struct reserve_info *list,
135 struct reserve_info *new)
136{
137 struct reserve_info *last;
138
139 new->next = NULL;
140
141 if (! list)
142 return new;
143
144 for (last = list; last->next; last = last->next)
145 ;
146
147 last->next = new;
148
149 return list;
150}
David Gibsonfc14dad2005-06-08 17:18:34 +1000151
152/*
153 * Tree accessor functions
154 */
155
David Gibson230f2532005-08-29 12:48:02 +1000156static char *get_unitname(struct node *node)
David Gibsonfc14dad2005-06-08 17:18:34 +1000157{
158 if (node->name[node->basenamelen] == '\0')
159 return "";
160 else
161 return node->name + node->basenamelen + 1;
162}
163
David Gibson230f2532005-08-29 12:48:02 +1000164static struct property *get_property(struct node *node, char *propname)
David Gibsonfc14dad2005-06-08 17:18:34 +1000165{
166 struct property *prop;
167
168 for_each_property(node, prop)
169 if (streq(prop->name, propname))
170 return prop;
171
172 return NULL;
173}
174
175static cell_t propval_cell(struct property *prop)
176{
177 assert(prop->val.len == sizeof(cell_t));
178 return be32_to_cpu(*((cell_t *)prop->val.val));
179}
180
181static struct node *get_subnode(struct node *node, char *nodename)
182{
183 struct node *child;
184
David Gibson81f2e892005-06-16 17:04:00 +1000185 for_each_child(node, child)
186 if (streq(child->name, nodename))
187 return child;
188
189 return NULL;
190}
191
192static struct node *get_node_by_path(struct node *tree, char *path)
193{
194 char *p;
195 struct node *child;
196
197 if (!path || ! (*path))
198 return tree;
199
200 while (path[0] == '/')
201 path++;
202
203 p = strchr(path, '/');
204
205 for_each_child(tree, child) {
206 if (p && strneq(path, child->name, p-path))
207 return get_node_by_path(child, p+1);
208 else if (!p && streq(path, child->name))
David Gibsonfc14dad2005-06-08 17:18:34 +1000209 return child;
210 }
211
212 return NULL;
213}
214
David Gibsonc226ddc2007-02-07 14:29:07 +1100215static struct node *get_node_by_label(struct node *tree, const char *label)
216{
217 struct node *child, *node;
218
219 assert(label && (strlen(label) > 0));
220
221 if (tree->label && streq(tree->label, label))
222 return tree;
223
224 for_each_child(tree, child) {
225 node = get_node_by_label(child, label);
226 if (node)
227 return node;
228 }
229
230 return NULL;
231}
232
David Gibsonfc14dad2005-06-08 17:18:34 +1000233static struct node *get_node_by_phandle(struct node *tree, cell_t phandle)
234{
235 struct node *child, *node;
236
237 assert((phandle != 0) && (phandle != -1));
238
239 if (tree->phandle == phandle)
240 return tree;
241
242 for_each_child(tree, child) {
243 node = get_node_by_phandle(child, phandle);
244 if (node)
245 return node;
246 }
247
248 return NULL;
249}
David Gibsonc226ddc2007-02-07 14:29:07 +1100250
David Gibsonfc14dad2005-06-08 17:18:34 +1000251/*
252 * Tree checking functions
253 */
254
Jerry Van Barencd1da872007-03-18 16:49:24 -0400255#define ERRMSG(...) if (quiet < 2) fprintf(stderr, "ERROR: " __VA_ARGS__)
256#define WARNMSG(...) if (quiet < 1) fprintf(stderr, "Warning: " __VA_ARGS__)
David Gibsonfc14dad2005-06-08 17:18:34 +1000257
258static int must_be_one_cell(struct property *prop, struct node *node)
259{
260 if (prop->val.len != sizeof(cell_t)) {
261 ERRMSG("\"%s\" property in %s has the wrong length (should be 1 cell)\n",
262 prop->name, node->fullpath);
263 return 0;
264 }
265
266 return 1;
267}
268
269static int must_be_cells(struct property *prop, struct node *node)
270{
271 if ((prop->val.len % sizeof(cell_t)) != 0) {
272 ERRMSG("\"%s\" property in %s is not a multiple of cell size\n",
273 prop->name, node->fullpath);
274 return 0;
275 }
276
277 return 1;
278}
279
280static int must_be_string(struct property *prop, struct node *node)
281{
282 if (! data_is_one_string(prop->val)) {
283 ERRMSG("\"%s\" property in %s is not a string\n",
284 prop->name, node->fullpath);
285 return 0;
286 }
287
288 return 1;
289}
290
291static int name_prop_check(struct property *prop, struct node *node)
292{
293 if ((prop->val.len != node->basenamelen+1)
David Gibson81f2e892005-06-16 17:04:00 +1000294 || !strneq(prop->val.val, node->name, node->basenamelen)) {
David Gibsonfc14dad2005-06-08 17:18:34 +1000295 ERRMSG("name property \"%s\" does not match node basename in %s\n",
296 prop->val.val,
297 node->fullpath);
298 return 0;
299 }
300
301 return 1;
302}
303
David Gibson230f2532005-08-29 12:48:02 +1000304static struct {
David Gibsonfc14dad2005-06-08 17:18:34 +1000305 char *propname;
306 int (*check_fn)(struct property *prop, struct node *node);
307} prop_checker_table[] = {
308 {"name", must_be_string},
309 {"name", name_prop_check},
310 {"linux,phandle", must_be_one_cell},
311 {"#address-cells", must_be_one_cell},
312 {"#size-cells", must_be_one_cell},
313 {"reg", must_be_cells},
314 {"model", must_be_string},
315 {"device_type", must_be_string},
316};
317
318#define DO_ERR(...) do {ERRMSG(__VA_ARGS__); ok = 0; } while (0)
319
320static int check_properties(struct node *node)
321{
322 struct property *prop, *prop2;
323 int ok = 1;
324
325 for_each_property(node, prop) {
326 int i;
327
328 /* check for duplicates */
329 /* FIXME: do this more efficiently */
330 for (prop2 = prop->next; prop2; prop2 = prop2->next) {
331 if (streq(prop->name, prop2->name)) {
332 DO_ERR("Duplicate propertyname %s in node %s\n",
333 prop->name, node->fullpath);
334 }
335 }
336
337
338 /* check name length */
339 if (strlen(prop->name) > MAX_PROPNAME_LEN)
David Gibsoncba839c2005-10-20 13:56:23 +1000340 WARNMSG("Property name %s is too long in %s\n",
341 prop->name, node->fullpath);
David Gibsonfc14dad2005-06-08 17:18:34 +1000342
343 /* check this property */
344 for (i = 0; i < ARRAY_SIZE(prop_checker_table); i++) {
345 if (streq(prop->name, prop_checker_table[i].propname))
346 if (! prop_checker_table[i].check_fn(prop, node)) {
347 ok = 0;
348 break;
349 }
350 }
351 }
352
353 return ok;
354}
355
356static int check_node_name(struct node *node)
357{
358 int ok = 1;
359 int len = strlen(node->name);
360
361 if (len == 0 && node->parent)
362 DO_ERR("Empty, non-root nodename at %s\n", node->fullpath);
363
364 if (len > MAX_NODENAME_LEN)
365 DO_ERR("Overlength nodename at %s\n", node->fullpath);
366
367
368 return ok;
369}
370
371static int check_structure(struct node *tree)
372{
373 struct node *child, *child2;
374 int ok = 1;
375
376 if (! check_node_name(tree))
377 ok = 0;
378
379 if (! check_properties(tree))
380 ok = 0;
381
382 for_each_child(tree, child) {
383 /* Check for duplicates */
384
385 for (child2 = child->next_sibling;
386 child2;
387 child2 = child2->next_sibling) {
388 if (streq(child->name, child2->name))
389 DO_ERR("Duplicate node name %s\n",
390 child->fullpath);
391 }
392 if (! check_structure(child))
393 ok = 0;
394 }
395
396 return ok;
397}
398
399#define CHECK_HAVE(node, propname) \
400 do { \
401 if (! (prop = get_property((node), (propname)))) \
402 DO_ERR("Missing \"%s\" property in %s\n", (propname), \
403 (node)->fullpath); \
404 } while (0);
405
406#define CHECK_HAVE_WARN(node, propname) \
407 do { \
408 if (! (prop = get_property((node), (propname)))) \
409 WARNMSG("%s has no \"%s\" property\n", \
410 (node)->fullpath, (propname)); \
411 } while (0)
412
413#define CHECK_HAVE_STRING(node, propname) \
414 do { \
415 CHECK_HAVE((node), (propname)); \
416 if (prop && !data_is_one_string(prop->val)) \
417 DO_ERR("\"%s\" property in %s is not a string\n", \
418 (propname), (node)->fullpath); \
419 } while (0)
420
421#define CHECK_HAVE_STREQ(node, propname, value) \
422 do { \
423 CHECK_HAVE_STRING((node), (propname)); \
424 if (prop && !streq(prop->val.val, (value))) \
425 DO_ERR("%s has wrong %s, %s (should be %s\n", \
426 (node)->fullpath, (propname), \
427 prop->val.val, (value)); \
428 } while (0)
429
430#define CHECK_HAVE_ONECELL(node, propname) \
431 do { \
432 CHECK_HAVE((node), (propname)); \
433 if (prop && (prop->val.len != sizeof(cell_t))) \
434 DO_ERR("\"%s\" property in %s has wrong size %d (should be 1 cell)\n", (propname), (node)->fullpath, prop->val.len); \
435 } while (0)
436
437#define CHECK_HAVE_WARN_ONECELL(node, propname) \
438 do { \
439 CHECK_HAVE_WARN((node), (propname)); \
440 if (prop && (prop->val.len != sizeof(cell_t))) \
441 DO_ERR("\"%s\" property in %s has wrong size %d (should be 1 cell)\n", (propname), (node)->fullpath, prop->val.len); \
442 } while (0)
443
444#define CHECK_HAVE_WARN_PHANDLE(xnode, propname, root) \
445 do { \
446 struct node *ref; \
447 CHECK_HAVE_WARN_ONECELL((xnode), (propname)); \
448 if (prop) {\
David Gibson54382392007-01-31 15:45:26 +1100449 cell_t phandle = propval_cell(prop); \
450 if ((phandle == 0) || (phandle == -1)) { \
451 DO_ERR("\"%s\" property in %s contains an invalid phandle %x\n", (propname), (xnode)->fullpath, phandle); \
452 } else { \
453 ref = get_node_by_phandle((root), propval_cell(prop)); \
454 if (! ref) \
455 DO_ERR("\"%s\" property in %s refers to non-existant phandle %x\n", (propname), (xnode)->fullpath, propval_cell(prop)); \
456 } \
David Gibsonfc14dad2005-06-08 17:18:34 +1000457 } \
458 } while (0)
459
460#define CHECK_HAVE_WARN_STRING(node, propname) \
461 do { \
462 CHECK_HAVE_WARN((node), (propname)); \
463 if (prop && !data_is_one_string(prop->val)) \
464 DO_ERR("\"%s\" property in %s is not a string\n", \
465 (propname), (node)->fullpath); \
466 } while (0)
467
468static int check_root(struct node *root)
469{
470 struct property *prop;
471 int ok = 1;
472
473 CHECK_HAVE_STRING(root, "model");
474
475 CHECK_HAVE(root, "#address-cells");
476 CHECK_HAVE(root, "#size-cells");
477
478 CHECK_HAVE_WARN(root, "compatible");
479
480 return ok;
481}
482
Michael Neuling38e8f8f2006-05-31 08:31:51 +1000483static int check_cpus(struct node *root, int outversion, int boot_cpuid_phys)
David Gibsonfc14dad2005-06-08 17:18:34 +1000484{
485 struct node *cpus, *cpu;
486 struct property *prop;
487 struct node *bootcpu = NULL;
488 int ok = 1;
489
490 cpus = get_subnode(root, "cpus");
491 if (! cpus) {
492 ERRMSG("Missing /cpus node\n");
493 return 0;
494 }
495
496 CHECK_HAVE_WARN(cpus, "#address-cells");
497 CHECK_HAVE_WARN(cpus, "#size-cells");
498
499 for_each_child(cpus, cpu) {
500 CHECK_HAVE_STREQ(cpu, "device_type", "cpu");
501
502 if (cpu->addr_cells != 1)
503 DO_ERR("%s has bad #address-cells value %d (should be 1)\n",
504 cpu->fullpath, cpu->addr_cells);
505 if (cpu->size_cells != 0)
506 DO_ERR("%s has bad #size-cells value %d (should be 0)\n",
507 cpu->fullpath, cpu->size_cells);
508
509 CHECK_HAVE_ONECELL(cpu, "reg");
510 if (prop) {
511 cell_t unitnum;
512 char *eptr;
513
514 unitnum = strtol(get_unitname(cpu), &eptr, 16);
Jerry Van Barencd1da872007-03-18 16:49:24 -0400515 if (*eptr) {
David Gibsonfc14dad2005-06-08 17:18:34 +1000516 WARNMSG("%s has bad format unit name %s (should be CPU number\n",
517 cpu->fullpath, get_unitname(cpu));
Jerry Van Barencd1da872007-03-18 16:49:24 -0400518 } else if (unitnum != propval_cell(prop)) {
David Gibsonfc14dad2005-06-08 17:18:34 +1000519 WARNMSG("%s unit name \"%s\" does not match \"reg\" property <%x>\n",
520 cpu->fullpath, get_unitname(cpu),
521 propval_cell(prop));
Jerry Van Barencd1da872007-03-18 16:49:24 -0400522 }
David Gibsonfc14dad2005-06-08 17:18:34 +1000523 }
524
525/* CHECK_HAVE_ONECELL(cpu, "d-cache-line-size"); */
526/* CHECK_HAVE_ONECELL(cpu, "i-cache-line-size"); */
527 CHECK_HAVE_ONECELL(cpu, "d-cache-size");
528 CHECK_HAVE_ONECELL(cpu, "i-cache-size");
529
530 CHECK_HAVE_WARN_ONECELL(cpu, "clock-frequency");
531 CHECK_HAVE_WARN_ONECELL(cpu, "timebase-frequency");
532
533 prop = get_property(cpu, "linux,boot-cpu");
534 if (prop) {
535 if (prop->val.len)
536 WARNMSG("\"linux,boot-cpu\" property in %s is non-empty\n",
537 cpu->fullpath);
538 if (bootcpu)
539 DO_ERR("Multiple boot cpus (%s and %s)\n",
540 bootcpu->fullpath, cpu->fullpath);
541 else
542 bootcpu = cpu;
543 }
544 }
545
Michael Neuling38e8f8f2006-05-31 08:31:51 +1000546 if (outversion < 2) {
547 if (! bootcpu)
548 WARNMSG("No cpu has \"linux,boot-cpu\" property\n");
549 } else {
550 if (bootcpu)
551 WARNMSG("\"linux,boot-cpu\" property is deprecated in blob version 2 or higher\n");
552 if (boot_cpuid_phys == 0xfeedbeef)
553 WARNMSG("physical boot CPU not set. Use -b option to set\n");
554 }
David Gibsonfc14dad2005-06-08 17:18:34 +1000555
556 return ok;
557}
558
559static int check_memory(struct node *root)
560{
561 struct node *mem;
562 struct property *prop;
563 int nnodes = 0;
564 int ok = 1;
565
566 for_each_child(root, mem) {
David Gibson81f2e892005-06-16 17:04:00 +1000567 if (! strneq(mem->name, "memory", mem->basenamelen))
David Gibsonfc14dad2005-06-08 17:18:34 +1000568 continue;
569
570 nnodes++;
571
572 CHECK_HAVE_STREQ(mem, "device_type", "memory");
573 CHECK_HAVE(mem, "reg");
574 }
575
576 if (nnodes == 0) {
577 ERRMSG("No memory nodes\n");
578 return 0;
579 }
580
581 return ok;
582}
583
584static int check_chosen(struct node *root)
585{
586 struct node *chosen;
587 struct property *prop;
588 int ok = 1;
589
590 chosen = get_subnode(root, "chosen");
591 if (! chosen) {
592 ERRMSG("Missing /chosen node\n");
593 return 0;
594 }
595
David Gibsonfc14dad2005-06-08 17:18:34 +1000596 CHECK_HAVE_WARN_STRING(chosen, "bootargs");
597 CHECK_HAVE_WARN_STRING(chosen, "linux,stdout-path");
David Gibsonfc14dad2005-06-08 17:18:34 +1000598
Stuart Yoder5ae78ad2007-02-19 11:28:27 -0600599 /* give warning for obsolete interrupt-controller property */
600 do {
601 if ((prop = get_property(chosen, "interrupt-controller")) != NULL) {
602 WARNMSG("%s has obsolete \"%s\" property\n",
603 chosen->fullpath, "interrupt-controller");
604 }
605 } while (0);
606
607 return ok;
David Gibsonfc14dad2005-06-08 17:18:34 +1000608}
609
610static int check_addr_size_reg(struct node *node,
611 int p_addr_cells, int p_size_cells)
612{
613 int addr_cells = p_addr_cells;
614 int size_cells = p_size_cells;
615 struct property *prop;
616 struct node *child;
617 int ok = 1;
618
619 node->addr_cells = addr_cells;
620 node->size_cells = size_cells;
621
622 prop = get_property(node, "reg");
623 if (prop) {
624 int len = prop->val.len / 4;
625
626 if ((len % (addr_cells+size_cells)) != 0)
627 DO_ERR("\"reg\" property in %s has invalid length (%d) for given #address-cells (%d) and #size-cells (%d)\n",
628 node->fullpath, prop->val.len,
629 addr_cells, size_cells);
630 }
631
632 prop = get_property(node, "#address-cells");
633 if (prop)
634 addr_cells = propval_cell(prop);
635
636 prop = get_property(node, "#size-cells");
637 if (prop)
638 size_cells = propval_cell(prop);
639
640 for_each_child(node, child) {
641 ok = ok && check_addr_size_reg(child, addr_cells, size_cells);
642 }
643
644 return ok;
645}
646
647static int check_phandles(struct node *root, struct node *node)
648{
649 struct property *prop;
650 struct node *child, *other;
651 cell_t phandle;
652 int ok = 1;
653
654 prop = get_property(node, "linux,phandle");
655 if (prop) {
656 phandle = propval_cell(prop);
657 if ((phandle == 0) || (phandle == -1)) {
658 DO_ERR("%s has invalid linux,phandle %x\n",
659 node->fullpath, phandle);
660 } else {
661 other = get_node_by_phandle(root, phandle);
662 if (other)
663 DO_ERR("%s has duplicated phandle %x (seen before at %s)\n",
664 node->fullpath, phandle, other->fullpath);
665
666 node->phandle = phandle;
667 }
668 }
669
670 for_each_child(node, child)
671 ok = ok && check_phandles(root, child);
672
673 return 1;
674}
675
David Gibson81f2e892005-06-16 17:04:00 +1000676static cell_t get_node_phandle(struct node *root, struct node *node)
677{
678 static cell_t phandle = 1; /* FIXME: ick, static local */
679
David Gibson81f2e892005-06-16 17:04:00 +1000680 if ((node->phandle != 0) && (node->phandle != -1))
681 return node->phandle;
682
683 assert(! get_property(node, "linux,phandle"));
684
685 while (get_node_by_phandle(root, phandle))
686 phandle++;
687
688 node->phandle = phandle;
689 add_property(node,
690 build_property("linux,phandle",
691 data_append_cell(empty_data, phandle),
692 NULL));
693
694 return node->phandle;
695}
696
697static void apply_fixup(struct node *root, struct property *prop,
698 struct fixup *f)
699{
700 struct node *refnode;
701 cell_t phandle;
702
David Gibsonc226ddc2007-02-07 14:29:07 +1100703 if (f->ref[0] == '/') {
704 /* Reference to full path */
705 refnode = get_node_by_path(root, f->ref);
706 if (! refnode)
707 die("Reference to non-existent node \"%s\"\n", f->ref);
708 } else {
709 refnode = get_node_by_label(root, f->ref);
710 if (! refnode)
711 die("Reference to non-existent node label \"%s\"\n", f->ref);
712 }
David Gibson81f2e892005-06-16 17:04:00 +1000713
714 phandle = get_node_phandle(root, refnode);
715
716 assert(f->offset + sizeof(cell_t) <= prop->val.len);
717
718 *((cell_t *)(prop->val.val + f->offset)) = cpu_to_be32(phandle);
719}
720
721static void fixup_phandles(struct node *root, struct node *node)
722{
723 struct property *prop;
724 struct node *child;
725
726 for_each_property(node, prop) {
727 struct fixup *f = prop->val.refs;
728
729 while (f) {
730 apply_fixup(root, prop, f);
731 prop->val.refs = f->next;
732 fixup_free(f);
733 f = prop->val.refs;
734 }
735 }
736
737 for_each_child(node, child)
738 fixup_phandles(root, child);
739}
740
Michael Neuling38e8f8f2006-05-31 08:31:51 +1000741int check_device_tree(struct node *dt, int outversion, int boot_cpuid_phys)
David Gibsonfc14dad2005-06-08 17:18:34 +1000742{
743 int ok = 1;
744
745 if (! check_structure(dt))
746 return 0;
747
748 ok = ok && check_addr_size_reg(dt, -1, -1);
749 ok = ok && check_phandles(dt, dt);
750
David Gibson81f2e892005-06-16 17:04:00 +1000751 fixup_phandles(dt, dt);
752
David Gibsonfc14dad2005-06-08 17:18:34 +1000753 if (! ok)
754 return 0;
755
756 ok = ok && check_root(dt);
Michael Neuling38e8f8f2006-05-31 08:31:51 +1000757 ok = ok && check_cpus(dt, outversion, boot_cpuid_phys);
David Gibsonfc14dad2005-06-08 17:18:34 +1000758 ok = ok && check_memory(dt);
759 ok = ok && check_chosen(dt);
760 if (! ok)
761 return 0;
762
763 return 1;
764}
David Gibsonf0517db2005-07-15 17:14:24 +1000765
David Gibsonf040d952005-10-24 18:18:38 +1000766struct boot_info *build_boot_info(struct reserve_info *reservelist,
David Gibsonf0517db2005-07-15 17:14:24 +1000767 struct node *tree)
768{
769 struct boot_info *bi;
770
771 bi = xmalloc(sizeof(*bi));
David Gibsonf040d952005-10-24 18:18:38 +1000772 bi->reservelist = reservelist;
David Gibsonf0517db2005-07-15 17:14:24 +1000773 bi->dt = tree;
774
775 return bi;
776}