Skip to contentSkip to conversation

Retrieve MAC address from EEPROM

PATCH New Olliver Schinagl 3 participants 24 messages Dec 14, 2015 – Jan 26, 2016

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v2 cover Retrieve MAC address from EEPROM

Changes since v1:
* Do not CRC the id byte, move it just after the crc byte.
One of the reasons I decided to move it after the crc8 was mostly due to mass generation of MAC + CRC combo's where the ID is still unknown. Also not crc-ing the ID means that it is much easier for a user to change it (via the u-boot i2c cmd line or from within linux) without having to worry about the crc.
* Add a generator to convert a MAC address from the input to a MAC + CRC8 on the output.

Olliver Schinagl (5):
net: Add ability to set MAC address via EEPROM to Kconfig
sunxi: net: Allow the sunxi to set the MAC from an EEPROM
sunxi: net: Enable eeprom on OLinuXino Lime2 boards
tools: Allow crc8 to be used
tools: Add tool to add crc8 to a mac address

 board/sunxi/Kconfig                   |  4 +++
 board/sunxi/board.c                   | 36 +++++++++++++++++++++
 configs/A20-OLinuXino-Lime2_defconfig |  3 ++
 doc/README.enetaddr                   | 34 ++++++++++++++++++++
 include/u-boot/crc.h                  |  3 ++
 net/Kconfig                           | 59 +++++++++++++++++++++++++++++++++++
 tools/Makefile                        |  5 +++
 tools/gen_mac_addr.c                  | 51 ++++++++++++++++++++++++++++++
 8 files changed, 195 insertions(+)
 create mode 100644 tools/gen_mac_addr.c
Signature · 1 line
2.6.2
#1 lore raw

PATCH v2 1/5 net: Add ability to set MAC address via EEPROM to Kconfig

This patch allows Kconfig to enable and set parameters to make it possible to read the MAC address from an EEPROM. This patch only sets up some environment variables, it is up to the specific boards to actually use these defines.

Besides the various tuneables as to how to access the eeprom (bus, address, addressing mode/length, 2 configurable that are EEPROM generic (e.g. SPI or some other form of access) which are:

NET_ETHADDR_EEPROM_OFFSET, indicating where in the EEPROM the start of the MAC address is. The default is 8 allowing for 8 bytes before the MAC for other purposes (header MAGIC for example).

NET_ETHADDR_EEPROM_CRC8, indicating the MAC is appended with a CRC8-CCIT checksum that should be verified.

Currently only I2C eeproms have been tested and thus only those options are available, but shouldn't be a limit. NET_ETHADDR_EEPROM_SPI can be just as created.

---
 doc/README.enetaddr | 34 +++++++++++++++++++++++++++++++
 net/Kconfig         | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+)
doc/README.enetaddr +34 -0
index 50e4899..1dc4119 100644
@@ -47,6 +47,40 @@ Correct flow of setting up the MAC address (summarized):
 Previous behavior had the MAC address always being programmed into hardware
 in the device's init() function.
 
+--------
+ EEPROM
+--------
+
+When there is an EEPROM available on a board, but the EEPROM is not large enough
+to store the whole environment, it may be desired to store a MAC address in the
+onboard EEPROM. Using CONFIG_NET_ETHADDR_EEPROM enables this feature. Depending
+on the board, the EEPROM may be connected on various methods, but currently,
+only the I2C bus is available via CONFIG_NET_ETHADDR_EEPROM_I2C.
+CONFIG_NET_ETHADDR_EEPROM_I2C_BUS I2C bus on which the eeprom is present and
+CONFIG_NET_ETHADDR_EEPROM_I2C_ADDR set the address of the EEPROM, which
+defaults to the very common 0x50. Small size EEPROM's generally use single byte
+addressing but larger EEPROM's may use double byte addressing, which can be
+configured using CONFIG_NET_ETHADDR_EEPROM_ADDRLEN.
+
+Within the EEPROM, the MAC address can be stored on any arbitrary offset,
+CONFIG_NET_ETHADDR_EEPROM_OFFSET sets this to 8 as a default however, allowing
+the first 8 bytes to be used for an optional data, for example a header magic.
+
+Appending the 6 MAC bytes a CRC8 byte over the previous 6 bytes. Whether to check
+this CRC8 or not is dependent on CONFIG_NET_ETHADDR_EEPROM_CRC8.
+
+After the 6 bytes used for the MAC address, the 8th byte is used to indicate
+the ID of the network interface this MAC address is for. 0xff here means 'for
+the first available interface' and 0x00 means the first network interface, 0x01
+the second, etc. It is up to the platform however to enforce this.
+
+Layout example:
+
+00000000  21 4d 61 67 69 63 2e 21  01 23 45 67 89 ab be ff |!Magic.!.#Eg....|
+
+where the Header magic (!Magic.!) is spread over the first 8 bytes, and the MAC
+address '01-23-45-67-89-ab' with the CRC8 checksum 0xbe for any interface (0xff)
+
 -------
  Usage
 -------
net/Kconfig +58 -0

64 lines not on this page · raw message

Signature · 1 line
2.6.2
#2 lore raw

PATCH v2 1/5 net: Add ability to set MAC address via EEPROM to Kconfig

Quoted 13 lines · Olliver Schinagl

This patch allows Kconfig to enable and set parameters to make it possible to read the MAC address from an EEPROM. This patch only sets up some environment variables, it is up to the specific boards to actually use these defines.

Besides the various tuneables as to how to access the eeprom (bus, address, addressing mode/length, 2 configurable that are EEPROM generic (e.g. SPI or some other form of access) which are:

NET_ETHADDR_EEPROM_OFFSET, indicating where in the EEPROM the start of the MAC address is. The default is 8 allowing for 8 bytes before the MAC for other purposes (header MAGIC for example).

Quoted 8 lines

NET_ETHADDR_EEPROM_CRC8, indicating the MAC is appended with a CRC8-CCIT checksum that should be verified.

Currently only I2C eeproms have been tested and thus only those options are available, but shouldn't be a limit. NET_ETHADDR_EEPROM_SPI can be just as created.

#3 lore raw

PATCH v2 2/5 sunxi: net: Allow the sunxi to set the MAC from an EEPROM

In reply to Olliver Schinagl

This patch uses the newly introduced Kconfig options to set the MAC address from an EEPROM, this will be especially useful for the Olimex OLinuXino series of sunxi boards as they all have an 2k i2c eeprom chip.

The MAC address is in the eeprom is ignored if there is already a MAC address in the environment or (if enabled) the CRC8 check fails.

---
 board/sunxi/Kconfig |  4 ++++
 board/sunxi/board.c | 36 ++++++++++++++++++++++++++++++++++++
 net/Kconfig         |  1 +
 3 files changed, 41 insertions(+)
board/sunxi/Kconfig +4 -0
index 2dd9d3b..a2da3a6 100644
@@ -339,18 +339,21 @@ config I2C0_ENABLE
 
 config I2C1_ENABLE
 	bool "Enable I2C/TWI controller 1"
+	default y if (NET_ETHADDR_EEPROM_I2C_BUS = 1)
 	default n
 	---help---
 	See I2C0_ENABLE help text.
 
 config I2C2_ENABLE
 	bool "Enable I2C/TWI controller 2"
+	default y if NET_ETHADDR_EEPROM_I2C_BUS = 2
 	default n
 	---help---
 	See I2C0_ENABLE help text.
 
 if MACH_SUN6I || MACH_SUN7I
 config I2C3_ENABLE
+	default y if NET_ETHADDR_EEPROM_I2C_BUS = 3
 	bool "Enable I2C/TWI controller 3"
 	default n
 	---help---
@@ -359,6 +362,7 @@ endif
 
 if MACH_SUN7I
 config I2C4_ENABLE
+	default y if NET_ETHADDR_EEPROM_I2C_BUS = 4
 	bool "Enable I2C/TWI controller 4"
 	default n
 	---help---
board/sunxi/board.c +36 -0
index 6ac398c..28310a2 100644
@@ -12,6 +12,7 @@
  */
 
 #include <common.h>
+#include <i2c.h>
 #include <mmc.h>
 #include <axp_pmic.h>
 #include <asm/arch/clock.h>
@@ -23,6 +24,7 @@
 #include <asm/arch/usb_phy.h>
 #include <asm/gpio.h>
 #include <asm/io.h>
+#include <linux/crc8.h>
 #include <nand.h>
 #include <net.h>
 
@@ -510,6 +512,37 @@ void get_board_serial(struct tag_serialnr *serialnr)
 }
 #endif
 
+#if defined(CONFIG_NET_ETHADDR_EEPROM) && defined(CONFIG_NET_ETHADDR_EEPROM_I2C)
+static int read_mac_from_eeprom(uint8_t *mac_addr)
+{
+	uint8_t eeprom[7];
+	int old_i2c_bus;
+
+	old_i2c_bus = i2c_get_bus_num();
+	i2c_set_bus_num(CONFIG_NET_ETHADDR_EEPROM_I2C_BUS);
+	if (i2c_read(CONFIG_NET_ETHADDR_EEPROM_I2C_ADDR,
+		     CONFIG_NET_ETHADDR_EEPROM_OFFSET,
+		     CONFIG_NET_ETHADDR_EEPROM_I2C_ADDRLEN,
+		     eeprom, 7)) {
+		i2c_set_bus_num(old_i2c_bus);
+		puts("Could not read the EEPROM; EEPROM missing?\n");
+		return -1;
+	}
+	i2c_set_bus_num(old_i2c_bus);
+#ifdef CONFIG_NET_ETHADDR_EEPROM_CRC8
+	if (crc8(eeprom, 6) != eeprom[6]) {
+		puts("CRC error on MAC address from EEPROM.\n");
+		return -1;
+	}
+#endif
+	memcpy(mac_addr, eeprom, 6);
+
+	return 0;
+}
+#else
+static int read_mac_from_eeprom(uint8_t *mac_addr) { return -1; }
+#endif
+
 #if !defined(CONFIG_SPL_BUILD)
 #include <asm/arch/spl.h>
 
