From patchwork Fri Jan 27 12:57:09 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: 13118680 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 0C8F6C54EAA for ; Fri, 27 Jan 2023 13:30:16 +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=+WQPmq9C68/bE6DxlSrAAhTyHiDtnwNX4Y6rSeHZDxo=; b=ZVZyODUnFT+lOw McvgpiFd/5gR7TGgQQKgYpkC2vAWhPoeUGyIogbOYtxUqHzD5iU1UbtYkMa8Jx2zcUKxH6cARLGwL 6kEo0rG6VIB5i+EATqu+lqhrvjn/iG/8GnlvfdHdSqxkp/Pj4iAzzKGQsYWg4XXaMPEBAATfitZ/I sgQahCepUXatzGSnmV4aKoPWfo1J/0xEfSYhd6Mzq12zZkSLcH9cWhmHZIInupmkX9AXrenLnAq4x lWakOm/LzllLABqH7Z5TgPSvUstnvo3Wi71/02P18q5KaVGnGxcsYcol7sU4oz76mPEg62c+Li6vF vfE7pMGmvuJ98GAPBmBA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLOmr-00EzmJ-8b; Fri, 27 Jan 2023 13:29:02 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pLOIY-00EmHf-8B for linux-arm-kernel@bombadil.infradead.org; Fri, 27 Jan 2023 12:57:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=9ZG5/dJfEvlfksUEy4dZqlxkQUvfDpGnkVNpt/A8DFM=; b=HjfBoB1Y8KDNPYcTx9r3CKjqBG kvhPQYlLUKfxw0UNDdebI/zdCSWfIVeRv7NtuibqetEAXDPH0YczD3ilm/dRmLDNrPopnxw9Yq6tc eS5WWoyNginLJKbntnn+kYexq3+1HApf1CsROShXKabhJPB3VEZf3TwoDu9IQn5Dj+nSSYMo2iFcl 4y+ZvwAqr9LvT4LDs4WyGKhlEW6tjEHMi4CGJNoY4rCerfIuiPqVeRZGPwtSVEfIs5GPC950gSzSx pCvAS/FsZy24myMt41/JYk9jLSKl84nqaBvGOlzZkI57SqzfV8wGWaaMF2wKMDKQX/YB6UGsRZLjw uow82sYQ==; Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pLOHu-002nzz-25 for linux-arm-kernel@lists.infradead.org; Fri, 27 Jan 2023 12:57:08 +0000 Received: by mail-ed1-x534.google.com with SMTP id x7so1436248edr.0 for ; Fri, 27 Jan 2023 04:57:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=9ZG5/dJfEvlfksUEy4dZqlxkQUvfDpGnkVNpt/A8DFM=; b=EX3d7D9gnItYT1rU6c/kJyqXPYfLJK0VS58ySEa8KxtMm+SfJqn3lQxVk09N6+0cCT kl8DduwQd8D+ta6lsxIUn3FaKKsR28tvCVCEu4JyFLzf8ukjn5p7JwgZLFzTLpIkcomx 3hfIzFHnvUquZFohcnL7uBSbixlVbDLaTK0t2Q71quau437fCyVkKwgx0o8TtvwfgG1J rfxZsv5iSj9m9br8IPfIi4MVeiwAwFTg6CIYcp/sksPUHqu49wiFIWu9urk0YoHrriqm sXnvzEKRBBSRtlp3I6E2j4S8O2l91TxyyS7G+rPgV84RWPNAnwFNimu4IOaXMgPS+0jt Wecg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=9ZG5/dJfEvlfksUEy4dZqlxkQUvfDpGnkVNpt/A8DFM=; b=M/f7FZTuSiAdyKqHG3NlnFF/BArgpNXH1s2F4yM6WbthUgr8BiH1GFH1NKCHNWFs+S 8ukhTGV5DB3hJp8GB2CbXtWgzGTWCEEMeGovmcaNo2R9jTRtjFcCQQz7Q2L9DWcy1R+5 8wx5+K8HHEwZJ0A0Ar/0bhb9eaCJL5/fL/EStt4bcxrxmT9cnCWLFn3CvHT9ok8DVIVo EbY5+2VX4oZRWEXJFap846s1PZkNupAbvnpU3bYjvNEDfHu7H7hEOH5g5mIiEPhjr8ZW Zn7iehm2HgygMzXe+DsfAI3cTAef8C95apIlg7gioJWByhyvYhHRGRMq989Ox8d+cx5w +i3A== X-Gm-Message-State: AFqh2kpyZHObc4DK7I2XTpwaod7td2lqVEqDPj6Zni4E9ZH5D+2DQFYC oQuxJYGlFCNbcrP3emH6J34= X-Google-Smtp-Source: AMrXdXs9hkTQoMtsQj/q7bK+0hqEGX45N2hOmMzacl7O03MEP6FYZIiUlc8wIjtyjmskicMgm3eMPg== X-Received: by 2002:a50:ff12:0:b0:492:8c77:7da9 with SMTP id a18-20020a50ff12000000b004928c777da9mr37459278edu.9.1674824250105; Fri, 27 Jan 2023 04:57:30 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id y5-20020a056402358500b00482e0c55e2bsm2248136edc.93.2023.01.27.04.57.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 04:57:29 -0800 (PST) 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 , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, u-boot@lists.denx.de, =?utf-8?b?UmFmYcWCIE1p?= =?utf-8?b?xYJlY2tp?= Subject: [PATCH V3 6/6] nvmem: u-boot-env: post process "ethaddr" env variable Date: Fri, 27 Jan 2023 13:57:09 +0100 Message-Id: <20230127125709.32191-6-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127125709.32191-1-zajec5@gmail.com> References: <20230127125709.32191-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230127_125702_986693_2E4D47AC X-CRM114-Status: GOOD ( 15.97 ) 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/layouts/Kconfig | 1 + drivers/nvmem/layouts/u-boot-env.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig index 8a38c514943a..566b4f25630d 100644 --- a/drivers/nvmem/layouts/Kconfig +++ b/drivers/nvmem/layouts/Kconfig @@ -23,6 +23,7 @@ config NVMEM_LAYOUT_ONIE_TLV config NVMEM_LAYOUT_U_BOOT_ENV bool "U-Boot environment variables support" 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/layouts/u-boot-env.c b/drivers/nvmem/layouts/u-boot-env.c index 95c314553952..e99b853a44c4 100644 --- a/drivers/nvmem/layouts/u-boot-env.c +++ b/drivers/nvmem/layouts/u-boot-env.c @@ -4,6 +4,8 @@ */ #include +#include +#include #include #include #include @@ -36,6 +38,27 @@ struct u_boot_env_image_broadcom { uint8_t data[]; } __packed; +static int u_boot_env_read_post_process_ethaddr(void *context, const char *id, int index, + unsigned int offset, void **data, size_t *bytes) +{ + u8 mac[ETH_ALEN]; + + if (*bytes != 3 * ETH_ALEN - 1) + return -EINVAL; + + if (!mac_pton(*data, mac)) + return -EINVAL; + + if (index) + eth_addr_add(mac, index); + + /* We need *smaller* buffer so don't bother to krealloc() */ + ether_addr_copy(*data, mac); + *bytes = ETH_ALEN; + + return 0; +} + static int u_boot_env_parse_data(struct device *dev, struct nvmem_device *nvmem, uint8_t *buf, size_t data_offset, size_t data_len) { @@ -67,6 +90,8 @@ static int u_boot_env_parse_data(struct device *dev, struct nvmem_device *nvmem, info.offset = data_offset + value - data; info.bytes = strlen(value); info.np = of_get_child_by_name(np, info.name); + if (!strcmp(var, "ethaddr")) + info.read_post_process = u_boot_env_read_post_process_ethaddr; err = nvmem_add_one_cell(nvmem, &info); if (err) {