[U-Boot] [PATCH v3 29/58] sunxi: Get fat device wrt boot device, 'auto' partition
Jagan Teki
jagan at amarulasolutions.com
Sun Aug 19 13:56:46 UTC 2018
Setting fat device, partition using CONFIG_ENV_FAT_DEVICE_AND_PART
via Kconfig option is difficult to maintain since Allwinner
support more than one mmc controllers with SD and eMMC.
So, add dynamic function to get the device based on the
boot device source with 'auto' partition.
Signed-off-by: Jagan Teki <jagan at amarulasolutions.com>
---
arch/arm/mach-sunxi/board.c | 50 +++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/arch/arm/mach-sunxi/board.c b/arch/arm/mach-sunxi/board.c
index d22a84ea6b..cf174bd0a3 100644
--- a/arch/arm/mach-sunxi/board.c
+++ b/arch/arm/mach-sunxi/board.c
@@ -10,6 +10,7 @@
*/
#include <common.h>
+#include <fat.h>
#include <mmc.h>
#include <i2c.h>
#include <serial.h>
@@ -253,6 +254,55 @@ uint32_t sunxi_get_boot_device(void)
return -1; /* Never reached */
}
+#if CONFIG_IS_ENABLED(ENV_IS_IN_FAT)
+static int find_first_sd_device(void)
+{
+ struct mmc *mmc;
+ int i;
+
+ for (i = 0; (mmc = find_mmc_device(i)); i++) {
+ if (!mmc_init(mmc) && IS_SD(mmc))
+ return i;
+ }
+
+ return -ENODEV;
+}
+
+static int find_first_mmc_device(void)
+{
+ struct mmc *mmc;
+ int i;
+
+ for (i = 0; (mmc = find_mmc_device(i)); i++) {
+ if (!mmc_init(mmc) && IS_MMC(mmc))
+ return i;
+ }
+
+ return -ENODEV;
+}
+
+char *get_env_fat_dev_part(void)
+{
+ int devno, boot_source;
+ static char dev_part[10];
+
+ boot_source = readb(SPL_ADDR + 0x28);
+ switch (boot_source) {
+ case SUNXI_BOOTED_FROM_MMC0:
+ devno = find_first_sd_device();
+ break;
+ case SUNXI_BOOTED_FROM_MMC2:
+ devno = find_first_mmc_device();
+ break;
+ default:
+ return CONFIG_ENV_FAT_DEVICE_AND_PART;
+ }
+
+ snprintf(dev_part, sizeof(dev_part), "%d:auto", devno);
+ return dev_part;
+}
+#endif
+
#ifdef CONFIG_SPL_BUILD
u32 spl_boot_device(void)
{
--
2.18.0.321.gffc6fa0e3
More information about the U-Boot
mailing list