@@ -553,6 +586,9 @@ int misc_init_r(void)
 	}
 #endif
 
+	if ((!getenv("ethaddr")) && (!read_mac_from_eeprom(mac_addr)))
+		eth_setenv_enetaddr("ethaddr", mac_addr);
+
 	ret = sunxi_get_sid(sid);
 	if (ret == 0 && sid[0] != 0 && sid[3] != 0) {
 		if (!getenv("ethaddr")) {
net/Kconfig +1 -0
index aced51e..0f4cc5a 100644
@@ -8,6 +8,7 @@ menuconfig NET
 if NET
 
 config NET_ETHADDR_EEPROM
+	depends on ARCH_SUNXI
 	bool "Get ethaddr from eeprom"
 	help
 	  Selecting this will try to get the Ethernet address from an onboard
Signature · 1 line
2.6.2
#4 lore raw

PATCH v2 2/5 sunxi: net: Allow the sunxi to set the MAC from an EEPROM

Quoted 5 lines · Olliver Schinagl

This patch uses the newly introduced Kconfig options to set the MAC address from an EEPROM, this will be especially useful for the Olimex OLinuXino series of sunxi boards as they all have an 2k i2c eeprom chip.

The MAC address is in the eeprom is ignored if there is already a MAC

"The MAC address in the eeprom is ignored..."

Quoted 102 lines

address in the environment or (if enabled) the CRC8 check fails.

---
 board/sunxi/Kconfig |  4 ++++
 board/sunxi/board.c | 36 ++++++++++++++++++++++++++++++++++++
 net/Kconfig         |  1 +
 3 files changed, 41 insertions(+)
board/sunxi/Kconfig +4 -0
index 2dd9d3b..a2da3a6 100644
@@ -339,18 +339,21 @@ config I2C0_ENABLE
 
 config I2C1_ENABLE
        bool "Enable I2C/TWI controller 1"
+       default y if (NET_ETHADDR_EEPROM_I2C_BUS = 1)
        default n
        ---help---
        See I2C0_ENABLE help text.
 
 config I2C2_ENABLE
        bool "Enable I2C/TWI controller 2"
+       default y if NET_ETHADDR_EEPROM_I2C_BUS = 2
        default n
        ---help---
        See I2C0_ENABLE help text.
 
 if MACH_SUN6I || MACH_SUN7I
 config I2C3_ENABLE
+       default y if NET_ETHADDR_EEPROM_I2C_BUS = 3
        bool "Enable I2C/TWI controller 3"
        default n
        ---help---
@@ -359,6 +362,7 @@ endif
 
 if MACH_SUN7I
 config I2C4_ENABLE
+       default y if NET_ETHADDR_EEPROM_I2C_BUS = 4
        bool "Enable I2C/TWI controller 4"
        default n
        ---help---
board/sunxi/board.c +33 -0
index 6ac398c..28310a2 100644
@@ -12,6 +12,7 @@
  */
 
 #include <common.h>
+#include <i2c.h>
 #include <mmc.h>
 #include <axp_pmic.h>
 #include <asm/arch/clock.h>
@@ -23,6 +24,7 @@
 #include <asm/arch/usb_phy.h>
 #include <asm/gpio.h>
 #include <asm/io.h>
+#include <linux/crc8.h>
 #include <nand.h>
 #include <net.h>
 
@@ -510,6 +512,37 @@ void get_board_serial(struct tag_serialnr *serialnr)
 }
 #endif
 
+#if defined(CONFIG_NET_ETHADDR_EEPROM) && defined(CONFIG_NET_ETHADDR_EEPROM_I2C)
+static int read_mac_from_eeprom(uint8_t *mac_addr)
+{
+       uint8_t eeprom[7];
+       int old_i2c_bus;
+
+       old_i2c_bus = i2c_get_bus_num();
+       i2c_set_bus_num(CONFIG_NET_ETHADDR_EEPROM_I2C_BUS);
+       if (i2c_read(CONFIG_NET_ETHADDR_EEPROM_I2C_ADDR,
+                    CONFIG_NET_ETHADDR_EEPROM_OFFSET,
+                    CONFIG_NET_ETHADDR_EEPROM_I2C_ADDRLEN,
+                    eeprom, 7)) {
+               i2c_set_bus_num(old_i2c_bus);
+               puts("Could not read the EEPROM; EEPROM missing?\n");
+               return -1;
+       }
+       i2c_set_bus_num(old_i2c_bus);
+#ifdef CONFIG_NET_ETHADDR_EEPROM_CRC8
+       if (crc8(eeprom, 6) != eeprom[6]) {
+               puts("CRC error on MAC address from EEPROM.\n");
+               return -1;
+       }
+#endif
+       memcpy(mac_addr, eeprom, 6);
+
+       return 0;
+}
+#else
+static int read_mac_from_eeprom(uint8_t *mac_addr) { return -1; }
+#endif
+
 #if !defined(CONFIG_SPL_BUILD)
 #include <asm/arch/spl.h>
 

board/sunxi/board.c int misc_init_r(void) · line 590

Quoted 5 lines
board/sunxi/board.c +2 -0
@@ -553,6 +586,9 @@ int misc_init_r(void)
        }
 #endif
 
+       if ((!getenv("ethaddr")) && (!read_mac_from_eeprom(mac_addr)))
+               eth_setenv_enetaddr("ethaddr", mac_addr);

It seems a bit odd to actually write this to the environment instead of it being a read_rom_hwaddr operation for the Ethernet driver that this board uses.

Do we need a different board-level ROM callback? Maybe the drivers used in such situations can be the only ones to support it.

Quoted 23 lines
board/sunxi/board.c +1 -0
+
        ret = sunxi_get_sid(sid);
        if (ret == 0 && sid[0] != 0 && sid[3] != 0) {
                if (!getenv("ethaddr")) {
net/Kconfig +1 -1
index aced51e..0f4cc5a 100644
@@ -8,6 +8,7 @@ menuconfig NET
 if NET
 
 config NET_ETHADDR_EEPROM
+       depends on ARCH_SUNXI
        bool "Get ethaddr from eeprom"
        help
          Selecting this will try to get the Ethernet address from an onboard
--

2.6.2

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#5 lore raw

PATCH v2 2/5 sunxi: net: Allow the sunxi to set the MAC from an EEPROM

Hey Joe

Quoted 8 lines · Joe Hershberger
Quoted 5 lines · Olliver Schinagl

This patch uses the newly introduced Kconfig options to set the MAC address from an EEPROM, this will be especially useful for the Olimex OLinuXino series of sunxi boards as they all have an 2k i2c eeprom chip.

The MAC address is in the eeprom is ignored if there is already a MAC

"The MAC address in the eeprom is ignored..."

oops :) fixed for v3

Quoted 106 lines
Quoted 106 lines

address in the environment or (if enabled) the CRC8 check fails.

---
  board/sunxi/Kconfig |  4 ++++
  board/sunxi/board.c | 36 ++++++++++++++++++++++++++++++++++++
  net/Kconfig         |  1 +
  3 files changed, 41 insertions(+)
board/sunxi/Kconfig +4 -0
index 2dd9d3b..a2da3a6 100644
@@ -339,18 +339,21 @@ config I2C0_ENABLE
 
  config I2C1_ENABLE
         bool "Enable I2C/TWI controller 1"
+       default y if (NET_ETHADDR_EEPROM_I2C_BUS = 1)
         default n
         ---help---
         See I2C0_ENABLE help text.
 
  config I2C2_ENABLE
         bool "Enable I2C/TWI controller 2"
+       default y if NET_ETHADDR_EEPROM_I2C_BUS = 2
         default n
         ---help---
         See I2C0_ENABLE help text.
 
  if MACH_SUN6I || MACH_SUN7I
  config I2C3_ENABLE
+       default y if NET_ETHADDR_EEPROM_I2C_BUS = 3
         bool "Enable I2C/TWI controller 3"
         default n
         ---help---
@@ -359,6 +362,7 @@ endif
 
  if MACH_SUN7I
  config I2C4_ENABLE
+       default y if NET_ETHADDR_EEPROM_I2C_BUS = 4
         bool "Enable I2C/TWI controller 4"
         default n
         ---help---
board/sunxi/board.c +33 -0
index 6ac398c..28310a2 100644
@@ -12,6 +12,7 @@
   */
 
  #include <common.h>
+#include <i2c.h>
  #include <mmc.h>
  #include <axp_pmic.h>
  #include <asm/arch/clock.h>
@@ -23,6 +24,7 @@
  #include <asm/arch/usb_phy.h>
  #include <asm/gpio.h>
  #include <asm/io.h>
+#include <linux/crc8.h>
  #include <nand.h>
  #include <net.h>
 
@@ -510,6 +512,37 @@ void get_board_serial(struct tag_serialnr *serialnr)
  }
  #endif
 
+#if defined(CONFIG_NET_ETHADDR_EEPROM) && defined(CONFIG_NET_ETHADDR_EEPROM_I2C)
+static int read_mac_from_eeprom(uint8_t *mac_addr)
+{
+       uint8_t eeprom[7];
+       int old_i2c_bus;
+
+       old_i2c_bus = i2c_get_bus_num();
+       i2c_set_bus_num(CONFIG_NET_ETHADDR_EEPROM_I2C_BUS);
+       if (i2c_read(CONFIG_NET_ETHADDR_EEPROM_I2C_ADDR,
+                    CONFIG_NET_ETHADDR_EEPROM_OFFSET,
+                    CONFIG_NET_ETHADDR_EEPROM_I2C_ADDRLEN,
+                    eeprom, 7)) {
+               i2c_set_bus_num(old_i2c_bus);
+               puts("Could not read the EEPROM; EEPROM missing?\n");
+               return -1;
+       }
+       i2c_set_bus_num(old_i2c_bus);
+#ifdef CONFIG_NET_ETHADDR_EEPROM_CRC8
+       if (crc8(eeprom, 6) != eeprom[6]) {
+               puts("CRC error on MAC address from EEPROM.\n");
+               return -1;
+       }
+#endif
+       memcpy(mac_addr, eeprom, 6);
+
+       return 0;
+}
+#else
+static int read_mac_from_eeprom(uint8_t *mac_addr) { return -1; }
+#endif
+
  #if !defined(CONFIG_SPL_BUILD)
  #include <asm/arch/spl.h>
 
