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