From patchwork Tue Jan 10 10:54:25 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: 41401 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2677318wrt; Tue, 10 Jan 2023 02:56:27 -0800 (PST) X-Google-Smtp-Source: AMrXdXs0u0+r8Y4JfH3c+ITxt2SCADFtEii1S8ms1JcK8H8zS8Sb4sRzGWFzlXH4afY2UxQDOgL2 X-Received: by 2002:a17:906:185b:b0:841:e5b3:c95d with SMTP id w27-20020a170906185b00b00841e5b3c95dmr61646872eje.30.1673348187095; Tue, 10 Jan 2023 02:56:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673348187; cv=none; d=google.com; s=arc-20160816; b=j2OWdLjVoti+xj1Nmg3u6F+biZ7+GroCaoPTj79Ac1IdOWgo/RFj0a7hXzphDs7X8m EEqCA2ai10L3Q3jZl+WY+Cfa+aVc/x1nPokYStL7KNbHUAYltyKKO2KsKim/SIhH/4B6 UZ1vkmvCZi1k7+zX8VU/HRidtUaNVoJNJ9QfNvdZEZx2ZbnvV3VXKWY/tOXyxwXXYAcr Hf8Wz1rpmfpmjOelYStH247HZAx9m9eA31WP5Dbrcpj4+L+X1hD0LWmBw1qcOYVRkNcJ nyplCiRIFunpEJr0rgnc2vfh6nObS38qw9GgeJTppY9WSC9H8ZtaZyF0tR1mFbYwWTzl 0EJQ== 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=wAqYvgRzLQ4rzA87QLNuurx0Mvg1Ygp2KEVQbcFxer4=; b=L6AFIqCVTybT8iEGmBKsoG4d0bEfQ3w7Lr7W65EQl7DfJ3dM3eqBiaDCeKY8MiLvHE OqwdAoOOASQdt3y9ePjEqdy8fYMNYtu0hZKIIdAFk5I3nyxbF5GQAJ3rskBHq0Z6CZwF QcS1qhed5iv77y16jw7xCgSWDogTwXzZn8NBl0h1YFyUcu46IjBM3jy+GYnp6kiv0pZ6 gMV1LrOemM5vHJJZSviDA84cZzc2tCbc16h/8Q01Nyfpd4yuiqiwn8C8qlOWL3hLX6Pi UHBUKnbkMKG2wL79GNoMUjER3AtBEA5kJl2cfQbtDiWygheQPoGSVzLNWvSO+gDzHb9E sQjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=SJ7SFb8l; 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 hc41-20020a17090716a900b007aeaacd5592si13702060ejc.124.2023.01.10.02.56.03; Tue, 10 Jan 2023 02:56: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=SJ7SFb8l; 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 S238197AbjAJKzU (ORCPT + 99 others); Tue, 10 Jan 2023 05:55:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232107AbjAJKyq (ORCPT ); Tue, 10 Jan 2023 05:54:46 -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 72F1B1409F; Tue, 10 Jan 2023 02:54:45 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id fc4so27488415ejc.12; Tue, 10 Jan 2023 02:54:45 -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=wAqYvgRzLQ4rzA87QLNuurx0Mvg1Ygp2KEVQbcFxer4=; b=SJ7SFb8lSmxhm2NTUJn6edKXr2E6ocnaCm828IPBngsZmWq1fx4++PuFndDgKs7qoL Cyp2n6vHrRXFGBeDGFTSzfitsjvkIihjc0zpjySshruHuZQGaE4aktnpf/fPhTopvdjx qoJLiT5pX5fxUblFYSWoItSQwavPoqv+8cNMN4/Z7hrRk+D8Uk+rTTfYgKqjTGFzrrJd 04KdQuFJqsa+VHF9irSvMGFn01TYJf06NLJZbGHj5wRcOQcvZ61+Fvk0gG02XTsjvuLx upYWU7na/qKc2fHeox3X0iUXzhxEjK1xfCpQZ9pnw1Y+ZXeD8fre8eiRWY4QJIAjyZ+O N+gg== 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=wAqYvgRzLQ4rzA87QLNuurx0Mvg1Ygp2KEVQbcFxer4=; b=joMd54O3jtxH5ZYAGkG9m7o5deJdPb/MH97YGeP+HZB18ivXN3vjCuSzNx0+bNNvND 028Lmpxw0YAIIYfJuuzqGYVE8rSotDy3SS5WRWVL8LAKYqKDUAt5U6GjO3V4hM/16PMP 6gULftBwcXdQ9+50K2ArJtZL1c6bbWqgxMdkOKQk93GX7JHKkugZ4a/bW9/xeW6vQ6Yb aB4xnbaJIaaJvuXif7SFpjo1DpiAoXbEzF5D6HP5M6QEO5dvcQOVT8RwsvIslc+gvcHu 647s+YcSUAq5A1sp8Aj1qOqpsCeL/ye6XpLKgG80zUOPLJ9FlJIUJIWwe+jiqapik0rD Zr0Q== X-Gm-Message-State: AFqh2ko/hRiqPzeVpEHvE82OcD5d3X2Ttcyj9ZHhrqVm6iUGWpB+LTJJ ElI8Fph8M0FKR+HSbKfjfwQ= X-Received: by 2002:a17:906:5202:b0:7c1:4a3:10b6 with SMTP id g2-20020a170906520200b007c104a310b6mr56805461ejm.53.1673348083920; Tue, 10 Jan 2023 02:54:43 -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 s1-20020aa7c541000000b00495c3573b36sm4818199edr.32.2023.01.10.02.54.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 02:54:43 -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 6/6] nvmem: u-boot-env: post process "ethaddr" env variable Date: Tue, 10 Jan 2023 11:54:25 +0100 Message-Id: <20230110105425.13188-6-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110105425.13188-1-zajec5@gmail.com> References: <20230110105425.13188-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?1754632748369454604?= X-GMAIL-MSGID: =?utf-8?q?1754632748369454604?= 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 | 24 ++++++++++++++++++++++++ 2 files changed, 25 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..63baeb18bd56 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,26 @@ 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); + + 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 +89,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) {