@@ -553,6 +586,9 @@ int misc_init_r(void)
         }
  #endif
 
Quoted 8 lines

board/sunxi/board.c int misc_init_r(void) · line 590

Quoted 2 lines
board/sunxi/board.c +2 -0
+       if ((!getenv("ethaddr")) && (!read_mac_from_eeprom(mac_addr)))
+               eth_setenv_enetaddr("ethaddr", mac_addr);

It seems a bit odd to actually write this to the environment instead of it being a read_rom_hwaddr operation for the Ethernet driver that this board uses.

Do we need a different board-level ROM callback? Maybe the drivers used in such situations can be the only ones to support it.

I'm hoping your thinking out-loud, as I'm not too familiar with all the backing code. But if I understand you correctly, you suggest to implement a new callback for ethernet drivers to get mac's from eeprom? Anyhow, I just followed suit with how the address gets set in case of when it is not in the environment and we need to generate a random one.

I was reading the u-boot documentation and though the assumed method was to use the environment and to only use other methods (such as the eeprom method) where it is absolutely a must. In this case the eeprom is not directly related to the ethernet, it's a generic eeprom.

But then again, I am new to this stuff so I can be gladly very wrong here :)

Quoted 24 lines
Quoted 24 lines
board/sunxi/board.c +1 -0
+
         ret = sunxi_get_sid(sid);
         if (ret == 0 && sid[0] != 0 && sid[3] != 0) {
                 if (!getenv("ethaddr")) {
net/Kconfig +1 -1
index aced51e..0f4cc5a 100644
@@ -8,6 +8,7 @@ menuconfig NET
  if NET
 
  config NET_ETHADDR_EEPROM
+       depends on ARCH_SUNXI
         bool "Get ethaddr from eeprom"
         help
           Selecting this will try to get the Ethernet address from an onboard
--

2.6.2

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Signature · 6 lines
Met vriendelijke groeten, Kind regards, ??????

Olliver Schinagl
Software Engineer
Research & Development
Ultimaker B.V.
#6 lore raw

PATCH v2 2/5 sunxi: net: Allow the sunxi to set the MAC from an EEPROM

Quoted 131 lines · Olliver Schinagl

Hey Joe

Quoted 11 lines · Joe Hershberger
Quoted 6 lines · Olliver Schinagl

This patch uses the newly introduced Kconfig options to set the MAC address from an EEPROM, this will be especially useful for the Olimex OLinuXino series of sunxi boards as they all have an 2k i2c eeprom chip.

The MAC address is in the eeprom is ignored if there is already a MAC

"The MAC address in the eeprom is ignored..."

oops :) fixed for v3

Quoted 114 lines
Quoted 104 lines

address in the environment or (if enabled) the CRC8 check fails.

---
  board/sunxi/Kconfig |  4 ++++
  board/sunxi/board.c | 36 ++++++++++++++++++++++++++++++++++++
  net/Kconfig         |  1 +
  3 files changed, 41 insertions(+)
board/sunxi/Kconfig +4 -0
index 2dd9d3b..a2da3a6 100644
@@ -339,18 +339,21 @@ config I2C0_ENABLE
 
  config I2C1_ENABLE
         bool "Enable I2C/TWI controller 1"
+       default y if (NET_ETHADDR_EEPROM_I2C_BUS = 1)
         default n
         ---help---
         See I2C0_ENABLE help text.
 
  config I2C2_ENABLE
         bool "Enable I2C/TWI controller 2"
+       default y if NET_ETHADDR_EEPROM_I2C_BUS = 2
         default n
         ---help---
         See I2C0_ENABLE help text.
 
  if MACH_SUN6I || MACH_SUN7I
  config I2C3_ENABLE
+       default y if NET_ETHADDR_EEPROM_I2C_BUS = 3
         bool "Enable I2C/TWI controller 3"
         default n
         ---help---
@@ -359,6 +362,7 @@ endif
 
  if MACH_SUN7I
  config I2C4_ENABLE
+       default y if NET_ETHADDR_EEPROM_I2C_BUS = 4
         bool "Enable I2C/TWI controller 4"
         default n
         ---help---
board/sunxi/board.c +33 -0
index 6ac398c..28310a2 100644
@@ -12,6 +12,7 @@
   */
 
  #include <common.h>
+#include <i2c.h>
  #include <mmc.h>
  #include <axp_pmic.h>
  #include <asm/arch/clock.h>
@@ -23,6 +24,7 @@
  #include <asm/arch/usb_phy.h>
  #include <asm/gpio.h>
  #include <asm/io.h>
+#include <linux/crc8.h>
  #include <nand.h>
  #include <net.h>
 
@@ -510,6 +512,37 @@ void get_board_serial(struct tag_serialnr *serialnr)
  }
  #endif
 
+#if defined(CONFIG_NET_ETHADDR_EEPROM) &&
 defined(CONFIG_NET_ETHADDR_EEPROM_I2C)
+static int read_mac_from_eeprom(uint8_t *mac_addr)
+{
+       uint8_t eeprom[7];
+       int old_i2c_bus;
+
+       old_i2c_bus = i2c_get_bus_num();
+       i2c_set_bus_num(CONFIG_NET_ETHADDR_EEPROM_I2C_BUS);
+       if (i2c_read(CONFIG_NET_ETHADDR_EEPROM_I2C_ADDR,
+                    CONFIG_NET_ETHADDR_EEPROM_OFFSET,
+                    CONFIG_NET_ETHADDR_EEPROM_I2C_ADDRLEN,
+                    eeprom, 7)) {
+               i2c_set_bus_num(old_i2c_bus);
+               puts("Could not read the EEPROM; EEPROM missing?\n");
+               return -1;
+       }
+       i2c_set_bus_num(old_i2c_bus);
+#ifdef CONFIG_NET_ETHADDR_EEPROM_CRC8
+       if (crc8(eeprom, 6) != eeprom[6]) {
+               puts("CRC error on MAC address from EEPROM.\n");
+               return -1;
+       }
+#endif
+       memcpy(mac_addr, eeprom, 6);
+
+       return 0;
+}
+#else
+static int read_mac_from_eeprom(uint8_t *mac_addr) { return -1; }
+#endif
+
  #if !defined(CONFIG_SPL_BUILD)
  #include <asm/arch/spl.h>

board/sunxi/board.c int misc_init_r(void) · line 590

Quoted 5 lines
board/sunxi/board.c +2 -0
@@ -553,6 +586,9 @@ int misc_init_r(void)
         }
  #endif
 
+       if ((!getenv("ethaddr")) && (!read_mac_from_eeprom(mac_addr)))
+               eth_setenv_enetaddr("ethaddr", mac_addr);

It seems a bit odd to actually write this to the environment instead of it being a read_rom_hwaddr operation for the Ethernet driver that this board uses.

Quoted 4 lines
Quoted 2 lines

Do we need a different board-level ROM callback? Maybe the drivers used in such situations can be the only ones to support it.

I'm hoping your thinking out-loud, as I'm not too familiar with all the

Indeed. I was thinking out loud.

Quoted 2 lines

backing code. But if I understand you correctly, you suggest to implement a new callback for ethernet drivers to get mac's from eeprom? Anyhow, I just

Not for now... at least not in the core code.

Quoted 2 lines

followed suit with how the address gets set in case of when it is not in the environment and we need to generate a random one.

Sure. I don't think it's the same case though. We already have the entry for the driver to read the rom ethaddr. I think you should use that.

Quoted 4 lines

I was reading the u-boot documentation and though the assumed method was to use the environment and to only use other methods (such as the eeprom method) where it is absolutely a must. In this case the eeprom is not directly related to the ethernet, it's a generic eeprom.

Sure. I think you should add support to whatever driver your board uses (it's a driver model driver, right?) for a weak board function. That way that one driver is responsible for that behavior because of your board's need. Any other boards that use that driver just don't supply that function and it is a no-op. I'd rather be able to easily follow where that ethaddr is getting configured instead of using misc_init_r() and having the env populate magically. This also means you'll be in a context to write the ethaddr to the pdata struct instead of the env.

Quoted 2 lines

But then again, I am new to this stuff so I can be gladly very wrong here :)

