[PATCH 10/17] bootwrapper: Add dt_set_mac_addresses().

Scott Wood scottwood at freescale.com
Sat Mar 17 04:28:53 EST 2007


This adds a library function that platform code can call to set the mac
addresses of network devices with a linux,network-index property,
according to a caller-provided table of mac address pointers.

Signed-off-by: Scott Wood <scottwood at freescale.com>
---
 arch/powerpc/boot/devtree.c |   28 ++++++++++++++++++++++++++++
 arch/powerpc/boot/ops.h     |    1 +
 2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/boot/devtree.c b/arch/powerpc/boot/devtree.c
index bfb7dcb..ae2d26b 100644
--- a/arch/powerpc/boot/devtree.c
+++ b/arch/powerpc/boot/devtree.c
@@ -241,3 +241,31 @@ void dt_set_cpu_clocks(u32 clock, u32 bus, u32 timebase)
 		setprop(node, "timebase-frequency", &timebase, 4);
 	}
 }
+
+/* mac_table points to a table of mac addresses, where the index
+ * into the table for a given device corresponds to the
+ * linux,network-index property of its device node.  Network
+ * device nodes without such a property will not be assigned
+ * addresses by this function.
+ */
+void dt_set_mac_addresses(u8 **mac_table, int num_addrs)
+{
+	void *node = NULL;
+
+	while ((node = find_node_by_devtype(node, "network"))) {
+		u32 index;
+		u8 dummy[6];
+
+		if (getprop(node, "linux,network-index",
+		            &index, sizeof(index)) != sizeof(index))
+			continue;
+
+		if (index >= num_addrs)
+			continue;
+
+		if (getprop(node, "mac-address", dummy, 6) == 6)
+			setprop(node, "mac-address", mac_table[index], 6);
+
+		setprop(node, "local-mac-address", mac_table[index], 6);
+	}
+}
diff --git a/arch/powerpc/boot/ops.h b/arch/powerpc/boot/ops.h
index c739764..64e5472 100644
--- a/arch/powerpc/boot/ops.h
+++ b/arch/powerpc/boot/ops.h
@@ -82,6 +82,7 @@ void *simple_alloc_init(char *base, u32 heap_size, u32 granularity,
 int xlate_reg(void *node, int res, unsigned long *addr, unsigned long *size);
 void dt_set_memory(u64 start, u64 len, int ncells);
 void dt_set_cpu_clocks(u32 clock, u32 bus, u32 timebase);
+void dt_set_mac_addresses(u8 **mac_table, int num_addrs);
 
 static inline void *finddevice(const char *name)
 {
-- 
1.5.0.3




More information about the Linuxppc-dev mailing list