blob: b5937e35f7abe1abff3cf262bd76140fa03c1ef0 [file] [log] [blame]
Wolfgang Denk814d98f2005-10-13 01:59:29 +02001/*
2 * OF flat tree builder
Matthew McClintock1b380ec2006-06-28 10:42:24 -05003 * Written by: Pantelis Antoniou <pantelis.antoniou@gmail.com>
4 * Updated by: Matthew McClintock <msm@freescale.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19 * MA 02111-1307 USA
Wolfgang Denk814d98f2005-10-13 01:59:29 +020020 */
21
22#include <common.h>
23#include <malloc.h>
24#include <environment.h>
25
Marian Balakowiczfe934832005-10-28 18:08:03 +020026#ifdef CONFIG_OF_FLAT_TREE
27
Wolfgang Denk814d98f2005-10-13 01:59:29 +020028#include <asm/errno.h>
29#include <stddef.h>
30
31#include <ft_build.h>
32
Matthew McClintock1b380ec2006-06-28 10:42:24 -050033#undef DEBUG
34
Wolfgang Denk814d98f2005-10-13 01:59:29 +020035/* align addr on a size boundary - adjust address up if needed -- Cort */
36#define _ALIGN(addr,size) (((addr)+(size)-1)&(~((size)-1)))
Matthew McClintock1b380ec2006-06-28 10:42:24 -050037#ifndef CONFIG_OF_BOOT_CPU
38#define CONFIG_OF_BOOT_CPU 0
39#endif
40#define SIZE_OF_RSVMAP_ENTRY (2*sizeof(u64))
Wolfgang Denk814d98f2005-10-13 01:59:29 +020041
42static void ft_put_word(struct ft_cxt *cxt, u32 v)
43{
Matthew McClintock1b380ec2006-06-28 10:42:24 -050044 memmove(cxt->p + sizeof(u32), cxt->p, cxt->p_end - cxt->p);
Wolfgang Denk814d98f2005-10-13 01:59:29 +020045
46 *(u32 *) cxt->p = cpu_to_be32(v);
Matthew McClintock1b380ec2006-06-28 10:42:24 -050047 cxt->p += sizeof(u32);
48 cxt->p_end += sizeof(u32);
Wolfgang Denk814d98f2005-10-13 01:59:29 +020049}
50
51static inline void ft_put_bin(struct ft_cxt *cxt, const void *data, int sz)
52{
Matthew McClintock1b380ec2006-06-28 10:42:24 -050053 int aligned_size = ((u8 *)_ALIGN((unsigned long)cxt->p + sz,
54 sizeof(u32))) - cxt->p;
Wolfgang Denk814d98f2005-10-13 01:59:29 +020055
Matthew McClintock1b380ec2006-06-28 10:42:24 -050056 memmove(cxt->p + aligned_size, cxt->p, cxt->p_end - cxt->p);
Wolfgang Denk814d98f2005-10-13 01:59:29 +020057
Matthew McClintock1b380ec2006-06-28 10:42:24 -050058 /* make sure the last bytes are zeroed */
59 memset(cxt->p + aligned_size - (aligned_size % sizeof(u32)), 0,
60 (aligned_size % sizeof(u32)));
Wolfgang Denk814d98f2005-10-13 01:59:29 +020061
62 memcpy(cxt->p, data, sz);
Matthew McClintock1b380ec2006-06-28 10:42:24 -050063
64 cxt->p += aligned_size;
65 cxt->p_end += aligned_size;
Wolfgang Denk814d98f2005-10-13 01:59:29 +020066}
67
68void ft_begin_node(struct ft_cxt *cxt, const char *name)
69{
70 ft_put_word(cxt, OF_DT_BEGIN_NODE);
71 ft_put_bin(cxt, name, strlen(name) + 1);
72}
73
74void ft_end_node(struct ft_cxt *cxt)
75{
76 ft_put_word(cxt, OF_DT_END_NODE);
77}
78
79void ft_nop(struct ft_cxt *cxt)
80{
81 ft_put_word(cxt, OF_DT_NOP);
82}
83
84static int lookup_string(struct ft_cxt *cxt, const char *name)
85{
86 u8 *p;
87
Matthew McClintock1b380ec2006-06-28 10:42:24 -050088 p = cxt->p;
89 while (p < cxt->p_end) {
Wolfgang Denk814d98f2005-10-13 01:59:29 +020090 if (strcmp(p, name) == 0)
Matthew McClintock1b380ec2006-06-28 10:42:24 -050091 return p - cxt->p;
Wolfgang Denk814d98f2005-10-13 01:59:29 +020092 p += strlen(p) + 1;
93 }
94
95 return -1;
96}
97
98void ft_prop(struct ft_cxt *cxt, const char *name, const void *data, int sz)
99{
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500100 int off = 0;
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200101
102 off = lookup_string(cxt, name);
103 if (off == -1) {
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500104 memcpy(cxt->p_end, name, strlen(name) + 1);
105 off = cxt->p_end - cxt->p;
Zhang Wei88c8f492006-08-28 14:25:31 +0800106 cxt->p_end += strlen(name) + 1;
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200107 }
108
109 /* now put offset from beginning of *STRUCTURE* */
110 /* will be fixed up at the end */
111 ft_put_word(cxt, OF_DT_PROP);
112 ft_put_word(cxt, sz);
113 ft_put_word(cxt, off);
114 ft_put_bin(cxt, data, sz);
115}
116
117void ft_prop_str(struct ft_cxt *cxt, const char *name, const char *str)
118{
119 ft_prop(cxt, name, str, strlen(str) + 1);
120}
121
122void ft_prop_int(struct ft_cxt *cxt, const char *name, int val)
123{
124 u32 v = cpu_to_be32((u32) val);
125
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500126 ft_prop(cxt, name, &v, sizeof(u32));
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200127}
128
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500129/* pick up and start working on a tree in place */
130void ft_init_cxt(struct ft_cxt *cxt, void *blob)
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200131{
132 struct boot_param_header *bph = blob;
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200133
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200134 memset(cxt, 0, sizeof(*cxt));
135
136 cxt->bph = bph;
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500137 bph->boot_cpuid_phys = CONFIG_OF_BOOT_CPU;
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200138
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500139 /* find beginning and end of reserve map table (zeros in last entry) */
140 cxt->p_rsvmap = (u8 *)bph + bph->off_mem_rsvmap;
141 while ( ((uint64_t *)cxt->p_rsvmap)[0] != 0 &&
142 ((uint64_t *)cxt->p_rsvmap)[1] != 0 ) {
143 cxt->p_rsvmap += SIZE_OF_RSVMAP_ENTRY;
144 }
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200145
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500146 cxt->p_start = (char*)bph + bph->off_dt_struct;
147 cxt->p_end = (char *)bph + bph->totalsize;
148 cxt->p = (char *)bph + bph->off_dt_strings;
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200149}
150
151/* add a reserver physical area to the rsvmap */
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500152void ft_add_rsvmap(struct ft_cxt *cxt, u64 physstart, u64 physend)
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200153{
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500154 memmove(cxt->p_rsvmap + SIZE_OF_RSVMAP_ENTRY, cxt->p_rsvmap,
155 cxt->p_end - cxt->p_rsvmap);
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200156
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500157 ((u64 *)cxt->p_rsvmap)[0] = cpu_to_be64(physstart);
158 ((u64 *)cxt->p_rsvmap)[1] = cpu_to_be64(physend);
159 ((u64 *)cxt->p_rsvmap)[2] = 0;
160 ((u64 *)cxt->p_rsvmap)[3] = 0;
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200161
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500162 cxt->p_rsvmap += SIZE_OF_RSVMAP_ENTRY;
163 cxt->p_start += SIZE_OF_RSVMAP_ENTRY;
164 cxt->p += SIZE_OF_RSVMAP_ENTRY;
165 cxt->p_end += SIZE_OF_RSVMAP_ENTRY;
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200166}
167
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500168void ft_end_tree(struct ft_cxt *cxt)
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200169{
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200170 ft_put_word(cxt, OF_DT_END);
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200171}
172
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500173/* update the boot param header with correct values */
174void ft_finalize_tree(struct ft_cxt *cxt) {
175 struct boot_param_header *bph = cxt->bph;
176
177 bph->totalsize = cxt->p_end - (u8 *)bph;
178 bph->off_dt_struct = cxt->p_start - (u8 *)bph;
179 bph->off_dt_strings = cxt->p - (u8 *)bph;
180 bph->dt_strings_size = cxt->p_end - cxt->p;
181}
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200182
183static inline int isprint(int c)
184{
185 return c >= 0x20 && c <= 0x7e;
186}
187
188static int is_printable_string(const void *data, int len)
189{
190 const char *s = data;
191 const char *ss;
192
193 /* zero length is not */
194 if (len == 0)
195 return 0;
196
197 /* must terminate with zero */
198 if (s[len - 1] != '\0')
199 return 0;
200
201 ss = s;
202 while (*s && isprint(*s))
203 s++;
204
205 /* not zero, or not done yet */
206 if (*s != '\0' || (s + 1 - ss) < len)
207 return 0;
208
209 return 1;
210}
211
212static void print_data(const void *data, int len)
213{
214 int i;
215 const u8 *s;
216
217 /* no data, don't print */
218 if (len == 0)
219 return;
220
221 if (is_printable_string(data, len)) {
222 printf(" = \"%s\"", (char *)data);
223 return;
224 }
225
226 switch (len) {
227 case 1: /* byte */
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500228 printf(" = <%02x>", (*(u8 *) data) & 0xff);
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200229 break;
230 case 2: /* half-word */
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500231 printf(" = <%04x>", be16_to_cpu(*(u16 *) data) & 0xffff);
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200232 break;
233 case 4: /* word */
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500234 printf(" = <%x>", be32_to_cpu(*(u32 *) data) & 0xffffffffU);
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200235 break;
236 case 8: /* double-word */
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500237 printf(" = <%qx>", be64_to_cpu(*(uint64_t *) data));
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200238 break;
239 default: /* anything else... hexdump */
240 printf(" = [");
241 for (i = 0, s = data; i < len; i++)
242 printf("%02x%s", s[i], i < len - 1 ? " " : "");
243 printf("]");
244
245 break;
246 }
247}
248
249void ft_dump_blob(const void *bphp)
250{
251 const struct boot_param_header *bph = bphp;
252 const uint64_t *p_rsvmap = (const uint64_t *)
253 ((const char *)bph + be32_to_cpu(bph->off_mem_rsvmap));
254 const u32 *p_struct = (const u32 *)
255 ((const char *)bph + be32_to_cpu(bph->off_dt_struct));
256 const u32 *p_strings = (const u32 *)
257 ((const char *)bph + be32_to_cpu(bph->off_dt_strings));
258 u32 tag;
259 const u32 *p;
260 const char *s, *t;
261 int depth, sz, shift;
262 int i;
263 uint64_t addr, size;
264
265 if (be32_to_cpu(bph->magic) != OF_DT_HEADER) {
266 /* not valid tree */
267 return;
268 }
269
270 depth = 0;
271 shift = 4;
272
273 for (i = 0;; i++) {
274 addr = be64_to_cpu(p_rsvmap[i * 2]);
275 size = be64_to_cpu(p_rsvmap[i * 2 + 1]);
276 if (addr == 0 && size == 0)
277 break;
278
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500279 printf("/memreserve/ %qx %qx;\n", addr, size);
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200280 }
281
282 p = p_struct;
283 while ((tag = be32_to_cpu(*p++)) != OF_DT_END) {
284
285 /* printf("tag: 0x%08x (%d)\n", tag, p - p_struct); */
286
287 if (tag == OF_DT_BEGIN_NODE) {
288 s = (const char *)p;
289 p = (u32 *) _ALIGN((unsigned long)p + strlen(s) + 1, 4);
290
291 printf("%*s%s {\n", depth * shift, "", s);
292
293 depth++;
294 continue;
295 }
296
297 if (tag == OF_DT_END_NODE) {
298 depth--;
299
300 printf("%*s};\n", depth * shift, "");
301 continue;
302 }
303
304 if (tag == OF_DT_NOP) {
305 printf("%*s[NOP]\n", depth * shift, "");
306 continue;
307 }
308
309 if (tag != OF_DT_PROP) {
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500310 fprintf(stderr, "%*s ** Unknown tag 0x%08x at 0x%x\n",
311 depth * shift, "", tag, --p);
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200312 break;
313 }
314 sz = be32_to_cpu(*p++);
315 s = (const char *)p_strings + be32_to_cpu(*p++);
316 t = (const char *)p;
317 p = (const u32 *)_ALIGN((unsigned long)p + sz, 4);
318 printf("%*s%s", depth * shift, "", s);
319 print_data(t, sz);
320 printf(";\n");
321 }
322}
323
324void ft_backtrack_node(struct ft_cxt *cxt)
325{
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500326 int i = 4;
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200327
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500328 while (be32_to_cpu(*(u32 *) (cxt->p - i)) != OF_DT_END_NODE)
329 i += 4;
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200330
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500331 memmove (cxt->p - i, cxt->p, cxt->p_end - cxt->p);
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200332
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500333 cxt->p_end -= i;
334 cxt->p -= i;
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200335}
336
337void *ft_get_prop(void *bphp, const char *propname, int *szp)
338{
339 struct boot_param_header *bph = bphp;
340 uint32_t *p_struct =
341 (uint32_t *) ((char *)bph + be32_to_cpu(bph->off_dt_struct));
342 uint32_t *p_strings =
343 (uint32_t *) ((char *)bph + be32_to_cpu(bph->off_dt_strings));
344 uint32_t version = be32_to_cpu(bph->version);
345 uint32_t tag;
346 uint32_t *p;
347 char *s, *t;
348 char *ss;
349 int sz;
350 static char path[256], prop[256];
351
352 path[0] = '\0';
353
354 p = p_struct;
355 while ((tag = be32_to_cpu(*p++)) != OF_DT_END) {
356
357 if (tag == OF_DT_BEGIN_NODE) {
358 s = (char *)p;
359 p = (uint32_t *) _ALIGN((unsigned long)p + strlen(s) +
360 1, 4);
361 strcat(path, s);
362 strcat(path, "/");
363 continue;
364 }
365
366 if (tag == OF_DT_END_NODE) {
367 path[strlen(path) - 1] = '\0';
368 ss = strrchr(path, '/');
369 if (ss != NULL)
370 ss[1] = '\0';
371 continue;
372 }
373
374 if (tag == OF_DT_NOP)
375 continue;
376
377 if (tag != OF_DT_PROP)
378 break;
379
380 sz = be32_to_cpu(*p++);
381 s = (char *)p_strings + be32_to_cpu(*p++);
382 if (version < 0x10 && sz >= 8)
383 p = (uint32_t *) _ALIGN((unsigned long)p, 8);
384 t = (char *)p;
385 p = (uint32_t *) _ALIGN((unsigned long)p + sz, 4);
386
387 strcpy(prop, path);
388 strcat(prop, s);
389
390 if (strcmp(prop, propname) == 0) {
391 *szp = sz;
392 return t;
393 }
394 }
395
396 return NULL;
397}
398
399/********************************************************************/
400
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200401/* Function that returns a character from the environment */
402extern uchar(*env_get_char) (int);
403
404#define BDM(x) { .name = #x, .offset = offsetof(bd_t, bi_ ##x ) }
405
Kumar Galae4f880e2006-01-11 13:49:31 -0600406#ifdef CONFIG_OF_HAS_BD_T
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200407static const struct {
408 const char *name;
409 int offset;
410} bd_map[] = {
411 BDM(memstart),
412 BDM(memsize),
413 BDM(flashstart),
414 BDM(flashsize),
415 BDM(flashoffset),
416 BDM(sramstart),
417 BDM(sramsize),
418#if defined(CONFIG_5xx) || defined(CONFIG_8xx) || defined(CONFIG_8260) \
419 || defined(CONFIG_E500)
420 BDM(immr_base),
421#endif
422#if defined(CONFIG_MPC5xxx)
423 BDM(mbar_base),
424#endif
425#if defined(CONFIG_MPC83XX)
426 BDM(immrbar),
427#endif
428#if defined(CONFIG_MPC8220)
429 BDM(mbar_base),
430 BDM(inpfreq),
431 BDM(pcifreq),
432 BDM(pevfreq),
433 BDM(flbfreq),
434 BDM(vcofreq),
435#endif
436 BDM(bootflags),
437 BDM(ip_addr),
438 BDM(intfreq),
439 BDM(busfreq),
440#ifdef CONFIG_CPM2
441 BDM(cpmfreq),
442 BDM(brgfreq),
443 BDM(sccfreq),
444 BDM(vco),
445#endif
446#if defined(CONFIG_MPC5xxx)
447 BDM(ipbfreq),
448 BDM(pcifreq),
449#endif
450 BDM(baudrate),
451};
Kumar Galae4f880e2006-01-11 13:49:31 -0600452#endif
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200453
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500454void ft_setup(void *blob, bd_t * bd, ulong initrd_start, ulong initrd_end)
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200455{
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200456 u32 *p;
457 int len;
458 struct ft_cxt cxt;
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200459 ulong clock;
Kumar Galae4f880e2006-01-11 13:49:31 -0600460#if defined(CONFIG_OF_HAS_UBOOT_ENV)
461 int k, nxt;
462#endif
463#if defined(CONFIG_OF_HAS_BD_T)
464 u8 *end;
465#endif
466#if defined(CONFIG_OF_HAS_UBOOT_ENV) || defined(CONFIG_OF_HAS_BD_T)
467 int i;
468 static char tmpenv[256];
469#endif
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200470
471 /* disable OF tree; booting old kernel */
472 if (getenv("disable_of") != NULL) {
473 memcpy(blob, bd, sizeof(*bd));
474 return;
475 }
476
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500477#ifdef DEBUG
478 printf ("recieved oftree\n");
479 ft_dump_blob(blob);
480#endif
481
482 ft_init_cxt(&cxt, blob);
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200483
Kumar Galae559a692006-01-11 16:41:35 -0600484 if (initrd_start && initrd_end)
485 ft_add_rsvmap(&cxt, initrd_start, initrd_end - initrd_start + 1);
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200486
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200487 /* back into root */
488 ft_backtrack_node(&cxt);
489
Kumar Galae4f880e2006-01-11 13:49:31 -0600490#ifdef CONFIG_OF_HAS_UBOOT_ENV
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200491 ft_begin_node(&cxt, "u-boot-env");
492
493 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
Kumar Galae4f880e2006-01-11 13:49:31 -0600494 char *s, *lval, *rval;
495
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200496 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt) ;
497 s = tmpenv;
498 for (k = i; k < nxt && s < &tmpenv[sizeof(tmpenv) - 1]; ++k)
499 *s++ = env_get_char(k);
500 *s++ = '\0';
501 lval = tmpenv;
502 s = strchr(tmpenv, '=');
503 if (s != NULL) {
504 *s++ = '\0';
505 rval = s;
506 } else
507 continue;
508 ft_prop_str(&cxt, lval, rval);
509 }
510
511 ft_end_node(&cxt);
Kumar Galae4f880e2006-01-11 13:49:31 -0600512#endif
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200513
514 ft_begin_node(&cxt, "chosen");
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200515 ft_prop_str(&cxt, "name", "chosen");
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500516
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200517 ft_prop_str(&cxt, "bootargs", getenv("bootargs"));
518 ft_prop_int(&cxt, "linux,platform", 0x600); /* what is this? */
Kumar Galae559a692006-01-11 16:41:35 -0600519 if (initrd_start && initrd_end) {
520 ft_prop_int(&cxt, "linux,initrd-start", initrd_start);
521 ft_prop_int(&cxt, "linux,initrd-end", initrd_end);
522 }
Kumar Galac2871f02006-01-11 13:59:02 -0600523#ifdef OF_STDOUT_PATH
524 ft_prop_str(&cxt, "linux,stdout-path", OF_STDOUT_PATH);
525#endif
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200526
527 ft_end_node(&cxt);
528
529 ft_end_node(&cxt); /* end root */
530
531 ft_end_tree(&cxt);
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500532 ft_finalize_tree(&cxt);
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200533
Kumar Galae4f880e2006-01-11 13:49:31 -0600534#ifdef CONFIG_OF_HAS_BD_T
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200535 /* paste the bd_t at the end of the flat tree */
536 end = (char *)blob +
537 be32_to_cpu(((struct boot_param_header *)blob)->totalsize);
538 memcpy(end, bd, sizeof(*bd));
Kumar Galae4f880e2006-01-11 13:49:31 -0600539#endif
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200540
541#ifdef CONFIG_PPC
542
Kumar Galae4f880e2006-01-11 13:49:31 -0600543#ifdef CONFIG_OF_HAS_BD_T
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200544 for (i = 0; i < sizeof(bd_map)/sizeof(bd_map[0]); i++) {
Kumar Galae4f880e2006-01-11 13:49:31 -0600545 uint32_t v;
546
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200547 sprintf(tmpenv, "/bd_t/%s", bd_map[i].name);
548 v = *(uint32_t *)((char *)bd + bd_map[i].offset);
549
550 p = ft_get_prop(blob, tmpenv, &len);
551 if (p != NULL)
552 *p = cpu_to_be32(v);
553 }
554
555 p = ft_get_prop(blob, "/bd_t/enetaddr", &len);
556 if (p != NULL)
557 memcpy(p, bd->bi_enetaddr, 6);
558
559 p = ft_get_prop(blob, "/bd_t/ethspeed", &len);
560 if (p != NULL)
561 *p = cpu_to_be32((uint32_t) bd->bi_ethspeed);
Kumar Galae4f880e2006-01-11 13:49:31 -0600562#endif
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200563
564 clock = bd->bi_intfreq;
565 p = ft_get_prop(blob, "/cpus/" OF_CPU "/clock-frequency", &len);
566 if (p != NULL)
567 *p = cpu_to_be32(clock);
568
569#ifdef OF_TBCLK
570 clock = OF_TBCLK;
571 p = ft_get_prop(blob, "/cpus/" OF_CPU "/timebase-frequency", &len);
572 if (p != NULL)
Kumar Galae4f880e2006-01-11 13:49:31 -0600573 *p = cpu_to_be32(clock);
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200574#endif
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200575#endif /* __powerpc__ */
576
Kumar Gala4e253132006-01-11 13:54:17 -0600577#ifdef CONFIG_OF_BOARD_SETUP
578 ft_board_setup(blob, bd);
579#endif
580
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500581 /* in case the size changed in the platform code */
582 ft_finalize_tree(&cxt);
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200583
Matthew McClintock1b380ec2006-06-28 10:42:24 -0500584#ifdef DEBUG
585 printf("final OF-tree\n");
586 ft_dump_blob(blob);
587#endif
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200588}
Wolfgang Denk814d98f2005-10-13 01:59:29 +0200589#endif