blob: b3619889f794bdb714beeb85965bcf27af7fcf0d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Schwarze21d2d82011-09-14 15:33:34 -04002/*
3 * (C) Copyright 2010
4 * Texas Instruments, <www.ti.com>
5 *
6 * Aneesh V <aneesh@ti.com>
Simon Schwarze21d2d82011-09-14 15:33:34 -04007 */
8#include <common.h>
Simon Glassf22851a2015-06-23 15:38:51 -06009#include <dm.h>
Tom Rini28591df2012-08-13 12:03:19 -070010#include <spl.h>
Paul Kocialkowski0d139722015-04-27 10:20:22 +020011#include <linux/compiler.h>
Nikita Kiryanov33eefe42015-11-08 17:11:49 +020012#include <errno.h>
Simon Schwarze21d2d82011-09-14 15:33:34 -040013#include <asm/u-boot.h>
Nikita Kiryanov022ddb82015-11-08 17:11:44 +020014#include <errno.h>
Simon Schwarze21d2d82011-09-14 15:33:34 -040015#include <mmc.h>
Tom Rini1530e8a2013-06-28 14:43:01 -040016#include <image.h>
Simon Schwarze21d2d82011-09-14 15:33:34 -040017
Simon Glassee306792016-09-24 18:20:13 -060018static int mmc_load_legacy(struct spl_image_info *spl_image, struct mmc *mmc,
19 ulong sector, struct image_header *header)
Simon Glassb52c7fc2016-02-22 22:55:58 -070020{
21 u32 image_size_sectors;
22 unsigned long count;
Marek Vasut02266e22016-04-29 00:44:54 +020023 int ret;
24
Simon Glassee306792016-09-24 18:20:13 -060025 ret = spl_parse_image_header(spl_image, header);
Marek Vasut02266e22016-04-29 00:44:54 +020026 if (ret)
27 return ret;
Simon Glassb52c7fc2016-02-22 22:55:58 -070028
Simon Glassb52c7fc2016-02-22 22:55:58 -070029 /* convert size to sectors - round up */
Simon Glassee306792016-09-24 18:20:13 -060030 image_size_sectors = (spl_image->size + mmc->read_bl_len - 1) /
Simon Glassb52c7fc2016-02-22 22:55:58 -070031 mmc->read_bl_len;
32
33 /* Read the header too to avoid extra memcpy */
Simon Glass670d3042016-05-14 14:03:06 -060034 count = blk_dread(mmc_get_blk_desc(mmc), sector, image_size_sectors,
Simon Glassee306792016-09-24 18:20:13 -060035 (void *)(ulong)spl_image->load_addr);
Andre Przywara6c526072017-01-02 11:48:31 +000036 debug("read %x sectors to %lx\n", image_size_sectors,
Simon Glassee306792016-09-24 18:20:13 -060037 spl_image->load_addr);
Simon Glassb52c7fc2016-02-22 22:55:58 -070038 if (count != image_size_sectors)
39 return -EIO;
40
41 return 0;
42}
43
Simon Glassb52c7fc2016-02-22 22:55:58 -070044static ulong h_spl_load_read(struct spl_load_info *load, ulong sector,
45 ulong count, void *buf)
46{
47 struct mmc *mmc = load->dev;
48
Simon Glass670d3042016-05-14 14:03:06 -060049 return blk_dread(mmc_get_blk_desc(mmc), sector, count, buf);
Simon Glassb52c7fc2016-02-22 22:55:58 -070050}
Simon Glassb52c7fc2016-02-22 22:55:58 -070051
Seung-Woo Kimc0a4e2d2017-09-19 13:29:45 +090052static __maybe_unused
53int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
54 struct mmc *mmc, unsigned long sector)
Simon Schwarze21d2d82011-09-14 15:33:34 -040055{
Paul Kocialkowski2d69f252015-05-22 12:45:35 +020056 unsigned long count;
Peter Korsgaardf2471292013-03-21 04:55:17 +000057 struct image_header *header;
Marek Vasut1dda46f2018-08-14 11:27:02 +020058 struct blk_desc *bd = mmc_get_blk_desc(mmc);
Simon Glassb52c7fc2016-02-22 22:55:58 -070059 int ret = 0;
Simon Schwarze21d2d82011-09-14 15:33:34 -040060
Marek Vasut1dda46f2018-08-14 11:27:02 +020061 header = spl_get_load_buffer(-sizeof(*header), bd->blksz);
Simon Schwarze21d2d82011-09-14 15:33:34 -040062
63 /* read image header to find the image size & load address */
Marek Vasut1dda46f2018-08-14 11:27:02 +020064 count = blk_dread(bd, sector, 1, header);
Simon Glassb52c7fc2016-02-22 22:55:58 -070065 debug("hdr read sector %lx, count=%lu\n", sector, count);
66 if (count == 0) {
67 ret = -EIO;
Simon Schwarze21d2d82011-09-14 15:33:34 -040068 goto end;
Simon Glassb52c7fc2016-02-22 22:55:58 -070069 }
Simon Schwarze21d2d82011-09-14 15:33:34 -040070
Masahiro Yamada802f1c32016-03-16 12:10:00 +090071 if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
72 image_get_magic(header) == FDT_MAGIC) {
Simon Glassb52c7fc2016-02-22 22:55:58 -070073 struct spl_load_info load;
74
75 debug("Found FIT\n");
76 load.dev = mmc;
77 load.priv = NULL;
Lokesh Vutlaf62cef12016-05-24 10:34:38 +053078 load.filename = NULL;
Simon Glassb52c7fc2016-02-22 22:55:58 -070079 load.bl_len = mmc->read_bl_len;
80 load.read = h_spl_load_read;
Simon Glass43a734f2016-09-24 18:20:16 -060081 ret = spl_load_simple_fit(spl_image, &load, sector, header);
Masahiro Yamada802f1c32016-03-16 12:10:00 +090082 } else {
Simon Glassee306792016-09-24 18:20:13 -060083 ret = mmc_load_legacy(spl_image, mmc, sector, header);
Simon Glass5614db82015-06-23 15:38:47 -060084 }
Tom Rini1530e8a2013-06-28 14:43:01 -040085
Simon Schwarze21d2d82011-09-14 15:33:34 -040086end:
Simon Glassb52c7fc2016-02-22 22:55:58 -070087 if (ret) {
Paul Burtona8015fd2013-09-04 16:12:24 +010088#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
Fabio Estevam37342ab2016-04-20 23:12:04 -030089 puts("mmc_load_image_raw_sector: mmc block read error\n");
Paul Burtona8015fd2013-09-04 16:12:24 +010090#endif
Paul Kocialkowski2d69f252015-05-22 12:45:35 +020091 return -1;
Paul Kocialkowski01c723f2015-06-03 18:48:51 +020092 }
Paul Kocialkowski2d69f252015-05-22 12:45:35 +020093
94 return 0;
Simon Schwarze21d2d82011-09-14 15:33:34 -040095}
96
Masahiro Yamada2a4a20c2017-06-22 16:52:36 +090097static int spl_mmc_get_device_index(u32 boot_device)
Nikita Kiryanove63b2dd2015-11-08 17:11:54 +020098{
99 switch (boot_device) {
100 case BOOT_DEVICE_MMC1:
101 return 0;
102 case BOOT_DEVICE_MMC2:
103 case BOOT_DEVICE_MMC2_2:
104 return 1;
105 }
106
107#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
108 printf("spl: unsupported mmc boot device.\n");
109#endif
110
111 return -ENODEV;
112}
113
Simon Glass4faf63b2015-12-02 10:59:12 -0700114static int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device)
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200115{
Simon Glass5f4bd8c2017-07-04 13:31:19 -0600116#if CONFIG_IS_ENABLED(DM_MMC)
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200117 struct udevice *dev;
Simon Glass51ace322015-12-02 10:59:13 -0700118#endif
Nikita Kiryanove63b2dd2015-11-08 17:11:54 +0200119 int err, mmc_dev;
120
121 mmc_dev = spl_mmc_get_device_index(boot_device);
122 if (mmc_dev < 0)
123 return mmc_dev;
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200124
125 err = mmc_initialize(NULL);
126 if (err) {
127#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
128 printf("spl: could not initialize mmc. error: %d\n", err);
129#endif
130 return err;
131 }
132
Simon Glass5f4bd8c2017-07-04 13:31:19 -0600133#if CONFIG_IS_ENABLED(DM_MMC)
Nikita Kiryanove63b2dd2015-11-08 17:11:54 +0200134 err = uclass_get_device(UCLASS_MMC, mmc_dev, &dev);
Simon Glass51ace322015-12-02 10:59:13 -0700135 if (!err)
136 *mmcp = mmc_get_mmc_dev(dev);
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200137#else
Simon Glass51ace322015-12-02 10:59:13 -0700138 *mmcp = find_mmc_device(mmc_dev);
139 err = *mmcp ? 0 : -ENODEV;
140#endif
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200141 if (err) {
142#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
Alex Kiernanf5920d02018-09-18 08:11:55 +0000143 printf("spl: could not find mmc device %d. error: %d\n",
144 mmc_dev, 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,
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500154 struct mmc *mmc, int partition,
155 unsigned long sector)
Paul Kocialkowski17675c82014-11-08 23:14:56 +0100156{
157 disk_partition_t info;
Paul Kocialkowski2d69f252015-05-22 12:45:35 +0200158 int err;
Paul Kocialkowski17675c82014-11-08 23:14:56 +0100159
Dalon Westergreen8d770f42017-02-10 17:15:34 -0800160#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION_TYPE
161 int type_part;
162 /* Only support MBR so DOS_ENTRY_NUMBERS */
163 for (type_part = 1; type_part <= DOS_ENTRY_NUMBERS; type_part++) {
164 err = part_get_info(mmc_get_blk_desc(mmc), type_part, &info);
165 if (err)
166 continue;
167 if (info.sys_ind ==
168 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_TYPE) {
169 partition = type_part;
170 break;
171 }
172 }
173#endif
174
Simon Glass55877f92016-07-05 17:10:18 -0600175 err = part_get_info(mmc_get_blk_desc(mmc), partition, &info);
Paul Kocialkowski2d69f252015-05-22 12:45:35 +0200176 if (err) {
Paul Kocialkowski17675c82014-11-08 23:14:56 +0100177#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
Paul Kocialkowski01c723f2015-06-03 18:48:51 +0200178 puts("spl: partition error\n");
Paul Kocialkowski17675c82014-11-08 23:14:56 +0100179#endif
180 return -1;
181 }
182
Semen Protsenko7e3ba482016-11-16 19:19:05 +0200183#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500184 return mmc_load_image_raw_sector(spl_image, mmc, info.start + 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{
Lokesh Vutla9dee77f2016-04-11 15:24:50 +0530195 int ret;
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200196
York Suncea88212018-06-26 09:44:39 -0700197#if defined(CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR)
198 unsigned long count;
199
Simon Glass70061ba2016-06-12 23:30:32 -0600200 count = blk_dread(mmc_get_blk_desc(mmc),
Paul Kocialkowski2d69f252015-05-22 12:45:35 +0200201 CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR,
202 CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS,
203 (void *) CONFIG_SYS_SPL_ARGS_ADDR);
Tom Rini195bc4b2017-08-14 21:01:30 -0400204 if (count != CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS) {
Paul Burtona8015fd2013-09-04 16:12:24 +0100205#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
Fabio Estevam37342ab2016-04-20 23:12:04 -0300206 puts("mmc_load_image_raw_os: mmc block read error\n");
Paul Burtona8015fd2013-09-04 16:12:24 +0100207#endif
Peter Korsgaard01b542f2013-05-13 08:36:29 +0000208 return -1;
209 }
York Suncea88212018-06-26 09:44:39 -0700210#endif /* CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR */
Peter Korsgaard01b542f2013-05-13 08:36:29 +0000211
Simon Glassee306792016-09-24 18:20:13 -0600212 ret = mmc_load_image_raw_sector(spl_image, mmc,
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200213 CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR);
Lokesh Vutla9dee77f2016-04-11 15:24:50 +0530214 if (ret)
215 return ret;
216
Simon Glassee306792016-09-24 18:20:13 -0600217 if (spl_image->os != IH_OS_LINUX) {
Lokesh Vutla9dee77f2016-04-11 15:24:50 +0530218 puts("Expected Linux image is not found. Trying to start U-boot\n");
219 return -ENOENT;
220 }
221
222 return 0;
Peter Korsgaard01b542f2013-05-13 08:36:29 +0000223}
Nikita Kiryanovcc49f552015-11-08 17:11:45 +0200224#else
225int spl_start_uboot(void)
226{
227 return 1;
228}
Simon Glassee306792016-09-24 18:20:13 -0600229static int mmc_load_image_raw_os(struct spl_image_info *spl_image,
230 struct mmc *mmc)
Nikita Kiryanovcc49f552015-11-08 17:11:45 +0200231{
232 return -ENOSYS;
233}
Peter Korsgaard01b542f2013-05-13 08:36:29 +0000234#endif
235
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200236#ifdef CONFIG_SYS_MMCSD_FS_BOOT_PARTITION
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500237static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, struct mmc *mmc,
238 const char *filename)
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200239{
240 int err = -ENOSYS;
241
Tien Fong Chee6fd0a712019-01-23 14:20:03 +0800242#ifdef CONFIG_SPL_FS_FAT
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200243 if (!spl_start_uboot()) {
Simon Glass3eb382a2016-09-24 18:20:15 -0600244 err = spl_load_image_fat_os(spl_image, mmc_get_blk_desc(mmc),
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200245 CONFIG_SYS_MMCSD_FS_BOOT_PARTITION);
246 if (!err)
247 return err;
248 }
249#ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
Simon Glass3eb382a2016-09-24 18:20:15 -0600250 err = spl_load_image_fat(spl_image, mmc_get_blk_desc(mmc),
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200251 CONFIG_SYS_MMCSD_FS_BOOT_PARTITION,
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500252 filename);
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200253 if (!err)
254 return err;
255#endif
256#endif
Tien Fong Chee6091dd12019-01-23 14:20:05 +0800257#ifdef CONFIG_SPL_FS_EXT4
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200258 if (!spl_start_uboot()) {
Michal Simek0ef6ec82016-12-01 11:09:01 +0100259 err = spl_load_image_ext_os(spl_image, mmc_get_blk_desc(mmc),
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200260 CONFIG_SYS_MMCSD_FS_BOOT_PARTITION);
261 if (!err)
262 return err;
263 }
264#ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
Michal Simek0ef6ec82016-12-01 11:09:01 +0100265 err = spl_load_image_ext(spl_image, mmc_get_blk_desc(mmc),
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200266 CONFIG_SYS_MMCSD_FS_BOOT_PARTITION,
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500267 filename);
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200268 if (!err)
269 return err;
270#endif
271#endif
272
Tien Fong Chee6091dd12019-01-23 14:20:05 +0800273#if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200274 err = -ENOENT;
275#endif
276
277 return err;
278}
279#else
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500280static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, struct mmc *mmc,
281 const char *filename)
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200282{
283 return -ENOSYS;
284}
285#endif
286
Lukasz Majewski7c88d102018-02-03 08:29:52 +0100287u32 __weak spl_boot_mode(const u32 boot_device)
288{
Tien Fong Chee6091dd12019-01-23 14:20:05 +0800289#if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
Lukasz Majewski7c88d102018-02-03 08:29:52 +0100290 return MMCSD_MODE_FS;
291#elif defined(CONFIG_SUPPORT_EMMC_BOOT)
292 return MMCSD_MODE_EMMCBOOT;
293#else
294 return MMCSD_MODE_RAW;
295#endif
296}
297
Patrick Delaunay113aa502018-03-20 10:54:51 +0100298#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
299__weak
300int spl_boot_partition(const u32 boot_device)
301{
302 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION;
303}
304#endif
305
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500306int spl_mmc_load(struct spl_image_info *spl_image,
307 struct spl_boot_device *bootdev,
308 const char *filename,
309 int raw_part,
310 unsigned long raw_sect)
Simon Schwarze21d2d82011-09-14 15:33:34 -0400311{
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500312 static struct mmc *mmc;
Simon Schwarze21d2d82011-09-14 15:33:34 -0400313 u32 boot_mode;
Simon Glassf22851a2015-06-23 15:38:51 -0600314 int err = 0;
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200315 __maybe_unused int part;
Simon Schwarze21d2d82011-09-14 15:33:34 -0400316
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500317 /* Perform peripheral init only once */
318 if (!mmc) {
319 err = spl_mmc_find_device(&mmc, bootdev->boot_device);
320 if (err)
321 return err;
Simon Schwarze21d2d82011-09-14 15:33:34 -0400322
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500323 err = mmc_init(mmc);
324 if (err) {
325 mmc = NULL;
Paul Burtona8015fd2013-09-04 16:12:24 +0100326#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500327 printf("spl: mmc init failed with error: %d\n", err);
Paul Burtona8015fd2013-09-04 16:12:24 +0100328#endif
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500329 return err;
330 }
Simon Schwarze21d2d82011-09-14 15:33:34 -0400331 }
Peter Korsgaard5e5483d2013-05-13 08:36:25 +0000332
Simon Glassc0b6c9b2016-09-24 18:19:57 -0600333 boot_mode = spl_boot_mode(bootdev->boot_device);
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200334 err = -EINVAL;
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200335 switch (boot_mode) {
Nikita Kiryanov2b3ae5f2015-11-08 17:11:48 +0200336 case MMCSD_MODE_EMMCBOOT:
337 /*
338 * We need to check what the partition is configured to.
339 * 1 and 2 match up to boot0 / boot1 and 7 is user data
340 * which is the first physical partition (0).
341 */
342 part = (mmc->part_config >> 3) & PART_ACCESS_MASK;
343
344 if (part == 7)
345 part = 0;
346
Marek Vasutf537e392016-12-01 02:06:33 +0100347 if (CONFIG_IS_ENABLED(MMC_TINY))
348 err = mmc_switch_part(mmc, part);
349 else
350 err = blk_dselect_hwpart(mmc_get_blk_desc(mmc), part);
351
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200352 if (err) {
Nikita Kiryanov2b3ae5f2015-11-08 17:11:48 +0200353#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
354 puts("spl: mmc partition switch failed\n");
355#endif
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200356 return err;
Nikita Kiryanov2b3ae5f2015-11-08 17:11:48 +0200357 }
358 /* Fall through */
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200359 case MMCSD_MODE_RAW:
360 debug("spl: mmc boot mode: raw\n");
361
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200362 if (!spl_start_uboot()) {
Simon Glassee306792016-09-24 18:20:13 -0600363 err = mmc_load_image_raw_os(spl_image, mmc);
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200364 if (!err)
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200365 return err;
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200366 }
Dalon Westergreenf5ba9852017-02-10 17:15:35 -0800367#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500368 err = mmc_load_image_raw_partition(spl_image, mmc, raw_part,
369 raw_sect);
Paul Kocialkowski4bd66e72015-06-08 23:05:09 +0200370 if (!err)
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200371 return err;
Dalon Westergreenf5ba9852017-02-10 17:15:35 -0800372#endif
Semen Protsenko7e3ba482016-11-16 19:19:05 +0200373#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500374 err = mmc_load_image_raw_sector(spl_image, mmc, raw_sect);
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200375 if (!err)
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200376 return err;
Paul Kocialkowski4bd66e72015-06-08 23:05:09 +0200377#endif
Guillaume GARDET834dd882016-02-18 18:17:36 +0100378 /* If RAW mode fails, try FS mode. */
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200379 case MMCSD_MODE_FS:
380 debug("spl: mmc boot mode: fs\n");
381
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500382 err = spl_mmc_do_fs_boot(spl_image, mmc, filename);
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200383 if (!err)
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200384 return err;
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200385
Nikita Kiryanoved52f4d2015-11-08 17:11:43 +0200386 break;
Paul Burtona8015fd2013-09-04 16:12:24 +0100387#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
Nikita Kiryanoved52f4d2015-11-08 17:11:43 +0200388 default:
389 puts("spl: mmc: wrong boot mode\n");
Paul Burtona8015fd2013-09-04 16:12:24 +0100390#endif
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200391 }
Nikita Kiryanoved52f4d2015-11-08 17:11:43 +0200392
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200393 return err;
Simon Schwarze21d2d82011-09-14 15:33:34 -0400394}
Simon Glassd449cb82016-09-24 18:20:00 -0600395
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500396int spl_mmc_load_image(struct spl_image_info *spl_image,
397 struct spl_boot_device *bootdev)
398{
399 return spl_mmc_load(spl_image, bootdev,
400#ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
401 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME,
402#else
403 NULL,
404#endif
405#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION
406 spl_boot_partition(bootdev->boot_device),
407#else
408 0,
409#endif
410#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR
411 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR);
412#else
413 0);
414#endif
415}
416
Simon Glass4fc1f252016-11-30 15:30:50 -0700417SPL_LOAD_IMAGE_METHOD("MMC1", 0, BOOT_DEVICE_MMC1, spl_mmc_load_image);
418SPL_LOAD_IMAGE_METHOD("MMC2", 0, BOOT_DEVICE_MMC2, spl_mmc_load_image);
419SPL_LOAD_IMAGE_METHOD("MMC2_2", 0, BOOT_DEVICE_MMC2_2, spl_mmc_load_image);