[U-Boot] [PATCHv1 0/3] Retrieve MAC address from EEPROM

From: Olliver Schinagl o.schinagl@ultimaker.com
This patch-series introduces methods to retrieve the MAC address from an onboard EEPROM. I know there is probably a thing or two that might needed to be changed to make the concept apply in a more generic way.
The reason we might want to read the MAC address from an EEPROM instead of storing the entire environment is mostly a size thing. Our default environment already is bigger then the EEPROM so it is understandable that someone might not give up the entire eeprom just for the u-boot environment. Especially if only board specific things might be stored in the eeprom (MAC, serial, product number etc).
The current idea of the eeprom layout, is to skip the first 8 bytes, so that other information can be stored there if needed, for example a header with some magic to identify the EEPROM. Or equivalent purposes.
After those 8 bytes the MAC address follows and identifier byte to indicate the interface the MAC is applicable too, 0x00 - 0xFE to indicate ethernet interface 0 to 254. 0xFF has special meaning that it does not matter. This bit (no pun intended) is where I am not sure it should be in here at all, but it seemed more logical than simple order based. For example, if there are 2 ethernet devices on a board, eth0 being an internal device, and eth1 being an external facing device and only 1 MAC address per device is allotted, it can seem logical that eth1 gets the MAC address and eth0 gets a randomly chosen MAC address (or whatever the fall back behavior is).
These 7 bytes are then appended with a CRC8 byte and can be optionally checked, although the whole optional-ness could be very well dropped.
Hans de Goede and I talked about retrieving the MAC from the EEPROM for sunxi based boards a while ago, but hopefully this patch makes possible to have something slightly more generic, even if only the configuration option and the EEPROM layout.
Since the Olimex OLinuXino sunxi boards all seem to have an eeprom, I started my work on one of these and tested the implementation with one of our own real MAC addresses.
Features planned for v2, simple tool to write the MAC address to the eeprom from Linux.
Olliver Schinagl (3): 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
board/sunxi/Kconfig | 4 +++ board/sunxi/board.c | 36 +++++++++++++++++++++ configs/A20-OLinuXino-Lime2_defconfig | 3 ++ doc/README.enetaddr | 36 +++++++++++++++++++++ net/Kconfig | 59 +++++++++++++++++++++++++++++++++++ 5 files changed, 138 insertions(+)

From: Olliver Schinagl o.schinagl@ultimaker.com
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.
Signed-off-by: Olliver Schinagl o.schinagl@ultimaker.com --- doc/README.enetaddr | 36 +++++++++++++++++++++++++++++++++ net/Kconfig | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+)
diff --git a/doc/README.enetaddr b/doc/README.enetaddr index 50e4899..c53b455 100644 --- a/doc/README.enetaddr +++ b/doc/README.enetaddr @@ -47,6 +47,42 @@ 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 some header magic for example. + +After the 6 bytes used for the MAC address, there is an 8 byte field 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. + +Appending the 6 MAC bytes and the 7th interface byte is a CRC8 byte over the +previous 7 bytes. Whether to check this CRC8 or not is dependent on +CONFIG_NET_ETHADDR_EEPROM_CRC8. + +Layout example: + +00000000 21 4d 61 67 69 63 2e 21 01 23 45 67 89 ab ff c0 |!Magic.!.#Eg....| + +where the Header magic (!Magic.!) is spread over the first 8 bytes, and the MAC +address '01-23-45-67-89-ab' for the first interface (0xff) with the CRC8 +checksum 0xc0. + ------- Usage ------- diff --git a/net/Kconfig b/net/Kconfig index a44a783..aced51e 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -7,6 +7,64 @@ menuconfig NET
if NET
+config NET_ETHADDR_EEPROM + bool "Get ethaddr from eeprom" + help + Selecting this will try to get the Ethernet address from an onboard + EEPROM and set into the environment if and only if the environment + does currently not already hold a MAC address. For more information + see doc/README.enetaddr. + +config NET_ETHADDR_EEPROM_I2C + depends on NET_ETHADDR_EEPROM + bool "EEPROM on I2C bus" + help + This switch enables checks for an EEPROM on the I2C bus. Naturally + this will only work if there is an actual EEPROM connected on the + I2C bus and the bus and device are properly configured via the + options below. + +config NET_ETHADDR_EEPROM_I2C_BUS + depends on NET_ETHADDR_EEPROM_I2C + int "I2C bus" + default 0 + help + Select the bus on which the EEPROM is present, defaults to bus 0. + +config NET_ETHADDR_EEPROM_I2C_ADDR + depends on NET_ETHADDR_EEPROM_I2C + hex "eeprom address" + default 0x50 + help + Select the address of the eeprom, defaults to address 0x50. + +config NET_ETHADDR_EEPROM_I2C_ADDRLEN + depends on NET_ETHADDR_EEPROM_I2C + int "eeprom address length" + default 1 + help + Number of bytes to be used for the I2C address length. Typically 1, + 2 for large memories, 0 for register type devices with only one + register. + +config NET_ETHADDR_EEPROM_OFFSET + depends on NET_ETHADDR_EEPROM + int "EEPROM offset" + default 8 + help + Select the byte offset of the MAC address within the page, + defaults to byte 8. + +config NET_ETHADDR_EEPROM_CRC8 + depends on NET_ETHADDR_EEPROM + bool "Check CRC8 of MAC" + default y + help + Optionally, it is possible to run a CRC-8-CCITT check on the MAC + address. To do so, the MAC address is stored with a CRC8 byte append. + This option enables the CRC check of the MAC address against the CRC + byte. + config NET_RANDOM_ETHADDR bool "Random ethaddr if unset" select LIB_RAND

