* [PATCH] env/fat.c: allow loading from a FAT partition on the MMC boot device
@ 2020-06-19 22:07 David Woodhouse
2020-07-23 23:18 ` David Woodhouse
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: David Woodhouse @ 2020-06-19 22:07 UTC (permalink / raw)
To: u-boot
I don't want to have to specify the device; only the partition.
This allows me to use the same image on internal eMMC or SD card for
Banana Pi R2, and it finds its own environment either way.
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
---
env/Kconfig | 4 ++++
env/fat.c | 29 +++++++++++++++++++++++++++--
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/env/Kconfig b/env/Kconfig
index 38e7fadbb9..5784136674 100644
--- a/env/Kconfig
+++ b/env/Kconfig
@@ -434,6 +434,10 @@ config ENV_FAT_DEVICE_AND_PART
If none, first valid partition in device D. If no
partition table then means device D.
+ If ENV_FAT_INTERFACE is set to "mmc" then device 'D' can be omitted,
+ leaving the string starting with a colon, and the boot device will
+ be used.
+
config ENV_FAT_FILE
string "Name of the FAT file to use for the environment"
depends on ENV_IS_IN_FAT
diff --git a/env/fat.c b/env/fat.c
index 35a1955e63..37c15d16cd 100644
--- a/env/fat.c
+++ b/env/fat.c
@@ -29,6 +29,31 @@
# define LOADENV
#endif
+__weak int mmc_get_env_dev(void)
+{
+ return CONFIG_SYS_MMC_ENV_DEV;
+}
+
+static char *env_fat_device_and_part(void)
+{
+#ifdef CONFIG_MMC
+ static char *part_str;
+
+ if (!part_str) {
+ part_str = CONFIG_ENV_FAT_DEVICE_AND_PART;
+ if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc")
+ && part_str[0] == ':') {
+ part_str = "0" CONFIG_ENV_FAT_DEVICE_AND_PART;
+ part_str[0] += mmc_get_env_dev();
+ }
+ }
+
+ return part_str;
+#else
+ return CONFIG_ENV_FAT_DEVICE_AND_PART;
+#endif
+}
+
static int env_fat_save(void)
{
env_t __aligned(ARCH_DMA_MINALIGN) env_new;
@@ -43,7 +68,7 @@ static int env_fat_save(void)
return err;
part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
- CONFIG_ENV_FAT_DEVICE_AND_PART,
+ env_fat_device_and_part(),
&dev_desc, &info, 1);
if (part < 0)
return 1;
@@ -89,7 +114,7 @@ static int env_fat_load(void)
#endif
part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
- CONFIG_ENV_FAT_DEVICE_AND_PART,
+ env_fat_device_and_part(),
&dev_desc, &info, 1);
if (part < 0)
goto err_env_relocate;
--
2.26.2
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5174 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200619/081c0e60/attachment.bin>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] env/fat.c: allow loading from a FAT partition on the MMC boot device
2020-06-19 22:07 [PATCH] env/fat.c: allow loading from a FAT partition on the MMC boot device David Woodhouse
@ 2020-07-23 23:18 ` David Woodhouse
2020-07-25 17:03 ` Tom Rini
2020-07-27 13:32 ` Tom Rini
2 siblings, 0 replies; 4+ messages in thread
From: David Woodhouse @ 2020-07-23 23:18 UTC (permalink / raw)
To: u-boot
On Fri, 2020-06-19 at 23:07 +0100, David Woodhouse wrote:
> I don't want to have to specify the device; only the partition.
>
> This allows me to use the same image on internal eMMC or SD card for
> Banana Pi R2, and it finds its own environment either way.
>
> Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Ping?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5174 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200724/ba1af829/attachment.bin>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] env/fat.c: allow loading from a FAT partition on the MMC boot device
2020-06-19 22:07 [PATCH] env/fat.c: allow loading from a FAT partition on the MMC boot device David Woodhouse
2020-07-23 23:18 ` David Woodhouse
@ 2020-07-25 17:03 ` Tom Rini
2020-07-27 13:32 ` Tom Rini
2 siblings, 0 replies; 4+ messages in thread
From: Tom Rini @ 2020-07-25 17:03 UTC (permalink / raw)
To: u-boot
On Fri, Jun 19, 2020 at 11:07:17PM +0100, David Woodhouse wrote:
> I don't want to have to specify the device; only the partition.
>
> This allows me to use the same image on internal eMMC or SD card for
> Banana Pi R2, and it finds its own environment either way.
>
> Signed-off-by: David Woodhouse <dwmw2@infradead.org>
> ---
> env/Kconfig | 4 ++++
> env/fat.c | 29 +++++++++++++++++++++++++++--
> 2 files changed, 31 insertions(+), 2 deletions(-)
>
> diff --git a/env/Kconfig b/env/Kconfig
> index 38e7fadbb9..5784136674 100644
> --- a/env/Kconfig
> +++ b/env/Kconfig
> @@ -434,6 +434,10 @@ config ENV_FAT_DEVICE_AND_PART
> If none, first valid partition in device D. If no
> partition table then means device D.
>
> + If ENV_FAT_INTERFACE is set to "mmc" then device 'D' can be omitted,
> + leaving the string starting with a colon, and the boot device will
> + be used.
> +
> config ENV_FAT_FILE
> string "Name of the FAT file to use for the environment"
> depends on ENV_IS_IN_FAT
> diff --git a/env/fat.c b/env/fat.c
> index 35a1955e63..37c15d16cd 100644
> --- a/env/fat.c
> +++ b/env/fat.c
> @@ -29,6 +29,31 @@
> # define LOADENV
> #endif
>
> +__weak int mmc_get_env_dev(void)
> +{
> + return CONFIG_SYS_MMC_ENV_DEV;
> +}
> +
> +static char *env_fat_device_and_part(void)
> +{
> +#ifdef CONFIG_MMC
> + static char *part_str;
> +
> + if (!part_str) {
> + part_str = CONFIG_ENV_FAT_DEVICE_AND_PART;
> + if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc")
> + && part_str[0] == ':') {
> + part_str = "0" CONFIG_ENV_FAT_DEVICE_AND_PART;
> + part_str[0] += mmc_get_env_dev();
> + }
> + }
> +
> + return part_str;
> +#else
> + return CONFIG_ENV_FAT_DEVICE_AND_PART;
> +#endif
> +}
> +
> static int env_fat_save(void)
> {
> env_t __aligned(ARCH_DMA_MINALIGN) env_new;
> @@ -43,7 +68,7 @@ static int env_fat_save(void)
> return err;
>
> part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
> - CONFIG_ENV_FAT_DEVICE_AND_PART,
> + env_fat_device_and_part(),
> &dev_desc, &info, 1);
> if (part < 0)
> return 1;
> @@ -89,7 +114,7 @@ static int env_fat_load(void)
> #endif
>
> part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
> - CONFIG_ENV_FAT_DEVICE_AND_PART,
> + env_fat_device_and_part(),
> &dev_desc, &info, 1);
> if (part < 0)
> goto err_env_relocate;
So, the biggest problem here, which I found while testing, is that since
CONFIG_SYS_MMC_ENV_DEV isn't always defined, this blows up a few cases.
Migrating this to Kconfig needs to happen anyhow, so I started on that.
Doing so however isn't trivial as we have cases where we set the value
to 0 (along with SYS_MMC_ENV_PART), and setting it to 0 isn't the same
code paths as unset. I've sent out patches to deal with that now. For
the moment, I'm adding a #ifndef / #define 0 / #endif to this patch.
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200725/74be937a/attachment.sig>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] env/fat.c: allow loading from a FAT partition on the MMC boot device
2020-06-19 22:07 [PATCH] env/fat.c: allow loading from a FAT partition on the MMC boot device David Woodhouse
2020-07-23 23:18 ` David Woodhouse
2020-07-25 17:03 ` Tom Rini
@ 2020-07-27 13:32 ` Tom Rini
2 siblings, 0 replies; 4+ messages in thread
From: Tom Rini @ 2020-07-27 13:32 UTC (permalink / raw)
To: u-boot
On Fri, Jun 19, 2020 at 11:07:17PM +0100, David Woodhouse wrote:
> I don't want to have to specify the device; only the partition.
>
> This allows me to use the same image on internal eMMC or SD card for
> Banana Pi R2, and it finds its own environment either way.
>
> Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Applied to u-boot/master, thanks!
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200727/ce566650/attachment.sig>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-07-27 13:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-19 22:07 [PATCH] env/fat.c: allow loading from a FAT partition on the MMC boot device David Woodhouse
2020-07-23 23:18 ` David Woodhouse
2020-07-25 17:03 ` Tom Rini
2020-07-27 13:32 ` Tom Rini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox