]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/fdt_support.c
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 * fdt points to our working device tree.
43 struct fdt_header
*fdt
;
45 /********************************************************************/
47 int fdt_chosen(void *fdt
, ulong initrd_start
, ulong initrd_end
, int force
)
52 u32 tmp
; /* used to set 32 bit integer properties */
53 char *str
; /* used to set string properties */
55 err
= fdt_check_header(fdt
);
57 printf("fdt_chosen: %s\n", fdt_strerror(err
));
61 if (initrd_start
&& initrd_end
) {
62 struct fdt_reserve_entry re
;
67 err
= fdt_num_reservemap(fdt
, &used
, &total
);
69 printf("fdt_chosen: %s\n", fdt_strerror(err
));
74 "no room in the reserved map (%d of %d)\n",
79 * Look for an existing entry and update it. If we don't find
80 * the entry, we will j be the next available slot.
82 for (j
= 0; j
< used
; j
++) {
83 err
= fdt_get_reservemap(fdt
, j
, &re
);
84 if (re
.address
== initrd_start
) {
88 err
= fdt_replace_reservemap_entry(fdt
, j
,
89 initrd_start
, initrd_end
- initrd_start
+ 1);
91 printf("fdt_chosen: %s\n", fdt_strerror(err
));
97 * Find the "chosen" node.
99 nodeoffset
= fdt_find_node_by_path (fdt
, "/chosen");
102 * If we have a "chosen" node already the "force the writing"
103 * is not set, our job is done.
105 if ((nodeoffset
>= 0) && !force
)
109 * No "chosen" node in the blob: create it.
111 if (nodeoffset
< 0) {
113 * Create a new node "/chosen" (offset 0 is root level)
115 nodeoffset
= fdt_add_subnode(fdt
, 0, "chosen");
116 if (nodeoffset
< 0) {
117 printf("WARNING: could not create /chosen %s.\n",
118 fdt_strerror(nodeoffset
));
124 * Update pre-existing properties, create them if non-existant.
126 str
= getenv("bootargs");
128 err
= fdt_setprop(fdt
, nodeoffset
,
129 "bootargs", str
, strlen(str
)+1);
131 printf("WARNING: could not set bootargs %s.\n",
134 if (initrd_start
&& initrd_end
) {
135 tmp
= __cpu_to_be32(initrd_start
);
136 err
= fdt_setprop(fdt
, nodeoffset
,
137 "linux,initrd-start", &tmp
, sizeof(tmp
));
140 "could not set linux,initrd-start %s.\n",
142 tmp
= __cpu_to_be32(initrd_end
);
143 err
= fdt_setprop(fdt
, nodeoffset
,
144 "linux,initrd-end", &tmp
, sizeof(tmp
));
146 printf("WARNING: could not set linux,initrd-end %s.\n",
149 #ifdef OF_STDOUT_PATH
150 err
= fdt_setprop(fdt
, nodeoffset
,
151 "linux,stdout-path", OF_STDOUT_PATH
, strlen(OF_STDOUT_PATH
)+1);
153 printf("WARNING: could not set linux,stdout-path %s.\n",
160 /********************************************************************/
162 #ifdef CONFIG_OF_HAS_UBOOT_ENV
164 /* Function that returns a character from the environment */
165 extern uchar(*env_get_char
) (int);
168 int fdt_env(void *fdt
)
174 static char tmpenv
[256];
176 err
= fdt_check_header(fdt
);
178 printf("fdt_env: %s\n", fdt_strerror(err
));
183 * See if we already have a "u-boot-env" node, delete it if so.
184 * Then create a new empty node.
186 nodeoffset
= fdt_find_node_by_path (fdt
, "/u-boot-env");
187 if (nodeoffset
>= 0) {
188 err
= fdt_del_node(fdt
, nodeoffset
);
190 printf("fdt_env: %s\n", fdt_strerror(err
));
195 * Create a new node "/u-boot-env" (offset 0 is root level)
197 nodeoffset
= fdt_add_subnode(fdt
, 0, "u-boot-env");
198 if (nodeoffset
< 0) {
199 printf("WARNING: could not create /u-boot-env %s.\n",
200 fdt_strerror(nodeoffset
));
204 for (i
= 0; env_get_char(i
) != '\0'; i
= nxt
+ 1) {
205 char *s
, *lval
, *rval
;
208 * Find the end of the name=definition
210 for (nxt
= i
; env_get_char(nxt
) != '\0'; ++nxt
)
213 for (k
= i
; k
< nxt
&& s
< &tmpenv
[sizeof(tmpenv
) - 1]; ++k
)
214 *s
++ = env_get_char(k
);
218 * Find the first '=': it separates the name from the value
220 s
= strchr(tmpenv
, '=');
226 err
= fdt_setprop(fdt
, nodeoffset
, lval
, rval
, strlen(rval
)+1);
228 printf("WARNING: could not set %s %s.\n",
229 lval
, fdt_strerror(err
));
235 #endif /* ifdef CONFIG_OF_HAS_UBOOT_ENV */
237 /********************************************************************/
239 #ifdef CONFIG_OF_HAS_BD_T
241 #define BDM(x) { .name = #x, .offset = offsetof(bd_t, bi_ ##x ) }
243 static const struct {
254 #if defined(CONFIG_5xx) || defined(CONFIG_8xx) || defined(CONFIG_8260) \
255 || defined(CONFIG_E500)
258 #if defined(CONFIG_MPC5xxx)
261 #if defined(CONFIG_MPC83XX)
264 #if defined(CONFIG_MPC8220)
282 #if defined(CONFIG_MPC5xxx)
290 int fdt_bd_t(void *fdt
)
295 u32 tmp
; /* used to set 32 bit integer properties */
298 err
= fdt_check_header(fdt
);
300 printf("fdt_bd_t: %s\n", fdt_strerror(err
));
305 * See if we already have a "bd_t" node, delete it if so.
306 * Then create a new empty node.
308 nodeoffset
= fdt_find_node_by_path (fdt
, "/bd_t");
309 if (nodeoffset
>= 0) {
310 err
= fdt_del_node(fdt
, nodeoffset
);
312 printf("fdt_bd_t: %s\n", fdt_strerror(err
));
317 * Create a new node "/bd_t" (offset 0 is root level)
319 nodeoffset
= fdt_add_subnode(fdt
, 0, "bd_t");
320 if (nodeoffset
< 0) {
321 printf("WARNING: could not create /bd_t %s.\n",
322 fdt_strerror(nodeoffset
));
323 printf("fdt_bd_t: %s\n", fdt_strerror(nodeoffset
));
327 * Use the string/pointer structure to create the entries...
329 for (i
= 0; i
< sizeof(bd_map
)/sizeof(bd_map
[0]); i
++) {
330 tmp
= cpu_to_be32(getenv("bootargs"));
331 err
= fdt_setprop(fdt
, nodeoffset
,
332 bd_map
[i
].name
, &tmp
, sizeof(tmp
));
334 printf("WARNING: could not set %s %s.\n",
335 bd_map
[i
].name
, fdt_strerror(err
));
338 * Add a couple of oddball entries...
340 err
= fdt_setprop(fdt
, nodeoffset
, "enetaddr", &bd
->bi_enetaddr
, 6);
342 printf("WARNING: could not set enetaddr %s.\n",
344 err
= fdt_setprop(fdt
, nodeoffset
, "ethspeed", &bd
->bi_ethspeed
, 4);
346 printf("WARNING: could not set ethspeed %s.\n",
350 #endif /* ifdef CONFIG_OF_HAS_BD_T */
352 #endif /* CONFIG_OF_LIBFDT */