[U-Boot] [U-Boot, PATCHv1, 1/3] net: Add ability to set MAC address via EEPROM to Kconfig
Joe Hershberger
joe.hershberger at gmail.com
Thu Dec 10 21:25:19 CET 2015
Hi Olliver,
On Thu, Dec 10, 2015 at 4:40 AM, Olliver Schinagl
<o.schinagl at 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 at 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 at 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 at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
More information about the U-Boot
mailing list