Seems it's not a case that comes up, so it's fairly new territory.

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
board/sunxi/board.c +1 -0
+
         ret = sunxi_get_sid(sid);
         if (ret == 0 && sid[0] != 0 && sid[3] != 0) {
                 if (!getenv("ethaddr")) {
net/Kconfig +0 -0
index aced51e..0f4cc5a 100644
@@ -8,6 +8,7 @@ menuconfig NET
  if NET
 
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
net/Kconfig +1 -0
  config NET_ETHADDR_EEPROM
+       depends on ARCH_SUNXI
         bool "Get ethaddr from eeprom"
         help
           Selecting this will try to get the Ethernet address from an

onboard

Thanks,
-Joe

#7 lore raw

PATCH v2 2/5 sunxi: net: Allow the sunxi to set the MAC from an EEPROM

Hey Joe,

Quoted 134 lines · Joe Hershberger
Quoted 125 lines · Olliver Schinagl

Hey Joe

Quoted 8 lines · Joe Hershberger
Quoted 5 lines · Olliver Schinagl

This patch uses the newly introduced Kconfig options to set the MAC address from an EEPROM, this will be especially useful for the Olimex OLinuXino series of sunxi boards as they all have an 2k i2c eeprom chip.

The MAC address is in the eeprom is ignored if there is already a MAC

"The MAC address in the eeprom is ignored..."

oops :) fixed for v3

Quoted 112 lines
Quoted 103 lines

address in the environment or (if enabled) the CRC8 check fails.

---
   board/sunxi/Kconfig |  4 ++++
   board/sunxi/board.c | 36 ++++++++++++++++++++++++++++++++++++
   net/Kconfig         |  1 +
   3 files changed, 41 insertions(+)
board/sunxi/Kconfig +4 -0
index 2dd9d3b..a2da3a6 100644
@@ -339,18 +339,21 @@ config I2C0_ENABLE
 
   config I2C1_ENABLE
          bool "Enable I2C/TWI controller 1"
+       default y if (NET_ETHADDR_EEPROM_I2C_BUS = 1)
          default n
          ---help---
          See I2C0_ENABLE help text.
 
   config I2C2_ENABLE
          bool "Enable I2C/TWI controller 2"
+       default y if NET_ETHADDR_EEPROM_I2C_BUS = 2
          default n
          ---help---
          See I2C0_ENABLE help text.
 
   if MACH_SUN6I || MACH_SUN7I
   config I2C3_ENABLE
+       default y if NET_ETHADDR_EEPROM_I2C_BUS = 3
          bool "Enable I2C/TWI controller 3"
          default n
          ---help---
@@ -359,6 +362,7 @@ endif
 
   if MACH_SUN7I
   config I2C4_ENABLE
+       default y if NET_ETHADDR_EEPROM_I2C_BUS = 4
          bool "Enable I2C/TWI controller 4"
          default n
          ---help---
board/sunxi/board.c +33 -0
index 6ac398c..28310a2 100644
@@ -12,6 +12,7 @@
    */
 
   #include <common.h>
+#include <i2c.h>
   #include <mmc.h>
   #include <axp_pmic.h>
   #include <asm/arch/clock.h>
@@ -23,6 +24,7 @@
   #include <asm/arch/usb_phy.h>
   #include <asm/gpio.h>
   #include <asm/io.h>
+#include <linux/crc8.h>
   #include <nand.h>
   #include <net.h>
 
@@ -510,6 +512,37 @@ void get_board_serial(struct tag_serialnr *serialnr)
   }
   #endif
 
+#if defined(CONFIG_NET_ETHADDR_EEPROM) &&
 defined(CONFIG_NET_ETHADDR_EEPROM_I2C)
+static int read_mac_from_eeprom(uint8_t *mac_addr)
+{
+       uint8_t eeprom[7];
+       int old_i2c_bus;
+
+       old_i2c_bus = i2c_get_bus_num();
+       i2c_set_bus_num(CONFIG_NET_ETHADDR_EEPROM_I2C_BUS);
+       if (i2c_read(CONFIG_NET_ETHADDR_EEPROM_I2C_ADDR,
+                    CONFIG_NET_ETHADDR_EEPROM_OFFSET,
+                    CONFIG_NET_ETHADDR_EEPROM_I2C_ADDRLEN,
+                    eeprom, 7)) {
+               i2c_set_bus_num(old_i2c_bus);
+               puts("Could not read the EEPROM; EEPROM missing?\n");
+               return -1;
+       }
+       i2c_set_bus_num(old_i2c_bus);
+#ifdef CONFIG_NET_ETHADDR_EEPROM_CRC8
+       if (crc8(eeprom, 6) != eeprom[6]) {
+               puts("CRC error on MAC address from EEPROM.\n");
+               return -1;
+       }
+#endif
+       memcpy(mac_addr, eeprom, 6);
+
+       return 0;
+}
+#else
+static int read_mac_from_eeprom(uint8_t *mac_addr) { return -1; }
+#endif
+
   #if !defined(CONFIG_SPL_BUILD)
   #include <asm/arch/spl.h>

board/sunxi/board.c int misc_init_r(void) · line 590

Quoted 5 lines
board/sunxi/board.c +2 -0
@@ -553,6 +586,9 @@ int misc_init_r(void)
          }
   #endif
 
+       if ((!getenv("ethaddr")) && (!read_mac_from_eeprom(mac_addr)))
+               eth_setenv_enetaddr("ethaddr", mac_addr);

It seems a bit odd to actually write this to the environment instead of it being a read_rom_hwaddr operation for the Ethernet driver that this board uses.

Quoted 3 lines
Quoted 2 lines

Do we need a different board-level ROM callback? Maybe the drivers used in such situations can be the only ones to support it.

I'm hoping your thinking out-loud, as I'm not too familiar with all the

Indeed. I was thinking out loud.

Quoted 2 lines

backing code. But if I understand you correctly, you suggest to implement a new callback for ethernet drivers to get mac's from eeprom? Anyhow, I just

Quoted 7 lines

Not for now... at least not in the core code.

Quoted 2 lines

followed suit with how the address gets set in case of when it is not in the environment and we need to generate a random one.

Sure. I don't think it's the same case though. We already have the entry for the driver to read the rom ethaddr. I think you should use that.

I think I lost you here, what function/example can you point me to that uses this already so I can spy/learn from?

olliver

Quoted 38 lines
Quoted 5 lines

I was reading the u-boot documentation and though the assumed method was to use the environment and to only use other methods (such as the eeprom method) where it is absolutely a must. In this case the eeprom is not directly related to the ethernet, it's a generic eeprom.

Sure. I think you should add support to whatever driver your board uses (it's a driver model driver, right?) for a weak board function. That way that one driver is responsible for that behavior because of your board's need. Any other boards that use that driver just don't supply that function and it is a no-op. I'd rather be able to easily follow where that ethaddr is getting configured instead of using misc_init_r() and having the env populate magically. This also means you'll be in a context to write the ethaddr to the pdata struct instead of the env.

Quoted 1 line

But then again, I am new to this stuff so I can be gladly very wrong here :)

Seems it's not a case that comes up, so it's fairly new territory.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
board/sunxi/board.c +1 -0
+
          ret = sunxi_get_sid(sid);
          if (ret == 0 && sid[0] != 0 && sid[3] != 0) {
                  if (!getenv("ethaddr")) {
net/Kconfig +0 -0
index aced51e..0f4cc5a 100644
@@ -8,6 +8,7 @@ menuconfig NET
   if NET
 
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
net/Kconfig +1 -0
   config NET_ETHADDR_EEPROM
+       depends on ARCH_SUNXI
          bool "Get ethaddr from eeprom"
          help
            Selecting this will try to get the Ethernet address from an

onboard

Thanks,
-Joe

Signature · 6 lines
Met vriendelijke groeten, Kind regards, ??????

Olliver Schinagl
Software Engineer
Research & Development
Ultimaker B.V.
#8 lore raw

PATCH v2 2/5 sunxi: net: Allow the sunxi to set the MAC from an EEPROM

Quoted 158 lines · Olliver Schinagl

Hey Joe,

Quoted 154 lines · Joe Hershberger
Quoted 133 lines · Olliver Schinagl

Hey Joe

Quoted 4 lines · Joe Hershberger
Quoted 1 line · Olliver Schinagl
Quoted 8 lines
Quoted 6 lines

This patch uses the newly introduced Kconfig options to set the MAC address from an EEPROM, this will be especially useful for the Olimex OLinuXino series of sunxi boards as they all have an 2k i2c eeprom chip.

The MAC address is in the eeprom is ignored if there is already a MAC

"The MAC address in the eeprom is ignored..."

oops :) fixed for v3

Quoted 114 lines
Quoted 104 lines

address in the environment or (if enabled) the CRC8 check fails.

---
   board/sunxi/Kconfig |  4 ++++
   board/sunxi/board.c | 36 ++++++++++++++++++++++++++++++++++++
   net/Kconfig         |  1 +
   3 files changed, 41 insertions(+)
board/sunxi/Kconfig +4 -0
index 2dd9d3b..a2da3a6 100644
@@ -339,18 +339,21 @@ config I2C0_ENABLE
 
   config I2C1_ENABLE
          bool "Enable I2C/TWI controller 1"
+       default y if (NET_ETHADDR_EEPROM_I2C_BUS = 1)
          default n
          ---help---
          See I2C0_ENABLE help text.
 
   config I2C2_ENABLE
          bool "Enable I2C/TWI controller 2"
+       default y if NET_ETHADDR_EEPROM_I2C_BUS = 2
          default n
          ---help---
          See I2C0_ENABLE help text.
 
   if MACH_SUN6I || MACH_SUN7I
   config I2C3_ENABLE
+       default y if NET_ETHADDR_EEPROM_I2C_BUS = 3
          bool "Enable I2C/TWI controller 3"
          default n
          ---help---
@@ -359,6 +362,7 @@ endif
 
   if MACH_SUN7I
   config I2C4_ENABLE
+       default y if NET_ETHADDR_EEPROM_I2C_BUS = 4
          bool "Enable I2C/TWI controller 4"
          default n
          ---help---
board/sunxi/board.c +33 -0
index 6ac398c..28310a2 100644
@@ -12,6 +12,7 @@
    */
 
   #include <common.h>
+#include <i2c.h>
   #include <mmc.h>
   #include <axp_pmic.h>
   #include <asm/arch/clock.h>
@@ -23,6 +24,7 @@
   #include <asm/arch/usb_phy.h>
   #include <asm/gpio.h>
   #include <asm/io.h>
+#include <linux/crc8.h>
   #include <nand.h>
   #include <net.h>
 
@@ -510,6 +512,37 @@ void get_board_serial(struct tag_serialnr
 *serialnr)
   }
   #endif
 
+#if defined(CONFIG_NET_ETHADDR_EEPROM) &&
 defined(CONFIG_NET_ETHADDR_EEPROM_I2C)
