From patchwork Thu Dec 3 17:18:03 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 5157 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id EA6823F3B1 for ; Thu, 3 Dec 2026 18:19:33 +0100 (CET) Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-492b5408dedsf54119f8f.3 for ; Thu, 03 Dec 2026 09:19:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1796318373; cv=pass; d=google.com; s=arc-20260327; b=f4EGtqjX1OHaHRZNH9QUHvev0Q0V/bwpY86N6F5sbRB7w/sQjPMY1rplkRvKp+QDsz 0rwYub5GgbSrQZcE+tQbpo1zt92uy4tky8RFCo32S1MAKwFAr3gx4tynBCVG4QO9wyAD 9q3OPqN4TFap58I779BWLMky/xeuKUQmrFAvb5IrUiAOqlJt0ovgryIpIa+npeSbgZ8M srdD+lmVCmjS+X8rkCNmUtu3lK871FsKzzumq8yWDowsBKGwjh12BBsfi3stwIFiZ0bx E3HV3bhOB6mC8E9Nfo6DtfBzCrYmyqAZHpdlE0Hr2evmFdAw7dfVocGvwYrLpM3tKUEv pbwQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=FxcBaqozxAUvHm8ZlfH8DV47feLFmzHcpSLuBHS8SH8=; fh=KbuijPtv1k56zUmzycnqZb3R1gZWP5Oi0PI58WwFx5w=; b=Us1NgBlvCBnmAld/3va8lko4uhiQFuskXAsC2sFxPKKmKCveWd8I5jdrsQHdMhH143 RVEFWyam1lOJgcV8NTvP0KbXJVagvMi/lo1+0CKCmU3mdy1FQCllz96JNt9068l3wTGg Zbf+OYVdE/U9OKi064vPe1qcHYS/pH5xlH9eo/POTItRQA8CoojgX2102kWbPsBRNs8o z7uj6lDv7HvElnfpHJWUOOYmFBEYlI4vDgiAQNobLy7SgNipt6Z/veJx9b9FqHAVL/MZ 23a+z4dk115TerkfEa/27/P+vqkBpTDYytRsoWwgr2agp08iVz0FP18MArAq/4AwYfYm Hx4g==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=CIfeKGyr; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1796318373; x=1796923173; darn=patchwork.amarulasolutions.com; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:content-type :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to:content-type; bh=FxcBaqozxAUvHm8ZlfH8DV47feLFmzHcpSLuBHS8SH8=; b=iecGND7FKN8w/t2zkbTBWbdLnlxfajylZUqz4vMVGVhyDXi5Rs6y0ziLajSlrfecsY qSa6TFWiYm6Qy00B+Z5alrb9io9pjkfqeuh7pr1tpdyyqab7Gc/0yFLbxLdWHYYdTNXG 2CCqU8Pu8rPPTxjFjpdHoyjPo8A66oBSwO/T8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796318373; x=1796923173; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :content-type:x-original-authentication-results:x-original-sender :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-gg:x-beenthere:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=FxcBaqozxAUvHm8ZlfH8DV47feLFmzHcpSLuBHS8SH8=; b=Fhq55QNoJaGNTCsT1lNX/VGxs3N2wExPaQuiC75+RbAOr+EfkwKkKRfGSRXzTJZ9/+ bgn+Mu+WlOxM6h/nT9vC3k9VfsiF7QTM6zX57aWhrNw9B+Qu0Veo2LGSuR+LLxBc1wfu 461BXnc4uB2U8YW89+r/ITtSegfWu4FDJpsxRDPeiXW2vvc48EHl2Dm5OSmTrMFfxICO 0xOAwQ5qc40kHqukAMSpMLHl9mVqHY33DBFI6X3Yhgsonq5e0HsFbyf2eL9dYJ7ey0CK 4J4hxHVEWKsapzliL17r762dd7wui6wqfLj2mrASCVavD4L4Zo8tNXk1y3QpT/XJD0QS DNfg== X-Forwarded-Encrypted: i=2; AL+hErFA0ZTgdLB3bvanxVhtCaljlfVI1blgvo5rFLbSlS0WNYpXM6Iw9NImYbURyeONz67ldWzQRVcBmJpvkYCH@patchwork.amarulasolutions.com X-Gm-Message-State: APuU4Z/kbpdpkuMGeV6vF0czYK7aCTX5CENpw2uCy4iW4JcaVBoXme7y 0UvwIfhC8LylH45zxEOuNVMZ+YMdEALx7bmT9xV7/Nx0tH+voyKAw5Npmc7oDJt65jSLCJs8UuQ I2w== X-Received: by 2002:a05:6000:40c9:b0:4b4:510c:519e with SMTP id ffacd0b85a97d-4bdfa714d92mr50591236f8f.27.1796318373624; Thu, 03 Dec 2026 09:19:33 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com; h="ATskLdcPQTJaLpKJvIqvD+/PfP46T4resprp3/LrYfeevUzSDQ==" Received: by 2002:a05:6000:2889:b0:486:e8fb:7aa4 with SMTP id ffacd0b85a97d-4abcdd50b75ls142069f8f.1.-pod-prod-08-eu; Thu, 03 Dec 2026 09:19:32 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErGc1OVJqhkzr6ZKpXO3fTee46MoOWs/bYm0bK5MVQELRtSZd0Fzm4v9jh8R19caXfNl8+66PiW4iUkfvjCv@amarulasolutions.com X-Received: by 2002:a05:6000:258a:b0:4a5:a777:b5df with SMTP id ffacd0b85a97d-4aba53215femr88380002f8f.0.1796318370676; Thu, 03 Dec 2026 09:19:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1796318370; cv=none; d=google.com; s=arc-20260327; b=HUqsPZEW9eyFANl8kz2DXTSBgKH44YH87Rd7f1/Qn6qRyfwgLr14tVZNwIpX1VlvdA h27xjRSqzuaFRMr5IHD87ehb7+5ikLXd0t7M5wNpHdk/vTRtpFSkvOAG8mzr/rDdV1fB kKWCiKOhNX+hgXn7Vniu3KzQsEd0tgDB2tuOYFNq6dR7xl//ejoZa8EYe1NNGn1kUqGW lBtHItzZZ/j50Bm4agBFNA2Gx5ko7WGxUYM4UCAdFq6fqwDGB5eC6XiN2QM0CilrrOzI 7ZO/bsEn9LIE/adp7A6OsuKJFZuoPaU7+ad4cYDSotbi6akKyK5rO417WvFYjozvLTX/ 6czg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=tYqquPNi60jmN9Z0legA/bhrONNjIC49KfirirskFSk=; fh=CwGTN4RyiwHzmuNnJ9kte45BbKm//QMUFuf/ZXaGGks=; b=YDBV5T55ZS/zHAKtDB/RMDiBxnO+HrFU2EjgUo5lzHPP80Re5H/vPDuWTzH1m8GkbZ bK7JiJ+2d+sC0tH0+6y7Ejjq+ZVUjtVYP27kKr95RKd/VSsjfg9NkictC+5uOrTFg+EZ X//7HteMlArSungdorfMzoPNSO8H61i0DMOIsgc5ij48jsIzPaTVVV6v+65oV/+Y7A8H NOV0NEY3hvPqYmjapOyGdmiu/Td3PCGQ5n86ozRzWK0J4feiISbfTozhoUzD9wgWZj7h cSEH8DyOv4Ax0Tu3pvh9nzmTzvh7+L1pTT0/lsTm28vgBqYt5C6qVP+jBAMRNMkix+Pa hUng==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=CIfeKGyr; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id ffacd0b85a97d-4ab70b053d9sor4706623f8f.4.2026.12.03.09.19.30 for (Google Transport Security); Thu, 03 Dec 2026 09:19:30 -0800 (PST) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Forwarded-Encrypted: i=1; AL+hErFLdUSbqseztT2xP5hb1uPWMrhvYhp3Ah2BsjT5E1jKJafgLSiaygPCdVq8isI8LF3vmm14KdJaiVD7CEM1@amarulasolutions.com X-Gm-Gg: AZFdTZeCWpHsJkCE+OA1bx8hXeo2hZTD/VI+v+oHzzAOm+XbWwrt2h7c7GzQyKmA7X1 q8vFMK9tjgqfdoqOoZY05sK4cZr6UiaGKTjDHeG+menR0EN1kyIFBMe1LkH62TqJhvoTiLJ+l3C v4iMme23MeLGzWvdF+4iYTD3MI2NyBvLWHRSGfUqfmYTQ3UH0X4o4B2falZNkLkY+SlhW2t42S9 TcLsvfUCc6taZDkJZXBHEHcQZHOR1HOStZdNCQmh8GiFF0WLNFY/SBQ+4N37BKQl3r45kuT9SxP VI+M63v6lfaky8YDczGwgAZCJc+m2eOcLqLlnpLZluDHdnHpzVN0Kxq8u3J7T8Q9yBZ6B6mEr3e NvJyvHWLnqXksbCJ7bjoPKM7771qF2uN+I9hZiS579fe99tnm1vl3ujUlztMdf4xs9Sv9LLCCKv VLL/G1A+LABzY1qoOOijV7J6lvGzLIijqJ121CiVMPlMRv3lYplooNVRUIqzkQoId2wNFwo3k4o Mb/JjPum5e8cRxgsZoNbwbH47NpSkGm8wMgCdwkzWwh8jPXKpXW36tj040I2DSh6MNVAs71Bip0 Dt+5hJ88nwivZW64y5Z19VBeMcH8UcH33W9422bYyNC/i4DflPMhV7VVA5PGdgWSAjVL3L24j+3 c177L68tNvq7DkAoFan3+T+NXIixQu2A6odOCQ7lVerCB4RszmCIVqsuXIYh4etHfnSFKMFUmEq ooQ1/BBDXjs+vtDtt8yu0aWmb0wQ== X-Received: by 2002:a05:6000:4704:b0:4a9:760f:183a with SMTP id ffacd0b85a97d-4abb400aef0mr89483704f8f.32.1796318370247; Thu, 03 Dec 2026 09:19:30 -0800 (PST) Received: from dario-ThinkPad-P14s-Gen-5.homenet.telecomitalia.it (host-79-14-29-58.business.telecomitalia.it. [79.14.29.58]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d173ab8e3fsm329012f8f.42.2026.12.03.09.19.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 09:19:29 -0800 (PST) From: Dario Binacchi To: Patrice Chotard , Patrick Delaunay Cc: michael@amarulasolutions.com, Yannick Fertre , linux-amarula@amarulasolutions.com, Dario Binacchi , Ilias Apalodimas , Tom Rini , u-boot@lists.u-boot-project.org Subject: [PATCH v4 18/29] arm: stm32mp: stm32mp2: move boot device environment helpers to SoC code Date: Thu, 3 Dec 2026 18:18:03 +0100 Message-ID: <20261203171852.62649-19-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261203171852.62649-1-dario.binacchi@amarulasolutions.com> References: <20261203171852.62649-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=CIfeKGyr; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The environment location and the MMC environment device only depend on the boot device reported by the ROM code, so they are not specific to the STMicroelectronics boards. Move env_get_location(), mmc_get_env_dev() and the mmc_get_boot() helper to the SoC code, so that other vendor boards can use them too. No functional change intended. Signed-off-by: Dario Binacchi Reviewed-by: Patrice Chotard --- (no changes since v3) Changes in v3: - Add Reviewed-by tag arch/arm/mach-stm32mp/stm32mp2/Makefile | 1 + arch/arm/mach-stm32mp/stm32mp2/env.c | 82 +++++++++++++++++++++++++ board/st/stm32mp2/stm32mp2.c | 71 +-------------------- 3 files changed, 84 insertions(+), 70 deletions(-) create mode 100644 arch/arm/mach-stm32mp/stm32mp2/env.c diff --git a/arch/arm/mach-stm32mp/stm32mp2/Makefile b/arch/arm/mach-stm32mp/stm32mp2/Makefile index 8f2e641dcab6..f2def2d1283e 100644 --- a/arch/arm/mach-stm32mp/stm32mp2/Makefile +++ b/arch/arm/mach-stm32mp/stm32mp2/Makefile @@ -5,6 +5,7 @@ obj-y += cpu.o obj-y += arm64-mmu.o +obj-y += env.o obj-y += rifsc.o obj-y += stm32mp2x.o obj-$(CONFIG_OF_SYSTEM_SETUP) += fdt.o diff --git a/arch/arm/mach-stm32mp/stm32mp2/env.c b/arch/arm/mach-stm32mp/stm32mp2/env.c new file mode 100644 index 000000000000..9e7b5b882908 --- /dev/null +++ b/arch/arm/mach-stm32mp/stm32mp2/env.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause +/* + * Copyright (C) 2023, STMicroelectronics - All Rights Reserved + */ + +#define LOG_CATEGORY LOGC_ARCH + +#include +#include +#include +#include +#include +#include +#include + +enum env_location env_get_location(enum env_operation op, int prio) +{ + u32 bootmode = get_bootmode(); + + if (prio) + return ENVL_UNKNOWN; + + switch (bootmode & TAMP_BOOT_DEVICE_MASK) { + case BOOT_FLASH_SD: + case BOOT_FLASH_EMMC: + if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC)) + return ENVL_MMC; + else + return ENVL_NOWHERE; + + case BOOT_FLASH_NAND: + case BOOT_FLASH_SPINAND: + if (CONFIG_IS_ENABLED(ENV_IS_IN_UBI)) + return ENVL_UBI; + else + return ENVL_NOWHERE; + + case BOOT_FLASH_NOR: + if (CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH)) + return ENVL_SPI_FLASH; + else + return ENVL_NOWHERE; + default: + return ENVL_NOWHERE; + } +} + +static int mmc_get_boot(void) +{ + struct udevice *dev; + u32 boot_mode = get_bootmode(); + unsigned int instance = (boot_mode & TAMP_BOOT_INSTANCE_MASK) - 1; + char cmd[20]; + const u32 sdmmc_addr[] = { + STM32_SDMMC1_BASE, + STM32_SDMMC2_BASE, + STM32_SDMMC3_BASE + }; + + if (instance >= ARRAY_SIZE(sdmmc_addr)) + return 0; + + /* search associated sdmmc node in devicetree */ + snprintf(cmd, sizeof(cmd), "mmc@%x", sdmmc_addr[instance]); + if (uclass_get_device_by_name(UCLASS_MMC, cmd, &dev)) { + log_err("mmc%d = %s not found in device tree!\n", instance, cmd); + return 0; + } + + return dev_seq(dev); +} + +int mmc_get_env_dev(void) +{ + const int mmc_env_dev = CONFIG_IS_ENABLED(ENV_IS_IN_MMC, (CONFIG_ENV_MMC_DEVICE_INDEX), (-1)); + + if (mmc_env_dev >= 0) + return mmc_env_dev; + + /* use boot instance to select the correct mmc device identifier */ + return mmc_get_boot(); +} diff --git a/board/st/stm32mp2/stm32mp2.c b/board/st/stm32mp2/stm32mp2.c index f2575339b990..96735fa9f8a1 100644 --- a/board/st/stm32mp2/stm32mp2.c +++ b/board/st/stm32mp2/stm32mp2.c @@ -7,12 +7,11 @@ #include #include -#include +#include #include #include #include #include -#include #include #include #include @@ -88,74 +87,6 @@ int board_init(void) return 0; } -enum env_location env_get_location(enum env_operation op, int prio) -{ - u32 bootmode = get_bootmode(); - - if (prio) - return ENVL_UNKNOWN; - - switch (bootmode & TAMP_BOOT_DEVICE_MASK) { - case BOOT_FLASH_SD: - case BOOT_FLASH_EMMC: - if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC)) - return ENVL_MMC; - else - return ENVL_NOWHERE; - - case BOOT_FLASH_NAND: - case BOOT_FLASH_SPINAND: - if (CONFIG_IS_ENABLED(ENV_IS_IN_UBI)) - return ENVL_UBI; - else - return ENVL_NOWHERE; - - case BOOT_FLASH_NOR: - if (CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH)) - return ENVL_SPI_FLASH; - else - return ENVL_NOWHERE; - default: - return ENVL_NOWHERE; - } -} - -int mmc_get_boot(void) -{ - struct udevice *dev; - u32 boot_mode = get_bootmode(); - unsigned int instance = (boot_mode & TAMP_BOOT_INSTANCE_MASK) - 1; - char cmd[20]; - const u32 sdmmc_addr[] = { - STM32_SDMMC1_BASE, - STM32_SDMMC2_BASE, - STM32_SDMMC3_BASE - }; - - if (instance >= ARRAY_SIZE(sdmmc_addr)) - return 0; - - /* search associated sdmmc node in devicetree */ - snprintf(cmd, sizeof(cmd), "mmc@%x", sdmmc_addr[instance]); - if (uclass_get_device_by_name(UCLASS_MMC, cmd, &dev)) { - log_err("mmc%d = %s not found in device tree!\n", instance, cmd); - return 0; - } - - return dev_seq(dev); -}; - -int mmc_get_env_dev(void) -{ - const int mmc_env_dev = CONFIG_IS_ENABLED(ENV_IS_IN_MMC, (CONFIG_ENV_MMC_DEVICE_INDEX), (-1)); - - if (mmc_env_dev >= 0) - return mmc_env_dev; - - /* use boot instance to select the correct mmc device identifier */ - return mmc_get_boot(); -} - int board_late_init(void) { const void *fdt_compat;