Hi Olliver and Joe,
On 11/30/2015 05:50 PM, Oliver Schinagl wrote:
From: Olliver Schinagl o.schinagl@ultimaker.com
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.
Signed-off-by: Olliver Schinagl o.schinagl@ultimaker.com
Thanks, from a sunxi pov this and the other 2 patches look good.
Joe can we have your ack for this one please and/or can you merge this one through your tree? Either way I will take care of the other 2 patches in this set.
From my pov this is fine as v2016.01 material, but if you would rather postpone this to v2016.04 that is fine too.
Thanks & Regards,
Hans
doc/README.enetaddr | 36 +++++++++++++++++++++++++++++++++ net/Kconfig | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+)
diff --git a/doc/README.enetaddr b/doc/README.enetaddr index 50e4899..c53b455 100644 --- a/doc/README.enetaddr +++ b/doc/README.enetaddr @@ -47,6 +47,42 @@ 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 some header magic for example.
+After the 6 bytes used for the MAC address, there is an 8 byte field 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.
+Appending the 6 MAC bytes and the 7th interface byte is a CRC8 byte over the +previous 7 bytes. Whether to check this CRC8 or not is dependent on +CONFIG_NET_ETHADDR_EEPROM_CRC8.
+Layout example:
+00000000 21 4d 61 67 69 63 2e 21 01 23 45 67 89 ab ff c0 |!Magic.!.#Eg....|
+where the Header magic (!Magic.!) is spread over the first 8 bytes, and the MAC +address '01-23-45-67-89-ab' for the first interface (0xff) with the CRC8 +checksum 0xc0.
Usage
diff --git a/net/Kconfig b/net/Kconfig index a44a783..aced51e 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -7,6 +7,64 @@ menuconfig NET
if NET
+config NET_ETHADDR_EEPROM
- bool "Get ethaddr from eeprom"
- help
Selecting this will try to get the Ethernet address from an onboard
EEPROM and set into the environment if and only if the environment
does currently not already hold a MAC address. For more information
see doc/README.enetaddr.
+config NET_ETHADDR_EEPROM_I2C
- depends on NET_ETHADDR_EEPROM
- bool "EEPROM on I2C bus"
- help
This switch enables checks for an EEPROM on the I2C bus. Naturally
this will only work if there is an actual EEPROM connected on the
I2C bus and the bus and device are properly configured via the
options below.
+config NET_ETHADDR_EEPROM_I2C_BUS
- depends on NET_ETHADDR_EEPROM_I2C
- int "I2C bus"
- default 0
- help
Select the bus on which the EEPROM is present, defaults to bus 0.
+config NET_ETHADDR_EEPROM_I2C_ADDR
- depends on NET_ETHADDR_EEPROM_I2C
- hex "eeprom address"
- default 0x50
- help
Select the address of the eeprom, defaults to address 0x50.
+config NET_ETHADDR_EEPROM_I2C_ADDRLEN
- depends on NET_ETHADDR_EEPROM_I2C
- int "eeprom address length"
- default 1
- help
Number of bytes to be used for the I2C address length. Typically 1,
2 for large memories, 0 for register type devices with only one
register.
+config NET_ETHADDR_EEPROM_OFFSET
- depends on NET_ETHADDR_EEPROM
- int "EEPROM offset"
- default 8
- help
Select the byte offset of the MAC address within the page,
defaults to byte 8.
+config NET_ETHADDR_EEPROM_CRC8
- depends on NET_ETHADDR_EEPROM
- bool "Check CRC8 of MAC"
- default y
- help
Optionally, it is possible to run a CRC-8-CCITT check on the MAC
address. To do so, the MAC address is stored with a CRC8 byte append.
This option enables the CRC check of the MAC address against the CRC
byte.
- config NET_RANDOM_ETHADDR bool "Random ethaddr if unset" select LIB_RAND