+static int read_mac_from_eeprom(uint8_t *mac_addr)
+{
+       uint8_t eeprom[7];
+       int old_i2c_bus;
+
+       old_i2c_bus = i2c_get_bus_num();
+       i2c_set_bus_num(CONFIG_NET_ETHADDR_EEPROM_I2C_BUS);
+       if (i2c_read(CONFIG_NET_ETHADDR_EEPROM_I2C_ADDR,
+                    CONFIG_NET_ETHADDR_EEPROM_OFFSET,
+                    CONFIG_NET_ETHADDR_EEPROM_I2C_ADDRLEN,
+                    eeprom, 7)) {
+               i2c_set_bus_num(old_i2c_bus);
+               puts("Could not read the EEPROM; EEPROM missing?\n");
+               return -1;
+       }
+       i2c_set_bus_num(old_i2c_bus);
+#ifdef CONFIG_NET_ETHADDR_EEPROM_CRC8
+       if (crc8(eeprom, 6) != eeprom[6]) {
+               puts("CRC error on MAC address from EEPROM.\n");
+               return -1;
+       }
+#endif
+       memcpy(mac_addr, eeprom, 6);
+
+       return 0;
+}
+#else
+static int read_mac_from_eeprom(uint8_t *mac_addr) { return -1; }
+#endif
+
   #if !defined(CONFIG_SPL_BUILD)
   #include <asm/arch/spl.h>

board/sunxi/board.c int misc_init_r(void) · line 590

Quoted 5 lines
board/sunxi/board.c +2 -0
@@ -553,6 +586,9 @@ int misc_init_r(void)
          }
   #endif
 
+       if ((!getenv("ethaddr")) && (!read_mac_from_eeprom(mac_addr)))
+               eth_setenv_enetaddr("ethaddr", mac_addr);

It seems a bit odd to actually write this to the environment instead of it being a read_rom_hwaddr operation for the Ethernet driver that this board uses.

Quoted 4 lines
Quoted 2 lines

Do we need a different board-level ROM callback? Maybe the drivers used in such situations can be the only ones to support it.

I'm hoping your thinking out-loud, as I'm not too familiar with all the

Indeed. I was thinking out loud.

Quoted 4 lines

backing code. But if I understand you correctly, you suggest to implement a
new callback for ethernet drivers to get mac's from eeprom? Anyhow, I just

Not for now... at least not in the core code.

Quoted 3 lines

followed suit with how the address gets set in case of when it is not in the
environment and we need to generate a random one.

Quoted 6 lines
Quoted 3 lines

Sure. I don't think it's the same case though. We already have the entry for the driver to read the rom ethaddr. I think you should use that.

I think I lost you here, what function/example can you point me to that uses this already so I can spy/learn from?

I think you'll be the first driver ported to use this (it's driver model only).

It should be fairly straightforward. I've mocked up a simple version in the Zynq GEM driver as an example.

(quoted diff) +0 -0

b/arch/arm/mach-zynq/include/mach/sys_proto.h
index 882beab..44c9b50 100644

arch/arm/mach-zynq/include/mach/sys_proto.h +2 -0
@@ -19,6 +19,8 @@ extern int zynq_slcr_get_mio_pin_status(const char *periph);
 extern void zynq_ddrc_init(void);
 extern unsigned int zynq_get_silicon_version(void);
 
+int zynq_board_read_rom_ethaddr(unsigned char *ethaddr);
+
 /* Driver extern functions */
 extern void ps7_init(void);
 
board/xilinx/zynq/board.c +10 -0
index 414f530..ca617a5 100644
@@ -122,6 +122,16 @@ int board_eth_init(bd_t *bis)
        return ret;
 }
 
+#ifdef CONFIG_TARGET_ZYNQ_ZC770
+int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
+{
+       // TODO: Read from eeprom
+       memset(ethaddr, 0, ARP_HLEN);
+
+       return 0;
+}
+#endif
+
 int dram_init(void)
 {
 #if CONFIG_IS_ENABLED(OF_CONTROL)
drivers/net/zynq_gem.c +18 -0
index 7059c84..068f3d0 100644
@@ -588,6 +588,23 @@ static void zynq_gem_halt(struct udevice *dev)
                                                ZYNQ_GEM_NWCTRL_TXEN_MASK, 0);
 }
 
+__weak int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
+{
+       return -ENOSYS;
+}
+
+static int zynq_gem_read_rom_mac(struct udevice *dev)
+{
+       int retval;
+       struct eth_pdata *pdata = dev_get_platdata(dev);
+
+       retval = zynq_board_read_rom_ethaddr(pdata->enetaddr);
+       if (retval == -ENOSYS)
+               retval = 0;
+
+       return retval;
+}
+
 static int zynq_gem_miiphy_read(struct mii_dev *bus, int addr,
                                int devad, int reg)
 {
@@ -661,6 +678,7 @@ static const struct eth_ops zynq_gem_ops = {
        .free_pkt               = zynq_gem_free_pkt,
        .stop                   = zynq_gem_halt,
        .write_hwaddr           = zynq_gem_setup_mac,
+       .read_rom_hwaddr        = zynq_gem_read_rom_mac,
 };
 
 static int zynq_gem_ofdata_to_platdata(struct udevice *dev)

--

Hopefully this makes it more clear what I have in mind.

Thanks,
-Joe

Quoted 55 lines

olliver

Quoted 34 lines
Quoted 6 lines

I was reading the u-boot documentation and though the assumed method was to
use the environment and to only use other methods (such as the eeprom method) where it is absolutely a must. In this case the eeprom is not directly related to the ethernet, it's a generic eeprom.

Sure. I think you should add support to whatever driver your board uses (it's a driver model driver, right?) for a weak board function. That way that one driver is responsible for that behavior because of your board's need. Any other boards that use that driver just don't supply that function and it is a no-op. I'd rather be able to easily follow where that ethaddr is getting configured instead of using misc_init_r() and having the env populate magically. This also means you'll be in a context to write the ethaddr to the pdata struct instead of the env.

Quoted 2 lines

But then again, I am new to this stuff so I can be gladly very wrong here :)

Seems it's not a case that comes up, so it's fairly new territory.

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
board/sunxi/board.c +1 -0
+
          ret = sunxi_get_sid(sid);
          if (ret == 0 && sid[0] != 0 && sid[3] != 0) {
                  if (!getenv("ethaddr")) {
net/Kconfig +0 -0
index aced51e..0f4cc5a 100644
@@ -8,6 +8,7 @@ menuconfig NET
   if NET
 
Quoted 9 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
net/Kconfig +1 -0
   config NET_ETHADDR_EEPROM
+       depends on ARCH_SUNXI
          bool "Get ethaddr from eeprom"
          help
            Selecting this will try to get the Ethernet address from an

onboard

Thanks,
-Joe

--
Met vriendelijke groeten, Kind regards, ??????

Olliver Schinagl
Software Engineer
Research & Development
Ultimaker B.V.

#9 lore raw

PATCH v2 3/5 sunxi: net: Enable eeprom on OLinuXino Lime2 boards

In reply to Olliver Schinagl

This patch enables the I2C EEPROM to be probed for a MAC address on the OLinuXino board.

---
 configs/A20-OLinuXino-Lime2_defconfig | 3 +++
 1 file changed, 3 insertions(+)
configs/A20-OLinuXino-Lime2_defconfig +3 -0
index b5181c6..5e38618 100644
@@ -14,4 +14,7 @@ CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,RGMII,AHCI,SATAPWR=SUNXI_GPC(3)"
 # CONFIG_CMD_FPGA is not set
 CONFIG_CMD_GPIO=y
 CONFIG_ETH_DESIGNWARE=y
+CONFIG_NET_ETHADDR_EEPROM=y
+CONFIG_NET_ETHADDR_EEPROM_I2C=y
+CONFIG_NET_ETHADDR_EEPROM_I2C_BUS=1
 CONFIG_USB_EHCI_HCD=y
Signature · 1 line
2.6.2
#10 lore raw

PATCH v2 3/5 sunxi: net: Enable eeprom on OLinuXino Lime2 boards

Hi Olliver,

Quoted 5 lines · Olliver Schinagl

This patch enables the I2C EEPROM to be probed for a MAC address on the OLinuXino board.

---

You should use patman so that you can keep track of changes in revisions of your patches.

Quoted 22 lines
 configs/A20-OLinuXino-Lime2_defconfig | 3 +++
 1 file changed, 3 insertions(+)
configs/A20-OLinuXino-Lime2_defconfig +3 -1
index b5181c6..5e38618 100644
@@ -14,4 +14,7 @@ CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,RGMII,AHCI,SATAPWR=SUNXI_GPC(3)"
 # CONFIG_CMD_FPGA is not set
 CONFIG_CMD_GPIO=y
 CONFIG_ETH_DESIGNWARE=y
+CONFIG_NET_ETHADDR_EEPROM=y
+CONFIG_NET_ETHADDR_EEPROM_I2C=y
+CONFIG_NET_ETHADDR_EEPROM_I2C_BUS=1
 CONFIG_USB_EHCI_HCD=y
--

2.6.2

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#11 lore raw

PATCH v2 3/5 sunxi: net: Enable eeprom on OLinuXino Lime2 boards

Hey Joe,

Quoted 11 lines · Joe Hershberger

Hi Olliver,

Quoted 5 lines · Olliver Schinagl

This patch enables the I2C EEPROM to be probed for a MAC address on the OLinuXino board.

---

You should use patman so that you can keep track of changes in revisions of your patches.

I just looked up on it and it looks like a good tool! So I will try to get familiar with it, thanks for the tip!

Quoted 23 lines
Quoted 23 lines
  configs/A20-OLinuXino-Lime2_defconfig | 3 +++
  1 file changed, 3 insertions(+)
configs/A20-OLinuXino-Lime2_defconfig +3 -1
index b5181c6..5e38618 100644
@@ -14,4 +14,7 @@ CONFIG_SYS_EXTRA_OPTIONS="SUNXI_GMAC,RGMII,AHCI,SATAPWR=SUNXI_GPC(3)"
  # CONFIG_CMD_FPGA is not set
  CONFIG_CMD_GPIO=y
  CONFIG_ETH_DESIGNWARE=y
+CONFIG_NET_ETHADDR_EEPROM=y
+CONFIG_NET_ETHADDR_EEPROM_I2C=y
+CONFIG_NET_ETHADDR_EEPROM_I2C_BUS=1
  CONFIG_USB_EHCI_HCD=y
--

2.6.2

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Signature · 6 lines
Met vriendelijke groeten, Kind regards, ??????

Olliver Schinagl
Software Engineer
Research & Development
Ultimaker B.V.
#12 lore raw

PATCH v2 4/5 tools: Allow crc8 to be used

In reply to Olliver Schinagl

This patch enables crc8 to be used from within the tools directory using u-boot/crc.h.

---
 include/u-boot/crc.h | 3 +++
 tools/Makefile       | 1 +
 2 files changed, 4 insertions(+)
include/u-boot/crc.h +3 -0
index 754ac72..cbcf175 100644
@@ -9,6 +9,9 @@
 #ifndef _UBOOT_CRC_H
 #define _UBOOT_CRC_H
 
+/* lib/crc8.c */
+unsigned int crc8(const unsigned char *vptr, int len);
+
 /* lib/crc32.c */
 uint32_t crc32 (uint32_t, const unsigned char *, uint);
 uint32_t crc32_wd (uint32_t, const unsigned char *, uint, uint);
tools/Makefile +1 -0
index 9cfd80b..4a50744 100644
@@ -167,6 +167,7 @@ fdtgrep-objs += $(LIBFDT_OBJS) fdtgrep.o
 # that won't build on some weird host compiler -- though there are lots of
 # exceptions for files that aren't complaint.
 HOSTCFLAGS_crc32.o := -pedantic
+HOSTCFLAGS_crc8.o := -pedantic
 HOSTCFLAGS_md5.o := -pedantic
 HOSTCFLAGS_sha1.o := -pedantic
 HOSTCFLAGS_sha256.o := -pedantic
Signature · 1 line
2.6.2
#14 lore raw

PATCH v2 5/5 tools: Add tool to add crc8 to a mac address

In reply to Olliver Schinagl

This patch adds a little tool that takes a generic MAC address and generates a CRC byte for it. The output is the full MAC address without any separators, ready written into an EEPROM.

---
 tools/Makefile       |  4 ++++
 tools/gen_mac_addr.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)
 create mode 100644 tools/gen_mac_addr.c
tools/Makefile +4 -0
index 4a50744..6191c26 100644
@@ -43,6 +43,10 @@ envcrc-objs := envcrc.o lib/crc32.o common/env_embedded.o lib/sha1.o
 hostprogs-$(CONFIG_CMD_NET) += gen_eth_addr
 HOSTCFLAGS_gen_eth_addr.o := -pedantic
 
+hostprogs-$(CONFIG_CMD_NET) += gen_mac_addr
+gen_mac_addr-objs := gen_mac_addr.o lib/crc8.o
+HOSTCFLAGS_gen_mac_addr.o := -pedantic
+
 hostprogs-$(CONFIG_CMD_LOADS) += img2srec
 HOSTCFLAGS_img2srec.o := -pedantic
 
tools/gen_mac_addr.c new file +51 -0

51 lines not on this page · raw message

Signature · 1 line
2.6.2
#15 lore raw

PATCH v2 5/5 tools: Add tool to add crc8 to a mac address

tools/gen_mac_addr.c

Quoted 31 lines · Olliver Schinagl

This patch adds a little tool that takes a generic MAC address and generates a CRC byte for it. The output is the full MAC address without any separators, ready written into an EEPROM.

---
 tools/Makefile       |  4 ++++
 tools/gen_mac_addr.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)
 create mode 100644 tools/gen_mac_addr.c
tools/Makefile +4 -0
index 4a50744..6191c26 100644
@@ -43,6 +43,10 @@ envcrc-objs := envcrc.o lib/crc32.o common/env_embedded.o lib/sha1.o
 hostprogs-$(CONFIG_CMD_NET) += gen_eth_addr
 HOSTCFLAGS_gen_eth_addr.o := -pedantic
 
+hostprogs-$(CONFIG_CMD_NET) += gen_mac_addr
+gen_mac_addr-objs := gen_mac_addr.o lib/crc8.o
+HOSTCFLAGS_gen_mac_addr.o := -pedantic
+
 hostprogs-$(CONFIG_CMD_LOADS) += img2srec
 HOSTCFLAGS_img2srec.o := -pedantic
 
tools/gen_mac_addr.c new file +0 -0
new file mode 100644
index 0000000..bd8688f

This is not "generating a mac address", right? Its point is to create a CRC for the user-supplied MAC address.

Perhaps a better name would be "gen_ethaddr_rom_crc".

Quoted 21 lines
tools/gen_mac_addr.c new file +20 -0
@@ -0,0 +1,51 @@
+/*
+ * (C) Copyright 2016
+ * Olliver Schinagl <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <ctype.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <u-boot/crc.h>
+
+
+int main(int argc, char *argv[])
+{
+       uint_fast8_t i;
+       uint8_t mac_addr[7] = { 0x00 };
+

tools/gen_mac_addr.c line 30

Quoted 10 lines
tools/gen_mac_addr.c new file +10 -0
+       if (argc < 2) {
+               puts("Please supply a MAC address.");
+               return -1;
+       }
+
+       if (!((strlen(argv[1]) == 12) || (strlen(argv[1]) == 17))) {
+               puts("Please supply a valid MAC address with optionaly\n"
+                    "dashes (-) or colons (:) as seperators.");
+               return -1;
+       }

You could use the eth_validate_ethaddr_str() function here instead of this code.

tools/gen_mac_addr.c line 43

Quoted 13 lines
tools/gen_mac_addr.c new file +13 -0
+
+       i = 0;
+       while (*argv[1] != '\0') {
+               char nibble[2] = { 0x00, '\n' }; /* for strtol */
+
+               nibble[0] = *argv[1]++;
+               if (isxdigit(nibble[0])) {
+                       if (isupper(nibble[0]))
+                               nibble[0] = tolower(nibble[0]);
+                       mac_addr[i >> 1] |= strtol(nibble, NULL, 16) << ((i % 2) ? 0 : 4) & ((i % 2) ? 0x0f : 0xf0);
+                       i++;
+               }
+       }

