Hi Luis, +Jagan, On 14.8.2018 06:55, Luis Araneda wrote: > Implement a method for reading the MAC address from an > SPI flash memory. > In particular, this method is used by the Zybo Z7 board > to read the MAC address from the OTP region in the SPI NOR > memory > > Signed-off-by: Luis Araneda <luaran...@gmail.com> > --- > > I'm trying to implement the reading of the MAC address of > the Zybo Z7 board from the OTP region of its SPI NOR memory. > > I took some ideas from Digilent's fork, but the commit was > marked as not upstremeable. That's why I'm asking for comments.
I have done this code long time ago because there was a work which wasn't finished. Also upstreaming takes some time to finish. > > If the code can't be merged, ideas on how this can be implemented > are welcome. > > Thanks, > > Luis Araneda. > > --- > board/xilinx/zynq/board.c | 28 ++++++++++++++++++++++++++++ > configs/zynq_zybo_z7_defconfig | 3 +++ > drivers/misc/Kconfig | 17 +++++++++++++++++ > 3 files changed, 48 insertions(+) > > diff --git a/board/xilinx/zynq/board.c b/board/xilinx/zynq/board.c > index 614d93c082..a252c38956 100644 > --- a/board/xilinx/zynq/board.c > +++ b/board/xilinx/zynq/board.c > @@ -6,9 +6,12 @@ > > #include <common.h> > #include <dm/uclass.h> > +#include <dm/device.h> > +#include <dm/device-internal.h> > #include <fdtdec.h> > #include <fpga.h> > #include <mmc.h> > +#include <spi_flash.h> > #include <watchdog.h> > #include <wdt.h> > #include <zynqpl.h> > @@ -87,6 +90,31 @@ int zynq_board_read_rom_ethaddr(unsigned char *ethaddr) > printf("I2C EEPROM MAC address read failed\n"); > #endif > > +#if defined(CONFIG_MAC_ADDR_IN_SPI_FLASH) > + struct spi_flash *flash; > + struct udevice *dev; > + int ret; > + > + ret = spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS, > + CONFIG_SF_DEFAULT_CS, > + 0, 0, &dev); > + if (ret) { > + printf("SPI(bus:%u cs:%u) probe failed\n", > + CONFIG_SF_DEFAULT_BUS, > + CONFIG_SF_DEFAULT_CS); > + return 0; > + } > + > + flash = dev_get_uclass_priv(dev); > + flash->read_cmd = CONFIG_MAC_ADDR_SPI_FLASH_READ_CMD; > + > + if (spi_flash_read_dm(dev, > + CONFIG_MAC_ADDR_SPI_FLASH_DATA_OFFSET, > + 6, ethaddr)) > + printf("SPI MAC address read failed\n"); > + > + device_remove(dev, DM_REMOVE_NORMAL); > +#endif > return 0; > } > > diff --git a/configs/zynq_zybo_z7_defconfig b/configs/zynq_zybo_z7_defconfig > index ad44e772aa..ca402e3231 100644 > --- a/configs/zynq_zybo_z7_defconfig > +++ b/configs/zynq_zybo_z7_defconfig > @@ -44,6 +44,9 @@ CONFIG_DM_GPIO=y > CONFIG_SYS_I2C_ZYNQ=y > CONFIG_ZYNQ_I2C0=y > CONFIG_ZYNQ_I2C1=y > +CONFIG_MAC_ADDR_IN_SPI_FLASH=y > +CONFIG_MAC_ADDR_SPI_FLASH_READ_CMD=0x4b I am doing spi but isn't this any standard OTP read command which should put to spi framework. > +CONFIG_MAC_ADDR_SPI_FLASH_DATA_OFFSET=0x20 > CONFIG_MMC_SDHCI=y > CONFIG_MMC_SDHCI_ZYNQ=y > CONFIG_SPI_FLASH=y > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig > index c031dfde9d..40cec81e66 100644 > --- a/drivers/misc/Kconfig > +++ b/drivers/misc/Kconfig > @@ -272,6 +272,23 @@ config SYS_I2C_EEPROM_ADDR_OVERFLOW > > endif > > +config MAC_ADDR_IN_SPI_FLASH > + bool "MAC address in SPI flash" > + help > + Read MAC address from an SPI flash memory > + > +if MAC_ADDR_IN_SPI_FLASH > + > +config MAC_ADDR_SPI_FLASH_READ_CMD > + hex "Read command for the SPI flash memory" > + default 0 > + > +config MAC_ADDR_SPI_FLASH_DATA_OFFSET > + hex "Offset of MAC data in SPI flash memory" > + default 0 > + > +endif > + > config GDSYS_RXAUI_CTRL > bool "Enable gdsys RXAUI control driver" > depends on MISC > Thanks, Michal _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot