Merge git://git.denx.de/u-boot-video
[oweals/u-boot.git] / common / spl / spl_mmc.c
index 85e3de8f23053a7d93ca36f3514a3f77a162356d..d95f94ca15e0b4b07c4a894247044391be816c9d 100644 (file)
@@ -36,7 +36,7 @@ static int mmc_load_legacy(struct spl_image_info *spl_image, struct mmc *mmc,
        /* Read the header too to avoid extra memcpy */
        count = blk_dread(mmc_get_blk_desc(mmc), sector, image_size_sectors,
                          (void *)(ulong)spl_image->load_addr);
-       debug("read %x sectors to %x\n", image_size_sectors,
+       debug("read %x sectors to %lx\n", image_size_sectors,
              spl_image->load_addr);
        if (count != image_size_sectors)
                return -EIO;
@@ -96,7 +96,7 @@ end:
        return 0;
 }
 
-int spl_mmc_get_device_index(u32 boot_device)
+static int spl_mmc_get_device_index(u32 boot_device)
 {
        switch (boot_device) {
        case BOOT_DEVICE_MMC1:
@@ -115,7 +115,7 @@ int spl_mmc_get_device_index(u32 boot_device)
 
 static int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device)
 {
-#ifdef CONFIG_DM_MMC
+#if CONFIG_IS_ENABLED(DM_MMC)
        struct udevice *dev;
 #endif
        int err, mmc_dev;
@@ -132,7 +132,7 @@ static int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device)
                return err;
        }
 
-#ifdef CONFIG_DM_MMC
+#if CONFIG_IS_ENABLED(DM_MMC)
        err = uclass_get_device(UCLASS_MMC, mmc_dev, &dev);
        if (!err)
                *mmcp = mmc_get_mmc_dev(dev);
@@ -150,13 +150,28 @@ static int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device)
        return 0;
 }
 
-#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION
+#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
 static int mmc_load_image_raw_partition(struct spl_image_info *spl_image,
                                        struct mmc *mmc, int partition)
 {
        disk_partition_t info;
        int err;
 
+#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION_TYPE
+       int type_part;
+       /* Only support MBR so DOS_ENTRY_NUMBERS */
+       for (type_part = 1; type_part <= DOS_ENTRY_NUMBERS; type_part++) {
+               err = part_get_info(mmc_get_blk_desc(mmc), type_part, &info);
+               if (err)
+                       continue;
+               if (info.sys_ind == 
+                       CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_TYPE) {
+                       partition = type_part;
+                       break;
+               }
+       }
+#endif
+
        err = part_get_info(mmc_get_blk_desc(mmc), partition, &info);
        if (err) {
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
@@ -172,13 +187,6 @@ static int mmc_load_image_raw_partition(struct spl_image_info *spl_image,
        return mmc_load_image_raw_sector(spl_image, mmc, info.start);
 #endif
 }
-#else
-#define CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION -1
-static int mmc_load_image_raw_partition(struct spl_image_info *spl_image,
-                                       struct mmc *mmc, int partition)
-{
-       return -ENOSYS;
-}
 #endif
 
 #ifdef CONFIG_SPL_OS_BOOT
@@ -326,11 +334,12 @@ int spl_mmc_load_image(struct spl_image_info *spl_image,
                        if (!err)
                                return err;
                }
-
+#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
                err = mmc_load_image_raw_partition(spl_image, mmc,
                        CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION);
                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);