blob: ce73f50d3b2b4971d160282fe5c43b0a02bc88e0 [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");
Scott Woodb29597d2007-03-22 11:11:09 -0500591 if (!chosen)
592 return ok;
David Gibsonfc14dad2005-06-08 17:18:34 +1000593
Stuart Yoder5ae78ad2007-02-19 11:28:27 -0600594 /* give warning for obsolete interrupt-controller property */
595 do {
596 if ((prop = get_property(chosen, "interrupt-controller")) != NULL) {
597 WARNMSG("%s has obsolete \"%s\" property\n",
598 chosen->fullpath, "interrupt-controller");
599 }
600 } while (0);
601
602 return ok;
David Gibsonfc14dad2005-06-08 17:18:34 +1000603}
604
605static int check_addr_size_reg(struct node *node,
606 int p_addr_cells, int p_size_cells)
607{
608 int addr_cells = p_addr_cells;
609 int size_cells = p_size_cells;
610 struct property *prop;
611 struct node *child;
612 int ok = 1;
613
614 node->addr_cells = addr_cells;
615 node->size_cells = size_cells;
616
617 prop = get_property(node, "reg");
618 if (prop) {
619 int len = prop->val.len / 4;
620
621 if ((len % (addr_cells+size_cells)) != 0)
622 DO_ERR("\"reg\" property in %s has invalid length (%d) for given #address-cells (%d) and #size-cells (%d)\n",
623 node->fullpath, prop->val.len,
624 addr_cells, size_cells);
625 }
626
627 prop = get_property(node, "#address-cells");
628 if (prop)
629 addr_cells = propval_cell(prop);
630
631 prop = get_property(node, "#size-cells");
632 if (prop)
633 size_cells = propval_cell(prop);
634
635 for_each_child(node, child) {
636 ok = ok && check_addr_size_reg(child, addr_cells, size_cells);
637 }
638
639 return ok;
640}
641
642static int check_phandles(struct node *root, struct node *node)
643{
644 struct property *prop;
645 struct node *child, *other;
646 cell_t phandle;
647 int ok = 1;
648
649 prop = get_property(node, "linux,phandle");
650 if (prop) {
651 phandle = propval_cell(prop);
652 if ((phandle == 0) || (phandle == -1)) {
653 DO_ERR("%s has invalid linux,phandle %x\n",
654 node->fullpath, phandle);
655 } else {
656 other = get_node_by_phandle(root, phandle);
657 if (other)
658 DO_ERR("%s has duplicated phandle %x (seen before at %s)\n",
659 node->fullpath, phandle, other->fullpath);
660
661 node->phandle = phandle;
662 }
663 }
664
665 for_each_child(node, child)
666 ok = ok && check_phandles(root, child);
667
668 return 1;
669}
670
David Gibson81f2e892005-06-16 17:04:00 +1000671static cell_t get_node_phandle(struct node *root, struct node *node)
672{
673 static cell_t phandle = 1; /* FIXME: ick, static local */
674
David Gibson81f2e892005-06-16 17:04:00 +1000675 if ((node->phandle != 0) && (node->phandle != -1))
676 return node->phandle;
677
678 assert(! get_property(node, "linux,phandle"));
679
680 while (get_node_by_phandle(root, phandle))
681 phandle++;
682
683 node->phandle = phandle;
684 add_property(node,
685 build_property("linux,phandle",
686 data_append_cell(empty_data, phandle),
687 NULL));
688
689 return node->phandle;
690}
691
692static void apply_fixup(struct node *root, struct property *prop,
693 struct fixup *f)
694{
695 struct node *refnode;
696 cell_t phandle;
697
David Gibsonc226ddc2007-02-07 14:29:07 +1100698 if (f->ref[0] == '/') {
699 /* Reference to full path */
700 refnode = get_node_by_path(root, f->ref);
701 if (! refnode)
702 die("Reference to non-existent node \"%s\"\n", f->ref);
703 } else {
704 refnode = get_node_by_label(root, f->ref);
705 if (! refnode)
706 die("Reference to non-existent node label \"%s\"\n", f->ref);
707 }
David Gibson81f2e892005-06-16 17:04:00 +1000708
709 phandle = get_node_phandle(root, refnode);
710
711 assert(f->offset + sizeof(cell_t) <= prop->val.len);
712
713 *((cell_t *)(prop->val.val + f->offset)) = cpu_to_be32(phandle);
714}
715
716static void fixup_phandles(struct node *root, struct node *node)
717{
718 struct property *prop;
719 struct node *child;
720
721 for_each_property(node, prop) {
722 struct fixup *f = prop->val.refs;
723
724 while (f) {
725 apply_fixup(root, prop, f);
726 prop->val.refs = f->next;
727 fixup_free(f);
728 f = prop->val.refs;
729 }
730 }
731
732 for_each_child(node, child)
733 fixup_phandles(root, child);
734}
735
Michael Neuling38e8f8f2006-05-31 08:31:51 +1000736int check_device_tree(struct node *dt, int outversion, int boot_cpuid_phys)
David Gibsonfc14dad2005-06-08 17:18:34 +1000737{
738 int ok = 1;
739
740 if (! check_structure(dt))
741 return 0;
742
743 ok = ok && check_addr_size_reg(dt, -1, -1);
744 ok = ok && check_phandles(dt, dt);
745
David Gibson81f2e892005-06-16 17:04:00 +1000746 fixup_phandles(dt, dt);
747
David Gibsonfc14dad2005-06-08 17:18:34 +1000748 if (! ok)
749 return 0;
750
751 ok = ok && check_root(dt);
Michael Neuling38e8f8f2006-05-31 08:31:51 +1000752 ok = ok && check_cpus(dt, outversion, boot_cpuid_phys);
David Gibsonfc14dad2005-06-08 17:18:34 +1000753 ok = ok && check_memory(dt);
754 ok = ok && check_chosen(dt);
755 if (! ok)
756 return 0;
757
758 return 1;
759}
David Gibsonf0517db2005-07-15 17:14:24 +1000760
David Gibsonf040d952005-10-24 18:18:38 +1000761struct boot_info *build_boot_info(struct reserve_info *reservelist,
David Gibsonf0517db2005-07-15 17:14:24 +1000762 struct node *tree)
763{
764 struct boot_info *bi;
765
766 bi = xmalloc(sizeof(*bi));
David Gibsonf040d952005-10-24 18:18:38 +1000767 bi->reservelist = reservelist;
David Gibsonf0517db2005-07-15 17:14:24 +1000768 bi->dt = tree;
769
770 return bi;
771}