From patchwork Fri Jan 27 12:57:04 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: 49369 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp824303wrn; Fri, 27 Jan 2023 05:10:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXvEvfeLvAWIk8DyjJ/+hWZimEh+aYmjAUHtBGgtcGjB+I4ga9/BL668VXDgne3gUdybg23Q X-Received: by 2002:a05:6a21:3982:b0:af:f1d1:6f7f with SMTP id ad2-20020a056a21398200b000aff1d16f7fmr43520996pzc.31.1674825021293; Fri, 27 Jan 2023 05:10:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674825021; cv=none; d=google.com; s=arc-20160816; b=LCDWD8c9epte1C1CAvLQf4C0lIpn7lkxlA1UFWFnnRUuPnwWJX6wqstN+8oJ0qzyvL FsuEJf86WwOC1CQJQ4zCDap4CPi1c0mqqmDocwJVFev3tASLOL+zUm6EFqEJ5Z0Aj2la Wua6H0gwB6I2Si5amI5rsMfcHndVSnxgNWPLfslkS617UV2jzrxLA1Hb3s0GIvxDfGSA RkLPTwQEHrlpZ93WcVAtYKaBmREwJPYVO8mccHTQOClxrSQzojoH0DW2tEixk2zxfKOU d/WkhZcLscNA0DhyQ+eEn92Xkz8Z9QjkCmQP9wiHEki4hXJdYZtkhjx4zDBG6EWhGHhH zZmg== 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=WSGMh7tRNAaLj5yI1m4PdJqLgl2acNMOyBtFtlK7OZk=; b=PFEISPsqVhyWDMRjZWcVtG8x69RRCDizSiIf3BoOEjtQgBimmDdh+ipuVRpEPiKTTf kgirBtw4OGxgPvW8ei9Y8E9UX5Xj9Xniq+jR8ZOwAxGfEF33QK5sD/Rs07iXicJ8Yo8t /OOt2O+SOazLJNBsflU6jMcezt7TO42PtXlGo1aZSoiUQU6PtyyMIV/L9Csx2Zk1Q2g+ 0jSxF/uqoVp6EayY6/2Xhd61G8z6I057tC/Um+kNdEeNvtcMQh0p7+CEmTl34urAxoAK G4xusF2/AvfRuPuXdcPklwIapHRfMeVP7SozNDNPbCOMqlFMhNkjw4YCHB43aBUXHVHT sugA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=QwChc0PK; 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 l123-20020a633e81000000b004dffd0e0409si1695223pga.518.2023.01.27.05.10.07; Fri, 27 Jan 2023 05:10:21 -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=QwChc0PK; 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 S234132AbjA0M5W (ORCPT + 99 others); Fri, 27 Jan 2023 07:57:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232727AbjA0M5U (ORCPT ); Fri, 27 Jan 2023 07:57:20 -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 0380720068; Fri, 27 Jan 2023 04:57:19 -0800 (PST) Received: by mail-ed1-x52e.google.com with SMTP id x10so4631865edd.10; Fri, 27 Jan 2023 04:57:18 -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=WSGMh7tRNAaLj5yI1m4PdJqLgl2acNMOyBtFtlK7OZk=; b=QwChc0PKt4BnWFjr/KdVghPRZqy3T2yTdWM7BYwvCzsYOHWWkhWqkuBK/CKWB+hiuR 74a55Kfc/aa1z76rQBd6a9a0PK2/7SXelwmC88ai1mm/2KEqZNxjUIftDMrUj15rWPo+ J5EohSEHtCCOJfLHHgQszp62I/bCTWMR5llQP9DpchNEnIClDFjE1uJWxxVRi7MgBJCm Q01Subftos9N9h14/ntJjV9G97HO/g0kS3Mx3jWzMRjtIacVz4V43rfM96IPR+d/KrNO Gnc7HsmPRFgujE0Tt/hUyGW/XQepQHsoQZEs1sooSM59OtGkpcXc46d42bUi7YzLvfnk NbwQ== 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=WSGMh7tRNAaLj5yI1m4PdJqLgl2acNMOyBtFtlK7OZk=; b=6gWJPI8bczBC91uGsX6+7ilJu9qzC9FlifdTsCFUihAUt5qbqDxSVnO8UjjXt4d+Z7 BRe5qQpLSP3IxioMVUse4CBbUl/u+hGqBmG17pu13d2CZlS5+IqW7Qr1N/Q1IEl5tQhm O20Apxbz+kXsL6yH+uC9pmepUK3C8X6UldAdE2u4BhBGD4+BWRUO8lvtEPuD7SDiXROG OZt447eQ7mehw9H9zaFriJlDxn7GJTDORxKdICqs97CUDgtgDr82+i5RGLbm5T8HUJEQ 8XMsBtUhGTxchuERLa86jgGQ7jmTghcjJzReqMk8SEXSIgh1rLISoQxa78EYb+/JUkbn p2sg== X-Gm-Message-State: AO0yUKXCbIYundQAxL8po3sxdxwtkkwoI+JyC5aOs6fQj8VwGvH8PjXn sriVME0A3xyK5LrbetORi1X/BwsVcQc= X-Received: by 2002:a05:6402:298c:b0:49f:a3d7:b84d with SMTP id eq12-20020a056402298c00b0049fa3d7b84dmr16189411edb.34.1674824237029; Fri, 27 Jan 2023 04:57:17 -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 y5-20020a056402358500b00482e0c55e2bsm2248136edc.93.2023.01.27.04.57.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 04:57:16 -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 V3 1/6] nvmem: core: add nvmem_dev_size() helper Date: Fri, 27 Jan 2023 13:57:04 +0100 Message-Id: <20230127125709.32191-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?1756181321428329873?= X-GMAIL-MSGID: =?utf-8?q?1756181321428329873?= 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 Reviewed-by: Miquel Raynal --- 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 38a5728bc65c..9e77af0164aa 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -2063,6 +2063,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 Fri Jan 27 12:57:05 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: 49370 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp824312wrn; Fri, 27 Jan 2023 05:10:23 -0800 (PST) X-Google-Smtp-Source: AMrXdXsiO6bkyAB8NQVCumjecWD2iOAbMDrZ5NzlSkDaONcte4ikoii1/vM3aFU0DTFNnje16LWp X-Received: by 2002:a17:902:ab50:b0:194:d5ed:b9ea with SMTP id ij16-20020a170902ab5000b00194d5edb9eamr24556326plb.57.1674825022897; Fri, 27 Jan 2023 05:10:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674825022; cv=none; d=google.com; s=arc-20160816; b=aqK0HOWKZaCfjFyx/xu7Gbnwi63LyE5wReWy0hFSuHZPwntS+ms1W/gzUy2JsBxmb1 PGDLW42ZpVIOWL9fmCtpg5PemVSazEzklZZyi/7UdXLZZCiqJiFVM0M7rUdjJgZg6zj4 KrCpDPmUIoBnX7uWbDFaMjQSFSrloOcgEw129BVv99g35fff6rN1ME7lPKqayvYP58nl XtwYwj0bJFS4eMFvvenJzSUiONiy9owwnjlJcwbXapPRAuUbqkuJdyR6ors31Qf23Ely iMdKuanpzLWHE8c31pSk6PSurcB0fy6K9GlJNGNdGGug5eQ8EerRBiOT3SqB4jdKzWXm TdiA== 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=CEAkJYnxqrZMOhdPjkEBTuVRB27vVAzsdoVajeGwdl8=; b=jRZ17USjN6H0Frn10m+q2Ld+dIke46cYJT+ff+WtYu4VXxjSZDiSR+pw2fTiTT1w2s 1RHOuPb/rXAuwLD6HB8OBK0v3pNvMXpjhB4ncvnk4rviG1kZ22MLpll04dUa3+zgCgrp DahGqJ5ho/xIrA4ctWl7pSWiphD4Ela5K7xvaigQuaRh46zotwoHMjTww7WT6ZGnKY8Z eMe+PrHB8HEt8embWv0vK0rTuvuuk8JCp16y0CGSeWcaGAFxKsy255tp1i4izk4H/BOm GV2ifVCZ9LA2j2HhB6rGpy41Dga3VmhuJeCzkZGy3KunQoiU7wNL0CDF9jmCeOJrHAYZ k6FQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IPo67SYQ; 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 o9-20020a1709026b0900b001963a6ebfa5si4399279plk.40.2023.01.27.05.10.10; Fri, 27 Jan 2023 05:10:22 -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=IPo67SYQ; 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 S234287AbjA0M5Y (ORCPT + 99 others); Fri, 27 Jan 2023 07:57:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234111AbjA0M5W (ORCPT ); Fri, 27 Jan 2023 07:57:22 -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 B8D393646E; Fri, 27 Jan 2023 04:57:20 -0800 (PST) Received: by mail-ed1-x52e.google.com with SMTP id x10so4631961edd.10; Fri, 27 Jan 2023 04:57: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=CEAkJYnxqrZMOhdPjkEBTuVRB27vVAzsdoVajeGwdl8=; b=IPo67SYQlof0606s8wMwkmMpL/q0CXu3HyeKevsPA+c+dLT+aacZA70ccJyyJPXKHa JyVuSpAun8AGzuLGmIE1Az6ZKxT6zSb5QuMCdwtPlhZIuBj94hvgKpExZvP2zLeWd4QL dmFGB1uKDmK9IGCiKHS86D8mA1xHn8hKtO7Wu8pTE1SZsLpoc2aKy3VhNuMauJVaeJVt W/rCXahEbFLLQZ+AtziBCgl5XZOXu7WWGjk/scynd/HdrTkHLHUugmZcaGnCoiTHW6/6 rLJV4jR7n0ONzD4vLSfKtApgGqBn8SicP1Pi+ii7qTp+QcUlENMCymZ4hyR2tYL+31X2 9tcA== 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=CEAkJYnxqrZMOhdPjkEBTuVRB27vVAzsdoVajeGwdl8=; b=5quF1hgmq1jihhwgisIVJPpC1TKWwqqwbvD026u0DAOVu9Gq2+/6TP9livVEU1I9g3 5OyjrvnKFu4hL6JHx/kbEJeg2h2tu4rHTdM/Jbhg+SIciAG7DdoRaD3JEKOw2LZDR+4F ex5CtFh5CwS01SDEmAa7Km2xjHezGdn4Iwbn6i7sbQmtkJrvYLUmoWfBdTJxgpODj2Ap Baulnw8oDPtmnYW0eRxPpk8PCk+VQvjWghobR9Dpzazze7iysCUXVSAfu0+6Z87YmP9C Ib9QB+Luq1HFsHqmKLBGKTxZpShrf1hafBeiDdVE7bkaVC4oR/EpIaknc5KRHZUN7/+b E8vA== X-Gm-Message-State: AFqh2kp3tYGhxSIAlRz/LYmG+XZcNQ6TbRnLr0oNupsYURbA+RHGOmEg V/hlyg8BJzB1dS1l/3mlRUs= X-Received: by 2002:a05:6402:3909:b0:499:bcd7:a968 with SMTP id fe9-20020a056402390900b00499bcd7a968mr43322323edb.22.1674824240299; Fri, 27 Jan 2023 04:57: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 y5-20020a056402358500b00482e0c55e2bsm2248136edc.93.2023.01.27.04.57.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 04:57:19 -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 V3 2/6] nvmem: core: allow .read_post_process() callbacks to adjust buffer Date: Fri, 27 Jan 2023 13:57:05 +0100 Message-Id: <20230127125709.32191-2-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127125709.32191-1-zajec5@gmail.com> References: <20230127125709.32191-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?1756181322926262082?= X-GMAIL-MSGID: =?utf-8?q?1756181322926262082?= 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 V3: Don't move unnecessarily code setting *len --- drivers/nvmem/core.c | 21 +++++++++++++-------- 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, 26 insertions(+), 23 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 9e77af0164aa..162054a39fa1 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1540,28 +1540,29 @@ 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) { + size_t bytes = cell->bytes; int rc; - rc = nvmem_reg_read(nvmem, cell->offset, buf, cell->bytes); + rc = nvmem_reg_read(nvmem, cell->offset, *buf, bytes); 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, &bytes); if (rc) return rc; } if (len) - *len = cell->bytes; + *len = bytes; return 0; } @@ -1579,7 +1580,7 @@ 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; + void *buf; int rc; if (!nvmem) @@ -1589,7 +1590,7 @@ void *nvmem_cell_read(struct nvmem_cell *cell, size_t *len) 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, len, cell->id, cell->index); if (rc) { kfree(buf); return ERR_PTR(rc); @@ -1906,11 +1907,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, &len, 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 Fri Jan 27 12:57:06 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: 49371 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp824321wrn; Fri, 27 Jan 2023 05:10:23 -0800 (PST) X-Google-Smtp-Source: AK7set/EqFdLIvq4t+8M3H8XyXbtHksWZu14+IVzQd84ixZGZal/GwI9oEQnR3jbyaQ0ZcVpjqZz X-Received: by 2002:a17:90a:14a5:b0:22b:b25a:d0a0 with SMTP id k34-20020a17090a14a500b0022bb25ad0a0mr6561497pja.15.1674825023576; Fri, 27 Jan 2023 05:10:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674825023; cv=none; d=google.com; s=arc-20160816; b=Jlcki7FN2B48wu8aDUQ8B7G5zg+U6q/vBdtIsuQGtBztRNrFqX2rzC3kqQwhHqUapo ngc+D574CSADKTD6bHrxnBEDj/KspkmqLK4QzIcLV1kqO71A6sEMOfXdrxgD09/qPVlY 1CmI43e1mtevGXa61ww9/X4RNjp7BrPNhkOLC9R2nU7dbWKd7MjqABuzbwZQ0orwAJCd L7bvrm9cj6/ciZquJLQ3QNHSqLGSknLeTYWuOxDw5kWMGZpbktvGU4iL05KASDEHH407 WrtgIUcpEFaUJqpjVUW+7MZfHOkpjZusaj2O+RL5WU2TAlur+KzkMj5iBCe+0JW3nFtw dFbw== 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=lu06/R6jtaPsdOb+3M2mEKtYsdSHx6tfbfAcrndOQiY=; b=rpo0hY7EVEpb93qqTWvg2VQQN3RNhGGfPN3aGNX2UpH3c3I4cquEV0SEg+4+OGqtp6 RiYUh/tEvEmEEFPS5Xb1E/dT1ydCKl4DKRpUROciaJWGYGfLRcJsAxjHCfckdKXu8LCR nol7V3bKQuQGj1akO7s87glYItkM+xT+hZ2oks0OIy+WCmKcPkppfu3kZ58tw6TM1NWR ThtjLsy0JYPNZxHH/msZmKb2uv6sAFjwl0rI2/tllg/Xi/iw+3eaKH7FCE8qlfxQ2sWz zlgYY4gaFnvbXofbkIbtPNQB5nalpmg+jlSxiQ2E27jehDVFo5/drD+vxq3L+M56FrxF srxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RDP38X1z; 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 mv10-20020a17090b198a00b0022bfa408e6fsi4416809pjb.44.2023.01.27.05.10.11; Fri, 27 Jan 2023 05:10: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=RDP38X1z; 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 S232344AbjA0M5c (ORCPT + 99 others); Fri, 27 Jan 2023 07:57:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234467AbjA0M50 (ORCPT ); Fri, 27 Jan 2023 07:57:26 -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 64B317D299; Fri, 27 Jan 2023 04:57:24 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id p26so2233320ejx.13; Fri, 27 Jan 2023 04:57:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lu06/R6jtaPsdOb+3M2mEKtYsdSHx6tfbfAcrndOQiY=; b=RDP38X1zJPgqzvN1XCkEq4SVPmTQJgz+TtoZ7p0KPbx1HzpefwgV2vrv9+u3ztby+C qEuJMPPnNz01zSJ+T+PdJoEC6KDvVw4vaT0vM1cAwh4t5HDF7UiAmhA5k0+R0bCU9NKn CIr0AQlSY9uqDjDhm3imWKkQQeDamC2guKI8dJTdCR0mASfR1Et9eG8Mhj4r3GJcFUtS SDhDg7+5ElZpS0RIMNnMuu4LlCtXGXsrT0GXlR7tlOOkpZ5/AkzbbReCT9bDTGlPWXba 8xgLTnW16ajKyA4K7/LcpvJcvIqTPg+0v2/R8gaMmkqll+bDZQMn6SOPUY8tv+m5Wvtf Q3Pg== 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=lu06/R6jtaPsdOb+3M2mEKtYsdSHx6tfbfAcrndOQiY=; b=zMBJYIxTCYJ/drcfRGBtXI49E1swbBnfqoU7LUApdHOUaEFitHMr3Ro9BUGS/tHoXl RycYyGEv3R1k40nMa4XG8HKe9I/XH0Nls0a49AqXntpEV6fAQaSDQmdp9kDrgIFU2dFM gLwC1MS0N6cdquBO9o7DspKixSMGjHqLtHAPOPBqAlBbcmeqThyCP/TBAujunUnhPjib HDXDc8Df4QmL1vxSVPQiQW8pGg+b4JuRtSiwXcADZ0WDHTgtYWCK8uJJ7mcGOTNNsu+b Kyl2c3t08yRNolsxxJegRZwArJN9lg8c4LtPeXnt2Dqrkx5HUYM9DpLKbqCBNUgdwoF1 rpjQ== X-Gm-Message-State: AO0yUKU0DbCETvjKjOdCynCN4rxmixMSIPWLW29mBjcBByTnJqUckHnj eiOSZhetRFlif+l6bncdwmZsNvSCkw8= X-Received: by 2002:a17:907:7f25:b0:87a:4802:cb4f with SMTP id qf37-20020a1709077f2500b0087a4802cb4fmr3981598ejc.76.1674824242666; Fri, 27 Jan 2023 04:57:22 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id y5-20020a056402358500b00482e0c55e2bsm2248136edc.93.2023.01.27.04.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 04:57:22 -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?= , Rob Herring Subject: [PATCH V3 3/6] dt-bindings: nvmem: convert U-Boot env vars to NVMEM layout Date: Fri, 27 Jan 2023 13:57:06 +0100 Message-Id: <20230127125709.32191-3-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127125709.32191-1-zajec5@gmail.com> References: <20230127125709.32191-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?1756181324168530407?= X-GMAIL-MSGID: =?utf-8?q?1756181324168530407?= 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 35385df2302c..1373154c0b49 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -21214,7 +21214,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 Fri Jan 27 12:57:07 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: 49372 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp824352wrn; Fri, 27 Jan 2023 05:10:28 -0800 (PST) X-Google-Smtp-Source: AK7set/QzDyMCTXHgi8MwMMF4BnnL4k7VNjRoh5StwPkXB9mePEbmXnz7eYVyYpSU973m8waSN20 X-Received: by 2002:a17:903:11d1:b0:196:489a:a79f with SMTP id q17-20020a17090311d100b00196489aa79fmr4770871plh.6.1674825027776; Fri, 27 Jan 2023 05:10:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674825027; cv=none; d=google.com; s=arc-20160816; b=drGFxLDD1alHIDz0i1yXICd+HVt3P7lR4Qly4VMzuh6V/LJhU0khvxwxgCnELDMx8a sklv9+534XbdvwVNC3xlFmNhxajKwtfoggfLX5UlEM+BK3FGTI5d/ZFPieHxMcI6fxy6 5ExeliUKDa5pgzEondUAxAG1RNO/JfWdfrqNfYscfsEGtvcr3opLWEKtwy6qgpFzRlXH 4+deyrXA7U4Fi3tYG9zkXsoYYQZpw+T5B9NbDYGYF5mVdXv45P35Ouyz+orgvEnDnXnW Lek2XDTAMq4XYrMFE/6b0z+kz89ryqsWJqlydNLolRWmWc3ChGfW8V8u0+F1ITdnzPrM IWlg== 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=DOA6rTzaxoDT4ywl6BgnOBO+LKsBOsMxhvInNbwGkrI=; b=AgpLvfvCNgOCLVeiAS9S3SeZ6f0ejBAusgfRHR6mRCuQbe16PgiKe86oUbLgbFy4zd 4/6vPZHr+56p3AiMjg7nRh81Wph8SNaea9noHPQrJdj5gXuJ29OWgRYlkfj+zX7XgsSf r7QsnB2vvUDbZihr5bnMPrrpIaQpQAJUvXU3WsPyyn27CDHUfp3HQoFJVPwhpWTZdD3X CqR1oyYooc4AmyDPW9NdkGRzCLxBPabPdH2egGOCMTbHjZmccYuu4PiXPI424zmYs7ab kNxEFcSkUbmVNPzcesMdgVtsq89Qo6osi7GMHyOeAmahUZUVbQfZ/WdBLstfr0XZ/mK2 2a7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=IjwirLhA; 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 k21-20020a170902761500b00178b95aa01fsi4265216pll.614.2023.01.27.05.10.14; Fri, 27 Jan 2023 05:10: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=IjwirLhA; 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 S234485AbjA0M5e (ORCPT + 99 others); Fri, 27 Jan 2023 07:57:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234490AbjA0M5a (ORCPT ); Fri, 27 Jan 2023 07:57:30 -0500 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FC5B7E049; Fri, 27 Jan 2023 04:57:26 -0800 (PST) Received: by mail-ed1-x534.google.com with SMTP id y15so3982743edq.13; Fri, 27 Jan 2023 04:57:26 -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=DOA6rTzaxoDT4ywl6BgnOBO+LKsBOsMxhvInNbwGkrI=; b=IjwirLhAdzlRXR/s6OqoJTtmgPGzYR0IM4XrG73eA2+frp4UGr5Na7UF1dk9VnEIfL IkvoznMsvp/rZj8585AO+/+99rLeMzfBlaEHo7o+PWIfDd/4Txz3UnZ3GLI8hMpF+DP/ wcmJFslXMKaO+E9o2O8xCuMGjHwAkIEPiIItF1o8ASxEyuArvHzB8VLJLwwlDgqOyaUs qD6gOLEeeANjdn8AM/riP+H+BuIs/nS8PNBVHrTqP+nmULm6/1NyDFvjT4wCS1uGvRP9 yp3mcJjpAfABA0FHQgJfj6VfMDOExrtjB7VTeB9aibc8zPzbSmq0UDinA59DvGKq9Bn9 I7Pw== 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=DOA6rTzaxoDT4ywl6BgnOBO+LKsBOsMxhvInNbwGkrI=; b=L1eaKJ86//9UZvRwiX30IZrH9uyAOu9NMjf6F3QUWQTH4MxR1g2tGdX+koWLum2Zrn /twVqshgal83AP0IyXSFb7pizboxgbkxUEbZtKzL1K3XvMiQr/pHF8HHMwh8yT2x2F5R vsMYpBRG8dTL9PwHCR6TDlWgLCfwQ1KxZaz1eVPmUlerDzI4WkNM3BSxx5XN6o7A+C7N FWEKZL0tiMWO3o2sby5qneqEUubvinVYnb4FbFbPxTS+uNP+/m0T7K0s3ZzjRhKJE+/7 P3fy/3mhz9Ye3Dmr+TaE/GvY+WxpQBBwzTfPR+XclBatLy+IjjVHqCOPPmRC3oC268Y9 1npw== X-Gm-Message-State: AFqh2kq5M0K4AdporQbf4+0Lrt84VQq3qsNITiF586EPdoeH+o2yat4u MIqdjQWVVbQm3exbmZwVgE0= X-Received: by 2002:aa7:c393:0:b0:49e:6887:9f88 with SMTP id k19-20020aa7c393000000b0049e68879f88mr32885581edq.29.1674824244643; Fri, 27 Jan 2023 04:57: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 y5-20020a056402358500b00482e0c55e2bsm2248136edc.93.2023.01.27.04.57.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 04:57: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 V3 4/6] nvmem: u-boot-env: convert to layout driver Date: Fri, 27 Jan 2023 13:57:07 +0100 Message-Id: <20230127125709.32191-4-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127125709.32191-1-zajec5@gmail.com> References: <20230127125709.32191-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?1756181328188124244?= X-GMAIL-MSGID: =?utf-8?q?1756181328188124244?= 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 1373154c0b49..3f58e14fba6f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -21215,7 +21215,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 ed8ef7460be2..789729ff7e50 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -338,17 +338,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 f82431ec8aef..442f9a4876a5 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -67,8 +67,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 Fri Jan 27 12:57:08 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: 49373 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp824381wrn; Fri, 27 Jan 2023 05:10:32 -0800 (PST) X-Google-Smtp-Source: AK7set93jq0HkPOyZemqgKxRfK9Q3Gvw1ARqXj+AJ6FV/w+3KeA/1wD7x2wh8ueFKWqqmdKSiZwV X-Received: by 2002:a17:903:cd:b0:195:f097:d65b with SMTP id x13-20020a17090300cd00b00195f097d65bmr4021550plc.49.1674825032132; Fri, 27 Jan 2023 05:10:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674825032; cv=none; d=google.com; s=arc-20160816; b=aTxpuGWhb8WecMTKWF1TwiaQvmaU2il/WOwmVKFPHQaiUTb1CX6v6x7kfcVGRQE/RK 4fT0wjEkE+tEYJx7TiuoPUa3SxrPQ2oEtOytt8KP4BtTVoV+I+1XVelv5UcdQ0vZuPUg U+f0K9t+iifIOiSQyvaScBJaV3scG5JYg7kQWW29SKTMBKAOp2xiL2p5+M7q9KtSmJgB rdMf0ndzduIDTYdWwlg4X//M0v48uFTSR9tP6uN65F+saRmGBumJO6BOUPz2w+5RQpZl dU2QBwVNQB44rfWcgGo7va3RsxmIkSvS1N8FC/ariOvuHbKLYXc4iYd2M7YLWevNhe9N q0Ig== 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=YWNUjeJHZnSxax1J2QjLkizJUwF4ziE2YWbkX0rtPtc=; b=AouBB/9aWnbB46iLwSQCeUUZiv/qGzbrlLEfoOOMDtt89SO9WHgRiIt5dpGcZWqzud HO64PkV2VoWZfhUrQ/ztRhsQ1fI8IFsaIuDIpNS61406hcOjnfywCmptr+6HnJ941GAY 9u6ODISEABLbu3LMkj4wqC+82DIOpPtiJ3iRf25zQ6mmGEi3qHaDD4xHOqENMkuvix4m 1Awc8HsLVS5+Npaep/bfW9EjPDe6RL+5VwIO1+2R7hhiR/Ro1ZU3qBROUdzLqpvc0ceS 7xR27U4ayNtMqRqwejFdU3XNF68pYFY007mN39JEbXVBox3iUZFyymYE+v+iUwMYT7e9 dd8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=nLzIreB5; 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 t5-20020a170902e84500b001944ced796asi5177250plg.125.2023.01.27.05.10.19; Fri, 27 Jan 2023 05:10:32 -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=nLzIreB5; 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 S234496AbjA0M5h (ORCPT + 99 others); Fri, 27 Jan 2023 07:57:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234499AbjA0M5b (ORCPT ); Fri, 27 Jan 2023 07:57:31 -0500 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACE577D6C6; Fri, 27 Jan 2023 04:57:28 -0800 (PST) Received: by mail-ed1-x535.google.com with SMTP id y11so4656519edd.6; Fri, 27 Jan 2023 04:57:28 -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=YWNUjeJHZnSxax1J2QjLkizJUwF4ziE2YWbkX0rtPtc=; b=nLzIreB5ldC6Mp5rqVhPzuPxFbBJ/iBxrU+VlBRAVm43hgO6dsx9XK0J0BE1Z/iYGE WcVyHAcJvvYBynwjHXkdR34VzcyeNSCGYVtBfQth1l1h16TbdTJPAivb8BfifmS8/nlM MWpFiH9oggy1HEBeOVKqmPHKudXjp2m83NMfzeweSC6qnOj8w4FiPr/A8JkKybI9ZSvN T3VcZjEB0mXOXZpPwhVTvaecKa9dKnlL5dWX2IDRFGzm1dBsjfr7fQGrCEmomDOBGQ2Y Tke5PgnbquaWAQILFe2AKvPwPxpEeg0SG0XFOv8Olh5sbBZW2+mUqEMN4ajEwip94fiX 0P8Q== 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=YWNUjeJHZnSxax1J2QjLkizJUwF4ziE2YWbkX0rtPtc=; b=Xn0ZnsMkh18ssPH0BVIhGk328jQ6bGsnF+Mb6gOo0UA1F5G+UYMaDE4RWtg4KF7Mdm ysKc0eBJNPW+nN8UhHQTwGJVNESYRsDxPzMyiZqs431edLa0jJbRm5g8cC7+XFAGI9Oz 9YURVwdFkIhl5Dgm40k8hGxppSssdkV9+b1BeQ/cEOHnflWZfs1QHeBAovliXzLoMbJE 0rV/Cvwm+lvSwD4XfDw/tmQJDw94+YlC3QjsiKQi6Y5h9ax4FiYoGHPAMDfKL7/S78AP U8We06qpGpfmrkhUGmwif9ZHZ1ajnO3jMSqvv7NXiM8pcdQMuhwr8ujVAU9b/HpNZI4N pHFw== X-Gm-Message-State: AO0yUKW5pLfzBu/vRpPhy298cWg2vtewc4nn8x+taksdt8COJGMvC2fe 10d9wSgKljjpxOQEfRPP9CA= X-Received: by 2002:a05:6402:320c:b0:4a0:b756:cfba with SMTP id g12-20020a056402320c00b004a0b756cfbamr8972644eda.32.1674824247045; Fri, 27 Jan 2023 04:57:27 -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 y5-20020a056402358500b00482e0c55e2bsm2248136edc.93.2023.01.27.04.57.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 04:57:26 -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?= , Rob Herring Subject: [PATCH V3 5/6] dt-bindings: nvmem: u-boot,env: add MAC's #nvmem-cell-cells Date: Fri, 27 Jan 2023 13:57:08 +0100 Message-Id: <20230127125709.32191-5-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127125709.32191-1-zajec5@gmail.com> References: <20230127125709.32191-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?1756181332708076767?= X-GMAIL-MSGID: =?utf-8?q?1756181332708076767?= 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 Fri Jan 27 12:57:09 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: 49374 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp825021wrn; Fri, 27 Jan 2023 05:11:43 -0800 (PST) X-Google-Smtp-Source: AMrXdXtmtoqh9lRjyDWu5FkO1fKVA6RVYjphYKcyngrRfc35Vcq71be7KpV1flwzwL5eMZs59lK1 X-Received: by 2002:a17:903:2348:b0:195:ed3e:cfa8 with SMTP id c8-20020a170903234800b00195ed3ecfa8mr30919041plh.9.1674825103377; Fri, 27 Jan 2023 05:11:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674825103; cv=none; d=google.com; s=arc-20160816; b=NMEUrAzhPRowjrfkOyP2mxLlPYf2CD2t4d+X8k+IsVow5GewavkMQOLeW7CvaFCP5b 7DTSNjJHf0d+Trpcz14OLTv2hT1dA41r8Cn0738x0Hp6vjREiqlqYOrTkHdOKM95VKnp YxG0juS0wy3biFGo5nMhQEzrst3M7MPVBa+1mpYELdZvd3GDDoyuZBqrD3g4vTzCGTNU jN7ndAsbVBd4w1bnnRvab8vJnrDG0oGP3Wny6WLwyPurITWhwz0HWwAHkHwFvAY3M9NK BZXikUg7/pVhRyKbMG0+EjVs5Q2VUB00jsFOqRTeokxQ72jkU5FqxxM/qX8r+WlIKCw2 46Jw== 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=00D1C8yg/+1dt2ITaNNgv9jvHd23QxdCvFwz/QLKm+ErR+67s9558epGMX4pH2p3/K TxvmQ3idIp23sjhVqkCD3kfy0gKvXzb/CBrXm35YeObTkDXXGBNX5K9Ggz/VrPr7i5jq H6MtsmEewxQHt+6qC8lAGtYaVi6ovw7jERKgE9X8t0DZZAtYnXmV2fDNpEPaUvf2OCGX E/Vr5fmFhQ8y7WmcWiwyestIGTLmrZBjQXUP/h6NXz5XbDm+2FOImJHt/X8O4Fvpnze3 IcyJypiihcNHPgnr6pV4W+F4iMLVLK6milMfOiggh4+t+8XrOh1RdBYKZwosoejzXSTD 21/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=EX3d7D9g; 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 k13-20020a170902c40d00b0019608f59d65si4989153plk.616.2023.01.27.05.11.29; Fri, 27 Jan 2023 05:11:43 -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=EX3d7D9g; 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 S234519AbjA0M5t (ORCPT + 99 others); Fri, 27 Jan 2023 07:57:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234512AbjA0M5n (ORCPT ); Fri, 27 Jan 2023 07:57:43 -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 B34EB7D28E; Fri, 27 Jan 2023 04:57:31 -0800 (PST) Received: by mail-ed1-x52a.google.com with SMTP id m12so4658716edq.5; Fri, 27 Jan 2023 04:57:31 -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=EX3d7D9gnItYT1rU6c/kJyqXPYfLJK0VS58ySEa8KxtMm+SfJqn3lQxVk09N6+0cCT kl8DduwQd8D+ta6lsxIUn3FaKKsR28tvCVCEu4JyFLzf8ukjn5p7JwgZLFzTLpIkcomx 3hfIzFHnvUquZFohcnL7uBSbixlVbDLaTK0t2Q71quau437fCyVkKwgx0o8TtvwfgG1J rfxZsv5iSj9m9br8IPfIi4MVeiwAwFTg6CIYcp/sksPUHqu49wiFIWu9urk0YoHrriqm sXnvzEKRBBSRtlp3I6E2j4S8O2l91TxyyS7G+rPgV84RWPNAnwFNimu4IOaXMgPS+0jt Wecg== 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=6uK4ehbU2/VMrQMQRFoqsigZMq0MXghwLi1+uLOKjKh2JzqvCQT4FvT3M7NLoJJdT8 +4N/N5AUq6S8DGo3cZ+X3fac4ygPVlBX+hl8+pNGRd4LrHx4/vK4O32vw/wr/5R+m5CD 6c+5ILeeJ3/D6oFZS4HqIXdWWj0I13W2C7yl8SJdwI4b0KEaM4f3jxv8oOTSMaLCz9gb oDQCVxf57Spmh3ZVK7NzCK7vfpZ32e8lb5EAf7NPT5Ps0nAkp2x13pQ5viBqHH18ZtsK LRm/Q4HuER8MbUuf4uVO9V9SKC3XVVCnuERHTXOOEfPkf7lmXrk9YsZ7BvWii1cPaoaR Adng== X-Gm-Message-State: AFqh2kqU/T5Quh3cTk02ENLIw1fhS7BQAPUwBOox5c3w8j7XYB2yGASB AaB5iLriftZ/w11mxAkcM4U= X-Received: by 2002:a50:ff12:0:b0:492:8c77:7da9 with SMTP id a18-20020a50ff12000000b004928c777da9mr37459278edu.9.1674824250105; Fri, 27 Jan 2023 04:57:30 -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 y5-20020a056402358500b00482e0c55e2bsm2248136edc.93.2023.01.27.04.57.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 04:57:29 -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 V3 6/6] nvmem: u-boot-env: post process "ethaddr" env variable Date: Fri, 27 Jan 2023 13:57:09 +0100 Message-Id: <20230127125709.32191-6-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230127125709.32191-1-zajec5@gmail.com> References: <20230127125709.32191-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?1756181407832476760?= X-GMAIL-MSGID: =?utf-8?q?1756181407832476760?= 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) {