blob: 6c6eaf4ec87e043b3d0a3719f478b63549f32e83 [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);
Peng Fand8670762019-08-22 07:42:38 +000082 } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
83 struct spl_load_info load;
84
85 load.dev = mmc;
86 load.priv = NULL;
87 load.filename = NULL;
88 load.bl_len = mmc->read_bl_len;
89 load.read = h_spl_load_read;
90
91 ret = spl_load_imx_container(spl_image, &load, sector);
Masahiro Yamada802f1c32016-03-16 12:10:00 +090092 } else {
Simon Glassee306792016-09-24 18:20:13 -060093 ret = mmc_load_legacy(spl_image, mmc, sector, header);
Simon Glass5614db82015-06-23 15:38:47 -060094 }
Tom Rini1530e8a2013-06-28 14:43:01 -040095
Simon Schwarze21d2d82011-09-14 15:33:34 -040096end:
Simon Glassb52c7fc2016-02-22 22:55:58 -070097 if (ret) {
Paul Burtona8015fd2013-09-04 16:12:24 +010098#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
Fabio Estevam37342ab2016-04-20 23:12:04 -030099 puts("mmc_load_image_raw_sector: mmc block read error\n");
Paul Burtona8015fd2013-09-04 16:12:24 +0100100#endif
Paul Kocialkowski2d69f252015-05-22 12:45:35 +0200101 return -1;
Paul Kocialkowski01c723f2015-06-03 18:48:51 +0200102 }
Paul Kocialkowski2d69f252015-05-22 12:45:35 +0200103
104 return 0;
Simon Schwarze21d2d82011-09-14 15:33:34 -0400105}
106
Masahiro Yamada2a4a20c2017-06-22 16:52:36 +0900107static int spl_mmc_get_device_index(u32 boot_device)
Nikita Kiryanove63b2dd2015-11-08 17:11:54 +0200108{
109 switch (boot_device) {
110 case BOOT_DEVICE_MMC1:
111 return 0;
112 case BOOT_DEVICE_MMC2:
113 case BOOT_DEVICE_MMC2_2:
114 return 1;
115 }
116
117#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
118 printf("spl: unsupported mmc boot device.\n");
119#endif
120
121 return -ENODEV;
122}
123
Simon Glass4faf63b2015-12-02 10:59:12 -0700124static int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device)
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200125{
Simon Glass5f4bd8c2017-07-04 13:31:19 -0600126#if CONFIG_IS_ENABLED(DM_MMC)
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200127 struct udevice *dev;
Simon Glass51ace322015-12-02 10:59:13 -0700128#endif
Nikita Kiryanove63b2dd2015-11-08 17:11:54 +0200129 int err, mmc_dev;
130
131 mmc_dev = spl_mmc_get_device_index(boot_device);
132 if (mmc_dev < 0)
133 return mmc_dev;
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200134
135 err = mmc_initialize(NULL);
136 if (err) {
137#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
138 printf("spl: could not initialize mmc. error: %d\n", err);
139#endif
140 return err;
141 }
142
Simon Glass5f4bd8c2017-07-04 13:31:19 -0600143#if CONFIG_IS_ENABLED(DM_MMC)
Nikita Kiryanove63b2dd2015-11-08 17:11:54 +0200144 err = uclass_get_device(UCLASS_MMC, mmc_dev, &dev);
Simon Glass51ace322015-12-02 10:59:13 -0700145 if (!err)
146 *mmcp = mmc_get_mmc_dev(dev);
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200147#else
Simon Glass51ace322015-12-02 10:59:13 -0700148 *mmcp = find_mmc_device(mmc_dev);
149 err = *mmcp ? 0 : -ENODEV;
150#endif
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200151 if (err) {
152#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
Alex Kiernanf5920d02018-09-18 08:11:55 +0000153 printf("spl: could not find mmc device %d. error: %d\n",
154 mmc_dev, err);
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200155#endif
156 return err;
157 }
158
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200159 return 0;
160}
Nikita Kiryanov022ddb82015-11-08 17:11:44 +0200161
Dalon Westergreenf5ba9852017-02-10 17:15:35 -0800162#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
Simon Glassee306792016-09-24 18:20:13 -0600163static int mmc_load_image_raw_partition(struct spl_image_info *spl_image,
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500164 struct mmc *mmc, int partition,
165 unsigned long sector)
Paul Kocialkowski17675c82014-11-08 23:14:56 +0100166{
167 disk_partition_t info;
Paul Kocialkowski2d69f252015-05-22 12:45:35 +0200168 int err;
Paul Kocialkowski17675c82014-11-08 23:14:56 +0100169
Dalon Westergreen8d770f42017-02-10 17:15:34 -0800170#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION_TYPE
171 int type_part;
172 /* Only support MBR so DOS_ENTRY_NUMBERS */
173 for (type_part = 1; type_part <= DOS_ENTRY_NUMBERS; type_part++) {
174 err = part_get_info(mmc_get_blk_desc(mmc), type_part, &info);
175 if (err)
176 continue;
177 if (info.sys_ind ==
178 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_TYPE) {
179 partition = type_part;
180 break;
181 }
182 }
183#endif
184
Simon Glass55877f92016-07-05 17:10:18 -0600185 err = part_get_info(mmc_get_blk_desc(mmc), partition, &info);
Paul Kocialkowski2d69f252015-05-22 12:45:35 +0200186 if (err) {
Paul Kocialkowski17675c82014-11-08 23:14:56 +0100187#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
Paul Kocialkowski01c723f2015-06-03 18:48:51 +0200188 puts("spl: partition error\n");
Paul Kocialkowski17675c82014-11-08 23:14:56 +0100189#endif
190 return -1;
191 }
192
Semen Protsenko7e3ba482016-11-16 19:19:05 +0200193#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500194 return mmc_load_image_raw_sector(spl_image, mmc, info.start + sector);
Stefan Roesed0503cd2015-07-20 11:20:39 +0200195#else
Simon Glassee306792016-09-24 18:20:13 -0600196 return mmc_load_image_raw_sector(spl_image, mmc, info.start);
Stefan Roesed0503cd2015-07-20 11:20:39 +0200197#endif
Paul Kocialkowski17675c82014-11-08 23:14:56 +0100198}
199#endif
200
Peter Korsgaard01b542f2013-05-13 08:36:29 +0000201#ifdef CONFIG_SPL_OS_BOOT
Simon Glassee306792016-09-24 18:20:13 -0600202static int mmc_load_image_raw_os(struct spl_image_info *spl_image,
203 struct mmc *mmc)
Peter Korsgaard01b542f2013-05-13 08:36:29 +0000204{
Lokesh Vutla9dee77f2016-04-11 15:24:50 +0530205 int ret;
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200206
York Suncea88212018-06-26 09:44:39 -0700207#if defined(CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR)
208 unsigned long count;
209
Simon Glass70061ba2016-06-12 23:30:32 -0600210 count = blk_dread(mmc_get_blk_desc(mmc),
Paul Kocialkowski2d69f252015-05-22 12:45:35 +0200211 CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR,
212 CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS,
213 (void *) CONFIG_SYS_SPL_ARGS_ADDR);
Tom Rini195bc4b2017-08-14 21:01:30 -0400214 if (count != CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS) {
Paul Burtona8015fd2013-09-04 16:12:24 +0100215#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
Fabio Estevam37342ab2016-04-20 23:12:04 -0300216 puts("mmc_load_image_raw_os: mmc block read error\n");
Paul Burtona8015fd2013-09-04 16:12:24 +0100217#endif
Peter Korsgaard01b542f2013-05-13 08:36:29 +0000218 return -1;
219 }
York Suncea88212018-06-26 09:44:39 -0700220#endif /* CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR */
Peter Korsgaard01b542f2013-05-13 08:36:29 +0000221
Simon Glassee306792016-09-24 18:20:13 -0600222 ret = mmc_load_image_raw_sector(spl_image, mmc,
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200223 CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR);
Lokesh Vutla9dee77f2016-04-11 15:24:50 +0530224 if (ret)
225 return ret;
226
Simon Glassee306792016-09-24 18:20:13 -0600227 if (spl_image->os != IH_OS_LINUX) {
Lokesh Vutla9dee77f2016-04-11 15:24:50 +0530228 puts("Expected Linux image is not found. Trying to start U-boot\n");
229 return -ENOENT;
230 }
231
232 return 0;
Peter Korsgaard01b542f2013-05-13 08:36:29 +0000233}
Nikita Kiryanovcc49f552015-11-08 17:11:45 +0200234#else
235int spl_start_uboot(void)
236{
237 return 1;
238}
Simon Glassee306792016-09-24 18:20:13 -0600239static int mmc_load_image_raw_os(struct spl_image_info *spl_image,
240 struct mmc *mmc)
Nikita Kiryanovcc49f552015-11-08 17:11:45 +0200241{
242 return -ENOSYS;
243}
Peter Korsgaard01b542f2013-05-13 08:36:29 +0000244#endif
245
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200246#ifdef CONFIG_SYS_MMCSD_FS_BOOT_PARTITION
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500247static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, struct mmc *mmc,
248 const char *filename)
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200249{
250 int err = -ENOSYS;
251
Tien Fong Chee6fd0a712019-01-23 14:20:03 +0800252#ifdef CONFIG_SPL_FS_FAT
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200253 if (!spl_start_uboot()) {
Simon Glass3eb382a2016-09-24 18:20:15 -0600254 err = spl_load_image_fat_os(spl_image, mmc_get_blk_desc(mmc),
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200255 CONFIG_SYS_MMCSD_FS_BOOT_PARTITION);
256 if (!err)
257 return err;
258 }
259#ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
Simon Glass3eb382a2016-09-24 18:20:15 -0600260 err = spl_load_image_fat(spl_image, mmc_get_blk_desc(mmc),
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200261 CONFIG_SYS_MMCSD_FS_BOOT_PARTITION,
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500262 filename);
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200263 if (!err)
264 return err;
265#endif
266#endif
Tien Fong Chee6091dd12019-01-23 14:20:05 +0800267#ifdef CONFIG_SPL_FS_EXT4
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200268 if (!spl_start_uboot()) {
Michal Simek0ef6ec82016-12-01 11:09:01 +0100269 err = spl_load_image_ext_os(spl_image, mmc_get_blk_desc(mmc),
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200270 CONFIG_SYS_MMCSD_FS_BOOT_PARTITION);
271 if (!err)
272 return err;
273 }
274#ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
Michal Simek0ef6ec82016-12-01 11:09:01 +0100275 err = spl_load_image_ext(spl_image, mmc_get_blk_desc(mmc),
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200276 CONFIG_SYS_MMCSD_FS_BOOT_PARTITION,
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500277 filename);
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200278 if (!err)
279 return err;
280#endif
281#endif
282
Tien Fong Chee6091dd12019-01-23 14:20:05 +0800283#if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200284 err = -ENOENT;
285#endif
286
287 return err;
288}
289#else
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500290static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, struct mmc *mmc,
291 const char *filename)
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200292{
293 return -ENOSYS;
294}
295#endif
296
Lukasz Majewski7c88d102018-02-03 08:29:52 +0100297u32 __weak spl_boot_mode(const u32 boot_device)
298{
Tien Fong Chee6091dd12019-01-23 14:20:05 +0800299#if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4)
Lukasz Majewski7c88d102018-02-03 08:29:52 +0100300 return MMCSD_MODE_FS;
301#elif defined(CONFIG_SUPPORT_EMMC_BOOT)
302 return MMCSD_MODE_EMMCBOOT;
303#else
304 return MMCSD_MODE_RAW;
305#endif
306}
307
Patrick Delaunay113aa502018-03-20 10:54:51 +0100308#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
309__weak
310int spl_boot_partition(const u32 boot_device)
311{
312 return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION;
313}
314#endif
315
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500316int spl_mmc_load(struct spl_image_info *spl_image,
317 struct spl_boot_device *bootdev,
318 const char *filename,
319 int raw_part,
320 unsigned long raw_sect)
Simon Schwarze21d2d82011-09-14 15:33:34 -0400321{
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500322 static struct mmc *mmc;
Simon Schwarze21d2d82011-09-14 15:33:34 -0400323 u32 boot_mode;
Simon Glassf22851a2015-06-23 15:38:51 -0600324 int err = 0;
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200325 __maybe_unused int part;
Simon Schwarze21d2d82011-09-14 15:33:34 -0400326
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500327 /* Perform peripheral init only once */
328 if (!mmc) {
329 err = spl_mmc_find_device(&mmc, bootdev->boot_device);
330 if (err)
331 return err;
Simon Schwarze21d2d82011-09-14 15:33:34 -0400332
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500333 err = mmc_init(mmc);
334 if (err) {
335 mmc = NULL;
Paul Burtona8015fd2013-09-04 16:12:24 +0100336#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500337 printf("spl: mmc init failed with error: %d\n", err);
Paul Burtona8015fd2013-09-04 16:12:24 +0100338#endif
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500339 return err;
340 }
Simon Schwarze21d2d82011-09-14 15:33:34 -0400341 }
Peter Korsgaard5e5483d2013-05-13 08:36:25 +0000342
Simon Glassc0b6c9b2016-09-24 18:19:57 -0600343 boot_mode = spl_boot_mode(bootdev->boot_device);
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200344 err = -EINVAL;
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200345 switch (boot_mode) {
Nikita Kiryanov2b3ae5f2015-11-08 17:11:48 +0200346 case MMCSD_MODE_EMMCBOOT:
347 /*
348 * We need to check what the partition is configured to.
349 * 1 and 2 match up to boot0 / boot1 and 7 is user data
350 * which is the first physical partition (0).
351 */
352 part = (mmc->part_config >> 3) & PART_ACCESS_MASK;
353
354 if (part == 7)
355 part = 0;
356
Marek Vasutf537e392016-12-01 02:06:33 +0100357 if (CONFIG_IS_ENABLED(MMC_TINY))
358 err = mmc_switch_part(mmc, part);
359 else
360 err = blk_dselect_hwpart(mmc_get_blk_desc(mmc), part);
361
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200362 if (err) {
Nikita Kiryanov2b3ae5f2015-11-08 17:11:48 +0200363#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
364 puts("spl: mmc partition switch failed\n");
365#endif
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200366 return err;
Nikita Kiryanov2b3ae5f2015-11-08 17:11:48 +0200367 }
368 /* Fall through */
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200369 case MMCSD_MODE_RAW:
370 debug("spl: mmc boot mode: raw\n");
371
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200372 if (!spl_start_uboot()) {
Simon Glassee306792016-09-24 18:20:13 -0600373 err = mmc_load_image_raw_os(spl_image, mmc);
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200374 if (!err)
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200375 return err;
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200376 }
Dalon Westergreenf5ba9852017-02-10 17:15:35 -0800377#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500378 err = mmc_load_image_raw_partition(spl_image, mmc, raw_part,
379 raw_sect);
Paul Kocialkowski4bd66e72015-06-08 23:05:09 +0200380 if (!err)
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200381 return err;
Dalon Westergreenf5ba9852017-02-10 17:15:35 -0800382#endif
Semen Protsenko7e3ba482016-11-16 19:19:05 +0200383#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500384 err = mmc_load_image_raw_sector(spl_image, mmc, raw_sect);
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200385 if (!err)
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200386 return err;
Paul Kocialkowski4bd66e72015-06-08 23:05:09 +0200387#endif
Guillaume GARDET834dd882016-02-18 18:17:36 +0100388 /* If RAW mode fails, try FS mode. */
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200389 case MMCSD_MODE_FS:
390 debug("spl: mmc boot mode: fs\n");
391
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500392 err = spl_mmc_do_fs_boot(spl_image, mmc, filename);
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200393 if (!err)
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200394 return err;
Nikita Kiryanov642648c2015-11-08 17:11:47 +0200395
Nikita Kiryanoved52f4d2015-11-08 17:11:43 +0200396 break;
Paul Burtona8015fd2013-09-04 16:12:24 +0100397#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
Nikita Kiryanoved52f4d2015-11-08 17:11:43 +0200398 default:
399 puts("spl: mmc: wrong boot mode\n");
Paul Burtona8015fd2013-09-04 16:12:24 +0100400#endif
Paul Kocialkowski0d139722015-04-27 10:20:22 +0200401 }
Nikita Kiryanoved52f4d2015-11-08 17:11:43 +0200402
Nikita Kiryanov33eefe42015-11-08 17:11:49 +0200403 return err;
Simon Schwarze21d2d82011-09-14 15:33:34 -0400404}
Simon Glassd449cb82016-09-24 18:20:00 -0600405
Andreas Dannenberg8d9f7f12019-06-04 17:55:46 -0500406int spl_mmc_load_image(struct spl_image_info *spl_image,
407 struct spl_boot_device *bootdev)
408{
409 return spl_mmc_load(spl_image, bootdev,
410#ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME
411 CONFIG_SPL_FS_LOAD_PAYLOAD_NAME,
412#else
413 NULL,
414#endif
415#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION
416 spl_boot_partition(bootdev->boot_device),
417#else
418 0,
419#endif
420#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR
421 CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR);
422#else
423 0);
424#endif
425}
426
Simon Glass4fc1f252016-11-30 15:30:50 -0700427SPL_LOAD_IMAGE_METHOD("MMC1", 0, BOOT_DEVICE_MMC1, spl_mmc_load_image);
428SPL_LOAD_IMAGE_METHOD("MMC2", 0, BOOT_DEVICE_MMC2, spl_mmc_load_image);
429SPL_LOAD_IMAGE_METHOD("MMC2_2", 0, BOOT_DEVICE_MMC2_2, spl_mmc_load_image);