[U-Boot] [PATCHv5 00/21] Retrieve MAC address from EEPROM

Olliver Schinagl oliver at schinagl.nl
Mon Apr 10 15:33:35 UTC 2017


First off:
P.S. Joe, for some reason my previous patches where added with me as:
"oliver at schinagl.nl <oliver at schinagl.nl>" I see that it comes from patchwork
as such. Is there some way to fix this to
"Olliver Schinagl <oliver at schinagl.nl>"?

Below the updated summary:

This patch-series introduces methods to retrieve the MAC address from an
onboard EEPROM. The series does a few small cleanups at the start, as either
I ran into them while doing this series and fixed them along the way or
actually depended on them.

A manufacturer wants to produce boards and may even have MAC addresses for
boards. Maintaining unique environments on a per-board basis however is
horrible. Also this data should be very persistent, and not easily deletable
by simply wiping the environment or device tree. Finally there are
chips available on the market with a pre-programmed MAC address chips 
(proms)
that a board manufacturer wants to use. Because of this, the MAC needs to be
stored be able to read from such an 'external' source.

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 the first macaddress. The 
macaddress is appended by a CRC8 byte and then padded to make for nice 8 bytes. 
Following the first macaddress one can store a second, or a third etc etc
macaddress.

The CRC8 is optional (via a define) but is strongly recommended to have. It
helps preventing user error and more importantly, checks if the bytes 
read are actually a user inserted address. E.g. only writing 1 macaddress into 
the eeprom but trying to consume 2.

These patches where tested on Olimex OLinuXino Lime1 (A10/A20), Lime2 (NAND
and eMMC) and A20-OLinuXino-MICRO-4G variants and have been in use
internally on our production systems since v2 of this patch set.

TODO in a follow up series:
* Replace the I2C specific read function to a generic function using
Maxime Ripard's EEPROM uclass once merged.
* Upgrade to use the EERPOM layout functionality.

=======
Changes since v4:
* Some patches have been merged, so those are no longer included in the set.
* Reworked review comments
* Added the source of a MAC address
* Made sunxi-gmac a subclassed driver
* Switch sunxi-[eg]mac to Kconfig
* Drop the FDT injection code for now, this needs more thought/discussion

Changes since v3:
* Split off board specific stuff and only modify the generic functions
* Make reading of an eeprom available to every board. By default this is
   unconfigure and thus should just fall through
* Clean some minor bits up (ARP_HLEN) and use it more generically
* Update the gen_ethaddr_crc as suggested by simon
* Let the fixup_ethernet from fdt_common insert mac addresses to the 
environment
   for unconfigured devices. There is a small caveat here however as 
described
   in the TODO above.
* Print the mac address that u-boot assigned to each device.

Changes since v2:
* Drop the id byte altogether and just mark it as reserved. The 'index' 
can be
used to indicate the interface instead
* Addopt the read_rom_hwaddr hooks
* Renamed crc8 tool to gen_ethaddr_crc
* Improved the layout EEPROM example
* Made a function out of the hwaddress writing function in sunxi_emac so it
can be re-used as the write_hwaddr net_ops hook.
* No longer handle fdt parameters in board.c

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 (21):
  net: cosmetic: Do not use magic values for ARP_HLEN
  net: core: Sanitize get/set operations for enetaddr
  net: core: Inform the user of the device MAC address
  net: core: Add function to check/set MAC locality
  net: Add ability to set MAC address via EEPROM
  net: core: print the source of the MAC address
  net: cosmetic: A MAC address is not limited to SROM
  fdt: fixup_eth: Remove code duplication with a function
  fdt: fixup_eth: improve error catching/reduce identation
  net: sunxi: Enable I2C bus set via NET_ETHADDR_EEPROM_I2C_BUS
  net: sunxi_[eg]mac: Convert to Kconfig
  arm: sunxi: Expose function to generate sunxi-specific a MAC address
  net: sunxi_emac: Write HW address via net_ops hook
  net: sunxi: Have sunxi common functions together
  net: sunxi_emac: Add read_rom_hwaddr hook
  net: sunxi_gmac: Make the sunxi variant of dw driver a subclass
  net: dw: Expose designware_eth_start
  net: sunxi_gmac: Add read_rom_hwaddr hook
  net: sun8i_gmac: Add read_rom_hwaddr hook
  net: sun8i: fix whitespace
  net: core: Check return value of read_rom_hwaddr

 arch/arm/include/asm/arch-sunxi/sys_proto.h    |   7 +-
 arch/arm/mach-sunxi/board.c                    |   1 -
 board/sunxi/Kconfig                            |   4 +
 board/sunxi/Makefile                           |   1 -
 board/sunxi/board.c                            | 145 ++++++++++++++++---------
 common/fdt_support.c                           |  33 +++---
 configs/A10-OLinuXino-Lime_defconfig           |   4 +-
 configs/A10s-OLinuXino-M_defconfig             |   2 +-
 configs/A20-OLinuXino-Lime2_defconfig          |   5 +-
 configs/A20-OLinuXino-Lime_defconfig           |   5 +-
 configs/A20-OLinuXino_MICRO_defconfig          |   5 +-
 configs/A20-Olimex-SOM-EVB_defconfig           |   4 +-
 configs/Bananapi_defconfig                     |   4 +-
 configs/Bananapro_defconfig                    |   4 +-
 configs/CSQ_CS908_defconfig                    |   3 +-
 configs/Colombus_defconfig                     |   4 +-
 configs/Cubieboard2_defconfig                  |   4 +-
 configs/Cubieboard_defconfig                   |   3 +-
 configs/Cubietruck_defconfig                   |   4 +-
 configs/Hummingbird_A31_defconfig              |   4 +-
 configs/Itead_Ibox_A20_defconfig               |   4 +-
 configs/Lamobo_R1_defconfig                    |   4 +-
 configs/Linksprite_pcDuino3_Nano_defconfig     |   4 +-
 configs/Linksprite_pcDuino3_defconfig          |   4 +-
 configs/Linksprite_pcDuino_defconfig           |   2 +-
 configs/Marsboard_A10_defconfig                |   2 +-
 configs/Mele_A1000G_quad_defconfig             |   3 +-
 configs/Mele_A1000_defconfig                   |   3 +-
 configs/Mele_I7_defconfig                      |   3 +-
 configs/Mele_M3_defconfig                      |   3 +-
 configs/Mele_M5_defconfig                      |   3 +-
 configs/Mele_M9_defconfig                      |   3 +-
 configs/Orangepi_defconfig                     |   4 +-
 configs/Orangepi_mini_defconfig                |   4 +-
 configs/Sinlinx_SinA31s_defconfig              |   3 +-
 configs/Sinovoip_BPI_M2_defconfig              |   4 +-
 configs/Wits_Pro_A20_DKT_defconfig             |   4 +-
 configs/ba10_tv_box_defconfig                  |   2 +-
 configs/i12-tvbox_defconfig                    |   4 +-
 configs/icnova-a20-swac_defconfig              |   4 +-
 configs/jesurun_q5_defconfig                   |   3 +-
 configs/mixtile_loftq_defconfig                |   4 +-
 doc/README.enetaddr                            |  99 +++++++++++++++++
 drivers/net/Kconfig                            |  33 +++++-
 drivers/net/Makefile                           |   5 +-
 drivers/net/designware.c                       |   3 +-
 drivers/net/designware.h                       |   1 +
 drivers/net/sun8i_emac.c                       |  15 ++-
 drivers/net/sunxi_common.c                     |  33 ++++++
 drivers/net/sunxi_common.h                     |  13 +++
 drivers/net/sunxi_emac.c                       |  15 +++
 board/sunxi/gmac.c => drivers/net/sunxi_gmac.c |  54 ++++++++-
 include/configs/sunxi-common.h                 |   5 -
 include/net.h                                  |  53 ++++++++-
 net/Kconfig                                    |  59 ++++++++++
 net/eth-uclass.c                               |  65 ++++++-----
 net/eth_common.c                               |  53 ++++++++-
 net/eth_legacy.c                               |   7 +-
 58 files changed, 626 insertions(+), 207 deletions(-)
 create mode 100644 drivers/net/sunxi_common.c
 create mode 100644 drivers/net/sunxi_common.h
 rename board/sunxi/gmac.c => drivers/net/sunxi_gmac.c (67%)

-- 
2.11.0



More information about the U-Boot mailing list