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) {