Add routines to enable U-Boot SPL to be able to proceed with the boot from
MMC partitions.

Reviewed-by: Balaji Selvanathan <[email protected]>
Reviewed-by: Simon Glass <[email protected]>
Signed-off-by: Varadarajan Narayanan <[email protected]>
---
 arch/arm/mach-snapdragon/board_spl.c | 107 +++++++++++++++++++++++++++++++++++
 1 file changed, 107 insertions(+)

diff --git a/arch/arm/mach-snapdragon/board_spl.c 
b/arch/arm/mach-snapdragon/board_spl.c
index 69a32e5d8cf..c5e86458616 100644
--- a/arch/arm/mach-snapdragon/board_spl.c
+++ b/arch/arm/mach-snapdragon/board_spl.c
@@ -131,3 +131,110 @@ static int qcom_spl_populate_smem(void *ctx)
        return -ENOENT;
 }
 #endif /* IS_ENABLED(CONFIG_SPL_SMEM) */
+
+#if CONFIG_IS_ENABLED(MMC)
+
+#define QCOM_SPL_FIT_IMG_PARTITION     "0:BOOTLDR"
+
+/**
+ * spl_find_partition_info() - Find partition information by name
+ * @uclass_id: Device class ID (UCLASS_MMC)
+ * @device_num: Device number within the class
+ * @part_name: Name of the partition to find
+ * @info: Pointer to store partition information
+ *
+ * This function provides partition lookup logic for MMC.
+ * Return: Partition number on success, negative error code on failure
+ */
+static int spl_find_partition_info(enum uclass_id uclass_id, int device_num,
+                                  const char *part_name,
+                                  struct disk_partition *info)
+{
+       int ret;
+       struct blk_desc *desc;
+
+       if (!part_name || !info) {
+               printf("Invalid parameters for partition lookup\n");
+               return -EINVAL;
+       }
+
+       /*
+        * Get block device descriptor
+        */
+       desc = blk_get_devnum_by_uclass_id(uclass_id, device_num);
+       if (!desc) {
+               printf("Block device not found for class %d, device %d\n",
+                      uclass_id, device_num);
+               return -ENODEV;
+       }
+
+       /*
+        * Initialize partition table if needed
+        */
+       if (desc->part_type == PART_TYPE_UNKNOWN) {
+               printf("Initializing partition table\n");
+               /*
+                * Prefer EFI/GPT
+                */
+               desc->part_type = PART_TYPE_EFI;
+       }
+
+       /*
+        * Find partition by name
+        */
+       ret = part_get_info_by_name(desc, part_name, info);
+       if (ret < 0) {
+               printf("Partition '%s' not found\n", part_name);
+               return -ENOENT;
+       }
+
+       printf("Found partition '%s' at partition number %d\n", part_name, ret);
+       return ret;
+}
+
+/**
+ * spl_mmc_boot_mode() - Determine the boot mode for MMC
+ * @mmc:       Pointer to the MMC device
+ * @boot_device:       Boot device ID
+ *
+ * Return: MMCSD_MODE_RAW to use raw partition access
+ */
+u32 spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device)
+{
+       return MMCSD_MODE_RAW;
+}
+
+/**
+ * spl_mmc_boot_partition() - Determine which partition to boot from
+ * @boot_device:       Boot device ID
+ *
+ * Return: Partition number to boot from, or default partition on error
+ */
+int spl_mmc_boot_partition(const u32 boot_device)
+{
+       int ret;
+       struct disk_partition info;
+
+       ret = spl_find_partition_info(UCLASS_MMC, 0, 
QCOM_SPL_FIT_IMG_PARTITION, &info);
+#if IS_ENABLED(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION)
+       if (ret < 0) {
+               printf("Using default MMC partition %d\n",
+                      CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION);
+               return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION;
+       }
+#endif
+       return ret;
+}
+
+/**
+ * spl_mmc_get_uboot_raw_sector() - Find the raw sector offset
+ * @mmc:       Pointer to the MMC device
+ * @raw_sect:  Sector
+ *
+ * Return: 0 if the image is at the starting of the partition without any 
offset.
+ */
+unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc, ulong raw_sect)
+{
+       return 0;
+}
+#endif /* CONFIG_IS_ENABLED(MMC) */

-- 
2.34.1

Reply via email to