Instead of all this you could just compile in (maybe it already is?) the eth_parse_enetaddr() function that U-Boot uses for this very purpose.

Quoted 15 lines
tools/gen_mac_addr.c new file +8 -1
+       mac_addr[6] = crc8(mac_addr, 6);
+
+       for (i = 0; i < 7; i++)
+               printf("%.2x", mac_addr[i]);
+       putchar('\n');
+
+       return 0;
+}
--

2.6.2

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#16 lore raw

PATCH v2 5/5 tools: Add tool to add crc8 to a mac address

Hello Joe,

Quoted 9 lines · Joe Hershberger
Quoted 1 line · Olliver Schinagl

+++ b/tools/gen_mac_addr.c

This is not "generating a mac address", right? Its point is to create a CRC for the user-supplied MAC address.

Perhaps a better name would be "gen_ethaddr_rom_crc".

Hmm, why the "_rom" part?

Amicalement,

Signature · 1 line
Albert.
#17 lore raw

PATCH v2 5/5 tools: Add tool to add crc8 to a mac address

Hi Albert,

Quoted 7 lines · Albert ARIBAUD

Hello Joe,

Quoted 2 lines · Joe Hershberger

On Mon, Dec 14, 2015 at 6:41 AM, Olliver Schinagl
<[email protected]> wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

+++ b/tools/gen_mac_addr.c

This is not "generating a mac address", right? Its point is to create a CRC for the user-supplied MAC address.

Perhaps a better name would be "gen_ethaddr_rom_crc".

Hmm, why the "_rom" part?

Just to give more hints to the observer that this is for creating a rom or eeprom image to be read by the associated new code in U-Boot.

Cheers,
-Joe

Quoted 4 lines

Amicalement,
--
Albert.

#18 lore raw

PATCH v2 5/5 tools: Add tool to add crc8 to a mac address

Hey all,

Quoted 10 lines · Joe Hershberger

Hi Albert,

Quoted 6 lines · Albert ARIBAUD

Hello Joe,

Quoted 2 lines · Joe Hershberger

On Mon, Dec 14, 2015 at 6:41 AM, Olliver Schinagl
<[email protected]> wrote:

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 1 line

+++ b/tools/gen_mac_addr.c

This is not "generating a mac address", right? Its point is to create a CRC for the user-supplied MAC address.

Perhaps a better name would be "gen_ethaddr_rom_crc".

Hmm, why the "_rom" part?

Just to give more hints to the observer that this is for creating a rom or eeprom image to be read by the associated new code in U-Boot.

Well depending on the output, it could even be used to verify what is stored in an ROM. So i understand Albert's reasoning that it may not be related to ROM at all

Quoted 7 lines

Cheers,
-Joe

Quoted 3 lines

Amicalement,
--
Albert.

Signature · 6 lines
Met vriendelijke groeten, Kind regards, ??????

Olliver Schinagl
Software Engineer
Research & Development
Ultimaker B.V.
#19 lore raw

PATCH v2 5/5 tools: Add tool to add crc8 to a mac address

Quoted 24 lines · Olliver Schinagl

Hey all,

Quoted 21 lines · Joe Hershberger

Hi Albert,

Quoted 16 lines · Albert ARIBAUD

Hello Joe,

Quoted 10 lines · Joe Hershberger
Quoted 2 lines · Olliver Schinagl

+++ b/tools/gen_mac_addr.c

This is not "generating a mac address", right? Its point is to create a CRC for the user-supplied MAC address.

Perhaps a better name would be "gen_ethaddr_rom_crc".

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Hmm, why the "_rom" part?

Just to give more hints to the observer that this is for creating a rom or eeprom image to be read by the associated new code in U-Boot.

Well depending on the output, it could even be used to verify what is stored in an ROM. So i understand Albert's reasoning that it may not be related to ROM at all

You could make it even more generic and just call it gen_crc8... make it take an arbitrary byte stream. Anyway. I think there's no need for speculative generality. Make the tool be named for what its purpose is. Include the features you need it to have. If someone wants to expand it, it can be renamed at that point.

