007-env-fat-use-bootdevice.patch 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. From 6731bef6966ea2b26cdcfe0109ff5a950003fd03 Mon Sep 17 00:00:00 2001
  2. From: David Woodhouse <[email protected]>
  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. I don't want to have to specify the device; only the partition.
  7. This allows me to use the same image on internal eMMC or SD card for
  8. Banana Pi R2, and it finds its own environment either way.
  9. Signed-off-by: David Woodhouse <[email protected]>
  10. [trini: Add #if/#else/#endif logic around CONFIG_SYS_MMC_ENV_DEV usage,
  11. whitespace changes]
  12. Signed-off-by: Tom Rini <[email protected]>
  13. ---
  14. env/Kconfig | 4 ++++
  15. env/fat.c | 32 ++++++++++++++++++++++++++++++--
  16. 2 files changed, 34 insertions(+), 2 deletions(-)
  17. diff --git a/env/Kconfig b/env/Kconfig
  18. index 38e7fadbb9..5784136674 100644
  19. --- a/env/Kconfig
  20. +++ b/env/Kconfig
  21. @@ -434,6 +434,10 @@ config ENV_FAT_DEVICE_AND_PART
  22. If none, first valid partition in device D. If no
  23. partition table then means device D.
  24. + If ENV_FAT_INTERFACE is set to "mmc" then device 'D' can be omitted,
  25. + leaving the string starting with a colon, and the boot device will
  26. + be used.
  27. +
  28. config ENV_FAT_FILE
  29. string "Name of the FAT file to use for the environment"
  30. depends on ENV_IS_IN_FAT
  31. diff --git a/env/fat.c b/env/fat.c
  32. index 35a1955e63..63aced9317 100644
  33. --- a/env/fat.c
  34. +++ b/env/fat.c
  35. @@ -29,6 +29,34 @@
  36. # define LOADENV
  37. #endif
  38. +__weak int mmc_get_env_dev(void)
  39. +{
  40. +#ifdef CONFIG_SYS_MMC_ENV_DEV
  41. + return CONFIG_SYS_MMC_ENV_DEV;
  42. +#else
  43. + return 0;
  44. +#endif
  45. +}
  46. +
  47. +static char *env_fat_device_and_part(void)
  48. +{
  49. +#ifdef CONFIG_MMC
  50. + static char *part_str;
  51. +
  52. + if (!part_str) {
  53. + part_str = CONFIG_ENV_FAT_DEVICE_AND_PART;
  54. + if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc") && part_str[0] == ':') {
  55. + part_str = "0" CONFIG_ENV_FAT_DEVICE_AND_PART;
  56. + part_str[0] += mmc_get_env_dev();
  57. + }
  58. + }
  59. +
  60. + return part_str;
  61. +#else
  62. + return CONFIG_ENV_FAT_DEVICE_AND_PART;
  63. +#endif
  64. +}
  65. +
  66. static int env_fat_save(void)
  67. {
  68. env_t __aligned(ARCH_DMA_MINALIGN) env_new;
  69. @@ -43,7 +71,7 @@ static int env_fat_save(void)
  70. return err;
  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. @@ -89,7 +117,7 @@ static int env_fat_load(void)
  78. #endif
  79. part = blk_get_device_part_str(CONFIG_ENV_FAT_INTERFACE,
  80. - CONFIG_ENV_FAT_DEVICE_AND_PART,
  81. + env_fat_device_and_part(),
  82. &dev_desc, &info, 1);
  83. if (part < 0)
  84. goto err_env_relocate;
  85. --
  86. 2.26.2