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> |
Sean Anderson | 952ed67 | 2023-10-14 16:47:44 -0400 | [diff] [blame] | 9 | #include <imx_container.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 12 | #include <linux/libfdt.h> |
| 13 | #include <spl.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); |
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 | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 116 | struct spl_load_info load; |
| 117 | |
| 118 | memset(&load, 0, sizeof(load)); |
| 119 | load.bl_len = pagesize; |
| 120 | load.read = spl_romapi_read_seekable; |
| 121 | load.priv = &pagesize; |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 122 | |
| 123 | ret = spl_load_imx_container(spl_image, &load, offset / pagesize); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 124 | } else { |
| 125 | /* TODO */ |
| 126 | puts("Can't support legacy image\n"); |
| 127 | return -1; |
| 128 | } |
| 129 | |
| 130 | return 0; |
Marek Vasut | 0063916 | 2023-07-02 03:03:51 +0200 | [diff] [blame] | 131 | |
| 132 | err: |
| 133 | puts("ROMAPI: Failure query boot infor pagesize/offset\n"); |
| 134 | return -1; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Rasmus Villemoes | 51600f1 | 2023-09-19 15:49:31 +0200 | [diff] [blame] | 137 | struct stream_state { |
| 138 | u8 *base; |
| 139 | u8 *end; |
| 140 | u32 pagesize; |
| 141 | }; |
| 142 | |
| 143 | static ulong spl_romapi_read_stream(struct spl_load_info *load, ulong sector, |
| 144 | ulong count, void *buf) |
| 145 | { |
| 146 | struct stream_state *ss = load->priv; |
| 147 | u8 *end = (u8*)(sector + count); |
| 148 | u32 bytes; |
| 149 | int ret; |
| 150 | |
| 151 | if (end > ss->end) { |
| 152 | bytes = end - ss->end; |
| 153 | bytes += ss->pagesize - 1; |
| 154 | bytes /= ss->pagesize; |
| 155 | bytes *= ss->pagesize; |
| 156 | |
| 157 | debug("downloading another 0x%x bytes\n", bytes); |
| 158 | ret = rom_api_download_image(ss->end, 0, bytes); |
| 159 | |
| 160 | if (ret != ROM_API_OKAY) { |
| 161 | printf("Failure download %d\n", bytes); |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | ss->end = end; |
| 166 | } |
| 167 | |
| 168 | memcpy(buf, (void *)(sector), count); |
| 169 | return count; |
| 170 | } |
| 171 | |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 172 | static ulong spl_ram_load_read(struct spl_load_info *load, ulong sector, |
| 173 | ulong count, void *buf) |
| 174 | { |
| 175 | memcpy(buf, (void *)(sector), count); |
| 176 | |
| 177 | if (load->priv) { |
| 178 | ulong *p = (ulong *)load->priv; |
| 179 | ulong total = sector + count; |
| 180 | |
| 181 | if (total > *p) |
| 182 | *p = total; |
| 183 | } |
| 184 | |
| 185 | return count; |
| 186 | } |
| 187 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 188 | static u8 *search_fit_header(u8 *p, int size) |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 189 | { |
| 190 | int i; |
| 191 | |
| 192 | for (i = 0; i < size; i += 4) |
| 193 | if (genimg_get_format(p + i) == IMAGE_FORMAT_FIT) |
| 194 | return p + i; |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 195 | |
| 196 | return NULL; |
| 197 | } |
| 198 | |
| 199 | static u8 *search_container_header(u8 *p, int size) |
| 200 | { |
| 201 | int i = 0; |
| 202 | u8 *hdr; |
| 203 | |
| 204 | for (i = 0; i < size; i += 4) { |
| 205 | hdr = p + i; |
Sean Anderson | c512668 | 2023-10-14 16:47:43 -0400 | [diff] [blame] | 206 | if (valid_container_hdr((void *)hdr) && |
| 207 | (*(hdr + 1) != 0 || *(hdr + 2) != 0)) |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 208 | return p + i; |
| 209 | } |
| 210 | |
| 211 | return NULL; |
| 212 | } |
| 213 | |
| 214 | static u8 *search_img_header(u8 *p, int size) |
| 215 | { |
| 216 | if (IS_ENABLED(CONFIG_SPL_LOAD_FIT)) |
| 217 | return search_fit_header(p, size); |
| 218 | else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) |
| 219 | return search_container_header(p, size); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 220 | |
| 221 | return NULL; |
| 222 | } |
| 223 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 224 | static u32 img_header_size(void) |
| 225 | { |
| 226 | if (IS_ENABLED(CONFIG_SPL_LOAD_FIT)) |
| 227 | return sizeof(struct fdt_header); |
| 228 | else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) |
| 229 | return sizeof(struct container_hdr); |
| 230 | |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | static int img_info_size(void *img_hdr) |
| 235 | { |
| 236 | #ifdef CONFIG_SPL_LOAD_FIT |
| 237 | return fit_get_size(img_hdr); |
| 238 | #elif defined CONFIG_SPL_LOAD_IMX_CONTAINER |
| 239 | struct container_hdr *container = img_hdr; |
| 240 | |
| 241 | return (container->length_lsb + (container->length_msb << 8)); |
| 242 | #else |
| 243 | return 0; |
| 244 | #endif |
| 245 | } |
| 246 | |
| 247 | static int img_total_size(void *img_hdr) |
| 248 | { |
Rasmus Villemoes | 6eb4f78 | 2023-09-19 15:49:32 +0200 | [diff] [blame] | 249 | if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) { |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 250 | int total = get_container_size((ulong)img_hdr, NULL); |
| 251 | |
| 252 | if (total < 0) { |
| 253 | printf("invalid container image\n"); |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | return total; |
| 258 | } |
| 259 | |
| 260 | return 0; |
| 261 | } |
| 262 | |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 263 | static int spl_romapi_load_image_stream(struct spl_image_info *spl_image, |
| 264 | struct spl_boot_device *bootdev) |
| 265 | { |
| 266 | struct spl_load_info load; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 267 | u32 pagesize, pg; |
| 268 | int ret; |
| 269 | int i = 0; |
| 270 | u8 *p = (u8 *)CONFIG_SPL_IMX_ROMAPI_LOADADDR; |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 271 | u8 *phdr = NULL; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 272 | int imagesize; |
| 273 | int total; |
| 274 | |
Rasmus Villemoes | 9bfb1ba | 2022-06-20 10:53:20 +0200 | [diff] [blame] | 275 | ret = rom_api_query_boot_infor(QUERY_PAGE_SZ, &pagesize); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 276 | |
| 277 | if (ret != ROM_API_OKAY) |
| 278 | puts("failure at query_boot_info\n"); |
| 279 | |
| 280 | pg = pagesize; |
| 281 | if (pg < 1024) |
| 282 | pg = 1024; |
| 283 | |
| 284 | for (i = 0; i < 640; i++) { |
Rasmus Villemoes | 9bfb1ba | 2022-06-20 10:53:20 +0200 | [diff] [blame] | 285 | ret = rom_api_download_image(p, 0, pg); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 286 | |
| 287 | if (ret != ROM_API_OKAY) { |
| 288 | puts("Steam(USB) download failure\n"); |
| 289 | return -1; |
| 290 | } |
| 291 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 292 | phdr = search_img_header(p, pg); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 293 | p += pg; |
| 294 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 295 | if (phdr) |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 296 | break; |
| 297 | } |
| 298 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 299 | if (!phdr) { |
| 300 | puts("Can't found uboot image in 640K range\n"); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 301 | return -1; |
| 302 | } |
| 303 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 304 | if (p - phdr < img_header_size()) { |
Rasmus Villemoes | 9bfb1ba | 2022-06-20 10:53:20 +0200 | [diff] [blame] | 305 | ret = rom_api_download_image(p, 0, pg); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 306 | |
| 307 | if (ret != ROM_API_OKAY) { |
| 308 | puts("Steam(USB) download failure\n"); |
| 309 | return -1; |
| 310 | } |
| 311 | |
| 312 | p += pg; |
| 313 | } |
| 314 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 315 | imagesize = img_info_size(phdr); |
Marcel Ziswiler | ff110e3 | 2022-07-20 09:27:55 +0200 | [diff] [blame] | 316 | printf("Find img info 0x%p, size %d\n", phdr, imagesize); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 317 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 318 | if (p - phdr < imagesize) { |
| 319 | imagesize -= p - phdr; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 320 | /*need pagesize hear after ROM fix USB problme*/ |
| 321 | imagesize += pg - 1; |
| 322 | imagesize /= pg; |
| 323 | imagesize *= pg; |
| 324 | |
| 325 | printf("Need continue download %d\n", imagesize); |
| 326 | |
Rasmus Villemoes | 9bfb1ba | 2022-06-20 10:53:20 +0200 | [diff] [blame] | 327 | ret = rom_api_download_image(p, 0, imagesize); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 328 | |
| 329 | p += imagesize; |
| 330 | |
| 331 | if (ret != ROM_API_OKAY) { |
| 332 | printf("Failure download %d\n", imagesize); |
| 333 | return -1; |
| 334 | } |
| 335 | } |
| 336 | |
Rasmus Villemoes | 51600f1 | 2023-09-19 15:49:31 +0200 | [diff] [blame] | 337 | if (IS_ENABLED(CONFIG_SPL_LOAD_FIT)) { |
| 338 | struct stream_state ss; |
| 339 | |
| 340 | ss.base = phdr; |
| 341 | ss.end = p; |
| 342 | ss.pagesize = pagesize; |
| 343 | |
| 344 | memset(&load, 0, sizeof(load)); |
| 345 | load.bl_len = 1; |
| 346 | load.read = spl_romapi_read_stream; |
| 347 | load.priv = &ss; |
| 348 | |
| 349 | return spl_load_simple_fit(spl_image, &load, (ulong)phdr, phdr); |
| 350 | } |
| 351 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 352 | total = img_total_size(phdr); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 353 | total += 3; |
| 354 | total &= ~0x3; |
| 355 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 356 | imagesize = total - (p - phdr); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 357 | |
| 358 | imagesize += pagesize - 1; |
| 359 | imagesize /= pagesize; |
| 360 | imagesize *= pagesize; |
| 361 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 362 | printf("Download %d, Total size %d\n", imagesize, total); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 363 | |
Rasmus Villemoes | 9bfb1ba | 2022-06-20 10:53:20 +0200 | [diff] [blame] | 364 | ret = rom_api_download_image(p, 0, imagesize); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 365 | if (ret != ROM_API_OKAY) |
| 366 | printf("ROM download failure %d\n", imagesize); |
| 367 | |
| 368 | memset(&load, 0, sizeof(load)); |
| 369 | load.bl_len = 1; |
| 370 | load.read = spl_ram_load_read; |
| 371 | |
Rasmus Villemoes | 6eb4f78 | 2023-09-19 15:49:32 +0200 | [diff] [blame] | 372 | if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 373 | return spl_load_imx_container(spl_image, &load, (ulong)phdr); |
| 374 | |
| 375 | return -1; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | int board_return_to_bootrom(struct spl_image_info *spl_image, |
| 379 | struct spl_boot_device *bootdev) |
| 380 | { |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 381 | int ret; |
Ye Li | 504514b | 2023-02-03 18:21:47 +0800 | [diff] [blame] | 382 | u32 boot, bstage; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 383 | |
Rasmus Villemoes | 9bfb1ba | 2022-06-20 10:53:20 +0200 | [diff] [blame] | 384 | ret = rom_api_query_boot_infor(QUERY_BT_DEV, &boot); |
Marek Vasut | 0063916 | 2023-07-02 03:03:51 +0200 | [diff] [blame] | 385 | if (ret != ROM_API_OKAY) |
| 386 | goto err; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 387 | |
Marek Vasut | 0063916 | 2023-07-02 03:03:51 +0200 | [diff] [blame] | 388 | ret = rom_api_query_boot_infor(QUERY_BT_STAGE, &bstage); |
| 389 | if (ret != ROM_API_OKAY) |
| 390 | goto err; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 391 | |
Ye Li | 504514b | 2023-02-03 18:21:47 +0800 | [diff] [blame] | 392 | printf("Boot Stage: "); |
| 393 | |
| 394 | switch (bstage) { |
| 395 | case BT_STAGE_PRIMARY: |
| 396 | printf("Primary boot\n"); |
| 397 | break; |
| 398 | case BT_STAGE_SECONDARY: |
| 399 | printf("Secondary boot\n"); |
| 400 | break; |
| 401 | case BT_STAGE_RECOVERY: |
| 402 | printf("Recovery boot\n"); |
| 403 | break; |
| 404 | case BT_STAGE_USB: |
| 405 | printf("USB boot\n"); |
| 406 | break; |
| 407 | default: |
Peng Fan | b7052db | 2023-04-28 12:08:08 +0800 | [diff] [blame] | 408 | printf("Unknown (0x%x)\n", bstage); |
Ye Li | 504514b | 2023-02-03 18:21:47 +0800 | [diff] [blame] | 409 | } |
| 410 | |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 411 | if (is_boot_from_stream_device(boot)) |
| 412 | return spl_romapi_load_image_stream(spl_image, bootdev); |
| 413 | |
| 414 | return spl_romapi_load_image_seekable(spl_image, bootdev, boot); |
Marek Vasut | 0063916 | 2023-07-02 03:03:51 +0200 | [diff] [blame] | 415 | err: |
| 416 | puts("ROMAPI: failure at query_boot_info\n"); |
| 417 | return -1; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 418 | } |