Thanks,
-Joe

#20 lore raw

PATCH v2 5/5 tools: Add tool to add crc8 to a mac address

In reply to Joe Hershberger

Hey Joe,

Quoted 36 lines · Joe Hershberger

tools/gen_mac_addr.c

Quoted 31 lines · Olliver Schinagl

This patch adds a little tool that takes a generic MAC address and generates a CRC byte for it. The output is the full MAC address without any separators, ready written into an EEPROM.

---
  tools/Makefile       |  4 ++++
  tools/gen_mac_addr.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 55 insertions(+)

create mode 100644 tools/gen_mac_addr.c

tools/Makefile +4 -0
index 4a50744..6191c26 100644
@@ -43,6 +43,10 @@ envcrc-objs := envcrc.o lib/crc32.o common/env_embedded.o lib/sha1.o
  hostprogs-$(CONFIG_CMD_NET) += gen_eth_addr
  HOSTCFLAGS_gen_eth_addr.o := -pedantic
 
+hostprogs-$(CONFIG_CMD_NET) += gen_mac_addr
+gen_mac_addr-objs := gen_mac_addr.o lib/crc8.o
+HOSTCFLAGS_gen_mac_addr.o := -pedantic
+
  hostprogs-$(CONFIG_CMD_LOADS) += img2srec
  HOSTCFLAGS_img2srec.o := -pedantic
 
tools/gen_mac_addr.c new file +0 -0
new file mode 100644
index 0000000..bd8688f

This is not "generating a mac address", right? Its point is to create a CRC for the user-supplied MAC address.

Quoted 1 line

Perhaps a better name would be "gen_ethaddr_rom_crc".

Yes, it takes a mac address as input and generates a macaddress + crc as output.

e.g. 11:22:33:44:55:66 -> 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0xcc

But maybe it should get some flags to output either both (as described here) or just the crc based on the input, and then a few flags to either output it in hex format or as an int?

Quoted 25 lines
Quoted 25 lines
tools/gen_mac_addr.c new file +23 -0
@@ -0,0 +1,51 @@
+/*
+ * (C) Copyright 2016
+ * Olliver Schinagl <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <ctype.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <u-boot/crc.h>
+
+
+int main(int argc, char *argv[])
+{
+       uint_fast8_t i;
+       uint8_t mac_addr[7] = { 0x00 };
+
+       if (argc < 2) {
+               puts("Please supply a MAC address.");
+               return -1;
Quoted 8 lines

tools/gen_mac_addr.c line 30

Quoted 7 lines
tools/gen_mac_addr.c new file +7 -0
+       }
+
+       if (!((strlen(argv[1]) == 12) || (strlen(argv[1]) == 17))) {
+               puts("Please supply a valid MAC address with optionaly\n"
+                    "dashes (-) or colons (:) as seperators.");
+               return -1;
+       }

You could use the eth_validate_ethaddr_str() function here instead of this code.

A right, well when I first wrote this, I think this didn't exist there yet. I'll replace it and use it instead.

Quoted 17 lines
Quoted 4 lines
tools/gen_mac_addr.c new file +3 -0
+
+       i = 0;
+       while (*argv[1] != '\0') {

tools/gen_mac_addr.c line 43

Quoted 10 lines
tools/gen_mac_addr.c new file +10 -0
+               char nibble[2] = { 0x00, '\n' }; /* for strtol */
+
+               nibble[0] = *argv[1]++;
+               if (isxdigit(nibble[0])) {
+                       if (isupper(nibble[0]))
+                               nibble[0] = tolower(nibble[0]);
+                       mac_addr[i >> 1] |= strtol(nibble, NULL, 16) << ((i % 2) ? 0 : 4) & ((i % 2) ? 0x0f : 0xf0);
+                       i++;
+               }
+       }

Instead of all this you could just compile in (maybe it already is?) the eth_parse_enetaddr() function that U-Boot uses for this very purpose.

I'll see if I can have access to this function and then rewrite this to use that.

Quoted 16 lines
Quoted 16 lines
tools/gen_mac_addr.c new file +8 -1
+       mac_addr[6] = crc8(mac_addr, 6);
+
+       for (i = 0; i < 7; i++)
+               printf("%.2x", mac_addr[i]);
+       putchar('\n');
+
+       return 0;
+}
--

2.6.2

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Signature · 6 lines
Met vriendelijke groeten, Kind regards, ??????

Olliver Schinagl
Software Engineer
Research & Development
Ultimaker B.V.
#21 lore raw

PATCH v2 5/5 tools: Add tool to add crc8 to a mac address

Quoted 47 lines · Olliver Schinagl

Hey Joe,

Quoted 41 lines · Joe Hershberger

tools/gen_mac_addr.c

Quoted 34 lines · Olliver Schinagl

This patch adds a little tool that takes a generic MAC address and generates a CRC byte for it. The output is the full MAC address without any separators, ready written into an EEPROM.

---
  tools/Makefile       |  4 ++++
  tools/gen_mac_addr.c | 51
+++++++++++++++++++++++++++++++++++++++++++++++++++
  2 files changed, 55 insertions(+)

create mode 100644 tools/gen_mac_addr.c

tools/Makefile +0 -0
index 4a50744..6191c26 100644
@@ -43,6 +43,10 @@ envcrc-objs := envcrc.o lib/crc32.o

common/env_embedded.o lib/sha1.o
hostprogs-$(CONFIG_CMD_NET) += gen_eth_addr
HOSTCFLAGS_gen_eth_addr.o := -pedantic

tools/Makefile +4 -0
+hostprogs-$(CONFIG_CMD_NET) += gen_mac_addr
+gen_mac_addr-objs := gen_mac_addr.o lib/crc8.o
+HOSTCFLAGS_gen_mac_addr.o := -pedantic
+
  hostprogs-$(CONFIG_CMD_LOADS) += img2srec
  HOSTCFLAGS_img2srec.o := -pedantic
tools/gen_mac_addr.c new file +0 -0
new file mode 100644
index 0000000..bd8688f

This is not "generating a mac address", right? Its point is to create a CRC for the user-supplied MAC address.

Quoted 1 line

Perhaps a better name would be "gen_ethaddr_rom_crc".

Quoted 8 lines

Yes, it takes a mac address as input and generates a macaddress + crc as output.

e.g. 11:22:33:44:55:66 -> 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0xcc

But maybe it should get some flags to output either both (as described here) or just the crc based on the input, and then a few flags to either output it in hex format or as an int?

What ever features you think will be useful for the users of this dev board I guess. I'm not sure if this is a platform (the included eeprom) that would carry over into other products.

Quoted 88 lines
Quoted 27 lines
Quoted 27 lines
tools/gen_mac_addr.c new file +25 -0
@@ -0,0 +1,51 @@
+/*
+ * (C) Copyright 2016
+ * Olliver Schinagl <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <ctype.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <u-boot/crc.h>
+
+
+int main(int argc, char *argv[])
+{
+       uint_fast8_t i;
+       uint8_t mac_addr[7] = { 0x00 };
+
+       if (argc < 2) {
+               puts("Please supply a MAC address.");
+               return -1;
+       }
+
Quoted 8 lines

tools/gen_mac_addr.c line 30

Quoted 5 lines
tools/gen_mac_addr.c new file +5 -0
+       if (!((strlen(argv[1]) == 12) || (strlen(argv[1]) == 17))) {
+               puts("Please supply a valid MAC address with optionaly\n"
+                    "dashes (-) or colons (:) as seperators.");
+               return -1;
+       }

You could use the eth_validate_ethaddr_str() function here instead of this code.

A right, well when I first wrote this, I think this didn't exist there yet. I'll replace it and use it instead.

Quoted 12 lines
Quoted 12 lines
tools/gen_mac_addr.c new file +10 -0
+
+       i = 0;
+       while (*argv[1] != '\0') {
+               char nibble[2] = { 0x00, '\n' }; /* for strtol */
+
+               nibble[0] = *argv[1]++;
+               if (isxdigit(nibble[0])) {
+                       if (isupper(nibble[0]))
+                               nibble[0] = tolower(nibble[0]);
+                       mac_addr[i >> 1] |= strtol(nibble, NULL, 16) <<
Quoted 8 lines

tools/gen_mac_addr.c line 43

Quoted 4 lines

((i % 2) ? 0 : 4) & ((i % 2) ? 0x0f : 0xf0);

tools/gen_mac_addr.c new file +3 -0
+                       i++;
+               }
+       }

Instead of all this you could just compile in (maybe it already is?) the eth_parse_enetaddr() function that U-Boot uses for this very purpose.

I'll see if I can have access to this function and then rewrite this to use that.

Quoted 12 lines
Quoted 12 lines
tools/gen_mac_addr.c new file +8 -1
+       mac_addr[6] = crc8(mac_addr, 6);
+
+       for (i = 0; i < 7; i++)
+               printf("%.2x", mac_addr[i]);
+       putchar('\n');
+
+       return 0;
+}
--

2.6.2

Quoted 4 lines
Quoted 4 lines

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

--
Met vriendelijke groeten, Kind regards, ??????

Olliver Schinagl
Software Engineer
Research & Development
Ultimaker B.V.

#22 lore raw

PATCH v2 5/5 tools: Add tool to add crc8 to a mac address

Hey Joe,

Quoted 48 lines · Joe Hershberger
Quoted 46 lines · Olliver Schinagl

Hey Joe,

Quoted 38 lines · Joe Hershberger

tools/gen_mac_addr.c

Quoted 33 lines · Olliver Schinagl

This patch adds a little tool that takes a generic MAC address and generates a CRC byte for it. The output is the full MAC address without any separators, ready written into an EEPROM.

---
   tools/Makefile       |  4 ++++
   tools/gen_mac_addr.c | 51
+++++++++++++++++++++++++++++++++++++++++++++++++++
   2 files changed, 55 insertions(+)

