Add fdt_fixup_ethernet helper to set mac addresses
authorKumar Gala <galak@kernel.crashing.org>
Wed, 21 Nov 2007 17:11:03 +0000 (11:11 -0600)
committerKumar Gala <galak@kernel.crashing.org>
Wed, 21 Nov 2007 21:08:56 +0000 (15:08 -0600)
Added a fixup helper that uses aliases to set mac addresses
in the device tree based on the bd_t

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
common/fdt_support.c
include/fdt_support.h

index d5743b445d1ee4346148f71a07f3ef76aaa2a5f2..e848386fbef8344112d990ec9c3390e56a94fdb8 100644 (file)
@@ -386,4 +386,50 @@ void do_fixup_by_path_u32(void *fdt, const char *path, const char *prop,
        do_fixup_by_path(fdt, path, prop, &val, sizeof(val), create);
 }
 
+void fdt_fixup_ethernet(void *fdt, bd_t *bd)
+{
+       int node;
+       const char *path;
+
+       node = fdt_path_offset(fdt, "/aliases");
+       if (node >= 0) {
+#if defined(CONFIG_HAS_ETH0)
+               path = fdt_getprop(fdt, node, "ethernet0", NULL);
+               if (path) {
+                       do_fixup_by_path(fdt, path, "mac-address",
+                               bd->bi_enetaddr, 6, 0);
+                       do_fixup_by_path(fdt, path, "local-mac-address",
+                               bd->bi_enetaddr, 6, 1);
+               }
+#endif
+#if defined(CONFIG_HAS_ETH1)
+               path = fdt_getprop(fdt, node, "ethernet1", NULL);
+               if (path) {
+                       do_fixup_by_path(fdt, path, "mac-address",
+                               bd->bi_enet1addr, 6, 0);
+                       do_fixup_by_path(fdt, path, "local-mac-address",
+                               bd->bi_enet1addr, 6, 1);
+               }
+#endif
+#if defined(CONFIG_HAS_ETH2)
+               path = fdt_getprop(fdt, node, "ethernet2", NULL);
+               if (path) {
+                       do_fixup_by_path(fdt, path, "mac-address",
+                               bd->bi_enet2addr, 6, 0);
+                       do_fixup_by_path(fdt, path, "local-mac-address",
+                               bd->bi_enet2addr, 6, 1);
+               }
+#endif
+#if defined(CONFIG_HAS_ETH3)
+               path = fdt_getprop(fdt, node, "ethernet3", NULL);
+               if (path) {
+                       do_fixup_by_path(fdt, path, "mac-address",
+                               bd->bi_enet3addr, 6, 0);
+                       do_fixup_by_path(fdt, path, "local-mac-address",
+                               bd->bi_enet3addr, 6, 1);
+               }
+#endif
+       }
+}
+
 #endif /* CONFIG_OF_LIBFDT */
index 0314dfdf822e50cde50338939d13b6651ae63a35..150dd2b22fc6bd622ea29f3c2c1d8efb96236a4c 100644 (file)
@@ -33,6 +33,7 @@ void do_fixup_by_path(void *fdt, const char *path, const char *prop,
                      const void *val, int len, int create);
 void do_fixup_by_path_u32(void *fdt, const char *path, const char *prop,
                          u32 val, int create);
+void fdt_fixup_ethernet(void *fdt, bd_t *bd);
 
 #ifdef CONFIG_OF_HAS_UBOOT_ENV
 int fdt_env(void *fdt);