]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
imx8mm-cl-iot-gate: Retrieve the MAC address from EEPROM
authorFabio Estevam <festevam@denx.de>
Tue, 12 Apr 2022 16:05:37 +0000 (13:05 -0300)
committerStefano Babic <sbabic@denx.de>
Tue, 12 Apr 2022 17:10:44 +0000 (19:10 +0200)
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
board/compulab/imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c
configs/imx8mm-cl-iot-gate-optee_defconfig
configs/imx8mm-cl-iot-gate_defconfig

index 62e8d03949335875806568d7099fb51b702e583e..425701204a0c393aec72d37e37902161bbd431c2 100644 (file)
                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>;
        pinctrl-0 = <&pinctrl_i2c2>;
        status = "okay";
 
+       i2c_eeprom1: eeprom@50 {
+                 compatible = "atmel,24c08";
+                 reg = <0x50>;
+                 pagesize = <16>;
+       };
        rtc@69 {
                compatible = "abracon,ab1805";
                reg = <0x69>;
index 7e2d88f449cefe25bc07169583a7edea3f908bd0..779b64b140ad12e62628cc8dbf0aaa9a634d15ab 100644 (file)
@@ -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;
 }
index 2014509ed52de0e73af4e1f4ecd20d72026407b7..c736fd84d91c6f3a7893487d831c91bdfddfcc03 100644 (file)
@@ -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
index 0ef9e2548e993b6f86a1dfab089c000f5ad08594..9265299e98f991489c5d51965bad22f2a2b587a5 100644 (file)
@@ -85,6 +85,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