1 From 6731bef6966ea2b26cdcfe0109ff5a950003fd03 Mon Sep 17 00:00:00 2001
2 From: David Woodhouse <dwmw2@infradead.org>
3 Date: Fri, 19 Jun 2020 23:07:17 +0100
4 Subject: [PATCH] env/fat.c: allow loading from a FAT partition on the MMC boot
7 I don't want to have to specify the device; only the partition.
9 This allows me to use the same image on internal eMMC or SD card for
10 Banana Pi R2, and it finds its own environment either way.
12 Signed-off-by: David Woodhouse <dwmw2@infradead.org>
13 [trini: Add #if/#else/#endif logic around CONFIG_SYS_MMC_ENV_DEV usage,
15 Signed-off-by: Tom Rini <trini@konsulko.com>
18 env/fat.c | 32 ++++++++++++++++++++++++++++++--
19 2 files changed, 34 insertions(+), 2 deletions(-)
21 diff --git a/env/Kconfig b/env/Kconfig
22 index 38e7fadbb9..5784136674 100644
25 @@ -434,6 +434,10 @@ config ENV_FAT_DEVICE_AND_PART
26 If none, first valid partition in device D. If no
27 partition table then means device D.
29 + If ENV_FAT_INTERFACE is set to "mmc" then device 'D' can be omitted,
30 + leaving the string starting with a colon, and the boot device will
34 string "Name of the FAT file to use for the environment"
35 depends on ENV_IS_IN_FAT
36 diff --git a/env/fat.c b/env/fat.c
37 index 35a1955e63..63aced9317 100644
44 +__weak int mmc_get_env_dev(void)
46 +#ifdef CONFIG_SYS_MMC_ENV_DEV
47 + return CONFIG_SYS_MMC_ENV_DEV;
53 +static char *env_fat_device_and_part(void)
56 + static char *part_str;
59 + part_str = CONFIG_ENV_FAT_DEVICE_AND_PART;
60 + if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc") && part_str[0] == ':') {
61 + part_str = "0" CONFIG_ENV_FAT_DEVICE_AND_PART;
62 + part_str[0] += mmc_get_env_dev();
68 + return CONFIG_ENV_FAT_DEVICE_AND_PART;
72 static int env_fat_save(void)
74 env_t __aligned(ARCH_DMA_MINALIGN) env_new;
75 @@ -43,7 +71,7 @@ static int env_fat_save(void)
78 part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
79 - CONFIG_ENV_FAT_DEVICE_AND_PART,
80 + env_fat_device_and_part(),
84 @@ -89,7 +117,7 @@ static int env_fat_load(void)
87 part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
88 - CONFIG_ENV_FAT_DEVICE_AND_PART,
89 + env_fat_device_and_part(),
92 goto err_env_relocate;