uboot-mediatek: resync patches with upstream
[openwrt/openwrt.git] / package / boot / uboot-mediatek / patches / 007-env-fat-use-bootdevice.patch
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
5 device
6
7 I don't want to have to specify the device; only the partition.
8
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.
11
12 Signed-off-by: David Woodhouse <dwmw2@infradead.org>
13 [trini: Add #if/#else/#endif logic around CONFIG_SYS_MMC_ENV_DEV usage,
14 whitespace changes]
15 Signed-off-by: Tom Rini <trini@konsulko.com>
16 ---
17 env/Kconfig | 4 ++++
18 env/fat.c | 32 ++++++++++++++++++++++++++++++--
19 2 files changed, 34 insertions(+), 2 deletions(-)
20
21 diff --git a/env/Kconfig b/env/Kconfig
22 index 38e7fadbb9..5784136674 100644
23 --- a/env/Kconfig
24 +++ b/env/Kconfig
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.
28
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
31 + be used.
32 +
33 config ENV_FAT_FILE
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
38 --- a/env/fat.c
39 +++ b/env/fat.c
40 @@ -29,6 +29,36 @@
41 # endif
42 #endif
43
44 +#if defined(CMD_SAVEENV) || defined(CMD_LOADENV)
45 +__weak int mmc_get_env_dev(void)
46 +{
47 +#ifdef CONFIG_SYS_MMC_ENV_DEV
48 + return CONFIG_SYS_MMC_ENV_DEV;
49 +#else
50 + return 0;
51 +#endif
52 +}
53 +
54 +static char *env_fat_device_and_part(void)
55 +{
56 +#ifdef CONFIG_MMC
57 + static char *part_str;
58 +
59 + if (!part_str) {
60 + part_str = CONFIG_ENV_FAT_DEVICE_AND_PART;
61 + if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc") && part_str[0] == ':') {
62 + part_str = "0" CONFIG_ENV_FAT_DEVICE_AND_PART;
63 + part_str[0] += mmc_get_env_dev();
64 + }
65 + }
66 +
67 + return part_str;
68 +#else
69 + return CONFIG_ENV_FAT_DEVICE_AND_PART;
70 +#endif
71 +}
72 +#endif
73 +
74 #ifdef CMD_SAVEENV
75 static int env_fat_save(void)
76 {
77 @@ -43,7 +71,7 @@ static int env_fat_save(void)
78 return err;
79
80 part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
81 - CONFIG_ENV_FAT_DEVICE_AND_PART,
82 + env_fat_device_and_part(),
83 &dev_desc, &info, 1);
84 if (part < 0)
85 return 1;
86 @@ -89,7 +117,7 @@ static int env_fat_load(void)
87 #endif
88
89 part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
90 - CONFIG_ENV_FAT_DEVICE_AND_PART,
91 + env_fat_device_and_part(),
92 &dev_desc, &info, 1);
93 if (part < 0)
94 goto err_env_relocate;
95 --
96 2.26.2
97