3 * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 #include <linux/ctype.h>
26 #include <linux/types.h>
28 #ifdef CONFIG_OF_LIBFDT
30 #include <asm/global_data.h>
33 #include <fdt_support.h>
36 * Global data (for the gd->bd)
38 DECLARE_GLOBAL_DATA_PTR;
41 /********************************************************************/
43 int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force)
48 u32 tmp; /* used to set 32 bit integer properties */
49 char *str; /* used to set string properties */
52 err = fdt_check_header(fdt);
54 printf("libfdt: %s\n", fdt_strerror(err));
58 #warning "Don't double-add the reserved map"
59 if (initrd_start && initrd_end) {
60 err = fdt_add_reservemap_entry(fdt,
61 initrd_start, initrd_end - initrd_start + 1);
63 printf("libfdt: %s\n", fdt_strerror(err));
69 * Find the "chosen" node.
71 nodeoffset = fdt_path_offset (fdt, "/chosen");
74 * If we have a "chosen" node already the "force the writing"
75 * is not set, our job is done.
77 if ((nodeoffset >= 0) && !force)
81 * No "chosen" node in the blob: create it.
85 * Create a new node "/chosen" (offset 0 is root level)
87 nodeoffset = fdt_add_subnode(fdt, 0, "chosen");
89 printf("libfdt: %s\n", fdt_strerror(nodeoffset));
95 * Update pre-existing properties, create them if non-existant.
97 str = getenv("bootargs");
99 err = fdt_setprop(fdt, nodeoffset, "bootargs", str, strlen(str)+1);
101 printf("libfdt: %s\n", fdt_strerror(err));
103 if (initrd_start && initrd_end) {
104 tmp = __cpu_to_be32(initrd_start);
105 err = fdt_setprop(fdt, nodeoffset, "linux,initrd-start", &tmp, sizeof(tmp));
107 printf("libfdt: %s\n", fdt_strerror(err));
108 tmp = __cpu_to_be32(initrd_end);
109 err = fdt_setprop(fdt, nodeoffset, "linux,initrd-end", &tmp, sizeof(tmp));
111 printf("libfdt: %s\n", fdt_strerror(err));
113 #ifdef OF_STDOUT_PATH
114 err = fdt_setprop(fdt, nodeoffset, "linux,stdout-path", OF_STDOUT_PATH, strlen(OF_STDOUT_PATH)+1);
116 printf("libfdt: %s\n", fdt_strerror(err));
119 nodeoffset = fdt_path_offset (fdt, "/cpus");
120 if (nodeoffset >= 0) {
121 clock = cpu_to_be32(bd->bi_intfreq);
122 err = fdt_setprop(fdt, nodeoffset, "clock-frequency", &clock, 4);
124 printf("libfdt: %s\n", fdt_strerror(err));
127 nodeoffset = fdt_path_offset (fdt, "/cpus/" OF_CPU "/timebase-frequency");
128 if (nodeoffset >= 0) {
129 clock = cpu_to_be32(OF_TBCLK);
130 err = fdt_setprop(fdt, nodeoffset, "clock-frequency", &clock, 4);
132 printf("libfdt: %s\n", fdt_strerror(err));
138 /********************************************************************/
140 #ifdef CONFIG_OF_HAS_UBOOT_ENV
142 /* Function that returns a character from the environment */
143 extern uchar(*env_get_char) (int);
146 int fdt_env(void *fdt)
152 static char tmpenv[256];
154 err = fdt_check_header(fdt);
156 printf("libfdt: %s\n", fdt_strerror(err));
161 * See if we already have a "u-boot-env" node, delete it if so.
162 * Then create a new empty node.
164 nodeoffset = fdt_path_offset (fdt, "/u-boot-env");
165 if (nodeoffset >= 0) {
166 err = fdt_del_node(fdt, nodeoffset);
168 printf("libfdt: %s\n", fdt_strerror(err));
173 * Create a new node "/u-boot-env" (offset 0 is root level)
175 nodeoffset = fdt_add_subnode(fdt, 0, "u-boot-env");
176 if (nodeoffset < 0) {
177 printf("libfdt: %s\n", fdt_strerror(nodeoffset));
181 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
182 char *s, *lval, *rval;
185 * Find the end of the name=definition
187 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
190 for (k = i; k < nxt && s < &tmpenv[sizeof(tmpenv) - 1]; ++k)
191 *s++ = env_get_char(k);
195 * Find the first '=': it separates the name from the value
197 s = strchr(tmpenv, '=');
203 err = fdt_setprop(fdt, nodeoffset, lval, rval, strlen(rval)+1);
205 printf("libfdt: %s\n", lval, fdt_strerror(err));
211 #endif /* CONFIG_OF_HAS_UBOOT_ENV */
213 /********************************************************************/
215 #ifdef CONFIG_OF_HAS_BD_T
217 #define BDM(x) { .name = #x, .offset = offsetof(bd_t, bi_ ##x ) }
219 static const struct {
230 #if defined(CONFIG_5xx) || defined(CONFIG_8xx) || defined(CONFIG_8260) \
231 || defined(CONFIG_E500)
234 #if defined(CONFIG_MPC5xxx)
237 #if defined(CONFIG_MPC83XX)
240 #if defined(CONFIG_MPC8220)
258 #if defined(CONFIG_MPC5xxx)
266 int fdt_bd_t(void *fdt)
271 u32 tmp; /* used to set 32 bit integer properties */
274 err = fdt_check_header(fdt);
276 printf("libfdt: %s\n", fdt_strerror(err));
281 * See if we already have a "bd_t" node, delete it if so.
282 * Then create a new empty node.
284 nodeoffset = fdt_path_offset (fdt, "/bd_t");
285 if (nodeoffset >= 0) {
286 err = fdt_del_node(fdt, nodeoffset);
288 printf("libfdt: %s\n", fdt_strerror(err));
293 * Create a new node "/bd_t" (offset 0 is root level)
295 nodeoffset = fdt_add_subnode(fdt, 0, "bd_t");
296 if (nodeoffset < 0) {
297 printf("libfdt: %s\n", fdt_strerror(nodeoffset));
301 * Use the string/pointer structure to create the entries...
303 for (i = 0; i < sizeof(bd_map)/sizeof(bd_map[0]); i++) {
304 tmp = cpu_to_be32(getenv("bootargs"));
305 err = fdt_setprop(fdt, nodeoffset, bd_map[i].name, &tmp, sizeof(tmp));
307 printf("libfdt: %s\n", fdt_strerror(err));
310 * Add a couple of oddball entries...
312 err = fdt_setprop(fdt, nodeoffset, "enetaddr", &bd->bi_enetaddr, 6);
314 printf("libfdt: %s\n", fdt_strerror(err));
315 err = fdt_setprop(fdt, nodeoffset, "ethspeed", &bd->bi_ethspeed, 4);
317 printf("libfdt: %s\n", fdt_strerror(err));
321 #endif /* CONFIG_OF_HAS_BD_T */
323 #endif /* CONFIG_OF_LIBFDT */