3 * Texas Instruments, <www.ti.com>
5 * Aneesh V <aneesh@ti.com>
7 * SPDX-License-Identifier: GPL-2.0+
11 #include <asm/u-boot.h>
16 DECLARE_GLOBAL_DATA_PTR
;
18 static int mmc_load_image_raw(struct mmc
*mmc
, unsigned long sector
)
21 u32 image_size_sectors
;
22 struct image_header
*header
;
24 header
= (struct image_header
*)(CONFIG_SYS_TEXT_BASE
-
25 sizeof(struct image_header
));
27 /* read image header to find the image size & load address */
28 err
= mmc
->block_dev
.block_read(0, sector
, 1, header
);
32 if (image_get_magic(header
) != IH_MAGIC
)
35 spl_parse_image_header(header
);
37 /* convert size to sectors - round up */
38 image_size_sectors
= (spl_image
.size
+ mmc
->read_bl_len
- 1) /
41 /* Read the header too to avoid extra memcpy */
42 err
= mmc
->block_dev
.block_read(0, sector
, image_size_sectors
,
43 (void *)spl_image
.load_addr
);
46 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
48 printf("spl: mmc blk read err - %lu\n", err
);
54 #ifdef CONFIG_SPL_OS_BOOT
55 static int mmc_load_image_raw_os(struct mmc
*mmc
)
57 if (!mmc
->block_dev
.block_read(0,
58 CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR
,
59 CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS
,
60 (void *)CONFIG_SYS_SPL_ARGS_ADDR
)) {
61 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
62 printf("mmc args blk read error\n");
67 return mmc_load_image_raw(mmc
, CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR
);
71 void spl_mmc_load_image(void)
77 mmc_initialize(gd
->bd
);
78 /* We register only one device. So, the dev id is always 0 */
79 mmc
= find_mmc_device(0);
81 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
82 puts("spl: mmc device not found!!\n");
89 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
90 printf("spl: mmc init failed: err - %d\n", err
);
95 boot_mode
= spl_boot_mode();
96 if (boot_mode
== MMCSD_MODE_RAW
) {
97 debug("boot mode - RAW\n");
98 #ifdef CONFIG_SPL_OS_BOOT
99 if (spl_start_uboot() || mmc_load_image_raw_os(mmc
))
101 err
= mmc_load_image_raw(mmc
,
102 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR
);
103 #ifdef CONFIG_SPL_FAT_SUPPORT
104 } else if (boot_mode
== MMCSD_MODE_FS
) {
105 debug("boot mode - FAT\n");
106 #ifdef CONFIG_SPL_OS_BOOT
107 if (spl_start_uboot() || spl_load_image_fat_os(&mmc
->block_dev
,
108 CONFIG_SYS_MMC_SD_FS_BOOT_PARTITION
))
110 err
= spl_load_image_fat(&mmc
->block_dev
,
111 CONFIG_SYS_MMC_SD_FS_BOOT_PARTITION
,
112 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
);
114 #ifdef CONFIG_SUPPORT_EMMC_BOOT
115 } else if (boot_mode
== MMCSD_MODE_EMMCBOOT
) {
117 * We need to check what the partition is configured to.
118 * 1 and 2 match up to boot0 / boot1 and 7 is user data
119 * which is the first physical partition (0).
121 int part
= (mmc
->part_config
>> 3) & PART_ACCESS_MASK
;
126 if (mmc_switch_part(0, part
)) {
127 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
128 puts("MMC partition switch failed\n");
132 #ifdef CONFIG_SPL_OS_BOOT
133 if (spl_start_uboot() || mmc_load_image_raw_os(mmc
))
135 err
= mmc_load_image_raw(mmc
,
136 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR
);
139 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
140 puts("spl: wrong MMC boot mode\n");