[U-Boot] [PATCH] SPL: add support to boot from a partition type

Dalon Westergreen
2017-01-28T23:20:09Z

From: Dalon Westergreen <dalon.westergreen@intel.com>

the socfpga bootrom supports mmc booting from either a raw image
starting at 0x0, or from a partition of type 0xa2. This patch
adds support for locating the boot image in the first type 0xa2
partition found.

Signed-off-by: Dalon Westergreen <dalon.westergreen@intel.com>
---
common/spl/Kconfig | 17 +++++++++++++++++
common/spl/spl_mmc.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
disk/part_dos.c | 1 +
include/part.h | 1 +
4 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index b1aa148..a0430ec 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -97,6 +97,23 @@ config SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR
Address on the MMC to load U-Boot from, when the MMC is being used
in raw mode. Units: MMC sectors (1 sector = 512 bytes).

+config SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION_TYPE
+ bool "MMC raw mode: by partition type"
+ depends on SPL
+ default y if ARCH_SOCFPGA
+ help
+ Use partition type for specifying U-Boot partition on MMC/SD in
+ raw mode. U-Boot will be loaded from the first partition of this
+ type to be found.
+
+config SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_TYPE
+ hex "Partition Type on the MMC to load U-Boot from"
+ depends on SPL && SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION_TYPE
+ default 0xa2 if ARCH_SOCFPGA
+ help
+ Partition Type on the MMC to load U-Boot from, when the MMC is being
+ used in raw mode.
+
config TPL
bool
depends on SPL && SUPPORT_TPL
diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index 0cd355c..9dd3172 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -181,6 +181,42 @@ static int mmc_load_image_raw_partition(struct spl_image_info *spl_image,
}
#endif

+#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_TYPE
+#define MAX_SEARCH_PARTITIONS 4
+static int mmc_load_image_raw_partition_type(struct spl_image_info *spl_image,
+ struct mmc *mmc, int partition_type)
+{
+ disk_partition_t info;
+ int ret;
+ int p;
+
+ /*
+ * Find the first partition of type partition_id
+ */
+ for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
+ ret = part_get_info(mmc_get_blk_desc(mmc), p, &info);
+ if(ret)
+ continue;
+ if(info.sys_ind == partition_type) {
+ break;
+ }
+ }
+#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
+ return mmc_load_image_raw_sector(spl_image, mmc,
+ info.start + CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR);
+#else
+ return mmc_load_image_raw_sector(spl_image, mmc, info.start);
+#endif
+}
+#else
+#define CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_TYPE -1
+static int mmc_load_image_raw_partition_type(struct spl_image_info *spl_image,
+ struct mmc *mmc, int partition_type)
+{
+ return -ENOSYS;
+}
+#endif
+
#ifdef CONFIG_SPL_OS_BOOT
static int mmc_load_image_raw_os(struct spl_image_info *spl_image,
struct mmc *mmc)
@@ -331,12 +367,19 @@ int spl_mmc_load_image(struct spl_image_info *spl_image,
CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION);
if (!err)
return err;
+
+#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION_TYPE
+ err = mmc_load_image_raw_partition_type(spl_image, mmc,
+ CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_TYPE);
+ if (!err)
+ return err;
+#endif
#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
err = mmc_load_image_raw_sector(spl_image, mmc,
CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR);
if (!err)
return err;
-#endif
+#endif
/* If RAW mode fails, try FS mode. */
case MMCSD_MODE_FS:
debug("spl: mmc boot mode: fs\n");
diff --git a/disk/part_dos.c b/disk/part_dos.c
index ed78334..f485f11 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -217,6 +217,7 @@ static int part_get_info_extended(struct blk_desc *dev_desc,
#ifdef CONFIG_PARTITION_UUIDS
sprintf(info->uuid, "%08x-%02x", disksig, part_num);
#endif
+ info->sys_ind = pt->sys_ind;
return 0;
}

diff --git a/include/part.h b/include/part.h
index 0979005..a58b687 100644
--- a/include/part.h
+++ b/include/part.h
@@ -59,6 +59,7 @@ typedef struct disk_partition {
#ifdef CONFIG_PARTITION_TYPE_GUID
char type_guid[37]; /* type GUID as string, if exists */
#endif
+ uchar sys_ind; /* partition type */
} disk_partition_t;

/* Misc _get_dev functions */
--
2.7.4