From patchwork Sat Mar 18 17:13:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 13179923 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EAAB4C7618B for ; Sat, 18 Mar 2023 17:15:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wASja4R3xQ7VAmJzp1LsPSoCBytu0gcnseiH2AJ49N8=; b=OoPTdWGsB3qMqW aDTGVIEdwMFWru8DGX2AvvbvUl9LBRaomokmSxxHPJKNuFhtAdx6la1ZfL31h50SgJTG45fOHx6Lf isqfMbuc7ovVrFlrgHNN1wiLIPxCNTHROlNSyHJ+Xqjkxc2lj58LCHotF4JlPhh33XzfmSuNbu8// hzYP6qS/QreKTFha8RNeyN9EGVRcujieeSPcxcws2G5Dq0hEvX/v6doM7TUmdiiHy0kO0Pq4RyjuU M6+aIRuhvNfnZgFvJnuDJKRfMhQA4EmLVvl/WhlqgKtQvAggU95ZMFp/3Q4CvbxTiI6bHzQhKGMou R+5t2z5apNVwWr4ego5A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pda8V-00531C-0u; Sat, 18 Mar 2023 17:14:31 +0000 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pda8N-0052xj-0o for linux-arm-kernel@lists.infradead.org; Sat, 18 Mar 2023 17:14:24 +0000 Received: by mail-lj1-x22a.google.com with SMTP id by8so6937616ljb.12 for ; Sat, 18 Mar 2023 10:14:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679159660; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=o6gVXR7MyV0dGeKTkzI0XUj6QXrFR6902YeCKHs1ZQM=; b=mdenNH8Nyexs6YyB62R/BZLhJHWiUS4++a1cZgCzO3QzqQ13iScjbNS8+W9Nxo9Z9o nScggbnS6OkYgx2/QfjKc9S82cp+l+kNMyaGGh0C1QAyLO0d8SUZcgcMTIEaNmChWl6v u1Hs51u4M9GmZ+BAZRYB+F5sYcp6/ZoiDnI07OOR1QmpifluKrnBqpFdiLZbjQnpnaU4 de2By0/MmkKVHh0Wjm45cKM6/zOGETPSD4zkBo/LghjDi4FI6Hq1r+g+K93M57C/YAFT JaoT2+1axMz5zCIHevO/igMIB7A+U4i3J4UBjIojSr1foZN5eFiLKDU4VO6jrPi7amJg f1Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679159660; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o6gVXR7MyV0dGeKTkzI0XUj6QXrFR6902YeCKHs1ZQM=; b=DLIe/8D9jlcvLtCSgQ923pqFFIBbf0pDBNzi/skEXctADMnS89QLngu2HfspOm9Rc8 krJ8+nboWqtv3Ul06tm2YEUXwyEUQWi1vYgjoXdzxKhfZCQwG4OzedT6Ta9XkiA5QQcQ 3ZQfc8YkXz+2ZTTA+Ph71Ul1GAM8AvN9SFRe97Ka6KvgG8EMGfY6xEEneFaqhkPbUvXH NIeadqJQf/BYfvAz6HiDlvkCqKFhSzducYpwL4HAsy7QBjUKRgou+YXCGsRuUpg3BnJC oCyOZZ+jQEGORcNt11ZhaOy3PcagW0L4If5O048mQScWNvvzY8dOPLTddNSkvKaOuB40 kJ7Q== X-Gm-Message-State: AO0yUKWapucRx+HE2Df/ZzyW8R2mSzB9reSBQ4BS4F6xkzR5p7sV+Kcn fHwwr5tk6vI6EksYf0OH6GU= X-Google-Smtp-Source: AK7set8khjgdJDLOjsL60JsKr969nfrsBSBbcfsEBMv6ZZISnKH1yfHmoQD7kzYtX9KchAV/GxaTnA== X-Received: by 2002:a2e:7d15:0:b0:298:b065:c29b with SMTP id y21-20020a2e7d15000000b00298b065c29bmr4403516ljc.38.1679159660245; Sat, 18 Mar 2023 10:14:20 -0700 (PDT) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id r9-20020a2e80c9000000b0029573844d03sm929221ljg.109.2023.03.18.10.14.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 10:14:19 -0700 (PDT) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Srinivas Kandagatla , Rob Herring , Krzysztof Kozlowski Cc: Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Miquel Raynal , Michael Walle , gregkh@linuxfoundation.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, u-boot@lists.denx.de, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH V2 3/3] nvmem: u-boot-env: post-process "ethaddr" env variable Date: Sat, 18 Mar 2023 18:13:56 +0100 Message-Id: <20230318171356.29515-4-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230318171356.29515-1-zajec5@gmail.com> References: <20230318171356.29515-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230318_101423_289688_68F6D4AB X-CRM114-Status: GOOD ( 15.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Rafał Miłecki U-Boot environment variables are stored in ASCII format so "ethaddr" requires parsing into binary to make it work with Ethernet interfaces. This includes support for indexes to support #nvmem-cell-cells = <1>. Signed-off-by: Rafał Miłecki --- drivers/nvmem/Kconfig | 1 + drivers/nvmem/u-boot-env.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index a2afba11c890..b291b27048c7 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -340,6 +340,7 @@ config NVMEM_U_BOOT_ENV tristate "U-Boot environment variables support" depends on OF && MTD select CRC32 + select GENERIC_NET_UTILS help U-Boot stores its setup as environment variables. This driver adds support for verifying & exporting such data. It also exposes variables diff --git a/drivers/nvmem/u-boot-env.c b/drivers/nvmem/u-boot-env.c index 29b1d87a3c51..ee9fd9989b6e 100644 --- a/drivers/nvmem/u-boot-env.c +++ b/drivers/nvmem/u-boot-env.c @@ -4,6 +4,8 @@ */ #include +#include +#include #include #include #include @@ -70,6 +72,25 @@ static int u_boot_env_read(void *context, unsigned int offset, void *val, return 0; } +static int u_boot_env_read_post_process_ethaddr(void *context, const char *id, int index, + unsigned int offset, void *buf, size_t bytes) +{ + u8 mac[ETH_ALEN]; + + if (bytes != 3 * ETH_ALEN - 1) + return -EINVAL; + + if (!mac_pton(buf, mac)) + return -EINVAL; + + if (index) + eth_addr_add(mac, index); + + ether_addr_copy(buf, mac); + + return 0; +} + static int u_boot_env_add_cells(struct u_boot_env *priv, uint8_t *buf, size_t data_offset, size_t data_len) { @@ -101,6 +122,11 @@ static int u_boot_env_add_cells(struct u_boot_env *priv, uint8_t *buf, priv->cells[idx].offset = data_offset + value - data; priv->cells[idx].bytes = strlen(value); priv->cells[idx].np = of_get_child_by_name(dev->of_node, priv->cells[idx].name); + if (!strcmp(var, "ethaddr")) { + priv->cells[idx].raw_len = strlen(value); + priv->cells[idx].bytes = ETH_ALEN; + priv->cells[idx].read_post_process = u_boot_env_read_post_process_ethaddr; + } } if (WARN_ON(idx != priv->ncells))