Hans, Joe,
On 10-12-15 11:29, Hans de Goede wrote:
Hi Olliver and Joe,
On 11/30/2015 05:50 PM, Oliver Schinagl wrote:
From: Olliver Schinagl o.schinagl@ultimaker.com
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.
Signed-off-by: Olliver Schinagl o.schinagl@ultimaker.com
Thanks, from a sunxi pov this and the other 2 patches look good.
Joe can we have your ack for this one please and/or can you merge this one through your tree? Either way I will take care of the other 2 patches in this set.
I do intend to make a v2 and one of the things I hoped would bring up some discussion is wether to do the CRC with or without the interface ID. In this patch I calculate the CRC on 7 bytes, MAC + id, but I kinda went back on that and do a mac + crc + id.
Since nobody commented before, I haven't sent the v2 just yet (which will include a generator tool).
Any thoughts before merging this on that subject?
Olliver
From my pov this is fine as v2016.01 material, but if you would rather postpone this to v2016.04 that is fine too.
Thanks & Regards,
Hans
doc/README.enetaddr | 36 +++++++++++++++++++++++++++++++++ net/Kconfig | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+)
diff --git a/doc/README.enetaddr b/doc/README.enetaddr index 50e4899..c53b455 100644 --- a/doc/README.enetaddr +++ b/doc/README.enetaddr @@ -47,6 +47,42 @@ 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 some header magic for example.
+After the 6 bytes used for the MAC address, there is an 8 byte field 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.
+Appending the 6 MAC bytes and the 7th interface byte is a CRC8 byte over the +previous 7 bytes. Whether to check this CRC8 or not is dependent on +CONFIG_NET_ETHADDR_EEPROM_CRC8.
+Layout example:
+00000000 21 4d 61 67 69 63 2e 21 01 23 45 67 89 ab ff c0 |!Magic.!.#Eg....|
+where the Header magic (!Magic.!) is spread over the first 8 bytes, and the MAC +address '01-23-45-67-89-ab' for the first interface (0xff) with the CRC8 +checksum 0xc0.
Usage
diff --git a/net/Kconfig b/net/Kconfig index a44a783..aced51e 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -7,6 +7,64 @@ menuconfig NET
if NET
+config NET_ETHADDR_EEPROM
- bool "Get ethaddr from eeprom"
- help
Selecting this will try to get the Ethernet address from an
onboard
EEPROM and set into the environment if and only if the
environment
does currently not already hold a MAC address. For more
information
see doc/README.enetaddr.
+config NET_ETHADDR_EEPROM_I2C
- depends on NET_ETHADDR_EEPROM
- bool "EEPROM on I2C bus"
- help
This switch enables checks for an EEPROM on the I2C bus.
Naturally
this will only work if there is an actual EEPROM connected on the
I2C bus and the bus and device are properly configured via the
options below.
+config NET_ETHADDR_EEPROM_I2C_BUS
- depends on NET_ETHADDR_EEPROM_I2C
- int "I2C bus"
- default 0
- help
Select the bus on which the EEPROM is present, defaults to bus 0.
+config NET_ETHADDR_EEPROM_I2C_ADDR
- depends on NET_ETHADDR_EEPROM_I2C
- hex "eeprom address"
- default 0x50
- help
Select the address of the eeprom, defaults to address 0x50.
+config NET_ETHADDR_EEPROM_I2C_ADDRLEN
- depends on NET_ETHADDR_EEPROM_I2C
- int "eeprom address length"
- default 1
- help
Number of bytes to be used for the I2C address length.
Typically 1,
2 for large memories, 0 for register type devices with only one
register.
+config NET_ETHADDR_EEPROM_OFFSET
- depends on NET_ETHADDR_EEPROM
- int "EEPROM offset"
- default 8
- help
Select the byte offset of the MAC address within the page,
defaults to byte 8.
+config NET_ETHADDR_EEPROM_CRC8
- depends on NET_ETHADDR_EEPROM
- bool "Check CRC8 of MAC"
- default y
- help
Optionally, it is possible to run a CRC-8-CCITT check on the MAC
address. To do so, the MAC address is stored with a CRC8 byte
append.
This option enables the CRC check of the MAC address against
the CRC
byte.
- config NET_RANDOM_ETHADDR bool "Random ethaddr if unset" select LIB_RAND

Hi Olliver,
On Thu, Dec 10, 2015 at 4:40 AM, Olliver Schinagl o.schinagl@ultimaker.com wrote:
Hans, Joe,
On 10-12-15 11:29, Hans de Goede wrote:
Hi Olliver and Joe,
On 11/30/2015 05:50 PM, Oliver Schinagl wrote:
From: Olliver Schinagl o.schinagl@ultimaker.com
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.
Signed-off-by: Olliver Schinagl o.schinagl@ultimaker.com
Thanks, from a sunxi pov this and the other 2 patches look good.
Joe can we have your ack for this one please and/or can you merge this one through your tree? Either way I will take care of the other 2 patches in this set.
I do intend to make a v2 and one of the things I hoped would bring up some discussion is wether to do the CRC with or without the interface ID. In this patch I calculate the CRC on 7 bytes, MAC + id, but I kinda went back on that and do a mac + crc + id.
Since nobody commented before, I haven't sent the v2 just yet (which will include a generator tool).
Any thoughts before merging this on that subject?
Seems to me that if you are worried about the integrity of the MAC address in EEPROM, then the interface number is just as important to check for integrity.
From my pov this is fine as v2016.01 material, but if you would rather postpone this to v2016.04 that is fine too.
Thanks & Regards,
Hans
doc/README.enetaddr | 36 +++++++++++++++++++++++++++++++++ net/Kconfig | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+)
diff --git a/doc/README.enetaddr b/doc/README.enetaddr index 50e4899..c53b455 100644 --- a/doc/README.enetaddr +++ b/doc/README.enetaddr @@ -47,6 +47,42 @@ 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 some header magic for example.
+After the 6 bytes used for the MAC address, there is an 8 byte field 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.
+Appending the 6 MAC bytes and the 7th interface byte is a CRC8 byte over the +previous 7 bytes. Whether to check this CRC8 or not is dependent on +CONFIG_NET_ETHADDR_EEPROM_CRC8.
+Layout example:
+00000000 21 4d 61 67 69 63 2e 21 01 23 45 67 89 ab ff c0 |!Magic.!.#Eg....|
+where the Header magic (!Magic.!) is spread over the first 8 bytes, and the MAC +address '01-23-45-67-89-ab' for the first interface (0xff) with the CRC8 +checksum 0xc0.
Usage
diff --git a/net/Kconfig b/net/Kconfig index a44a783..aced51e 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -7,6 +7,64 @@ menuconfig NET
if NET
+config NET_ETHADDR_EEPROM
- bool "Get ethaddr from eeprom"
- help
Selecting this will try to get the Ethernet address from an
onboard
EEPROM and set into the environment if and only if the environment
does currently not already hold a MAC address. For more
information
see doc/README.enetaddr.
+config NET_ETHADDR_EEPROM_I2C
- depends on NET_ETHADDR_EEPROM
- bool "EEPROM on I2C bus"
- help
This switch enables checks for an EEPROM on the I2C bus. Naturally
this will only work if there is an actual EEPROM connected on the
I2C bus and the bus and device are properly configured via the
options below.
+config NET_ETHADDR_EEPROM_I2C_BUS
- depends on NET_ETHADDR_EEPROM_I2C
- int "I2C bus"
- default 0
- help
Select the bus on which the EEPROM is present, defaults to bus 0.
+config NET_ETHADDR_EEPROM_I2C_ADDR
- depends on NET_ETHADDR_EEPROM_I2C
- hex "eeprom address"
- default 0x50
- help
Select the address of the eeprom, defaults to address 0x50.
+config NET_ETHADDR_EEPROM_I2C_ADDRLEN
- depends on NET_ETHADDR_EEPROM_I2C
- int "eeprom address length"
- default 1
- help
Number of bytes to be used for the I2C address length. Typically
1,
2 for large memories, 0 for register type devices with only one
register.
+config NET_ETHADDR_EEPROM_OFFSET
- depends on NET_ETHADDR_EEPROM
- int "EEPROM offset"
- default 8
- help
Select the byte offset of the MAC address within the page,
defaults to byte 8.
+config NET_ETHADDR_EEPROM_CRC8
- depends on NET_ETHADDR_EEPROM
- bool "Check CRC8 of MAC"
- default y
- help
Optionally, it is possible to run a CRC-8-CCITT check on the MAC
address. To do so, the MAC address is stored with a CRC8 byte
append.
This option enables the CRC check of the MAC address against the
CRC
byte.
- config NET_RANDOM_ETHADDR bool "Random ethaddr if unset" select LIB_RAND
-- Met vriendelijke groeten, Kind regards, 与亲切的问候
Olliver Schinagl Software Engineer Research & Development Ultimaker B.V.
U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot

Hey Joe,
On 10-12-15 21:25, Joe Hershberger wrote:
Hi Olliver,
On Thu, Dec 10, 2015 at 4:40 AM, Olliver Schinagl o.schinagl@ultimaker.com wrote:
Hans, Joe,
On 10-12-15 11:29, Hans de Goede wrote:
Hi Olliver and Joe,
On 11/30/2015 05:50 PM, Oliver Schinagl wrote:
From: Olliver Schinagl o.schinagl@ultimaker.com
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.
Signed-off-by: Olliver Schinagl o.schinagl@ultimaker.com
Thanks, from a sunxi pov this and the other 2 patches look good.
Joe can we have your ack for this one please and/or can you merge this one through your tree? Either way I will take care of the other 2 patches in this set.
I do intend to make a v2 and one of the things I hoped would bring up some discussion is wether to do the CRC with or without the interface ID. In this patch I calculate the CRC on 7 bytes, MAC + id, but I kinda went back on that and do a mac + crc + id.
Since nobody commented before, I haven't sent the v2 just yet (which will include a generator tool).
Any thoughts before merging this on that subject?
Seems to me that if you are worried about the integrity of the MAC address in EEPROM, then the interface number is just as important to check for integrity.
I'm not worried about the EEPROM failing etc, I'm worried about user error. A user may knowingly want to change the ID (via u-boot i2c-cmd's or via linux by writing the eeprom), so protect the eeprom from accidental fudging. Also generating macs + crc is trivial, but then you may have to change it all again when you change the ID (shuffle mac's around interfaces on boards).
I'll send the v2 now though.
Olliver
From my pov this is fine as v2016.01 material, but if you would rather postpone this to v2016.04 that is fine too.
Thanks & Regards,
Hans
doc/README.enetaddr | 36 +++++++++++++++++++++++++++++++++ net/Kconfig | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+)
diff --git a/doc/README.enetaddr b/doc/README.enetaddr index 50e4899..c53b455 100644 --- a/doc/README.enetaddr +++ b/doc/README.enetaddr @@ -47,6 +47,42 @@ 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 some header magic for example.
+After the 6 bytes used for the MAC address, there is an 8 byte field 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.
+Appending the 6 MAC bytes and the 7th interface byte is a CRC8 byte over the +previous 7 bytes. Whether to check this CRC8 or not is dependent on +CONFIG_NET_ETHADDR_EEPROM_CRC8.
+Layout example:
+00000000 21 4d 61 67 69 63 2e 21 01 23 45 67 89 ab ff c0 |!Magic.!.#Eg....|
+where the Header magic (!Magic.!) is spread over the first 8 bytes, and the MAC +address '01-23-45-67-89-ab' for the first interface (0xff) with the CRC8 +checksum 0xc0.
Usage
diff --git a/net/Kconfig b/net/Kconfig index a44a783..aced51e 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -7,6 +7,64 @@ menuconfig NET
if NET
+config NET_ETHADDR_EEPROM
- bool "Get ethaddr from eeprom"
- help
Selecting this will try to get the Ethernet address from an
onboard
EEPROM and set into the environment if and only if the environment
does currently not already hold a MAC address. For more
information
see doc/README.enetaddr.
+config NET_ETHADDR_EEPROM_I2C
- depends on NET_ETHADDR_EEPROM
- bool "EEPROM on I2C bus"
- help
This switch enables checks for an EEPROM on the I2C bus. Naturally
this will only work if there is an actual EEPROM connected on the
I2C bus and the bus and device are properly configured via the
options below.
+config NET_ETHADDR_EEPROM_I2C_BUS
- depends on NET_ETHADDR_EEPROM_I2C
- int "I2C bus"
- default 0
- help
Select the bus on which the EEPROM is present, defaults to bus 0.
+config NET_ETHADDR_EEPROM_I2C_ADDR
- depends on NET_ETHADDR_EEPROM_I2C
- hex "eeprom address"
- default 0x50
- help
Select the address of the eeprom, defaults to address 0x50.
+config NET_ETHADDR_EEPROM_I2C_ADDRLEN
- depends on NET_ETHADDR_EEPROM_I2C
- int "eeprom address length"
- default 1
- help
Number of bytes to be used for the I2C address length. Typically
1,
2 for large memories, 0 for register type devices with only one
register.
+config NET_ETHADDR_EEPROM_OFFSET
- depends on NET_ETHADDR_EEPROM
- int "EEPROM offset"
- default 8
- help
Select the byte offset of the MAC address within the page,
defaults to byte 8.
+config NET_ETHADDR_EEPROM_CRC8
- depends on NET_ETHADDR_EEPROM
- bool "Check CRC8 of MAC"
- default y
- help
Optionally, it is possible to run a CRC-8-CCITT check on the MAC
address. To do so, the MAC address is stored with a CRC8 byte
append.
This option enables the CRC check of the MAC address against the
CRC
byte.
- config NET_RANDOM_ETHADDR bool "Random ethaddr if unset" select LIB_RAND
-- Met vriendelijke groeten, Kind regards, 与亲切的问候
Olliver Schinagl Software Engineer Research & Development Ultimaker B.V.
U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot

Hi Hans,
On Thu, Dec 10, 2015 at 4:29 AM, Hans de Goede hdegoede@redhat.com wrote:
Hi Olliver and Joe,
On 11/30/2015 05:50 PM, Oliver Schinagl wrote:
From: Olliver Schinagl o.schinagl@ultimaker.com
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.
Signed-off-by: Olliver Schinagl o.schinagl@ultimaker.com
Thanks, from a sunxi pov this and the other 2 patches look good.
Joe can we have your ack for this one please and/or can you merge this one through your tree? Either way I will take care of the other 2 patches in this set.
I'm fine either way. I'm thinking I'll be pulling anything assigned to me in patchwork next week.
From my pov this is fine as v2016.01 material, but if you would rather postpone this to v2016.04 that is fine too.
Seems safe enough. v2016.01 is fine with me.
Thanks & Regards,
Hans
doc/README.enetaddr | 36 +++++++++++++++++++++++++++++++++ net/Kconfig | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+)
diff --git a/doc/README.enetaddr b/doc/README.enetaddr index 50e4899..c53b455 100644 --- a/doc/README.enetaddr +++ b/doc/README.enetaddr @@ -47,6 +47,42 @@ 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 some header magic for example.
+After the 6 bytes used for the MAC address, there is an 8 byte field 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.
+Appending the 6 MAC bytes and the 7th interface byte is a CRC8 byte over the +previous 7 bytes. Whether to check this CRC8 or not is dependent on +CONFIG_NET_ETHADDR_EEPROM_CRC8.
+Layout example:
+00000000 21 4d 61 67 69 63 2e 21 01 23 45 67 89 ab ff c0 |!Magic.!.#Eg....|
+where the Header magic (!Magic.!) is spread over the first 8 bytes, and the MAC +address '01-23-45-67-89-ab' for the first interface (0xff) with the CRC8 +checksum 0xc0.
Usage
diff --git a/net/Kconfig b/net/Kconfig index a44a783..aced51e 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -7,6 +7,64 @@ menuconfig NET
if NET
+config NET_ETHADDR_EEPROM
bool "Get ethaddr from eeprom"
help
Selecting this will try to get the Ethernet address from an
onboard
EEPROM and set into the environment if and only if the
environment
does currently not already hold a MAC address. For more
information
see doc/README.enetaddr.
+config NET_ETHADDR_EEPROM_I2C
depends on NET_ETHADDR_EEPROM
bool "EEPROM on I2C bus"
help
This switch enables checks for an EEPROM on the I2C bus.
Naturally
this will only work if there is an actual EEPROM connected on
the
I2C bus and the bus and device are properly configured via the
options below.
+config NET_ETHADDR_EEPROM_I2C_BUS
depends on NET_ETHADDR_EEPROM_I2C
int "I2C bus"
default 0
help
Select the bus on which the EEPROM is present, defaults to bus
+config NET_ETHADDR_EEPROM_I2C_ADDR
depends on NET_ETHADDR_EEPROM_I2C
hex "eeprom address"
default 0x50
help
Select the address of the eeprom, defaults to address 0x50.
+config NET_ETHADDR_EEPROM_I2C_ADDRLEN
depends on NET_ETHADDR_EEPROM_I2C
int "eeprom address length"
default 1
help
Number of bytes to be used for the I2C address length. Typically
1,
2 for large memories, 0 for register type devices with only one
register.
+config NET_ETHADDR_EEPROM_OFFSET
depends on NET_ETHADDR_EEPROM
int "EEPROM offset"
default 8
help
Select the byte offset of the MAC address within the page,
defaults to byte 8.
+config NET_ETHADDR_EEPROM_CRC8
depends on NET_ETHADDR_EEPROM
bool "Check CRC8 of MAC"
default y
help
Optionally, it is possible to run a CRC-8-CCITT check on the MAC
address. To do so, the MAC address is stored with a CRC8 byte
append.
This option enables the CRC check of the MAC address against the
CRC
byte.
- config NET_RANDOM_ETHADDR bool "Random ethaddr if unset" select LIB_RAND
U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot

Hi,
On 10-12-15 21:26, Joe Hershberger wrote:
Hi Hans,
On Thu, Dec 10, 2015 at 4:29 AM, Hans de Goede hdegoede@redhat.com wrote:
Hi Olliver and Joe,
On 11/30/2015 05:50 PM, Oliver Schinagl wrote:
From: Olliver Schinagl o.schinagl@ultimaker.com
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.
Signed-off-by: Olliver Schinagl o.schinagl@ultimaker.com
Thanks, from a sunxi pov this and the other 2 patches look good.
Joe can we have your ack for this one please and/or can you merge this one through your tree? Either way I will take care of the other 2 patches in this set.
I'm fine either way. I'm thinking I'll be pulling anything assigned to me in patchwork next week.
Ok, Olliver if you can get a v2 to Joe before next week then he can pick that one up, and then I'll merge the other 2 after the v2 of this one has been merged.
Regards,
Hans
From my pov this is fine as v2016.01 material, but if you would rather postpone this to v2016.04 that is fine too.
Seems safe enough. v2016.01 is fine with me.
Thanks & Regards,
Hans
doc/README.enetaddr | 36 +++++++++++++++++++++++++++++++++ net/Kconfig | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+)
diff --git a/doc/README.enetaddr b/doc/README.enetaddr index 50e4899..c53b455 100644 --- a/doc/README.enetaddr +++ b/doc/README.enetaddr @@ -47,6 +47,42 @@ 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 some header magic for example.
+After the 6 bytes used for the MAC address, there is an 8 byte field 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.
+Appending the 6 MAC bytes and the 7th interface byte is a CRC8 byte over the +previous 7 bytes. Whether to check this CRC8 or not is dependent on +CONFIG_NET_ETHADDR_EEPROM_CRC8.
+Layout example:
+00000000 21 4d 61 67 69 63 2e 21 01 23 45 67 89 ab ff c0 |!Magic.!.#Eg....|
+where the Header magic (!Magic.!) is spread over the first 8 bytes, and the MAC +address '01-23-45-67-89-ab' for the first interface (0xff) with the CRC8 +checksum 0xc0.
Usage
diff --git a/net/Kconfig b/net/Kconfig index a44a783..aced51e 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -7,6 +7,64 @@ menuconfig NET
if NET
+config NET_ETHADDR_EEPROM
bool "Get ethaddr from eeprom"
help
Selecting this will try to get the Ethernet address from an
onboard
EEPROM and set into the environment if and only if the
environment
does currently not already hold a MAC address. For more
information
see doc/README.enetaddr.
+config NET_ETHADDR_EEPROM_I2C
depends on NET_ETHADDR_EEPROM
bool "EEPROM on I2C bus"
help
This switch enables checks for an EEPROM on the I2C bus.
Naturally
this will only work if there is an actual EEPROM connected on
the
I2C bus and the bus and device are properly configured via the
options below.
+config NET_ETHADDR_EEPROM_I2C_BUS
depends on NET_ETHADDR_EEPROM_I2C
int "I2C bus"
default 0
help
Select the bus on which the EEPROM is present, defaults to bus
+config NET_ETHADDR_EEPROM_I2C_ADDR
depends on NET_ETHADDR_EEPROM_I2C
hex "eeprom address"
default 0x50
help
Select the address of the eeprom, defaults to address 0x50.
+config NET_ETHADDR_EEPROM_I2C_ADDRLEN
depends on NET_ETHADDR_EEPROM_I2C
int "eeprom address length"
default 1
help
Number of bytes to be used for the I2C address length. Typically
1,
2 for large memories, 0 for register type devices with only one
register.
+config NET_ETHADDR_EEPROM_OFFSET
depends on NET_ETHADDR_EEPROM
int "EEPROM offset"
default 8
help
Select the byte offset of the MAC address within the page,
defaults to byte 8.
+config NET_ETHADDR_EEPROM_CRC8
depends on NET_ETHADDR_EEPROM
bool "Check CRC8 of MAC"
default y
help
Optionally, it is possible to run a CRC-8-CCITT check on the MAC
address. To do so, the MAC address is stored with a CRC8 byte
append.
This option enables the CRC check of the MAC address against the
CRC
byte.
- config NET_RANDOM_ETHADDR bool "Random ethaddr if unset" select LIB_RAND
U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot

On Mon, Nov 30, 2015 at 10:50 AM, Olliver Schinagl oliver+list@schinagl.nl wrote:
From: Olliver Schinagl o.schinagl@ultimaker.com
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.
Signed-off-by: Olliver Schinagl o.schinagl@ultimaker.com
Acked-by: Joe Hershberger joe.hershberger@ni.com

From: Olliver Schinagl o.schinagl@ultimaker.com
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.
Signed-off-by: Olliver Schinagl o.schinagl@ultimaker.com --- board/sunxi/Kconfig | 4 ++++ board/sunxi/board.c | 36 ++++++++++++++++++++++++++++++++++++ net/Kconfig | 1 + 3 files changed, 41 insertions(+)
diff --git a/board/sunxi/Kconfig b/board/sunxi/Kconfig index 2dd9d3b..a2da3a6 100644 --- a/board/sunxi/Kconfig +++ b/board/sunxi/Kconfig @@ -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--- diff --git a/board/sunxi/board.c b/board/sunxi/board.c index 6ac398c..5087478 100644 --- a/board/sunxi/board.c +++ b/board/sunxi/board.c @@ -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[8]; + 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, 8)) { + 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, 7) != eeprom[7]) { + 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")) { diff --git a/net/Kconfig b/net/Kconfig index aced51e..0f4cc5a 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -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

From: Olliver Schinagl o.schinagl@ultimaker.com
This patch enables the I2C EEPROM to be probed for a MAC address on the OLinuXino board.
Signed-off-by: Olliver Schinagl o.schinagl@ultimaker.com --- configs/A20-OLinuXino-Lime2_defconfig | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/configs/A20-OLinuXino-Lime2_defconfig b/configs/A20-OLinuXino-Lime2_defconfig index b5181c6..5e38618 100644 --- a/configs/A20-OLinuXino-Lime2_defconfig +++ b/configs/A20-OLinuXino-Lime2_defconfig @@ -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
participants (4)
-
Hans de Goede
-
Joe Hershberger
-
Olliver Schinagl
-
Olliver Schinagl