create mode 100644 tools/gen_mac_addr.c

tools/Makefile +0 -0
index 4a50744..6191c26 100644
@@ -43,6 +43,10 @@ envcrc-objs := envcrc.o lib/crc32.o

common/env_embedded.o lib/sha1.o
hostprogs-$(CONFIG_CMD_NET) += gen_eth_addr
HOSTCFLAGS_gen_eth_addr.o := -pedantic

tools/Makefile +4 -0
+hostprogs-$(CONFIG_CMD_NET) += gen_mac_addr
+gen_mac_addr-objs := gen_mac_addr.o lib/crc8.o
+HOSTCFLAGS_gen_mac_addr.o := -pedantic
+
   hostprogs-$(CONFIG_CMD_LOADS) += img2srec
   HOSTCFLAGS_img2srec.o := -pedantic
tools/gen_mac_addr.c new file +0 -0
new file mode 100644
index 0000000..bd8688f

This is not "generating a mac address", right? Its point is to create a CRC for the user-supplied MAC address.

Quoted 1 line

Perhaps a better name would be "gen_ethaddr_rom_crc".

Yes, it takes a mac address as input and generates a macaddress + crc as output.

Quoted 8 lines
Quoted 5 lines

e.g. 11:22:33:44:55:66 -> 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0xcc

But maybe it should get some flags to output either both (as described here) or just the crc based on the input, and then a few flags to either output it in hex format or as an int?

What ever features you think will be useful for the users of this dev board I guess. I'm not sure if this is a platform (the included eeprom) that would carry over into other products.

Why not? It just reads a mac address and generates a crc8-appended mac address (or just the crc8) everybody that uses a mac address to be stored somewhere (even if the env is pre-generated) could use this. I don't think it is limited to our platform since it does something very generic.

Quoted 81 lines
Quoted 81 lines
Quoted 26 lines
Quoted 26 lines
tools/gen_mac_addr.c new file +24 -0
@@ -0,0 +1,51 @@
+/*
+ * (C) Copyright 2016
+ * Olliver Schinagl <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <ctype.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <u-boot/crc.h>
+
+
+int main(int argc, char *argv[])
+{
+       uint_fast8_t i;
+       uint8_t mac_addr[7] = { 0x00 };
+
+       if (argc < 2) {
+               puts("Please supply a MAC address.");
+               return -1;
+       }
Quoted 8 lines

tools/gen_mac_addr.c line 30

Quoted 6 lines
tools/gen_mac_addr.c new file +6 -0
+
+       if (!((strlen(argv[1]) == 12) || (strlen(argv[1]) == 17))) {
+               puts("Please supply a valid MAC address with optionaly\n"
+                    "dashes (-) or colons (:) as seperators.");
+               return -1;
+       }

You could use the eth_validate_ethaddr_str() function here instead of this code.

A right, well when I first wrote this, I think this didn't exist there yet. I'll replace it and use it instead.

Quoted 10 lines
Quoted 10 lines
tools/gen_mac_addr.c new file +9 -0
+
+       i = 0;
+       while (*argv[1] != '\0') {
+               char nibble[2] = { 0x00, '\n' }; /* for strtol */
+
+               nibble[0] = *argv[1]++;
+               if (isxdigit(nibble[0])) {
+                       if (isupper(nibble[0]))
+                               nibble[0] = tolower(nibble[0]);
Quoted 8 lines

tools/gen_mac_addr.c line 43

Quoted 5 lines
tools/gen_mac_addr.c new file +1 -0
+                       mac_addr[i >> 1] |= strtol(nibble, NULL, 16) <<

((i % 2) ? 0 : 4) & ((i % 2) ? 0x0f : 0xf0);

tools/gen_mac_addr.c new file +3 -0
+                       i++;
+               }
+       }

Instead of all this you could just compile in (maybe it already is?) the eth_parse_enetaddr() function that U-Boot uses for this very purpose.

I'll see if I can have access to this function and then rewrite this to use that.

Quoted 11 lines
Quoted 11 lines
tools/gen_mac_addr.c new file +8 -1
+       mac_addr[6] = crc8(mac_addr, 6);
+
+       for (i = 0; i < 7; i++)
+               printf("%.2x", mac_addr[i]);
+       putchar('\n');
+
+       return 0;
+}
--

2.6.2

Quoted 4 lines
Quoted 4 lines

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

--
Met vriendelijke groeten, Kind regards, ??????

Olliver Schinagl
Software Engineer
Research & Development
Ultimaker B.V.

Signature · 6 lines
Met vriendelijke groeten, Kind regards, ??????

Olliver Schinagl
Software Engineer
Research & Development
Ultimaker B.V.
#23 lore raw

PATCH v2 5/5 tools: Add tool to add crc8 to a mac address

Quoted 66 lines · Olliver Schinagl

Hey Joe,

Quoted 62 lines · Joe Hershberger
Quoted 58 lines · Olliver Schinagl

Hey Joe,

Quoted 41 lines · Joe Hershberger

tools/gen_mac_addr.c

Quoted 34 lines · Olliver Schinagl

This patch adds a little tool that takes a generic MAC address and generates a CRC byte for it. The output is the full MAC address without any separators, ready written into an EEPROM.

---
   tools/Makefile       |  4 ++++
   tools/gen_mac_addr.c | 51
+++++++++++++++++++++++++++++++++++++++++++++++++++
   2 files changed, 55 insertions(+)

create mode 100644 tools/gen_mac_addr.c

tools/Makefile +0 -0
index 4a50744..6191c26 100644
@@ -43,6 +43,10 @@ envcrc-objs := envcrc.o lib/crc32.o

common/env_embedded.o lib/sha1.o
hostprogs-$(CONFIG_CMD_NET) += gen_eth_addr
HOSTCFLAGS_gen_eth_addr.o := -pedantic

tools/Makefile +4 -0
+hostprogs-$(CONFIG_CMD_NET) += gen_mac_addr
+gen_mac_addr-objs := gen_mac_addr.o lib/crc8.o
+HOSTCFLAGS_gen_mac_addr.o := -pedantic
+
   hostprogs-$(CONFIG_CMD_LOADS) += img2srec
   HOSTCFLAGS_img2srec.o := -pedantic
tools/gen_mac_addr.c new file +0 -0
new file mode 100644
index 0000000..bd8688f

This is not "generating a mac address", right? Its point is to create a CRC for the user-supplied MAC address.

Quoted 1 line

Perhaps a better name would be "gen_ethaddr_rom_crc".

Yes, it takes a mac address as input and generates a macaddress + crc as output.

e.g. 11:22:33:44:55:66 -> 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0xcc

But maybe it should get some flags to output either both (as described here)
or just the crc based on the input, and then a few flags to either output it
in hex format or as an int?

Quoted 8 lines
Quoted 3 lines

What ever features you think will be useful for the users of this dev board I guess. I'm not sure if this is a platform (the included eeprom) that would carry over into other products.

Why not? It just reads a mac address and generates a crc8-appended mac address (or just the crc8) everybody that uses a mac address to be stored somewhere (even if the env is pre-generated) could use this. I don't think it is limited to our platform since it does something very generic.

OK.

Quoted 101 lines
Quoted 87 lines
Quoted 87 lines
Quoted 30 lines
Quoted 30 lines
tools/gen_mac_addr.c new file +27 -0
@@ -0,0 +1,51 @@
+/*
+ * (C) Copyright 2016
+ * Olliver Schinagl <[email protected]>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <ctype.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <u-boot/crc.h>
+
+
+int main(int argc, char *argv[])
+{
+       uint_fast8_t i;
+       uint8_t mac_addr[7] = { 0x00 };
+
+       if (argc < 2) {
+               puts("Please supply a MAC address.");
+               return -1;
+       }
+
+       if (!((strlen(argv[1]) == 12) || (strlen(argv[1]) == 17))) {
+               puts("Please supply a valid MAC address with
Quoted 8 lines

tools/gen_mac_addr.c line 30

Quoted 4 lines

optionaly\n"

tools/gen_mac_addr.c new file +3 -0
+                    "dashes (-) or colons (:) as seperators.");
+               return -1;
+       }

You could use the eth_validate_ethaddr_str() function here instead of this
code.

A right, well when I first wrote this, I think this didn't exist there yet.
I'll replace it and use it instead.

Quoted 12 lines
Quoted 12 lines
tools/gen_mac_addr.c new file +10 -0
+
+       i = 0;
+       while (*argv[1] != '\0') {
+               char nibble[2] = { 0x00, '\n' }; /* for strtol */
+
+               nibble[0] = *argv[1]++;
+               if (isxdigit(nibble[0])) {
+                       if (isupper(nibble[0]))
+                               nibble[0] = tolower(nibble[0]);
+                       mac_addr[i >> 1] |= strtol(nibble, NULL, 16) <<
Quoted 8 lines

tools/gen_mac_addr.c line 43

Quoted 4 lines

((i % 2) ? 0 : 4) & ((i % 2) ? 0x0f : 0xf0);

tools/gen_mac_addr.c new file +3 -0
+                       i++;
+               }
+       }

Instead of all this you could just compile in (maybe it already is?) the eth_parse_enetaddr() function that U-Boot uses for this very purpose.

I'll see if I can have access to this function and then rewrite this to use
that.

Quoted 11 lines
Quoted 11 lines
tools/gen_mac_addr.c new file +8 -1
+       mac_addr[6] = crc8(mac_addr, 6);
+
+       for (i = 0; i < 7; i++)
+               printf("%.2x", mac_addr[i]);
+       putchar('\n');
+
+       return 0;
+}
--

2.6.2

Quoted 4 lines
Quoted 4 lines

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

--
Met vriendelijke groeten, Kind regards, ??????

Quoted 5 lines
Quoted 5 lines

Olliver Schinagl
Software Engineer
Research & Development
Ultimaker B.V.

--
Met vriendelijke groeten, Kind regards, ??????

Olliver Schinagl
Software Engineer
Research & Development
Ultimaker B.V.