From patchwork Wed Jan 11 07:30:57 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: 13096154 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 A4470C54EBE for ; Wed, 11 Jan 2023 07:32: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: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=FQPvVZmuiElWtQgRmQBW9Vs7ob6PzKdFmGCnyqTbmK4=; b=Kodelfdn8yr4gL 8XMiW8+QY2EEP1oM5ENWj52s3OmjGjRLANvqU9/3DKmtCplzwh27EneHWvojC1V6aAi9D6Jf7HXiM wmbEBndbdP53oUlZHH5N2kYPveuNdKW+xeM61d5dRcEPoPRHIRA7pAFw4MGQNew+q2CrS/E2KiYHq LfeG1RSbCsnkMvKfia1Skr6xd4V8KEaUEi2qaGWT/AGuZL4HaO07OZZBFpULnXA0Rhttb03FVx5Y0 5b7UExddjLaRQt1rtLbDPB6Bn3HhuqWCbAA9oiYGXwo60tzdi0tvIoAOq6fZFVqjOdngddvlvKr6H /Va9w01JACJXFmVuE2og==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFVZx-00A34Z-7t; Wed, 11 Jan 2023 07:31:21 +0000 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFVZs-00A32O-9I for linux-arm-kernel@lists.infradead.org; Wed, 11 Jan 2023 07:31:17 +0000 Received: by mail-ed1-x532.google.com with SMTP id s5so21050421edc.12 for ; Tue, 10 Jan 2023 23:31:13 -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=8DBHbw8SRKxIaaEznlgvFtV6o4AQh3C5twMwXmVKndw=; b=LKZl3Yl1yaH9pHPcrGazQYIO/+lPuf0TVx5YL6feozCkqA0Y3rsXDrPv7+ShBohCGE mav3xeeCzvYfgs7cVqj2k8cDb4fur4tYELCuJfHlTGMbAFF0LCN14a9bLzyiMCsef1WH wl7/sxpMWWGKhzMEV2FjqMmAMatKIqDjV8E0Vu9Mx6XHPOglF4ZP83Jt828aQfXaGeDe 5742PSda/syaQ0PJFDoHuNopxeADoOKLpitq3OAuD84Q8VnMeVrVYn5mUaJsQi0r8vH3 VNnsVGX3qIbYEuYlTKe3T3xALuE8WUuSFOe6BbP58ExuaMQAAxTpzLNJ+gQwRZLu7qMT UQPw== 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=8DBHbw8SRKxIaaEznlgvFtV6o4AQh3C5twMwXmVKndw=; b=z41zDs86SU+V10dyeIFqTpq3E5TGBJRPyvseVSEEUxBtKIRBvzW57+xQIznWwnbK4O gjYVwwuBuZ1El2NNBW0wW7N5Vm0HDLoueLRkgL1NVaggeGzbpp2YMGPHWnANQrmu6VAT JS0u2+lrfUM5EAMDp42ZZjZcqOp2YUrzYAIN9FkXMRq1xQ3hwzdhVuGQB6XZH0TFQM4c zqL5FNZBtKCYHq/BizxFVCZe9mFjkWoFp8G2P4QlY929vvHmrpp4pD7GZoLKVndJwyMQ gcXbYFlFwJnX2zqtlAzaKUy5WFSfxz4XpEgOUrNn++O7Peec94K+9uWrrapAG4Xodp8+ KS0A== X-Gm-Message-State: AFqh2kqPmA1hjJ0XUDG8yVj84X/U27a2a3Zz6wjoPqNX4uYgf3PbedPs fLheIQHcWI70Ci6NCa/tbCI= X-Google-Smtp-Source: AMrXdXsw6vb7Yhx0xIv6eleitRwomvZGl2Ys/JovDBbL5+Orm3lT8EcRZCM5TMZQiwbRXUkftpCrNg== X-Received: by 2002:a05:6402:456:b0:484:8b49:e117 with SMTP id p22-20020a056402045600b004848b49e117mr50242343edw.3.1673422271823; Tue, 10 Jan 2023 23:31:11 -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 ed6-20020a056402294600b00499e5659988sm593193edb.68.2023.01.10.23.31.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 23:31:11 -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 V2 1/6] nvmem: core: add nvmem_dev_size() helper Date: Wed, 11 Jan 2023 08:30:57 +0100 Message-Id: <20230111073102.8147-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_233116_361693_0396FE56 X-CRM114-Status: GOOD ( 12.21 ) 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 --- V2: Drop "const" from "const size_t" --- 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 d3be50ed2d0b..32f7fb81375a 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. + */ +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..c3005ab6cc4f 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); +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 Wed Jan 11 07:30:58 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: 13096155 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 743CBC46467 for ; Wed, 11 Jan 2023 07:32: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: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=WHEdTYrKlJL3Qy5x1uSeaN8GaKtGGGDZ7HR6sVtXR2A=; b=zw2LI7DTujo0cg mJzjMBqyDREjNMFWjQiEz987/EudMufKXVBoEV8njUgTNDHY15evXfhi1bAdXFMxm718E7rlD1VkA jxaOS4I+p0eAk66TIuApFlTKvlyGv3OsqHFla+pvANN9mjxQiOgelePV4uxIovVns7/tULlhee/4V FHDEPgFfRJr8tGRYu45n6wQPiYLsbdAAkCzHtUTkjUhW6eRdTJS26ymFDaEwlWUn+4GON6NuJdPuB d4aRGAdTaomap0aoB7r4zDi0jRw9VR6bEIemjOn5ORUS8HlCYZcI4u3AdbaN5RdVVhoQkQzyB0opt Pml7fiPf3Gmj+x2ygWhQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFVa5-00A37T-L5; Wed, 11 Jan 2023 07:31:29 +0000 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFVZt-00A32U-0a for linux-arm-kernel@lists.infradead.org; Wed, 11 Jan 2023 07:31:18 +0000 Received: by mail-ed1-x535.google.com with SMTP id i9so21101091edj.4 for ; Tue, 10 Jan 2023 23:31:14 -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=J1GVfniV/eqw+M+Qk9AYkx0B8mMbL6xPt6dFX6gFZ+c=; b=XBfqfp86TfTbEgHEWu+4+2kc4dqReBWMlZl0Ef+sQRR0RfM6EcNuxKsPDJf13I/t3n DoGQYHvqceIMbIPX6AxAaRvSY6Ukwjj5XHHVB+ISemsKWPcjRcES5waTC2ffzcXnm3Mp Yu4AkpOgzp5BDAAMPjZbguApaW2oY+OpbPT+8ojzlQ7tl8czYIapSvuiivJl0HOia/oa LSbDJ4XmHb1ZbR+R9+71/y+pSSlH9volCYs8fC35fBvUH/ZXiYh2XvAf+aySOzQK3QK+ 9SYJ/XwOXiwnzNO6ijb/z53paAt76+30o+n/30VosqWf8jvqfDjlwe/WEa3gu9cqZdLE zvdQ== 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=J1GVfniV/eqw+M+Qk9AYkx0B8mMbL6xPt6dFX6gFZ+c=; b=h8jdau7C1mnAyNuWPVZ7EeYPMXkhhAAa1Y2pJ9aA/w4ikGvnb1/kFFH5pFy/0mSRgR kFSHk28s4Yjn6KSo+0ULqQH/GySyhrTqL9Q7UAyXbM/V199LYKHdzpp89bdKigA0sIJA nx7CZHUpaT+fh7A3T3o5J60ikixiG9M5caFtgqGlBOHxF4pzsPtQ/+RfhenbFpvgZ8KX n7SnzYqa+Gmtm7LwIVo9EduR/3XUaZ72KLDngqixDePni013BXi4S1/nQoWJbydTuqrV 4lH2UY0LmJ5I04bYX1E3fqtXsdJJCSSPezq/0kfjjax2duyyg840R56VLrq4H7nTaQ6a tH1A== X-Gm-Message-State: AFqh2koUQ1yp/g2CAbGnLHf+q93cDvvMwPzHLbI+BhqJQ7qeJo7VREtL mOLqWoOz5iuhOzCgt44RE5I= X-Google-Smtp-Source: AMrXdXs7mPDKQ/zeiRPwPYMkxb5RmoO5NTdfRKoVFicG354P9OUG//iwPe3sU69d8nCWM30dQZPP3A== X-Received: by 2002:aa7:db47:0:b0:46d:b89a:de1e with SMTP id n7-20020aa7db47000000b0046db89ade1emr58014514edt.1.1673422273705; Tue, 10 Jan 2023 23:31:13 -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 ed6-20020a056402294600b00499e5659988sm593193edb.68.2023.01.10.23.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 23:31:13 -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 V2 2/6] nvmem: core: allow .read_post_process() callbacks to adjust buffer Date: Wed, 11 Jan 2023 08:30:58 +0100 Message-Id: <20230111073102.8147-2-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230111073102.8147-1-zajec5@gmail.com> References: <20230111073102.8147-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_233117_085447_2154A0C0 X-CRM114-Status: GOOD ( 20.74 ) 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 may require resizing available buffer. 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 --- V2: Pass buffer pointer to allow krealloc() if needed --- drivers/nvmem/core.c | 27 ++++++++++++++++----------- drivers/nvmem/imx-ocotp.c | 8 ++++---- drivers/nvmem/layouts/onie-tlv.c | 5 ++--- drivers/nvmem/layouts/sl28vpd.c | 10 +++++----- include/linux/nvmem-provider.h | 5 ++--- 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 32f7fb81375a..2c9e4ac8a772 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1539,29 +1539,26 @@ static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void static int __nvmem_cell_read(struct nvmem_device *nvmem, struct nvmem_cell_entry *cell, - void *buf, size_t *len, const char *id, int index) + void **buf, size_t *len, const char *id, int index) { int rc; - rc = nvmem_reg_read(nvmem, cell->offset, buf, cell->bytes); + rc = nvmem_reg_read(nvmem, cell->offset, *buf, *len); if (rc) return rc; /* shift bits in-place */ if (cell->bit_offset || cell->nbits) - nvmem_shift_read_buffer_in_place(cell, buf); + nvmem_shift_read_buffer_in_place(cell, *buf); if (cell->read_post_process) { rc = cell->read_post_process(cell->priv, id, index, - cell->offset, buf, cell->bytes); + cell->offset, buf, len); if (rc) return rc; } - if (len) - *len = cell->bytes; - return 0; } @@ -1578,22 +1575,26 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem, void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len) { struct nvmem_device *nvmem = cell->entry->nvmem; - u8 *buf; + size_t bytes = cell->entry->bytes; + void *buf; int rc; if (!nvmem) return ERR_PTR(-EINVAL); - buf = kzalloc(cell->entry->bytes, GFP_KERNEL); + buf = kzalloc(bytes, GFP_KERNEL); if (!buf) return ERR_PTR(-ENOMEM); - rc = __nvmem_cell_read(nvmem, cell->entry, buf, len, cell->id, cell->index); + rc = __nvmem_cell_read(nvmem, cell->entry, &buf, &bytes, cell->id, cell->index); if (rc) { kfree(buf); return ERR_PTR(rc); } + if (len) + *len = bytes; + return buf; } EXPORT_SYMBOL_GPL(nvmem_cell_read); @@ -1905,11 +1906,15 @@ ssize_t nvmem_device_cell_read(struct nvmem_device *nvmem, if (!nvmem) return -EINVAL; + /* Cells with read_post_process hook may realloc buffer we can't allow here */ + if (info->read_post_process) + return -EINVAL; + rc = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, &cell); if (rc) return rc; - rc = __nvmem_cell_read(nvmem, &cell, buf, &len, NULL, 0); + rc = __nvmem_cell_read(nvmem, &cell, &buf, &cell.bytes, NULL, 0); if (rc) return rc; diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index ac0edb6398f1..e17500bc0acc 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; + 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..f26bcce2a44d 100644 --- a/drivers/nvmem/layouts/onie-tlv.c +++ b/drivers/nvmem/layouts/onie-tlv.c @@ -75,10 +75,9 @@ 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) + unsigned int offset, void **buf, size_t *bytes) { - eth_addr_add(buf, index); + eth_addr_add(*buf, index); return 0; } diff --git a/drivers/nvmem/layouts/sl28vpd.c b/drivers/nvmem/layouts/sl28vpd.c index a36800f201a3..869cb513d79a 100644 --- a/drivers/nvmem/layouts/sl28vpd.c +++ b/drivers/nvmem/layouts/sl28vpd.c @@ -22,19 +22,19 @@ struct sl28vpd_v1 { } __packed; static int sl28vpd_mac_address_pp(void *priv, const char *id, int index, - unsigned int offset, void *buf, - size_t bytes) + unsigned int offset, void **buf, + size_t *bytes) { - if (bytes != ETH_ALEN) + if (*bytes != ETH_ALEN) return -EINVAL; if (index < 0) return -EINVAL; - if (!is_valid_ether_addr(buf)) + if (!is_valid_ether_addr(*buf)) return -EINVAL; - eth_addr_add(buf, index); + eth_addr_add(*buf, index); return 0; } diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 0cf9f9490514..e70766013f97 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -19,9 +19,8 @@ typedef int (*nvmem_reg_read_t)(void *priv, unsigned int offset, typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset, void *val, size_t bytes); /* 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); +typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, int index, unsigned int offset, + void **buf, size_t *bytes); enum nvmem_type { NVMEM_TYPE_UNKNOWN = 0, From patchwork Wed Jan 11 07:30:59 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: 13096156 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 2ECC8C46467 for ; Wed, 11 Jan 2023 07:32:34 +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=Vz02ad04zzt09K YFjtNSZ2/m6w8pb2bBo3OZehRpsUkH8sIw1fzuxgTU0q+md5AdPXgvfqHf3XG3cTZMnTUc9646/6M jQA7d7QoOqUjCpXOaitdg3oQnnzhoArVN5/NgVqn1rvy1yw4LDH0j7VSPIJ+AYbedUuCuymMGFcnY xWPxj/Bj0Fiyq42FEAb62pHrmrwrbUACrjwPaMjq8RpKnwYHFhrPiMS/0Apv2R/F3vnrOgcZke95O GnI2oecynoc7Saj3szRMr52jmcv44QbeoyfcBmBvtYTOXEICJ1XlacYoY4cGBQYeBj/UI6u0R+/27 J3FflZAFaIfEOSnwNg4Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFVaE-00A3AM-41; Wed, 11 Jan 2023 07:31:38 +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 1pFVZu-00A331-Ib for linux-arm-kernel@lists.infradead.org; Wed, 11 Jan 2023 07:31:20 +0000 Received: by mail-ed1-x52d.google.com with SMTP id 18so21067567edw.7 for ; Tue, 10 Jan 2023 23:31:17 -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=AdHiFpQdoA09CZEj5w953fkCedR6xXBwi/v2pnfJIvJChAWTHwFHisWOe4bheUZDRA A8enp6oPE/6Muccn+lVT364GP9a1S9tZ0xS3KOH8kMNabGN3kY0+cAxueomtqqaBUkXU 3BDy1nuUAK4PLPLkKFmc9zgxRGVv2kLmceDzKhJghJUhnBg6sqkrW+lfFwRhAwJ2mxbG YtbmDPIWuVjWLU1zzCHSemztcPOSd4IwR93eb9ulpwv3tBtJGceGcSSGtIrlv4VTK4ms JptkRFpb31kyO1B5urcjh+twOef07Rj5em4haoU1WtaorRxPBVFqLLL5hSqbosCxdCw8 /wdA== 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=63PBtFtiGQI+bc/fVN2SOY4OpKGOdwPXwBvj0JtD5O/5IX2zx9lUvh0X/A1YNNvKlo iSh/UZnBaxcd34w6DZSdC/Vc46ntG3IyTtrf9gWfLVTOm2Hq4JRObaT+CqY5NmTVZalV vC/o6gayjfXsqxJ8ulE+kL6fIC0MBllCwDPQnxojm+IDuVHBiiQLfHhBlC6oOnq2rI9W Z0t7+YXv8sflHnYTXr9lrO3BJ1EiWIhDn9kKWQmBoPJTie0rpojRwZXsNmngdoqp3zbJ 9mLk54miGiCgaX74W1cpFmkfccZ8SLezhlNO0lBsaC4ybXQwIxRb0z3gPuQpAk+azB7N s/pA== X-Gm-Message-State: AFqh2krtcFwXEyMhb0aBvu/11oF/ouaH8Tjr8UXfNWhO6cROd4LHiK7S q8CfY71lEZ8wehhAlmYo3XA= X-Google-Smtp-Source: AMrXdXvXcOBuq4tt32IRxlFPwJkena6RpsWqDJWjTvn1AZibTtum4mml/kSn4pbl6DxqtXfDduQ9hQ== X-Received: by 2002:aa7:d752:0:b0:499:bcfc:f47b with SMTP id a18-20020aa7d752000000b00499bcfcf47bmr7436081eds.16.1673422276146; Tue, 10 Jan 2023 23:31:16 -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 ed6-20020a056402294600b00499e5659988sm593193edb.68.2023.01.10.23.31.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 23:31:15 -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 V2 3/6] dt-bindings: nvmem: convert U-Boot env vars to NVMEM layout Date: Wed, 11 Jan 2023 08:30:59 +0100 Message-Id: <20230111073102.8147-3-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230111073102.8147-1-zajec5@gmail.com> References: <20230111073102.8147-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_233118_633376_79E40167 X-CRM114-Status: GOOD ( 16.16 ) 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 Reviewed-by: Rob Herring --- .../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 Wed Jan 11 07:31:00 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: 13096157 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 3346AC5479D for ; Wed, 11 Jan 2023 07:32:48 +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=EXrFSipmDYEfRi wASrOOeLXrPJbTmQ6riVoDR5bWwzFA7y6eXkFsVWy6F11CyPteaJRiVXK1Ea3HD49AgBEIUVkpeAK pjg1qg1JuntuSkFmJDooCN621Ww5ndnpkg74Eki05mUvNP29Qf4di+RUckRhQUnTFp2uYtft6auwz nTdwp3G90Q1H5KNOWO8SsL/ge34gFjvMRwPfvC+R/ZUPvurR2U+/Z+I4wL3Aog5lIRjy75tw+5oN6 086VPGzAnKlHrEL1KG/pUvuAAhElQcYPA9DWOop1AF+0/L1qpnmuyoS1clmBVJoqK9QJk3fvvaZQJ u2h8msGfM9Q6m5IKHH+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFVaN-00A3Ee-Ix; Wed, 11 Jan 2023 07:31:47 +0000 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFVZv-00A32U-Cj for linux-arm-kernel@lists.infradead.org; Wed, 11 Jan 2023 07:31:21 +0000 Received: by mail-ed1-x535.google.com with SMTP id i9so21101310edj.4 for ; Tue, 10 Jan 2023 23:31:19 -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=oVf3RRoSlbr8Cd0ABVNjtfIwmsZ2EErGn4MG6Ucw4xuj1MCSuT3sZVpKeBD6nmnu+y IIra5RZNQD/VCJQQfd6kRCqxzwYM/AilfznRTHCzS5wFUuWiYM7otaKPKdeqjRGXfdEW 1aEF2Z/locbkDpwmgMrS7bOWug/VKcZTbNHKSHR7XPVy+hWSo0dRylUPR/1MOPI3PEwB A7mmjTdVPS17RKTmPbcwdMmwRqa4wb0exfgIl7L8m1UdccMoi5Z5N096tII3/HNA4ig0 oSSjK13tQCR0DlKPe/mxMYUz+j8lUA7gq6ACIv3f9ItfOI6o6E5t0ijByOdLHkr0iWbt AATQ== 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=r6PGVxFhbNyqjfsNny5eebrpvShqqKYDgK4FyriXh3cM8hwzAKxumGMYuAoINiq4Pb YYsii80ja4iCGWPPU1fBnE+NYPSkLzJjt7kbxp0Z9Te/3M0C9Ld0rwP0tmge9rq+Hl+N 1AVlSYeeftMsELZsxh+CS7IobDHqtl789jMENCE1n6W/Rae4xv9TWAelEG48wtYDQSso OPlXZLkOYQ7oyQ4piAyiqJWCT/yQljiF1QPu+wHLCzJXeTX0LJdZtMQvR1QmQScZO1Kv PFT8BYsJJgH1GRkhohOUY8/vu4A5ZQGdHNLtl03NrqZQ0PhvNBR8iHmLpMxuteNAPTti 3BNg== X-Gm-Message-State: AFqh2ko1a9smdRv8ViprHvqhRXVz9M2SHxz3lS4vRNvrJe1jUu2wZyPr Z6knlz2fFFJBghyunZrHpUs= X-Google-Smtp-Source: AMrXdXuGmRbZvnVQ8DhlzsbiHp+060l1H1tyd5DOMLprVxRlY9bukgFPmLX8RKVkQogijjTmYogOTQ== X-Received: by 2002:a05:6402:3212:b0:499:8849:5fb0 with SMTP id g18-20020a056402321200b0049988495fb0mr13335791eda.30.1673422278763; Tue, 10 Jan 2023 23:31:18 -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 ed6-20020a056402294600b00499e5659988sm593193edb.68.2023.01.10.23.31.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 23:31:18 -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 V2 4/6] nvmem: u-boot-env: convert to layout driver Date: Wed, 11 Jan 2023 08:31:00 +0100 Message-Id: <20230111073102.8147-4-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230111073102.8147-1-zajec5@gmail.com> References: <20230111073102.8147-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_233119_522577_956169C5 X-CRM114-Status: GOOD ( 33.58 ) 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 Wed Jan 11 07:31:01 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: 13096158 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 57629C5479D for ; Wed, 11 Jan 2023 07:32: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=0dU9vv25c4qy18p08IO2ceI4e/7oD/agzWjIxIOYOH4=; b=ympaWZnkxN55Fm p4oSYKd4SOuRxRqO61GZT+GaRZqEBbucpYAlqe0vrYtXUkdTUI8hALiPGSb2GZ9vyt/QhCBATmq0t Va2cq3bU55wU1aUMP6qs5aaoMemHuGN5b7tWMjahmXpfNw4Lt0S2AkItlmw1adW+Nyo7ozMtsouKv EPdnJw3rxu3RFEyAVSLC3wZzI82k9WQ9nPTIEgQDRZQyivqcyiU7XmSWuWjMyTqHtohrnrRSOFAzt cdJWESRHp796gqAVqZLO2iL4y97/3NZ0ytTVDM9C/WjQtoghk/Xl1FFV1ctH1VYRZ+dRIokv+JvAb q0fEe4+L6J9SOBOe2Oug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFVaX-00A3Iz-IV; Wed, 11 Jan 2023 07:31:57 +0000 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFVZy-00A34h-Va for linux-arm-kernel@lists.infradead.org; Wed, 11 Jan 2023 07:31:24 +0000 Received: by mail-ed1-x52c.google.com with SMTP id x10so18182450edd.10 for ; Tue, 10 Jan 2023 23:31:21 -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=clAg3pNMynRTgt/ZYGkCxez++C8JfrcYYOJZCCGvBuPqzuRYGoWbhgwlQOdL134HL/ 2Eho/ERuAQm679eEFNivP61UWKBR6vnvRLVlRBoBbj/5A8qfWPCJpvnJluJXduu2y2Zw 5N6HGQdGRmuoZTI17dO44aXEDGxlwvnrNHwrgWiUxXLvby4S9tsB3hvnRLpjA6OtG5nR Yj7DfjmE0lqgaIN4gTyJiI4Sdl0AXsoWZa2ufgS02RNunujn2FKKpB1u6VcTo+CHgKAD iYCuFF3HgSga/zF2X9d+Tx/G7CZKSTC3nXzE+jrxJZmMLCyI5wsU4rp4xM9mC53YPYuO 2maA== 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=RzZAOmzzDEnu0lL0XptTy2ISDKtY1HNwCUKT6LumJ620gruLj4+fu7CyEJeugc/h2/ Jb0yMQr9N95LFrt5+WpCima3ornkvL6IGjPJ2QOqig/CydDGWSG3d5rnttBws6LB6rrk QwkcqXpm48oRhYWQ9pDzOZ3u5evCszI8jjCd0nHH6N+eHPqHPI5ljuGmDXmHtf+4imnc gnU/1Ci4qsfijaBZtBnDYNNhppFsNpSHjTVtrAKj8DR+MIzW6Dk5rImrb6mePM7rWdpH oQR1FZLDHlPv53cBoerEgyXYHt8qEWrAS/z9pKK3pfjqpmu1Ifprd/NxndDe93uI7TWd YSog== X-Gm-Message-State: AFqh2kqKgdGvsFKnV5QvEZSHBnGDLcq4iJb2KhdhqZc92Un/wc04ZoXM BlgSOJhFKEgucZQIcVUuTHQ= X-Google-Smtp-Source: AMrXdXshmijD2se+S/uS6CRtU21sfZ8aA7lNf5pWw0PkbyxS3Q4+XC35AzGeVuw9BhxMstgIidu0rA== X-Received: by 2002:a50:a401:0:b0:46d:53d7:d21e with SMTP id u1-20020a50a401000000b0046d53d7d21emr64886229edb.27.1673422280601; Tue, 10 Jan 2023 23:31:20 -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 ed6-20020a056402294600b00499e5659988sm593193edb.68.2023.01.10.23.31.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 23:31:20 -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 V2 5/6] dt-bindings: nvmem: u-boot,env: add MAC's #nvmem-cell-cells Date: Wed, 11 Jan 2023 08:31:01 +0100 Message-Id: <20230111073102.8147-5-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230111073102.8147-1-zajec5@gmail.com> References: <20230111073102.8147-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_233123_025026_EC31FBFB X-CRM114-Status: GOOD ( 12.95 ) 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 Reviewed-by: Rob Herring --- .../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 Wed Jan 11 07:31:02 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: 13096159 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 BD4C9C46467 for ; Wed, 11 Jan 2023 07:33:15 +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=27exnvHjhYGMaB ZJYk6/pL8dv8hyI6by48rZMcKOpvjC6tTQDpr+cF+9Mc7u22e+Fnm7R4SNcFrClEvuHQkePmFu+PM 3ks01npRj7CxEHw5UutyJwVXh0br8vDSo8ax6uLPWiGDEbMJlkd0LyLPVNajSNy72JroRXd4m3nNi IVGjhJYCxYcSr/JPdArCdTRFq8KTD/RJhy1yBHN1rQ+kf3ZdDG04SvwmkKikGhIhFG9U7or5+hwGI CPrcDm7+qSWY4nFGFvXraMTpwkQjgmek8BBvstwALf2eZBDHx/2Nx3zmjD526f7hjOXxFlI/uta0Q dYSBnKt1MonSU/WbXs1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFVap-00A3Qk-Bq; Wed, 11 Jan 2023 07:32:15 +0000 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFVa1-00A32U-1v for linux-arm-kernel@lists.infradead.org; Wed, 11 Jan 2023 07:31:26 +0000 Received: by mail-ed1-x535.google.com with SMTP id i9so21101595edj.4 for ; Tue, 10 Jan 2023 23:31:24 -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=L7tzBu0DFenwt3+uzh4aGNJXZrLz9+JI73DKhb1jKJJPerJQP4FXl+Nka8fNjQzWPy 3aywNKLauxX1cB4gN8yKBq69FHT8fNTE+J2/++uYpGvCf3dSzEetjSXixny8rXJgE5Xq oo9PI6kahvQTLhucbBFTGwTqwTFnuxVyS6OFcIumGzsj1Ybv4jRx08kxWWOzygLKpiAk 7nlKGTNB+GRBqzg6r+K6bltbOAQ0tHJnctOvJmjpu/+pEdPtwtkAqxpG072S4zoPP66v nx+c/09bgi9sLhCWoZof+AAQtzbyT3CJiZhye8S6jtuvlE07aG2P3e9FxFUFiSW8ukS6 PWSw== 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=AHVWiXSwEiaqIixKEyCEz0e+h7YsncN0p43nrgAr4UUsiK4554UoyqoSYc3DH/lmsv o7Bgbu5fSSSsfHMHM6tNUuG82SBRgbcIbmqd4/beyg+umE1u7volT//xb/DWE01KtEj0 0zO+XhrexLJN6X/ux1T0Yb0nNnDw62+740efxHUIkCTS4mFVFKRTWARrWap5F7wucJ+I V6OXtCi5uOSScdzP7Rt+cTsn7wSv8uI3Gxo/t/gWj3eE3PWxrR884jFC3d5EHDMqjfin F4Smp7xCL2ocz/nemJeO4H5SZyz+j/pB0ww+ZCe4Ht7mV/vVQpH+PhvTuKt7yTCZD8pd UF5w== X-Gm-Message-State: AFqh2krQ9FZ13v7+x8wxfzqJg9bEKldyWe63CL9Idw/I0GzwGzH1AV64 rAUBiniv/bNNfn+Lx/mPAck= X-Google-Smtp-Source: AMrXdXviRWemoxJeyz2j5A2MJA1bIBH5p+F2cAyWLSNk5iJigeCylpmCPfufczACWXrlMLnmM2wjbA== X-Received: by 2002:a50:eac6:0:b0:461:d042:80db with SMTP id u6-20020a50eac6000000b00461d04280dbmr61859126edp.0.1673422284520; Tue, 10 Jan 2023 23:31:24 -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 ed6-20020a056402294600b00499e5659988sm593193edb.68.2023.01.10.23.31.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 23:31:24 -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 V2 6/6] nvmem: u-boot-env: post process "ethaddr" env variable Date: Wed, 11 Jan 2023 08:31:02 +0100 Message-Id: <20230111073102.8147-6-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230111073102.8147-1-zajec5@gmail.com> References: <20230111073102.8147-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_233125_125134_E78B6412 X-CRM114-Status: GOOD ( 16.52 ) 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) {