Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0FB85C433FE for ; Tue, 12 Apr 2022 16:06:17 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8AA0983B42; Tue, 12 Apr 2022 18:06:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ATT6ml/R"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 260C083B4E; Tue, 12 Apr 2022 18:05:58 +0200 (CEST) Received: from mail-oa1-x32.google.com (mail-oa1-x32.google.com [IPv6:2001:4860:4864:20::32]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 31EDE83BAC for ; Tue, 12 Apr 2022 18:05:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=festevam@gmail.com Received: by mail-oa1-x32.google.com with SMTP id 586e51a60fabf-de3ca1efbaso21227300fac.9 for ; Tue, 12 Apr 2022 09:05:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+Q9LmhWnd7+dDw20GM3OqU/Osqjkfx+z8odqAKV2fz4=; b=ATT6ml/RM13JiG6F3I07Hh6jrh1KW8Sp3w2ipGjCUei7ALvKGMRRAGZbUkFjhsZcwS CHS3EURhroD9Xoibmn/AMDDR5Gv4rcBdxViaLMHLx+tuTiNm2JG5niyvS9LX2ru9UhB1 l4Wev7wuJou04IrqyxTe7d1qD+9zS5+GtlAVS4zLXElXZvbK0569MgVHL1YRiFtfeFPV ac5OuaKm/X5P2V6Ow5DRNqb6pLDCjZaWIetCd966mPfjVlkQ8q4TH+YRC3x6A5H5ks4H nFwBu6MeC5pELKIQ13Jlmj4IJnHK1B7xaaMGlD29VKCm88wCsKwoxSASZFePGEtIFB63 3SqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+Q9LmhWnd7+dDw20GM3OqU/Osqjkfx+z8odqAKV2fz4=; b=CxdJxZbsjqA1ibGbGQ3leOfCABRNROv64wKmhrvcN/wZdfqlpYv2g7ScEX5iRjTAGJ 1KIEd2vKWIOoSDzYoV60/7bLi7ox4GYL/B2JD0dsXFFydViQ7CyZ3ykujgzzjEt40QDP xqKPNWbYOtvGnbYhofU0zYkp9VxcBKgUPZBFVSQa1+JOQywtgpIV/cxFQj052uIT+ozH 1d0a+oGCUMY2vtpELSIJLqL/9nCJymSEvw6YJ34TwaIwmuh1NBZdotZA3+piQOJjHhGi /LfOKtS26bzqHlKQVMdqxsdD/hwUMjWUsSj5eDsPUv4EAldvCL0Qg9gmmDe8hZ1iyr39 lvKg== X-Gm-Message-State: AOAM530WqoA9M1izesCflA2Xo8M6T8cTKZoomH5PWm3kpThKNIrXS7Zx dk7jLwkElYy0tbq5jz4UMWoVlIA1/sU= X-Google-Smtp-Source: ABdhPJzKwynLzrF3K90EDUEsVg6MnQDICdgp+ecdCP3JaMhSB99r5JEVK4FtkoGus8y4so1RPn/a5A== X-Received: by 2002:a05:6870:f697:b0:da:b3f:3268 with SMTP id el23-20020a056870f69700b000da0b3f3268mr2438611oab.280.1649779553898; Tue, 12 Apr 2022 09:05:53 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:485:4b69:db7b:6eca:4085:74a9]) by smtp.gmail.com with ESMTPSA id i28-20020a056870891c00b000de777f1a41sm13325247oao.46.2022.04.12.09.05.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 09:05:53 -0700 (PDT) From: Fabio Estevam To: sbabic@denx.de Cc: paul.liu@linaro.org, u-boot@lists.denx.de, Fabio Estevam Subject: [PATCH v2 3/5] imx8mm-cl-iot-gate: Retrieve the MAC address from EEPROM Date: Tue, 12 Apr 2022 13:05:37 -0300 Message-Id: <20220412160539.3249234-3-festevam@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220412160539.3249234-1-festevam@gmail.com> References: <20220412160539.3249234-1-festevam@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean From: Fabio Estevam Currently the eth0 MAC address is randomly assigned. Retrieve the MAC address from EEPROM. Signed-off-by: Fabio Estevam --- Changes since v1: - Also update imx8mm-cl-iot-gate-optee_defconfig to fix the build (Stefano). arch/arm/dts/imx8mm-cl-iot-gate.dts | 12 ++++- .../imx8mm-cl-iot-gate/imx8mm-cl-iot-gate.c | 51 +++++++++++++++++++ configs/imx8mm-cl-iot-gate-optee_defconfig | 2 + configs/imx8mm-cl-iot-gate_defconfig | 2 + 4 files changed, 66 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 #include #include +#include +#include #include #include @@ -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-optee_defconfig b/configs/imx8mm-cl-iot-gate-optee_defconfig index 2014509ed52d..c736fd84d91c 100644 --- a/configs/imx8mm-cl-iot-gate-optee_defconfig +++ b/configs/imx8mm-cl-iot-gate-optee_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 diff --git a/configs/imx8mm-cl-iot-gate_defconfig b/configs/imx8mm-cl-iot-gate_defconfig index 0ef9e2548e99..9265299e98f9 100644 --- a/configs/imx8mm-cl-iot-gate_defconfig +++ b/configs/imx8mm-cl-iot-gate_defconfig @@ -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 -- 2.25.1