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: 13057070 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1FBF2C433FE for ; Mon, 28 Nov 2022 07:01:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9h8/MOH+8fMO7AjyOSllpa1TYrIiHpA6SgqKhftuZPw=; b=0lUQzi0ad1YWE1 8pCp6Teu2MHVHJgN8+mXpeC7dB8UTpz0RULYCimuKIfq3K9iPpkfKEspjkjQ68FnH5EfnlljrOmGD WQG2/kFJ+0cReSuI+00dVFGDnbtfntV/zUE/BbHjNqxkR/Oa7eRFsTMBAAiDNAeRjK2Fd5d4Ue0bO KFGorMQXFUss3/cCJfP/BZ7I46Ft4GNjlSrV9/qKC/f8fpTDPNgl/7LHsV2x+tBfWimXevwzcfFy9 zGxPxgf0p+rFDZEZMc2B1YuERdW8ZBe8fvkY16PxLxcdb/75/TKKQ6D+AS0vpeWOJQm3pgfAmx6hq S/PhvNz3ILecQRvxcwvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ozY7s-00H3qH-6c; Mon, 28 Nov 2022 07:00:24 +0000 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ozY7n-00H3mv-NQ; Mon, 28 Nov 2022 07:00:21 +0000 Received: by mail-lf1-x12a.google.com with SMTP id g7so15915752lfv.5; 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=69/d2eqheqoofF7NFWtsjSob2UHZnmMbBuT4uQLnvwq7uOgU9kalNxTFZ6pKoJ+Chz wW4RZCjmJQSch7dZdKG4RambTuPnN5eHc37hkqihUvGXg4GmzkM5suNWnhPAPJwcYBmB ZetcMAGonUFU6dXd0wvPgRBOksxKae32FC2xSY/ARZmAPynlAQhTj42y105lLyOIWOkz 4sh6yJI2PEytESJqZcM2bOusj4RXTfyQhuva3kxZ8UE44ETqJNrlouJp37DSXBFOvJas okqngKi6DOa9zSMSESQbJB/j49H5xgyOyDtc6Zkv6ERgF+toll3hUEhqjicb33FpTcS6 AIrg== X-Gm-Message-State: ANoB5pmNC8tiOPuPLqkq5zhnUshh0/i6AVjcWRdeSmr/pPm8HbEzlEfA 46YeKNH7PFDgXF+quSstLqw= X-Google-Smtp-Source: AA0mqf6MDwAz9//kkzdVgCtw2+Ffvol7C4TGrXdX4s+wwD0HRr9r+8MCg2EpImrmXN6Xn32kNpiJSg== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221127_230019_807675_9226ED73 X-CRM114-Status: GOOD ( 15.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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;