public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [RFC PATCH] arm: zynq: read mac address from SPI flash memory
@ 2018-08-14  4:55 Luis Araneda
  2018-08-14 14:07 ` Michal Simek
  0 siblings, 1 reply; 3+ messages in thread
From: Luis Araneda @ 2018-08-14  4:55 UTC (permalink / raw)
  To: u-boot

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 <luaraneda@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.

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
+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
-- 
2.18.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-08-16  6:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-14  4:55 [U-Boot] [RFC PATCH] arm: zynq: read mac address from SPI flash memory Luis Araneda
2018-08-14 14:07 ` Michal Simek
2018-08-16  6:04   ` Luis Araneda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox