Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2010 |
| 3 | * Texas Instruments, <www.ti.com> |
| 4 | * |
| 5 | * Aneesh V <aneesh@ti.com> |
| 6 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 8 | */ |
| 9 | #include <common.h> |
Simon Glass | f22851a | 2015-06-23 15:38:51 -0600 | [diff] [blame] | 10 | #include <dm.h> |
Tom Rini | 28591df | 2012-08-13 12:03:19 -0700 | [diff] [blame] | 11 | #include <spl.h> |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 12 | #include <linux/compiler.h> |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 13 | #include <errno.h> |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 14 | #include <asm/u-boot.h> |
Nikita Kiryanov | 022ddb8 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 15 | #include <errno.h> |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 16 | #include <mmc.h> |
Tom Rini | 1530e8a | 2013-06-28 14:43:01 -0400 | [diff] [blame] | 17 | #include <image.h> |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 21 | static int mmc_load_legacy(struct mmc *mmc, ulong sector, |
| 22 | struct image_header *header) |
| 23 | { |
| 24 | u32 image_size_sectors; |
| 25 | unsigned long count; |
| 26 | |
| 27 | spl_parse_image_header(header); |
| 28 | /* convert size to sectors - round up */ |
| 29 | image_size_sectors = (spl_image.size + mmc->read_bl_len - 1) / |
| 30 | mmc->read_bl_len; |
| 31 | |
| 32 | /* Read the header too to avoid extra memcpy */ |
| 33 | count = mmc->block_dev.block_read(&mmc->block_dev, sector, |
| 34 | image_size_sectors, |
| 35 | (void *)(ulong)spl_image.load_addr); |
| 36 | debug("read %x sectors to %x\n", image_size_sectors, |
| 37 | spl_image.load_addr); |
| 38 | if (count != image_size_sectors) |
| 39 | return -EIO; |
| 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | #ifdef CONFIG_SPL_LOAD_FIT |
| 45 | static 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 | |
| 50 | return mmc->block_dev.block_read(&mmc->block_dev, sector, count, buf); |
| 51 | } |
| 52 | #endif |
| 53 | |
Paul Kocialkowski | 17675c8 | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 54 | static int mmc_load_image_raw_sector(struct mmc *mmc, unsigned long sector) |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 55 | { |
Paul Kocialkowski | 2d69f25 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 56 | unsigned long count; |
Peter Korsgaard | f247129 | 2013-03-21 04:55:17 +0000 | [diff] [blame] | 57 | struct image_header *header; |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 58 | int ret = 0; |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 59 | |
| 60 | header = (struct image_header *)(CONFIG_SYS_TEXT_BASE - |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 61 | sizeof(struct image_header)); |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 62 | |
| 63 | /* read image header to find the image size & load address */ |
Stephen Warren | e73f296 | 2015-12-07 11:38:48 -0700 | [diff] [blame] | 64 | count = mmc->block_dev.block_read(&mmc->block_dev, sector, 1, header); |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 65 | debug("hdr read sector %lx, count=%lu\n", sector, count); |
| 66 | if (count == 0) { |
| 67 | ret = -EIO; |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 68 | goto end; |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 69 | } |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 70 | |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 71 | switch (image_get_magic(header)) { |
| 72 | case IH_MAGIC: |
| 73 | ret = mmc_load_legacy(mmc, sector, header); |
| 74 | break; |
| 75 | #ifdef CONFIG_SPL_LOAD_FIT |
| 76 | case FDT_MAGIC: { |
| 77 | struct spl_load_info load; |
| 78 | |
| 79 | debug("Found FIT\n"); |
| 80 | load.dev = mmc; |
| 81 | load.priv = NULL; |
| 82 | load.bl_len = mmc->read_bl_len; |
| 83 | load.read = h_spl_load_read; |
| 84 | ret = spl_load_simple_fit(&load, sector, header); |
| 85 | break; |
| 86 | } |
| 87 | #endif |
| 88 | default: |
Simon Glass | 5614db8 | 2015-06-23 15:38:47 -0600 | [diff] [blame] | 89 | puts("bad magic\n"); |
Tom Rini | 1530e8a | 2013-06-28 14:43:01 -0400 | [diff] [blame] | 90 | return -1; |
Simon Glass | 5614db8 | 2015-06-23 15:38:47 -0600 | [diff] [blame] | 91 | } |
Tom Rini | 1530e8a | 2013-06-28 14:43:01 -0400 | [diff] [blame] | 92 | |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 93 | end: |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 94 | if (ret) { |
Paul Burton | a8015fd | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 95 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
Paul Kocialkowski | 01c723f | 2015-06-03 18:48:51 +0200 | [diff] [blame] | 96 | puts("spl: mmc block read error\n"); |
Paul Burton | a8015fd | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 97 | #endif |
Paul Kocialkowski | 2d69f25 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 98 | return -1; |
Paul Kocialkowski | 01c723f | 2015-06-03 18:48:51 +0200 | [diff] [blame] | 99 | } |
Paul Kocialkowski | 2d69f25 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 100 | |
| 101 | return 0; |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 102 | } |
| 103 | |
Nikita Kiryanov | e63b2dd | 2015-11-08 17:11:54 +0200 | [diff] [blame] | 104 | int spl_mmc_get_device_index(u32 boot_device) |
| 105 | { |
| 106 | switch (boot_device) { |
| 107 | case BOOT_DEVICE_MMC1: |
| 108 | return 0; |
| 109 | case BOOT_DEVICE_MMC2: |
| 110 | case BOOT_DEVICE_MMC2_2: |
| 111 | return 1; |
| 112 | } |
| 113 | |
| 114 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
| 115 | printf("spl: unsupported mmc boot device.\n"); |
| 116 | #endif |
| 117 | |
| 118 | return -ENODEV; |
| 119 | } |
| 120 | |
Simon Glass | 4faf63b | 2015-12-02 10:59:12 -0700 | [diff] [blame] | 121 | static int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device) |
Nikita Kiryanov | 022ddb8 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 122 | { |
Simon Glass | 51ace32 | 2015-12-02 10:59:13 -0700 | [diff] [blame] | 123 | #ifdef CONFIG_DM_MMC |
Nikita Kiryanov | 022ddb8 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 124 | struct udevice *dev; |
Simon Glass | 51ace32 | 2015-12-02 10:59:13 -0700 | [diff] [blame] | 125 | #endif |
Nikita Kiryanov | e63b2dd | 2015-11-08 17:11:54 +0200 | [diff] [blame] | 126 | int err, mmc_dev; |
| 127 | |
| 128 | mmc_dev = spl_mmc_get_device_index(boot_device); |
| 129 | if (mmc_dev < 0) |
| 130 | return mmc_dev; |
Nikita Kiryanov | 022ddb8 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 131 | |
| 132 | err = mmc_initialize(NULL); |
| 133 | if (err) { |
| 134 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
| 135 | printf("spl: could not initialize mmc. error: %d\n", err); |
| 136 | #endif |
| 137 | return err; |
| 138 | } |
| 139 | |
Simon Glass | 51ace32 | 2015-12-02 10:59:13 -0700 | [diff] [blame] | 140 | #ifdef CONFIG_DM_MMC |
Nikita Kiryanov | e63b2dd | 2015-11-08 17:11:54 +0200 | [diff] [blame] | 141 | err = uclass_get_device(UCLASS_MMC, mmc_dev, &dev); |
Simon Glass | 51ace32 | 2015-12-02 10:59:13 -0700 | [diff] [blame] | 142 | if (!err) |
| 143 | *mmcp = mmc_get_mmc_dev(dev); |
Nikita Kiryanov | 022ddb8 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 144 | #else |
Simon Glass | 51ace32 | 2015-12-02 10:59:13 -0700 | [diff] [blame] | 145 | *mmcp = find_mmc_device(mmc_dev); |
| 146 | err = *mmcp ? 0 : -ENODEV; |
| 147 | #endif |
Nikita Kiryanov | 022ddb8 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 148 | if (err) { |
| 149 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
Simon Glass | 51ace32 | 2015-12-02 10:59:13 -0700 | [diff] [blame] | 150 | printf("spl: could not find mmc device. error: %d\n", err); |
Nikita Kiryanov | 022ddb8 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 151 | #endif |
| 152 | return err; |
| 153 | } |
| 154 | |
Nikita Kiryanov | 022ddb8 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 155 | return 0; |
| 156 | } |
Nikita Kiryanov | 022ddb8 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 157 | |
Paul Kocialkowski | 17675c8 | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 158 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION |
| 159 | static int mmc_load_image_raw_partition(struct mmc *mmc, int partition) |
| 160 | { |
| 161 | disk_partition_t info; |
Paul Kocialkowski | 2d69f25 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 162 | int err; |
Paul Kocialkowski | 17675c8 | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 163 | |
Simon Glass | b89a844 | 2016-02-29 15:25:48 -0700 | [diff] [blame] | 164 | err = part_get_info(&mmc->block_dev, partition, &info); |
Paul Kocialkowski | 2d69f25 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 165 | if (err) { |
Paul Kocialkowski | 17675c8 | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 166 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
Paul Kocialkowski | 01c723f | 2015-06-03 18:48:51 +0200 | [diff] [blame] | 167 | puts("spl: partition error\n"); |
Paul Kocialkowski | 17675c8 | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 168 | #endif |
| 169 | return -1; |
| 170 | } |
| 171 | |
Stefan Roese | d0503cd | 2015-07-20 11:20:39 +0200 | [diff] [blame] | 172 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR |
| 173 | return mmc_load_image_raw_sector(mmc, info.start + |
| 174 | CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR); |
| 175 | #else |
Paul Kocialkowski | 17675c8 | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 176 | return mmc_load_image_raw_sector(mmc, info.start); |
Stefan Roese | d0503cd | 2015-07-20 11:20:39 +0200 | [diff] [blame] | 177 | #endif |
Paul Kocialkowski | 17675c8 | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 178 | } |
Nikita Kiryanov | 011cd8f | 2015-11-08 17:11:46 +0200 | [diff] [blame] | 179 | #else |
| 180 | #define CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION -1 |
| 181 | static int mmc_load_image_raw_partition(struct mmc *mmc, int partition) |
| 182 | { |
| 183 | return -ENOSYS; |
| 184 | } |
Paul Kocialkowski | 17675c8 | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 185 | #endif |
| 186 | |
Peter Korsgaard | 01b542f | 2013-05-13 08:36:29 +0000 | [diff] [blame] | 187 | #ifdef CONFIG_SPL_OS_BOOT |
| 188 | static int mmc_load_image_raw_os(struct mmc *mmc) |
| 189 | { |
Paul Kocialkowski | 2d69f25 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 190 | unsigned long count; |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 191 | |
Stephen Warren | e73f296 | 2015-12-07 11:38:48 -0700 | [diff] [blame] | 192 | count = mmc->block_dev.block_read(&mmc->block_dev, |
Paul Kocialkowski | 2d69f25 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 193 | CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR, |
| 194 | CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS, |
| 195 | (void *) CONFIG_SYS_SPL_ARGS_ADDR); |
| 196 | if (count == 0) { |
Paul Burton | a8015fd | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 197 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
Paul Kocialkowski | 01c723f | 2015-06-03 18:48:51 +0200 | [diff] [blame] | 198 | puts("spl: mmc block read error\n"); |
Paul Burton | a8015fd | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 199 | #endif |
Peter Korsgaard | 01b542f | 2013-05-13 08:36:29 +0000 | [diff] [blame] | 200 | return -1; |
| 201 | } |
| 202 | |
Paul Kocialkowski | 17675c8 | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 203 | return mmc_load_image_raw_sector(mmc, |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 204 | CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR); |
Peter Korsgaard | 01b542f | 2013-05-13 08:36:29 +0000 | [diff] [blame] | 205 | } |
Nikita Kiryanov | cc49f55 | 2015-11-08 17:11:45 +0200 | [diff] [blame] | 206 | #else |
| 207 | int spl_start_uboot(void) |
| 208 | { |
| 209 | return 1; |
| 210 | } |
| 211 | static int mmc_load_image_raw_os(struct mmc *mmc) |
| 212 | { |
| 213 | return -ENOSYS; |
| 214 | } |
Peter Korsgaard | 01b542f | 2013-05-13 08:36:29 +0000 | [diff] [blame] | 215 | #endif |
| 216 | |
Nikita Kiryanov | 642648c | 2015-11-08 17:11:47 +0200 | [diff] [blame] | 217 | #ifdef CONFIG_SYS_MMCSD_FS_BOOT_PARTITION |
| 218 | int spl_mmc_do_fs_boot(struct mmc *mmc) |
| 219 | { |
| 220 | int err = -ENOSYS; |
| 221 | |
| 222 | #ifdef CONFIG_SPL_FAT_SUPPORT |
| 223 | if (!spl_start_uboot()) { |
| 224 | err = spl_load_image_fat_os(&mmc->block_dev, |
| 225 | CONFIG_SYS_MMCSD_FS_BOOT_PARTITION); |
| 226 | if (!err) |
| 227 | return err; |
| 228 | } |
| 229 | #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME |
| 230 | err = spl_load_image_fat(&mmc->block_dev, |
| 231 | CONFIG_SYS_MMCSD_FS_BOOT_PARTITION, |
| 232 | CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); |
| 233 | if (!err) |
| 234 | return err; |
| 235 | #endif |
| 236 | #endif |
| 237 | #ifdef CONFIG_SPL_EXT_SUPPORT |
| 238 | if (!spl_start_uboot()) { |
| 239 | err = spl_load_image_ext_os(&mmc->block_dev, |
| 240 | CONFIG_SYS_MMCSD_FS_BOOT_PARTITION); |
| 241 | if (!err) |
| 242 | return err; |
| 243 | } |
| 244 | #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME |
| 245 | err = spl_load_image_ext(&mmc->block_dev, |
| 246 | CONFIG_SYS_MMCSD_FS_BOOT_PARTITION, |
| 247 | CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); |
| 248 | if (!err) |
| 249 | return err; |
| 250 | #endif |
| 251 | #endif |
| 252 | |
| 253 | #if defined(CONFIG_SPL_FAT_SUPPORT) || defined(CONFIG_SPL_EXT_SUPPORT) |
| 254 | err = -ENOENT; |
| 255 | #endif |
| 256 | |
| 257 | return err; |
| 258 | } |
| 259 | #else |
| 260 | int spl_mmc_do_fs_boot(struct mmc *mmc) |
| 261 | { |
| 262 | return -ENOSYS; |
| 263 | } |
| 264 | #endif |
| 265 | |
Nikita Kiryanov | e63b2dd | 2015-11-08 17:11:54 +0200 | [diff] [blame] | 266 | int spl_mmc_load_image(u32 boot_device) |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 267 | { |
Simon Glass | a2b771c | 2015-12-02 10:59:11 -0700 | [diff] [blame] | 268 | struct mmc *mmc = NULL; |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 269 | u32 boot_mode; |
Simon Glass | f22851a | 2015-06-23 15:38:51 -0600 | [diff] [blame] | 270 | int err = 0; |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 271 | __maybe_unused int part; |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 272 | |
Nikita Kiryanov | e63b2dd | 2015-11-08 17:11:54 +0200 | [diff] [blame] | 273 | err = spl_mmc_find_device(&mmc, boot_device); |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 274 | if (err) |
| 275 | return err; |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 276 | |
Nikita Kiryanov | 022ddb8 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 277 | err = mmc_init(mmc); |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 278 | if (err) { |
Paul Burton | a8015fd | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 279 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 280 | printf("spl: mmc init failed with error: %d\n", err); |
Paul Burton | a8015fd | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 281 | #endif |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 282 | return err; |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 283 | } |
Peter Korsgaard | 5e5483d | 2013-05-13 08:36:25 +0000 | [diff] [blame] | 284 | |
Tom Rini | a76ff95 | 2012-08-14 09:19:44 -0700 | [diff] [blame] | 285 | boot_mode = spl_boot_mode(); |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 286 | err = -EINVAL; |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 287 | switch (boot_mode) { |
Nikita Kiryanov | 2b3ae5f | 2015-11-08 17:11:48 +0200 | [diff] [blame] | 288 | case MMCSD_MODE_EMMCBOOT: |
| 289 | /* |
| 290 | * We need to check what the partition is configured to. |
| 291 | * 1 and 2 match up to boot0 / boot1 and 7 is user data |
| 292 | * which is the first physical partition (0). |
| 293 | */ |
| 294 | part = (mmc->part_config >> 3) & PART_ACCESS_MASK; |
| 295 | |
| 296 | if (part == 7) |
| 297 | part = 0; |
| 298 | |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 299 | err = mmc_switch_part(0, part); |
| 300 | if (err) { |
Nikita Kiryanov | 2b3ae5f | 2015-11-08 17:11:48 +0200 | [diff] [blame] | 301 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
| 302 | puts("spl: mmc partition switch failed\n"); |
| 303 | #endif |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 304 | return err; |
Nikita Kiryanov | 2b3ae5f | 2015-11-08 17:11:48 +0200 | [diff] [blame] | 305 | } |
| 306 | /* Fall through */ |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 307 | case MMCSD_MODE_RAW: |
| 308 | debug("spl: mmc boot mode: raw\n"); |
| 309 | |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 310 | if (!spl_start_uboot()) { |
| 311 | err = mmc_load_image_raw_os(mmc); |
| 312 | if (!err) |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 313 | return err; |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 314 | } |
Nikita Kiryanov | 011cd8f | 2015-11-08 17:11:46 +0200 | [diff] [blame] | 315 | |
Paul Kocialkowski | 17675c8 | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 316 | err = mmc_load_image_raw_partition(mmc, |
| 317 | CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION); |
Paul Kocialkowski | 4bd66e7 | 2015-06-08 23:05:09 +0200 | [diff] [blame] | 318 | if (!err) |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 319 | return err; |
Nikita Kiryanov | 011cd8f | 2015-11-08 17:11:46 +0200 | [diff] [blame] | 320 | #if defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR) |
Paul Kocialkowski | 17675c8 | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 321 | err = mmc_load_image_raw_sector(mmc, |
Dan Murphy | b7b5b0c | 2014-01-16 11:23:29 -0600 | [diff] [blame] | 322 | CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR); |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 323 | if (!err) |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 324 | return err; |
Paul Kocialkowski | 4bd66e7 | 2015-06-08 23:05:09 +0200 | [diff] [blame] | 325 | #endif |
Guillaume GARDET | 834dd88 | 2016-02-18 18:17:36 +0100 | [diff] [blame] | 326 | /* If RAW mode fails, try FS mode. */ |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 327 | case MMCSD_MODE_FS: |
| 328 | debug("spl: mmc boot mode: fs\n"); |
| 329 | |
Nikita Kiryanov | 642648c | 2015-11-08 17:11:47 +0200 | [diff] [blame] | 330 | err = spl_mmc_do_fs_boot(mmc); |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 331 | if (!err) |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 332 | return err; |
Nikita Kiryanov | 642648c | 2015-11-08 17:11:47 +0200 | [diff] [blame] | 333 | |
Nikita Kiryanov | ed52f4d | 2015-11-08 17:11:43 +0200 | [diff] [blame] | 334 | break; |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 335 | case MMCSD_MODE_UNDEFINED: |
Paul Burton | a8015fd | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 336 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
Nikita Kiryanov | ed52f4d | 2015-11-08 17:11:43 +0200 | [diff] [blame] | 337 | default: |
| 338 | puts("spl: mmc: wrong boot mode\n"); |
Paul Burton | a8015fd | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 339 | #endif |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 340 | } |
Nikita Kiryanov | ed52f4d | 2015-11-08 17:11:43 +0200 | [diff] [blame] | 341 | |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 342 | return err; |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 343 | } |