Simon Schwarz | 9ea5c6e | 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 | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 8 | */ |
| 9 | #include <common.h> |
Simon Glass | dc3dedf | 2015-06-23 15:38:51 -0600 | [diff] [blame] | 10 | #include <dm.h> |
Tom Rini | 47f7bca | 2012-08-13 12:03:19 -0700 | [diff] [blame] | 11 | #include <spl.h> |
Paul Kocialkowski | 91199f4 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 12 | #include <linux/compiler.h> |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 13 | #include <errno.h> |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 14 | #include <asm/u-boot.h> |
Nikita Kiryanov | 4188ba3 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 15 | #include <errno.h> |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 16 | #include <mmc.h> |
Tom Rini | e4c444b | 2013-06-28 14:43:01 -0400 | [diff] [blame] | 17 | #include <image.h> |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
Paul Kocialkowski | b97300b | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 21 | static int mmc_load_image_raw_sector(struct mmc *mmc, unsigned long sector) |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 22 | { |
Paul Kocialkowski | 3bc37b6 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 23 | unsigned long count; |
Peter Korsgaard | 2e22210 | 2013-03-21 04:55:17 +0000 | [diff] [blame] | 24 | u32 image_size_sectors; |
| 25 | struct image_header *header; |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 26 | |
| 27 | header = (struct image_header *)(CONFIG_SYS_TEXT_BASE - |
Paul Kocialkowski | 91199f4 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 28 | sizeof(struct image_header)); |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 29 | |
| 30 | /* read image header to find the image size & load address */ |
Stephen Warren | 7c4213f | 2015-12-07 11:38:48 -0700 | [diff] [blame] | 31 | count = mmc->block_dev.block_read(&mmc->block_dev, sector, 1, header); |
Simon Glass | fdfa39d | 2015-06-23 15:38:47 -0600 | [diff] [blame] | 32 | debug("read sector %lx, count=%lu\n", sector, count); |
Paul Kocialkowski | 3bc37b6 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 33 | if (count == 0) |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 34 | goto end; |
| 35 | |
Simon Glass | fdfa39d | 2015-06-23 15:38:47 -0600 | [diff] [blame] | 36 | if (image_get_magic(header) != IH_MAGIC) { |
| 37 | puts("bad magic\n"); |
Tom Rini | e4c444b | 2013-06-28 14:43:01 -0400 | [diff] [blame] | 38 | return -1; |
Simon Glass | fdfa39d | 2015-06-23 15:38:47 -0600 | [diff] [blame] | 39 | } |
Tom Rini | e4c444b | 2013-06-28 14:43:01 -0400 | [diff] [blame] | 40 | |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 41 | spl_parse_image_header(header); |
| 42 | |
| 43 | /* convert size to sectors - round up */ |
Tom Rini | f088125 | 2012-08-14 10:25:15 -0700 | [diff] [blame] | 44 | image_size_sectors = (spl_image.size + mmc->read_bl_len - 1) / |
Paul Kocialkowski | 91199f4 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 45 | mmc->read_bl_len; |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 46 | |
| 47 | /* Read the header too to avoid extra memcpy */ |
Stephen Warren | 7c4213f | 2015-12-07 11:38:48 -0700 | [diff] [blame] | 48 | count = mmc->block_dev.block_read(&mmc->block_dev, sector, |
| 49 | image_size_sectors, |
Gong Qianyu | 7ef4c45 | 2015-07-30 14:07:12 +0800 | [diff] [blame] | 50 | (void *)(ulong)spl_image.load_addr); |
Simon Glass | fdfa39d | 2015-06-23 15:38:47 -0600 | [diff] [blame] | 51 | debug("read %x sectors to %x\n", image_size_sectors, |
| 52 | spl_image.load_addr); |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 53 | |
| 54 | end: |
Paul Kocialkowski | 1ec2646 | 2015-06-03 18:48:51 +0200 | [diff] [blame] | 55 | if (count == 0) { |
Paul Burton | 8112f5f | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 56 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
Paul Kocialkowski | 1ec2646 | 2015-06-03 18:48:51 +0200 | [diff] [blame] | 57 | puts("spl: mmc block read error\n"); |
Paul Burton | 8112f5f | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 58 | #endif |
Paul Kocialkowski | 3bc37b6 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 59 | return -1; |
Paul Kocialkowski | 1ec2646 | 2015-06-03 18:48:51 +0200 | [diff] [blame] | 60 | } |
Paul Kocialkowski | 3bc37b6 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 61 | |
| 62 | return 0; |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 63 | } |
| 64 | |
Nikita Kiryanov | a1e56cf | 2015-11-08 17:11:54 +0200 | [diff] [blame] | 65 | int spl_mmc_get_device_index(u32 boot_device) |
| 66 | { |
| 67 | switch (boot_device) { |
| 68 | case BOOT_DEVICE_MMC1: |
| 69 | return 0; |
| 70 | case BOOT_DEVICE_MMC2: |
| 71 | case BOOT_DEVICE_MMC2_2: |
| 72 | return 1; |
| 73 | } |
| 74 | |
| 75 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
| 76 | printf("spl: unsupported mmc boot device.\n"); |
| 77 | #endif |
| 78 | |
| 79 | return -ENODEV; |
| 80 | } |
| 81 | |
Simon Glass | 99c7a51 | 2015-12-02 10:59:12 -0700 | [diff] [blame] | 82 | static int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device) |
Nikita Kiryanov | 4188ba3 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 83 | { |
Simon Glass | b4857aa | 2015-12-02 10:59:13 -0700 | [diff] [blame] | 84 | #ifdef CONFIG_DM_MMC |
Nikita Kiryanov | 4188ba3 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 85 | struct udevice *dev; |
Simon Glass | b4857aa | 2015-12-02 10:59:13 -0700 | [diff] [blame] | 86 | #endif |
Nikita Kiryanov | a1e56cf | 2015-11-08 17:11:54 +0200 | [diff] [blame] | 87 | int err, mmc_dev; |
| 88 | |
| 89 | mmc_dev = spl_mmc_get_device_index(boot_device); |
| 90 | if (mmc_dev < 0) |
| 91 | return mmc_dev; |
Nikita Kiryanov | 4188ba3 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 92 | |
| 93 | err = mmc_initialize(NULL); |
| 94 | if (err) { |
| 95 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
| 96 | printf("spl: could not initialize mmc. error: %d\n", err); |
| 97 | #endif |
| 98 | return err; |
| 99 | } |
| 100 | |
Simon Glass | b4857aa | 2015-12-02 10:59:13 -0700 | [diff] [blame] | 101 | #ifdef CONFIG_DM_MMC |
Nikita Kiryanov | a1e56cf | 2015-11-08 17:11:54 +0200 | [diff] [blame] | 102 | err = uclass_get_device(UCLASS_MMC, mmc_dev, &dev); |
Simon Glass | b4857aa | 2015-12-02 10:59:13 -0700 | [diff] [blame] | 103 | if (!err) |
| 104 | *mmcp = mmc_get_mmc_dev(dev); |
| 105 | #else |
| 106 | *mmcp = find_mmc_device(mmc_dev); |
| 107 | err = *mmcp ? 0 : -ENODEV; |
| 108 | #endif |
Nikita Kiryanov | 4188ba3 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 109 | if (err) { |
| 110 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
| 111 | printf("spl: could not find mmc device. error: %d\n", err); |
| 112 | #endif |
| 113 | return err; |
| 114 | } |
| 115 | |
Nikita Kiryanov | 4188ba3 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 116 | return 0; |
| 117 | } |
Nikita Kiryanov | 4188ba3 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 118 | |
Paul Kocialkowski | b97300b | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 119 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION |
| 120 | static int mmc_load_image_raw_partition(struct mmc *mmc, int partition) |
| 121 | { |
| 122 | disk_partition_t info; |
Paul Kocialkowski | 3bc37b6 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 123 | int err; |
Paul Kocialkowski | b97300b | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 124 | |
Paul Kocialkowski | 3bc37b6 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 125 | err = get_partition_info(&mmc->block_dev, partition, &info); |
| 126 | if (err) { |
Paul Kocialkowski | b97300b | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 127 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
Paul Kocialkowski | 1ec2646 | 2015-06-03 18:48:51 +0200 | [diff] [blame] | 128 | puts("spl: partition error\n"); |
Paul Kocialkowski | b97300b | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 129 | #endif |
| 130 | return -1; |
| 131 | } |
| 132 | |
Stefan Roese | 4bfcc54 | 2015-07-20 11:20:39 +0200 | [diff] [blame] | 133 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR |
| 134 | return mmc_load_image_raw_sector(mmc, info.start + |
| 135 | CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR); |
| 136 | #else |
Paul Kocialkowski | b97300b | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 137 | return mmc_load_image_raw_sector(mmc, info.start); |
Stefan Roese | 4bfcc54 | 2015-07-20 11:20:39 +0200 | [diff] [blame] | 138 | #endif |
Paul Kocialkowski | b97300b | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 139 | } |
Nikita Kiryanov | d074ebb | 2015-11-08 17:11:46 +0200 | [diff] [blame] | 140 | #else |
| 141 | #define CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION -1 |
| 142 | static int mmc_load_image_raw_partition(struct mmc *mmc, int partition) |
| 143 | { |
| 144 | return -ENOSYS; |
| 145 | } |
Paul Kocialkowski | b97300b | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 146 | #endif |
| 147 | |
Peter Korsgaard | 2b75b0a | 2013-05-13 08:36:29 +0000 | [diff] [blame] | 148 | #ifdef CONFIG_SPL_OS_BOOT |
| 149 | static int mmc_load_image_raw_os(struct mmc *mmc) |
| 150 | { |
Paul Kocialkowski | 3bc37b6 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 151 | unsigned long count; |
Paul Kocialkowski | 91199f4 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 152 | |
Stephen Warren | 7c4213f | 2015-12-07 11:38:48 -0700 | [diff] [blame] | 153 | count = mmc->block_dev.block_read(&mmc->block_dev, |
Paul Kocialkowski | 3bc37b6 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 154 | CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR, |
| 155 | CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS, |
| 156 | (void *) CONFIG_SYS_SPL_ARGS_ADDR); |
| 157 | if (count == 0) { |
Paul Burton | 8112f5f | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 158 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
Paul Kocialkowski | 1ec2646 | 2015-06-03 18:48:51 +0200 | [diff] [blame] | 159 | puts("spl: mmc block read error\n"); |
Paul Burton | 8112f5f | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 160 | #endif |
Peter Korsgaard | 2b75b0a | 2013-05-13 08:36:29 +0000 | [diff] [blame] | 161 | return -1; |
| 162 | } |
| 163 | |
Paul Kocialkowski | b97300b | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 164 | return mmc_load_image_raw_sector(mmc, |
Paul Kocialkowski | 91199f4 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 165 | CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR); |
Peter Korsgaard | 2b75b0a | 2013-05-13 08:36:29 +0000 | [diff] [blame] | 166 | } |
Nikita Kiryanov | 339245b | 2015-11-08 17:11:45 +0200 | [diff] [blame] | 167 | #else |
| 168 | int spl_start_uboot(void) |
| 169 | { |
| 170 | return 1; |
| 171 | } |
| 172 | static int mmc_load_image_raw_os(struct mmc *mmc) |
| 173 | { |
| 174 | return -ENOSYS; |
| 175 | } |
Peter Korsgaard | 2b75b0a | 2013-05-13 08:36:29 +0000 | [diff] [blame] | 176 | #endif |
| 177 | |
Nikita Kiryanov | f52b729 | 2015-11-08 17:11:47 +0200 | [diff] [blame] | 178 | #ifdef CONFIG_SYS_MMCSD_FS_BOOT_PARTITION |
| 179 | int spl_mmc_do_fs_boot(struct mmc *mmc) |
| 180 | { |
| 181 | int err = -ENOSYS; |
| 182 | |
| 183 | #ifdef CONFIG_SPL_FAT_SUPPORT |
| 184 | if (!spl_start_uboot()) { |
| 185 | err = spl_load_image_fat_os(&mmc->block_dev, |
| 186 | CONFIG_SYS_MMCSD_FS_BOOT_PARTITION); |
| 187 | if (!err) |
| 188 | return err; |
| 189 | } |
| 190 | #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME |
| 191 | err = spl_load_image_fat(&mmc->block_dev, |
| 192 | CONFIG_SYS_MMCSD_FS_BOOT_PARTITION, |
| 193 | CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); |
| 194 | if (!err) |
| 195 | return err; |
| 196 | #endif |
| 197 | #endif |
| 198 | #ifdef CONFIG_SPL_EXT_SUPPORT |
| 199 | if (!spl_start_uboot()) { |
| 200 | err = spl_load_image_ext_os(&mmc->block_dev, |
| 201 | CONFIG_SYS_MMCSD_FS_BOOT_PARTITION); |
| 202 | if (!err) |
| 203 | return err; |
| 204 | } |
| 205 | #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME |
| 206 | err = spl_load_image_ext(&mmc->block_dev, |
| 207 | CONFIG_SYS_MMCSD_FS_BOOT_PARTITION, |
| 208 | CONFIG_SPL_FS_LOAD_PAYLOAD_NAME); |
| 209 | if (!err) |
| 210 | return err; |
| 211 | #endif |
| 212 | #endif |
| 213 | |
| 214 | #if defined(CONFIG_SPL_FAT_SUPPORT) || defined(CONFIG_SPL_EXT_SUPPORT) |
| 215 | err = -ENOENT; |
| 216 | #endif |
| 217 | |
| 218 | return err; |
| 219 | } |
| 220 | #else |
| 221 | int spl_mmc_do_fs_boot(struct mmc *mmc) |
| 222 | { |
| 223 | return -ENOSYS; |
| 224 | } |
| 225 | #endif |
| 226 | |
Nikita Kiryanov | a1e56cf | 2015-11-08 17:11:54 +0200 | [diff] [blame] | 227 | int spl_mmc_load_image(u32 boot_device) |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 228 | { |
Simon Glass | d773a00 | 2015-12-02 10:59:11 -0700 | [diff] [blame] | 229 | struct mmc *mmc = NULL; |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 230 | u32 boot_mode; |
Simon Glass | dc3dedf | 2015-06-23 15:38:51 -0600 | [diff] [blame] | 231 | int err = 0; |
Paul Kocialkowski | 91199f4 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 232 | __maybe_unused int part; |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 233 | |
Nikita Kiryanov | a1e56cf | 2015-11-08 17:11:54 +0200 | [diff] [blame] | 234 | err = spl_mmc_find_device(&mmc, boot_device); |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 235 | if (err) |
| 236 | return err; |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 237 | |
Nikita Kiryanov | 4188ba3 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 238 | err = mmc_init(mmc); |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 239 | if (err) { |
Paul Burton | 8112f5f | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 240 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
Paul Kocialkowski | 91199f4 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 241 | printf("spl: mmc init failed with error: %d\n", err); |
Paul Burton | 8112f5f | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 242 | #endif |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 243 | return err; |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 244 | } |
Peter Korsgaard | 79adb7a | 2013-05-13 08:36:25 +0000 | [diff] [blame] | 245 | |
Tom Rini | 37189a1 | 2012-08-14 09:19:44 -0700 | [diff] [blame] | 246 | boot_mode = spl_boot_mode(); |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 247 | err = -EINVAL; |
Paul Kocialkowski | 91199f4 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 248 | switch (boot_mode) { |
Nikita Kiryanov | 83cdf6f | 2015-11-08 17:11:48 +0200 | [diff] [blame] | 249 | case MMCSD_MODE_EMMCBOOT: |
| 250 | /* |
| 251 | * We need to check what the partition is configured to. |
| 252 | * 1 and 2 match up to boot0 / boot1 and 7 is user data |
| 253 | * which is the first physical partition (0). |
| 254 | */ |
| 255 | part = (mmc->part_config >> 3) & PART_ACCESS_MASK; |
| 256 | |
| 257 | if (part == 7) |
| 258 | part = 0; |
| 259 | |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 260 | err = mmc_switch_part(0, part); |
| 261 | if (err) { |
Nikita Kiryanov | 83cdf6f | 2015-11-08 17:11:48 +0200 | [diff] [blame] | 262 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
| 263 | puts("spl: mmc partition switch failed\n"); |
| 264 | #endif |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 265 | return err; |
Nikita Kiryanov | 83cdf6f | 2015-11-08 17:11:48 +0200 | [diff] [blame] | 266 | } |
| 267 | /* Fall through */ |
Paul Kocialkowski | 91199f4 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 268 | case MMCSD_MODE_RAW: |
| 269 | debug("spl: mmc boot mode: raw\n"); |
| 270 | |
Paul Kocialkowski | 91199f4 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 271 | if (!spl_start_uboot()) { |
| 272 | err = mmc_load_image_raw_os(mmc); |
| 273 | if (!err) |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 274 | return err; |
Paul Kocialkowski | 91199f4 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 275 | } |
Nikita Kiryanov | d074ebb | 2015-11-08 17:11:46 +0200 | [diff] [blame] | 276 | |
Paul Kocialkowski | b97300b | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 277 | err = mmc_load_image_raw_partition(mmc, |
| 278 | CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION); |
Paul Kocialkowski | 91199f4 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 279 | if (!err) |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 280 | return err; |
Nikita Kiryanov | d074ebb | 2015-11-08 17:11:46 +0200 | [diff] [blame] | 281 | #if defined(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR) |
Paul Kocialkowski | 3ae8f4c | 2015-06-08 23:05:09 +0200 | [diff] [blame] | 282 | err = mmc_load_image_raw_sector(mmc, |
| 283 | CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR); |
| 284 | if (!err) |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 285 | return err; |
Paul Kocialkowski | 3ae8f4c | 2015-06-08 23:05:09 +0200 | [diff] [blame] | 286 | #endif |
Guillaume GARDET | 86a0df7 | 2016-02-18 18:17:36 +0100 | [diff] [blame] | 287 | /* If RAW mode fails, try FS mode. */ |
Paul Kocialkowski | 91199f4 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 288 | case MMCSD_MODE_FS: |
| 289 | debug("spl: mmc boot mode: fs\n"); |
| 290 | |
Nikita Kiryanov | f52b729 | 2015-11-08 17:11:47 +0200 | [diff] [blame] | 291 | err = spl_mmc_do_fs_boot(mmc); |
Paul Kocialkowski | 91199f4 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 292 | if (!err) |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 293 | return err; |
Nikita Kiryanov | f52b729 | 2015-11-08 17:11:47 +0200 | [diff] [blame] | 294 | |
Nikita Kiryanov | fd61d39 | 2015-11-08 17:11:43 +0200 | [diff] [blame] | 295 | break; |
Paul Kocialkowski | 91199f4 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 296 | case MMCSD_MODE_UNDEFINED: |
Guillaume GARDET | 2c84c9a | 2014-12-16 12:00:44 +0100 | [diff] [blame] | 297 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
Nikita Kiryanov | fd61d39 | 2015-11-08 17:11:43 +0200 | [diff] [blame] | 298 | default: |
| 299 | puts("spl: mmc: wrong boot mode\n"); |
Guillaume GARDET | 2c84c9a | 2014-12-16 12:00:44 +0100 | [diff] [blame] | 300 | #endif |
Paul Kocialkowski | 91199f4 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 301 | } |
Nikita Kiryanov | fd61d39 | 2015-11-08 17:11:43 +0200 | [diff] [blame] | 302 | |
Nikita Kiryanov | 36afd45 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 303 | return err; |
Simon Schwarz | 9ea5c6e | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 304 | } |