Commit ba37aa03287c5483c61c0a3e320c8888bee0143a
Committed by
Wolfgang Denk
1 parent
4cacf7c646
Exists in
master
and in
54 other branches
fdt: rework fdt_fixup_ethernet() to use env instead of bd_t
Move to using the environment variables 'ethaddr', 'eth1addr', etc.. instead of bd->bi_enetaddr, bi_enet1addr, etc. This makes the code a bit more flexible to the number of ethernet interfaces. Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Showing 10 changed files with 36 additions and 50 deletions Side-by-side Diff
common/fdt_support.c
... | ... | @@ -368,55 +368,41 @@ |
368 | 368 | return 0; |
369 | 369 | } |
370 | 370 | |
371 | -#if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) ||\ | |
372 | - defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3) | |
373 | - | |
374 | -void fdt_fixup_ethernet(void *fdt, bd_t *bd) | |
371 | +void fdt_fixup_ethernet(void *fdt) | |
375 | 372 | { |
376 | - int node; | |
373 | + int node, i, j; | |
374 | + char enet[16], *tmp, *end; | |
375 | + char mac[16] = "ethaddr"; | |
377 | 376 | const char *path; |
377 | + unsigned char mac_addr[6]; | |
378 | 378 | |
379 | 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); | |
380 | + if (node < 0) | |
381 | + return; | |
382 | + | |
383 | + i = 0; | |
384 | + while ((tmp = getenv(mac)) != NULL) { | |
385 | + sprintf(enet, "ethernet%d", i); | |
386 | + path = fdt_getprop(fdt, node, enet, NULL); | |
387 | + if (!path) { | |
388 | + debug("No alias for %s\n", enet); | |
389 | + sprintf(mac, "eth%daddr", ++i); | |
390 | + continue; | |
388 | 391 | } |
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); | |
392 | + | |
393 | + for (j = 0; j < 6; j++) { | |
394 | + mac_addr[j] = tmp ? simple_strtoul(tmp, &end, 16) : 0; | |
395 | + if (tmp) | |
396 | + tmp = (*end) ? end+1 : end; | |
397 | 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 | |
398 | + | |
399 | + do_fixup_by_path(fdt, path, "mac-address", &mac_addr, 6, 0); | |
400 | + do_fixup_by_path(fdt, path, "local-mac-address", | |
401 | + &mac_addr, 6, 1); | |
402 | + | |
403 | + sprintf(mac, "eth%daddr", ++i); | |
417 | 404 | } |
418 | 405 | } |
419 | -#endif | |
420 | 406 | |
421 | 407 | #ifdef CONFIG_HAS_FSL_DR_USB |
422 | 408 | void fdt_fixup_dr_usb(void *blob, bd_t *bd) |
cpu/74xx_7xx/cpu.c
cpu/mpc512x/cpu.c
cpu/mpc8260/cpu.c
... | ... | @@ -307,7 +307,7 @@ |
307 | 307 | |
308 | 308 | #if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) ||\ |
309 | 309 | defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3) |
310 | - fdt_fixup_ethernet(blob, bd); | |
310 | + fdt_fixup_ethernet(blob); | |
311 | 311 | #endif |
312 | 312 | |
313 | 313 | do_fixup_by_path_u32(blob, cpu_path, "bus-frequency", bd->bi_busfreq, 1); |
cpu/mpc83xx/fdt.c
... | ... | @@ -53,7 +53,7 @@ |
53 | 53 | |
54 | 54 | #if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) ||\ |
55 | 55 | defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3) |
56 | - fdt_fixup_ethernet(blob, bd); | |
56 | + fdt_fixup_ethernet(blob); | |
57 | 57 | #endif |
58 | 58 | |
59 | 59 | do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, |
cpu/mpc85xx/fdt.c
... | ... | @@ -212,7 +212,7 @@ |
212 | 212 | |
213 | 213 | #if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) ||\ |
214 | 214 | defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3) |
215 | - fdt_fixup_ethernet(blob, bd); | |
215 | + fdt_fixup_ethernet(blob); | |
216 | 216 | #endif |
217 | 217 | |
218 | 218 | do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, |
cpu/mpc86xx/fdt.c
cpu/mpc8xx/fdt.c
cpu/ppc4xx/fdt.c
include/fdt_support.h
... | ... | @@ -45,7 +45,7 @@ |
45 | 45 | void do_fixup_by_compat_u32(void *fdt, const char *compat, |
46 | 46 | const char *prop, u32 val, int create); |
47 | 47 | int fdt_fixup_memory(void *blob, u64 start, u64 size); |
48 | -void fdt_fixup_ethernet(void *fdt, bd_t *bd); | |
48 | +void fdt_fixup_ethernet(void *fdt); | |
49 | 49 | int fdt_find_and_setprop(void *fdt, const char *node, const char *prop, |
50 | 50 | const void *val, int len, int create); |
51 | 51 | void fdt_fixup_qe_firmware(void *fdt); |