diff mbox

[U-Boot,v2,17/21] keymile boards: add CONFIG_PIGGY_MAC_ADRESS_OFFSET

Message ID 1300179844-8951-18-git-send-email-hs@denx.de
State Superseded
Headers show

Commit Message

Heiko Schocher March 15, 2011, 9:04 a.m. UTC
Normaly the PIGGY_MAC_ADRESS can be read directly from the
IVM on keymile boards. On mgcoge3 it differs. Because there
are two piggy boards deployed the second MAC adress must be
calculated with the IVM mac adress and an offset. This patch
allows to set such a offset in the board config.

Signed-off-by: Holger Brunck <holger.brunck@keymile.com>
cc: Valentin Longchamp <valentin.longchamp@keymile.com>
cc: Heiko Schocher <hs@denx.de>
---
Changes for v2:
  - fix checkpatch.pl errors and warnings

 board/keymile/common/common.c |   20 ++++++++++++++++++++
 board/keymile/common/common.h |    3 +++
 2 files changed, 23 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/board/keymile/common/common.c b/board/keymile/common/common.c
index 5bb18a8..ecb9664 100644
--- a/board/keymile/common/common.c
+++ b/board/keymile/common/common.c
@@ -227,8 +227,28 @@  static int ivm_analyze_block2 (unsigned char *buf, int len)
 			buf[5],
 			buf[6]);
 	ivm_set_value ("IVM_MacAddress", (char *)valbuf);
+	/* if an offset is defined, add it */
+#if defined(CONFIG_PIGGY_MAC_ADRESS_OFFSET)
+	if (CONFIG_PIGGY_MAC_ADRESS_OFFSET > 0) {
+		unsigned long val = (buf[4] << 16) + (buf[5] << 8) + buf[6];
+
+		val += CONFIG_PIGGY_MAC_ADRESS_OFFSET;
+		buf[4] = (val >> 16) & 0xff;
+		buf[5] = (val >> 8) & 0xff;
+		buf[6] = val & 0xff;
+
+		sprintf((char *)valbuf, "%02X:%02X:%02X:%02X:%02X:%02X",
+			buf[1],
+			buf[2],
+			buf[3],
+			buf[4],
+			buf[5],
+			buf[6]);
+	}
+#endif
 	if (getenv ("ethaddr") == NULL)
 		setenv ((char *)"ethaddr", (char *)valbuf);
+
 	/* IVM_MacCount */
 	count = (buf[10] << 24) +
 		   (buf[11] << 16) +
diff --git a/board/keymile/common/common.h b/board/keymile/common/common.h
index 8fabe77..a2adf1d 100644
--- a/board/keymile/common/common.h
+++ b/board/keymile/common/common.h
@@ -11,6 +11,9 @@ 
 #ifndef __KEYMILE_COMMON_H
 #define __KEYMILE_COMMON_H
 
+#if !defined(CONFIG_PIGGY_MAC_ADRESS_OFFSET)
+#define CONFIG_PIGGY_MAC_ADRESS_OFFSET	0
+#endif
 int ethernet_present(void);
 int ivm_read_eeprom(void);
 void writeStartSeq(void);