From patchwork Mon Nov 28 06:59:23 2022 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: 26562 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5477879wrr; Sun, 27 Nov 2022 23:02:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf6xAxLNxKa5jh2hX2GVKVHirRj13zuMi1OSrIr23x2fdzfrJj3a8DoB3L8QId5scRdsVO/Q X-Received: by 2002:a17:906:aac8:b0:7ae:df97:a033 with SMTP id kt8-20020a170906aac800b007aedf97a033mr25786494ejb.344.1669618960022; Sun, 27 Nov 2022 23:02:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669618960; cv=none; d=google.com; s=arc-20160816; b=VJAL5rNNk88Y7cMNcN2lzphJl1x955ApHaqTI+whbLY08h/xSXxXPoHlxbbO5Nl0Bw +HsGA7L3Zs9DO4j6oislfGb1dCeYSkqmcNmc4XE6KOLFrvliCGmrA+T/nrSyjOYYx14x jLAWsjlhji2JnZQyWtbfelVdRIXh7yFtCkgT92kK7o2Bbs9sBGHzJR5kdC1VyxipR6tM 9wdskK23Kb8C/OGukWnLjPMvht6GREHwff6s+xJSgPN8uqKTrcbViE8yM0DTy6vFVI4K Lq5AuZrznCJiGtOLwzp0JlB3o34n6vqemrvRxwvTGCARXpEv7u2RiCtTwQ71zZ4HVDbm 0bQQ== 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=OJWjxLIZ+Li8orVpVlkA5rNx5NNvxzopWHGhybrJ+vg=; b=JSqmHOwSsdjZtYlbPdOooDqlxXWuqZs7JFzZPzKnTFXuFFU1Mh2zlG/8GBVctxKCgP WnYQvxbZ1TtGFEay+WSkjYAiqkkokObdzhYXxBp8tNTCHZ11x93OEQsnxhdAgF7R2cZ3 o9woQcaJ2/elUVtqP3Ko7ifEUn51bX88HqgBMvQHeif7pjeET3mLe3Hr/OeYxRXQgM03 dyjLB0CK7l9tcMBWX5tju9OBiHmTphW6P1jEEY/BslFmWe4tsXfsYyIP2CJmvJ062rkP YB3sKZxlnmz51wHVncMIqok1jbE6Rpxv4cGIJAuosGeiXE8XS028+otsE31VuTwPlSFh S1pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="Tyb/aNze"; 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 b16-20020a056402351000b0046a31967739si8423839edd.96.2022.11.27.23.02.16; Sun, 27 Nov 2022 23:02:40 -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="Tyb/aNze"; 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 S229775AbiK1HAc (ORCPT + 99 others); Mon, 28 Nov 2022 02:00:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229629AbiK1HAS (ORCPT ); Mon, 28 Nov 2022 02:00:18 -0500 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC3BC2DFC; Sun, 27 Nov 2022 23:00:17 -0800 (PST) Received: by mail-lf1-x134.google.com with SMTP id d6so15907011lfs.10; Sun, 27 Nov 2022 23:00: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=OJWjxLIZ+Li8orVpVlkA5rNx5NNvxzopWHGhybrJ+vg=; b=Tyb/aNzeI0/O97kORWdBoPLZO+TZxvW1az2Kk+utIvANkQEGC1Jw6dVuplT0gmcUW+ Hjwdumc6BFqk5p0FWAstJXFvewXzANBRypRYIIP95TB4JflyiM5PTiLuoc7ZlVRhn8NE zq3Az0F5N9NqxrfzuJJ8nMx19uRmHNDKKnj8mzLLhBOoWhIeYaCx3w1mxI1VWGrpC5Z/ yVtdrpZu7vY7yGsLuEUYtqF6+bftMvvOQc6tHpG9Ag3eb/VFYppm+ZBG2n5uPu7cRb17 /2CeWoXW7CjUaMyf5Z7cwRnuaG1TFSjfOiMMFw6yfmi49YkkGVlcx9EdC8e1lH0f1Gd3 5I7g== 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=OJWjxLIZ+Li8orVpVlkA5rNx5NNvxzopWHGhybrJ+vg=; b=69mZX5JaN01kp+5mc46qERAxcKcWaHBN0BLmAF5yBuM8B9iJXZALwg/LEd1OooIISW PzQLaF/EwwO2Bv+Dzn7lXINEr6hp04NKeXCFGLH1xesLyNPp6w/M2Kwi9D41pU2rleyb dP6oSZcNTsa4feod/iyuPy32ZxHjF4Xe9iCSta/CZSzG44/rhiWA+3ecwAHVhQ/HpjpN Kc0aLuOzOX+BbVf/CHT713slU7EeZAcBI2HS+XFPqCF4jFjG8XON+sHQt5WMdQKv88pe 9JzM2+1IuYY5kd4hpFVNfqU1/APD7hpNh4ZrbIDav/ZHzUp3AW9a09g5GUQssOlwsVTE 1pGQ== X-Gm-Message-State: ANoB5pmlC8ntMwnKH24OOYZcJkA2QAwUNPetl9bn0iN73xHlebP99RNL hnQ/bG1zJx4eqTu648adGQU= X-Received: by 2002:a19:6b1a:0:b0:4b4:3313:feaf with SMTP id d26-20020a196b1a000000b004b43313feafmr16169443lfa.365.1669618816051; Sun, 27 Nov 2022 23:00: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 t12-20020a2e780c000000b002770a7e320esm1129686ljc.81.2022.11.27.23.00.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Nov 2022 23:00:15 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Srinivas Kandagatla Cc: Michael Walle , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Shawn Guo , linux-mtd@lists.infradead.org, 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/2] nvmem: u-boot-env: reformat MAC in "ethaddr" cell when reading Date: Mon, 28 Nov 2022 07:59:23 +0100 Message-Id: <20221128065923.1180-2-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221128065923.1180-1-zajec5@gmail.com> References: <20221128065923.1180-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?1750722370921601456?= X-GMAIL-MSGID: =?utf-8?q?1750722370921601456?= From: Rafał Miłecki NVMEM consumers expect MAC in a byte-based format (see e.g. nvmem_get_mac_address()). U-Boot environment data stores all values in ASCII form. Add post processing callback detecting "ethaddr" reads and reformat data as expected. This fixes Ethernet drivers reading MAC from NVMEM devices. Signed-off-by: Rafał Miłecki --- V2: select GENERIC_NET_UTILS & drop unused "priv" variable --- drivers/nvmem/Kconfig | 1 + drivers/nvmem/u-boot-env.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 755f551426b5..34fb0ba36b80 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -326,6 +326,7 @@ config NVMEM_U_BOOT_ENV tristate "U-Boot environment variables support" depends on OF && MTD 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/u-boot-env.c b/drivers/nvmem/u-boot-env.c index 2a87dda45188..e30ce4f7ea20 100644 --- a/drivers/nvmem/u-boot-env.c +++ b/drivers/nvmem/u-boot-env.c @@ -4,6 +4,8 @@ */ #include +#include +#include #include #include #include @@ -70,6 +72,22 @@ static int u_boot_env_read(void *context, unsigned int offset, void *val, return 0; } +static int u_boot_env_cell_post_process(void *context, struct nvmem_cell_entry *cell, + const char *id, void *buf, size_t *len) +{ + if (!strcmp(cell->name, "ethaddr")) { + u8 mac[ETH_ALEN]; + + if (mac_pton(buf, mac)) { + ether_addr_copy(buf, mac); + if (len) + *len = ETH_ALEN; + } + } + + 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) { @@ -179,6 +197,7 @@ static int u_boot_env_probe(struct platform_device *pdev) struct nvmem_config config = { .name = "u-boot-env", .reg_read = u_boot_env_read, + .cell_post_process = u_boot_env_cell_post_process, }; struct device *dev = &pdev->dev; struct device_node *np = dev->of_node;