From patchwork Tue Jan 10 10:54:20 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: 13094962 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 803C7C54EBC for ; Tue, 10 Jan 2023 10:56:28 +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: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:In-Reply-To:References: List-Owner; bh=9rrX9i/b+/8Ma0xcFZu85hfae77Ai+0xC8RnWT7UoJA=; b=fOQArg+hPnsX1w COn2VcxqjKX59M+7fEMIZiG+IPGRpfwYsMhm/911b7IHd+7WTFVav+hza2fviBJduO7KbIDKAaS8M 7uZ5GVClbQ1U2xBCccsWLsTqSn0HgOf8vsrg5nAIl0240MFVRqDK3HaFlp/xWkfjcdFOsP1YQ0I5d +JuA/SPEjQfqibv02I8DGS/Nno3F09oiClinOrEVvPadEUyTvl8xa6kV4x4a1jca5DIkww12Sn1Zz 4VjNEzQ5X9EFl8PfkCM7U3EAMoMBMMhtU9oqqnGJ9KMWYpSxk1GzGt9T3Hnx8EW0ua4nAwduXbjuE rszf9xscSq3K4ytNMvoA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFCHu-006SvK-8e; Tue, 10 Jan 2023 10:55:26 +0000 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFCH6-006SaA-R2 for linux-arm-kernel@lists.infradead.org; Tue, 10 Jan 2023 10:54:38 +0000 Received: by mail-ed1-x536.google.com with SMTP id j16so16907244edw.11 for ; Tue, 10 Jan 2023 02:54:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=kx33osG0iIsA/kyalJIybKATyfWaMXF9jLXNGZKLKMc=; b=k5eMydzOQ4SSz/enP/AZgMBTxZ3wxzbr4iy9HH74X9Wo7sH3oUW9IyrLVrLK2cf2wc zuSWFUOsT12RRRHg2LOo6wi1bQWeWdvi08ypPH0suPvYe+xYM9RWrc9BzUB71YgF9fOi Lq4HPmCy2nRPI+/kCyS8sG1WqgxIDuZeE73JQL4ny4jhpXP8KdtjHNyQJoRZLH10FQK4 WIgKcEIu5m3iYn1NQzZ2p92sCfpp+3ZnGYc8JsWpiSeWKlNP9jjHsaKIPHrS0XxWtJih 4BKng+Gsh8KOWVcY5YCvwpbZpxPJRWVEahK0ERsB1omXnGLj0ABvGnNNWA7a6XhI0p8n d87w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kx33osG0iIsA/kyalJIybKATyfWaMXF9jLXNGZKLKMc=; b=I2y+HI3wBtsNU4LMP9ED1IVdHOlNq/h6+wKMMLU3JN0hNFYq+HicCLdhXt0px9WPfE 0eRYNbD+JKLKHE+DJqHGRdo9ttIZJPpLNqZ2uhTVBHjm95lEhZZQsmFsi1SXUAw/ThXS XGC9ARFbZLaclgAvlGZRPzG08w7GQY6r0gPQs3vZ8ZQrcJ7KF8+FPozT6AOgWjPXCLqD VBbOce3SDS3bNnBQ3teFJhVBgjkradSGhZ9AmS4hQh+cw6+mZUK/xolMwb5jFEj1cftT LXeIOhqB79NSanVd8jcgJW6qWMluEKIvQ33eSqtIVa9W4HKInFKcf4xYrxm/l4UMzfgm et1g== X-Gm-Message-State: AFqh2koxNQWD0bMl/thMNu3kWQ0kvUWqwgkoJ+j5dYidefyttFlgtdH6 S2OC+YCk0CtiNFduXKALRwM= X-Google-Smtp-Source: AMrXdXujTDH9bun7NJvAXIkJISNElTOLLlrnMwl8tuomQ5TWs/s0LVewdaaY9i/gr94QXtYBCFBFJQ== X-Received: by 2002:a05:6402:2685:b0:493:b55d:d7f2 with SMTP id w5-20020a056402268500b00493b55dd7f2mr24287133edd.14.1673348074366; Tue, 10 Jan 2023 02:54:34 -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 s1-20020aa7c541000000b00495c3573b36sm4818199edr.32.2023.01.10.02.54.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 02:54:33 -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 1/6] nvmem: core: add nvmem_dev_size() helper Date: Tue, 10 Jan 2023 11:54:20 +0100 Message-Id: <20230110105425.13188-1-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230110_025436_939958_6BFB414A X-CRM114-Status: GOOD ( 12.37 ) 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 This is required by layouts that need to read whole NVMEM space. It applies to NVMEM devices without hardcoded layout (like U-Boot environment data block). Signed-off-by: Rafał Miłecki --- drivers/nvmem/core.c | 13 +++++++++++++ include/linux/nvmem-consumer.h | 1 + 2 files changed, 14 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 1f05f0a50d86..81743ae8793b 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -2062,6 +2062,19 @@ void nvmem_del_cell_lookups(struct nvmem_cell_lookup *entries, size_t nentries) } EXPORT_SYMBOL_GPL(nvmem_del_cell_lookups); +/** + * nvmem_dev_size() - Get the size of a given nvmem device. + * + * @nvmem: nvmem device. + * + * Return: size of the nvmem device. + */ +const size_t nvmem_dev_size(struct nvmem_device *nvmem) +{ + return nvmem->size; +} +EXPORT_SYMBOL_GPL(nvmem_dev_size); + /** * nvmem_dev_name() - Get the name of a given nvmem device. * diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h index fa030d93b768..d88294ddf562 100644 --- a/include/linux/nvmem-consumer.h +++ b/include/linux/nvmem-consumer.h @@ -78,6 +78,7 @@ ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, int nvmem_device_cell_write(struct nvmem_device *nvmem, struct nvmem_cell_info *info, void *buf); +const size_t nvmem_dev_size(struct nvmem_device *nvmem); const char *nvmem_dev_name(struct nvmem_device *nvmem); void nvmem_add_cell_lookups(struct nvmem_cell_lookup *entries, From patchwork Tue Jan 10 10:54:21 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: 13094963 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 17A5DC54EBE for ; Tue, 10 Jan 2023 10:56:52 +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=TvNdYQdCPbfTi8f32rwqBErpEHQGTRM3VnBrLCm/4ks=; b=MCRqB7pcG1gIsl 4QJOc6JgliUvUmkhIYKlsNxyQj/JMdpm6hQbtdj05IZyPS8PHI53r6v78UMTaMwLAGWknJZvAF5zl EGiYpRfOR9hKdwxIo6/YECCfiYqI2p4o+HVVwiz4sbUwOqZ49CRxFCuPZ+f9YJCxJKX0RJmnvhM+I GRHLGp1KtgcAfwtuZ2Vezv7AS5kQUahU5QpIJqdePjI9yx6xBDnlieGEGZJP3hq3pYAtizCC2aqm7 SOvmCJTvzTI3h78In7ljhRy28RRuGAeglWDvMcFhzBFcoGkcyyJasMz33G8iNdeT9N3ImxDytG2Uj GBsyjiuMJRnZZtzrACUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFCII-006T57-3L; Tue, 10 Jan 2023 10:55:50 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFCH8-006Sah-3Y for linux-arm-kernel@lists.infradead.org; Tue, 10 Jan 2023 10:54:40 +0000 Received: by mail-ed1-x529.google.com with SMTP id c17so16899444edj.13 for ; Tue, 10 Jan 2023 02:54:37 -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=0rYqNvw1clZ8LqYgMptRErDOAS/Q5a8tz7ExdHTB2xE=; b=OzrLT3uMZnZyonsG0BfQLaW4dNc5Lqk8do1tjuMdzVPGNz693KtSsJOaedcQlns/Uy ZuE6fhfng2yKAZ84snlCvjb7Qrut0A3m6cMw4eD1WskGiQR/YGeseIKN0s6J7dd0eNkO i8mC5N4E6lIkmGERUywImret5/YH3fLrSLq0bKpn/azpV6uRyOrAndCFF9rDyh3qh7Pm azUULhHJVAII0iMvKZKcJ8/x/6Uj51K+ITZCwFRH7+EF1AGIecFlVlVoEQZ1HXq2fL4Z bePoRLTBUJNmKymydIkHaZkmkdeubcCM4ztbDGK4txOlspd5ilxKUz3n9zZmJcpJItpK 46RA== 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=0rYqNvw1clZ8LqYgMptRErDOAS/Q5a8tz7ExdHTB2xE=; b=Y7wfslU5rbpp17prnlzDOqZazbxWd2hKO0z+P9sG+x2INOlq+Udf7e7HWtaLV0LXRe YSd0ituPyRtIgDjapCH5BxWNlEFkjElMUYSM07lFaCoFpY0FCsGeTISMARi2EOz+xnJs gMrx9dPS3aMMiEZjA8r4y5VMbXUck1ZQKyzX7nTaAbLvbt1QKKpu693r1Ya+WtYSgocf CInTKVRBmd8/4T/QxKQLB7IzVxtyHgJO0+hGCUqifF2U9CVRRhGjqhqIaPvYaQYWJk6a 5q/8rp6uyUAOrRnWZXdH+NQlekLwxjkpgCl/Qr93VuShAUjPV8zI8CK8wKgvWiv3fY2O tOLA== X-Gm-Message-State: AFqh2kpNAnYqAWEyBQnwAcyw0tNp66hC7a2BwyNX4aOAO6rOZYdce1oV ugoZe+rwQC/L98oj4Sgz4mw= X-Google-Smtp-Source: AMrXdXtp3wN8YWvbU8A8T8icWXq0xBr4Xw4SxejizDnsm3B8V9o3Pk0WFVdao8d16D7SJi3bb4++kA== X-Received: by 2002:a05:6402:3887:b0:496:4d2f:1b4b with SMTP id fd7-20020a056402388700b004964d2f1b4bmr13847018edb.7.1673348076271; Tue, 10 Jan 2023 02:54:36 -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 s1-20020aa7c541000000b00495c3573b36sm4818199edr.32.2023.01.10.02.54.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 02:54:35 -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 2/6] nvmem: core: allow .read_post_process() callbacks to adjust data length Date: Tue, 10 Jan 2023 11:54:21 +0100 Message-Id: <20230110105425.13188-2-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110105425.13188-1-zajec5@gmail.com> References: <20230110105425.13188-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230110_025438_192782_B05CB47D X-CRM114-Status: GOOD ( 19.98 ) 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 Sometimes reading NVMEM cell value involves some data reformatting. It requires passing updated size value to the caller. Support that. It's required e.g. to provide properly formatted MAC address in case it's stored in a non-binary format (e.g. using ASCII). Signed-off-by: Rafał Miłecki --- drivers/nvmem/core.c | 5 +++-- drivers/nvmem/imx-ocotp.c | 6 +++--- drivers/nvmem/layouts/onie-tlv.c | 2 +- drivers/nvmem/layouts/sl28vpd.c | 4 ++-- include/linux/nvmem-provider.h | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 81743ae8793b..f4040776e96c 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1541,6 +1541,7 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem, struct nvmem_cell_entry *cell, void *buf, size_t *len, const char *id, int index) { + size_t bytes = cell->bytes; int rc; rc = nvmem_reg_read(nvmem, cell->offset, buf, cell->bytes); @@ -1554,13 +1555,13 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem, if (cell->read_post_process) { rc = cell->read_post_process(cell->priv, id, index, - cell->offset, buf, cell->bytes); + cell->offset, buf, &bytes); if (rc) return rc; } if (len) - *len = cell->bytes; + *len = bytes; return 0; } diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index ac0edb6398f1..ebd0e9e0314e 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -223,15 +223,15 @@ static int imx_ocotp_read(void *context, unsigned int offset, } static int imx_ocotp_cell_pp(void *context, const char *id, int index, - unsigned int offset, void *data, size_t bytes) + unsigned int offset, void *data, size_t *bytes) { u8 *buf = data; int i; /* Deal with some post processing of nvmem cell data */ if (id && !strcmp(id, "mac-address")) - for (i = 0; i < bytes / 2; i++) - swap(buf[i], buf[bytes - i - 1]); + for (i = 0; i < *bytes / 2; i++) + swap(buf[i], buf[*bytes - i - 1]); return 0; } diff --git a/drivers/nvmem/layouts/onie-tlv.c b/drivers/nvmem/layouts/onie-tlv.c index 767f39fff717..1e1f8935abe7 100644 --- a/drivers/nvmem/layouts/onie-tlv.c +++ b/drivers/nvmem/layouts/onie-tlv.c @@ -76,7 +76,7 @@ static const char *onie_tlv_cell_name(u8 type) static int onie_tlv_mac_read_cb(void *priv, const char *id, int index, unsigned int offset, void *buf, - size_t bytes) + size_t *bytes) { eth_addr_add(buf, index); diff --git a/drivers/nvmem/layouts/sl28vpd.c b/drivers/nvmem/layouts/sl28vpd.c index a36800f201a3..63c0da58ad60 100644 --- a/drivers/nvmem/layouts/sl28vpd.c +++ b/drivers/nvmem/layouts/sl28vpd.c @@ -23,9 +23,9 @@ struct sl28vpd_v1 { static int sl28vpd_mac_address_pp(void *priv, const char *id, int index, unsigned int offset, void *buf, - size_t bytes) + size_t *bytes) { - if (bytes != ETH_ALEN) + if (*bytes != ETH_ALEN) return -EINVAL; if (index < 0) diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 0cf9f9490514..5d896eec2f1c 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -21,7 +21,7 @@ typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset, /* used for vendor specific post processing of cell data */ typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, int index, unsigned int offset, void *buf, - size_t bytes); + size_t *bytes); enum nvmem_type { NVMEM_TYPE_UNKNOWN = 0, From patchwork Tue Jan 10 10:54:22 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: 13094964 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 43D04C46467 for ; Tue, 10 Jan 2023 10:57:29 +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=BSqCbwZsMfF922fuljTv9RtNQdo1QDzGdAqipBY7HGw=; b=urOvppabcnL7E0 AUYmGnu9GFO3+Jhe+pz/7GDuJAzNkrlOmmZOSBY+//LYgHHrHDABkYbd/JjoeCk6ODHuRPq/HUOHr t0NVYwnkfj/xEWLf+EuE8JQCCOzWoZEkrAiiwdD2sns7sD1qumkSGmlJWOchav8RqpN2uiXI0WXAz Qxhi/QPFeFiyVQmxJ6801T54DpxeCuJyp7K6pD3ESFa5iBQc/Ownh/fBCq72SsJIiYxiCeScraaFj Q5iXdVGjzxsgBQBmqdikuAlup402H07pyQl33uUv9LAzagPdCKcv3Ctjil4quTjRz3+nJPWc4sz3j U9BBN/W+rXERLNUBetvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFCIl-006TFl-E3; Tue, 10 Jan 2023 10:56:20 +0000 Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFCH9-006Sbe-So for linux-arm-kernel@lists.infradead.org; Tue, 10 Jan 2023 10:54:41 +0000 Received: by mail-ed1-x52d.google.com with SMTP id i15so16947142edf.2 for ; Tue, 10 Jan 2023 02:54:39 -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=xLzMMc8ebvQzEKmQRYFOwkLETqyrkUTk5WSaxVlJTiI=; b=IsCWQtuQDU5qsCQI6/tTjUWEUyImFFhL4B88algPA7RIysJjlhBgZeDzBc8/3lxixG 2FDafXmGbGiPQ3OrB8GT3/BcYy6bFRMqVCum8+O7UnoyfTjeenl2qQmY6IyvHrLMZbtw JNN7WJ02vfrAog/W9sGzUeOaa9i3NGxVgZVQv/AnovdnEOkJPrdlbhBvaGJOH+u2rpRU b7cp50CEW2thZQstFlNoy0qQdQEBNetkrZTJb3/5aMTK79wMmBoswM1IuCXYanY94OpM 4/5/TKPWlEgSjc6mEJk/sWXbsF/MC9z9vT9X+IX+wT3f5Ahiab/K1QKG+NuLbWo9XACP 2jHQ== 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=xLzMMc8ebvQzEKmQRYFOwkLETqyrkUTk5WSaxVlJTiI=; b=s71T4717mNgb2naUcXIT7GbYhnzWkiYcb/wjUwyid1/lMQQBuuef6wnKkU6HK2fCbc BtXBGhEyY9kPf16hVKNWlrhCNwmp73rFVwbo1LSzzzFz7LMRQrC3joig9031+cxanoaC ucwpPsPi+VH3+PcW9iwWHm2SzH1qcUwVeWbIfx5b6oyzdZryU2iJwpHcoUusoTT90RnC uxjArlKQzJthOKKYdROIKN2Ap3ZWoGsn1yZ9J826Nn8NLHkUZxUnrok+DGHkwxqisxl6 31gx7WohijRXmTCm/0gZp3XXyywOcCAh43ds3XrUSYZ3CL9Ai+Gw8eTtrmzMCA3YmYpO wqtA== X-Gm-Message-State: AFqh2krIBH8eFHTbk1YFc+Ydq3kKK22XSdeg/+d9i+UYLjAvRnl6Tbln a89pwKUK9PfO42HhAs5YM4E= X-Google-Smtp-Source: AMrXdXu38Gs7Qnlsw9kDlHcdMDp/WAeOqy1ZliIhH6aoLn9i+awk7EjgqndYA5XoH55hAoDmQyfXEw== X-Received: by 2002:a05:6402:1caa:b0:475:b14a:f83a with SMTP id cz10-20020a0564021caa00b00475b14af83amr53164998edb.15.1673348077948; Tue, 10 Jan 2023 02:54:37 -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 s1-20020aa7c541000000b00495c3573b36sm4818199edr.32.2023.01.10.02.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 02:54:37 -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 3/6] dt-bindings: nvmem: convert U-Boot env vars to NVMEM layout Date: Tue, 10 Jan 2023 11:54:22 +0100 Message-Id: <20230110105425.13188-3-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110105425.13188-1-zajec5@gmail.com> References: <20230110105425.13188-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230110_025439_993200_E3AD4888 X-CRM114-Status: GOOD ( 16.59 ) 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 can be found of various underlaying storage entities. This binding should be defined as a layout on top on NVMEM device not a NVMEM device itself. Signed-off-by: Rafał Miłecki --- .../bindings/nvmem/layouts/nvmem-layout.yaml | 1 + .../nvmem/{ => layouts}/u-boot,env.yaml | 29 ++++++++++--------- MAINTAINERS | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) rename Documentation/devicetree/bindings/nvmem/{ => layouts}/u-boot,env.yaml (77%) diff --git a/Documentation/devicetree/bindings/nvmem/layouts/nvmem-layout.yaml b/Documentation/devicetree/bindings/nvmem/layouts/nvmem-layout.yaml index 8512ee538c4c..8835b1781a9f 100644 --- a/Documentation/devicetree/bindings/nvmem/layouts/nvmem-layout.yaml +++ b/Documentation/devicetree/bindings/nvmem/layouts/nvmem-layout.yaml @@ -20,6 +20,7 @@ description: | oneOf: - $ref: kontron,sl28-vpd.yaml - $ref: onie,tlv-layout.yaml + - $ref: u-boot,env.yaml properties: compatible: true diff --git a/Documentation/devicetree/bindings/nvmem/u-boot,env.yaml b/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml similarity index 77% rename from Documentation/devicetree/bindings/nvmem/u-boot,env.yaml rename to Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml index cbc5c69fd405..fb273b174fe7 100644 --- a/Documentation/devicetree/bindings/nvmem/u-boot,env.yaml +++ b/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml @@ -1,10 +1,10 @@ # SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause %YAML 1.2 --- -$id: http://devicetree.org/schemas/nvmem/u-boot,env.yaml# +$id: http://devicetree.org/schemas/nvmem/layouts/u-boot,env.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: U-Boot environment variables +title: NVMEM layout of U-Boot environment variables description: | U-Boot uses environment variables to store device parameters and @@ -14,16 +14,11 @@ description: | Data is stored using U-Boot specific formats (variant specific header and NUL separated key-value pairs). - Environment data can be stored on various storage entities, e.g.: + Environment data can be stored on NVMEM devices of various underlaying storage + entities, e.g.: 1. Raw flash partition 2. UBI volume - This binding allows marking storage device (as containing env data) and - specifying used format. - - Right now only flash partition case is covered but it may be extended to e.g. - UBI volumes in the future. - Variables can be defined as NVMEM device subnodes. maintainers: @@ -67,11 +62,14 @@ examples: read-only; }; - env: partition@40000 { - compatible = "u-boot,env"; + partition@40000 { reg = <0x40000 0x10000>; - mac: ethaddr { + nvmem-layout { + compatible = "u-boot,env"; + + mac: ethaddr { + }; }; }; }; @@ -87,9 +85,12 @@ examples: label = "u-boot"; partition-u-boot-env { - compatible = "brcm,env"; - ethaddr { + nvmem-layout { + compatible = "brcm,env"; + + ethaddr { + }; }; }; }; diff --git a/MAINTAINERS b/MAINTAINERS index 2a1368722c45..2e13ee875c77 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -21136,7 +21136,7 @@ F: drivers/media/pci/tw686x/ U-BOOT ENVIRONMENT VARIABLES M: Rafał Miłecki S: Maintained -F: Documentation/devicetree/bindings/nvmem/u-boot,env.yaml +F: Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml F: drivers/nvmem/u-boot-env.c UACCE ACCELERATOR FRAMEWORK From patchwork Tue Jan 10 10:54:23 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: 13094965 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 D5908C54EBC for ; Tue, 10 Jan 2023 10:58:23 +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=3ajKjOz7NV0JS7AUkJVWurHVrAuww514kVdH8QoUNuM=; b=ps+1w1AkrsLKxO bFY1q329zuWBCnNeES99HimIYSPkBMKvzyohvABad8FwhsRqbCYIslnRsc63xZnrdi3XABrWh7k5H N7gPvJlp9AiH+IuWFvSv4U8h7bB1Aqqu5DxyWCzeT/03lJH1P/CEJMFhtwxLdMhALDuL35N3WORx7 fyYjTfT5XNeW/MwxOnKZ7RAXv7wJOwEyK+dn31lOkjEpAP0nZuM06En9TwLm+89zAfuxnDzqOzTf6 Hfv10Tt+QaS1/cmdzUgf4ntOAXMagZMysUTEnWeEJ2ovb4yzKZckkwmjuPDn0syCp3jmRL0a0BK7q iDlVkfkCQcAJiPzXWBRA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFCJd-006Td5-72; Tue, 10 Jan 2023 10:57:14 +0000 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFCHB-006Sd0-V9 for linux-arm-kernel@lists.infradead.org; Tue, 10 Jan 2023 10:54:44 +0000 Received: by mail-ed1-x530.google.com with SMTP id z11so16970404ede.1 for ; Tue, 10 Jan 2023 02:54:41 -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=fmyqQiyVRmFOYXu2QDS2W36W/FBaUp726XptlAMZsWw=; b=C4w2ryEpWmmmLMnP5N7qhckTFtP0fKcI8wSrRoV+o5k4orXcq567QMwSlXJmqWwf/p nBn+V1j62Z+9oEchALJmriNG8GVQqK9PRqSiLsCDvQL68yWmcf1WhkOl3gkBiG7re+lQ SL+L9n/Nowg6ZBV4skY6fB3Ovc8SZtxquXANK9SHmciBqhdv6FskQMLnv0sums2mOXoC 0zFfYhq2WFyqVtqX+eBtJXGk9B00Yp3G9tb8D4jxVYtXRecUUffImEWESbH2ZobWoMlQ VI94yoH2K9pjOlas6c60IpnfAmOWIJDH3RNehnbSReNMBOBxEr3BAlWe0SMrChvCzGnt xUpw== 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=fmyqQiyVRmFOYXu2QDS2W36W/FBaUp726XptlAMZsWw=; b=1z6zflH9FIXI76YiQxzzoRHQr+9MymemGMclbe8R7fCVqhfOZq1VHOWf3CekEo8ULF kULmSENmYhbVyAFcpLUytbjafD/TBsjo9eJ71xQTMqAUDwL/Tdb4cMcrS54DD4l/pmOv QGukLT0QBto3OQgdSOsOivQpxNVngPC2G9UIby14sP5PFyasIihGbj8Oi2pTfakt1HnA OCc4Ig1qDAKqDuaui4Hac8EtE+DaZSbIkwF4cWnR/A3mPxvvRhb1hFRW9q1g55rJMi8z 1p++0etFPuEoNPg1smxpkijfgZ+kUFkZVnoOPNxy4oegn2a60zjHfhlVxBwkIfzO+FNa ynLw== X-Gm-Message-State: AFqh2koVRIusaPqJGOseFKWCBgcAnakvHQOTJRCAMd3S12N/Y5Wv7uoO 4lvAUqwdqoqH2ESivD+zvHs= X-Google-Smtp-Source: AMrXdXuMmiAS5CQc8ZMzHqiyRin8fv767BLT2Ch4nTfKwilZM5AUijtZL2U+SVLHvX95NzHtpOaKUw== X-Received: by 2002:a05:6402:4141:b0:469:ee22:d97a with SMTP id x1-20020a056402414100b00469ee22d97amr62099196eda.32.1673348079841; Tue, 10 Jan 2023 02:54:39 -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 s1-20020aa7c541000000b00495c3573b36sm4818199edr.32.2023.01.10.02.54.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 02:54:39 -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 4/6] nvmem: u-boot-env: convert to layout driver Date: Tue, 10 Jan 2023 11:54:23 +0100 Message-Id: <20230110105425.13188-4-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110105425.13188-1-zajec5@gmail.com> References: <20230110105425.13188-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230110_025442_082963_EC04D70D X-CRM114-Status: GOOD ( 33.83 ) 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 can be found on various NVMEM devices (not just MTD) so convert this driver to a generic layout one. This way - thanks to using NVMEM generic API - this driver can be reused in other scenarios. For backward DT compatibility we need to support the old compatible brinding string for now. Luckily it's just a one line of code. Signed-off-by: Rafał Miłecki --- MAINTAINERS | 2 +- drivers/mtd/mtdcore.c | 7 +- drivers/nvmem/Kconfig | 14 +- drivers/nvmem/Makefile | 2 - drivers/nvmem/layouts/Kconfig | 10 ++ drivers/nvmem/layouts/Makefile | 1 + drivers/nvmem/layouts/u-boot-env.c | 176 ++++++++++++++++++++++ drivers/nvmem/u-boot-env.c | 233 ----------------------------- 8 files changed, 199 insertions(+), 246 deletions(-) create mode 100644 drivers/nvmem/layouts/u-boot-env.c delete mode 100644 drivers/nvmem/u-boot-env.c diff --git a/MAINTAINERS b/MAINTAINERS index 2e13ee875c77..ace29081c613 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -21137,7 +21137,7 @@ U-BOOT ENVIRONMENT VARIABLES M: Rafał Miłecki S: Maintained F: Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml -F: drivers/nvmem/u-boot-env.c +F: drivers/nvmem/layouts/u-boot-env.c UACCE ACCELERATOR FRAMEWORK M: Zhangfei Gao diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 0feacb9fbdac..621e0b87b781 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -518,6 +518,11 @@ static int mtd_nvmem_add(struct mtd_info *mtd) { struct device_node *node = mtd_get_of_node(mtd); struct nvmem_config config = {}; + bool use_dev_of_node = false; + + if (of_device_is_compatible(node, "nvmem-cells") || + (IS_ENABLED(CONFIG_NVMEM_U_BOOT_ENV) && of_device_is_compatible(node, "brcm,env"))) + use_dev_of_node = true; config.id = -1; config.dev = &mtd->dev; @@ -530,7 +535,7 @@ static int mtd_nvmem_add(struct mtd_info *mtd) config.read_only = true; config.root_only = true; config.ignore_wp = true; - config.no_of_node = !of_device_is_compatible(node, "nvmem-cells"); + config.no_of_node = !use_dev_of_node; config.priv = mtd; mtd->nvmem = nvmem_register(&config); diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 0e10b5b094b9..980734ba8ddc 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -327,17 +327,13 @@ config NVMEM_SUNXI_SID will be called nvmem_sunxi_sid. config NVMEM_U_BOOT_ENV - tristate "U-Boot environment variables support" + bool "U-Boot environment variables deprecated binding support" depends on OF && MTD - select CRC32 + select NVMEM_LAYOUT_U_BOOT_ENV help - U-Boot stores its setup as environment variables. This driver adds - support for verifying & exporting such data. It also exposes variables - as NVMEM cells so they can be referenced by other drivers. - - Currently this drivers works only with env variables on top of MTD. - - If compiled as module it will be called nvmem_u-boot-env. + This option enables support for deprecated DT binding for U-Boot + environment variables. It was used by DT files before introducing + nvmem-layout node based syntax. config NVMEM_UNIPHIER_EFUSE tristate "UniPhier SoCs eFuse support" diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index 4cf87ef6c24d..3b827ce96f6d 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -66,8 +66,6 @@ obj-$(CONFIG_NVMEM_SUNPLUS_OCOTP) += nvmem_sunplus_ocotp.o nvmem_sunplus_ocotp-y := sunplus-ocotp.o obj-$(CONFIG_NVMEM_SUNXI_SID) += nvmem_sunxi_sid.o nvmem_sunxi_sid-y := sunxi_sid.o -obj-$(CONFIG_NVMEM_U_BOOT_ENV) += nvmem_u-boot-env.o -nvmem_u-boot-env-y := u-boot-env.o obj-$(CONFIG_NVMEM_UNIPHIER_EFUSE) += nvmem-uniphier-efuse.o nvmem-uniphier-efuse-y := uniphier-efuse.o obj-$(CONFIG_NVMEM_VF610_OCOTP) += nvmem-vf610-ocotp.o diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig index 9ad50474cb77..8a38c514943a 100644 --- a/drivers/nvmem/layouts/Kconfig +++ b/drivers/nvmem/layouts/Kconfig @@ -20,4 +20,14 @@ config NVMEM_LAYOUT_ONIE_TLV If unsure, say N. +config NVMEM_LAYOUT_U_BOOT_ENV + bool "U-Boot environment variables support" + select CRC32 + help + U-Boot stores its setup as environment variables. This driver adds + support for verifying & exporting such data. It also exposes variables + as NVMEM cells so they can be referenced by other drivers. + + If unsure, say N. + endmenu diff --git a/drivers/nvmem/layouts/Makefile b/drivers/nvmem/layouts/Makefile index 2974bd7d33ed..4940c9db0665 100644 --- a/drivers/nvmem/layouts/Makefile +++ b/drivers/nvmem/layouts/Makefile @@ -5,3 +5,4 @@ obj-$(CONFIG_NVMEM_LAYOUT_SL28_VPD) += sl28vpd.o obj-$(CONFIG_NVMEM_LAYOUT_ONIE_TLV) += onie-tlv.o +obj-$(CONFIG_NVMEM_LAYOUT_U_BOOT_ENV) += u-boot-env.o diff --git a/drivers/nvmem/layouts/u-boot-env.c b/drivers/nvmem/layouts/u-boot-env.c new file mode 100644 index 000000000000..95c314553952 --- /dev/null +++ b/drivers/nvmem/layouts/u-boot-env.c @@ -0,0 +1,176 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2022 Rafał Miłecki + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +enum u_boot_env_format { + U_BOOT_FORMAT_SINGLE, + U_BOOT_FORMAT_REDUNDANT, + U_BOOT_FORMAT_BROADCOM, +}; + +struct u_boot_env_image_single { + __le32 crc32; + uint8_t data[]; +} __packed; + +struct u_boot_env_image_redundant { + __le32 crc32; + u8 mark; + uint8_t data[]; +} __packed; + +struct u_boot_env_image_broadcom { + __le32 magic; + __le32 len; + __le32 crc32; + uint8_t data[]; +} __packed; + +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) +{ + struct device_node *np; + char *data = buf + data_offset; + char *var, *value, *eq; + int err = 0; + + np = of_nvmem_layout_get_container(nvmem); + if (!np) + return -ENOENT; + + for (var = data; + var < data + data_len && *var; + var = value + strlen(value) + 1) { + struct nvmem_cell_info info = {}; + + eq = strchr(var, '='); + if (!eq) + break; + *eq = '\0'; + value = eq + 1; + + info.name = devm_kstrdup(dev, var, GFP_KERNEL); + if (!info.name) { + err = -ENOMEM; + break; + } + info.offset = data_offset + value - data; + info.bytes = strlen(value); + info.np = of_get_child_by_name(np, info.name); + + err = nvmem_add_one_cell(nvmem, &info); + if (err) { + dev_err(dev, "Failed to add \"%s\" cell: %d\n", info.name, err); + break; + } + } + + of_node_put(np); + + return err; +} + +static int u_boot_env_add_cells(struct device *dev, struct nvmem_device *nvmem, + struct nvmem_layout *layout) +{ + enum u_boot_env_format format; + size_t crc32_data_offset; + size_t crc32_data_len; + size_t crc32_offset; + size_t data_offset; + size_t data_len; + size_t dev_size; + uint32_t crc32; + uint32_t calc; + size_t bytes; + uint8_t *buf; + int err; + + format = (uintptr_t)nvmem_layout_get_match_data(nvmem, layout); + + dev_size = nvmem_dev_size(nvmem); + + buf = kcalloc(1, dev_size, GFP_KERNEL); + if (!buf) { + err = -ENOMEM; + goto err_out; + } + + bytes = nvmem_device_read(nvmem, 0, dev_size, buf); + if (bytes < 0 || bytes != dev_size) { + dev_err(dev, "Failed to read from NVMEM device: %zd\n", bytes); + goto err_kfree; + } + + switch (format) { + case U_BOOT_FORMAT_SINGLE: + crc32_offset = offsetof(struct u_boot_env_image_single, crc32); + crc32_data_offset = offsetof(struct u_boot_env_image_single, data); + data_offset = offsetof(struct u_boot_env_image_single, data); + break; + case U_BOOT_FORMAT_REDUNDANT: + crc32_offset = offsetof(struct u_boot_env_image_redundant, crc32); + crc32_data_offset = offsetof(struct u_boot_env_image_redundant, data); + data_offset = offsetof(struct u_boot_env_image_redundant, data); + break; + case U_BOOT_FORMAT_BROADCOM: + crc32_offset = offsetof(struct u_boot_env_image_broadcom, crc32); + crc32_data_offset = offsetof(struct u_boot_env_image_broadcom, data); + data_offset = offsetof(struct u_boot_env_image_broadcom, data); + break; + } + crc32 = le32_to_cpu(*(__le32 *)(buf + crc32_offset)); + crc32_data_len = dev_size - crc32_data_offset; + data_len = dev_size - data_offset; + + calc = crc32(~0, buf + crc32_data_offset, crc32_data_len) ^ ~0L; + if (calc != crc32) { + dev_err(dev, "Invalid calculated CRC32: 0x%08x (expected: 0x%08x)\n", calc, crc32); + err = -EINVAL; + goto err_kfree; + } + + buf[dev_size - 1] = '\0'; + err = u_boot_env_parse_data(dev, nvmem, buf, data_offset, data_len); + if (err) + dev_err(dev, "Failed to parse cells: %d\n", err); + +err_kfree: + kfree(buf); +err_out: + return err; +} + +static const struct of_device_id u_boot_env_of_match_table[] = { + { .compatible = "u-boot,env", .data = (void *)U_BOOT_FORMAT_SINGLE, }, + { .compatible = "u-boot,env-redundant-bool", .data = (void *)U_BOOT_FORMAT_REDUNDANT, }, + { .compatible = "u-boot,env-redundant-count", .data = (void *)U_BOOT_FORMAT_REDUNDANT, }, + { .compatible = "brcm,env", .data = (void *)U_BOOT_FORMAT_BROADCOM, }, + {}, +}; + +static struct nvmem_layout u_boot_env_layout = { + .name = "U-Boot environment variables layout", + .of_match_table = u_boot_env_of_match_table, + .add_cells = u_boot_env_add_cells, +}; + +static int __init u_boot_env_init(void) +{ + return nvmem_layout_register(&u_boot_env_layout); +} +subsys_initcall(u_boot_env_init); + +MODULE_AUTHOR("Rafał Miłecki"); +MODULE_LICENSE("GPL"); +MODULE_DEVICE_TABLE(of, u_boot_env_of_match_table); diff --git a/drivers/nvmem/u-boot-env.c b/drivers/nvmem/u-boot-env.c deleted file mode 100644 index 29b1d87a3c51..000000000000 --- a/drivers/nvmem/u-boot-env.c +++ /dev/null @@ -1,233 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Copyright (C) 2022 Rafał Miłecki - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -enum u_boot_env_format { - U_BOOT_FORMAT_SINGLE, - U_BOOT_FORMAT_REDUNDANT, - U_BOOT_FORMAT_BROADCOM, -}; - -struct u_boot_env { - struct device *dev; - enum u_boot_env_format format; - - struct mtd_info *mtd; - - /* Cells */ - struct nvmem_cell_info *cells; - int ncells; -}; - -struct u_boot_env_image_single { - __le32 crc32; - uint8_t data[]; -} __packed; - -struct u_boot_env_image_redundant { - __le32 crc32; - u8 mark; - uint8_t data[]; -} __packed; - -struct u_boot_env_image_broadcom { - __le32 magic; - __le32 len; - __le32 crc32; - uint8_t data[0]; -} __packed; - -static int u_boot_env_read(void *context, unsigned int offset, void *val, - size_t bytes) -{ - struct u_boot_env *priv = context; - struct device *dev = priv->dev; - size_t bytes_read; - int err; - - err = mtd_read(priv->mtd, offset, bytes, &bytes_read, val); - if (err && !mtd_is_bitflip(err)) { - dev_err(dev, "Failed to read from mtd: %d\n", err); - return err; - } - - if (bytes_read != bytes) { - dev_err(dev, "Failed to read %zu bytes\n", bytes); - return -EIO; - } - - 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) -{ - struct device *dev = priv->dev; - char *data = buf + data_offset; - char *var, *value, *eq; - int idx; - - priv->ncells = 0; - for (var = data; var < data + data_len && *var; var += strlen(var) + 1) - priv->ncells++; - - priv->cells = devm_kcalloc(dev, priv->ncells, sizeof(*priv->cells), GFP_KERNEL); - if (!priv->cells) - return -ENOMEM; - - for (var = data, idx = 0; - var < data + data_len && *var; - var = value + strlen(value) + 1, idx++) { - eq = strchr(var, '='); - if (!eq) - break; - *eq = '\0'; - value = eq + 1; - - priv->cells[idx].name = devm_kstrdup(dev, var, GFP_KERNEL); - if (!priv->cells[idx].name) - return -ENOMEM; - 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 (WARN_ON(idx != priv->ncells)) - priv->ncells = idx; - - return 0; -} - -static int u_boot_env_parse(struct u_boot_env *priv) -{ - struct device *dev = priv->dev; - size_t crc32_data_offset; - size_t crc32_data_len; - size_t crc32_offset; - size_t data_offset; - size_t data_len; - uint32_t crc32; - uint32_t calc; - size_t bytes; - uint8_t *buf; - int err; - - buf = kcalloc(1, priv->mtd->size, GFP_KERNEL); - if (!buf) { - err = -ENOMEM; - goto err_out; - } - - err = mtd_read(priv->mtd, 0, priv->mtd->size, &bytes, buf); - if ((err && !mtd_is_bitflip(err)) || bytes != priv->mtd->size) { - dev_err(dev, "Failed to read from mtd: %d\n", err); - goto err_kfree; - } - - switch (priv->format) { - case U_BOOT_FORMAT_SINGLE: - crc32_offset = offsetof(struct u_boot_env_image_single, crc32); - crc32_data_offset = offsetof(struct u_boot_env_image_single, data); - data_offset = offsetof(struct u_boot_env_image_single, data); - break; - case U_BOOT_FORMAT_REDUNDANT: - crc32_offset = offsetof(struct u_boot_env_image_redundant, crc32); - crc32_data_offset = offsetof(struct u_boot_env_image_redundant, data); - data_offset = offsetof(struct u_boot_env_image_redundant, data); - break; - case U_BOOT_FORMAT_BROADCOM: - crc32_offset = offsetof(struct u_boot_env_image_broadcom, crc32); - crc32_data_offset = offsetof(struct u_boot_env_image_broadcom, data); - data_offset = offsetof(struct u_boot_env_image_broadcom, data); - break; - } - crc32 = le32_to_cpu(*(__le32 *)(buf + crc32_offset)); - crc32_data_len = priv->mtd->size - crc32_data_offset; - data_len = priv->mtd->size - data_offset; - - calc = crc32(~0, buf + crc32_data_offset, crc32_data_len) ^ ~0L; - if (calc != crc32) { - dev_err(dev, "Invalid calculated CRC32: 0x%08x (expected: 0x%08x)\n", calc, crc32); - err = -EINVAL; - goto err_kfree; - } - - buf[priv->mtd->size - 1] = '\0'; - err = u_boot_env_add_cells(priv, buf, data_offset, data_len); - if (err) - dev_err(dev, "Failed to add cells: %d\n", err); - -err_kfree: - kfree(buf); -err_out: - return err; -} - -static int u_boot_env_probe(struct platform_device *pdev) -{ - struct nvmem_config config = { - .name = "u-boot-env", - .reg_read = u_boot_env_read, - }; - struct device *dev = &pdev->dev; - struct device_node *np = dev->of_node; - struct u_boot_env *priv; - int err; - - priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); - if (!priv) - return -ENOMEM; - priv->dev = dev; - - priv->format = (uintptr_t)of_device_get_match_data(dev); - - priv->mtd = of_get_mtd_device_by_node(np); - if (IS_ERR(priv->mtd)) { - dev_err_probe(dev, PTR_ERR(priv->mtd), "Failed to get %pOF MTD\n", np); - return PTR_ERR(priv->mtd); - } - - err = u_boot_env_parse(priv); - if (err) - return err; - - config.dev = dev; - config.cells = priv->cells; - config.ncells = priv->ncells; - config.priv = priv; - config.size = priv->mtd->size; - - return PTR_ERR_OR_ZERO(devm_nvmem_register(dev, &config)); -} - -static const struct of_device_id u_boot_env_of_match_table[] = { - { .compatible = "u-boot,env", .data = (void *)U_BOOT_FORMAT_SINGLE, }, - { .compatible = "u-boot,env-redundant-bool", .data = (void *)U_BOOT_FORMAT_REDUNDANT, }, - { .compatible = "u-boot,env-redundant-count", .data = (void *)U_BOOT_FORMAT_REDUNDANT, }, - { .compatible = "brcm,env", .data = (void *)U_BOOT_FORMAT_BROADCOM, }, - {}, -}; - -static struct platform_driver u_boot_env_driver = { - .probe = u_boot_env_probe, - .driver = { - .name = "u_boot_env", - .of_match_table = u_boot_env_of_match_table, - }, -}; -module_platform_driver(u_boot_env_driver); - -MODULE_AUTHOR("Rafał Miłecki"); -MODULE_LICENSE("GPL"); -MODULE_DEVICE_TABLE(of, u_boot_env_of_match_table); From patchwork Tue Jan 10 10:54:24 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: 13094966 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 9E9B9C54EBC for ; Tue, 10 Jan 2023 10:58:58 +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=0dU9vv25c4qy18p08IO2ceI4e/7oD/agzWjIxIOYOH4=; b=dwLcvy+nTEmiKc SXC5mj/uXxXCH+y48cD81xWDOgoL59WWWIo+Yaq9/o9+a2boHoQVIRqD3woksguoVYETQGUPnBQjb FA5k2hL9kdX8E5J7VaBcj+W2ls8f3dy3G/dgwUZUCtDyCVHD5WvJjmUWtE+rM0rtTvR7l1/gqsT8M e1288o6RxPS3OuQFO6pPvGQprTudrgnOhid27immY61yTPCrqT1lOXj9N5G/i5UMhoMa3iPgAhp9q 7zmy6fqNLphb6mmUfd6/saZmKwXmiNmU599U0LHKbhoC7SazemSCdH6/GyRkKuCtnzDCj3WrgV3kI uKWnpheq5BPsry13ruow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFCKC-006Tqo-3a; Tue, 10 Jan 2023 10:57:48 +0000 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFCHD-006Sdb-EO for linux-arm-kernel@lists.infradead.org; Tue, 10 Jan 2023 10:54:46 +0000 Received: by mail-ej1-x630.google.com with SMTP id fy8so27448297ejc.13 for ; Tue, 10 Jan 2023 02:54:42 -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=r5xJKON5Ta6zI9VZAQEfIhcRQtQRxrWmROsI4bJtDyw=; b=fHEP579INgzePeFpjuOCrhgw+APWLrqlZj78kQe5xeeOLiJcbbl+2QOudZjLBFH5X2 ZfjqjvOG1vWV3FuyP3G4YALYeMDVqcv0cQpD20pxnlNn351Nonkw/G6W0VUmZPK7391l nYo4xBECTFtAZdm4prqhWZVXmDTrSmf/KT4zmAWWkVQ+tKZRLZd7fwZH2G2DUXPCs0tG zqldBkFl8bUAnUnapAXsndHTIgIBALFCMREUsCuD1OkqudL65NGPCJJzYSBHetA+fKeT DvBwoss03FzrBF/MARRAoP6jwkm9Vwcbk4IXPiaJTs6Wp9qHwhw6pjoj2eImKEjYRYLz SW/w== 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=r5xJKON5Ta6zI9VZAQEfIhcRQtQRxrWmROsI4bJtDyw=; b=BmAWkIRX8eQgOXDPpsHOHbE7b/JxxTumRlwC9Ig4epA5OK4U+YjWxUe+0N1cA4exwp fyLsAM0JSWbSztcGIl+Urfft09DIG9gaHX+HLJBNOMIiIG52i1wlvd6efpPBLGuXYkcD 8NwDlsxih0OUrMAWsW72XA2Qky86Yq/GPPqxLXbwGvxhO/lP3HC4K4/6qIpByjG2cZ8v mRtVLCeprooGPipWD7qP0H/Gde7OfPBlAaqLPitUPi51LtuWIUtkKmmBXmGFM6amJbMi EOyLSo7Ls7395kfEIgMgsaM28/f5xlDLUUaGQBgwCA3L6NCdo3+hiFzReRfae/GO7VkV d7Zg== X-Gm-Message-State: AFqh2kpT1RNOhXnfLWR89dpEn4N+83kW5oV0fao/bP5iRwyEmHcAo6UW ipcIARUI6MeUK45qlprFhYk= X-Google-Smtp-Source: AMrXdXsDivvK1wuFjL3hwWcq9UhWxr3hw428dQsN7UkIH5bPtEZNJm+US7BfJfiW2PQV1vpAs6ue3g== X-Received: by 2002:a17:907:d093:b0:7c0:cd95:bbb7 with SMTP id vc19-20020a170907d09300b007c0cd95bbb7mr54046916ejc.77.1673348081568; Tue, 10 Jan 2023 02:54:41 -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 s1-20020aa7c541000000b00495c3573b36sm4818199edr.32.2023.01.10.02.54.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 02:54:41 -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 5/6] dt-bindings: nvmem: u-boot,env: add MAC's #nvmem-cell-cells Date: Tue, 10 Jan 2023 11:54:24 +0100 Message-Id: <20230110105425.13188-5-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110105425.13188-1-zajec5@gmail.com> References: <20230110105425.13188-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230110_025443_570724_B15CE6D1 X-CRM114-Status: GOOD ( 13.27 ) 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's "ethaddr" environment variable is very often used to store *base* MAC address. It's used as a base for calculating addresses for multiple interfaces. It's done by adding proper values. Actual offsets are picked by manufacturers and vary across devices. Signed-off-by: Rafał Miłecki --- .../devicetree/bindings/nvmem/layouts/u-boot,env.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml b/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml index fb273b174fe7..dbff702f2e5d 100644 --- a/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml +++ b/Documentation/devicetree/bindings/nvmem/layouts/u-boot,env.yaml @@ -45,7 +45,11 @@ properties: ethaddr: type: object - description: Ethernet interface's MAC address + description: Ethernet interfaces base MAC address. + properties: + "#nvmem-cell-cells": + description: The first argument is a MAC address offset. + const: 1 additionalProperties: false @@ -69,6 +73,7 @@ examples: compatible = "u-boot,env"; mac: ethaddr { + #nvmem-cell-cells = <1>; }; }; }; From patchwork Tue Jan 10 10:54:25 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: 13094967 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 0379EC46467 for ; Tue, 10 Jan 2023 10:59:21 +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=V6KtsdYIVuKUpLWnjcn9RHnNMDCGLy+UshvBgC8ojWY=; b=LkEE9NKf9yYnKr rFt8CFGWWEX0CcpsbTNXkufNpIreSm8d56Gjl74lHkem0rp/vutbTcpikZkMJMsU4yoKLRrSaasCo 6axAlrQu5019cwDEDKvolxLN76Q146GovmGjAVjdKaSoLyKu5/99vod2NGsMdlk+vVHs9l+sVl+VT SLRgh1ore/vbcm0Q7/f6cQl40nZKhQpsbsGm/0VUWlD3U4mofhgcefebf0FZmJNweFo9pCb0IA0kq Sk46d0L9XzFVgwJlwYPouXyZwPhwsDmue0FATm3eh3Y/39G5YF7dT3iEVftliS6Yhqq3/B+oVU9gZ mj3q5gxWHChcOFnp5jnA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFCKf-006U3D-PF; Tue, 10 Jan 2023 10:58:18 +0000 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFCHG-006Sf0-9T for linux-arm-kernel@lists.infradead.org; Tue, 10 Jan 2023 10:54:49 +0000 Received: by mail-ej1-x633.google.com with SMTP id u9so27603662ejo.0 for ; Tue, 10 Jan 2023 02:54:45 -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=wAqYvgRzLQ4rzA87QLNuurx0Mvg1Ygp2KEVQbcFxer4=; b=SJ7SFb8lSmxhm2NTUJn6edKXr2E6ocnaCm828IPBngsZmWq1fx4++PuFndDgKs7qoL Cyp2n6vHrRXFGBeDGFTSzfitsjvkIihjc0zpjySshruHuZQGaE4aktnpf/fPhTopvdjx qoJLiT5pX5fxUblFYSWoItSQwavPoqv+8cNMN4/Z7hrRk+D8Uk+rTTfYgKqjTGFzrrJd 04KdQuFJqsa+VHF9irSvMGFn01TYJf06NLJZbGHj5wRcOQcvZ61+Fvk0gG02XTsjvuLx upYWU7na/qKc2fHeox3X0iUXzhxEjK1xfCpQZ9pnw1Y+ZXeD8fre8eiRWY4QJIAjyZ+O N+gg== 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=wAqYvgRzLQ4rzA87QLNuurx0Mvg1Ygp2KEVQbcFxer4=; b=AghtvqyVgascrb9SFn7rsj3U39G37OJl8xA0BFTQDSdOEj9yyplB+QPMS25ivn96/5 Dgv86XujFCKCaOOJLBMtphOonU56wtACbWSoTDaJ/KZBNEwzSS69UilSEd4ouH/qUXVc 7l43NdYQfwWmhMBQ63xQ/zwuRWUfaglunjRpRKGL3oc/f8v893eM9SPO6+0gdUMaFSRV fj+hkye0fNgNdkjUtPozs1EF+FZ1JFN/9UOLxIJQe9UWVjMBwUStA4Db0L8P/6RpZc/T IOSAFRe1/Md72rG9CPOkuYNchK3qRlI+Lheqh6NG3lkn8aj44bhJtzG4mEdcoLNi8Bjr lxQQ== X-Gm-Message-State: AFqh2kpmAa5EJ1QqKchPO6I4UwFykhrPbtXBOo3OYdhumUs067ch5rKj zcrPheT9haJbxJuVZtpopEU= X-Google-Smtp-Source: AMrXdXur9POe208kdUVnqB2kY9qDlv0+hMyxhP8CXXFsMHUuSjJmZ80rZEFvMyJE2kSVSIcX8Ezf1g== X-Received: by 2002:a17:906:5202:b0:7c1:4a3:10b6 with SMTP id g2-20020a170906520200b007c104a310b6mr56805461ejm.53.1673348083920; Tue, 10 Jan 2023 02:54:43 -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 s1-20020aa7c541000000b00495c3573b36sm4818199edr.32.2023.01.10.02.54.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 02:54:43 -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 6/6] nvmem: u-boot-env: post process "ethaddr" env variable Date: Tue, 10 Jan 2023 11:54:25 +0100 Message-Id: <20230110105425.13188-6-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110105425.13188-1-zajec5@gmail.com> References: <20230110105425.13188-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230110_025446_406098_89E6623D X-CRM114-Status: GOOD ( 16.22 ) 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 | 24 ++++++++++++++++++++++++ 2 files changed, 25 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..63baeb18bd56 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,26 @@ 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); + + 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 +89,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) {