From patchwork Wed Feb 22 17:22:45 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: 13149392 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 9CFCAC61DA4 for ; Wed, 22 Feb 2023 17:24:57 +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=3FUjZlLVgAl+XGCoTpZ36bTE/kBG6ML6uUg6twcc+nM=; b=nO9kmnv+7nj072 n6MK34vx/mwaip0RvyunmvvODFyo4QiCv+xD+nrVf0D2BKw9HSZSVDEEQY4dl+vgXqbdBPfbMpi7S Ci1blZmvh3r9Kh6HPFRQdrt+LQKh+6f8FggaL2Pgyr4J/abKCjvU7FsJ9DFPaLdI6laXdSo2wQLHi UiZJhiWYnVldK3eYdE565bMbcevkc2A2wlzOkNberI5YwOyEf4CmZeeNtFDc7TEqZqMJ8+tHZA7dc 0ZBfKdx7b0U25djhH1od9z09tOaByE7TRL6jd9eRch+1/WflO6WUyVVRdTkcRHAlLDVWSHt4NWnuu U5l5g6n4O7Gl9yZhzxYg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pUsqX-00DCiW-Up; Wed, 22 Feb 2023 17:24:02 +0000 Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pUspy-00DCQY-5g for linux-arm-kernel@lists.infradead.org; Wed, 22 Feb 2023 17:23:27 +0000 Received: by mail-lj1-x234.google.com with SMTP id e24so2359139ljj.3 for ; Wed, 22 Feb 2023 09:23:23 -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=nSnsOpv8KS0rCS6ksY5VSkRcczl5vnYaXjWVVff7kGI=; b=DEqh460Bb4lDxi7itAAchy/jrIh1Oa/jWaYu4Nx7cgDY96x8jDagi1unEus9USivCe hnkt0DAxuUro+wf1TVDiaPwef0RpD0ZP0ZUI8XqdpEPHbmWx56WXNhJwjrTSTcFh9L81 l9UdDjbAjJrPEQiIYw4C5tm5ibZkYM/+w/O51saS4ht8gDwJkU4o9D3Z6RpPtAhUnaWp XsuVGK3z0vNMtxihXuJ7DqtCo0g3x7kxtzvmUU74ztWEhfW5e7JLrAaE4tOs8EIf9lqf gOyOJeMDeRctrIJkNNsQLdgto+hJ4uQKSybCQG8NcK8wJBT3zd7HMfpr/tJ62VAC4HpK zZPw== 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=nSnsOpv8KS0rCS6ksY5VSkRcczl5vnYaXjWVVff7kGI=; b=Z028hIt7V0X8nZl06hDlIKl2afao7ZmnAW+OGOff7QzRcgW9zPmBvu/1VMXjwalglB mi8/7NNugbrj+pPZak/8fkLRxIiZVxm83nxC4V00238tKXc1zTXZAM9/1w8I7O/am5NS 2CoC7pDduHp6Xzem7X8SuzdtPEA7rXFMv3zWqnMwr58InsvM1MbzXkfDahvkMr7LBzTB Ln4r5G7FtpA6ZJdorWhq7B5CEcPNerWNP/DxSO9uvw8SRqe0dt63w0vGkZ5eOO0uqMvo TkSbpN8wKo25p3XQaxDDU/sYbeHdR9VMJFfteC+jPII3yvBoj7fnG0gooMblyNdF105x Zt+Q== X-Gm-Message-State: AO0yUKXN63/++v2zF4M+ZwRloebPeN9RqHHkQaCVzSatUVrMk45J6ccy X/JKepB3uKYXPrE+jNmfKuw= X-Google-Smtp-Source: AK7set8ci3FrIvgl9vUPXevbFYj2J3UGpD1jWl8kUSJoUcZ0ZOiGOLUbvHQ4ZGdGUqeYXnal0wky2g== X-Received: by 2002:a05:651c:50f:b0:293:4fff:422e with SMTP id o15-20020a05651c050f00b002934fff422emr4780096ljp.16.1677086602368; Wed, 22 Feb 2023 09:23:22 -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 p2-20020a2e93c2000000b0029477417d80sm721513ljh.85.2023.02.22.09.23.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Feb 2023 09:23:21 -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 , 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 4/4] nvmem: u-boot-env: post-process "ethaddr" env variable Date: Wed, 22 Feb 2023 18:22:45 +0100 Message-Id: <20230222172245.6313-5-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222172245.6313-1-zajec5@gmail.com> References: <20230222172245.6313-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230222_092326_242240_D8F1A2F4 X-CRM114-Status: GOOD ( 15.82 ) 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 | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 189ea85bd67d..71322ea7cf53 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -346,6 +346,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..1f5d8aba98bf 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,27 @@ 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 **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_add_cells(struct u_boot_env *priv, uint8_t *buf, size_t data_offset, size_t data_len) { @@ -101,6 +124,8 @@ 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].read_post_process = u_boot_env_read_post_process_ethaddr; } if (WARN_ON(idx != priv->ncells))