From patchwork Tue May 21 07:13:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1937232 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; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=n68SN0ub; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vk5Jj65yVz1ydW for ; Tue, 21 May 2024 17:13:57 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 981128870D; Tue, 21 May 2024 09:13:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="n68SN0ub"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 20E0F88703; Tue, 21 May 2024 09:13:46 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6E85788706 for ; Tue, 21 May 2024 09:13:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 312B261FF2; Tue, 21 May 2024 07:13:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5DE5EC32782; Tue, 21 May 2024 07:13:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716275621; bh=LGrmxjSoFYLqgfGB/7b+QkRkv/d4ampIHd/wOAXj8t8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n68SN0ubbLhdgnzEmimWnCKzPiMG479ZP+gXSAnGmrN44bzJFNEEMD63QTMBWtHbw QY0PgV0GSxbfazBaU7q4Sv+z/RN+W1y+Q+B0PQgHAgxbYGVR4GCtoK/aFF6FK7MOvp upTJYjRpLLMIlKMtbcUaky4pUSjNrjnNk5tIfsnoHL0RC0M9MqLmUrtBwQCNrzsgAR KzIFMHYq1l8VnDekpeHsZK3LsyygCI+0r24P0cDHIud9cH3OrjhNXV1Vw3mtFZwPKi wui/8FJWE8glLHmUhmOUOfbC4rTep40U7VodYYNEOQh9+AZI7V6ZZVZTUW3PMRhLO4 AzZAhTxP1kYXA== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Tom Rini , u-boot@lists.denx.de, Stefan Roese Cc: Simon Glass , Ilias Apalodimas , Nikita Kiryanov , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 01/11] common: eeprom_layout: Assign default layout methods and parameters before specific ones Date: Tue, 21 May 2024 09:13:25 +0200 Message-ID: <20240521071335.4193-2-kabel@kernel.org> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240521071335.4193-1-kabel@kernel.org> References: <20240521071335.4193-1-kabel@kernel.org> 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.8 at phobos.denx.de X-Virus-Status: Clean Assign the default eeprom layout parameter .data_size and methods .print() and .update() before calling eeprom_layout_assign() in eeprom_layout_setup(). This allows eeprom_layout_assign() to overwrite these if needed. Signed-off-by: Marek Behún --- common/eeprom/eeprom_layout.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/eeprom/eeprom_layout.c b/common/eeprom/eeprom_layout.c index 5a9be1da06..406db3f7d1 100644 --- a/common/eeprom/eeprom_layout.c +++ b/common/eeprom/eeprom_layout.c @@ -111,14 +111,14 @@ void eeprom_layout_setup(struct eeprom_layout *layout, unsigned char *buf, else layout->layout_version = layout_version; + layout->data_size = buf_size; + layout->print = eeprom_layout_print; + layout->update = eeprom_layout_update_field; + eeprom_layout_assign(layout, layout_version); layout->data = buf; for (i = 0; i < layout->num_of_fields; i++) { layout->fields[i].buf = buf; buf += layout->fields[i].size; } - - layout->data_size = buf_size; - layout->print = eeprom_layout_print; - layout->update = eeprom_layout_update_field; } From patchwork Tue May 21 07:13:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1937233 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; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=lBwVNEPI; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vk5Jx2Fl8z1ydW for ; Tue, 21 May 2024 17:14:09 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0013988714; Tue, 21 May 2024 09:13:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="lBwVNEPI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5BEC08870D; Tue, 21 May 2024 09:13:47 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 361F687FA1 for ; Tue, 21 May 2024 09:13:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 2216B62023; Tue, 21 May 2024 07:13:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EC6DC4AF07; Tue, 21 May 2024 07:13:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716275623; bh=1zJMs5UINm8+SccMtIC6Y10WB1G7s2Jqg9gnzuyAzgg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lBwVNEPIouAHe1NSKv7Oj9kwbhPeawuHFIDY8N7wVNFuFVmf7VX1TEujPm+99BCkX l1OsOzv6mpRCSt4dHSP9slsdA3jFZnQELgRw04U6X4Brhakty5EQJ08iEriMG7DNQi nYjVJt+kfq2DZB+sEzuT108W0dOvys6Kvz8DS0aHJXxGaItx2tRgg2aNgNdnoUUIFz HhyBbgmvNPSOk0P8r7PjzkNr9suVYGDKw9jnJ/UOxhF8xQGpUeMm06XKjNXNtk4jKL UAqmY0GaJBGMBCKQ3TELvr//LqPPDHEwAGrutjeFPe6u/pcRLLhHnCu9yu4xWuOYfO r3cI0VkcTUMUA== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Tom Rini , u-boot@lists.denx.de, Stefan Roese Cc: Simon Glass , Ilias Apalodimas , Nikita Kiryanov , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 02/11] common: eeprom_layout: Split field finding code from the field update function Date: Tue, 21 May 2024 09:13:26 +0200 Message-ID: <20240521071335.4193-3-kabel@kernel.org> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240521071335.4193-1-kabel@kernel.org> References: <20240521071335.4193-1-kabel@kernel.org> 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.8 at phobos.denx.de X-Virus-Status: Clean Split the eeprom layout field finding code from the eeprom_layout_update_field() function in order to make it usable in alternative implementations of update method. Signed-off-by: Marek Behún --- common/eeprom/eeprom_layout.c | 46 +++++++++++++++++++++++------------ include/eeprom_layout.h | 4 +++ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/common/eeprom/eeprom_layout.c b/common/eeprom/eeprom_layout.c index 406db3f7d1..801e90d38d 100644 --- a/common/eeprom/eeprom_layout.c +++ b/common/eeprom/eeprom_layout.c @@ -56,6 +56,28 @@ static void eeprom_layout_print(const struct eeprom_layout *layout) fields[i].print(&fields[i]); } +/* + * eeprom_layout_find_field() - finds a layout field by name + * @layout: A pointer to an existing struct layout. + * @field_name: The name of the field to update. + * @warn: Whether to print a warning if the field is not found. + * + * Returns: a pointer to the found field or NULL on failure. + */ +struct eeprom_field *eeprom_layout_find_field(struct eeprom_layout *layout, + char *field_name, bool warn) +{ + for (int i = 0; i < layout->num_of_fields; i++) + if (layout->fields[i].name != RESERVED_FIELDS && + !strcmp(layout->fields[i].name, field_name)) + return &layout->fields[i]; + + if (warn) + printf("No such field '%s'\n", field_name); + + return NULL; +} + /* * eeprom_layout_update_field() - update a single field in the layout data. * @layout: A pointer to an existing struct layout. @@ -67,8 +89,8 @@ static void eeprom_layout_print(const struct eeprom_layout *layout) static int eeprom_layout_update_field(struct eeprom_layout *layout, char *field_name, char *new_data) { - int i, err; - struct eeprom_field *fields = layout->fields; + struct eeprom_field *field; + int err; if (new_data == NULL) return 0; @@ -76,21 +98,15 @@ static int eeprom_layout_update_field(struct eeprom_layout *layout, if (field_name == NULL) return -1; - for (i = 0; i < layout->num_of_fields; i++) { - if (fields[i].name == RESERVED_FIELDS || - strcmp(fields[i].name, field_name)) - continue; - - err = fields[i].update(&fields[i], new_data); - if (err) - printf("Invalid data for field %s\n", field_name); - - return err; - } + field = eeprom_layout_find_field(layout, field_name, true); + if (field == NULL) + return -1; - printf("No such field '%s'\n", field_name); + err = field->update(field, new_data); + if (err) + printf("Invalid data for field %s\n", field_name); - return -1; + return err; } /* diff --git a/include/eeprom_layout.h b/include/eeprom_layout.h index 730d963ab9..b1d6220595 100644 --- a/include/eeprom_layout.h +++ b/include/eeprom_layout.h @@ -9,6 +9,8 @@ #ifndef _LAYOUT_ #define _LAYOUT_ +#include + #define RESERVED_FIELDS NULL #define LAYOUT_VERSION_UNRECOGNIZED -1 #define LAYOUT_VERSION_AUTODETECT -2 @@ -24,6 +26,8 @@ struct eeprom_layout { char *new_data); }; +struct eeprom_field *eeprom_layout_find_field(struct eeprom_layout *layout, + char *field_name, bool warn); void eeprom_layout_setup(struct eeprom_layout *layout, unsigned char *buf, unsigned int buf_size, int layout_version); __weak void __eeprom_layout_assign(struct eeprom_layout *layout, From patchwork Tue May 21 07:13:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1937235 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; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=udY3NG3L; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vk5K83ZGWz1ydW for ; Tue, 21 May 2024 17:14:20 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6742988728; Tue, 21 May 2024 09:13:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="udY3NG3L"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 438D78871A; Tue, 21 May 2024 09:13:49 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 42C5C8870B for ; Tue, 21 May 2024 09:13:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 131666201E; Tue, 21 May 2024 07:13:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FB0BC2BD11; Tue, 21 May 2024 07:13:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716275625; bh=7RVidHPJdNkmb71oOh0BZ7YaTO9xABgdKKrVNZfvSi8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=udY3NG3LE+6U4+i/kBd74VU9S/ScCWcrF582L+2EVMfk9FWLRvwJB8ja/vjT9asC0 aRSKRia4q52FrIYEjmTLtyOfxe/oTj0jTiZmUWp/CR0uXkue5Yqwyca1C5nZFekV2E T5Bd4c4DmX6IoNMyf8NY5taRyhXAFQFPyfc9jDbIVcRQNswCMlJj57vyJg21HceCV0 trwMDuADt3wH6h+suMu3K184ofTHGWDDdQx1l+gx2bWdUzq/eQPT4MNy82QgsoFfuz h+3HczCLu464rtbpeNUfzdvtqVMiSGWVPxtG1KkI7pNawX5jEVEuHtOyGrRDyTIYpv nuwaOsC3cvDYQ== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Tom Rini , u-boot@lists.denx.de, Stefan Roese Cc: Simon Glass , Ilias Apalodimas , Nikita Kiryanov , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 03/11] common: eeprom_field: Fix updating binary field Date: Tue, 21 May 2024 09:13:27 +0200 Message-ID: <20240521071335.4193-4-kabel@kernel.org> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240521071335.4193-1-kabel@kernel.org> References: <20240521071335.4193-1-kabel@kernel.org> 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.8 at phobos.denx.de X-Virus-Status: Clean The __eeprom_field_update_bin() function is expected to parse a hex string into bytes (potentially in reverse order), but the simple_strtoul() function is given 0 as base. This does not work since the string does not contain '0x' prefix. Add explicit base 16. Signed-off-by: Marek Behún --- common/eeprom/eeprom_field.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/eeprom/eeprom_field.c b/common/eeprom/eeprom_field.c index f56eebe679..9b831414a4 100644 --- a/common/eeprom/eeprom_field.c +++ b/common/eeprom/eeprom_field.c @@ -55,7 +55,7 @@ static int __eeprom_field_update_bin(struct eeprom_field *field, tmp[k] = value[reverse ? i - 1 + k : i + k]; } - byte = simple_strtoul(tmp, &endptr, 0); + byte = simple_strtoul(tmp, &endptr, 16); if (*endptr != '\0' || byte < 0) return -1; From patchwork Tue May 21 07:13:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1937236 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; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=CDT/rWuj; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vk5KP0Td8z1ydW for ; Tue, 21 May 2024 17:14:33 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 05B2988702; Tue, 21 May 2024 09:13:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="CDT/rWuj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 20CE58803E; Tue, 21 May 2024 09:13:51 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 238F488719 for ; Tue, 21 May 2024 09:13:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 108666201E; Tue, 21 May 2024 07:13:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30BC2C32782; Tue, 21 May 2024 07:13:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716275627; bh=wr43Ls3kS9v++eJj9oia9bi6eJXVJ3tY49h9p8I1eSY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CDT/rWujlypDUz+sCDrNZ8wzNCfWFBEEHmu3F/ISYtLNZ2AuK5u6PbLbukUn8QFAi UP1c7I1eqo+WHy4iMF3bcMtWMSo5T3yKBIuzbZBkH45ZjUv5OdVGTcNRT1bmiTMj9C unkly/aWltnNty/DyOGBaLzOZX8Yxc/4mMcVd93HKd/xfRRkJtkzjJV5c5av7P5UkB 4q2DW0NTUxhjYmnTKmVs502UUui3y/9j8yoiufwNAeC3D3poT1mwN5WZQkqViYvdbl 2nOAM++9VHzQzgBEK6z9dIxEtx4BaWZlnH9y575p++w93rk+k94oUpet+LHsJhFHOJ 5GwZN6ew9uKgA== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Tom Rini , u-boot@lists.denx.de, Stefan Roese Cc: Simon Glass , Ilias Apalodimas , Nikita Kiryanov , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 04/11] common: eeprom_field: Drop unnecessary comparison Date: Tue, 21 May 2024 09:13:28 +0200 Message-ID: <20240521071335.4193-5-kabel@kernel.org> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240521071335.4193-1-kabel@kernel.org> References: <20240521071335.4193-1-kabel@kernel.org> 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.8 at phobos.denx.de X-Virus-Status: Clean The byte variable is of type unsigned char, it is never less than zero. The error case is handled by *endptr, so drop the comparison altogether. Signed-off-by: Marek Behún --- common/eeprom/eeprom_field.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/eeprom/eeprom_field.c b/common/eeprom/eeprom_field.c index 9b831414a4..26f6041e54 100644 --- a/common/eeprom/eeprom_field.c +++ b/common/eeprom/eeprom_field.c @@ -56,7 +56,7 @@ static int __eeprom_field_update_bin(struct eeprom_field *field, } byte = simple_strtoul(tmp, &endptr, 16); - if (*endptr != '\0' || byte < 0) + if (*endptr != '\0') return -1; field->buf[j] = byte; From patchwork Tue May 21 07:13:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1937237 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; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=PlszoA4+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vk5Kf4WmBz1ydW for ; Tue, 21 May 2024 17:14:46 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 735C98871F; Tue, 21 May 2024 09:13:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="PlszoA4+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B2A99886FF; Tue, 21 May 2024 09:13:53 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 37ABF88713 for ; Tue, 21 May 2024 09:13:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 10A896202A; Tue, 21 May 2024 07:13:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D016C2BD11; Tue, 21 May 2024 07:13:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716275629; bh=9CaGO6PB4D9Dv65Mn4OctTjpsfAtAnCrFCYQeipcZ5s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PlszoA4+lnRxVLUrWOJBJVUfWU1JNX0Jx3niJqAS6n2FrGMT57QqLQhF7P2vMkuNY +khSnogMT6GWGc2QaeeSc+CA64MpQrhUpsfVw1H2tcd8S8suFuj7cUhaemE/YgA/l6 LoE1nEl3HjkK8jaiaqQd+wppM5xKS6kdBHXukp78uJHos82P6ioNrP00c65b21hg6s +1T6RSu+QcaMZwlelJY6GOMPQgMycX50KfRCQyGHdwxE+BM3y1idH2qzoOIzKDqvT/ PqwFjSJMvEYxxN2xE35z9rf0n6aEcxMFaEsN4V8LprtgLYEOSr6ckhF8NbDOYAbk2M /hGuBQ7eyKEHw== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Tom Rini , u-boot@lists.denx.de, Stefan Roese Cc: Simon Glass , Ilias Apalodimas , Nikita Kiryanov , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 05/11] cmd: eeprom: Fix usage help for the eeprom command Date: Tue, 21 May 2024 09:13:29 +0200 Message-ID: <20240521071335.4193-6-kabel@kernel.org> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240521071335.4193-1-kabel@kernel.org> References: <20240521071335.4193-1-kabel@kernel.org> 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.8 at phobos.denx.de X-Virus-Status: Clean The bus and devaddr arguments of the eeprom command are optional, and if only one is given, it is assumed to be devaddr. Change the usage help from to [[bus] [devaddr] Signed-off-by: Marek Behún --- cmd/eeprom.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/eeprom.c b/cmd/eeprom.c index 322765ad02..0d604832e4 100644 --- a/cmd/eeprom.c +++ b/cmd/eeprom.c @@ -418,14 +418,14 @@ int do_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) U_BOOT_CMD( eeprom, 8, 1, do_eeprom, "EEPROM sub-system", - "read addr off cnt\n" - "eeprom write addr off cnt\n" + "read [[bus] devaddr] addr off cnt\n" + "eeprom write [[bus] devaddr] addr off cnt\n" " - read/write `cnt' bytes from `devaddr` EEPROM at offset `off'" #ifdef CONFIG_CMD_EEPROM_LAYOUT "\n" - "eeprom print [-l ] \n" + "eeprom print [-l ] [[bus] devaddr]\n" " - Print layout fields and their data in human readable format\n" - "eeprom update [-l ] field_name field_value\n" + "eeprom update [-l ] [[bus] devaddr] field_name field_value\n" " - Update a specific eeprom field with new data.\n" " The new data must be written in the same human readable format as shown by the print command.\n" "\n" From patchwork Tue May 21 07:13:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1937238 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; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=MV4MZL/F; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vk5Kt2nCMz1ydW for ; Tue, 21 May 2024 17:14:58 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D01548870F; Tue, 21 May 2024 09:13:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="MV4MZL/F"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 40DC78870B; Tue, 21 May 2024 09:13:55 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1887488720 for ; Tue, 21 May 2024 09:13:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id E5FD861FF2; Tue, 21 May 2024 07:13:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F5A5C4AF07; Tue, 21 May 2024 07:13:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716275631; bh=24IoUxTaqgkiNJOTFPqB/d7BBeJxM5Hwmylm9R59qLs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MV4MZL/FxPucIkSffQmLhjsHgzeaQtQ9CCSYVZ5P7llHPoghuRobSxbI0pdWlVl70 aFNGweNM1gOWYkkTet5bBD+O+xt5NKE11W2VXFQ1Ovxfsk2ArYLVUFaQfU+WIRClSc 6MLYMnPEtY0n558UAvWvKKOGTfqNEomPjNDcCdHzaidWTco6Xgf8nTRbu1IXp+WPFk 0XZGWxg9CN6hbwnXi+U9yANJM/indxv7B/1PrD1Rj+ypHoQugIu8RVmekSWt3ugekS IqA+El5sU1ET+yOACAx2DuD2cevmOrM/sQBrmS1ETsTSYeW2QJajQMDaEuplwb5wKq AFlhpk7/6M6Sw== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Tom Rini , u-boot@lists.denx.de, Stefan Roese Cc: Simon Glass , Ilias Apalodimas , Nikita Kiryanov , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 06/11] cmd: eeprom: Hide eeprom layout versioning behind a Kconfig option Date: Tue, 21 May 2024 09:13:30 +0200 Message-ID: <20240521071335.4193-7-kabel@kernel.org> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240521071335.4193-1-kabel@kernel.org> References: <20240521071335.4193-1-kabel@kernel.org> 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.8 at phobos.denx.de X-Virus-Status: Clean Add a new Kconfig option EEPROM_LAYOUT_VERSIONS, and hide eeprom layout versionsing code behind it. Only print the relevant help in 'eeprom' command usage if this option is enabled. Enable this new option for cm_fx6_defconfig and cm_t43_defconfig. These are the only boards using EEPROM layout versioning. Signed-off-by: Marek Behún --- cmd/Kconfig | 9 ++++++++- cmd/eeprom.c | 20 +++++++++++++++----- configs/cm_fx6_defconfig | 1 + configs/cm_t43_defconfig | 1 + 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/cmd/Kconfig b/cmd/Kconfig index b026439c77..8c370993f6 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -803,9 +803,16 @@ config CMD_EEPROM_LAYOUT types of eeprom fields. Can be used for defining custom layouts. +config EEPROM_LAYOUT_VERSIONS + bool "Support specifying eeprom layout version" + depends on CMD_EEPROM_LAYOUT + help + Support specifying eeprom layout version in the 'eeprom' command + via the -l option. + config EEPROM_LAYOUT_HELP_STRING string "Tells user what layout names are supported" - depends on CMD_EEPROM_LAYOUT + depends on EEPROM_LAYOUT_VERSIONS default "" help Help printed with the LAYOUT VERSIONS part of the 'eeprom' diff --git a/cmd/eeprom.c b/cmd/eeprom.c index 0d604832e4..d610dc9931 100644 --- a/cmd/eeprom.c +++ b/cmd/eeprom.c @@ -252,10 +252,12 @@ static int parse_i2c_bus_addr(int *i2c_bus, ulong *i2c_addr, int argc, #ifdef CONFIG_CMD_EEPROM_LAYOUT +#ifdef CONFIG_EEPROM_LAYOUT_VERSIONS __weak int eeprom_parse_layout_version(char *str) { return LAYOUT_VERSION_UNRECOGNIZED; } +#endif static unsigned char eeprom_buf[CONFIG_SYS_EEPROM_SIZE]; @@ -359,7 +361,7 @@ int do_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) if (action == EEPROM_ACTION_INVALID) return CMD_RET_USAGE; -#ifdef CONFIG_CMD_EEPROM_LAYOUT +#ifdef CONFIG_EEPROM_LAYOUT_VERSIONS if (action == EEPROM_PRINT || action == EEPROM_UPDATE) { if (!strcmp(argv[index], "-l")) { NEXT_PARAM(argc, index); @@ -415,6 +417,12 @@ int do_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) field_name, field_value, addr, off, cnt); } +#ifdef CONFIG_EEPROM_LAYOUT_VERSIONS +#define EEPROM_LAYOUT_SPEC "[-l ] " +#else +#define EEPROM_LAYOUT_SPEC "" +#endif + U_BOOT_CMD( eeprom, 8, 1, do_eeprom, "EEPROM sub-system", @@ -423,16 +431,18 @@ U_BOOT_CMD( " - read/write `cnt' bytes from `devaddr` EEPROM at offset `off'" #ifdef CONFIG_CMD_EEPROM_LAYOUT "\n" - "eeprom print [-l ] [[bus] devaddr]\n" + "eeprom print " EEPROM_LAYOUT_SPEC "[[bus] devaddr]\n" " - Print layout fields and their data in human readable format\n" - "eeprom update [-l ] [[bus] devaddr] field_name field_value\n" + "eeprom update " EEPROM_LAYOUT_SPEC "[[bus] devaddr] field_name field_value\n" " - Update a specific eeprom field with new data.\n" - " The new data must be written in the same human readable format as shown by the print command.\n" - "\n" + " The new data must be written in the same human readable format as shown by the print command." +#ifdef CONFIG_EEPROM_LAYOUT_VERSIONS + "\n\n" "LAYOUT VERSIONS\n" "The -l option can be used to force the command to interpret the EEPROM data using the chosen layout.\n" "If the -l option is omitted, the command will auto detect the layout based on the data in the EEPROM.\n" "The values which can be provided with the -l option are:\n" CONFIG_EEPROM_LAYOUT_HELP_STRING"\n" #endif +#endif ); diff --git a/configs/cm_fx6_defconfig b/configs/cm_fx6_defconfig index a4d5f91b35..386616cc42 100644 --- a/configs/cm_fx6_defconfig +++ b/configs/cm_fx6_defconfig @@ -46,6 +46,7 @@ CONFIG_SYS_MAXARGS=32 CONFIG_CMD_GREPENV=y CONFIG_CMD_EEPROM=y CONFIG_CMD_EEPROM_LAYOUT=y +CONFIG_EEPROM_LAYOUT_VERSIONS=y CONFIG_EEPROM_LAYOUT_HELP_STRING="v2, v3" CONFIG_SYS_I2C_EEPROM_BUS=2 CONFIG_SYS_EEPROM_PAGE_WRITE_BITS=4 diff --git a/configs/cm_t43_defconfig b/configs/cm_t43_defconfig index 93e667292c..32f126a517 100644 --- a/configs/cm_t43_defconfig +++ b/configs/cm_t43_defconfig @@ -50,6 +50,7 @@ CONFIG_SYS_PROMPT="CM-T43 # " CONFIG_CMD_ASKENV=y CONFIG_CMD_EEPROM=y CONFIG_CMD_EEPROM_LAYOUT=y +CONFIG_EEPROM_LAYOUT_VERSIONS=y CONFIG_EEPROM_LAYOUT_HELP_STRING="v2, v3" CONFIG_SYS_EEPROM_PAGE_WRITE_BITS=4 CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS=5 From patchwork Tue May 21 07:13:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1937239 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; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=P46bUfWu; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vk5L60xbcz1ynR for ; Tue, 21 May 2024 17:15:10 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 42CB788744; Tue, 21 May 2024 09:14:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="P46bUfWu"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5CE3A88737; Tue, 21 May 2024 09:13:59 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3B8118871D for ; Tue, 21 May 2024 09:13:57 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 4A8D4CE0E90; Tue, 21 May 2024 07:13:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FDDFC32782; Tue, 21 May 2024 07:13:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716275633; bh=2WVShhLd/mAQ4BLHQm+cBILxCcDGdEePcpU7WxN5c/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P46bUfWue47BsBForB4LGFvETo4NJnNgxgD7wA79Zm2ixESE9SELZ3wqfYxQHmXgg T6JB7S9xLagTYskHrvlgUWqG9MSeGJye7Fqhrp94FkjyGbBruC6RCWERQjJXVTRoFf wLjvOIoVSxNX9tedICtlQI0h9WC5asCpM3SDhqSFDCHAQL7u0HIGXSDKcS+qGgx6jI vXbLIHAicXwjEv+6cJXuL6Iti9C3GrrvlbvGiVcd9/sFMTw/SK0WwRwdd2AlBjyDFI 7pP8YHBE4xDlJ8csB0tuowwRwW1A+Ty8TpJgmyF9wYX0XJsgPks0Fk30N/ozKDi7xF 5LbYEwOyG6ZEg== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Tom Rini , u-boot@lists.denx.de, Stefan Roese Cc: Simon Glass , Ilias Apalodimas , Nikita Kiryanov , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 07/11] cmd: eeprom: Deduplicate parse_i2c_bus_addr() calls Date: Tue, 21 May 2024 09:13:31 +0200 Message-ID: <20240521071335.4193-8-kabel@kernel.org> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240521071335.4193-1-kabel@kernel.org> References: <20240521071335.4193-1-kabel@kernel.org> 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.8 at phobos.denx.de X-Virus-Status: Clean Deduplicate the calls to parse_i2c_bus_addr(). Signed-off-by: Marek Behún --- cmd/eeprom.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/cmd/eeprom.c b/cmd/eeprom.c index d610dc9931..12902e812e 100644 --- a/cmd/eeprom.c +++ b/cmd/eeprom.c @@ -339,6 +339,21 @@ static int eeprom_execute_command(enum eeprom_action action, int i2c_bus, return rcode; } +static int eeprom_action_expected_argc(enum eeprom_action action) +{ + switch (action) { + case EEPROM_READ: + case EEPROM_WRITE: + return 3; + case EEPROM_PRINT: + return 0; + case EEPROM_UPDATE: + return 2; + default: + return CMD_RET_USAGE; + } +} + #define NEXT_PARAM(argc, index) { (argc)--; (index)++; } int do_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -371,25 +386,8 @@ int do_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } #endif - switch (action) { - case EEPROM_READ: - case EEPROM_WRITE: - ret = parse_i2c_bus_addr(&i2c_bus, &i2c_addr, argc, - argv + index, 3); - break; - case EEPROM_PRINT: - ret = parse_i2c_bus_addr(&i2c_bus, &i2c_addr, argc, - argv + index, 0); - break; - case EEPROM_UPDATE: - ret = parse_i2c_bus_addr(&i2c_bus, &i2c_addr, argc, - argv + index, 2); - break; - default: - /* Get compiler to stop whining */ - return CMD_RET_USAGE; - } - + ret = parse_i2c_bus_addr(&i2c_bus, &i2c_addr, argc, argv + index, + eeprom_action_expected_argc(action)); if (ret == CMD_RET_USAGE) return ret; From patchwork Tue May 21 07:13:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1937241 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; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=Bf5wkxTg; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vk5LX1W28z20KF for ; Tue, 21 May 2024 17:15:32 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 291DE8874D; Tue, 21 May 2024 09:14:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="Bf5wkxTg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 067C988732; Tue, 21 May 2024 09:14:03 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 787268871D for ; Tue, 21 May 2024 09:13:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 3A637CE0E92; Tue, 21 May 2024 07:13:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01254C4AF07; Tue, 21 May 2024 07:13:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716275635; bh=j3mJD9f/KOQL+aQUAJ22YabGGTNvDNXNdxB8R/VfL/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bf5wkxTgASSYCcp0Khet3iM8sazHr618uMQ2YaMuYnqHFLDZvwLhnqDC99djx0fU1 OcTmYukSxPoOnLq5Eyo1qsglCqcgCw/QebH54ERYmqHXZh/VJ1K2EdEe6FGpWGvIgm KSRhKeBktuvelwKUuWwQTwuWNLWJig60e8gaqGOr6xuniitUvVEJPcBTLeVB9UMM8j Ns25osHm7VQ6DYbFWYyJv0tVRUkBjzYzw08KiaNp/7PZyyum7HB8Cc3Oxb2GAAz9A3 oNQxipACLM76vIKtrAPv7npemqeEf+KxaTIqfKVsw3Bi4Ox13Z0PfaFRslftUfi9eZ nSX8wsP2IsHNQ== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Tom Rini , u-boot@lists.denx.de, Stefan Roese Cc: Simon Glass , Ilias Apalodimas , Nikita Kiryanov , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 08/11] cmd: eeprom: Refactor eeprom device specifier parsing Date: Tue, 21 May 2024 09:13:32 +0200 Message-ID: <20240521071335.4193-9-kabel@kernel.org> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240521071335.4193-1-kabel@kernel.org> References: <20240521071335.4193-1-kabel@kernel.org> 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.8 at phobos.denx.de X-Virus-Status: Clean In preparation for allowing to access eeprom by driver-model device name, refactor the eeprom device specifier parsing. Instead of filling two parameters (i2c_bus, i2c_addr), the parsing function now fills one parameter of type struct eeprom_dev_spec. Signed-off-by: Marek Behún --- cmd/eeprom.c | 77 ++++++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/cmd/eeprom.c b/cmd/eeprom.c index 12902e812e..e29639780d 100644 --- a/cmd/eeprom.c +++ b/cmd/eeprom.c @@ -208,41 +208,42 @@ static long parse_numeric_param(char *str) return (*endptr != '\0') ? -1 : value; } +struct eeprom_dev_spec { + int i2c_bus; + ulong i2c_addr; +}; + /** - * parse_i2c_bus_addr - parse the i2c bus and i2c devaddr parameters + * parse_eeprom_dev_spec - parse the eeprom device specifier * - * @i2c_bus: address to store the i2c bus - * @i2c_addr: address to store the device i2c address - * @argc: count of command line arguments left to parse + * @dev: pointer to eeprom device specifier + * @argc: count of command line arguments that can be used to parse + * the device specifier * @argv: command line arguments left to parse - * @argc_no_bus_addr: argc value we expect to see when bus & addr aren't given * * @returns: number of arguments parsed or CMD_RET_USAGE if error */ -static int parse_i2c_bus_addr(int *i2c_bus, ulong *i2c_addr, int argc, - char *const argv[], int argc_no_bus_addr) +static int parse_eeprom_dev_spec(struct eeprom_dev_spec *dev, int argc, + char *const argv[]) { - int argc_no_bus = argc_no_bus_addr + 1; - int argc_bus_addr = argc_no_bus_addr + 2; - #ifdef CONFIG_SYS_I2C_EEPROM_ADDR - if (argc == argc_no_bus_addr) { - *i2c_bus = -1; - *i2c_addr = CONFIG_SYS_I2C_EEPROM_ADDR; + if (argc == 0) { + dev->i2c_bus = -1; + dev->i2c_addr = CONFIG_SYS_I2C_EEPROM_ADDR; return 0; } #endif - if (argc == argc_no_bus) { - *i2c_bus = -1; - *i2c_addr = parse_numeric_param(argv[0]); + if (argc == 1) { + dev->i2c_bus = -1; + dev->i2c_addr = parse_numeric_param(argv[0]); return 1; } - if (argc == argc_bus_addr) { - *i2c_bus = parse_numeric_param(argv[0]); - *i2c_addr = parse_numeric_param(argv[1]); + if (argc == 2) { + dev->i2c_bus = parse_numeric_param(argv[0]); + dev->i2c_addr = parse_numeric_param(argv[1]); return 2; } @@ -287,9 +288,10 @@ static enum eeprom_action parse_action(char *cmd) return EEPROM_ACTION_INVALID; } -static int eeprom_execute_command(enum eeprom_action action, int i2c_bus, - ulong i2c_addr, int layout_ver, char *key, - char *value, ulong addr, ulong off, ulong cnt) +static int eeprom_execute_command(enum eeprom_action action, + struct eeprom_dev_spec *dev, + int layout_ver, char *key, char *value, + ulong addr, ulong off, ulong cnt) { int rcode = 0; const char *const fmt = @@ -301,25 +303,26 @@ static int eeprom_execute_command(enum eeprom_action action, int i2c_bus, if (action == EEPROM_ACTION_INVALID) return CMD_RET_USAGE; - eeprom_init(i2c_bus); + eeprom_init(dev->i2c_bus); if (action == EEPROM_READ) { - printf(fmt, i2c_addr, "read", addr, off, cnt); + printf(fmt, dev->i2c_addr, "read", addr, off, cnt); - rcode = eeprom_read(i2c_addr, off, (uchar *)addr, cnt); + rcode = eeprom_read(dev->i2c_addr, off, (uchar *)addr, cnt); puts("done\n"); return rcode; } else if (action == EEPROM_WRITE) { - printf(fmt, i2c_addr, "write", addr, off, cnt); + printf(fmt, dev->i2c_addr, "write", addr, off, cnt); - rcode = eeprom_write(i2c_addr, off, (uchar *)addr, cnt); + rcode = eeprom_write(dev->i2c_addr, off, (uchar *)addr, cnt); puts("done\n"); return rcode; } #ifdef CONFIG_CMD_EEPROM_LAYOUT - rcode = eeprom_read(i2c_addr, 0, eeprom_buf, CONFIG_SYS_EEPROM_SIZE); + rcode = eeprom_read(dev->i2c_addr, 0, eeprom_buf, + CONFIG_SYS_EEPROM_SIZE); if (rcode < 0) return rcode; @@ -333,7 +336,8 @@ static int eeprom_execute_command(enum eeprom_action action, int i2c_bus, layout.update(&layout, key, value); - rcode = eeprom_write(i2c_addr, 0, layout.data, CONFIG_SYS_EEPROM_SIZE); + rcode = eeprom_write(dev->i2c_addr, 0, layout.data, + CONFIG_SYS_EEPROM_SIZE); #endif return rcode; @@ -359,9 +363,9 @@ int do_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { int layout_ver = LAYOUT_VERSION_AUTODETECT; enum eeprom_action action = EEPROM_ACTION_INVALID; - int i2c_bus = -1, index = 0; - ulong i2c_addr = -1, addr = 0, cnt = 0, off = 0; - int ret; + struct eeprom_dev_spec dev; + ulong addr = 0, cnt = 0, off = 0; + int ret, index = 0; char *field_name = ""; char *field_value = ""; @@ -386,8 +390,9 @@ int do_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } #endif - ret = parse_i2c_bus_addr(&i2c_bus, &i2c_addr, argc, argv + index, - eeprom_action_expected_argc(action)); + ret = parse_eeprom_dev_spec(&dev, + argc - eeprom_action_expected_argc(action), + argv + index); if (ret == CMD_RET_USAGE) return ret; @@ -411,8 +416,8 @@ int do_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } #endif - return eeprom_execute_command(action, i2c_bus, i2c_addr, layout_ver, - field_name, field_value, addr, off, cnt); + return eeprom_execute_command(action, &dev, layout_ver, field_name, + field_value, addr, off, cnt); } #ifdef CONFIG_EEPROM_LAYOUT_VERSIONS From patchwork Tue May 21 07:13:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1937240 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; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=BUQksAvX; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vk5LK4jMKz20KF for ; Tue, 21 May 2024 17:15:21 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A47378873A; Tue, 21 May 2024 09:14:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="BUQksAvX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 12B038874C; Tue, 21 May 2024 09:14:01 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id CD59A87FA1 for ; Tue, 21 May 2024 09:13:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id B939F6201E; Tue, 21 May 2024 07:13:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5C5FC32782; Tue, 21 May 2024 07:13:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716275637; bh=sgeNpu9nIELa68JF0KxLROY2xwH/8x3+ZchzuK1nXAg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BUQksAvXUiInW/qbFrvX0Ozjrep42yxXjRP3sROcSCAej3WwVAK8uBBBHETf7d1jB 2UbEi5GbOPqqpnOUwnOZJXhuOsOOaFTV+H3PqKkOiEF+NOygjNGJbVPBQhb0/mb12h xNDwEdWsx1UByNDxXyyHgh0nnkISh5cyFEUrG/9tn0bNg3rNVyC79PmBpy3Uzs6a77 mlZS0nZryJevojtHe1Bog/DGkQ+v3JDzB4ArLb7cVp2A/bqcDUW22SF5B/IZJIY65o aOHZ2sWU1NSOQwIHusnUySVv54+uuAewz0AOBN6QuTL7ipKvn95n+7ZO+1y0T1pMyZ LYtQLUnKpoGvA== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Tom Rini , u-boot@lists.denx.de, Stefan Roese Cc: Simon Glass , Ilias Apalodimas , Nikita Kiryanov , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 09/11] cmd: eeprom: Refactor command execution into function by action Date: Tue, 21 May 2024 09:13:33 +0200 Message-ID: <20240521071335.4193-10-kabel@kernel.org> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240521071335.4193-1-kabel@kernel.org> References: <20240521071335.4193-1-kabel@kernel.org> 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.8 at phobos.denx.de X-Virus-Status: Clean Refactor the eeprom_execute_command() function into separate functions do_eeprom_rw(), do_eeprom_print() and do_eeprom_update(). Signed-off-by: Marek Behún --- cmd/eeprom.c | 111 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 71 insertions(+), 40 deletions(-) diff --git a/cmd/eeprom.c b/cmd/eeprom.c index e29639780d..c76cf43157 100644 --- a/cmd/eeprom.c +++ b/cmd/eeprom.c @@ -288,61 +288,75 @@ static enum eeprom_action parse_action(char *cmd) return EEPROM_ACTION_INVALID; } -static int eeprom_execute_command(enum eeprom_action action, - struct eeprom_dev_spec *dev, - int layout_ver, char *key, char *value, - ulong addr, ulong off, ulong cnt) +static int do_eeprom_rw(struct eeprom_dev_spec *dev, bool read, + ulong addr, ulong off, ulong cnt) { - int rcode = 0; const char *const fmt = "\nEEPROM @0x%lX %s: addr 0x%08lx off 0x%04lx count %ld ... "; + uchar *memloc = (uchar *)addr; + int ret; + + printf(fmt, dev->i2c_addr, read ? "read" : "write", addr, off, cnt); + if (read) + ret = eeprom_read(dev->i2c_addr, off, memloc, cnt); + else + ret = eeprom_write(dev->i2c_addr, off, memloc, cnt); + puts("done\n"); + + return ret; +} + #ifdef CONFIG_CMD_EEPROM_LAYOUT - struct eeprom_layout layout; -#endif - if (action == EEPROM_ACTION_INVALID) - return CMD_RET_USAGE; +static int do_eeprom_layout(struct eeprom_dev_spec *dev, int layout_ver, + struct eeprom_layout *layout) +{ + int ret; - eeprom_init(dev->i2c_bus); - if (action == EEPROM_READ) { - printf(fmt, dev->i2c_addr, "read", addr, off, cnt); + ret = eeprom_read(dev->i2c_addr, 0, eeprom_buf, CONFIG_SYS_EEPROM_SIZE); + if (ret) + return ret; - rcode = eeprom_read(dev->i2c_addr, off, (uchar *)addr, cnt); + eeprom_layout_setup(layout, eeprom_buf, CONFIG_SYS_EEPROM_SIZE, + layout_ver); - puts("done\n"); - return rcode; - } else if (action == EEPROM_WRITE) { - printf(fmt, dev->i2c_addr, "write", addr, off, cnt); + return 0; +} - rcode = eeprom_write(dev->i2c_addr, off, (uchar *)addr, cnt); +static int do_eeprom_print(struct eeprom_dev_spec *dev, int layout_ver) +{ + struct eeprom_layout layout; + int ret; - puts("done\n"); - return rcode; - } + ret = do_eeprom_layout(dev, layout_ver, &layout); + if (ret) + return ret; -#ifdef CONFIG_CMD_EEPROM_LAYOUT - rcode = eeprom_read(dev->i2c_addr, 0, eeprom_buf, - CONFIG_SYS_EEPROM_SIZE); - if (rcode < 0) - return rcode; + layout.print(&layout); - eeprom_layout_setup(&layout, eeprom_buf, CONFIG_SYS_EEPROM_SIZE, - layout_ver); + return 0; +} - if (action == EEPROM_PRINT) { - layout.print(&layout); - return 0; - } +static int do_eeprom_update(struct eeprom_dev_spec *dev, int layout_ver, + char *key, char *value) +{ + struct eeprom_layout layout; + int ret; - layout.update(&layout, key, value); + ret = do_eeprom_layout(dev, layout_ver, &layout); + if (ret) + return ret; - rcode = eeprom_write(dev->i2c_addr, 0, layout.data, - CONFIG_SYS_EEPROM_SIZE); -#endif + ret = layout.update(&layout, key, value); + if (ret) + return CMD_RET_FAILURE; - return rcode; + return eeprom_write(dev->i2c_addr, 0, layout.data, + CONFIG_SYS_EEPROM_SIZE); } +#endif + static int eeprom_action_expected_argc(enum eeprom_action action) { switch (action) { @@ -361,13 +375,15 @@ static int eeprom_action_expected_argc(enum eeprom_action action) #define NEXT_PARAM(argc, index) { (argc)--; (index)++; } int do_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - int layout_ver = LAYOUT_VERSION_AUTODETECT; enum eeprom_action action = EEPROM_ACTION_INVALID; struct eeprom_dev_spec dev; ulong addr = 0, cnt = 0, off = 0; int ret, index = 0; +#ifdef CONFIG_CMD_EEPROM_LAYOUT char *field_name = ""; char *field_value = ""; + int layout_ver = LAYOUT_VERSION_AUTODETECT; +#endif if (argc <= 1) return CMD_RET_USAGE; @@ -416,8 +432,23 @@ int do_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } #endif - return eeprom_execute_command(action, &dev, layout_ver, field_name, - field_value, addr, off, cnt); + eeprom_init(dev.i2c_bus); + + switch (action) { + case EEPROM_READ: + case EEPROM_WRITE: + return do_eeprom_rw(&dev, action == EEPROM_READ, + addr, off, cnt); +#ifdef CONFIG_CMD_EEPROM_LAYOUT + case EEPROM_PRINT: + return do_eeprom_print(&dev, layout_ver); + case EEPROM_UPDATE: + return do_eeprom_update(&dev, layout_ver, + field_name, field_value); +#endif + default: + return CMD_RET_USAGE; + } } #ifdef CONFIG_EEPROM_LAYOUT_VERSIONS From patchwork Tue May 21 07:13:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1937242 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; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=P5SMslKM; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vk5Lk3hnPz20KF for ; Tue, 21 May 2024 17:15:42 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8B3B988708; Tue, 21 May 2024 09:14:05 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="P5SMslKM"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1963D886FF; Tue, 21 May 2024 09:14:05 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D014688730 for ; Tue, 21 May 2024 09:14:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 1C269CE0E6C; Tue, 21 May 2024 07:14:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6A37C4AF08; Tue, 21 May 2024 07:13:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716275639; bh=84VKJBZAAuBfcfYDVLAvI4efBCusskLSv/iJvfdOIpA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P5SMslKMSS/0ziI+TlbaiL1nCIcZQOdQn1tZ4K26HWgVBUD4AFE45fQfrkmiY81YS UOhT7ny0OeJj/UwdXMyoJMs/euV6xPF5LEOmv2aqnQPiYCE2us/Om6m0XKZm7xFRPx Tqc1ZXNf0ESIeyref7DZS/XJHpjAxn8r0x+YA4tSgMmvH4q/BP7cBPV+yRbcYSZ1qT 0It0w0Tc/JlBGDKewiGtZVxS/q7Xrhlzt6Ge+FbcjS1MLLBkHfUWeb6UFqyDxhj8RX ISw3d32C1i3sfA4AQb/UL8viGwk3bTkiXHzUBasnBGEEWoLHdjVHeovYXGqsAbSnQK j/1MRymaUli8Q== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Tom Rini , u-boot@lists.denx.de, Stefan Roese Cc: Simon Glass , Ilias Apalodimas , Nikita Kiryanov , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 10/11] cmd: eeprom: Don't read/write whole EEPROM if not necessary Date: Tue, 21 May 2024 09:13:34 +0200 Message-ID: <20240521071335.4193-11-kabel@kernel.org> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240521071335.4193-1-kabel@kernel.org> References: <20240521071335.4193-1-kabel@kernel.org> 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.8 at phobos.denx.de X-Virus-Status: Clean Don't read/write whole EEPROM if not necessary when printing / updating EEPROM layout fields. Only read/write layout.data_size bytes. Signed-off-by: Marek Behún --- cmd/eeprom.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/cmd/eeprom.c b/cmd/eeprom.c index c76cf43157..9c4af88738 100644 --- a/cmd/eeprom.c +++ b/cmd/eeprom.c @@ -311,16 +311,10 @@ static int do_eeprom_rw(struct eeprom_dev_spec *dev, bool read, static int do_eeprom_layout(struct eeprom_dev_spec *dev, int layout_ver, struct eeprom_layout *layout) { - int ret; - - ret = eeprom_read(dev->i2c_addr, 0, eeprom_buf, CONFIG_SYS_EEPROM_SIZE); - if (ret) - return ret; - eeprom_layout_setup(layout, eeprom_buf, CONFIG_SYS_EEPROM_SIZE, layout_ver); - return 0; + return eeprom_read(dev->i2c_addr, 0, eeprom_buf, layout->data_size); } static int do_eeprom_print(struct eeprom_dev_spec *dev, int layout_ver) @@ -351,8 +345,7 @@ static int do_eeprom_update(struct eeprom_dev_spec *dev, int layout_ver, if (ret) return CMD_RET_FAILURE; - return eeprom_write(dev->i2c_addr, 0, layout.data, - CONFIG_SYS_EEPROM_SIZE); + return eeprom_write(dev->i2c_addr, 0, layout.data, layout.data_size); } #endif From patchwork Tue May 21 07:13:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1937243 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; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=Ld96Ri2D; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vk5Lw4WWFz20KF for ; Tue, 21 May 2024 17:15:52 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E61D38871D; Tue, 21 May 2024 09:14:05 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org 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=kernel.org header.i=@kernel.org header.b="Ld96Ri2D"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 185D78870B; Tue, 21 May 2024 09:14:05 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id AD9D3886FF for ; Tue, 21 May 2024 09:14:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 9A9F061FF2; Tue, 21 May 2024 07:14:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C797AC32782; Tue, 21 May 2024 07:13:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716275641; bh=fb6Jd6DcoKyRKD7Wzx7N3VP+d2adhb7lwjg1YjcS5SM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ld96Ri2DYuMTSD2TpQ6DMo1aJY8bHZuaSEo9aurf5zwxFslYSEfZBCxIL+GjQ9IrY Y+O5z20ZA7UWcd/11L52gsAJAWzXo5RNjcCY8ZjvocGH/rZ8+0MdW9xcpy5db70vda 16Zrd3aA8znn/USNhC6ddp9vdWon7kgfhv4AyYOMbDx11TYn/RIFtaEkP27YZM/tYC zLJukV5RuvuJJICu5MLw8niP1rt8k301YKs2GcbS0xr+na1WxXDUPo6LaYrER1Bsow pYdVnDHtyU9G8OYbaxfiOzHXF02hO48J6Tu9DexjFRXdyPcPxqQPgWBXLO9SEzgE5U suMw1nZhE6T8Q== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Tom Rini , u-boot@lists.denx.de, Stefan Roese Cc: Simon Glass , Ilias Apalodimas , Nikita Kiryanov , =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH 11/11] cmd: eeprom: Extend to EEPROMs probed via driver model Date: Tue, 21 May 2024 09:13:35 +0200 Message-ID: <20240521071335.4193-12-kabel@kernel.org> X-Mailer: git-send-email 2.44.1 In-Reply-To: <20240521071335.4193-1-kabel@kernel.org> References: <20240521071335.4193-1-kabel@kernel.org> 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.8 at phobos.denx.de X-Virus-Status: Clean Extend the 'eeprom' command to allow accessing EEPROMs probed via driver model, uclass UCLASS_I2C_EEPROM. When the CONFIG_I2C_EEPROM config option is enabled (and so the i2c-eeprom driver is built), the 'eeprom' command now accepts driver model device name as EEPROM specifier for the 'eeprom' command, in addition to the legacy [[bus] devaddr] specifier. Moreover if no device specifier is given, then the first UCLASS_I2C_EEPROM device is used, if found. Signed-off-by: Marek Behún --- cmd/eeprom.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 112 insertions(+), 10 deletions(-) diff --git a/cmd/eeprom.c b/cmd/eeprom.c index 9c4af88738..a39fc5ffdc 100644 --- a/cmd/eeprom.c +++ b/cmd/eeprom.c @@ -22,8 +22,10 @@ #include #include #include +#include #include #include +#include #include #include @@ -209,10 +211,41 @@ static long parse_numeric_param(char *str) } struct eeprom_dev_spec { +#if CONFIG_IS_ENABLED(I2C_EEPROM) + struct udevice *dev; +#endif int i2c_bus; ulong i2c_addr; }; +static void eeprom_dev_spec_init(struct eeprom_dev_spec *dev) +{ +#if CONFIG_IS_ENABLED(I2C_EEPROM) + if (!dev->dev) +#endif + eeprom_init(dev->i2c_bus); +} + +static int eeprom_dev_spec_read(struct eeprom_dev_spec *dev, + unsigned offset, uchar *buffer, unsigned cnt) +{ +#if CONFIG_IS_ENABLED(I2C_EEPROM) + if (dev->dev) + return i2c_eeprom_read(dev->dev, offset, buffer, cnt); +#endif + return eeprom_read(dev->i2c_addr, offset, buffer, cnt); +} + +static int eeprom_dev_spec_write(struct eeprom_dev_spec *dev, + unsigned offset, uchar *buffer, unsigned cnt) +{ +#if CONFIG_IS_ENABLED(I2C_EEPROM) + if (dev->dev) + return i2c_eeprom_write(dev->dev, offset, buffer, cnt); +#endif + return eeprom_write(dev->i2c_addr, offset, buffer, cnt); +} + /** * parse_eeprom_dev_spec - parse the eeprom device specifier * @@ -226,6 +259,28 @@ struct eeprom_dev_spec { static int parse_eeprom_dev_spec(struct eeprom_dev_spec *dev, int argc, char *const argv[]) { +#if CONFIG_IS_ENABLED(I2C_EEPROM) + if (argc == 0) { + if (!uclass_first_device_err(UCLASS_I2C_EEPROM, &dev->dev)) + return 0; + } + + if (argc == 1) { + if (!uclass_get_device_by_name(UCLASS_I2C_EEPROM, argv[0], + &dev->dev)) + return 1; + + /* + * If we could not find the device by name and the parameter is + * not numeric (and so won't be handled later), fail. + */ + if (parse_numeric_param(argv[0]) == -1) { + printf("Can't get eeprom device: %s\n", argv[0]); + return CMD_RET_USAGE; + } + } +#endif + #ifdef CONFIG_SYS_I2C_EEPROM_ADDR if (argc == 0) { dev->i2c_bus = -1; @@ -265,6 +320,7 @@ static unsigned char eeprom_buf[CONFIG_SYS_EEPROM_SIZE]; #endif enum eeprom_action { + EEPROM_LIST, EEPROM_READ, EEPROM_WRITE, EEPROM_PRINT, @@ -274,6 +330,10 @@ enum eeprom_action { static enum eeprom_action parse_action(char *cmd) { +#if CONFIG_IS_ENABLED(I2C_EEPROM) + if (!strncmp(cmd, "list", 4)) + return EEPROM_LIST; +#endif if (!strncmp(cmd, "read", 4)) return EEPROM_READ; if (!strncmp(cmd, "write", 5)) @@ -288,6 +348,24 @@ static enum eeprom_action parse_action(char *cmd) return EEPROM_ACTION_INVALID; } +#if CONFIG_IS_ENABLED(I2C_EEPROM) +static int do_eeprom_list(void) +{ + struct udevice *dev; + struct uclass *uc; + int err; + + err = uclass_get(UCLASS_I2C_EEPROM, &uc); + if (err) + return CMD_RET_FAILURE; + + uclass_foreach_dev(dev, uc) + printf("%s (%s)\n", dev->name, dev->driver->name); + + return CMD_RET_SUCCESS; +} +#endif + static int do_eeprom_rw(struct eeprom_dev_spec *dev, bool read, ulong addr, ulong off, ulong cnt) { @@ -298,9 +376,9 @@ static int do_eeprom_rw(struct eeprom_dev_spec *dev, bool read, printf(fmt, dev->i2c_addr, read ? "read" : "write", addr, off, cnt); if (read) - ret = eeprom_read(dev->i2c_addr, off, memloc, cnt); + ret = eeprom_dev_spec_read(dev, off, memloc, cnt); else - ret = eeprom_write(dev->i2c_addr, off, memloc, cnt); + ret = eeprom_dev_spec_write(dev, off, memloc, cnt); puts("done\n"); return ret; @@ -314,7 +392,7 @@ static int do_eeprom_layout(struct eeprom_dev_spec *dev, int layout_ver, eeprom_layout_setup(layout, eeprom_buf, CONFIG_SYS_EEPROM_SIZE, layout_ver); - return eeprom_read(dev->i2c_addr, 0, eeprom_buf, layout->data_size); + return eeprom_dev_spec_read(dev, 0, eeprom_buf, layout->data_size); } static int do_eeprom_print(struct eeprom_dev_spec *dev, int layout_ver) @@ -345,7 +423,7 @@ static int do_eeprom_update(struct eeprom_dev_spec *dev, int layout_ver, if (ret) return CMD_RET_FAILURE; - return eeprom_write(dev->i2c_addr, 0, layout.data, layout.data_size); + return eeprom_dev_spec_write(dev, 0, layout.data, layout.data_size); } #endif @@ -353,6 +431,8 @@ static int do_eeprom_update(struct eeprom_dev_spec *dev, int layout_ver, static int eeprom_action_expected_argc(enum eeprom_action action) { switch (action) { + case EEPROM_LIST: + return 0; case EEPROM_READ: case EEPROM_WRITE: return 3; @@ -389,6 +469,11 @@ int do_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) if (action == EEPROM_ACTION_INVALID) return CMD_RET_USAGE; +#if CONFIG_IS_ENABLED(I2C_EEPROM) + if (action == EEPROM_LIST) + return do_eeprom_list(); +#endif + #ifdef CONFIG_EEPROM_LAYOUT_VERSIONS if (action == EEPROM_PRINT || action == EEPROM_UPDATE) { if (!strcmp(argv[index], "-l")) { @@ -425,7 +510,7 @@ int do_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } #endif - eeprom_init(dev.i2c_bus); + eeprom_dev_spec_init(&dev); switch (action) { case EEPROM_READ: @@ -450,19 +535,37 @@ int do_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) #define EEPROM_LAYOUT_SPEC "" #endif +#if CONFIG_IS_ENABLED(I2C_EEPROM) +# define EEPROM_DEV_SPEC "[device_specifier]" +#else +# define EEPROM_DEV_SPEC "[[bus] devaddr]" +#endif + U_BOOT_CMD( eeprom, 8, 1, do_eeprom, "EEPROM sub-system", - "read [[bus] devaddr] addr off cnt\n" - "eeprom write [[bus] devaddr] addr off cnt\n" +#if CONFIG_IS_ENABLED(I2C_EEPROM) + "list\n" + "eeprom " +#endif + "read " EEPROM_DEV_SPEC " addr off cnt\n" + "eeprom write " EEPROM_DEV_SPEC " addr off cnt\n" " - read/write `cnt' bytes from `devaddr` EEPROM at offset `off'" #ifdef CONFIG_CMD_EEPROM_LAYOUT "\n" - "eeprom print " EEPROM_LAYOUT_SPEC "[[bus] devaddr]\n" + "eeprom print " EEPROM_LAYOUT_SPEC EEPROM_DEV_SPEC "\n" " - Print layout fields and their data in human readable format\n" - "eeprom update " EEPROM_LAYOUT_SPEC "[[bus] devaddr] field_name field_value\n" + "eeprom update " EEPROM_LAYOUT_SPEC EEPROM_DEV_SPEC " field_name field_value\n" " - Update a specific eeprom field with new data.\n" " The new data must be written in the same human readable format as shown by the print command." +#endif +#if CONFIG_IS_ENABLED(I2C_EEPROM) + "\n\n" + "DEVICE SPECIFIER - the eeprom device can be specified\n" + " [dev_name] - by device name (devices can listed with the eeprom list command)\n" + " [[bus] devaddr] - or by I2C bus and I2C device address\n" + "If no device specifier is given, the first driver-model found device is used." +#endif #ifdef CONFIG_EEPROM_LAYOUT_VERSIONS "\n\n" "LAYOUT VERSIONS\n" @@ -471,5 +574,4 @@ U_BOOT_CMD( "The values which can be provided with the -l option are:\n" CONFIG_EEPROM_LAYOUT_HELP_STRING"\n" #endif -#endif );