Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2019 NXP |
| 4 | */ |
| 5 | |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 6 | #include <errno.h> |
| 7 | #include <image.h> |
Sean Anderson | 952ed67 | 2023-10-14 16:47:44 -0400 | [diff] [blame] | 8 | #include <imx_container.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 11 | #include <linux/libfdt.h> |
| 12 | #include <spl.h> |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 13 | #include <asm/arch/sys_proto.h> |
| 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 17 | /* Caller need ensure the offset and size to align with page size */ |
| 18 | ulong spl_romapi_raw_seekable_read(u32 offset, u32 size, void *buf) |
| 19 | { |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 20 | int ret; |
| 21 | |
| 22 | debug("%s 0x%x, size 0x%x\n", __func__, offset, size); |
| 23 | |
Rasmus Villemoes | 9bfb1ba | 2022-06-20 10:53:20 +0200 | [diff] [blame] | 24 | ret = rom_api_download_image(buf, offset, size); |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 25 | |
| 26 | if (ret == ROM_API_OKAY) |
| 27 | return size; |
| 28 | |
| 29 | printf("%s Failure when load 0x%x, size 0x%x\n", __func__, offset, size); |
| 30 | |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | ulong __weak spl_romapi_get_uboot_base(u32 image_offset, u32 rom_bt_dev) |
| 35 | { |
Marek Vasut | 8510756 | 2022-03-09 17:09:45 +0100 | [diff] [blame] | 36 | return image_offset + |
| 37 | (CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR * 512 - 0x8000); |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 38 | } |
| 39 | |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 40 | static int is_boot_from_stream_device(u32 boot) |
| 41 | { |
| 42 | u32 interface; |
| 43 | |
| 44 | interface = boot >> 16; |
| 45 | if (interface >= BT_DEV_TYPE_USB) |
| 46 | return 1; |
| 47 | |
| 48 | if (interface == BT_DEV_TYPE_MMC && (boot & 1)) |
| 49 | return 1; |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | static ulong spl_romapi_read_seekable(struct spl_load_info *load, |
Sean Anderson | 7d8d613 | 2023-11-08 11:48:40 -0500 | [diff] [blame] | 55 | ulong offset, ulong byte, |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 56 | void *buf) |
| 57 | { |
Sean Anderson | 7d8d613 | 2023-11-08 11:48:40 -0500 | [diff] [blame] | 58 | return spl_romapi_raw_seekable_read(offset, byte, buf); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image, |
| 62 | struct spl_boot_device *bootdev, |
| 63 | u32 rom_bt_dev) |
| 64 | { |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 65 | int ret; |
| 66 | u32 offset; |
| 67 | u32 pagesize, size; |
Simon Glass | bb7d3bb | 2022-09-06 20:26:52 -0600 | [diff] [blame] | 68 | struct legacy_img_hdr *header; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 69 | u32 image_offset; |
| 70 | |
Rasmus Villemoes | 9bfb1ba | 2022-06-20 10:53:20 +0200 | [diff] [blame] | 71 | ret = rom_api_query_boot_infor(QUERY_IVT_OFF, &offset); |
Marek Vasut | 0063916 | 2023-07-02 03:03:51 +0200 | [diff] [blame] | 72 | if (ret != ROM_API_OKAY) |
| 73 | goto err; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 74 | |
Marek Vasut | 0063916 | 2023-07-02 03:03:51 +0200 | [diff] [blame] | 75 | ret = rom_api_query_boot_infor(QUERY_PAGE_SZ, &pagesize); |
| 76 | if (ret != ROM_API_OKAY) |
| 77 | goto err; |
| 78 | |
| 79 | ret = rom_api_query_boot_infor(QUERY_IMG_OFF, &image_offset); |
| 80 | if (ret != ROM_API_OKAY) |
| 81 | goto err; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 82 | |
Simon Glass | bb7d3bb | 2022-09-06 20:26:52 -0600 | [diff] [blame] | 83 | header = (struct legacy_img_hdr *)(CONFIG_SPL_IMX_ROMAPI_LOADADDR); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 84 | |
| 85 | printf("image offset 0x%x, pagesize 0x%x, ivt offset 0x%x\n", |
| 86 | image_offset, pagesize, offset); |
| 87 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 88 | offset = spl_romapi_get_uboot_base(image_offset, rom_bt_dev); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 89 | |
Simon Glass | bb7d3bb | 2022-09-06 20:26:52 -0600 | [diff] [blame] | 90 | size = ALIGN(sizeof(struct legacy_img_hdr), pagesize); |
Rasmus Villemoes | 9bfb1ba | 2022-06-20 10:53:20 +0200 | [diff] [blame] | 91 | ret = rom_api_download_image((u8 *)header, offset, size); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 92 | |
| 93 | if (ret != ROM_API_OKAY) { |
| 94 | printf("ROMAPI: download failure offset 0x%x size 0x%x\n", |
| 95 | offset, size); |
| 96 | return -1; |
| 97 | } |
| 98 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 99 | if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && image_get_magic(header) == FDT_MAGIC) { |
| 100 | struct spl_load_info load; |
| 101 | |
| 102 | memset(&load, 0, sizeof(load)); |
Sean Anderson | 35f15fe | 2023-11-08 11:48:43 -0500 | [diff] [blame] | 103 | spl_set_bl_len(&load, pagesize); |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 104 | load.read = spl_romapi_read_seekable; |
Sean Anderson | 7d8d613 | 2023-11-08 11:48:40 -0500 | [diff] [blame] | 105 | return spl_load_simple_fit(spl_image, &load, offset, header); |
Sean Anderson | 952ed67 | 2023-10-14 16:47:44 -0400 | [diff] [blame] | 106 | } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) && |
| 107 | valid_container_hdr((void *)header)) { |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 108 | struct spl_load_info load; |
| 109 | |
| 110 | memset(&load, 0, sizeof(load)); |
Sean Anderson | 35f15fe | 2023-11-08 11:48:43 -0500 | [diff] [blame] | 111 | spl_set_bl_len(&load, pagesize); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 112 | load.read = spl_romapi_read_seekable; |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 113 | |
Sean Anderson | 7d8d613 | 2023-11-08 11:48:40 -0500 | [diff] [blame] | 114 | ret = spl_load_imx_container(spl_image, &load, offset); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 115 | } else { |
| 116 | /* TODO */ |
| 117 | puts("Can't support legacy image\n"); |
| 118 | return -1; |
| 119 | } |
| 120 | |
| 121 | return 0; |
Marek Vasut | 0063916 | 2023-07-02 03:03:51 +0200 | [diff] [blame] | 122 | |
| 123 | err: |
| 124 | puts("ROMAPI: Failure query boot infor pagesize/offset\n"); |
| 125 | return -1; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Rasmus Villemoes | 51600f1 | 2023-09-19 15:49:31 +0200 | [diff] [blame] | 128 | struct stream_state { |
| 129 | u8 *base; |
| 130 | u8 *end; |
| 131 | u32 pagesize; |
| 132 | }; |
| 133 | |
| 134 | static ulong spl_romapi_read_stream(struct spl_load_info *load, ulong sector, |
| 135 | ulong count, void *buf) |
| 136 | { |
| 137 | struct stream_state *ss = load->priv; |
| 138 | u8 *end = (u8*)(sector + count); |
| 139 | u32 bytes; |
| 140 | int ret; |
| 141 | |
| 142 | if (end > ss->end) { |
| 143 | bytes = end - ss->end; |
| 144 | bytes += ss->pagesize - 1; |
| 145 | bytes /= ss->pagesize; |
| 146 | bytes *= ss->pagesize; |
| 147 | |
| 148 | debug("downloading another 0x%x bytes\n", bytes); |
| 149 | ret = rom_api_download_image(ss->end, 0, bytes); |
| 150 | |
| 151 | if (ret != ROM_API_OKAY) { |
| 152 | printf("Failure download %d\n", bytes); |
| 153 | return 0; |
| 154 | } |
| 155 | |
Marcel Ziswiler | 4bd847f | 2023-10-26 09:32:20 +0200 | [diff] [blame] | 156 | ss->end += bytes; |
Rasmus Villemoes | 51600f1 | 2023-09-19 15:49:31 +0200 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | memcpy(buf, (void *)(sector), count); |
| 160 | return count; |
| 161 | } |
| 162 | |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 163 | static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector, |
| 164 | ulong count, void *buf) |
| 165 | { |
| 166 | memcpy(buf, (void *)(sector), count); |
| 167 | |
| 168 | if (load->priv) { |
| 169 | ulong *p = (ulong *)load->priv; |
| 170 | ulong total = sector + count; |
| 171 | |
| 172 | if (total > *p) |
| 173 | *p = total; |
| 174 | } |
| 175 | |
| 176 | return count; |
| 177 | } |
| 178 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 179 | static u8 *search_fit_header(u8 *p, int size) |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 180 | { |
| 181 | int i; |
| 182 | |
| 183 | for (i = 0; i < size; i += 4) |
| 184 | if (genimg_get_format(p + i) == IMAGE_FORMAT_FIT) |
| 185 | return p + i; |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 186 | |
| 187 | return NULL; |
| 188 | } |
| 189 | |
| 190 | static u8 *search_container_header(u8 *p, int size) |
| 191 | { |
| 192 | int i = 0; |
| 193 | u8 *hdr; |
| 194 | |
| 195 | for (i = 0; i < size; i += 4) { |
| 196 | hdr = p + i; |
Sean Anderson | c512668 | 2023-10-14 16:47:43 -0400 | [diff] [blame] | 197 | if (valid_container_hdr((void *)hdr) && |
| 198 | (*(hdr + 1) != 0 || *(hdr + 2) != 0)) |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 199 | return p + i; |
| 200 | } |
| 201 | |
| 202 | return NULL; |
| 203 | } |
| 204 | |
| 205 | static u8 *search_img_header(u8 *p, int size) |
| 206 | { |
| 207 | if (IS_ENABLED(CONFIG_SPL_LOAD_FIT)) |
| 208 | return search_fit_header(p, size); |
| 209 | else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) |
| 210 | return search_container_header(p, size); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 211 | |
| 212 | return NULL; |
| 213 | } |
| 214 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 215 | static u32 img_header_size(void) |
| 216 | { |
| 217 | if (IS_ENABLED(CONFIG_SPL_LOAD_FIT)) |
| 218 | return sizeof(struct fdt_header); |
| 219 | else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) |
| 220 | return sizeof(struct container_hdr); |
| 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | static int img_info_size(void *img_hdr) |
| 226 | { |
| 227 | #ifdef CONFIG_SPL_LOAD_FIT |
| 228 | return fit_get_size(img_hdr); |
| 229 | #elif defined CONFIG_SPL_LOAD_IMX_CONTAINER |
| 230 | struct container_hdr *container = img_hdr; |
| 231 | |
| 232 | return (container->length_lsb + (container->length_msb << 8)); |
| 233 | #else |
| 234 | return 0; |
| 235 | #endif |
| 236 | } |
| 237 | |
| 238 | static int img_total_size(void *img_hdr) |
| 239 | { |
Rasmus Villemoes | 6eb4f78 | 2023-09-19 15:49:32 +0200 | [diff] [blame] | 240 | if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) { |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 241 | int total = get_container_size((ulong)img_hdr, NULL); |
| 242 | |
| 243 | if (total < 0) { |
| 244 | printf("invalid container image\n"); |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | return total; |
| 249 | } |
| 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 254 | static int spl_romapi_load_image_stream(struct spl_image_info *spl_image, |
| 255 | struct spl_boot_device *bootdev) |
| 256 | { |
| 257 | struct spl_load_info load; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 258 | u32 pagesize, pg; |
| 259 | int ret; |
| 260 | int i = 0; |
| 261 | u8 *p = (u8 *)CONFIG_SPL_IMX_ROMAPI_LOADADDR; |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 262 | u8 *phdr = NULL; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 263 | int imagesize; |
| 264 | int total; |
| 265 | |
Rasmus Villemoes | 9bfb1ba | 2022-06-20 10:53:20 +0200 | [diff] [blame] | 266 | ret = rom_api_query_boot_infor(QUERY_PAGE_SZ, &pagesize); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 267 | |
| 268 | if (ret != ROM_API_OKAY) |
| 269 | puts("failure at query_boot_info\n"); |
| 270 | |
| 271 | pg = pagesize; |
| 272 | if (pg < 1024) |
| 273 | pg = 1024; |
| 274 | |
| 275 | for (i = 0; i < 640; i++) { |
Rasmus Villemoes | 9bfb1ba | 2022-06-20 10:53:20 +0200 | [diff] [blame] | 276 | ret = rom_api_download_image(p, 0, pg); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 277 | |
| 278 | if (ret != ROM_API_OKAY) { |
Marcel Ziswiler | 0f38fef | 2023-10-26 09:32:19 +0200 | [diff] [blame] | 279 | puts("Stream(USB) download failure\n"); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 280 | return -1; |
| 281 | } |
| 282 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 283 | phdr = search_img_header(p, pg); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 284 | p += pg; |
| 285 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 286 | if (phdr) |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 287 | break; |
| 288 | } |
| 289 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 290 | if (!phdr) { |
| 291 | puts("Can't found uboot image in 640K range\n"); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 292 | return -1; |
| 293 | } |
| 294 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 295 | if (p - phdr < img_header_size()) { |
Rasmus Villemoes | 9bfb1ba | 2022-06-20 10:53:20 +0200 | [diff] [blame] | 296 | ret = rom_api_download_image(p, 0, pg); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 297 | |
| 298 | if (ret != ROM_API_OKAY) { |
Marcel Ziswiler | 0f38fef | 2023-10-26 09:32:19 +0200 | [diff] [blame] | 299 | puts("Stream(USB) download failure\n"); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 300 | return -1; |
| 301 | } |
| 302 | |
| 303 | p += pg; |
| 304 | } |
| 305 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 306 | imagesize = img_info_size(phdr); |
Marcel Ziswiler | ff110e3 | 2022-07-20 09:27:55 +0200 | [diff] [blame] | 307 | printf("Find img info 0x%p, size %d\n", phdr, imagesize); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 308 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 309 | if (p - phdr < imagesize) { |
| 310 | imagesize -= p - phdr; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 311 | /*need pagesize hear after ROM fix USB problme*/ |
| 312 | imagesize += pg - 1; |
| 313 | imagesize /= pg; |
| 314 | imagesize *= pg; |
| 315 | |
| 316 | printf("Need continue download %d\n", imagesize); |
| 317 | |
Rasmus Villemoes | 9bfb1ba | 2022-06-20 10:53:20 +0200 | [diff] [blame] | 318 | ret = rom_api_download_image(p, 0, imagesize); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 319 | |
| 320 | p += imagesize; |
| 321 | |
| 322 | if (ret != ROM_API_OKAY) { |
| 323 | printf("Failure download %d\n", imagesize); |
| 324 | return -1; |
| 325 | } |
| 326 | } |
| 327 | |
Rasmus Villemoes | 51600f1 | 2023-09-19 15:49:31 +0200 | [diff] [blame] | 328 | if (IS_ENABLED(CONFIG_SPL_LOAD_FIT)) { |
| 329 | struct stream_state ss; |
| 330 | |
| 331 | ss.base = phdr; |
| 332 | ss.end = p; |
| 333 | ss.pagesize = pagesize; |
| 334 | |
| 335 | memset(&load, 0, sizeof(load)); |
Sean Anderson | 35f15fe | 2023-11-08 11:48:43 -0500 | [diff] [blame] | 336 | spl_set_bl_len(&load, 1); |
Rasmus Villemoes | 51600f1 | 2023-09-19 15:49:31 +0200 | [diff] [blame] | 337 | load.read = spl_romapi_read_stream; |
| 338 | load.priv = &ss; |
| 339 | |
| 340 | return spl_load_simple_fit(spl_image, &load, (ulong)phdr, phdr); |
| 341 | } |
| 342 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 343 | total = img_total_size(phdr); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 344 | total += 3; |
| 345 | total &= ~0x3; |
| 346 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 347 | imagesize = total - (p - phdr); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 348 | |
| 349 | imagesize += pagesize - 1; |
| 350 | imagesize /= pagesize; |
| 351 | imagesize *= pagesize; |
| 352 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 353 | printf("Download %d, Total size %d\n", imagesize, total); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 354 | |
Rasmus Villemoes | 9bfb1ba | 2022-06-20 10:53:20 +0200 | [diff] [blame] | 355 | ret = rom_api_download_image(p, 0, imagesize); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 356 | if (ret != ROM_API_OKAY) |
| 357 | printf("ROM download failure %d\n", imagesize); |
| 358 | |
| 359 | memset(&load, 0, sizeof(load)); |
Sean Anderson | 35f15fe | 2023-11-08 11:48:43 -0500 | [diff] [blame] | 360 | spl_set_bl_len(&load, 1); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 361 | load.read = spl_ram_load_read; |
| 362 | |
Rasmus Villemoes | 6eb4f78 | 2023-09-19 15:49:32 +0200 | [diff] [blame] | 363 | if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 364 | return spl_load_imx_container(spl_image, &load, (ulong)phdr); |
| 365 | |
| 366 | return -1; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | int board_return_to_bootrom(struct spl_image_info *spl_image, |
| 370 | struct spl_boot_device *bootdev) |
| 371 | { |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 372 | int ret; |
Ye Li | 504514b | 2023-02-03 18:21:47 +0800 | [diff] [blame] | 373 | u32 boot, bstage; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 374 | |
Rasmus Villemoes | 9bfb1ba | 2022-06-20 10:53:20 +0200 | [diff] [blame] | 375 | ret = rom_api_query_boot_infor(QUERY_BT_DEV, &boot); |
Marek Vasut | 0063916 | 2023-07-02 03:03:51 +0200 | [diff] [blame] | 376 | if (ret != ROM_API_OKAY) |
| 377 | goto err; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 378 | |
Marek Vasut | 0063916 | 2023-07-02 03:03:51 +0200 | [diff] [blame] | 379 | ret = rom_api_query_boot_infor(QUERY_BT_STAGE, &bstage); |
| 380 | if (ret != ROM_API_OKAY) |
| 381 | goto err; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 382 | |
Ye Li | 504514b | 2023-02-03 18:21:47 +0800 | [diff] [blame] | 383 | printf("Boot Stage: "); |
| 384 | |
| 385 | switch (bstage) { |
| 386 | case BT_STAGE_PRIMARY: |
| 387 | printf("Primary boot\n"); |
| 388 | break; |
| 389 | case BT_STAGE_SECONDARY: |
| 390 | printf("Secondary boot\n"); |
| 391 | break; |
| 392 | case BT_STAGE_RECOVERY: |
| 393 | printf("Recovery boot\n"); |
| 394 | break; |
| 395 | case BT_STAGE_USB: |
| 396 | printf("USB boot\n"); |
| 397 | break; |
| 398 | default: |
Peng Fan | b7052db | 2023-04-28 12:08:08 +0800 | [diff] [blame] | 399 | printf("Unknown (0x%x)\n", bstage); |
Ye Li | 504514b | 2023-02-03 18:21:47 +0800 | [diff] [blame] | 400 | } |
| 401 | |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 402 | if (is_boot_from_stream_device(boot)) |
| 403 | return spl_romapi_load_image_stream(spl_image, bootdev); |
| 404 | |
| 405 | return spl_romapi_load_image_seekable(spl_image, bootdev, boot); |
Marek Vasut | 0063916 | 2023-07-02 03:03:51 +0200 | [diff] [blame] | 406 | err: |
| 407 | puts("ROMAPI: failure at query_boot_info\n"); |
| 408 | return -1; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 409 | } |