]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
imx: kontron-sl-mx8mm: Use eMMC boot part for environment if booting from eMMC
authorFrieder Schrempf <frieder.schrempf@kontron.de>
Tue, 7 Oct 2025 08:16:03 +0000 (10:16 +0200)
committerFabio Estevam <festevam@gmail.com>
Tue, 7 Oct 2025 11:58:28 +0000 (08:58 -0300)
Depending on the MMC boot device, select the proper location for the
environment.

* SD card and eMMC main partition: use offsets from CONFIG_ENV_OFFSET
  and CONFIG_ENV_OFFSET_REDUND.
* eMMC boot partition: use offset -2*ENV_SIZE and -ENV_SIZE from the
  end of the partition.

Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de>
board/kontron/sl-mx8mm/sl-mx8mm.c

index 2e387038395f1fe59577f6925809a1c0d448661b..405ac0fb03f7a445ed0e68679667bd7c7c27c4fa 100644 (file)
@@ -142,7 +142,8 @@ enum env_location env_get_location(enum env_operation op, int prio)
         * the MMC if we are running from SD card or eMMC.
         */
        if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC) &&
-           (boot_dev == SD1_BOOT || boot_dev == SD2_BOOT))
+           (boot_dev == SD1_BOOT || boot_dev == SD2_BOOT ||
+            boot_dev == MMC1_BOOT || boot_dev == MMC2_BOOT))
                return ENVL_MMC;
 
        if (CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH))
@@ -156,4 +157,46 @@ int board_mmc_get_env_dev(int devno)
 {
        return devno;
 }
+
+uint mmc_get_env_part(struct mmc *mmc)
+{
+       if (IS_SD(mmc))
+               return EMMC_HWPART_DEFAULT;
+
+       switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) {
+       case EMMC_BOOT_PART_BOOT1:
+               return EMMC_HWPART_BOOT1;
+       case EMMC_BOOT_PART_BOOT2:
+               return EMMC_HWPART_BOOT2;
+       default:
+               return EMMC_HWPART_DEFAULT;
+       }
+}
+
+int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
+{
+       /* use normal offset for SD card */
+       if (IS_SD(mmc)) {
+               *env_addr = CONFIG_ENV_OFFSET;
+               if (copy)
+                       *env_addr = CONFIG_ENV_OFFSET_REDUND;
+
+               return 0;
+       }
+
+       switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) {
+       case EMMC_BOOT_PART_BOOT1:
+       case EMMC_BOOT_PART_BOOT2:
+               *env_addr = mmc->capacity - CONFIG_ENV_SIZE - CONFIG_ENV_SIZE;
+               if (copy)
+                       *env_addr = mmc->capacity - CONFIG_ENV_SIZE;
+       break;
+       default:
+               *env_addr = CONFIG_ENV_OFFSET;
+               if (copy)
+                       *env_addr = CONFIG_ENV_OFFSET_REDUND;
+       }
+
+       return 0;
+}
 #endif