blob: e780b82fd2bfa0bfc1dd95d797fe60886aaa32dd [file] [log] [blame]
Simon Schwarze21d2d82011-09-14 15:33:34 -04001/*
2 * (C) Copyright 2010
3 * Texas Instruments, <www.ti.com>
4 *
5 * Aneesh V <aneesh@ti.com>
6 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Simon Schwarze21d2d82011-09-14 15:33:34 -04008 */
9#include <common.h>
Simon Glassf22851a2015-06-23 15:38:51 -060010#include <dm.h>
Tom Rini28591df2012-08-13 12:03:19 -070011#include <spl.h>
Paul Kocialkowski0d139722015-04-27 10:20:22 +020012#include <linux/compiler.h>
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020013#include <errno.h>
Simon Schwarze21d2d82011-09-14 15:33:34 -040014#include <asm/u-boot.h>
Nikita Kiryanov022ddb82015-11-08 17:11:44 +020015#include <errno.h>
Simon Schwarze21d2d82011-09-14 15:33:34 -040016#include <mmc.h>
Tom Rini1530e8a2013-06-28 14:43:01 -040017#include <image.h>
Simon Schwarze21d2d82011-09-14 15:33:34 -040018
Simon Glassee306792016-09-24 18:20:13 -060019static int mmc_load_legacy(struct spl_image_info *spl_image, struct mmc *mmc,
20 ulong sector, struct image_header *header)
Simon Glassb52c7fc2016-02-22 22:55:58 -070021{
22 u32 image_size_sectors;
23 unsigned long count;
Marek Vasut02266e22016-04-29 00:44:54 +020024 int ret;
25
Simon Glassee306792016-09-24 18:20:13 -060026 ret = spl_parse_image_header(spl_image, header);
Marek Vasut02266e22016-04-29 00:44:54 +020027 if (ret)
28 return ret;
Simon Glassb52c7fc2016-02-22 22:55:58 -070029
Simon Glassb52c7fc2016-02-22 22:55:58 -070030 /* convert size to sectors - round up */
Simon Glassee306792016-09-24 18:20:13 -060031 image_size_sectors = (spl_image->size + mmc->read_bl_len - 1) /
Simon Glassb52c7fc2016-02-22 22:55:58 -070032 mmc->read_bl_len;
33
34 /* Read the header too to avoid extra memcpy */
Simon Glass670d3042016-05-14 14:03:06 -060035 count = blk_dread(mmc_get_blk_desc(mmc), sector, image_size_sectors,
Simon Glassee306792016-09-24 18:20:13 -060036 (void *)(ulong)spl_image->load_addr);
Andre Przywara6c526072017-01-02 11:48:31 +000037 debug("read %x sectors to %lx\n", image_size_sectors,
Simon Glassee306792016-09-24 18:20:13 -060038 spl_image->load_addr);
Simon Glassb52c7fc2016-02-22 22:55:58 -070039 if (count != image_size_sectors)
40 return -EIO;
41
42 return 0;
43}
44
Simon Glassb52c7fc2016-02-22 22:55:58 -070045static ulong h_spl_load_read(struct spl_load_info *load, ulong sector,
46 ulong count, void *buf)
47{
48 struct mmc *mmc = load->dev;
49
Simon Glass670d3042016-05-14 14:03:06 -060050 return blk_dread(mmc_get_blk_desc(mmc), sector, count, buf);
Simon Glassb52c7fc2016-02-22 22:55:58 -070051}
Simon Glassb52c7fc2016-02-22 22:55:58 -070052
Seung-Woo Kimc0a4e2d2017-09-19 13:29:45 +090053static __maybe_unused
54int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
55 struct mmc *mmc, unsigned long sector)
Simon Schwarze21d2d82011-09-14 15:33:34 -040056{
Paul Kocialkowski2d69f252015-05-22 12:45:35 +020057 unsigned long count;
Peter Korsgaardf2471292013-03-21 04:55:17 +000058 struct image_header *header;
Simon Glassb52c7fc2016-02-22 22:55:58 -070059 int ret = 0;
Simon Schwarze21d2d82011-09-14 15:33:34 -040060
61 header = (struct image_header *)(CONFIG_SYS_TEXT_BASE -
Paul Kocialkowski0d139722015-04-27 10:20:22 +020062 sizeof(struct image_header));
Simon Schwarze21d2d82011-09-14 15:33:34 -040063
64 /* read image header to find the image size & load address */
Simon Glass670d3042016-05-14 14:03:06 -060065 count = blk_dread(mmc_get_blk_desc(mmc), sector, 1, header);
Simon Glassb52c7fc2016-02-22 22:55:58 -070066 debug("hdr read sector %lx, count=%lu\n", sector, count);
67 if (count == 0) {
68 ret = -EIO;
Simon Schwarze21d2d82011-09-14 15:33:34 -040069 goto end;
Simon Glassb52c7fc2016-02-22 22:55:58 -070070 }
Simon Schwarze21d2d82011-09-14 15:33:34 -040071
Masahiro Yamada802f1c32016-03-16 12:10:00 +090072 if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
73 image_get_magic(header) == FDT_MAGIC) {
Simon Glassb52c7fc2016-02-22 22:55:58 -070074 struct spl_load_info load;
75
76 debug("Found FIT\n");
77 load.dev = mmc;
78 load.priv = NULL;
Lokesh Vutlaf62cef12016-05-24 10:34:38 +053079 load.filename = NULL;
Simon Glassb52c7fc2016-02-22 22:55:58 -070080 load.bl_len = mmc->read_bl_len;
81 load.read = h_spl_load_read;
Simon Glass43a734f2016-09-24 18:20:16 -060082 ret = spl_load_simple_fit(spl_image, &load, sector, header);
Masahiro Yamada802f1c32016-03-16 12:10:00 +090083 } else {
Simon Glassee306792016-09-24 18:20:13 -060084 ret = mmc_load_legacy(spl_image, mmc, sector, header);
Simon Glass5614db82015-06-23 15:38:47 -060085 }
Tom Rini1530e8a2013-06-28 14:43:01 -040086
Simon Schwarze21d2d82011-09-14 15:33:34 -040087end:
Simon Glassb52c7fc2016-02-22 22:55:58 -070088 if (ret) {
Paul Burtona8015fd2013-09-04 16:12:24 +010089#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
Fabio Estevam37342ab2016-04-20 23:12:04 -030090 puts("mmc_load_image_raw_sector: mmc block read error\n");
Paul Burtona8015fd2013-09-04 16:12:24 +010091#endif
Paul Kocialkowski2d69f252015-05-22 12:45:35 +020092 return -1;
Paul Kocialkowski01c723f2015-06-03 18:48:51 +020093 }
Paul Kocialkowski2d69f252015-05-22 12:45:35 +020094
95 return 0;
Simon Schwarze21d2d82011-09-14 15:33:34 -040096}
97
Masahiro Yamada2a4a20c2017-06-22 16:52:36 +090098static int spl_mmc_get_device_index(u32 boot_device)
Nikita Kiryanove63b2dd2015-11-08 17:11:54 +020099{
100 switch (boot_device) {
101 case BOOT_DEVICE_MMC1:
102 return 0;
103 case BOOT_DEVICE_MMC2:
104 case BOOT_DEVICE_MMC2_2:
105 return 1;
106 }
107
108#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
109 printf("spl: unsupported mmc boot device.\n");
110#endif
111
112 return -ENODEV;
113}
114
Simon Glass4faf63b2015-12-02 10:59:12 -0700115static int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device)
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200116{
Simon Glass5f4bd8c2017-07-04 13:31:19 -0600117#if CONFIG_IS_ENABLED(DM_MMC)
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200118 struct udevice *dev;
Simon Glass51ace322015-12-02 10:59:13 -0700119#endif
Nikita Kiryanove63b2dd2015-11-08 17:11:54 +0200120 int err, mmc_dev;
121
122 mmc_dev = spl_mmc_get_device_index(boot_device);
123 if (mmc_dev < 0)
124 return mmc_dev;
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200125
126 err = mmc_initialize(NULL);
127 if (err) {
128#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
129 printf("spl: could not initialize mmc. error: %d\n", err);
130#endif
131 return err;
132 }
133
Simon Glass5f4bd8c2017-07-04 13:31:19 -0600134#if CONFIG_IS_ENABLED(DM_MMC)
Nikita Kiryanove63b2dd2015-11-08 17:11:54 +0200135 err = uclass_get_device(UCLASS_MMC, mmc_dev, &dev);
Simon Glass51ace322015-12-02 10:59:13 -0700136 if (!err)
137 *mmcp = mmc_get_mmc_dev(dev);
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200138#else
Simon Glass51ace322015-12-02 10:59:13 -0700139 *mmcp = find_mmc_device(mmc_dev);
140 err = *mmcp ? 0 : -ENODEV;
141#endif
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200142 if (err) {
143#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
Simon Glass51ace322015-12-02 10:59:13 -0700144 printf("spl: could not find mmc device. error: %d\n", err);
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200145#endif
146 return err;
147 }
148
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200149 return 0;
150}
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200151
Dalon Westergreenf5ba9852017-02-10 17:15:35 -0800152#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
Simon Glassee306792016-09-24 18:20:13 -0600153static int mmc_load_image_raw_partition(struct spl_image_info *spl_image,
154 struct mmc *mmc, int partition)
Paul Kocialkowski17675c82014-11-08 23:14:56 +0100155{
156 disk_partition_t info;
Paul Kocialkowski2d69f252015-05-22 12:45:35 +0200157 int err;
Paul Kocialkowski17675c82014-11-08 23:14:56 +0100158
Dalon Westergreen8d770f42017-02-10 17:15:34 -0800159#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION_TYPE
160 int type_part;
161 /* Only support MBR so DOS_ENTRY_NUMBERS */
162 for (type_part = 1; type_part <= DOS_ENTRY_NUMBERS; type_part++) {
163 err = part_get_info(mmc_get_blk_desc(mmc), type_part, &info);
164 if (err)
165 continue;
166 if (info.sys_ind ==
167 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_TYPE) {
168 partition = type_part;
169 break;
170 }
171 }
172#endif
173
Simon Glass55877f92016-07-05 17:10:18 -0600174 err = part_get_info(mmc_get_blk_desc(mmc), partition, &info);
Paul Kocialkowski2d69f252015-05-22 12:45:35 +0200175 if (err) {
Paul Kocialkowski17675c82014-11-08 23:14:56 +0100176#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
Paul Kocialkowski01c723f2015-06-03 18:48:51 +0200177 puts("spl: partition error\n");
Paul Kocialkowski17675c82014-11-08 23:14:56 +0100178#endif
179 return -1;
180 }
181
Semen Protsenko7e3ba482016-11-16 19:19:05 +0200182#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
Simon Glassee306792016-09-24 18:20:13 -0600183 return mmc_load_image_raw_sector(spl_image, mmc,
184 info.start + CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR);
Stefan Roesed0503cd2015-07-20 11:20:39 +0200185#else
Simon Glassee306792016-09-24 18:20:13 -0600186 return mmc_load_image_raw_sector(spl_image, mmc, info.start);
Stefan Roesed0503cd2015-07-20 11:20:39 +0200187#endif
Paul Kocialkowski17675c82014-11-08 23:14:56 +0100188}
189#endif
190
Peter Korsgaard01b542f2013-05-13 08:36:29 +0000191#ifdef CONFIG_SPL_OS_BOOT
Simon Glassee306792016-09-24 18:20:13 -0600192static int mmc_load_image_raw_os(struct spl_image_info *spl_image,
193 struct mmc *mmc)
Peter Korsgaard01b542f2013-05-13 08:36:29 +0000194{
Paul Kocialkowski2d69f252015-05-22 12:45:35 +0200195 unsigned long count;
Lokesh Vutla9dee77f2016-04-11 15:24:50 +0530196 int ret;
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200197
Simon Glass70061ba2016-06-12 23:30:32 -0600198 count = blk_dread(mmc_get_blk_desc(mmc),
Paul Kocialkowski2d69f252015-05-22 12:45:35 +0200199 CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR,
200 CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS,
201 (void *) CONFIG_SYS_SPL_ARGS_ADDR);
Tom Rini195bc4b2017-08-14 21:01:30 -0400202 if (count != CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS) {
Paul Burtona8015fd2013-09-04 16:12:24 +0100203#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
Fabio Estevam37342ab2016-04-20 23:12:04 -0300204 puts("mmc_load_image_raw_os: mmc block read error\n");
Paul Burtona8015fd2013-09-04 16:12:24 +0100205#endif
Peter Korsgaard01b542f2013-05-13 08:36:29 +0000206 return -1;
207 }
208
Simon Glassee306792016-09-24 18:20:13 -0600209 ret = mmc_load_image_raw_sector(spl_image, mmc,
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200210 CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR);
Lokesh Vutla9dee77f2016-04-11 15:24:50 +0530211 if (ret)
212 return ret;
213
Simon Glassee306792016-09-24 18:20:13 -0600214 if (spl_image->os != IH_OS_LINUX) {
Lokesh Vutla9dee77f2016-04-11 15:24:50 +0530215 puts("Expected Linux image is not found. Trying to start U-boot\n");
216 return -ENOENT;
217 }
218
219 return 0;
Peter Korsgaard01b542f2013-05-13 08:36:29 +0000220}
Nikita Kiryanovcc49f552015-11-08 17:11:45 +0200221#else
222int spl_start_uboot(void)
223{
224 return 1;
225}
Simon Glassee306792016-09-24 18:20:13 -0600226static int mmc_load_image_raw_os(struct spl_image_info *spl_image,
227 struct mmc *mmc)
Nikita Kiryanovcc49f552015-11-08 17:11:45 +0200228{
229 return -ENOSYS;
230}
Peter Korsgaard01b542f2013-05-13 08:36:29 +0000231#endif
232
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200233#ifdef CONFIG_SYS_MMCSD_FS_BOOT_PARTITION
Simon Glassee306792016-09-24 18:20:13 -0600234static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, struct mmc *mmc)
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200235{
236 int err = -ENOSYS;
237
238#ifdef CONFIG_SPL_FAT_SUPPORT
239 if (!spl_start_uboot()) {
Simon Glass3eb382a2016-09-24 18:20:15 -0600240 err = spl_load_image_fat_os(spl_image, mmc_get_blk_desc(mmc),
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200241 CONFIG_SYS_MMCSD_FS_BOOT_PARTITION);
242 if (!err)
243 return err;
244 }
245#ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
Simon Glass3eb382a2016-09-24 18:20:15 -0600246 err = spl_load_image_fat(spl_image, mmc_get_blk_desc(mmc),
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200247 CONFIG_SYS_MMCSD_FS_BOOT_PARTITION,
248 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
249 if (!err)
250 return err;
251#endif
252#endif
253#ifdef CONFIG_SPL_EXT_SUPPORT
254 if (!spl_start_uboot()) {
Michal Simek0ef6ec82016-12-01 11:09:01 +0100255 err = spl_load_image_ext_os(spl_image, mmc_get_blk_desc(mmc),
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200256 CONFIG_SYS_MMCSD_FS_BOOT_PARTITION);
257 if (!err)
258 return err;
259 }
260#ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
Michal Simek0ef6ec82016-12-01 11:09:01 +0100261 err = spl_load_image_ext(spl_image, mmc_get_blk_desc(mmc),
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200262 CONFIG_SYS_MMCSD_FS_BOOT_PARTITION,
263 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME);
264 if (!err)
265 return err;
266#endif
267#endif
268
269#if defined(CONFIG_SPL_FAT_SUPPORT) || defined(CONFIG_SPL_EXT_SUPPORT)
270 err = -ENOENT;
271#endif
272
273 return err;
274}
275#else
Simon Glassee306792016-09-24 18:20:13 -0600276static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, struct mmc *mmc)
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200277{
278 return -ENOSYS;
279}
280#endif
281
Lukasz Majewski7c88d102018-02-03 08:29:52 +0100282u32 __weak spl_boot_mode(const u32 boot_device)
283{
284#if defined(CONFIG_SPL_FAT_SUPPORT) || defined(CONFIG_SPL_EXT_SUPPORT)
285 return MMCSD_MODE_FS;
286#elif defined(CONFIG_SUPPORT_EMMC_BOOT)
287 return MMCSD_MODE_EMMCBOOT;
288#else
289 return MMCSD_MODE_RAW;
290#endif
291}
292
Patrick Delaunay113aa502018-03-20 10:54:51 +0100293#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
294__weak
295int spl_boot_partition(const u32 boot_device)
296{
297 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION;
298}
299#endif
300
Marek Vasut8d5c4c32016-12-01 02:06:35 +0100301int spl_mmc_load_image(struct spl_image_info *spl_image,
302 struct spl_boot_device *bootdev)
Simon Schwarze21d2d82011-09-14 15:33:34 -0400303{
Simon Glassa2b771c2015-12-02 10:59:11 -0700304 struct mmc *mmc = NULL;
Simon Schwarze21d2d82011-09-14 15:33:34 -0400305 u32 boot_mode;
Simon Glassf22851a2015-06-23 15:38:51 -0600306 int err = 0;
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200307 __maybe_unused int part;
Simon Schwarze21d2d82011-09-14 15:33:34 -0400308
Simon Glassc0b6c9b2016-09-24 18:19:57 -0600309 err = spl_mmc_find_device(&mmc, bootdev->boot_device);
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200310 if (err)
311 return err;
Simon Schwarze21d2d82011-09-14 15:33:34 -0400312
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200313 err = mmc_init(mmc);
Simon Schwarze21d2d82011-09-14 15:33:34 -0400314 if (err) {
Paul Burtona8015fd2013-09-04 16:12:24 +0100315#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200316 printf("spl: mmc init failed with error: %d\n", err);
Paul Burtona8015fd2013-09-04 16:12:24 +0100317#endif
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200318 return err;
Simon Schwarze21d2d82011-09-14 15:33:34 -0400319 }
Peter Korsgaard5e5483d2013-05-13 08:36:25 +0000320
Simon Glassc0b6c9b2016-09-24 18:19:57 -0600321 boot_mode = spl_boot_mode(bootdev->boot_device);
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200322 err = -EINVAL;
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200323 switch (boot_mode) {
Nikita Kiryanov2b3ae5f2015-11-08 17:11:48 +0200324 case MMCSD_MODE_EMMCBOOT:
325 /*
326 * We need to check what the partition is configured to.
327 * 1 and 2 match up to boot0 / boot1 and 7 is user data
328 * which is the first physical partition (0).
329 */
330 part = (mmc->part_config >> 3) & PART_ACCESS_MASK;
331
332 if (part == 7)
333 part = 0;
334
Marek Vasutf537e392016-12-01 02:06:33 +0100335 if (CONFIG_IS_ENABLED(MMC_TINY))
336 err = mmc_switch_part(mmc, part);
337 else
338 err = blk_dselect_hwpart(mmc_get_blk_desc(mmc), part);
339
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200340 if (err) {
Nikita Kiryanov2b3ae5f2015-11-08 17:11:48 +0200341#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
342 puts("spl: mmc partition switch failed\n");
343#endif
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200344 return err;
Nikita Kiryanov2b3ae5f2015-11-08 17:11:48 +0200345 }
346 /* Fall through */
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200347 case MMCSD_MODE_RAW:
348 debug("spl: mmc boot mode: raw\n");
349
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200350 if (!spl_start_uboot()) {
Simon Glassee306792016-09-24 18:20:13 -0600351 err = mmc_load_image_raw_os(spl_image, mmc);
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200352 if (!err)
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200353 return err;
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200354 }
Dalon Westergreenf5ba9852017-02-10 17:15:35 -0800355#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
Patrick Delaunay113aa502018-03-20 10:54:51 +0100356 err = spl_boot_partition(bootdev->boot_device);
357 if (!err)
358 return err;
359
360 err = mmc_load_image_raw_partition(spl_image, mmc, err);
Paul Kocialkowski4bd66e72015-06-08 23:05:09 +0200361 if (!err)
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200362 return err;
Dalon Westergreenf5ba9852017-02-10 17:15:35 -0800363#endif
Semen Protsenko7e3ba482016-11-16 19:19:05 +0200364#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
Simon Glassee306792016-09-24 18:20:13 -0600365 err = mmc_load_image_raw_sector(spl_image, mmc,
Dan Murphyb7b5b0c2014-01-16 11:23:29 -0600366 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR);
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200367 if (!err)
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200368 return err;
Paul Kocialkowski4bd66e72015-06-08 23:05:09 +0200369#endif
Guillaume GARDET834dd882016-02-18 18:17:36 +0100370 /* If RAW mode fails, try FS mode. */
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200371 case MMCSD_MODE_FS:
372 debug("spl: mmc boot mode: fs\n");
373
Simon Glassee306792016-09-24 18:20:13 -0600374 err = spl_mmc_do_fs_boot(spl_image, mmc);
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200375 if (!err)
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200376 return err;
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200377
Nikita Kiryanoved52f4d2015-11-08 17:11:43 +0200378 break;
Paul Burtona8015fd2013-09-04 16:12:24 +0100379#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
Nikita Kiryanoved52f4d2015-11-08 17:11:43 +0200380 default:
381 puts("spl: mmc: wrong boot mode\n");
Paul Burtona8015fd2013-09-04 16:12:24 +0100382#endif
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200383 }
Nikita Kiryanoved52f4d2015-11-08 17:11:43 +0200384
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200385 return err;
Simon Schwarze21d2d82011-09-14 15:33:34 -0400386}
Simon Glassd449cb82016-09-24 18:20:00 -0600387
Simon Glass4fc1f252016-11-30 15:30:50 -0700388SPL_LOAD_IMAGE_METHOD("MMC1", 0, BOOT_DEVICE_MMC1, spl_mmc_load_image);
389SPL_LOAD_IMAGE_METHOD("MMC2", 0, BOOT_DEVICE_MMC2, spl_mmc_load_image);
390SPL_LOAD_IMAGE_METHOD("MMC2_2", 0, BOOT_DEVICE_MMC2_2, spl_mmc_load_image);