Commit ba37aa03287c5483c61c0a3e320c8888bee0143a

Authored by Kumar Gala
Committed by Wolfgang Denk
1 parent 4cacf7c646

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)
... ... @@ -314,7 +314,7 @@
314 314  
315 315 fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
316 316  
317   - fdt_fixup_ethernet(blob, bd);
  317 + fdt_fixup_ethernet(blob);
318 318 }
319 319 #endif
320 320 /* ------------------------------------------------------------------------- */
... ... @@ -191,7 +191,7 @@
191 191 #endif
192 192 ft_clock_setup(blob, bd);
193 193 #ifdef CONFIG_HAS_ETH0
194   - fdt_fixup_ethernet(blob, bd);
  194 + fdt_fixup_ethernet(blob);
195 195 #endif
196 196 }
197 197 #endif
... ... @@ -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);
... ... @@ -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,
... ... @@ -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,
... ... @@ -25,7 +25,7 @@
25 25  
26 26 #if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) \
27 27 || defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3)
28   - fdt_fixup_ethernet(blob, bd);
  28 + fdt_fixup_ethernet(blob);
29 29 #endif
30 30  
31 31 #ifdef CFG_NS16550
... ... @@ -40,7 +40,7 @@
40 40 gd->brg_clk, 1);
41 41  
42 42 /* Fixup ethernet MAC addresses */
43   - fdt_fixup_ethernet(blob, bd);
  43 + fdt_fixup_ethernet(blob);
44 44  
45 45 fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
46 46 }
... ... @@ -130,7 +130,7 @@
130 130 * Fixup all ethernet nodes
131 131 * Note: aliases in the dts are required for this
132 132 */
133   - fdt_fixup_ethernet(blob, bd);
  133 + fdt_fixup_ethernet(blob);
134 134  
135 135 /*
136 136 * Fixup all available PCIe nodes by setting the device_type property
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);