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: 41398 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2677055wrt; Tue, 10 Jan 2023 02:55:43 -0800 (PST) X-Google-Smtp-Source: AMrXdXtnRopM7u+pGS4ApS+STNaW1KM66V4qyDQ/7BAiC/ntN8YpdS7Dfy2xKFgfsJNN9BtKRCTF X-Received: by 2002:a05:6402:4004:b0:48e:a9a2:407 with SMTP id d4-20020a056402400400b0048ea9a20407mr33049518eda.23.1673348142784; Tue, 10 Jan 2023 02:55:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673348142; cv=none; d=google.com; s=arc-20160816; b=aQIhyjuFGiPVjU/ExSax+u0yMZyb0YjRI7w4nwwTT1ueoO4UIzmRtNd/QIHSWueiXx /igymYY+eIDECdxH5zhmahup6PJPFap/cz5zbZLhHZVcl5gmKL/5BBcw5JBAmioM0D63 wkVdyEIYW4lX1UXJ7eRSG+NN4uZkkeIohHuSheFtEUF/AxgKiSq0isfS2ceAc2vEqfJN XTVuK1BAoqszlfYnPHOl4nXy9HtEKaoO//+3qObZ0V1oW9kLN90W5lHFEL/uNyU5eEDp CWkqkmqIVFUsT7Qsf/HJOqDUQ+XakONyBddprwmNPTA4T1s7u/GxT5dHnQd3Cva2ka0K z6DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=kx33osG0iIsA/kyalJIybKATyfWaMXF9jLXNGZKLKMc=; b=HfsHjJyV07jiRGwZ64v0AyUMdEBV2gxLfEDUQ9zBFEWJrNErb3r0puZCBJcTsQkYK2 S2CaGXjZ3GEN6HhZxxJy0VTuKqeRscY93YiGAsD1Q/N6qt86zPBOQv0W8T6VaVNlfckj rQEnRSIFwp2a0ct333ORvSgnmkojLnWcA4Me2WBLSeY38lMXn2qQQueiDeEiIB48l4Lu lW6dFOd65SObUC80ZeaUIUooIQ2ZZevvbs5G/fW+REjbd+qAkUvlVFs7y1Mmw3rLzBvm vIoyUXQorI0dORd0F/3fHEWQmtIdeDmOAO0ftrd94l5TQ3H2MJGF2PzkK3IKKLn6cy9D Ewqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=k5eMydzO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt33-20020a1709072da100b007c151fc73d0si14443195ejc.653.2023.01.10.02.55.19; Tue, 10 Jan 2023 02:55:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=k5eMydzO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230057AbjAJKy5 (ORCPT + 99 others); Tue, 10 Jan 2023 05:54:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238165AbjAJKyn (ORCPT ); Tue, 10 Jan 2023 05:54:43 -0500 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1E8A6AD83; Tue, 10 Jan 2023 02:54:35 -0800 (PST) Received: by mail-ed1-x52e.google.com with SMTP id m21so16943251edc.3; 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=ndTdg9m9T56og+/86OnZwo65SC/dsfq6AJ9WAcXcI7g3rmnEroW7fERgMnI0EbuAK3 jBhUOTYvA6dXSJ/lBzk5CuzivMEPTUdhprkSwXKCVFEP3TKBe6JSDET5GGR8d8krJPWM b4OM/bUh64SQka/EugjizCIGyBQaq0q2MBkajxTnOyV4/WxjieSHWMPVsezl6JAmsw+f O0zd2xH+KfJDhEpkGVpPoxPQ5+awv5ABWrIDuloA4tbAQsOecOlWENWe85OqZCPsPt6D T8b3u9zQfJzuwdV3Z4r77dbQ2DVNc14LdSkHpZz6JValBTznkv0bBh3rtwRFfD57gkJv ZYMw== X-Gm-Message-State: AFqh2kpNd/1qXkzSa+k4hmD1E1iKWp/N5px83ctCG6EArHvL7xiIXr77 Uf9QcdgMkto9a9qDsruFOq8= 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-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754632702488216057?= X-GMAIL-MSGID: =?utf-8?q?1754632702488216057?= 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: 41402 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2677649wrt; Tue, 10 Jan 2023 02:57:27 -0800 (PST) X-Google-Smtp-Source: AMrXdXsFJQ54RFx0w4bDbAbt+/Fqgn1T4Kt3XIilNYABHeKUTfaQBamEPjs1H+Ae7K3H7gmIzoln X-Received: by 2002:a17:906:d788:b0:7c0:e5c6:2a6d with SMTP id pj8-20020a170906d78800b007c0e5c62a6dmr60102116ejb.39.1673348247462; Tue, 10 Jan 2023 02:57:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673348247; cv=none; d=google.com; s=arc-20160816; b=QjsHF0dsC4qN6zaW6iEHKhi1SFSiCrazHTYWlc1ZRCewJ5WgsYSDGfzGxKu+Nt0xmE 4BPIb18zapE3cnVgrgljrPBAmsYY2/qBtg26uErf80dDH1kQi9QNB6iRN1/nwoo6sM9p v6AnSlnduZtCUYBYDxLN/JDaZavHpXStXlg7d4Z64gZ9mfY8xpr9t4XNtpKAeR8H1shp o+8RK39aBFS6L9iImmnbWSYhu5gg39O6k78mqa5++Masc+key0fEn3Jl0X4SoVMtPq7p FZOVC+zPgwGeZDANPFV1gI/yg8xuGJ/jtwsrPuvzBSCMYbs5Q43o0xT+WgRuKvU/tgUz l60g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0rYqNvw1clZ8LqYgMptRErDOAS/Q5a8tz7ExdHTB2xE=; b=XaRodTDBHgN1Z8n7Mmfo347PmBoaksmV54F7cC4WwQ+xvq3SXZqtMTXuXv5IZBzIXT cvro+oJ3NdkcS4chFsYx061bqV5lH9soilapNc+2kzaYUoMNeyzEhMnie4xYz2cz4DFm TPYiDj76ijWYI5SbV5qmGwo4Lo45m4uYRGTxS03LTqnijLUBjFVB177uF7/i6yo+iEv8 5Q3aVva2sycQeP2ZqiaHol3oB5Uti3b4B/DezqyfgmDRTO99usYiRqAYxE19XPF3ESjg B+PoTPmFAypOWwu3mzWqAQSLFPU2jhZx+jEFo4Vx0Df0FeFTV6XzG1qjDqgeu2ZLu/45 PFNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OzrLT3uM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jg18-20020a170907971200b007c10f641a2dsi11998225ejc.148.2023.01.10.02.57.03; Tue, 10 Jan 2023 02:57:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OzrLT3uM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238165AbjAJKzC (ORCPT + 99 others); Tue, 10 Jan 2023 05:55:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234939AbjAJKyn (ORCPT ); Tue, 10 Jan 2023 05:54:43 -0500 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AAEF36AD9F; Tue, 10 Jan 2023 02:54:37 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id i15so16947054edf.2; 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=NpDGIi5FBzJKnAXNwjzCfJ9F6HnLCySaDoPM1MyPnW3BNbhmxrB0/k9J4aUCmKPbQX NOCVR8E9nlQTnRUSrrD2DLMQT+a+8mGyW2Fi4jbZzdL+Rc76iqdVuxduEdv34Pr8YhDZ 17Nc6ci2y27M0GUeRDpSMLdz2nZBIxQXCVJ8dd+7UiNKUdBgMvi4VzGyW1ZshfV4HQ89 V+l87KM96YAXFjOLtL+suseP3XkmfRLouSxq2eVLpi75dVl37AoiGNHJkg46g4DP99+5 5KonAm5S8pWAy+QqYxep+s33TO5eQ1ymu73D72f0lH6DVwkstxmMvH85urFvUzPIkVAV 8+Jw== X-Gm-Message-State: AFqh2kroLHclbaxr648a+DDOvsBMLRVZDt7qPZLOpBsoiTAX+oSKWfnS Gmc+DSF1mEw3HoUmnnqVOr0= 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-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754632811943301111?= X-GMAIL-MSGID: =?utf-8?q?1754632811943301111?= 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: 41403 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2677772wrt; Tue, 10 Jan 2023 02:57:50 -0800 (PST) X-Google-Smtp-Source: AMrXdXsTeRQ2Qo8SkmWgIRWD5pxeqoQM5i4HgLZaTNfdt7np61P/LW8fRlSjjp3ldDqvayC9Iypc X-Received: by 2002:a05:6402:1249:b0:48a:84da:538a with SMTP id l9-20020a056402124900b0048a84da538amr34595455edw.34.1673348269806; Tue, 10 Jan 2023 02:57:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673348269; cv=none; d=google.com; s=arc-20160816; b=0lTRgVdthMODzwXJ8BUSkiJEqtGt1yMz4DAKYTGBSf+T1PH8Ksd+Q2Fj+dioieRz/A R6k9JbE+edr3kwqoiagdcMdPxh30LqYzxI2iT+EJH2RG9WJ12Vl9KxnHGT3ys3mPrVQ6 hpjJmDXjNxivzUEVWhPHdmSke8XnDKCuyERM44BBwDGbpx+npXa7WJSKzRtQHYlDduCV Z8SPAbMngLyjR8irIBzH9yunnnuqGrVLq6nMaTxcdrgq37JXDs3pUhP9LtL3tov/nJ+u GOOwrcFKE3e9RmAI7ONA+7MNrXXnABQDRTjJQb5/fDGCq/UUjxfrtyUgWpBdHO6Zsj0O QJng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xLzMMc8ebvQzEKmQRYFOwkLETqyrkUTk5WSaxVlJTiI=; b=n1fvVX/UBttdjkNIueVphni0SxebAB/zPQ+TnjKWPyLYlsYvqJNAaMp/58BMi6764l XH+uXyc1yFlVnRYNxH4B+T37LCj7MhL/42uCgoOmP1qQt8OSmkZLDumOJ1VRG2w4KNox MUhDWyvnmRHc8DMS2UrGadQ47nJBj/PlSZVlWst6PtOXes0iY77QZU7LFK17oSVVjPLh wGupPrqpYBhzIUh+VeMUAVGy2ArFCstJLZ472rBE8XTbPJJj4HteV5D/3okh9TrDEFWp wCkoSuxrKbbMHe8LweXF0hka3fTfPCUbb4ESWbSFzlfCJLAXV6KNfS4YsRzsLNxf74ux L4fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IsCWQtuQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bd8-20020a056402206800b0047aaa487720si10532707edb.275.2023.01.10.02.57.26; Tue, 10 Jan 2023 02:57:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IsCWQtuQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238203AbjAJKzG (ORCPT + 99 others); Tue, 10 Jan 2023 05:55:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238180AbjAJKyo (ORCPT ); Tue, 10 Jan 2023 05:54:44 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6141013FA9; Tue, 10 Jan 2023 02:54:39 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id v6so16892841edd.6; 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=tmBIXqHkEbigENWUcPsO8SEJ6mYXMIWpWGY9xFcItGZ4tvOq5sWWFVwWqsVOMYXcoD HyVfAoItCOfVezT7jKPdTwGGEHJXl3rMcsJKDwZ6XfTbUc0wA1oeF/r3tKU26eVuYcQw Z6tdDDZObSL1Pe7YS8a7N+GE2ipiu+1B+5R1r2vzA7zUjpDVoavAt9jKoAmOsedY4BDR lw8qPs0q9gcjVMQxUm/a+ftsp4pxWdPxpbqMJA7u7fP5Gr7GVYIlixZ1ogpoV8AZcY4Y C1vdDgK6B/kExfzMmP9FmKdSTfzRVn/dsGQwZWRKf5pPRq0WcwDYiWYPaZ6VOQFaJpYb dkyw== X-Gm-Message-State: AFqh2kqzFztV0tXW0zuIuYyjEOir8J1aWTxT8YkXKvNzBw8PPk8hgIwN tA/LD1PyyKuM0cMx3MZSEN4= 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-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754632835423056092?= X-GMAIL-MSGID: =?utf-8?q?1754632835423056092?= 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: 41400 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2677299wrt; Tue, 10 Jan 2023 02:56:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXt/bhOsFANHvSiBM7G8lb+flXRCt37SBqF2QjzvEGou7enoBVzlr41JCM58p466i7lBFi0w X-Received: by 2002:a17:906:b043:b0:7c0:d23c:ead3 with SMTP id bj3-20020a170906b04300b007c0d23cead3mr59864640ejb.27.1673348184812; Tue, 10 Jan 2023 02:56:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673348184; cv=none; d=google.com; s=arc-20160816; b=o1Gs0oZdgPxVGt1nm46nqibdx2j0BTU5M29tADwTu2RyIaXKIE2TyMZo9PyVt5t+u4 hOoMdF8zKAZvYSnLcJnUSXctwdI/Ie56yYLEISYDeQUCffgtdXfXfaLm4cOJVfLnLRgY loz95jkeqPZA7AaseAQ9jdeXoktP47AbX6R+4b8zTD+pVDcgjxAzQLCI3GIvaY3Kkp63 mttrnrmPF2R4hqB5MMKCNcECErpCGgSlhagfX8CHM43or3UyLTdnbIk9fxiIKNA0Tr4q xOqkPyfVARPGcQR4USvwRgOFaGoU0et6MXOAPIwepw2ed5eXinnc9XkeGrg1BHwX8Ln1 mw3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fmyqQiyVRmFOYXu2QDS2W36W/FBaUp726XptlAMZsWw=; b=XHSGaqk+nleMHEG1L7WLIarsmRt9bcWe3zsurj3s2Ff/BIdPzhwDgAQLcGXDvxbrkg Fzppq+k9him0sbICWWk5ABq/4ZE0Hn2q7V69w5RJVoOwVwXMHyDRMPkp90eMPp+a5LD4 iJPS/D26o2r/UShre13LfOrHgrZlwPf+PAxhkWTNlNQO2PpUDDAoc/BuMIWdjp5epUQM 6c1+zI33RIlc8lcNn0fr50+UxnkrtzgUXCbdx2krx1XtT1G/rbbEGechhz0cskkuwwl1 eDPiR37eTS9AWgOXhJnu0nsz71um98sccZD5CtIOXhoHahG7e5TLd0w6bdS/0ulsA/RZ Pelw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=C4w2ryEp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dn4-20020a17090794c400b0084c7b099652si12891787ejc.567.2023.01.10.02.56.00; Tue, 10 Jan 2023 02:56:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=C4w2ryEp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238229AbjAJKzQ (ORCPT + 99 others); Tue, 10 Jan 2023 05:55:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237882AbjAJKyo (ORCPT ); Tue, 10 Jan 2023 05:54:44 -0500 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F41358FA1; Tue, 10 Jan 2023 02:54:41 -0800 (PST) Received: by mail-ed1-x52e.google.com with SMTP id c17so16899665edj.13; 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=zGe3trI5h4dwd5i8wItCeuCcByyMv/k+EYtR/rTCMwLOQJmnMMvEfBunQksrz2Kq+u JzAfIl4/tzkjw9HngAvc3iwEK1xwFnJm78vE2bxJxg5L3beW7VHN/CaStnSh90n9aLCF 5c3EZMTjY9qF6AWVtvpQHVMHZv5gcU9MQb1Ydb1TKiNGR8aLEv9cyRlWXQQbar8WhEoN BHtgMmikAC/s3TWUZicQsFva9gnewH98E1QrExckYJ9BXhx6jUAiETjqJOX8vfKSgq6v V1ulaOWhw1fcMazPgwHUuNS76/8ntWBx+vr2MIjeuY+vb4fZBpAbpzQcwRMlDyRLtUZd h4jQ== X-Gm-Message-State: AFqh2kr1EIAMSTP7PBguaqxX7PJYIaKfGJgsORYMkVXrz6d7oSew7OGq 17DfdhXAy1APMbO2G6eEBG8= 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-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754632746233308999?= X-GMAIL-MSGID: =?utf-8?q?1754632746233308999?= 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: 41399 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2677275wrt; Tue, 10 Jan 2023 02:56:20 -0800 (PST) X-Google-Smtp-Source: AMrXdXtzAwvf5Gug5EhzVkAMiVHQ6RyS8b6yetk7hf0cR1TdjzKdXMlfrlKtHudBOLeP0osWNLgR X-Received: by 2002:a17:906:c250:b0:79e:4880:dd85 with SMTP id bl16-20020a170906c25000b0079e4880dd85mr50927711ejb.47.1673348180668; Tue, 10 Jan 2023 02:56:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673348180; cv=none; d=google.com; s=arc-20160816; b=ObsFWYFg2olm9/ECkb3hfK8DrB5TKHkNESQq/7PMAk61SchH0YNNSVCIyS9P+uSdWy lKsm2GYsRN2IX3zphn4hnQKRfxCmq4qOxdklL9UNwx0vM8SVmlMCU763nX3CVxVyeyCK HiokRaOnxdttLi4AmxIT0uMRje5hsxRgfJNkAI3eKLgubJrWyQsbRQX9/KVaS5Ckr7b+ rl2wK4sawCpX+T9OpuP2KCeF5wbv9ltlk3XA2DVV/BXh7xohBIEwQMfmxzmRo1/hfm/T 4wx5dN01btV/hUGmU8kNH7OoB1T9ofCRZmxTg86UjuUeCbeEQsxBZLCbU0TZJ0EFnjmG MS6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=r5xJKON5Ta6zI9VZAQEfIhcRQtQRxrWmROsI4bJtDyw=; b=tnN/WZ3ye5rzIQWlwQ7oEp3AtNVGXFJe8SuOs/AIVuEnHoqQYyJMT7oZG7k8uAsz+x b29tSg2ldybLF3inPJNWqtOkGfYZUvM/62/bYrl8gBgyIYSk+UgJVJz/TlLykBK/IiFj pX+hFfs0iOrr1zE/46WasGX/U0385CZwsB8vkqfumwdNF/EHxCVhWtN11xvnOGh9UT3H Ai2pyQQZEMdAvsQLMKFiDkRsF4ckGwlroHGRATh9sfuJB92R9YhDbYG6INeTFbneT0iI JkC2Xci3BhawJrHwiHJNWONytFK7kN1svJLj3EYmtRD3kjzMs+IEQ2mbphNL69zvFuRb 4Kkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fHEP579I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dt14-20020a170907728e00b008318885e1f1si12755421ejc.176.2023.01.10.02.55.56; Tue, 10 Jan 2023 02:56:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fHEP579I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238217AbjAJKzL (ORCPT + 99 others); Tue, 10 Jan 2023 05:55:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237872AbjAJKyp (ORCPT ); Tue, 10 Jan 2023 05:54:45 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 166331F4; Tue, 10 Jan 2023 02:54:43 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id az20so8462796ejc.1; Tue, 10 Jan 2023 02:54:43 -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=x+rqVTeb5Ak3aL37/sfJ1Bk0JYh2CVLEmYkhI+LBglGiiHjZy4hlLNlLzn78sFHGci a4An9tBNLYuJOnN0sJLgEB/YP9BEfXwEdhju+89QgjIAYjHLKpWbEaUjvI/Es/nicv5X 6R5CLZoU3+8xbyLk8jd1PgGmd+uU56ke9UH7lROQsXai1SEkOLdzbnl/DCyuOoR4PsNK FmMUG25c9zOa65/TOAASVFOWOOnfRsfU3PPhCnfwYcoQGmXu0wW94iUjHYVWH3pgcn4d SQsw1GKO2XRvxM4QLcuqGZ6JpCb1szpL3Vy0a5ANWM0O4Ro2Fvzi4LAV5pGmKczIOPeA Ph0Q== X-Gm-Message-State: AFqh2koyZD1kmtdE92wGLJwqoSK+7N1hFYLHmodIhxA/NZbpKNhTMsuc acyAG1d9p/55NBcnXEGM3Sw= 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-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754632741873704333?= X-GMAIL-MSGID: =?utf-8?q?1754632741873704333?= 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: 41401 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2677318wrt; Tue, 10 Jan 2023 02:56:27 -0800 (PST) X-Google-Smtp-Source: AMrXdXs0u0+r8Y4JfH3c+ITxt2SCADFtEii1S8ms1JcK8H8zS8Sb4sRzGWFzlXH4afY2UxQDOgL2 X-Received: by 2002:a17:906:185b:b0:841:e5b3:c95d with SMTP id w27-20020a170906185b00b00841e5b3c95dmr61646872eje.30.1673348187095; Tue, 10 Jan 2023 02:56:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673348187; cv=none; d=google.com; s=arc-20160816; b=j2OWdLjVoti+xj1Nmg3u6F+biZ7+GroCaoPTj79Ac1IdOWgo/RFj0a7hXzphDs7X8m EEqCA2ai10L3Q3jZl+WY+Cfa+aVc/x1nPokYStL7KNbHUAYltyKKO2KsKim/SIhH/4B6 UZ1vkmvCZi1k7+zX8VU/HRidtUaNVoJNJ9QfNvdZEZx2ZbnvV3VXKWY/tOXyxwXXYAcr Hf8Wz1rpmfpmjOelYStH247HZAx9m9eA31WP5Dbrcpj4+L+X1hD0LWmBw1qcOYVRkNcJ nyplCiRIFunpEJr0rgnc2vfh6nObS38qw9GgeJTppY9WSC9H8ZtaZyF0tR1mFbYwWTzl 0EJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wAqYvgRzLQ4rzA87QLNuurx0Mvg1Ygp2KEVQbcFxer4=; b=L6AFIqCVTybT8iEGmBKsoG4d0bEfQ3w7Lr7W65EQl7DfJ3dM3eqBiaDCeKY8MiLvHE OqwdAoOOASQdt3y9ePjEqdy8fYMNYtu0hZKIIdAFk5I3nyxbF5GQAJ3rskBHq0Z6CZwF QcS1qhed5iv77y16jw7xCgSWDogTwXzZn8NBl0h1YFyUcu46IjBM3jy+GYnp6kiv0pZ6 gMV1LrOemM5vHJJZSviDA84cZzc2tCbc16h/8Q01Nyfpd4yuiqiwn8C8qlOWL3hLX6Pi UHBUKnbkMKG2wL79GNoMUjER3AtBEA5kJl2cfQbtDiWygheQPoGSVzLNWvSO+gDzHb9E sQjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=SJ7SFb8l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hc41-20020a17090716a900b007aeaacd5592si13702060ejc.124.2023.01.10.02.56.03; Tue, 10 Jan 2023 02:56:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=SJ7SFb8l; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238197AbjAJKzU (ORCPT + 99 others); Tue, 10 Jan 2023 05:55:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232107AbjAJKyq (ORCPT ); Tue, 10 Jan 2023 05:54:46 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72F1B1409F; Tue, 10 Jan 2023 02:54:45 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id fc4so27488415ejc.12; 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=joMd54O3jtxH5ZYAGkG9m7o5deJdPb/MH97YGeP+HZB18ivXN3vjCuSzNx0+bNNvND 028Lmpxw0YAIIYfJuuzqGYVE8rSotDy3SS5WRWVL8LAKYqKDUAt5U6GjO3V4hM/16PMP 6gULftBwcXdQ9+50K2ArJtZL1c6bbWqgxMdkOKQk93GX7JHKkugZ4a/bW9/xeW6vQ6Yb aB4xnbaJIaaJvuXif7SFpjo1DpiAoXbEzF5D6HP5M6QEO5dvcQOVT8RwsvIslc+gvcHu 647s+YcSUAq5A1sp8Aj1qOqpsCeL/ye6XpLKgG80zUOPLJ9FlJIUJIWwe+jiqapik0rD Zr0Q== X-Gm-Message-State: AFqh2ko/hRiqPzeVpEHvE82OcD5d3X2Ttcyj9ZHhrqVm6iUGWpB+LTJJ ElI8Fph8M0FKR+HSbKfjfwQ= 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-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754632748369454604?= X-GMAIL-MSGID: =?utf-8?q?1754632748369454604?= 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) {