ramips: fix kernel oops in `mt7621_nfc_write_page_hwecc`
[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,34 @@
41 # define LOADENV
42 #endif
43
44 +__weak int mmc_get_env_dev(void)
45 +{
46 +#ifdef CONFIG_SYS_MMC_ENV_DEV
47 + return CONFIG_SYS_MMC_ENV_DEV;
48 +#else
49 + return 0;
50 +#endif
51 +}
52 +
53 +static char *env_fat_device_and_part(void)
54 +{
55 +#ifdef CONFIG_MMC
56 + static char *part_str;
57 +
58 + if (!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();
63 + }
64 + }
65 +
66 + return part_str;
67 +#else
68 + return CONFIG_ENV_FAT_DEVICE_AND_PART;
69 +#endif
70 +}
71 +
72 static int env_fat_save(void)
73 {
74 env_t __aligned(ARCH_DMA_MINALIGN) env_new;
75 @@ -43,7 +71,7 @@ static int env_fat_save(void)
76 return err;
77
78 part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
79 - CONFIG_ENV_FAT_DEVICE_AND_PART,
80 + env_fat_device_and_part(),
81 &dev_desc, &info, 1);
82 if (part < 0)
83 return 1;
84 @@ -89,7 +117,7 @@ static int env_fat_load(void)
85 #endif
86
87 part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
88 - CONFIG_ENV_FAT_DEVICE_AND_PART,
89 + env_fat_device_and_part(),
90 &dev_desc, &info, 1);
91 if (part < 0)
92 goto err_env_relocate;
93 --
94 2.26.2
95