From patchwork Thu Jan 5 17:10:38 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: 1722058 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Jc/IGmb5; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NntL36FVfz23dq for ; Fri, 6 Jan 2023 04:11:39 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 55FB3855D3; Thu, 5 Jan 2023 18:11:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Jc/IGmb5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 08229855C3; Thu, 5 Jan 2023 18:11:12 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: 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,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C05EC855CB for ; Thu, 5 Jan 2023 18:11:07 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=zajec5@gmail.com Received: by mail-ed1-x532.google.com with SMTP id g1so39418661edj.8 for ; Thu, 05 Jan 2023 09:11:07 -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=MaNtjFyAXugDAWX/bR32Dva5wigb85ST8Ayk+tDoGms=; b=Jc/IGmb5ZhCXE5QR+3vxXRLGLCxIDNy2+fy0f2wmt8y0c9AMwje0Uo+hYkNeWMSZMR DxiFw3QRh2bqGnGySwQK2GRJHcvJ6kcg4eJzLbRmcpyP5WSiY71zRV8A8aRv9fUN1hZu gdhDQKZSNSoa05nkLCVrvZLUoxG+0Gf/Y48w/QhMqbA09GTpYUUhki0MN/CRE6vNYTMR /ykxnHm9vtwZqAzTTuFU1kAmAHysvdf97xqQdGDZXWBTYF4mz8BKIQVrX3dnc1G73RC/ zLdR2FQK3JxOZo74xaVXkzq91PzMowGeYVWhuSJqlrvTRYRnSctpYjxogelIlyCXbXpa NaiA== 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=MaNtjFyAXugDAWX/bR32Dva5wigb85ST8Ayk+tDoGms=; b=UnPQPnMGu6oiKTfvNorGt07wTGN0KOx/APL9PwzovXbqrfZyPMfbi1mtdngQHuvjv9 x73Ffs3JVPfJS0OK/Ee+b5qftn+io+6xDQczDGWMeOYjqGDhDmCPexoCgCDvmKRBu+HK 9wnThuEYyWYeY0EP9f4Wi3BqqfLA+uijWTz4ujCtOrkBGLrNg2XT1TPmFKIcwWP2b8by HVnWZN+34kDGDsVvT1ecOlGWvF+UvFxZG/Z1uA7xTsVk+LmHN+wmD44afShKXjAu49O4 TeDTAnQGPB5qnJh9iRMS7XuJ3vU9TbNInBQw0Xk6VYrNBWYM3naxvWzLuytHnpN3GI+c NX0Q== X-Gm-Message-State: AFqh2kpOB5NmaG/NJznL+dvp1bR1sd9xP05xFfIoeHS69mYH+HcGNcGe ZE7XMueVGVLJc+Z0qzBTcdbKItiy37I= X-Google-Smtp-Source: AMrXdXv5zDOsStIlsnwT9M02nEHELn4C8qBhZMwS49BaMy0TTTD9iNc3SDUbaUdl9yMz/XOGOycK+w== X-Received: by 2002:a05:6402:2072:b0:487:6d4a:444c with SMTP id bd18-20020a056402207200b004876d4a444cmr26202520edb.28.1672938667401; Thu, 05 Jan 2023 09:11:07 -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 cn9-20020a0564020ca900b0048fdf37c441sm1714829edb.3.2023.01.05.09.11.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 09:11:06 -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 3/3] nvmem: u-boot-env: post process "ethaddr" env variable Date: Thu, 5 Jan 2023 18:10:38 +0100 Message-Id: <20230105171038.13649-3-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230105171038.13649-1-zajec5@gmail.com> References: <20230105171038.13649-1-zajec5@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean 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/u-boot-env.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/nvmem/u-boot-env.c b/drivers/nvmem/u-boot-env.c index 2a87dda45188..54283f8061b0 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,26 @@ static int u_boot_env_read(void *context, unsigned int offset, void *val, return 0; } +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); + + ether_addr_copy(data, mac); + *bytes = 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) { @@ -101,6 +123,8 @@ static int u_boot_env_add_cells(struct u_boot_env *priv, uint8_t *buf, 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 (!strcmp(var, "ethaddr")) + priv->cells[idx].read_post_process = u_boot_env_read_post_process_ethaddr; } if (WARN_ON(idx != priv->ncells))