From patchwork Fri Apr 19 15:55:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Schultz X-Patchwork-Id: 1925623 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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=phytec.de header.i=@phytec.de header.a=rsa-sha256 header.s=a4 header.b=Y8crzEqh; 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 4VLg0S2thgz1xrS for ; Sat, 20 Apr 2024 02:22:32 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D8DC488782; Fri, 19 Apr 2024 18:22:19 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=phytec.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=phytec.de header.i=@phytec.de header.b="Y8crzEqh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 060F3886D9; Fri, 19 Apr 2024 17:55:56 +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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mickerik.phytec.de (mickerik.phytec.de [91.26.50.163]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 17806886DA for ; Fri, 19 Apr 2024 17:55:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=phytec.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=D.Schultz@phytec.de DKIM-Signature: v=1; a=rsa-sha256; d=phytec.de; s=a4; c=relaxed/simple; q=dns/txt; i=@phytec.de; t=1713542153; x=1716134153; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=woPLXzSDZjoP/iDLbE/qCjYZhmDxF5OqPJw5Xpmflco=; b=Y8crzEqhLAQpmOZxUnC2bBp9zlFZVAWrKrotKkQ1zbBf2eOri9dKIS3IN+cbqEgV uJVFbODCKbjai62HOQbPfjEhelXs4nzuQ8LOOMewx7JFQbKDOQdvCSpoOk26Jz2B fUiNBIyHF1u5ocshjW6oTRhJn2TWcANwO4UHy7KF7QM=; X-AuditID: ac14000a-fbefe7000000290d-6e-662294098a47 Received: from berlix.phytec.de (Unknown_Domain [172.25.0.12]) (using TLS with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mickerik.phytec.de (PHYTEC Mail Gateway) with SMTP id 0C.38.10509.90492266; Fri, 19 Apr 2024 17:55:53 +0200 (CEST) Received: from ls-radium.phytec (172.25.0.11) by Berlix.phytec.de (172.25.0.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.6; Fri, 19 Apr 2024 17:55:52 +0200 From: Daniel Schultz To: CC: Daniel Schultz Subject: [PATCH 1/5] board: phytec: common: Generic "add extension" function Date: Fri, 19 Apr 2024 08:55:36 -0700 Message-ID: <20240419155540.2447006-2-d.schultz@phytec.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240419155540.2447006-1-d.schultz@phytec.de> References: <20240419155540.2447006-1-d.schultz@phytec.de> MIME-Version: 1.0 X-Originating-IP: [172.25.0.11] X-ClientProxiedBy: Florix.phytec.de (172.25.0.13) To Berlix.phytec.de (172.25.0.12) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrILMWRmVeSWpSXmKPExsWyRpKBR5dzilKawfQPlhZv93ayOzB6nL2z gzGAMYrLJiU1J7MstUjfLoEr4+zea8wFb8UqJr47zNLAeES4i5GTQ0LAROLNlctMXYxcHEIC S5gknr9fzwzh3GeU+H55DTtIFZuAlsSdLXOZQWwRASmJl50bgWwODmYBDYn2Z0wgYWEBH4m1 HetYQGwWAVWJjf3dYOW8AlYS3ftOsUEsk5eYeek72EhOAWuJ79u/gNUIAdWcX3yeDaJeUOLk zCdgc5iB6pu3zmaGsCUkDr54AVWvIDF722RGmJnTzr1mhrBDJY5sWs00gVFoFpJRs5CMmoVk 1AJG5lWMQrmZydmpRZnZegUZlSWpyXopqZsYQcEqwsC1g7FvjschRiYOxkOMEhzMSiK8ZhyK aUK8KYmVValF+fFFpTmpxYcYpTlYlMR5V3cEpwoJpCeWpGanphakFsFkmTg4pRoYlVNCJ9t6 LSx8Wl/2LyvLSaPINfBeSsDswtX5YtbrCic+OTHn3M2Yhlb/sxulWHXY+vuYrOWln155wpBb 45ezODjY/8C7ZxMdJF/tSbtS7WrO/EVoyekcozVXZ8unxShEJytEOH2POjzDqElmQ4Tsx3+5 t7h1bunPiu9TZL8peiL2mXt1qrsSS3FGoqEWc1FxIgBh7ByYRAIAAA== X-Mailman-Approved-At: Fri, 19 Apr 2024 18:22:18 +0200 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 generic function to apply overlays in our board code to not implement the same logic in different PHYTEC products. Signed-off-by: Daniel Schultz Reviewed-by: Teresa Remmet --- board/phytec/common/phytec_som_detection.c | 33 ++++++++++++++++++++++ board/phytec/common/phytec_som_detection.h | 5 ++++ 2 files changed, 38 insertions(+) diff --git a/board/phytec/common/phytec_som_detection.c b/board/phytec/common/phytec_som_detection.c index a56e0f60d62..d167a77c25b 100644 --- a/board/phytec/common/phytec_som_detection.c +++ b/board/phytec/common/phytec_som_detection.c @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include "phytec_som_detection.h" @@ -213,6 +215,28 @@ u8 __maybe_unused phytec_get_som_type(struct phytec_eeprom_data *data) return data->data.data_api2.som_type; } +#if IS_ENABLED(CONFIG_CMD_EXTENSION) +struct extension *phytec_add_extension(const char *name, const char *overlay, + const char *other) +{ + struct extension *extension; + + if (strlen(overlay) > sizeof(extension->overlay)) { + pr_err("Overlay name %s is longer than %lu.\n", overlay, + sizeof(extension->overlay)); + return NULL; + } + + extension = calloc(1, sizeof(struct extension)); + snprintf(extension->name, sizeof(extension->name), name); + snprintf(extension->overlay, sizeof(extension->overlay), overlay); + snprintf(extension->other, sizeof(extension->other), other); + snprintf(extension->owner, sizeof(extension->owner), "PHYTEC"); + + return extension; +} +#endif /* IS_ENABLED(CONFIG_CMD_EXTENSION) */ + #else inline int phytec_eeprom_data_setup(struct phytec_eeprom_data *data, @@ -253,4 +277,13 @@ u8 __maybe_unused phytec_get_som_type(struct phytec_eeprom_data *data) return PHYTEC_EEPROM_INVAL; } +#if IS_ENABLED(CONFIG_CMD_EXTENSION) +inline struct extension *phytec_add_extension(const char *name, + const char *overlay, + const char *other) +{ + return NULL; +} +#endif /* IS_ENABLED(CONFIG_CMD_EXTENSION) */ + #endif /* IS_ENABLED(CONFIG_PHYTEC_SOM_DETECTION) */ diff --git a/board/phytec/common/phytec_som_detection.h b/board/phytec/common/phytec_som_detection.h index 7edbfa3ca5c..ea99a687fee 100644 --- a/board/phytec/common/phytec_som_detection.h +++ b/board/phytec/common/phytec_som_detection.h @@ -76,4 +76,9 @@ char * __maybe_unused phytec_get_opt(struct phytec_eeprom_data *data); u8 __maybe_unused phytec_get_rev(struct phytec_eeprom_data *data); u8 __maybe_unused phytec_get_som_type(struct phytec_eeprom_data *data); +#if IS_ENABLED(CONFIG_CMD_EXTENSION) +struct extension *phytec_add_extension(const char *name, const char *overlay, + const char *other); +#endif /* IS_ENABLED(CONFIG_CMD_EXTENSION) */ + #endif /* _PHYTEC_SOM_DETECTION_H */ From patchwork Fri Apr 19 15:55:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Schultz X-Patchwork-Id: 1925624 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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=phytec.de header.i=@phytec.de header.a=rsa-sha256 header.s=a4 header.b=hFB8yJBf; 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) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VLg0d1pRCz1xrS for ; Sat, 20 Apr 2024 02:22:41 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 48D3588790; Fri, 19 Apr 2024 18:22:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=phytec.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=phytec.de header.i=@phytec.de header.b="hFB8yJBf"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 540A388775; Fri, 19 Apr 2024 17:55:57 +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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mickerik.phytec.de (mickerik.phytec.de [91.26.50.163]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4956988758 for ; Fri, 19 Apr 2024 17:55:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=phytec.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=D.Schultz@phytec.de DKIM-Signature: v=1; a=rsa-sha256; d=phytec.de; s=a4; c=relaxed/simple; q=dns/txt; i=@phytec.de; t=1713542155; x=1716134155; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=S59DewJB5o1tldzmjn7vLyEyUApGCDCRrTqr9n1yJZw=; b=hFB8yJBfoaBdFQS2GKSBaqBD4+x0cWRuMDRCYrAwm/z/EXCiO0W0dbsqHQnfOHey M3nCf1RjKSJ2qXB9aR86sDm5NgpgM6WL6O9a5Ok/M0lNkf8ndHMdg+B4W0EJV6fD RhiNfEBEhlw0yt2V0ecHO9ljVMHKqXcudGw2e4jbMDM=; X-AuditID: ac14000a-fadff7000000290d-6f-6622940b5593 Received: from berlix.phytec.de (Unknown_Domain [172.25.0.12]) (using TLS with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mickerik.phytec.de (PHYTEC Mail Gateway) with SMTP id 2C.38.10509.B0492266; Fri, 19 Apr 2024 17:55:55 +0200 (CEST) Received: from ls-radium.phytec (172.25.0.11) by Berlix.phytec.de (172.25.0.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.6; Fri, 19 Apr 2024 17:55:54 +0200 From: Daniel Schultz To: CC: Yannic Moog , Daniel Schultz Subject: [PATCH 2/5] board: phytec: introduce eeprom struct member 'valid' Date: Fri, 19 Apr 2024 08:55:37 -0700 Message-ID: <20240419155540.2447006-3-d.schultz@phytec.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240419155540.2447006-1-d.schultz@phytec.de> References: <20240419155540.2447006-1-d.schultz@phytec.de> MIME-Version: 1.0 X-Originating-IP: [172.25.0.11] X-ClientProxiedBy: Florix.phytec.de (172.25.0.13) To Berlix.phytec.de (172.25.0.12) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrALMWRmVeSWpSXmKPExsWyRpKBR5d7ilKawdtLfBZv93ayOzB6nL2z gzGAMYrLJiU1J7MstUjfLoEr48Bc5YIt1hVzt69hbWDcY9DFyMkhIWAi0bbxLEsXIxeHkMAS JonDT5YzQTj3GSUmPp3FBFLFJqAlcWfLXGYQW0RASuJl50Ywm1nAQ2LqmT6wGmEBL4kdU96z gtgsAqoSTTOXs3UxcnDwClhJfJ1cC7FMXmLmpe/sIDangLXE9+1fwMYIAZWcX3yeDcTmFRCU ODnzCQvEeHmJ5q2zoVZJSBx88QKqXkFi9rbJjDAzp517zQxhh0oc2bSaaQKj0Cwko2YhGTUL yagFjMyrGIVyM5OzU4sys/UKMipLUpP1UlI3MYJCVYSBawdj3xyPQ4xMHIyHGCU4mJVEeM04 FNOEeFMSK6tSi/Lji0pzUosPMUpzsCiJ867uCE4VEkhPLEnNTk0tSC2CyTJxcEo1MK64IPL0 id3FnF2hNv/9LgZfEI7fxZJ+2ifCWfnFp4NOoUWPa8wTZb0s3hrvmpYn+rPeLY5ZSnPqKY/7 hwJjtCTWc60QvD7jtZkd/xeh3vMZHlPUrdUjg+17+zXWJE50eDet+cDEG1nLL0xpcznbEx1p mTzv9yxVgcOKDUsigsxeTvyZ5TdnqhJLcUaioRZzUXEiAN58fONDAgAA X-Mailman-Approved-At: Fri, 19 Apr 2024 18:22:18 +0200 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 From: Yannic Moog Add a new nember to the eeprom_data that indicates whether the associated data is valid or not. Make use of this new member in the phytec_eeprom_data_init function by setting the valid value appropriately. Move the eeprom data to a new struct payload that holds the payload of the eeprom. Signed-off-by: Yannic Moog Signed-off-by: Daniel Schultz Reviewed-by: Teresa Remmet --- board/phytec/common/imx8m_som_detection.c | 10 ++-- board/phytec/common/phytec_som_detection.c | 56 ++++++++++++---------- board/phytec/common/phytec_som_detection.h | 11 +++-- 3 files changed, 45 insertions(+), 32 deletions(-) diff --git a/board/phytec/common/imx8m_som_detection.c b/board/phytec/common/imx8m_som_detection.c index 214b75db3b0..7571076a09e 100644 --- a/board/phytec/common/imx8m_som_detection.c +++ b/board/phytec/common/imx8m_som_detection.c @@ -34,10 +34,10 @@ int __maybe_unused phytec_imx8m_detect(struct phytec_eeprom_data *data) data = &eeprom_data; /* We can not do the check for early API revisions */ - if (data->api_rev < PHYTEC_API_REV2) + if (data->payload.api_rev < PHYTEC_API_REV2) return -1; - som = data->data.data_api2.som_no; + som = data->payload.data.data_api2.som_no; debug("%s: som id: %u\n", __func__, som); opt = phytec_get_opt(data); @@ -99,7 +99,7 @@ u8 __maybe_unused phytec_get_imx8m_spi(struct phytec_eeprom_data *data) if (!data) data = &eeprom_data; - if (data->api_rev < PHYTEC_API_REV2) + if (data->payload.api_rev < PHYTEC_API_REV2) return PHYTEC_EEPROM_INVAL; opt = phytec_get_opt(data); @@ -126,7 +126,7 @@ u8 __maybe_unused phytec_get_imx8m_eth(struct phytec_eeprom_data *data) if (!data) data = &eeprom_data; - if (data->api_rev < PHYTEC_API_REV2) + if (data->payload.api_rev < PHYTEC_API_REV2) return PHYTEC_EEPROM_INVAL; opt = phytec_get_opt(data); @@ -154,7 +154,7 @@ u8 __maybe_unused phytec_get_imx8mp_rtc(struct phytec_eeprom_data *data) if (!data) data = &eeprom_data; - if (data->api_rev < PHYTEC_API_REV2) + if (data->payload.api_rev < PHYTEC_API_REV2) return PHYTEC_EEPROM_INVAL; opt = phytec_get_opt(data); diff --git a/board/phytec/common/phytec_som_detection.c b/board/phytec/common/phytec_som_detection.c index d167a77c25b..7913764be0a 100644 --- a/board/phytec/common/phytec_som_detection.c +++ b/board/phytec/common/phytec_som_detection.c @@ -54,6 +54,7 @@ int phytec_eeprom_data_init(struct phytec_eeprom_data *data, int ret, i; unsigned int crc; int *ptr; + const unsigned int payload_size = sizeof(struct phytec_eeprom_payload); if (!data) data = &eeprom_data; @@ -64,14 +65,13 @@ int phytec_eeprom_data_init(struct phytec_eeprom_data *data, ret = i2c_get_chip_for_busnum(bus_num, addr, 2, &dev); if (ret) { pr_err("%s: i2c EEPROM not found: %i.\n", __func__, ret); - return ret; + goto err; } - ret = dm_i2c_read(dev, 0, (uint8_t *)data, - sizeof(struct phytec_eeprom_data)); + ret = dm_i2c_read(dev, 0, (uint8_t *)data, payload_size); if (ret) { - pr_err("%s: Unable to read EEPROM data\n", __func__); - return ret; + pr_err("%s: Unable to read EEPROM data: %i\n", __func__, ret); + goto err; } #else i2c_set_bus_num(bus_num); @@ -79,36 +79,44 @@ int phytec_eeprom_data_init(struct phytec_eeprom_data *data, sizeof(struct phytec_eeprom_data)); #endif - if (data->api_rev == 0xff) { + if (data->payload.api_rev == 0xff) { pr_err("%s: EEPROM is not flashed. Prototype?\n", __func__); - return -EINVAL; + ret = -EINVAL; + goto err; } ptr = (int *)data; - for (i = 0; i < sizeof(struct phytec_eeprom_data); i++) + for (i = 0; i < payload_size; ++i) if (ptr[i] != 0x0) break; - if (i == sizeof(struct phytec_eeprom_data)) { + if (i == payload_size) { pr_err("%s: EEPROM data is all zero. Erased?\n", __func__); - return -EINVAL; + ret = -EINVAL; + goto err; } /* We are done here for early revisions */ - if (data->api_rev <= PHYTEC_API_REV1) + if (data->payload.api_rev <= PHYTEC_API_REV1) { + data->valid = true; return 0; + } - crc = crc8(0, (const unsigned char *)data, - sizeof(struct phytec_eeprom_data)); + crc = crc8(0, (const unsigned char *)&data->payload, payload_size); debug("%s: crc: %x\n", __func__, crc); if (crc) { - pr_err("%s: CRC mismatch. EEPROM data is not usable\n", + pr_err("%s: CRC mismatch. EEPROM data is not usable.\n", __func__); - return -EINVAL; + ret = -EINVAL; + goto err; } + data->valid = true; return 0; +err: + data->valid = false; + return ret; } void __maybe_unused phytec_print_som_info(struct phytec_eeprom_data *data) @@ -120,10 +128,10 @@ void __maybe_unused phytec_print_som_info(struct phytec_eeprom_data *data) if (!data) data = &eeprom_data; - if (data->api_rev < PHYTEC_API_REV2) + if (data->payload.api_rev < PHYTEC_API_REV2) return; - api2 = &data->data.data_api2; + api2 = &data->payload.data.data_api2; /* Calculate PCB subrevision */ pcb_sub_rev = api2->pcb_sub_opt_rev & 0x0f; @@ -182,10 +190,10 @@ char * __maybe_unused phytec_get_opt(struct phytec_eeprom_data *data) if (!data) data = &eeprom_data; - if (data->api_rev < PHYTEC_API_REV2) - opt = data->data.data_api0.opt; + if (data->payload.api_rev < PHYTEC_API_REV2) + opt = data->payload.data.data_api0.opt; else - opt = data->data.data_api2.opt; + opt = data->payload.data.data_api2.opt; return opt; } @@ -197,10 +205,10 @@ u8 __maybe_unused phytec_get_rev(struct phytec_eeprom_data *data) if (!data) data = &eeprom_data; - if (data->api_rev < PHYTEC_API_REV2) + if (data->payload.api_rev < PHYTEC_API_REV2) return PHYTEC_EEPROM_INVAL; - api2 = &data->data.data_api2; + api2 = &data->payload.data.data_api2; return api2->pcb_rev; } @@ -209,10 +217,10 @@ u8 __maybe_unused phytec_get_som_type(struct phytec_eeprom_data *data) { if (!data) data = &eeprom_data; - if (data->api_rev < PHYTEC_API_REV2) + if (data->payload.api_rev < PHYTEC_API_REV2) return PHYTEC_EEPROM_INVAL; - return data->data.data_api2.som_type; + return data->payload.data.data_api2.som_type; } #if IS_ENABLED(CONFIG_CMD_EXTENSION) diff --git a/board/phytec/common/phytec_som_detection.h b/board/phytec/common/phytec_som_detection.h index ea99a687fee..0ad5c14ef4e 100644 --- a/board/phytec/common/phytec_som_detection.h +++ b/board/phytec/common/phytec_som_detection.h @@ -55,7 +55,7 @@ struct phytec_api2_data { u8 crc8; /* checksum */ } __packed; -struct phytec_eeprom_data { +struct phytec_eeprom_payload { u8 api_rev; union { struct phytec_api0_data data_api0; @@ -63,13 +63,18 @@ struct phytec_eeprom_data { } data; } __packed; +struct phytec_eeprom_data { + struct phytec_eeprom_payload payload; + bool valid; +}; + int phytec_eeprom_data_setup_fallback(struct phytec_eeprom_data *data, int bus_num, int addr, int addr_fallback); int phytec_eeprom_data_setup(struct phytec_eeprom_data *data, int bus_num, int addr); -int phytec_eeprom_data_init(struct phytec_eeprom_data *data, - int bus_num, int addr); +int phytec_eeprom_data_init(struct phytec_eeprom_data *data, int bus_num, + int addr); void __maybe_unused phytec_print_som_info(struct phytec_eeprom_data *data); char * __maybe_unused phytec_get_opt(struct phytec_eeprom_data *data); From patchwork Fri Apr 19 15:55:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Schultz X-Patchwork-Id: 1925625 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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=phytec.de header.i=@phytec.de header.a=rsa-sha256 header.s=a4 header.b=Ckts0Igh; 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 4VLg0p258Lz1xrS for ; Sat, 20 Apr 2024 02:22:50 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1FD87887BD; Fri, 19 Apr 2024 18:22:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=phytec.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=phytec.de header.i=@phytec.de header.b="Ckts0Igh"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6C4AB8873B; Fri, 19 Apr 2024 17:56: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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mickerik.phytec.de (mickerik.phytec.de [91.26.50.163]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B2485886DA for ; Fri, 19 Apr 2024 17:55:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=phytec.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=D.Schultz@phytec.de DKIM-Signature: v=1; a=rsa-sha256; d=phytec.de; s=a4; c=relaxed/simple; q=dns/txt; i=@phytec.de; t=1713542156; x=1716134156; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=H07XR7DP9u5BVjqft4yW+SJvcuQYDslGXarPfBAhoiU=; b=Ckts0IghUSVYE0W+SV/vKwW19UXep3ZU3eJ+nHQ5jsBPhk5xrc19ygUMh3tGav2Y 6iC9FfW8rLBJVwSq/ztKci6SGxiGUyzPtJpSxbbdOU4WgoA9SAyK005InjNLo9If qyW6JYqYKod0wk8FPleFB4xre84mKW105iA9hXG8lQ8=; X-AuditID: ac14000a-fadff7000000290d-71-6622940cd008 Received: from berlix.phytec.de (Unknown_Domain [172.25.0.12]) (using TLS with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mickerik.phytec.de (PHYTEC Mail Gateway) with SMTP id 4C.38.10509.C0492266; Fri, 19 Apr 2024 17:55:56 +0200 (CEST) Received: from ls-radium.phytec (172.25.0.11) by Berlix.phytec.de (172.25.0.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.6; Fri, 19 Apr 2024 17:55:55 +0200 From: Daniel Schultz To: CC: Yannic Moog , Daniel Schultz Subject: [PATCH 3/5] board: phytec: check eeprom_data validity Date: Fri, 19 Apr 2024 08:55:38 -0700 Message-ID: <20240419155540.2447006-4-d.schultz@phytec.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240419155540.2447006-1-d.schultz@phytec.de> References: <20240419155540.2447006-1-d.schultz@phytec.de> MIME-Version: 1.0 X-Originating-IP: [172.25.0.11] X-ClientProxiedBy: Florix.phytec.de (172.25.0.13) To Berlix.phytec.de (172.25.0.12) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrELMWRmVeSWpSXmKPExsWyRpKBR5dnilKawcG7GhZv93ayOzB6nL2z gzGAMYrLJiU1J7MstUjfLoEr4+meJ0wF3+QrFnWsYmpgfCbVxcjJISFgIvH5whyWLkYuDiGB JUwSv1f8Z4Rw7jNKTFo4jRWkik1AS+LOlrnMILaIgJTEy86NYDazgIfE1DN9TCC2sICdRMeR 7WD1LAKqEtcu/mMDsXkFrCQeH/nMCLFNXmLmpe/sIDangLXE9+1fwOYIAdWcX3weql5Q4uTM JywQ8+UlmrfOhtolIXHwxQuoegWJ2dsmw82cdu41M4QdKnFk02qmCYxCs5CMmoVk1CwkoxYw Mq9iFMrNTM5OLcrM1ivIqCxJTdZLSd3ECApXEQauHYx9czwOMTJxMB5ilOBgVhLhNeNQTBPi TUmsrEotyo8vKs1JLT7EKM3BoiTOu7ojOFVIID2xJDU7NbUgtQgmy8TBKdXA6Dh7XeCc1e3f hGpimU9tOZq863TZEkk1vZumOzjFjyve196Qe8zNwcO3oW07n97dmymdm7692tPcp+3DvXWf RlPulf0T7bX9r7G/VRCUYXXjWvdPi79t2k2+1zlsU5e/ski5VXvymcFh7tnJh39s0pILzRBQ eK0VEbPax/e8v6Z63WrHmcb5SizFGYmGWsxFxYkAXkdRy0UCAAA= X-Mailman-Approved-At: Fri, 19 Apr 2024 18:22:18 +0200 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 From: Yannic Moog For all of the functions that access the eeprom_data, make sure these data are valid. Use the valid member of the phytec_eeprom_data struct. This fixes a bug where only the API revision check guarded against accessing rubbish. But if API revision was e.g. 6, eeprom setup failed before, but phytec_get_imx8m_eth would still happily access the data. Fixes: dc22188cdc8 ("board: phytec: Add common PHYTEC SoM detection") Signed-off-by: Yannic Moog Signed-off-by: Daniel Schultz Reviewed-by: Teresa Remmet --- board/phytec/common/imx8m_som_detection.c | 11 +++++++---- board/phytec/common/phytec_som_detection.c | 10 +++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/board/phytec/common/imx8m_som_detection.c b/board/phytec/common/imx8m_som_detection.c index 7571076a09e..ee34a5b9579 100644 --- a/board/phytec/common/imx8m_som_detection.c +++ b/board/phytec/common/imx8m_som_detection.c @@ -34,7 +34,7 @@ int __maybe_unused phytec_imx8m_detect(struct phytec_eeprom_data *data) data = &eeprom_data; /* We can not do the check for early API revisions */ - if (data->payload.api_rev < PHYTEC_API_REV2) + if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2) return -1; som = data->payload.data.data_api2.som_no; @@ -75,6 +75,9 @@ u8 __maybe_unused phytec_get_imx8m_ddr_size(struct phytec_eeprom_data *data) if (!data) data = &eeprom_data; + if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2) + return PHYTEC_EEPROM_INVAL; + opt = phytec_get_opt(data); if (opt) ddr_id = PHYTEC_GET_OPTION(opt[2]); @@ -99,7 +102,7 @@ u8 __maybe_unused phytec_get_imx8m_spi(struct phytec_eeprom_data *data) if (!data) data = &eeprom_data; - if (data->payload.api_rev < PHYTEC_API_REV2) + if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2) return PHYTEC_EEPROM_INVAL; opt = phytec_get_opt(data); @@ -126,7 +129,7 @@ u8 __maybe_unused phytec_get_imx8m_eth(struct phytec_eeprom_data *data) if (!data) data = &eeprom_data; - if (data->payload.api_rev < PHYTEC_API_REV2) + if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2) return PHYTEC_EEPROM_INVAL; opt = phytec_get_opt(data); @@ -154,7 +157,7 @@ u8 __maybe_unused phytec_get_imx8mp_rtc(struct phytec_eeprom_data *data) if (!data) data = &eeprom_data; - if (data->payload.api_rev < PHYTEC_API_REV2) + if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2) return PHYTEC_EEPROM_INVAL; opt = phytec_get_opt(data); diff --git a/board/phytec/common/phytec_som_detection.c b/board/phytec/common/phytec_som_detection.c index 7913764be0a..5a4cc9e8b02 100644 --- a/board/phytec/common/phytec_som_detection.c +++ b/board/phytec/common/phytec_som_detection.c @@ -128,7 +128,7 @@ void __maybe_unused phytec_print_som_info(struct phytec_eeprom_data *data) if (!data) data = &eeprom_data; - if (data->payload.api_rev < PHYTEC_API_REV2) + if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2) return; api2 = &data->payload.data.data_api2; @@ -190,6 +190,9 @@ char * __maybe_unused phytec_get_opt(struct phytec_eeprom_data *data) if (!data) data = &eeprom_data; + if (!data->valid) + return NULL; + if (data->payload.api_rev < PHYTEC_API_REV2) opt = data->payload.data.data_api0.opt; else @@ -205,7 +208,7 @@ u8 __maybe_unused phytec_get_rev(struct phytec_eeprom_data *data) if (!data) data = &eeprom_data; - if (data->payload.api_rev < PHYTEC_API_REV2) + if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2) return PHYTEC_EEPROM_INVAL; api2 = &data->payload.data.data_api2; @@ -217,7 +220,8 @@ u8 __maybe_unused phytec_get_som_type(struct phytec_eeprom_data *data) { if (!data) data = &eeprom_data; - if (data->payload.api_rev < PHYTEC_API_REV2) + + if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2) return PHYTEC_EEPROM_INVAL; return data->payload.data.data_api2.som_type; From patchwork Fri Apr 19 15:55:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Schultz X-Patchwork-Id: 1925626 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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=phytec.de header.i=@phytec.de header.a=rsa-sha256 header.s=a4 header.b=obgZmm0W; 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 4VLg0z6tnRz1xrS for ; Sat, 20 Apr 2024 02:22:59 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C45E3887CD; Fri, 19 Apr 2024 18:22:23 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=phytec.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=phytec.de header.i=@phytec.de header.b="obgZmm0W"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 53914886C1; Fri, 19 Apr 2024 17:56: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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mickerik.phytec.de (mickerik.phytec.de [91.26.50.163]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7E5C088771 for ; Fri, 19 Apr 2024 17:55:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=phytec.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=D.Schultz@phytec.de DKIM-Signature: v=1; a=rsa-sha256; d=phytec.de; s=a4; c=relaxed/simple; q=dns/txt; i=@phytec.de; t=1713542158; x=1716134158; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=HTOLsz3eHuPPxQpNm2Jx2yWT/wVT1buvk147hvAWspE=; b=obgZmm0Wok81PNJbDt/DSRSdguut/x91NiI6EO4ujd3y16wv9NOULg/e10JQw/8a 4o7IqTF3pra3upFk0BxXd8E4slsV3ldqINZLHnP9g1RUdx7UDtpI9pydNLmgTM+m 8fqcCiiKUJOSuL0mpB6267qESUFdqII0Uo9rMTH4bKE=; X-AuditID: ac14000a-fadff7000000290d-73-6622940e739b Received: from berlix.phytec.de (Unknown_Domain [172.25.0.12]) (using TLS with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mickerik.phytec.de (PHYTEC Mail Gateway) with SMTP id AC.38.10509.E0492266; Fri, 19 Apr 2024 17:55:58 +0200 (CEST) Received: from ls-radium.phytec (172.25.0.11) by Berlix.phytec.de (172.25.0.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.6; Fri, 19 Apr 2024 17:55:56 +0200 From: Daniel Schultz To: CC: Daniel Schultz Subject: [PATCH 4/5] board: phytec: common: Fix eepom is empty check Date: Fri, 19 Apr 2024 08:55:39 -0700 Message-ID: <20240419155540.2447006-5-d.schultz@phytec.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240419155540.2447006-1-d.schultz@phytec.de> References: <20240419155540.2447006-1-d.schultz@phytec.de> MIME-Version: 1.0 X-Originating-IP: [172.25.0.11] X-ClientProxiedBy: Florix.phytec.de (172.25.0.13) To Berlix.phytec.de (172.25.0.12) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrILMWRmVeSWpSXmKPExsWyRpKBR5dvilKawaHvYhZv93ayOzB6nL2z gzGAMYrLJiU1J7MstUjfLoEr49u3NYwF17kqNl3/zNrAeIuji5GTQ0LARKL/yFKmLkYuDiGB JUwSu+4fZYNw7jNKrPn6jhGkik1AS+LOlrnMILaIgJTEy86NQDYHB7OAhkT7MyaQsLCAi8T5 6+vBbBYBVYlN92+wgNi8AlYS+9b8YIFYJi8x89J3dhCbU8Ba4vv2L2AjhYBqzi8+zwZRLyhx cuYTsHpmoPrmrbOZIWwJiYMvXkDVK0jM3jaZEWbmtHOvmSHsUIkjm1YzTWAUmoVk1Cwko2Yh GbWAkXkVo1BuZnJ2alFmtl5BRmVJarJeSuomRlCwijBw7WDsm+NxiJGJg/EQowQHs5IIrxmH YpoQb0piZVVqUX58UWlOavEhRmkOFiVx3tUdwalCAumJJanZqakFqUUwWSYOTqkGRvudoVuW Rqg7qt5xCT528/u30vW52dXSfk4n9uiqxnzaZcyXM12U+5pm35r3386zWR1TVn9QfKSz4YjJ /lU75GQc99y+dEprnk4Ar56EdWl3p80iLS41xzIL2f3L81Nz7l6+eyOj/tNqlYmPupL/df/2 fbyBd9mLy6WHTbImbP6cUfdvw9b2g0osxRmJhlrMRcWJAP3F+W1EAgAA X-Mailman-Approved-At: Fri, 19 Apr 2024 18:22:18 +0200 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 ptr variable is currently defined as int and sizeof returns the size of the eeprom data struct as Byte (32 in total). In case the eeprom is empty, the check, if the eeprom is empty, will most likely stop after 8 iterations because it will continue with the stack which should contain some data. Therefore, the init function will detect an empty EEPROM as API0 and return with the valid flag set to True. Fixes: dc22188cdc8 ("board: phytec: Add common PHYTEC SoM detection") Signed-off-by: Daniel Schultz Reviewed-by: Teresa Remmet --- board/phytec/common/phytec_som_detection.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/board/phytec/common/phytec_som_detection.c b/board/phytec/common/phytec_som_detection.c index 5a4cc9e8b02..78c173df20d 100644 --- a/board/phytec/common/phytec_som_detection.c +++ b/board/phytec/common/phytec_som_detection.c @@ -53,7 +53,7 @@ int phytec_eeprom_data_init(struct phytec_eeprom_data *data, { int ret, i; unsigned int crc; - int *ptr; + u8 *ptr; const unsigned int payload_size = sizeof(struct phytec_eeprom_payload); if (!data) @@ -85,7 +85,7 @@ int phytec_eeprom_data_init(struct phytec_eeprom_data *data, goto err; } - ptr = (int *)data; + ptr = (u8 *)data; for (i = 0; i < payload_size; ++i) if (ptr[i] != 0x0) break; From patchwork Fri Apr 19 15:55:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Schultz X-Patchwork-Id: 1925627 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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=phytec.de header.i=@phytec.de header.a=rsa-sha256 header.s=a4 header.b=Nz+i8hqj; 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 4VLg1B22nWz1xrS for ; Sat, 20 Apr 2024 02:23:10 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2B54E887E0; Fri, 19 Apr 2024 18:22:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=phytec.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=phytec.de header.i=@phytec.de header.b="Nz+i8hqj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 93996886C1; Fri, 19 Apr 2024 17:56: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,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mickerik.phytec.de (mickerik.phytec.de [91.26.50.163]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8D1C588775 for ; Fri, 19 Apr 2024 17:56:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=phytec.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=D.Schultz@phytec.de DKIM-Signature: v=1; a=rsa-sha256; d=phytec.de; s=a4; c=relaxed/simple; q=dns/txt; i=@phytec.de; t=1713542159; x=1716134159; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:CC:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=JVMaO0MWAYSYKpcl689RuKNIvfPQ6/xqVwwhg3Mt26I=; b=Nz+i8hqjQBV4qyVzDLjIQH2Z4UJ4OKRRw7WnewtGK44hYlUvKgyz2uZJyM4VLXoZ FQUCW8iE7VZtzY5TR6Z839JNLvBTN1EUWkZ2UYxjb+13j2fz20qT/me+lJutOqGs NR8dVKb0ApOANHHo5z1TeoEK8ByD8pUYsz3v1Y84WwA=; X-AuditID: ac14000a-fbefe7000000290d-74-6622940feea8 Received: from berlix.phytec.de (Unknown_Domain [172.25.0.12]) (using TLS with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mickerik.phytec.de (PHYTEC Mail Gateway) with SMTP id CC.38.10509.F0492266; Fri, 19 Apr 2024 17:55:59 +0200 (CEST) Received: from ls-radium.phytec (172.25.0.11) by Berlix.phytec.de (172.25.0.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.6; Fri, 19 Apr 2024 17:55:58 +0200 From: Daniel Schultz To: CC: Daniel Schultz Subject: [PATCH 5/5] board: phytec: Add SOM detection for AM6x Date: Fri, 19 Apr 2024 08:55:40 -0700 Message-ID: <20240419155540.2447006-6-d.schultz@phytec.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240419155540.2447006-1-d.schultz@phytec.de> References: <20240419155540.2447006-1-d.schultz@phytec.de> MIME-Version: 1.0 X-Originating-IP: [172.25.0.11] X-ClientProxiedBy: Florix.phytec.de (172.25.0.13) To Berlix.phytec.de (172.25.0.12) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrILMWRmVeSWpSXmKPExsWyRpKBR5d/ilKawd1DmhZv93ayOzB6nL2z gzGAMYrLJiU1J7MstUjfLoEr49bhzYwFF5wqbvcdZ25gXG7excjJISFgInFt1m/GLkYuDiGB JUwSGyZ8hXLuM0rsm3CQDaSKTUBL4s6WucwgtoiAlMTLzo1ANgcHs4CGRPszJpCwsICdxMr2 5ywgNouAqsSN7m6wVl4BK4kJJ/azQyyTl5h56TuYzSlgLfF9+xewkUJANecXn4eqF5Q4OfMJ 2BxmoPrmrbOZIWwJiYMvXkDVK0jM3jaZEWbmtHOvmSHsUIkjm1YzTWAUmoVk1Cwko2YhGbWA kXkVo1BuZnJ2alFmtl5BRmVJarJeSuomRlCwijBw7WDsm+NxiJGJg/EQowQHs5IIrxmHYpoQ b0piZVVqUX58UWlOavEhRmkOFiVx3tUdwalCAumJJanZqakFqUUwWSYOTqkGRn/ZPyvyF8St jI14nrDszrHZPTwzUpcLXTc0aouYoc7mOSP+elvqtuqu7aKaXl23F7JGCid9shDsuPKXTful Voba2c2xXXsv1tRff9zhtdh5caH1vFnbOgu/T3yZ4/56beVCQ3mnqqUR/WEKS72/V3ismFd3 ZCKb+Sbpp7fFTXzk76co6shUKbEUZyQaajEXFScCAN/ufBJEAgAA X-Mailman-Approved-At: Fri, 19 Apr 2024 18:22:18 +0200 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 all functions to read each SOM option from the EEPROM image and detect whether it's the correct product for this image. Signed-off-by: Daniel Schultz --- board/phytec/common/Kconfig | 18 +++ board/phytec/common/Makefile | 1 + board/phytec/common/am6_som_detection.c | 159 ++++++++++++++++++++++++ board/phytec/common/am6_som_detection.h | 36 ++++++ board/phytec/phycore_am62x/Kconfig | 4 + board/phytec/phycore_am64x/Kconfig | 4 + 6 files changed, 222 insertions(+) create mode 100644 board/phytec/common/am6_som_detection.c create mode 100644 board/phytec/common/am6_som_detection.h diff --git a/board/phytec/common/Kconfig b/board/phytec/common/Kconfig index 3b1c5aa0d02..1077f0f4b61 100644 --- a/board/phytec/common/Kconfig +++ b/board/phytec/common/Kconfig @@ -11,3 +11,21 @@ config PHYTEC_IMX8M_SOM_DETECTION help Support of I2C EEPROM based SoM detection. Supported for PHYTEC i.MX8MM/i.MX8MP boards + +config PHYTEC_AM62_SOM_DETECTION + bool "Support SoM detection for AM62x PHYTEC platforms" + depends on (TARGET_PHYCORE_AM62X_A53 || TARGET_PHYCORE_AM62X_R5) && \ + PHYTEC_SOM_DETECTION + default y + help + Support of I2C EEPROM based SoM detection. Supported + for PHYTEC AM62x boards. + +config PHYTEC_AM64_SOM_DETECTION + bool "Support SoM detection for AM64x PHYTEC platforms" + depends on (TARGET_PHYCORE_AM64X_A53 || TARGET_PHYCORE_AM64X_R5) && \ + PHYTEC_SOM_DETECTION + default y + help + Support of I2C EEPROM based SoM detection. Supported + for PHYTEC AM64x boards. diff --git a/board/phytec/common/Makefile b/board/phytec/common/Makefile index 35c81741306..3feb00fd1ec 100644 --- a/board/phytec/common/Makefile +++ b/board/phytec/common/Makefile @@ -8,4 +8,5 @@ obj- := __dummy__.o endif obj-y += phytec_som_detection.o +obj-$(CONFIG_ARCH_K3) += am6_som_detection.o obj-$(CONFIG_ARCH_IMX8M) += imx8m_som_detection.o diff --git a/board/phytec/common/am6_som_detection.c b/board/phytec/common/am6_som_detection.c new file mode 100644 index 00000000000..2e9884dab44 --- /dev/null +++ b/board/phytec/common/am6_som_detection.c @@ -0,0 +1,159 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2024 PHYTEC Messtechnik GmbH + * Author: Daniel Schultz + */ + +#include + +#include "am6_som_detection.h" + +extern struct phytec_eeprom_data eeprom_data; + +#if IS_ENABLED(CONFIG_PHYTEC_AM62_SOM_DETECTION) || \ + IS_ENABLED(CONFIG_PHYTEC_AM64_SOM_DETECTION) + +/* Check if the SoM is actually one of the following products: + * - phyCORE-AM62x + * - phyCORE-AM64x + * + * Returns 0 in case it's a known SoM. Otherwise, returns -1. + */ +int phytec_am6_detect(struct phytec_eeprom_data *data) +{ + char *opt; + u8 som; + + if (!data) + data = &eeprom_data; + + /* We cannot do the check for early API revisions */ + if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2) + return -1; + + som = data->payload.data.data_api2.som_no; + debug("%s: som id: %u\n", __func__, som); + + opt = phytec_get_opt(data); + if (!opt) + return -1; + + if (som == PHYTEC_AM62X_SOM && soc_is_am62x()) + return 0; + + if (som == PHYTEC_AM64X_SOM && soc_is_am64x()) + return 0; + + return -1; +} + +static u8 phytec_check_opt(struct phytec_eeprom_data *data, u8 option) +{ + char *opt; + + if (!data) + data = &eeprom_data; + + if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2) + return PHYTEC_EEPROM_INVAL; + + if (option > 8) + return PHYTEC_EEPROM_INVAL; + + opt = phytec_get_opt(data); + if (opt) + return PHYTEC_GET_OPTION(opt[option]); + return PHYTEC_EEPROM_INVAL; +} + +/* + * Reads LPDDR4 ram size from EEPROM. + * + * returns: + * - The size + * - PHYTEC_EEPROM_INVAL when the data is invalid. + */ +u8 __maybe_unused phytec_get_am62_ddr_size(struct phytec_eeprom_data *data) +{ + u8 ddr_id = phytec_check_opt(data, 3); + + pr_debug("%s: ddr id: %u\n", __func__, ddr_id); + return ddr_id; +} + +/* + * Reads SPI-NOR flash size and type from EEPROM. + * + * returns: + * - PHYTEC_EEPROM_VALUE_X if no SPI is poulated. + * - Otherwise a board depended code for the size. + * - PHYTEC_EEPROM_INVAL when the data is invalid. + */ +u8 __maybe_unused phytec_get_am62_spi(struct phytec_eeprom_data *data) +{ + u8 spi = phytec_check_opt(data, 5); + + pr_debug("%s: spi: %u\n", __func__, spi); + return spi; +} + +/* + * Reads Ethernet phy information from EEPROM. + * + * returns: + * - 0x0 no ethernet phy is populated. + * - 0x1 if 10/100/1000 MBit Phy is populated. + * - PHYTEC_EEPROM_INVAL when the data is invalid. + */ +u8 __maybe_unused phytec_get_am62_eth(struct phytec_eeprom_data *data) +{ + u8 eth = phytec_check_opt(data, 6); + + pr_debug("%s: eth: %u\n", __func__, eth); + return eth; +} + +/* + * Reads RTC information from EEPROM. + * + * returns: + * - 0 if no RTC is poulated. + * - 1 if it is populated. + * - PHYTEC_EEPROM_INVAL when the data is invalid. + */ +u8 __maybe_unused phytec_get_am62_rtc(struct phytec_eeprom_data *data) +{ + u8 rtc = phytec_check_opt(data, 7); + + pr_debug("%s: rtc: %u\n", __func__, rtc); + return rtc; +} + +#else + +inline int __maybe_unused phytec_am62_detect(struct phytec_eeprom_data *data) +{ + return -1; +} + +inline u8 __maybe_unused +phytec_get_am62_ddr_size(struct phytec_eeprom_data *data) +{ + return PHYTEC_EEPROM_INVAL; +} + +inline u8 __maybe_unused phytec_get_am62_spi(struct phytec_eeprom_data *data) +{ + return PHYTEC_EEPROM_INVAL; +} + +inline u8 __maybe_unused phytec_get_am62_eth(struct phytec_eeprom_data *data) +{ + return PHYTEC_EEPROM_INVAL; +} + +inline u8 __maybe_unused phytec_get_am62_rtc(struct phytec_eeprom_data *data) +{ + return PHYTEC_EEPROM_INVAL; +} +#endif diff --git a/board/phytec/common/am6_som_detection.h b/board/phytec/common/am6_som_detection.h new file mode 100644 index 00000000000..032f9da3aab --- /dev/null +++ b/board/phytec/common/am6_som_detection.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2024 PHYTEC Messtechnik GmbH + * Author: Daniel Schultz + */ + +#ifndef _PHYTEC_AM6_SOM_DETECTION_H +#define _PHYTEC_AM6_SOM_DETECTION_H + +#include "phytec_som_detection.h" + +#define PHYTEC_AM62X_SOM 71 +#define PHYTEC_AM64X_SOM 72 +#define PHYTEC_EEPROM_VALUE_X 0x21 +#define PHYTEC_EEPROM_NOR_FLASH_64MB_QSPI 0xC + +int __maybe_unused phytec_am6_detect(struct phytec_eeprom_data *data); +u8 __maybe_unused phytec_get_am6_ddr_size(struct phytec_eeprom_data *data); +u8 __maybe_unused phytec_get_am6_spi(struct phytec_eeprom_data *data); +u8 __maybe_unused phytec_get_am6_eth(struct phytec_eeprom_data *data); +u8 __maybe_unused phytec_get_am6_rtc(struct phytec_eeprom_data *data); + +static inline int phytec_am6_is_qspi(struct phytec_eeprom_data *data) +{ + u8 spi = phytec_get_am6_spi(data); + + if (spi == PHYTEC_EEPROM_VALUE_X) + return 0; + return spi <= PHYTEC_EEPROM_NOR_FLASH_64MB_QSPI; +} + +static inline int phytec_am6_is_ospi(struct phytec_eeprom_data *data) +{ + return phytec_get_am6_spi(data) > PHYTEC_EEPROM_NOR_FLASH_64MB_QSPI; +} +#endif /* _PHYTEC_AM6_SOM_DETECTION_H */ diff --git a/board/phytec/phycore_am62x/Kconfig b/board/phytec/phycore_am62x/Kconfig index b64c3451389..1de8850c6c4 100644 --- a/board/phytec/phycore_am62x/Kconfig +++ b/board/phytec/phycore_am62x/Kconfig @@ -14,6 +14,8 @@ config SYS_VENDOR config SYS_CONFIG_NAME default "phycore_am62x" +source "board/phytec/common/Kconfig" + endif if TARGET_PHYCORE_AM62X_R5 @@ -30,4 +32,6 @@ config SYS_CONFIG_NAME config SPL_LDSCRIPT default "arch/arm/mach-omap2/u-boot-spl.lds" +source "board/phytec/common/Kconfig" + endif diff --git a/board/phytec/phycore_am64x/Kconfig b/board/phytec/phycore_am64x/Kconfig index 427adb6fedd..829526c3295 100644 --- a/board/phytec/phycore_am64x/Kconfig +++ b/board/phytec/phycore_am64x/Kconfig @@ -17,6 +17,8 @@ config SYS_VENDOR config SYS_CONFIG_NAME default "phycore_am64x" +source "board/phytec/common/Kconfig" + endif if TARGET_PHYCORE_AM64X_R5 @@ -30,4 +32,6 @@ config SYS_VENDOR config SYS_CONFIG_NAME default "phycore_am64x" +source "board/phytec/common/Kconfig" + endif