From: Luis Araneda <luaraneda@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC PATCH] arm: zynq: read mac address from SPI flash memory
Date: Tue, 14 Aug 2018 01:55:50 -0300 [thread overview]
Message-ID: <20180814045550.27492-1-luaraneda@gmail.com> (raw)
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
next reply other threads:[~2018-08-14 4:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-14 4:55 Luis Araneda [this message]
2018-08-14 14:07 ` [U-Boot] [RFC PATCH] arm: zynq: read mac address from SPI flash memory Michal Simek
2018-08-16 6:04 ` Luis Araneda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180814045550.27492-1-luaraneda@gmail.com \
--to=luaraneda@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox