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