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: 41785 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3180610wrt; Tue, 10 Jan 2023 23:42:08 -0800 (PST) X-Google-Smtp-Source: AMrXdXv/x4iEtDlFliMJTYrC2e+8eK55ruEw8kOQ+IeAQ8ySH0iUZihcflcdQIcWrLHmUScQ4W1e X-Received: by 2002:a05:6a20:94c3:b0:ad:dcdf:aaad with SMTP id ht3-20020a056a2094c300b000addcdfaaadmr90843066pzb.19.1673422928401; Tue, 10 Jan 2023 23:42:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673422928; cv=none; d=google.com; s=arc-20160816; b=PIA6qaALpgcRrO8A5Y/xF/9UmBeMb4yWLek0Iwz39TaKhyooHTMfwLvxj19UcDC5qy 4q7KO5/FwRjUCdlCiE5HwuRPQO1YGvE3IlwzdXH8zIKu7Vl4NvAJrKF1NR9v5pULBLen qEYpIbTUU0oo6fYCI3pkR/qAczB4duQ/4tToFmWHObSSjK+62kSLqmXcUsUpCr0uYfTF HvZgE6bzvrNjbIcV5gR/DUzeYwsppGMsrxVJRoM6sD9rTedViMSdjnBjLgmuC/yQP8j3 MauPy70ev6ykwl8FwjtNbJqDWj2UYZvvTJOxa2TFGgMffHZw6J+Cewlb1YbDzabvnD4k gEvg== 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=8DBHbw8SRKxIaaEznlgvFtV6o4AQh3C5twMwXmVKndw=; b=CW2WCTjPvcd/y8eAUilf/+dSNwqfUKyMC4sdU1LDfBatz64/9zgwDhZ+sB+PHewy0p LoFUnfcNaYvoTXi3TcNv+5O8I5FZPfGoJhn2w3WEqN1xwZRZVHxbvk/1V9/nCU0qEuQJ biSigMzKXhB71p9/exWcKL36UMXPiq6dNuLtWiwh/KOw18mVFEqH+802nkdwaVFVYDw5 DuuzGv3JbNyvQ6OV+rKFAcLgL/CBwokOA0mFhYwGLi6myCC694vjwkBzrNlGgrLuXMTN LJBSH+upCaobE/jqjOHh01jY1dn+Kl4loFJWfrIUB2BiA07mkOcMRz8VsNrGOj1Ck0mM 7dZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=LKZl3Yl1; 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 h29-20020a63385d000000b0047005e8d874si5373239pgn.9.2023.01.10.23.41.55; Tue, 10 Jan 2023 23:42:08 -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=LKZl3Yl1; 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 S231927AbjAKHbS (ORCPT + 99 others); Wed, 11 Jan 2023 02:31:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235641AbjAKHbP (ORCPT ); Wed, 11 Jan 2023 02:31:15 -0500 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EF78E9; Tue, 10 Jan 2023 23:31:13 -0800 (PST) Received: by mail-ed1-x52a.google.com with SMTP id v30so21067456edb.9; 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=JlcBM0AdvVelZFbC2n8sXB3zk4FSzh/JYZaA70zdn8NYJshW91r9qaFvnOofyeg7bD KcIjt78k2mPxzYHHz+7Gt5czetlH06LEOweqe3KeqpeHyGFvQU+e2HynbKCgUjuvGYZV 0plWidupNXE6t2O0DMp1LH/p9uZGuoL1osO4XmV8T/Z5RwwvqWeW8gJ6Y6ZjFm7IKXla YaLSA2Kk0s/ylFFlbxflVOxUFX2UC+0mPjghGzk8iQxOoUSs+/nuqtmi0geNEKrI9/lJ Vrb4sWb6miu4RxLnbT9sXsvXqvSXKQcSb0T0+G4YRywx2nUF0plbUpDssoLdwa996cut XlKA== X-Gm-Message-State: AFqh2kojWUl+vGKjGRCDb/8zwac3uoFmCrMT47Co0dCwwykFm2DOkMYl aeZldikn5N5VlOoz1iHYYhrzIE95QvI= 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-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?1754711120495096858?= X-GMAIL-MSGID: =?utf-8?q?1754711120495096858?= 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: 41784 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3179861wrt; Tue, 10 Jan 2023 23:39:54 -0800 (PST) X-Google-Smtp-Source: AMrXdXuQ+3XDyGB5+qSBFqgwBjajpK6CZ4oCHCDYflAvf5+adOUyXamqHnIq8LlLHL7q6ThR++A1 X-Received: by 2002:a17:902:e84d:b0:192:8824:e516 with SMTP id t13-20020a170902e84d00b001928824e516mr68371278plg.51.1673422794047; Tue, 10 Jan 2023 23:39:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673422794; cv=none; d=google.com; s=arc-20160816; b=NhoaV62TjgKDNzyq/LXn32R5nnp7A6Ox4OzWPHzBytMQtbUGUOD+laAOvi6wHXa0jZ kSg9SQp9K+ziOf21HaPkEeCewrAGy+JpjqonLY92sECiTY8tuFnTT23SN0hurKL7sFPx pT2UvcrGeXXNNDvt5ZVG4ptcsPRWgAGaM8bAbJCpOGGLkSdGNFk7Cf2rpmn82QjBjLgk kiK0hJe0VMv/x0K6CR98nZ3XBOJAqQWFIm5XvjBCr62wEHVYYVylzda5ZemAYldAERsc fo2o5CQ3YSE5Q9lV2anw80xQea0ee6nK+nAQa1LFVyCXMq4Z3UioHzBRSqfZiaUKbmwf L+0A== 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=J1GVfniV/eqw+M+Qk9AYkx0B8mMbL6xPt6dFX6gFZ+c=; b=cDetry/VxJaoxgF2xdx3pewuzHRT60ViFfulwFYcIuTgt2E8KYxzrebUsoWksUqFjk 9zDClVQIRUK1uwrhk8Qj4XVkrit5C4GT43JEc2vWgVnNcAUTRNM/Up/ZRF+n63s+ILOA /pChtI1i4hm+Un7f20TMh5GhxOrffjXFq+geDSBtMwFYeLrGaQ7FVSCvTTrAVlg/RRsG zGKWIgiGirtTU+H2UK/qeXhenR5T5zyvNQ6tHCjphug9RMT2NksvjDmoPJT1aFxceh6Y SWINEf4lEjacdaUjSOd/wuS34VxznTki3GdZPqwty2I+OPwKAMk1GvF3roZqqgygT/TC 5e7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=XBfqfp86; 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 j8-20020a170902da8800b00186881688f9si8375573plx.276.2023.01.10.23.39.42; Tue, 10 Jan 2023 23:39:54 -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=XBfqfp86; 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 S235850AbjAKHbX (ORCPT + 99 others); Wed, 11 Jan 2023 02:31:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235720AbjAKHbQ (ORCPT ); Wed, 11 Jan 2023 02:31:16 -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 286622CC; Tue, 10 Jan 2023 23:31:15 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id m21so21093991edc.3; Tue, 10 Jan 2023 23:31:15 -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=GHsm/bdJ339+UrM376AlwYCfaKrg00Rt6aGPGpSg/wRBGFNrPKG1XJUh2FKTzLDP+n IPvDKj8ued0HXLTPK6FRJl8BtBkpk0orMZ+bAAtujnuHZPa7E4jWyYniDiKyPQid30SE hHQSj7eDmdbYBZ9UEn071jivn5lRgNpMLkIhGEy/ZCf28CtZudpAR3rw2d7gifr/4Wjr 4DcTQOoNdJaluQ6BqKqRv30+PuRoRIJ/yV9zjobgq3JnA2yKeSP4egQ9JglYlJi/Oa8N r/Zjw8H8WeO2hfN9QJRvql6FD2RIDnYnX1kUb/Bi3qKdohazWbg5oo9Fsh8HW21dPhke 5fdg== X-Gm-Message-State: AFqh2kqN/zgSHiVehK1yEI/lHCQCgDfMYRwUEHeUmv5DoDIu4muYResE arKkByMkC94o65r6sMk3pDs= 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-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?1754710979674420560?= X-GMAIL-MSGID: =?utf-8?q?1754710979674420560?= 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: 41787 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3182032wrt; Tue, 10 Jan 2023 23:46:12 -0800 (PST) X-Google-Smtp-Source: AMrXdXvzM7DT8k3IFaMZSZV7ASOpLtHWCAkFWGyasTwOEmaknr+pkTziUBLmLG0F+WiXiCh9it4B X-Received: by 2002:a05:6a20:4417:b0:b5:d780:ffe3 with SMTP id ce23-20020a056a20441700b000b5d780ffe3mr2459840pzb.15.1673423171917; Tue, 10 Jan 2023 23:46:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673423171; cv=none; d=google.com; s=arc-20160816; b=hu+gTi/CjVx02dvO4zfXugN8MWvpXQ4MiIMGZqJzqhIlV0/i/Ep6dzKgw2PoLZJdmy ulX3YUSrRJEVHoavztJsCmCInUgxtKlcRaV6yGREo2YjsrUJON1XpeSYpcVYBUEPWcGr OFVzLpvIzebw+gIuh299wEBtho19vfJDKF2iry+HTlFS5Z9428NGuUkx8pRTyo/pWf5v 1+p+0sv+6wrBn8r3MMHf6ybE+cJu4OPQy67fErIrrsCQr76/9dcUPGe3auTL3Zk0KkY6 CfM5pY5LMCkD9Ujn151wfq3FmUgJyVTECuUiiKvAhvNRf2C+QOiU0Kbr696/v6M6lyxI OhDg== 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=eiGMotkkWfe+pMgZW3jEOSzwEvwutTLRM3fcSIfDJY0Bvi9ACglGjOpc+T6cyzl8py d/UGL0MfiO3xoawkRyYGiOCbO0KdC8MDq53WS3eMtK9/UpBUgrZj1Etw2UsRLPwjglIK UfAUK15EgeWm4zEiKQf4bUNPRaY4h6avIevJITx5dsctszUYiCKFoNUSwffN6lc+ckc7 wb5mQoWm0VOgVwwV99eTm01ZUPtwabSY/ADv09jy+rCkLIwbCoPZw6VWb2M5C70xZ/Xf 7h1nVv8QFU/tb+BVNfEqFJb+FAS0MhkM4+/kUSZT6eKN770FnRUaHG3eWPxWunI5brJb uVJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AdHiFpQd; 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 204-20020a6301d5000000b004821a35a3f6si14027006pgb.247.2023.01.10.23.45.55; Tue, 10 Jan 2023 23:46:11 -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=AdHiFpQd; 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 S231818AbjAKHb0 (ORCPT + 99 others); Wed, 11 Jan 2023 02:31:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235801AbjAKHbS (ORCPT ); Wed, 11 Jan 2023 02:31:18 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB71DE9; Tue, 10 Jan 2023 23:31:17 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id v10so19850738edi.8; 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=1r7Ed9F2DXly01+3aubMR86oQlV9LwSsJJ5I2jnRnYPIqKUP6wWk19HnUgRZYknYlq PZqj4oGvi2ZERkkSEXd9DvyruVh+ohJ/S9kbFS1VIliLmtVWFey5CjZ5EwG/LkYJaYkt DNhnKHJM6YIcPWrnjknTjEPPVhCYAA8hFbqJizcdYrxYlQTwkh4PC8ILXIuGLvMQ43jD Iax+j8XeKcNWTcgV76nKkyUmGwD8h8fyLYfUzsDCdYolnVOvlJgnxgnvHbUHYnvaWNcx ORNY/Vskuo16jPgqJlmIVrsBV0hADjw7/fruKkVDWyGdjDn1JAMlnWMiQ96uIuwcl5m4 FR5A== X-Gm-Message-State: AFqh2kofDKKy8rA44VQzvfmW/XAyCXwt8bA9wkOErSD3qm1opdlDasGI +d/S9YWUPRzwApHwjNBmj4E= 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-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?1754711375740355562?= X-GMAIL-MSGID: =?utf-8?q?1754711375740355562?= 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: 41783 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3179854wrt; Tue, 10 Jan 2023 23:39:53 -0800 (PST) X-Google-Smtp-Source: AMrXdXutKUrHsB8XMa9ni/S1w1FuhbXGgHphxDTOQOJ1yzPklSylhGMMpW/bcZtmH3IZBIskejvR X-Received: by 2002:a17:90a:d30e:b0:228:dac2:3707 with SMTP id p14-20020a17090ad30e00b00228dac23707mr3220922pju.48.1673422792700; Tue, 10 Jan 2023 23:39:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673422792; cv=none; d=google.com; s=arc-20160816; b=fvVpuzI4IHEkNWv0vUaj9u6erxwrJVx5Ult5MMtU12Tlv6LKI3821ZHaKScvNtVYVA C0KEUI2Q9h7CNtjy/ASKc34g3s7sDcHF13xOZZVcQtM7a+3/uVatbuCI+5XrXkNfhTn9 GqmaliXOTMtzP7Wd1/FtACTQiOWO+810KXphsPxKznSw4RJOI5sJIGOKXSGgd8PctPR3 5ThquYfCJaUugO/WbOLdTkslIoSzR7sRsfNoLZscqtU1eQO9kMyTeXeN/8UbdXTJH91M wFdfXh0L14vP1gGnJ6nnVMjVpnwSHfAapS1CDcVdzlnW5z8kOQ08B8VVjpBGVgRlCkES 8lnw== 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=xUnoAQJt/iZrLVDNxF4zeiLovjV7mgja3YW0R5F3JGM5hrfG5Fo2+DooX6WeX9bp4c LVCwvYwxqsgpK8v0S898rjmFt8AjUNQHVJXU+hnz4Iw7/zpAMzdye9LCcC3M3aho03Xp xKlM5bZoknMKCnCZCC44rkTLFOuCTKfrxkHRoYMvOmzMavQfMZpJT0OAthgksr0dIbY/ cpmev0iJKX+xn0HzBRZX8mLtM5NGMA3xuL45+7ZngqBlxoif3d72tzlz1R4wpnVASlTh XgXZLK0XZxGTDt7pZU+Hvq0/tphKU4erNcceOp95cwwDMrHKbfJDnJY3O8mECNPMSxBm eNgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=oVf3RRoS; 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 v11-20020a17090a6b0b00b00209a3e49f63si16492298pjj.94.2023.01.10.23.39.38; Tue, 10 Jan 2023 23:39:52 -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=oVf3RRoS; 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 S235923AbjAKHbe (ORCPT + 99 others); Wed, 11 Jan 2023 02:31:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235823AbjAKHbW (ORCPT ); Wed, 11 Jan 2023 02:31:22 -0500 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63112BE13; Tue, 10 Jan 2023 23:31:20 -0800 (PST) Received: by mail-ed1-x52a.google.com with SMTP id 18so21067674edw.7; Tue, 10 Jan 2023 23:31:20 -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=vN7zB+3IWeB5ihXdSeeSpdxBc+Qz3/snP1CHajMAiSnqg5+yEqdSqgkgZHS+Q+tfQC BkKXShqGDCrORuyA2TmqIgcTaJxgZBwzpoZEWprs97we4p21dluWSxKZduhsTQ5+pLoK wVjGAtx0YSK29Q//nJhcqtDNAKyXh4gl1ZDRUbxWhEclLP8xly+2Et5XxFLDnyCDfUE8 t3YEOU/RQAFC8wWqo53kMB0RduHdCudDZSPiUPdrzSHwadVCKQFD/p0WlS0z/+GKjXdN 1YD+Je+V7ZVeMGG9Hd9GWXI1vv7gLfJ2t9pqLZNQyHUU6tZex8PQRhfOGvBy2p4ddAkH XXzQ== X-Gm-Message-State: AFqh2krz0fS9wFMl2vQvICtcw4M0sDrMdidutPUSE7fNnU9c3fA/bQK4 PX2xEQgJf1RTBdJW+WDnbXU= 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-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?1754710978006371357?= X-GMAIL-MSGID: =?utf-8?q?1754710978006371357?= 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: 41786 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3181979wrt; Tue, 10 Jan 2023 23:46:03 -0800 (PST) X-Google-Smtp-Source: AMrXdXugVIPK7dlB9pmBJIgXdJ5YL/8ZT+/ykAJ9y+VEfI9fmh+kZpC/TmF08xPymZktbINymarA X-Received: by 2002:a17:90b:110a:b0:223:b920:28df with SMTP id gi10-20020a17090b110a00b00223b92028dfmr73757724pjb.29.1673423162817; Tue, 10 Jan 2023 23:46:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673423162; cv=none; d=google.com; s=arc-20160816; b=oIps+JQW8/A6ug8/MuY/Y2x1MiNuIbZN7OA+aSMMBBpyVkij2cO38jUq+r/Bx2bpnv 6q/SNm6DQRvlt0S/IWtGgj81UEDDW5aWjDdZbbS6s9E/rft+DEklNtnQtcGElP33oIV9 BBSl6xWtdn5Raqn/au0wbonzJeA3UKpbdRMsxbjBdCBh7Wz82xoEDlTCY3G6pIhW2X0/ QUyLfX1ffD5dznk6zqkJ9N1YPiWESuD218BouyxxXabiLFtl+OvRX2EhsLJYGOyr2yYb v5uHhUydZcDaUvLQsW5Z2PoQKWmp6RnyzXazlar6KI6gJ4zyOuU/XzRKIREW+xYdQ6Yj 6BNg== 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=UT2mDTdRVw1jRkCKX1mBhCc9ts+8t/SOp/ertIrHequ3ze03UULqZRFqu/cejdZohD UOURa6EN7f5xZDz8YXR0yVrnLBRJ0at5P5mYEv1SBwiEUHNlD+zJTOfDp4Yt4u610sO+ u3a67oDTepacr6fGQmvMghSYtXdhEJZDR/BZqAOWDhGVjL4vTsxZW9aGk18AXyGcFUIC c5bgSlOYmGNG60qRJqT1omngn4ruVp0V7hAcBy+b3QfOTsntv/2yNCSj+EVlu6TkZzXj 6Mp2DADaY6JQvj8EK5K4jTYatlWbYzmxs08QfsMQIveeiomAw8kmdTtf2FsSQUV870jn rXTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=clAg3pNM; 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 my7-20020a17090b4c8700b002187b07b835si14024760pjb.52.2023.01.10.23.45.49; Tue, 10 Jan 2023 23:46:02 -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=clAg3pNM; 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 S231779AbjAKHbb (ORCPT + 99 others); Wed, 11 Jan 2023 02:31:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235838AbjAKHbX (ORCPT ); Wed, 11 Jan 2023 02:31:23 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AC56C76A; Tue, 10 Jan 2023 23:31:22 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id i9so21101386edj.4; 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=HrXzNKYQ+wV9zCEip116MR4fgObsVZG430i2icnbQ7pQV68BWAQeZ3lKxpd2ntd2Q6 SOXvXF/joFTWqeyjF8dUM53QhNE7phmXt1YSWzJIRG5jpwHOxf4h2Enl0VFX37UwgL1e FCEYSTn6kyvB2YIBvC9b/7pF39URTAYxjX7zbYZFw+aQEz7wkm8R4RhkggHPEnZg2IKo yjYv08clC4VTKeIfrMf19/kR4jHd0CEOQHYvQjAVuds4ESiw9SCOcdveKdRgcKqxEmZw TQx1FmrKbFBLyk++mUVCSB+ZoA/KrbLhTq7kYt454MRex3S2oJpuWMGpvuu/V+D7C/nc u7Xw== X-Gm-Message-State: AFqh2kqETDcCfKnDAcUsg5Hg8w01O71b0o7JLFZc9lUMf0rMNnYjMb5c i9peJ1XM3eaPU1UbjMOJE14= 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-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?1754711366007022143?= X-GMAIL-MSGID: =?utf-8?q?1754711366007022143?= 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: 41789 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3182094wrt; Tue, 10 Jan 2023 23:46:23 -0800 (PST) X-Google-Smtp-Source: AMrXdXtUSffeRpBYeD2Xg1Pzo+4WSQwKEXR78glyIpJ+jpPTrPwJQ+VGGUJM+sQss4swB2YumilI X-Received: by 2002:a17:90b:902:b0:226:164d:a19a with SMTP id bo2-20020a17090b090200b00226164da19amr1383064pjb.49.1673423183336; Tue, 10 Jan 2023 23:46:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673423183; cv=none; d=google.com; s=arc-20160816; b=WNQcyigfuKB9Zc1NCD7O12UwBCUT0QVyRO/GChzLS44a7lXGdmnoGNi0PvXCJHf97H cID9hqpJxvOXI/hArGzGaKWizodoeayGQw5uj98Oz2D61jdO/mjV0KTBRkiHJX4ABdgo Y0CfDcGPd+EWD0CTloINOwlNQ6aXNjeFKryPbs2gkTsW4+2LI8kwQj0z1tL8VOcaGYhg nx3C6CCs3qmATkFOX37ih3UN5VQMLOKJQ9cH+p/Ire3pnTRwee/lVoLxlsiV6crXXX4D m3qfnE50vcSgRGN/ncMdlzt29P6WrCz/4if2e8/o3CcdelJOgNz+QdTw5S+rkmvNnEvC 2gWg== 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=9ZG5/dJfEvlfksUEy4dZqlxkQUvfDpGnkVNpt/A8DFM=; b=rlVuZ/jt3ydiv6McGVfOU4yVgOtGv1eQ2219tWL6xJodGBeUrsTPZeCaG7t1jeKZlz b/z1F4Gkfv/iCeJzvuQTSU7grTSF/UhC4VgP2lQWaxZoBsSBfHT1fvEo4cmb15MQAfCK tumAsyxplFQYKnBAtI5+IQBB1BZ6KQTiLyWblpZMBOxMyvx6+2EEUi1tWwpNAQ4z1jbf Le5rSLVy7TcjcIALctUpIDJusT6aLQfVVsgTUkqUVFhSz+2kx1M8sw2jR0fZ0ficf8ZM +2j8xFThI54w4s9Wlg/bA8RhfR2Dto+TpiWItbwGSl4u2wX0grul+/Bq/YZ0AN3KOwZJ SNaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=L7tzBu0D; 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 j1-20020a63fc01000000b00463dbc5cebfsi14166392pgi.67.2023.01.10.23.46.08; Tue, 10 Jan 2023 23:46:23 -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=L7tzBu0D; 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 S235995AbjAKHbr (ORCPT + 99 others); Wed, 11 Jan 2023 02:31:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235907AbjAKHb1 (ORCPT ); Wed, 11 Jan 2023 02:31:27 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 107F7C76A; Tue, 10 Jan 2023 23:31:26 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id j16so21067663edw.11; Tue, 10 Jan 2023 23:31:25 -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=8ILzlPluDnq+4TKJ7QPAtdLNLtphxVY6qX9DH8E9iM4fn08ho0jzVZDlo7xOgL51dr nfqNay7PpiOp58Lg3vr+RewaA7gAMfjpVN78WbzbGWvA91j8tCmKkWPLrGUwnYp/XNFG YwvOpSWj6cLMsYS3F/TEDhtV+g2WU+BnLxmT3h3Yg3n27A+mOvMhlQ9DJB2MjOtbpfR+ mz27I2InWTNlDtqTS2Z+IYuG8/EWKJFj+O087CeY3Kfoy6r6DmDHSya0xocu5fU/p3uV aHz8oazM3FvtukKVIXDMkM4e9NH3filVUiJi1siw1Ib84ftSMzmTnXQpM07iV4u+cjuP l9Tw== X-Gm-Message-State: AFqh2krQsdRjS2NCqHEpV8NTLgSKuvVZhE84mXRx7u4AGS9QvpOtV651 QL5uCSY6u74FleIV6r5Q6CE= 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-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?1754711387383912622?= X-GMAIL-MSGID: =?utf-8?q?1754711387383912622?= 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) {