Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 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. |
| 12 | * |
| 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. |
| 17 | * |
| 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, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <linux/ctype.h> |
| 26 | #include <linux/types.h> |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 27 | #include <asm/global_data.h> |
| 28 | #include <fdt.h> |
| 29 | #include <libfdt.h> |
| 30 | #include <fdt_support.h> |
Kumar Gala | 151c8b0 | 2007-11-26 17:06:15 -0600 | [diff] [blame] | 31 | #include <exports.h> |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * Global data (for the gd->bd) |
| 35 | */ |
| 36 | DECLARE_GLOBAL_DATA_PTR; |
| 37 | |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 38 | |
Kumar Gala | a3c2933 | 2007-10-24 10:21:57 -0500 | [diff] [blame] | 39 | /** |
| 40 | * fdt_find_and_setprop: Find a node and set it's property |
| 41 | * |
| 42 | * @fdt: ptr to device tree |
| 43 | * @node: path of node |
| 44 | * @prop: property name |
| 45 | * @val: ptr to new value |
| 46 | * @len: length of new property value |
| 47 | * @create: flag to create the property if it doesn't exist |
| 48 | * |
| 49 | * Convenience function to directly set a property given the path to the node. |
| 50 | */ |
| 51 | int fdt_find_and_setprop(void *fdt, const char *node, const char *prop, |
| 52 | const void *val, int len, int create) |
| 53 | { |
Kumar Gala | 8d04f02 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 54 | int nodeoff = fdt_path_offset(fdt, node); |
Kumar Gala | a3c2933 | 2007-10-24 10:21:57 -0500 | [diff] [blame] | 55 | |
| 56 | if (nodeoff < 0) |
| 57 | return nodeoff; |
| 58 | |
| 59 | if ((!create) && (fdt_get_property(fdt, nodeoff, prop, 0) == NULL)) |
| 60 | return 0; /* create flag not set; so exit quietly */ |
| 61 | |
| 62 | return fdt_setprop(fdt, nodeoff, prop, val, len); |
| 63 | } |
| 64 | |
Kumar Gala | 151c8b0 | 2007-11-26 17:06:15 -0600 | [diff] [blame] | 65 | #ifdef CONFIG_OF_STDOUT_VIA_ALIAS |
Detlev Zundel | 4077781 | 2008-06-20 22:24:05 +0200 | [diff] [blame] | 66 | static int fdt_fixup_stdout(void *fdt, int chosenoff) |
Kumar Gala | 151c8b0 | 2007-11-26 17:06:15 -0600 | [diff] [blame] | 67 | { |
| 68 | int err = 0; |
| 69 | #ifdef CONFIG_CONS_INDEX |
| 70 | int node; |
| 71 | char sername[9] = { 0 }; |
| 72 | const char *path; |
| 73 | |
| 74 | sprintf(sername, "serial%d", CONFIG_CONS_INDEX - 1); |
| 75 | |
| 76 | err = node = fdt_path_offset(fdt, "/aliases"); |
| 77 | if (node >= 0) { |
| 78 | int len; |
| 79 | path = fdt_getprop(fdt, node, sername, &len); |
| 80 | if (path) { |
| 81 | char *p = malloc(len); |
| 82 | err = -FDT_ERR_NOSPACE; |
| 83 | if (p) { |
| 84 | memcpy(p, path, len); |
Detlev Zundel | 4077781 | 2008-06-20 22:24:05 +0200 | [diff] [blame] | 85 | err = fdt_setprop(fdt, chosenoff, |
Kumar Gala | 151c8b0 | 2007-11-26 17:06:15 -0600 | [diff] [blame] | 86 | "linux,stdout-path", p, len); |
| 87 | free(p); |
| 88 | } |
| 89 | } else { |
| 90 | err = len; |
| 91 | } |
| 92 | } |
| 93 | #endif |
| 94 | if (err < 0) |
| 95 | printf("WARNING: could not set linux,stdout-path %s.\n", |
| 96 | fdt_strerror(err)); |
| 97 | |
| 98 | return err; |
| 99 | } |
| 100 | #endif |
| 101 | |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 102 | int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) |
| 103 | { |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 104 | int nodeoffset; |
| 105 | int err; |
Gerald Van Baren | 35ec398 | 2007-05-25 22:08:57 -0400 | [diff] [blame] | 106 | u32 tmp; /* used to set 32 bit integer properties */ |
| 107 | char *str; /* used to set string properties */ |
Gerald Van Baren | b60af3d | 2007-12-29 22:45:27 -0500 | [diff] [blame] | 108 | const char *path; |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 109 | |
| 110 | err = fdt_check_header(fdt); |
| 111 | if (err < 0) { |
Gerald Van Baren | 5fe6be6 | 2007-08-07 21:14:22 -0400 | [diff] [blame] | 112 | printf("fdt_chosen: %s\n", fdt_strerror(err)); |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 113 | return err; |
| 114 | } |
| 115 | |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 116 | if (initrd_start && initrd_end) { |
Kumar Gala | 8d04f02 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 117 | uint64_t addr, size; |
| 118 | int total = fdt_num_mem_rsv(fdt); |
Gerald Van Baren | c28abb9 | 2007-04-14 22:51:24 -0400 | [diff] [blame] | 119 | int j; |
| 120 | |
Gerald Van Baren | c28abb9 | 2007-04-14 22:51:24 -0400 | [diff] [blame] | 121 | /* |
| 122 | * Look for an existing entry and update it. If we don't find |
| 123 | * the entry, we will j be the next available slot. |
| 124 | */ |
Kumar Gala | 8d04f02 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 125 | for (j = 0; j < total; j++) { |
| 126 | err = fdt_get_mem_rsv(fdt, j, &addr, &size); |
| 127 | if (addr == initrd_start) { |
| 128 | fdt_del_mem_rsv(fdt, j); |
Gerald Van Baren | c28abb9 | 2007-04-14 22:51:24 -0400 | [diff] [blame] | 129 | break; |
| 130 | } |
| 131 | } |
Kumar Gala | 8d04f02 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 132 | |
| 133 | err = fdt_add_mem_rsv(fdt, initrd_start, initrd_end - initrd_start + 1); |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 134 | if (err < 0) { |
Gerald Van Baren | 5fe6be6 | 2007-08-07 21:14:22 -0400 | [diff] [blame] | 135 | printf("fdt_chosen: %s\n", fdt_strerror(err)); |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 136 | return err; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | /* |
| 141 | * Find the "chosen" node. |
| 142 | */ |
Kumar Gala | 8d04f02 | 2007-10-24 11:04:22 -0500 | [diff] [blame] | 143 | nodeoffset = fdt_path_offset (fdt, "/chosen"); |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 144 | |
| 145 | /* |
Gerald Van Baren | b60af3d | 2007-12-29 22:45:27 -0500 | [diff] [blame] | 146 | * If there is no "chosen" node in the blob, create it. |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 147 | */ |
| 148 | if (nodeoffset < 0) { |
| 149 | /* |
| 150 | * Create a new node "/chosen" (offset 0 is root level) |
| 151 | */ |
| 152 | nodeoffset = fdt_add_subnode(fdt, 0, "chosen"); |
| 153 | if (nodeoffset < 0) { |
Gerald Van Baren | 5fe6be6 | 2007-08-07 21:14:22 -0400 | [diff] [blame] | 154 | printf("WARNING: could not create /chosen %s.\n", |
Gerald Van Baren | 35ec398 | 2007-05-25 22:08:57 -0400 | [diff] [blame] | 155 | fdt_strerror(nodeoffset)); |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 156 | return nodeoffset; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | /* |
Gerald Van Baren | b60af3d | 2007-12-29 22:45:27 -0500 | [diff] [blame] | 161 | * Create /chosen properites that don't exist in the fdt. |
| 162 | * If the property exists, update it only if the "force" parameter |
| 163 | * is true. |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 164 | */ |
| 165 | str = getenv("bootargs"); |
| 166 | if (str != NULL) { |
Gerald Van Baren | b60af3d | 2007-12-29 22:45:27 -0500 | [diff] [blame] | 167 | path = fdt_getprop(fdt, nodeoffset, "bootargs", NULL); |
| 168 | if ((path == NULL) || force) { |
| 169 | err = fdt_setprop(fdt, nodeoffset, |
| 170 | "bootargs", str, strlen(str)+1); |
| 171 | if (err < 0) |
| 172 | printf("WARNING: could not set bootargs %s.\n", |
| 173 | fdt_strerror(err)); |
| 174 | } |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 175 | } |
| 176 | if (initrd_start && initrd_end) { |
Gerald Van Baren | b60af3d | 2007-12-29 22:45:27 -0500 | [diff] [blame] | 177 | path = fdt_getprop(fdt, nodeoffset, "linux,initrd-start", NULL); |
| 178 | if ((path == NULL) || force) { |
| 179 | tmp = __cpu_to_be32(initrd_start); |
| 180 | err = fdt_setprop(fdt, nodeoffset, |
| 181 | "linux,initrd-start", &tmp, sizeof(tmp)); |
| 182 | if (err < 0) |
| 183 | printf("WARNING: " |
| 184 | "could not set linux,initrd-start %s.\n", |
| 185 | fdt_strerror(err)); |
| 186 | tmp = __cpu_to_be32(initrd_end); |
| 187 | err = fdt_setprop(fdt, nodeoffset, |
| 188 | "linux,initrd-end", &tmp, sizeof(tmp)); |
| 189 | if (err < 0) |
| 190 | printf("WARNING: could not set linux,initrd-end %s.\n", |
| 191 | fdt_strerror(err)); |
| 192 | } |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 193 | } |
Kumar Gala | 151c8b0 | 2007-11-26 17:06:15 -0600 | [diff] [blame] | 194 | |
| 195 | #ifdef CONFIG_OF_STDOUT_VIA_ALIAS |
Gerald Van Baren | b60af3d | 2007-12-29 22:45:27 -0500 | [diff] [blame] | 196 | path = fdt_getprop(fdt, nodeoffset, "linux,stdout-path", NULL); |
| 197 | if ((path == NULL) || force) |
| 198 | err = fdt_fixup_stdout(fdt, nodeoffset); |
Kumar Gala | 151c8b0 | 2007-11-26 17:06:15 -0600 | [diff] [blame] | 199 | #endif |
| 200 | |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 201 | #ifdef OF_STDOUT_PATH |
Gerald Van Baren | b60af3d | 2007-12-29 22:45:27 -0500 | [diff] [blame] | 202 | path = fdt_getprop(fdt, nodeoffset, "linux,stdout-path", NULL); |
| 203 | if ((path == NULL) || force) { |
| 204 | err = fdt_setprop(fdt, nodeoffset, |
| 205 | "linux,stdout-path", OF_STDOUT_PATH, strlen(OF_STDOUT_PATH)+1); |
| 206 | if (err < 0) |
| 207 | printf("WARNING: could not set linux,stdout-path %s.\n", |
| 208 | fdt_strerror(err)); |
| 209 | } |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 210 | #endif |
| 211 | |
Gerald Van Baren | 64dbbd4 | 2007-04-06 14:19:43 -0400 | [diff] [blame] | 212 | return err; |
| 213 | } |
| 214 | |
Kumar Gala | e93becf | 2007-11-03 19:46:28 -0500 | [diff] [blame] | 215 | void do_fixup_by_path(void *fdt, const char *path, const char *prop, |
| 216 | const void *val, int len, int create) |
| 217 | { |
| 218 | #if defined(DEBUG) |
| 219 | int i; |
Kumar Gala | d9ad115 | 2008-02-13 15:09:58 -0600 | [diff] [blame] | 220 | debug("Updating property '%s/%s' = ", path, prop); |
Kumar Gala | e93becf | 2007-11-03 19:46:28 -0500 | [diff] [blame] | 221 | for (i = 0; i < len; i++) |
| 222 | debug(" %.2x", *(u8*)(val+i)); |
| 223 | debug("\n"); |
| 224 | #endif |
| 225 | int rc = fdt_find_and_setprop(fdt, path, prop, val, len, create); |
| 226 | if (rc) |
| 227 | printf("Unable to update property %s:%s, err=%s\n", |
| 228 | path, prop, fdt_strerror(rc)); |
| 229 | } |
| 230 | |
| 231 | void do_fixup_by_path_u32(void *fdt, const char *path, const char *prop, |
| 232 | u32 val, int create) |
| 233 | { |
| 234 | val = cpu_to_fdt32(val); |
| 235 | do_fixup_by_path(fdt, path, prop, &val, sizeof(val), create); |
| 236 | } |
| 237 | |
Kumar Gala | 9eb77ce | 2007-11-21 13:30:15 -0600 | [diff] [blame] | 238 | void do_fixup_by_prop(void *fdt, |
| 239 | const char *pname, const void *pval, int plen, |
| 240 | const char *prop, const void *val, int len, |
| 241 | int create) |
| 242 | { |
| 243 | int off; |
| 244 | #if defined(DEBUG) |
| 245 | int i; |
Kumar Gala | d9ad115 | 2008-02-13 15:09:58 -0600 | [diff] [blame] | 246 | debug("Updating property '%s' = ", prop); |
Kumar Gala | 9eb77ce | 2007-11-21 13:30:15 -0600 | [diff] [blame] | 247 | for (i = 0; i < len; i++) |
| 248 | debug(" %.2x", *(u8*)(val+i)); |
| 249 | debug("\n"); |
| 250 | #endif |
| 251 | off = fdt_node_offset_by_prop_value(fdt, -1, pname, pval, plen); |
| 252 | while (off != -FDT_ERR_NOTFOUND) { |
| 253 | if (create || (fdt_get_property(fdt, off, prop, 0) != NULL)) |
| 254 | fdt_setprop(fdt, off, prop, val, len); |
| 255 | off = fdt_node_offset_by_prop_value(fdt, off, pname, pval, plen); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | void do_fixup_by_prop_u32(void *fdt, |
| 260 | const char *pname, const void *pval, int plen, |
| 261 | const char *prop, u32 val, int create) |
| 262 | { |
| 263 | val = cpu_to_fdt32(val); |
| 264 | do_fixup_by_prop(fdt, pname, pval, plen, prop, &val, 4, create); |
| 265 | } |
| 266 | |
| 267 | void do_fixup_by_compat(void *fdt, const char *compat, |
| 268 | const char *prop, const void *val, int len, int create) |
| 269 | { |
| 270 | int off = -1; |
| 271 | #if defined(DEBUG) |
| 272 | int i; |
Kumar Gala | d9ad115 | 2008-02-13 15:09:58 -0600 | [diff] [blame] | 273 | debug("Updating property '%s' = ", prop); |
Kumar Gala | 9eb77ce | 2007-11-21 13:30:15 -0600 | [diff] [blame] | 274 | for (i = 0; i < len; i++) |
| 275 | debug(" %.2x", *(u8*)(val+i)); |
| 276 | debug("\n"); |
| 277 | #endif |
| 278 | off = fdt_node_offset_by_compatible(fdt, -1, compat); |
| 279 | while (off != -FDT_ERR_NOTFOUND) { |
| 280 | if (create || (fdt_get_property(fdt, off, prop, 0) != NULL)) |
| 281 | fdt_setprop(fdt, off, prop, val, len); |
| 282 | off = fdt_node_offset_by_compatible(fdt, off, compat); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | void do_fixup_by_compat_u32(void *fdt, const char *compat, |
| 287 | const char *prop, u32 val, int create) |
| 288 | { |
| 289 | val = cpu_to_fdt32(val); |
| 290 | do_fixup_by_compat(fdt, compat, prop, &val, 4, create); |
| 291 | } |
| 292 | |
Kumar Gala | 3c92728 | 2007-11-26 14:57:45 -0600 | [diff] [blame] | 293 | int fdt_fixup_memory(void *blob, u64 start, u64 size) |
| 294 | { |
| 295 | int err, nodeoffset, len = 0; |
| 296 | u8 tmp[16]; |
| 297 | const u32 *addrcell, *sizecell; |
| 298 | |
| 299 | err = fdt_check_header(blob); |
| 300 | if (err < 0) { |
| 301 | printf("%s: %s\n", __FUNCTION__, fdt_strerror(err)); |
| 302 | return err; |
| 303 | } |
| 304 | |
| 305 | /* update, or add and update /memory node */ |
| 306 | nodeoffset = fdt_path_offset(blob, "/memory"); |
| 307 | if (nodeoffset < 0) { |
| 308 | nodeoffset = fdt_add_subnode(blob, 0, "memory"); |
| 309 | if (nodeoffset < 0) |
| 310 | printf("WARNING: could not create /memory: %s.\n", |
| 311 | fdt_strerror(nodeoffset)); |
| 312 | return nodeoffset; |
| 313 | } |
| 314 | err = fdt_setprop(blob, nodeoffset, "device_type", "memory", |
| 315 | sizeof("memory")); |
| 316 | if (err < 0) { |
| 317 | printf("WARNING: could not set %s %s.\n", "device_type", |
| 318 | fdt_strerror(err)); |
| 319 | return err; |
| 320 | } |
| 321 | |
| 322 | addrcell = fdt_getprop(blob, 0, "#address-cells", NULL); |
| 323 | /* use shifts and mask to ensure endianness */ |
| 324 | if ((addrcell) && (*addrcell == 2)) { |
| 325 | tmp[0] = (start >> 56) & 0xff; |
| 326 | tmp[1] = (start >> 48) & 0xff; |
| 327 | tmp[2] = (start >> 40) & 0xff; |
| 328 | tmp[3] = (start >> 32) & 0xff; |
| 329 | tmp[4] = (start >> 24) & 0xff; |
| 330 | tmp[5] = (start >> 16) & 0xff; |
| 331 | tmp[6] = (start >> 8) & 0xff; |
| 332 | tmp[7] = (start ) & 0xff; |
| 333 | len = 8; |
| 334 | } else { |
| 335 | tmp[0] = (start >> 24) & 0xff; |
| 336 | tmp[1] = (start >> 16) & 0xff; |
| 337 | tmp[2] = (start >> 8) & 0xff; |
| 338 | tmp[3] = (start ) & 0xff; |
| 339 | len = 4; |
| 340 | } |
| 341 | |
| 342 | sizecell = fdt_getprop(blob, 0, "#size-cells", NULL); |
| 343 | /* use shifts and mask to ensure endianness */ |
| 344 | if ((sizecell) && (*sizecell == 2)) { |
| 345 | tmp[0+len] = (size >> 56) & 0xff; |
| 346 | tmp[1+len] = (size >> 48) & 0xff; |
| 347 | tmp[2+len] = (size >> 40) & 0xff; |
| 348 | tmp[3+len] = (size >> 32) & 0xff; |
| 349 | tmp[4+len] = (size >> 24) & 0xff; |
| 350 | tmp[5+len] = (size >> 16) & 0xff; |
| 351 | tmp[6+len] = (size >> 8) & 0xff; |
| 352 | tmp[7+len] = (size ) & 0xff; |
| 353 | len += 8; |
| 354 | } else { |
| 355 | tmp[0+len] = (size >> 24) & 0xff; |
| 356 | tmp[1+len] = (size >> 16) & 0xff; |
| 357 | tmp[2+len] = (size >> 8) & 0xff; |
| 358 | tmp[3+len] = (size ) & 0xff; |
| 359 | len += 4; |
| 360 | } |
| 361 | |
| 362 | err = fdt_setprop(blob, nodeoffset, "reg", tmp, len); |
| 363 | if (err < 0) { |
| 364 | printf("WARNING: could not set %s %s.\n", |
| 365 | "reg", fdt_strerror(err)); |
| 366 | return err; |
| 367 | } |
| 368 | return 0; |
| 369 | } |
| 370 | |
Gerald Van Baren | c01b17d | 2007-11-28 21:24:50 -0500 | [diff] [blame] | 371 | #if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) ||\ |
| 372 | defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3) |
| 373 | |
Kumar Gala | ab54463 | 2007-11-21 11:11:03 -0600 | [diff] [blame] | 374 | void fdt_fixup_ethernet(void *fdt, bd_t *bd) |
| 375 | { |
| 376 | int node; |
| 377 | const char *path; |
| 378 | |
| 379 | node = fdt_path_offset(fdt, "/aliases"); |
| 380 | if (node >= 0) { |
| 381 | #if defined(CONFIG_HAS_ETH0) |
| 382 | path = fdt_getprop(fdt, node, "ethernet0", NULL); |
| 383 | if (path) { |
| 384 | do_fixup_by_path(fdt, path, "mac-address", |
| 385 | bd->bi_enetaddr, 6, 0); |
| 386 | do_fixup_by_path(fdt, path, "local-mac-address", |
| 387 | bd->bi_enetaddr, 6, 1); |
| 388 | } |
| 389 | #endif |
| 390 | #if defined(CONFIG_HAS_ETH1) |
| 391 | path = fdt_getprop(fdt, node, "ethernet1", NULL); |
| 392 | if (path) { |
| 393 | do_fixup_by_path(fdt, path, "mac-address", |
| 394 | bd->bi_enet1addr, 6, 0); |
| 395 | do_fixup_by_path(fdt, path, "local-mac-address", |
| 396 | bd->bi_enet1addr, 6, 1); |
| 397 | } |
| 398 | #endif |
| 399 | #if defined(CONFIG_HAS_ETH2) |
| 400 | path = fdt_getprop(fdt, node, "ethernet2", NULL); |
| 401 | if (path) { |
| 402 | do_fixup_by_path(fdt, path, "mac-address", |
| 403 | bd->bi_enet2addr, 6, 0); |
| 404 | do_fixup_by_path(fdt, path, "local-mac-address", |
| 405 | bd->bi_enet2addr, 6, 1); |
| 406 | } |
| 407 | #endif |
| 408 | #if defined(CONFIG_HAS_ETH3) |
| 409 | path = fdt_getprop(fdt, node, "ethernet3", NULL); |
| 410 | if (path) { |
| 411 | do_fixup_by_path(fdt, path, "mac-address", |
| 412 | bd->bi_enet3addr, 6, 0); |
| 413 | do_fixup_by_path(fdt, path, "local-mac-address", |
| 414 | bd->bi_enet3addr, 6, 1); |
| 415 | } |
| 416 | #endif |
| 417 | } |
| 418 | } |
Gerald Van Baren | c01b17d | 2007-11-28 21:24:50 -0500 | [diff] [blame] | 419 | #endif |
Anton Vorontsov | 18e69a3 | 2008-03-14 23:20:18 +0300 | [diff] [blame] | 420 | |
| 421 | #ifdef CONFIG_HAS_FSL_DR_USB |
| 422 | void fdt_fixup_dr_usb(void *blob, bd_t *bd) |
| 423 | { |
| 424 | char *mode; |
Anton Vorontsov | 015b27b | 2008-07-08 20:59:43 +0400 | [diff] [blame^] | 425 | char *type; |
Anton Vorontsov | 18e69a3 | 2008-03-14 23:20:18 +0300 | [diff] [blame] | 426 | const char *compat = "fsl-usb2-dr"; |
Anton Vorontsov | 015b27b | 2008-07-08 20:59:43 +0400 | [diff] [blame^] | 427 | const char *prop_mode = "dr_mode"; |
| 428 | const char *prop_type = "phy_type"; |
Anton Vorontsov | 18e69a3 | 2008-03-14 23:20:18 +0300 | [diff] [blame] | 429 | int node_offset; |
| 430 | int err; |
| 431 | |
| 432 | mode = getenv("usb_dr_mode"); |
Anton Vorontsov | 015b27b | 2008-07-08 20:59:43 +0400 | [diff] [blame^] | 433 | type = getenv("usb_phy_type"); |
| 434 | if (!mode && !type) |
Anton Vorontsov | 18e69a3 | 2008-03-14 23:20:18 +0300 | [diff] [blame] | 435 | return; |
| 436 | |
| 437 | node_offset = fdt_node_offset_by_compatible(blob, 0, compat); |
Anton Vorontsov | 015b27b | 2008-07-08 20:59:43 +0400 | [diff] [blame^] | 438 | if (node_offset < 0) { |
Anton Vorontsov | 18e69a3 | 2008-03-14 23:20:18 +0300 | [diff] [blame] | 439 | printf("WARNING: could not find compatible node %s: %s.\n", |
| 440 | compat, fdt_strerror(node_offset)); |
Anton Vorontsov | 015b27b | 2008-07-08 20:59:43 +0400 | [diff] [blame^] | 441 | return; |
| 442 | } |
Anton Vorontsov | 18e69a3 | 2008-03-14 23:20:18 +0300 | [diff] [blame] | 443 | |
Anton Vorontsov | 015b27b | 2008-07-08 20:59:43 +0400 | [diff] [blame^] | 444 | if (mode) { |
| 445 | err = fdt_setprop(blob, node_offset, prop_mode, mode, |
| 446 | strlen(mode) + 1); |
| 447 | if (err < 0) |
| 448 | printf("WARNING: could not set %s for %s: %s.\n", |
| 449 | prop_mode, compat, fdt_strerror(err)); |
| 450 | } |
| 451 | |
| 452 | if (type) { |
| 453 | err = fdt_setprop(blob, node_offset, prop_type, type, |
| 454 | strlen(type) + 1); |
| 455 | if (err < 0) |
| 456 | printf("WARNING: could not set %s for %s: %s.\n", |
| 457 | prop_type, compat, fdt_strerror(err)); |
| 458 | } |
Anton Vorontsov | 18e69a3 | 2008-03-14 23:20:18 +0300 | [diff] [blame] | 459 | } |
| 460 | #endif /* CONFIG_HAS_FSL_DR_USB */ |
Kim Phillips | 6b70ffb | 2008-06-16 15:55:53 -0500 | [diff] [blame] | 461 | |
| 462 | #if defined(CONFIG_MPC83XX) || defined(CONFIG_MPC85xx) |
| 463 | /* |
| 464 | * update crypto node properties to a specified revision of the SEC |
| 465 | * called with sec_rev == 0 if not on an mpc8xxxE processor |
| 466 | */ |
| 467 | void fdt_fixup_crypto_node(void *blob, int sec_rev) |
| 468 | { |
| 469 | const struct sec_rev_prop { |
| 470 | u32 sec_rev; |
| 471 | u32 num_channels; |
| 472 | u32 channel_fifo_len; |
| 473 | u32 exec_units_mask; |
| 474 | u32 descriptor_types_mask; |
| 475 | } sec_rev_prop_list [] = { |
| 476 | { 0x0200, 4, 24, 0x07e, 0x01010ebf }, /* SEC 2.0 */ |
| 477 | { 0x0201, 4, 24, 0x0fe, 0x012b0ebf }, /* SEC 2.1 */ |
| 478 | { 0x0202, 1, 24, 0x04c, 0x0122003f }, /* SEC 2.2 */ |
| 479 | { 0x0204, 4, 24, 0x07e, 0x012b0ebf }, /* SEC 2.4 */ |
| 480 | { 0x0300, 4, 24, 0x9fe, 0x03ab0ebf }, /* SEC 3.0 */ |
| 481 | { 0x0303, 4, 24, 0x97c, 0x03ab0abf }, /* SEC 3.3 */ |
| 482 | }; |
| 483 | char compat_strlist[ARRAY_SIZE(sec_rev_prop_list) * |
| 484 | sizeof("fsl,secX.Y")]; |
| 485 | int crypto_node, sec_idx, err; |
| 486 | char *p; |
| 487 | u32 val; |
| 488 | |
| 489 | /* locate crypto node based on lowest common compatible */ |
| 490 | crypto_node = fdt_node_offset_by_compatible(blob, -1, "fsl,sec2.0"); |
| 491 | if (crypto_node == -FDT_ERR_NOTFOUND) |
| 492 | return; |
| 493 | |
| 494 | /* delete it if not on an E-processor */ |
| 495 | if (crypto_node > 0 && !sec_rev) { |
| 496 | fdt_del_node(blob, crypto_node); |
| 497 | return; |
| 498 | } |
| 499 | |
| 500 | /* else we got called for possible uprev */ |
| 501 | for (sec_idx = 0; sec_idx < ARRAY_SIZE(sec_rev_prop_list); sec_idx++) |
| 502 | if (sec_rev_prop_list[sec_idx].sec_rev == sec_rev) |
| 503 | break; |
| 504 | |
| 505 | if (sec_idx == ARRAY_SIZE(sec_rev_prop_list)) { |
| 506 | puts("warning: unknown SEC revision number\n"); |
| 507 | return; |
| 508 | } |
| 509 | |
| 510 | val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].num_channels); |
| 511 | err = fdt_setprop(blob, crypto_node, "fsl,num-channels", &val, 4); |
| 512 | if (err < 0) |
| 513 | printf("WARNING: could not set crypto property: %s\n", |
| 514 | fdt_strerror(err)); |
| 515 | |
| 516 | val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].descriptor_types_mask); |
| 517 | err = fdt_setprop(blob, crypto_node, "fsl,descriptor-types-mask", &val, 4); |
| 518 | if (err < 0) |
| 519 | printf("WARNING: could not set crypto property: %s\n", |
| 520 | fdt_strerror(err)); |
| 521 | |
| 522 | val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].exec_units_mask); |
| 523 | err = fdt_setprop(blob, crypto_node, "fsl,exec-units-mask", &val, 4); |
| 524 | if (err < 0) |
| 525 | printf("WARNING: could not set crypto property: %s\n", |
| 526 | fdt_strerror(err)); |
| 527 | |
| 528 | val = cpu_to_fdt32(sec_rev_prop_list[sec_idx].channel_fifo_len); |
| 529 | err = fdt_setprop(blob, crypto_node, "fsl,channel-fifo-len", &val, 4); |
| 530 | if (err < 0) |
| 531 | printf("WARNING: could not set crypto property: %s\n", |
| 532 | fdt_strerror(err)); |
| 533 | |
| 534 | val = 0; |
| 535 | while (sec_idx >= 0) { |
| 536 | p = compat_strlist + val; |
| 537 | val += sprintf(p, "fsl,sec%d.%d", |
| 538 | (sec_rev_prop_list[sec_idx].sec_rev & 0xff00) >> 8, |
| 539 | sec_rev_prop_list[sec_idx].sec_rev & 0x00ff) + 1; |
| 540 | sec_idx--; |
| 541 | } |
| 542 | err = fdt_setprop(blob, crypto_node, "compatible", &compat_strlist, val); |
| 543 | if (err < 0) |
| 544 | printf("WARNING: could not set crypto property: %s\n", |
| 545 | fdt_strerror(err)); |
| 546 | } |
| 547 | #endif /* defined(CONFIG_MPC83XX) || defined(CONFIG_MPC85xx) */ |