Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2010 |
| 4 | * Texas Instruments, <www.ti.com> |
| 5 | * |
| 6 | * Aneesh V <aneesh@ti.com> |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 7 | */ |
| 8 | #include <common.h> |
Simon Glass | f22851a | 2015-06-23 15:38:51 -0600 | [diff] [blame] | 9 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Sean Anderson | 5ff7772 | 2023-10-14 16:47:55 -0400 | [diff] [blame] | 11 | #include <mapmem.h> |
Simon Glass | 655306c | 2020-05-10 11:39:58 -0600 | [diff] [blame] | 12 | #include <part.h> |
Tom Rini | 28591df | 2012-08-13 12:03:19 -0700 | [diff] [blame] | 13 | #include <spl.h> |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 14 | #include <linux/compiler.h> |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 15 | #include <errno.h> |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 16 | #include <asm/u-boot.h> |
Nikita Kiryanov | 022ddb8 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 17 | #include <errno.h> |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 18 | #include <mmc.h> |
Tom Rini | 1530e8a | 2013-06-28 14:43:01 -0400 | [diff] [blame] | 19 | #include <image.h> |
Sean Anderson | 952ed67 | 2023-10-14 16:47:44 -0400 | [diff] [blame] | 20 | #include <imx_container.h> |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 21 | |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 22 | static int mmc_load_legacy(struct spl_image_info *spl_image, |
| 23 | struct spl_boot_device *bootdev, |
| 24 | struct mmc *mmc, |
Simon Glass | bb7d3bb | 2022-09-06 20:26:52 -0600 | [diff] [blame] | 25 | ulong sector, struct legacy_img_hdr *header) |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 26 | { |
Pali Rohár | 1104167 | 2021-07-23 11:14:27 +0200 | [diff] [blame] | 27 | u32 image_offset_sectors; |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 28 | u32 image_size_sectors; |
| 29 | unsigned long count; |
Pali Rohár | 1104167 | 2021-07-23 11:14:27 +0200 | [diff] [blame] | 30 | u32 image_offset; |
Marek Vasut | 02266e2 | 2016-04-29 00:44:54 +0200 | [diff] [blame] | 31 | int ret; |
| 32 | |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 33 | ret = spl_parse_image_header(spl_image, bootdev, header); |
Marek Vasut | 02266e2 | 2016-04-29 00:44:54 +0200 | [diff] [blame] | 34 | if (ret) |
| 35 | return ret; |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 36 | |
Pali Rohár | 1104167 | 2021-07-23 11:14:27 +0200 | [diff] [blame] | 37 | /* convert offset to sectors - round down */ |
| 38 | image_offset_sectors = spl_image->offset / mmc->read_bl_len; |
| 39 | /* calculate remaining offset */ |
| 40 | image_offset = spl_image->offset % mmc->read_bl_len; |
| 41 | |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 42 | /* convert size to sectors - round up */ |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 43 | image_size_sectors = (spl_image->size + mmc->read_bl_len - 1) / |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 44 | mmc->read_bl_len; |
| 45 | |
| 46 | /* Read the header too to avoid extra memcpy */ |
Pali Rohár | 1104167 | 2021-07-23 11:14:27 +0200 | [diff] [blame] | 47 | count = blk_dread(mmc_get_blk_desc(mmc), |
| 48 | sector + image_offset_sectors, |
| 49 | image_size_sectors, |
Sean Anderson | 5ff7772 | 2023-10-14 16:47:55 -0400 | [diff] [blame] | 50 | map_sysmem(spl_image->load_addr, |
| 51 | image_size_sectors * mmc->read_bl_len)); |
Andre Przywara | 6c52607 | 2017-01-02 11:48:31 +0000 | [diff] [blame] | 52 | debug("read %x sectors to %lx\n", image_size_sectors, |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 53 | spl_image->load_addr); |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 54 | if (count != image_size_sectors) |
| 55 | return -EIO; |
| 56 | |
Pali Rohár | 1104167 | 2021-07-23 11:14:27 +0200 | [diff] [blame] | 57 | if (image_offset) |
| 58 | memmove((void *)(ulong)spl_image->load_addr, |
| 59 | (void *)(ulong)spl_image->load_addr + image_offset, |
| 60 | spl_image->size); |
| 61 | |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 62 | return 0; |
| 63 | } |
| 64 | |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 65 | static ulong h_spl_load_read(struct spl_load_info *load, ulong sector, |
| 66 | ulong count, void *buf) |
| 67 | { |
| 68 | struct mmc *mmc = load->dev; |
| 69 | |
Simon Glass | 670d304 | 2016-05-14 14:03:06 -0600 | [diff] [blame] | 70 | return blk_dread(mmc_get_blk_desc(mmc), sector, count, buf); |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 71 | } |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 72 | |
Baruch Siach | fef81be | 2020-01-15 09:08:08 +0200 | [diff] [blame] | 73 | static __maybe_unused unsigned long spl_mmc_raw_uboot_offset(int part) |
| 74 | { |
| 75 | #if IS_ENABLED(CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR) |
| 76 | if (part == 0) |
| 77 | return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_DATA_PART_OFFSET; |
| 78 | #endif |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
Seung-Woo Kim | c0a4e2d | 2017-09-19 13:29:45 +0900 | [diff] [blame] | 83 | static __maybe_unused |
| 84 | int mmc_load_image_raw_sector(struct spl_image_info *spl_image, |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 85 | struct spl_boot_device *bootdev, |
Seung-Woo Kim | c0a4e2d | 2017-09-19 13:29:45 +0900 | [diff] [blame] | 86 | struct mmc *mmc, unsigned long sector) |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 87 | { |
Paul Kocialkowski | 2d69f25 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 88 | unsigned long count; |
Simon Glass | bb7d3bb | 2022-09-06 20:26:52 -0600 | [diff] [blame] | 89 | struct legacy_img_hdr *header; |
Marek Vasut | 1dda46f | 2018-08-14 11:27:02 +0200 | [diff] [blame] | 90 | struct blk_desc *bd = mmc_get_blk_desc(mmc); |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 91 | int ret = 0; |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 92 | |
Marek Vasut | 1dda46f | 2018-08-14 11:27:02 +0200 | [diff] [blame] | 93 | header = spl_get_load_buffer(-sizeof(*header), bd->blksz); |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 94 | |
| 95 | /* read image header to find the image size & load address */ |
Marek Vasut | 1dda46f | 2018-08-14 11:27:02 +0200 | [diff] [blame] | 96 | count = blk_dread(bd, sector, 1, header); |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 97 | debug("hdr read sector %lx, count=%lu\n", sector, count); |
| 98 | if (count == 0) { |
| 99 | ret = -EIO; |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 100 | goto end; |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 101 | } |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 102 | |
Masahiro Yamada | 802f1c3 | 2016-03-16 12:10:00 +0900 | [diff] [blame] | 103 | if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && |
| 104 | image_get_magic(header) == FDT_MAGIC) { |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 105 | struct spl_load_info load; |
| 106 | |
| 107 | debug("Found FIT\n"); |
| 108 | load.dev = mmc; |
| 109 | load.priv = NULL; |
Lokesh Vutla | f62cef1 | 2016-05-24 10:34:38 +0530 | [diff] [blame] | 110 | load.filename = NULL; |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 111 | load.bl_len = mmc->read_bl_len; |
| 112 | load.read = h_spl_load_read; |
Simon Glass | 43a734f | 2016-09-24 18:20:16 -0600 | [diff] [blame] | 113 | ret = spl_load_simple_fit(spl_image, &load, sector, header); |
Sean Anderson | 952ed67 | 2023-10-14 16:47:44 -0400 | [diff] [blame] | 114 | } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) && |
| 115 | valid_container_hdr((void *)header)) { |
Peng Fan | d867076 | 2019-08-22 07:42:38 +0000 | [diff] [blame] | 116 | struct spl_load_info load; |
| 117 | |
| 118 | load.dev = mmc; |
| 119 | load.priv = NULL; |
| 120 | load.filename = NULL; |
| 121 | load.bl_len = mmc->read_bl_len; |
| 122 | load.read = h_spl_load_read; |
| 123 | |
| 124 | ret = spl_load_imx_container(spl_image, &load, sector); |
Masahiro Yamada | 802f1c3 | 2016-03-16 12:10:00 +0900 | [diff] [blame] | 125 | } else { |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 126 | ret = mmc_load_legacy(spl_image, bootdev, mmc, sector, header); |
Simon Glass | 5614db8 | 2015-06-23 15:38:47 -0600 | [diff] [blame] | 127 | } |
Tom Rini | 1530e8a | 2013-06-28 14:43:01 -0400 | [diff] [blame] | 128 | |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 129 | end: |
Simon Glass | b52c7fc | 2016-02-22 22:55:58 -0700 | [diff] [blame] | 130 | if (ret) { |
Paul Burton | a8015fd | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 131 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
Fabio Estevam | 37342ab | 2016-04-20 23:12:04 -0300 | [diff] [blame] | 132 | puts("mmc_load_image_raw_sector: mmc block read error\n"); |
Paul Burton | a8015fd | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 133 | #endif |
Paul Kocialkowski | 2d69f25 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 134 | return -1; |
Paul Kocialkowski | 01c723f | 2015-06-03 18:48:51 +0200 | [diff] [blame] | 135 | } |
Paul Kocialkowski | 2d69f25 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 136 | |
| 137 | return 0; |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 138 | } |
| 139 | |
Masahiro Yamada | 2a4a20c | 2017-06-22 16:52:36 +0900 | [diff] [blame] | 140 | static int spl_mmc_get_device_index(u32 boot_device) |
Nikita Kiryanov | e63b2dd | 2015-11-08 17:11:54 +0200 | [diff] [blame] | 141 | { |
| 142 | switch (boot_device) { |
| 143 | case BOOT_DEVICE_MMC1: |
| 144 | return 0; |
| 145 | case BOOT_DEVICE_MMC2: |
| 146 | case BOOT_DEVICE_MMC2_2: |
| 147 | return 1; |
| 148 | } |
| 149 | |
| 150 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
| 151 | printf("spl: unsupported mmc boot device.\n"); |
| 152 | #endif |
| 153 | |
| 154 | return -ENODEV; |
| 155 | } |
| 156 | |
Simon Glass | 4faf63b | 2015-12-02 10:59:12 -0700 | [diff] [blame] | 157 | static int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device) |
Nikita Kiryanov | 022ddb8 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 158 | { |
Nikita Kiryanov | e63b2dd | 2015-11-08 17:11:54 +0200 | [diff] [blame] | 159 | int err, mmc_dev; |
| 160 | |
| 161 | mmc_dev = spl_mmc_get_device_index(boot_device); |
| 162 | if (mmc_dev < 0) |
| 163 | return mmc_dev; |
Nikita Kiryanov | 022ddb8 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 164 | |
Lokesh Vutla | c59b41c | 2019-09-09 14:40:36 +0530 | [diff] [blame] | 165 | #if CONFIG_IS_ENABLED(DM_MMC) |
| 166 | err = mmc_init_device(mmc_dev); |
| 167 | #else |
Nikita Kiryanov | 022ddb8 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 168 | err = mmc_initialize(NULL); |
Lokesh Vutla | c59b41c | 2019-09-09 14:40:36 +0530 | [diff] [blame] | 169 | #endif /* DM_MMC */ |
Nikita Kiryanov | 022ddb8 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 170 | if (err) { |
| 171 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
| 172 | printf("spl: could not initialize mmc. error: %d\n", err); |
| 173 | #endif |
| 174 | return err; |
| 175 | } |
Simon Glass | 51ace32 | 2015-12-02 10:59:13 -0700 | [diff] [blame] | 176 | *mmcp = find_mmc_device(mmc_dev); |
| 177 | err = *mmcp ? 0 : -ENODEV; |
Nikita Kiryanov | 022ddb8 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 178 | if (err) { |
| 179 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
Alex Kiernan | f5920d0 | 2018-09-18 08:11:55 +0000 | [diff] [blame] | 180 | printf("spl: could not find mmc device %d. error: %d\n", |
| 181 | mmc_dev, err); |
Nikita Kiryanov | 022ddb8 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 182 | #endif |
| 183 | return err; |
| 184 | } |
| 185 | |
Nikita Kiryanov | 022ddb8 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 186 | return 0; |
| 187 | } |
Nikita Kiryanov | 022ddb8 | 2015-11-08 17:11:44 +0200 | [diff] [blame] | 188 | |
Dalon Westergreen | f5ba985 | 2017-02-10 17:15:35 -0800 | [diff] [blame] | 189 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 190 | static int mmc_load_image_raw_partition(struct spl_image_info *spl_image, |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 191 | struct spl_boot_device *bootdev, |
Andreas Dannenberg | 8d9f7f1 | 2019-06-04 17:55:46 -0500 | [diff] [blame] | 192 | struct mmc *mmc, int partition, |
| 193 | unsigned long sector) |
Paul Kocialkowski | 17675c8 | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 194 | { |
Simon Glass | c1c4a8f | 2020-05-10 11:39:57 -0600 | [diff] [blame] | 195 | struct disk_partition info; |
Paul Kocialkowski | 2d69f25 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 196 | int err; |
Paul Kocialkowski | 17675c8 | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 197 | |
Dalon Westergreen | 8d770f4 | 2017-02-10 17:15:34 -0800 | [diff] [blame] | 198 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION_TYPE |
| 199 | int type_part; |
| 200 | /* Only support MBR so DOS_ENTRY_NUMBERS */ |
| 201 | for (type_part = 1; type_part <= DOS_ENTRY_NUMBERS; type_part++) { |
| 202 | err = part_get_info(mmc_get_blk_desc(mmc), type_part, &info); |
| 203 | if (err) |
| 204 | continue; |
Wolfgang Denk | 9d328a6 | 2021-09-27 17:42:38 +0200 | [diff] [blame] | 205 | if (info.sys_ind == |
Dalon Westergreen | 8d770f4 | 2017-02-10 17:15:34 -0800 | [diff] [blame] | 206 | CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION_TYPE) { |
| 207 | partition = type_part; |
| 208 | break; |
| 209 | } |
| 210 | } |
| 211 | #endif |
| 212 | |
Simon Glass | 55877f9 | 2016-07-05 17:10:18 -0600 | [diff] [blame] | 213 | err = part_get_info(mmc_get_blk_desc(mmc), partition, &info); |
Paul Kocialkowski | 2d69f25 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 214 | if (err) { |
Paul Kocialkowski | 17675c8 | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 215 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
Paul Kocialkowski | 01c723f | 2015-06-03 18:48:51 +0200 | [diff] [blame] | 216 | puts("spl: partition error\n"); |
Paul Kocialkowski | 17675c8 | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 217 | #endif |
| 218 | return -1; |
| 219 | } |
| 220 | |
Semen Protsenko | 7e3ba48 | 2016-11-16 19:19:05 +0200 | [diff] [blame] | 221 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 222 | return mmc_load_image_raw_sector(spl_image, bootdev, mmc, info.start + sector); |
Stefan Roese | d0503cd | 2015-07-20 11:20:39 +0200 | [diff] [blame] | 223 | #else |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 224 | return mmc_load_image_raw_sector(spl_image, bootdev, mmc, info.start); |
Stefan Roese | d0503cd | 2015-07-20 11:20:39 +0200 | [diff] [blame] | 225 | #endif |
Paul Kocialkowski | 17675c8 | 2014-11-08 23:14:56 +0100 | [diff] [blame] | 226 | } |
| 227 | #endif |
| 228 | |
Alexandru Gagniuc | 99426c8 | 2021-12-30 10:39:59 -0600 | [diff] [blame] | 229 | #if CONFIG_IS_ENABLED(FALCON_BOOT_MMCSD) |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 230 | static int mmc_load_image_raw_os(struct spl_image_info *spl_image, |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 231 | struct spl_boot_device *bootdev, |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 232 | struct mmc *mmc) |
Peter Korsgaard | 01b542f | 2013-05-13 08:36:29 +0000 | [diff] [blame] | 233 | { |
Lokesh Vutla | 9dee77f | 2016-04-11 15:24:50 +0530 | [diff] [blame] | 234 | int ret; |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 235 | |
Elena Popa | 6532fab | 2023-08-08 16:42:15 +0300 | [diff] [blame] | 236 | #if defined(CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR) |
York Sun | cea8821 | 2018-06-26 09:44:39 -0700 | [diff] [blame] | 237 | unsigned long count; |
| 238 | |
Simon Glass | 70061ba | 2016-06-12 23:30:32 -0600 | [diff] [blame] | 239 | count = blk_dread(mmc_get_blk_desc(mmc), |
Paul Kocialkowski | 2d69f25 | 2015-05-22 12:45:35 +0200 | [diff] [blame] | 240 | CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR, |
| 241 | CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS, |
Simon Glass | 259cdb4 | 2023-09-26 08:14:17 -0600 | [diff] [blame] | 242 | (void *)CONFIG_SPL_PAYLOAD_ARGS_ADDR); |
Tom Rini | 195bc4b | 2017-08-14 21:01:30 -0400 | [diff] [blame] | 243 | if (count != CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTORS) { |
Paul Burton | a8015fd | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 244 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
Fabio Estevam | 37342ab | 2016-04-20 23:12:04 -0300 | [diff] [blame] | 245 | puts("mmc_load_image_raw_os: mmc block read error\n"); |
Paul Burton | a8015fd | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 246 | #endif |
Peter Korsgaard | 01b542f | 2013-05-13 08:36:29 +0000 | [diff] [blame] | 247 | return -1; |
| 248 | } |
York Sun | cea8821 | 2018-06-26 09:44:39 -0700 | [diff] [blame] | 249 | #endif /* CONFIG_SYS_MMCSD_RAW_MODE_ARGS_SECTOR */ |
Peter Korsgaard | 01b542f | 2013-05-13 08:36:29 +0000 | [diff] [blame] | 250 | |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 251 | ret = mmc_load_image_raw_sector(spl_image, bootdev, mmc, |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 252 | CONFIG_SYS_MMCSD_RAW_MODE_KERNEL_SECTOR); |
Lokesh Vutla | 9dee77f | 2016-04-11 15:24:50 +0530 | [diff] [blame] | 253 | if (ret) |
| 254 | return ret; |
| 255 | |
Alexandru Gagniuc | 36fd3ba | 2021-07-15 14:19:23 -0500 | [diff] [blame] | 256 | if (spl_image->os != IH_OS_LINUX && spl_image->os != IH_OS_TEE) { |
Michal Simek | 50fa118 | 2023-05-17 09:17:16 +0200 | [diff] [blame] | 257 | puts("Expected image is not found. Trying to start U-Boot\n"); |
Lokesh Vutla | 9dee77f | 2016-04-11 15:24:50 +0530 | [diff] [blame] | 258 | return -ENOENT; |
| 259 | } |
| 260 | |
| 261 | return 0; |
Peter Korsgaard | 01b542f | 2013-05-13 08:36:29 +0000 | [diff] [blame] | 262 | } |
Nikita Kiryanov | cc49f55 | 2015-11-08 17:11:45 +0200 | [diff] [blame] | 263 | #else |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 264 | static int mmc_load_image_raw_os(struct spl_image_info *spl_image, |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 265 | struct spl_boot_device *bootdev, |
Simon Glass | ee30679 | 2016-09-24 18:20:13 -0600 | [diff] [blame] | 266 | struct mmc *mmc) |
Nikita Kiryanov | cc49f55 | 2015-11-08 17:11:45 +0200 | [diff] [blame] | 267 | { |
| 268 | return -ENOSYS; |
| 269 | } |
Peter Korsgaard | 01b542f | 2013-05-13 08:36:29 +0000 | [diff] [blame] | 270 | #endif |
| 271 | |
Alexandru Gagniuc | 99426c8 | 2021-12-30 10:39:59 -0600 | [diff] [blame] | 272 | #ifndef CONFIG_SPL_OS_BOOT |
| 273 | int spl_start_uboot(void) |
| 274 | { |
| 275 | return 1; |
| 276 | } |
| 277 | #endif |
| 278 | |
Pali Rohár | a081155 | 2023-01-21 15:13:08 +0100 | [diff] [blame] | 279 | #ifdef CONFIG_SYS_MMCSD_FS_BOOT |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 280 | static int spl_mmc_do_fs_boot(struct spl_image_info *spl_image, |
| 281 | struct spl_boot_device *bootdev, |
| 282 | struct mmc *mmc, |
Andreas Dannenberg | 8d9f7f1 | 2019-06-04 17:55:46 -0500 | [diff] [blame] | 283 | const char *filename) |
Nikita Kiryanov | 642648c | 2015-11-08 17:11:47 +0200 | [diff] [blame] | 284 | { |
| 285 | int err = -ENOSYS; |
| 286 | |
Jérôme Carretero | d0a8e59 | 2022-03-15 16:34:51 -0400 | [diff] [blame] | 287 | __maybe_unused int partition = CONFIG_SYS_MMCSD_FS_BOOT_PARTITION; |
| 288 | |
| 289 | #if CONFIG_SYS_MMCSD_FS_BOOT_PARTITION == -1 |
| 290 | { |
| 291 | struct disk_partition info; |
| 292 | debug("Checking for the first MBR bootable partition\n"); |
| 293 | for (int type_part = 1; type_part <= DOS_ENTRY_NUMBERS; type_part++) { |
| 294 | err = part_get_info(mmc_get_blk_desc(mmc), type_part, &info); |
| 295 | if (err) |
| 296 | continue; |
| 297 | debug("Partition %d is of type %d and bootable=%d\n", type_part, info.sys_ind, info.bootable); |
| 298 | if (info.bootable != 0) { |
| 299 | debug("Partition %d is bootable, using it\n", type_part); |
| 300 | partition = type_part; |
| 301 | break; |
| 302 | } |
| 303 | } |
| 304 | printf("Using first bootable partition: %d\n", partition); |
| 305 | if (partition == CONFIG_SYS_MMCSD_FS_BOOT_PARTITION) { |
| 306 | return -ENOSYS; |
| 307 | } |
| 308 | } |
| 309 | #endif |
| 310 | |
Tien Fong Chee | 6fd0a71 | 2019-01-23 14:20:03 +0800 | [diff] [blame] | 311 | #ifdef CONFIG_SPL_FS_FAT |
Nikita Kiryanov | 642648c | 2015-11-08 17:11:47 +0200 | [diff] [blame] | 312 | if (!spl_start_uboot()) { |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 313 | err = spl_load_image_fat_os(spl_image, bootdev, mmc_get_blk_desc(mmc), |
Jérôme Carretero | d0a8e59 | 2022-03-15 16:34:51 -0400 | [diff] [blame] | 314 | partition); |
Nikita Kiryanov | 642648c | 2015-11-08 17:11:47 +0200 | [diff] [blame] | 315 | if (!err) |
| 316 | return err; |
| 317 | } |
| 318 | #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 319 | err = spl_load_image_fat(spl_image, bootdev, mmc_get_blk_desc(mmc), |
Jérôme Carretero | d0a8e59 | 2022-03-15 16:34:51 -0400 | [diff] [blame] | 320 | partition, |
Andreas Dannenberg | 8d9f7f1 | 2019-06-04 17:55:46 -0500 | [diff] [blame] | 321 | filename); |
Nikita Kiryanov | 642648c | 2015-11-08 17:11:47 +0200 | [diff] [blame] | 322 | if (!err) |
| 323 | return err; |
| 324 | #endif |
| 325 | #endif |
Tien Fong Chee | 6091dd1 | 2019-01-23 14:20:05 +0800 | [diff] [blame] | 326 | #ifdef CONFIG_SPL_FS_EXT4 |
Nikita Kiryanov | 642648c | 2015-11-08 17:11:47 +0200 | [diff] [blame] | 327 | if (!spl_start_uboot()) { |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 328 | err = spl_load_image_ext_os(spl_image, bootdev, mmc_get_blk_desc(mmc), |
Jérôme Carretero | d0a8e59 | 2022-03-15 16:34:51 -0400 | [diff] [blame] | 329 | partition); |
Nikita Kiryanov | 642648c | 2015-11-08 17:11:47 +0200 | [diff] [blame] | 330 | if (!err) |
| 331 | return err; |
| 332 | } |
| 333 | #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 334 | err = spl_load_image_ext(spl_image, bootdev, mmc_get_blk_desc(mmc), |
Jérôme Carretero | d0a8e59 | 2022-03-15 16:34:51 -0400 | [diff] [blame] | 335 | partition, |
Andreas Dannenberg | 8d9f7f1 | 2019-06-04 17:55:46 -0500 | [diff] [blame] | 336 | filename); |
Nikita Kiryanov | 642648c | 2015-11-08 17:11:47 +0200 | [diff] [blame] | 337 | if (!err) |
| 338 | return err; |
| 339 | #endif |
| 340 | #endif |
| 341 | |
Tien Fong Chee | 6091dd1 | 2019-01-23 14:20:05 +0800 | [diff] [blame] | 342 | #if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4) |
Nikita Kiryanov | 642648c | 2015-11-08 17:11:47 +0200 | [diff] [blame] | 343 | err = -ENOENT; |
| 344 | #endif |
| 345 | |
| 346 | return err; |
| 347 | } |
Nikita Kiryanov | 642648c | 2015-11-08 17:11:47 +0200 | [diff] [blame] | 348 | #endif |
| 349 | |
Andre Przywara | 3cb12ef | 2021-07-12 11:06:49 +0100 | [diff] [blame] | 350 | u32 __weak spl_mmc_boot_mode(struct mmc *mmc, const u32 boot_device) |
Lukasz Majewski | 7c88d10 | 2018-02-03 08:29:52 +0100 | [diff] [blame] | 351 | { |
Tien Fong Chee | 6091dd1 | 2019-01-23 14:20:05 +0800 | [diff] [blame] | 352 | #if defined(CONFIG_SPL_FS_FAT) || defined(CONFIG_SPL_FS_EXT4) |
Lukasz Majewski | 7c88d10 | 2018-02-03 08:29:52 +0100 | [diff] [blame] | 353 | return MMCSD_MODE_FS; |
| 354 | #elif defined(CONFIG_SUPPORT_EMMC_BOOT) |
| 355 | return MMCSD_MODE_EMMCBOOT; |
| 356 | #else |
| 357 | return MMCSD_MODE_RAW; |
| 358 | #endif |
| 359 | } |
| 360 | |
Patrick Delaunay | 113aa50 | 2018-03-20 10:54:51 +0100 | [diff] [blame] | 361 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION |
Harald Seiler | bf16c30 | 2020-04-15 11:33:31 +0200 | [diff] [blame] | 362 | int __weak spl_mmc_boot_partition(const u32 boot_device) |
Patrick Delaunay | 113aa50 | 2018-03-20 10:54:51 +0100 | [diff] [blame] | 363 | { |
| 364 | return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION; |
| 365 | } |
| 366 | #endif |
| 367 | |
Marek Vasut | f9a921e | 2023-10-16 18:16:12 +0200 | [diff] [blame] | 368 | unsigned long __weak arch_spl_mmc_get_uboot_raw_sector(struct mmc *mmc, |
| 369 | unsigned long raw_sect) |
| 370 | { |
| 371 | return raw_sect; |
| 372 | } |
| 373 | |
| 374 | unsigned long __weak board_spl_mmc_get_uboot_raw_sector(struct mmc *mmc, |
| 375 | unsigned long raw_sect) |
| 376 | { |
| 377 | return arch_spl_mmc_get_uboot_raw_sector(mmc, raw_sect); |
| 378 | } |
| 379 | |
Faiz Abbas | 0bdf563 | 2020-02-26 13:44:35 +0530 | [diff] [blame] | 380 | unsigned long __weak spl_mmc_get_uboot_raw_sector(struct mmc *mmc, |
| 381 | unsigned long raw_sect) |
Peng Fan | 315cf59 | 2019-09-23 10:18:40 +0800 | [diff] [blame] | 382 | { |
Marek Vasut | f9a921e | 2023-10-16 18:16:12 +0200 | [diff] [blame] | 383 | return board_spl_mmc_get_uboot_raw_sector(mmc, raw_sect); |
Peng Fan | 315cf59 | 2019-09-23 10:18:40 +0800 | [diff] [blame] | 384 | } |
| 385 | |
Marek Vasut | de1ce23 | 2021-07-03 04:55:32 +0200 | [diff] [blame] | 386 | int default_spl_mmc_emmc_boot_partition(struct mmc *mmc) |
| 387 | { |
| 388 | int part; |
| 389 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_EMMC_BOOT_PARTITION |
| 390 | part = CONFIG_SYS_MMCSD_RAW_MODE_EMMC_BOOT_PARTITION; |
| 391 | #else |
| 392 | /* |
| 393 | * We need to check what the partition is configured to. |
| 394 | * 1 and 2 match up to boot0 / boot1 and 7 is user data |
| 395 | * which is the first physical partition (0). |
| 396 | */ |
Pali Rohár | eafdbe5 | 2023-03-11 11:44:27 +0100 | [diff] [blame] | 397 | part = EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config); |
Marek Vasut | de1ce23 | 2021-07-03 04:55:32 +0200 | [diff] [blame] | 398 | if (part == 7) |
| 399 | part = 0; |
| 400 | #endif |
| 401 | return part; |
| 402 | } |
| 403 | |
| 404 | int __weak spl_mmc_emmc_boot_partition(struct mmc *mmc) |
| 405 | { |
| 406 | return default_spl_mmc_emmc_boot_partition(mmc); |
| 407 | } |
| 408 | |
Harald Seiler | af8b7b7 | 2022-07-11 14:35:32 +0200 | [diff] [blame] | 409 | static int spl_mmc_get_mmc_devnum(struct mmc *mmc) |
| 410 | { |
| 411 | struct blk_desc *block_dev; |
| 412 | #if !CONFIG_IS_ENABLED(BLK) |
| 413 | block_dev = &mmc->block_dev; |
| 414 | #else |
Sean Anderson | d2b254e | 2023-10-07 21:47:48 -0400 | [diff] [blame] | 415 | block_dev = mmc_get_blk_desc(mmc); |
Harald Seiler | af8b7b7 | 2022-07-11 14:35:32 +0200 | [diff] [blame] | 416 | #endif |
| 417 | return block_dev->devnum; |
| 418 | } |
| 419 | |
Sean Anderson | 13e6d91 | 2023-10-14 16:47:54 -0400 | [diff] [blame] | 420 | static struct mmc *mmc; |
| 421 | |
| 422 | void spl_mmc_clear_cache(void) |
| 423 | { |
| 424 | mmc = NULL; |
| 425 | } |
| 426 | |
Andreas Dannenberg | 8d9f7f1 | 2019-06-04 17:55:46 -0500 | [diff] [blame] | 427 | int spl_mmc_load(struct spl_image_info *spl_image, |
| 428 | struct spl_boot_device *bootdev, |
| 429 | const char *filename, |
| 430 | int raw_part, |
| 431 | unsigned long raw_sect) |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 432 | { |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 433 | u32 boot_mode; |
Simon Glass | f22851a | 2015-06-23 15:38:51 -0600 | [diff] [blame] | 434 | int err = 0; |
Baruch Siach | fef81be | 2020-01-15 09:08:08 +0200 | [diff] [blame] | 435 | __maybe_unused int part = 0; |
Harald Seiler | af8b7b7 | 2022-07-11 14:35:32 +0200 | [diff] [blame] | 436 | int mmc_dev; |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 437 | |
Harald Seiler | af8b7b7 | 2022-07-11 14:35:32 +0200 | [diff] [blame] | 438 | /* Perform peripheral init only once for an mmc device */ |
| 439 | mmc_dev = spl_mmc_get_device_index(bootdev->boot_device); |
| 440 | if (!mmc || spl_mmc_get_mmc_devnum(mmc) != mmc_dev) { |
Andreas Dannenberg | 8d9f7f1 | 2019-06-04 17:55:46 -0500 | [diff] [blame] | 441 | err = spl_mmc_find_device(&mmc, bootdev->boot_device); |
| 442 | if (err) |
| 443 | return err; |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 444 | |
Andreas Dannenberg | 8d9f7f1 | 2019-06-04 17:55:46 -0500 | [diff] [blame] | 445 | err = mmc_init(mmc); |
| 446 | if (err) { |
| 447 | mmc = NULL; |
Paul Burton | a8015fd | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 448 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
Andreas Dannenberg | 8d9f7f1 | 2019-06-04 17:55:46 -0500 | [diff] [blame] | 449 | printf("spl: mmc init failed with error: %d\n", err); |
Paul Burton | a8015fd | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 450 | #endif |
Andreas Dannenberg | 8d9f7f1 | 2019-06-04 17:55:46 -0500 | [diff] [blame] | 451 | return err; |
| 452 | } |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 453 | } |
Peter Korsgaard | 5e5483d | 2013-05-13 08:36:25 +0000 | [diff] [blame] | 454 | |
Andre Przywara | 3cb12ef | 2021-07-12 11:06:49 +0100 | [diff] [blame] | 455 | boot_mode = spl_mmc_boot_mode(mmc, bootdev->boot_device); |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 456 | err = -EINVAL; |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 457 | switch (boot_mode) { |
Nikita Kiryanov | 2b3ae5f | 2015-11-08 17:11:48 +0200 | [diff] [blame] | 458 | case MMCSD_MODE_EMMCBOOT: |
Marek Vasut | de1ce23 | 2021-07-03 04:55:32 +0200 | [diff] [blame] | 459 | part = spl_mmc_emmc_boot_partition(mmc); |
Nikita Kiryanov | 2b3ae5f | 2015-11-08 17:11:48 +0200 | [diff] [blame] | 460 | |
Mans Rullgard | ec046a5 | 2019-09-03 16:17:17 +0200 | [diff] [blame] | 461 | if (CONFIG_IS_ENABLED(MMC_TINY)) |
| 462 | err = mmc_switch_part(mmc, part); |
| 463 | else |
| 464 | err = blk_dselect_hwpart(mmc_get_blk_desc(mmc), part); |
Marek Vasut | f537e39 | 2016-12-01 02:06:33 +0100 | [diff] [blame] | 465 | |
Mans Rullgard | ec046a5 | 2019-09-03 16:17:17 +0200 | [diff] [blame] | 466 | if (err) { |
Nikita Kiryanov | 2b3ae5f | 2015-11-08 17:11:48 +0200 | [diff] [blame] | 467 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
Mans Rullgard | ec046a5 | 2019-09-03 16:17:17 +0200 | [diff] [blame] | 468 | puts("spl: mmc partition switch failed\n"); |
Nikita Kiryanov | 2b3ae5f | 2015-11-08 17:11:48 +0200 | [diff] [blame] | 469 | #endif |
Mans Rullgard | ec046a5 | 2019-09-03 16:17:17 +0200 | [diff] [blame] | 470 | return err; |
| 471 | } |
| 472 | /* Fall through */ |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 473 | case MMCSD_MODE_RAW: |
| 474 | debug("spl: mmc boot mode: raw\n"); |
| 475 | |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 476 | if (!spl_start_uboot()) { |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 477 | err = mmc_load_image_raw_os(spl_image, bootdev, mmc); |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 478 | if (!err) |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 479 | return err; |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 480 | } |
Peng Fan | dc7d322 | 2019-10-23 01:43:30 +0000 | [diff] [blame] | 481 | |
Faiz Abbas | 0bdf563 | 2020-02-26 13:44:35 +0530 | [diff] [blame] | 482 | raw_sect = spl_mmc_get_uboot_raw_sector(mmc, raw_sect); |
Peng Fan | dc7d322 | 2019-10-23 01:43:30 +0000 | [diff] [blame] | 483 | |
Dalon Westergreen | f5ba985 | 2017-02-10 17:15:35 -0800 | [diff] [blame] | 484 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 485 | err = mmc_load_image_raw_partition(spl_image, bootdev, |
| 486 | mmc, raw_part, |
Andreas Dannenberg | 8d9f7f1 | 2019-06-04 17:55:46 -0500 | [diff] [blame] | 487 | raw_sect); |
Paul Kocialkowski | 4bd66e7 | 2015-06-08 23:05:09 +0200 | [diff] [blame] | 488 | if (!err) |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 489 | return err; |
Dalon Westergreen | f5ba985 | 2017-02-10 17:15:35 -0800 | [diff] [blame] | 490 | #endif |
Semen Protsenko | 7e3ba48 | 2016-11-16 19:19:05 +0200 | [diff] [blame] | 491 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 492 | err = mmc_load_image_raw_sector(spl_image, bootdev, mmc, |
Baruch Siach | fef81be | 2020-01-15 09:08:08 +0200 | [diff] [blame] | 493 | raw_sect + spl_mmc_raw_uboot_offset(part)); |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 494 | if (!err) |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 495 | return err; |
Paul Kocialkowski | 4bd66e7 | 2015-06-08 23:05:09 +0200 | [diff] [blame] | 496 | #endif |
Guillaume GARDET | 834dd88 | 2016-02-18 18:17:36 +0100 | [diff] [blame] | 497 | /* If RAW mode fails, try FS mode. */ |
Pali Rohár | a081155 | 2023-01-21 15:13:08 +0100 | [diff] [blame] | 498 | #ifdef CONFIG_SYS_MMCSD_FS_BOOT |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 499 | case MMCSD_MODE_FS: |
| 500 | debug("spl: mmc boot mode: fs\n"); |
| 501 | |
Pali Rohár | dda8f88 | 2022-01-14 14:31:38 +0100 | [diff] [blame] | 502 | err = spl_mmc_do_fs_boot(spl_image, bootdev, mmc, filename); |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 503 | if (!err) |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 504 | return err; |
Nikita Kiryanov | 642648c | 2015-11-08 17:11:47 +0200 | [diff] [blame] | 505 | |
Nikita Kiryanov | ed52f4d | 2015-11-08 17:11:43 +0200 | [diff] [blame] | 506 | break; |
Pali Rohár | a081155 | 2023-01-21 15:13:08 +0100 | [diff] [blame] | 507 | #endif |
Paul Burton | a8015fd | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 508 | #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT |
Nikita Kiryanov | ed52f4d | 2015-11-08 17:11:43 +0200 | [diff] [blame] | 509 | default: |
| 510 | puts("spl: mmc: wrong boot mode\n"); |
Paul Burton | a8015fd | 2013-09-04 16:12:24 +0100 | [diff] [blame] | 511 | #endif |
Paul Kocialkowski | 0d13972 | 2015-04-27 10:20:22 +0200 | [diff] [blame] | 512 | } |
Nikita Kiryanov | ed52f4d | 2015-11-08 17:11:43 +0200 | [diff] [blame] | 513 | |
Nikita Kiryanov | 33eefe4 | 2015-11-08 17:11:49 +0200 | [diff] [blame] | 514 | return err; |
Simon Schwarz | e21d2d8 | 2011-09-14 15:33:34 -0400 | [diff] [blame] | 515 | } |
Simon Glass | d449cb8 | 2016-09-24 18:20:00 -0600 | [diff] [blame] | 516 | |
Andreas Dannenberg | 8d9f7f1 | 2019-06-04 17:55:46 -0500 | [diff] [blame] | 517 | int spl_mmc_load_image(struct spl_image_info *spl_image, |
| 518 | struct spl_boot_device *bootdev) |
| 519 | { |
| 520 | return spl_mmc_load(spl_image, bootdev, |
| 521 | #ifdef CONFIG_SPL_FS_LOAD_PAYLOAD_NAME |
| 522 | CONFIG_SPL_FS_LOAD_PAYLOAD_NAME, |
| 523 | #else |
| 524 | NULL, |
| 525 | #endif |
| 526 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_PARTITION |
Harald Seiler | bf16c30 | 2020-04-15 11:33:31 +0200 | [diff] [blame] | 527 | spl_mmc_boot_partition(bootdev->boot_device), |
Andreas Dannenberg | 8d9f7f1 | 2019-06-04 17:55:46 -0500 | [diff] [blame] | 528 | #else |
| 529 | 0, |
| 530 | #endif |
| 531 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR |
| 532 | CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR); |
| 533 | #else |
| 534 | 0); |
| 535 | #endif |
| 536 | } |
| 537 | |
Simon Glass | 4fc1f25 | 2016-11-30 15:30:50 -0700 | [diff] [blame] | 538 | SPL_LOAD_IMAGE_METHOD("MMC1", 0, BOOT_DEVICE_MMC1, spl_mmc_load_image); |
| 539 | SPL_LOAD_IMAGE_METHOD("MMC2", 0, BOOT_DEVICE_MMC2, spl_mmc_load_image); |
| 540 | SPL_LOAD_IMAGE_METHOD("MMC2_2", 0, BOOT_DEVICE_MMC2_2, spl_mmc_load_image); |