From: Fabio Estevam <festevam@gmail.com>
To: sbabic@denx.de
Cc: paul.liu@linaro.org, u-boot@lists.denx.de,
Fabio Estevam <festevam@denx.de>
Subject: [PATCH 3/5] imx8mm-cl-iot-gate: Retrieve the MAC address from EEPROM
Date: Sat, 19 Mar 2022 09:22:47 -0300 [thread overview]
Message-ID: <20220319122249.77456-3-festevam@gmail.com> (raw)
In-Reply-To: <20220319122249.77456-1-festevam@gmail.com>
From: Fabio Estevam <festevam@denx.de>
Currently the eth0 MAC address is randomly assigned.
Retrieve the MAC address from EEPROM.
Signed-off-by: Fabio Estevam <<festevam@denx.de>
---
arch/arm/dts/imx8mm-cl-iot-gate.dts | 12 ++++-
.../imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c | 51 +++++++++++++++++++
configs/imx8mm-cl-iot-gate_defconfig | 2 +
3 files changed, 64 insertions(+), 1 deletion(-)
diff --git a/arch/arm/dts/imx8mm-cl-iot-gate.dts b/arch/arm/dts/imx8mm-cl-iot-gate.dts
index 62e8d0394933..425701204a0c 100644
--- a/arch/arm/dts/imx8mm-cl-iot-gate.dts
+++ b/arch/arm/dts/imx8mm-cl-iot-gate.dts
@@ -17,6 +17,11 @@
stdout-path = &uart3;
};
+ aliases {
+ eeprom0 = &i2c_eeprom0;
+ eeprom1 = &i2c_eeprom1;
+ };
+
reg_vusb_5v: regulator-usdhc2 {
compatible = "regulator-fixed";
regulator-name = "VUSB_5V";
@@ -79,7 +84,7 @@
pinctrl-0 = <&pinctrl_i2c1>;
status = "okay";
- eeprom@54 {
+ i2c_eeprom0: eeprom@54 {
compatible = "atmel,24c08";
reg = <0x54>;
pagesize = <16>;
@@ -92,6 +97,11 @@
pinctrl-0 = <&pinctrl_i2c2>;
status = "okay";
+ i2c_eeprom1: eeprom@50 {
+ compatible = "atmel,24c08";
+ reg = <0x50>;
+ pagesize = <16>;
+ };
rtc@69 {
compatible = "abracon,ab1805";
reg = <0x69>;
diff --git a/board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c b/board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c
index 7e2d88f449ce..779b64b140ad 100644
--- a/board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c
+++ b/board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c
@@ -12,6 +12,8 @@
#include <init.h>
#include <miiphy.h>
#include <netdev.h>
+#include <i2c_eeprom.h>
+#include <i2c.h>
#include <asm/arch/clock.h>
#include <asm/arch/imx8mm_pins.h>
@@ -418,12 +420,61 @@ int extension_board_scan(struct list_head *extension_list)
return ret;
}
+static int setup_mac_address(void)
+{
+ unsigned char enetaddr[6];
+ struct udevice *dev;
+ int ret, off;
+
+ ret = eth_env_get_enetaddr("ethaddr", enetaddr);
+ if (ret)
+ return 0;
+
+ off = fdt_path_offset(gd->fdt_blob, "eeprom1");
+ if (off < 0) {
+ printf("No eeprom0 path offset found in DT\n");
+ return off;
+ }
+
+ ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
+ if (ret) {
+ printf("%s: Could not find EEPROM\n", __func__);
+ return ret;
+ }
+
+ ret = i2c_set_chip_offset_len(dev, 1);
+ if (ret)
+ return ret;
+
+ ret = i2c_eeprom_read(dev, 4, enetaddr, sizeof(enetaddr));
+ if (ret) {
+ printf("%s: Could not read EEPROM\n", __func__);
+ return ret;
+ }
+
+ ret = is_valid_ethaddr(enetaddr);
+ if (!ret)
+ return -EINVAL;
+
+ ret = eth_env_set_enetaddr("ethaddr", enetaddr);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
int board_late_init(void)
{
+ int ret;
+
if (IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)) {
env_set("board_name", "IOT-GATE-IMX8");
env_set("board_rev", "SBC-IOTMX8");
}
+ ret = setup_mac_address();
+ if (ret < 0)
+ printf("Cannot set MAC address from EEPROM\n");
+
return 0;
}
diff --git a/configs/imx8mm-cl-iot-gate_defconfig b/configs/imx8mm-cl-iot-gate_defconfig
index b72f219c786c..ee171f704ed9 100644
--- a/configs/imx8mm-cl-iot-gate_defconfig
+++ b/configs/imx8mm-cl-iot-gate_defconfig
@@ -84,6 +84,8 @@ CONFIG_FASTBOOT_FLASH_MMC_DEV=2
CONFIG_MXC_GPIO=y
CONFIG_DM_I2C=y
CONFIG_DM_KEYBOARD=y
+CONFIG_MISC=y
+CONFIG_I2C_EEPROM=y
CONFIG_SUPPORT_EMMC_RPMB=y
CONFIG_SUPPORT_EMMC_BOOT=y
CONFIG_FSL_USDHC=y
--
2.25.1
next prev parent reply other threads:[~2022-03-19 12:23 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-19 12:22 [PATCH 1/5] imx8mm-cl-iot-gate: Add SPL EEPROM support Fabio Estevam
2022-03-19 12:22 ` [PATCH 2/5] imx8mm-cl-iot-gate: Retrieve the DDR type from EEPROM Fabio Estevam
2022-03-21 9:53 ` Harald Seiler
2022-03-21 17:31 ` Tim Harvey
2022-03-21 20:11 ` Paul Liu
2022-04-12 18:44 ` sbabic
2022-03-19 12:22 ` Fabio Estevam [this message]
2022-04-12 15:33 ` [PATCH 3/5] imx8mm-cl-iot-gate: Retrieve the MAC address " Stefano Babic
2022-04-12 16:07 ` Fabio Estevam
2022-04-12 15:56 ` Sean Anderson
2022-04-12 16:08 ` Fabio Estevam
2022-04-12 18:44 ` sbabic
2022-03-19 12:22 ` [PATCH 4/5] imx8mm-cl-iot-gate: Retrieve the serial number " Fabio Estevam
2022-03-19 12:22 ` [PATCH 5/5] imx8mm-cl-iot-gate: Add redundand environment support Fabio Estevam
2022-04-12 18:43 ` sbabic
2022-04-12 18:47 ` [PATCH 1/5] imx8mm-cl-iot-gate: Add SPL EEPROM support sbabic
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=20220319122249.77456-3-festevam@gmail.com \
--to=festevam@gmail.com \
--cc=festevam@denx.de \
--cc=paul.liu@linaro.org \
--cc=sbabic@denx.de \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.