DECLARE_GLOBAL_DATA_PTR;
+static int mmc_load_legacy(struct mmc *mmc, ulong sector,
+ struct image_header *header)
+{
+ u32 image_size_sectors;
+ unsigned long count;
+
+ spl_parse_image_header(header);
+ /* convert size to sectors - round up */
+ image_size_sectors = (spl_image.size + mmc->read_bl_len - 1) /
+ mmc->read_bl_len;
+
+ /* Read the header too to avoid extra memcpy */
+ count = mmc->block_dev.block_read(&mmc->block_dev, sector,
+ image_size_sectors,
+ (void *)(ulong)spl_image.load_addr);
+ debug("read %x sectors to %x\n", image_size_sectors,
+ spl_image.load_addr);
+ if (count != image_size_sectors)
+ return -EIO;
+
+ return 0;
+}
+
+#ifdef CONFIG_SPL_LOAD_FIT
+static ulong h_spl_load_read(struct spl_load_info *load, ulong sector,
+ ulong count, void *buf)
+{
+ struct mmc *mmc = load->dev;
+
+ return mmc->block_dev.block_read(&mmc->block_dev, sector, count, buf);
+}
+#endif
+
static int mmc_load_image_raw_sector(struct mmc *mmc, unsigned long sector)
{
unsigned long count;
- u32 image_size_sectors;
struct image_header *header;
+ int ret = 0;
header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
sizeof(struct image_header));
/* read image header to find the image size & load address */
- count = mmc->block_dev.block_read(0, sector, 1, header);
- debug("read sector %lx, count=%lu\n", sector, count);
- if (count == 0)
+ count = mmc->block_dev.block_read(&mmc->block_dev, sector, 1, header);
+ debug("hdr read sector %lx, count=%lu\n", sector, count);
+ if (count == 0) {
+ ret = -EIO;
goto end;
+ }
- if (image_get_magic(header) != IH_MAGIC) {
+ switch (image_get_magic(header)) {
+ case IH_MAGIC:
+ ret = mmc_load_legacy(mmc, sector, header);
+ break;
+#ifdef CONFIG_SPL_LOAD_FIT
+ case FDT_MAGIC: {
+ struct spl_load_info load;
+
+ debug("Found FIT\n");
+ load.dev = mmc;
+ load.priv = NULL;
+ load.bl_len = mmc->read_bl_len;
+ load.read = h_spl_load_read;
+ ret = spl_load_simple_fit(&load, sector, header);
+ break;
+ }
+#endif
+ default:
puts("bad magic\n");
return -1;
}
- spl_parse_image_header(header);
-
- /* convert size to sectors - round up */
- image_size_sectors = (spl_image.size + mmc->read_bl_len - 1) /
- mmc->read_bl_len;
-
- /* Read the header too to avoid extra memcpy */
- count = mmc->block_dev.block_read(0, sector, image_size_sectors,
- (void *)(ulong)spl_image.load_addr);
- debug("read %x sectors to %x\n", image_size_sectors,
- spl_image.load_addr);
-
end:
- if (count == 0) {
+ if (ret) {
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
puts("spl: mmc block read error\n");
#endif
return 0;
}
-#ifdef CONFIG_DM_MMC
-static int spl_mmc_find_device(struct mmc **mmc)
+int spl_mmc_get_device_index(u32 boot_device)
{
- struct udevice *dev;
- int err;
-
- err = mmc_initialize(NULL);
- if (err) {
-#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
- printf("spl: could not initialize mmc. error: %d\n", err);
-#endif
- return err;
+ switch (boot_device) {
+ case BOOT_DEVICE_MMC1:
+ return 0;
+ case BOOT_DEVICE_MMC2:
+ case BOOT_DEVICE_MMC2_2:
+ return 1;
}
- err = uclass_get_device(UCLASS_MMC, 0, &dev);
- if (err) {
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
- printf("spl: could not find mmc device. error: %d\n", err);
+ printf("spl: unsupported mmc boot device.\n");
#endif
- return err;
- }
- *mmc = NULL;
- *mmc = mmc_get_mmc_dev(dev);
- return *mmc != NULL ? 0 : -ENODEV;
+ return -ENODEV;
}
-#else
-static int spl_mmc_find_device(struct mmc **mmc)
+
+static int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device)
{
- int err;
+#ifdef CONFIG_DM_MMC
+ struct udevice *dev;
+#endif
+ int err, mmc_dev;
- err = mmc_initialize(gd->bd);
+ mmc_dev = spl_mmc_get_device_index(boot_device);
+ if (mmc_dev < 0)
+ return mmc_dev;
+
+ err = mmc_initialize(NULL);
if (err) {
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
printf("spl: could not initialize mmc. error: %d\n", err);
return err;
}
- /* We register only one device. So, the dev id is always 0 */
- *mmc = find_mmc_device(0);
- if (!*mmc) {
+#ifdef CONFIG_DM_MMC
+ err = uclass_get_device(UCLASS_MMC, mmc_dev, &dev);
+ if (!err)
+ *mmcp = mmc_get_mmc_dev(dev);
+#else
+ *mmcp = find_mmc_device(mmc_dev);
+ err = *mmcp ? 0 : -ENODEV;
+#endif
+ if (err) {
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
- puts("spl: mmc device not found\n");
+ printf("spl: could not find mmc device. error: %d\n", err);
#endif
- return -ENODEV;
+ return err;
}
return 0;
}
-#endif
#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION
static int mmc_load_image_raw_partition(struct mmc *mmc, int partition)
disk_partition_t info;
int err;
- err = get_partition_info(&mmc->block_dev, partition, &info);
+ err = part_get_info(&mmc->block_dev, partition, &info);
if (err) {
#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
puts("spl: partition error\n");
{
unsigned long count;
- count = mmc->block_dev.block_read(0,
+ count = mmc->block_dev.block_read(&mmc->block_dev,
CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR,
CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS,
(void *) CONFIG_SYS_SPL_ARGS_ADDR);
}
#endif
-int spl_mmc_load_image(void)
+int spl_mmc_load_image(u32 boot_device)
{
- struct mmc *mmc;
+ struct mmc *mmc = NULL;
u32 boot_mode;
int err = 0;
__maybe_unused int part;
- err = spl_mmc_find_device(&mmc);
+ err = spl_mmc_find_device(&mmc, boot_device);
if (err)
return err;
if (!err)
return err;
#endif
- break;
+ /* If RAW mode fails, try FS mode. */
case MMCSD_MODE_FS:
debug("spl: mmc boot mode: fs\n");