mediatek: use U-Boot FAT environment support for Banana Pi R2
[openwrt/openwrt.git] / package / boot / uboot-mediatek / patches / 007-env-fat-use-bootdevice.patch
1 From fb2810b2c7209d4ed690e48e5bffa52d1af2eda3 Mon Sep 17 00:00:00 2001
2 From: David Woodhouse <dwmw2@infradead.org>
3 Date: Fri, 19 Jun 2020 22:57:04 +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 Signed-off-by: David Woodhouse <dwmw2@infradead.org>
10 ---
11 env/Kconfig | 4 ++++
12 env/fat.c | 31 +++++++++++++++++++++++++++++--
13 2 files changed, 33 insertions(+), 2 deletions(-)
14
15 diff --git a/env/Kconfig b/env/Kconfig
16 index 0d6f559b39..a2020a8661 100644
17 --- a/env/Kconfig
18 +++ b/env/Kconfig
19 @@ -432,6 +432,10 @@ config ENV_FAT_DEVICE_AND_PART
20 If none, first valid partition in device D. If no
21 partition table then means device D.
22
23 + If ENV_FAT_INTERFACE is set to "mmc" then device 'D' can be omitted,
24 + leaving the string starting with a colon, and the boot device will
25 + be used.
26 +
27 config ENV_FAT_FILE
28 string "Name of the FAT file to use for the environment"
29 depends on ENV_IS_IN_FAT
30 diff --git a/env/fat.c b/env/fat.c
31 index 1836556f36..1c32d17bd5 100644
32 --- a/env/fat.c
33 +++ b/env/fat.c
34 @@ -31,6 +31,33 @@
35 # endif
36 #endif
37
38 +#if defined(CMD_SAVEENV) || defined(CMD_LOADENV)
39 +__weak int mmc_get_env_dev(void)
40 +{
41 + return CONFIG_SYS_MMC_ENV_DEV;
42 +}
43 +
44 +static char *env_fat_device_and_part(void)
45 +{
46 +#ifdef CONFIG_MMC
47 + static char *part_str;
48 +
49 + if (!part_str) {
50 + part_str = CONFIG_ENV_FAT_DEVICE_AND_PART;
51 + if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc")
52 + && part_str[0] == ':') {
53 + part_str = "0" CONFIG_ENV_FAT_DEVICE_AND_PART;
54 + part_str[0] += mmc_get_env_dev();
55 + }
56 + }
57 +
58 + return part_str;
59 +#else
60 + return CONFIG_ENV_FAT_DEVICE_AND_PART;
61 +#endif
62 +}
63 +#endif
64 +
65 #ifdef CMD_SAVEENV
66 static int env_fat_save(void)
67 {
68 @@ -46,7 +73,7 @@ static int env_fat_save(void)
69 return err;
70
71 part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
72 - CONFIG_ENV_FAT_DEVICE_AND_PART,
73 + env_fat_device_and_part(),
74 &dev_desc, &info, 1);
75 if (part < 0)
76 return 1;
77 @@ -93,7 +120,7 @@ static int env_fat_load(void)
78 #endif
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 goto err_env_relocate;
86 --
87 2.26.2
88