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 | { |
Simon Glass | 1842283 | 2024-08-22 07:55:00 -0600 | [diff] [blame^] | 36 | u32 sector = 0; |
| 37 | |
| 38 | /* |
| 39 | * Some boards use this value even though MMC is not enabled in SPL, for |
| 40 | * example imx8mn_bsh_smm_s2 |
| 41 | */ |
| 42 | #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR |
| 43 | sector = CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR; |
| 44 | #endif |
| 45 | |
| 46 | return image_offset + sector * 512 - 0x8000; |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 47 | } |
| 48 | |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 49 | static int is_boot_from_stream_device(u32 boot) |
| 50 | { |
| 51 | u32 interface; |
| 52 | |
| 53 | interface = boot >> 16; |
| 54 | if (interface >= BT_DEV_TYPE_USB) |
| 55 | return 1; |
| 56 | |
| 57 | if (interface == BT_DEV_TYPE_MMC && (boot & 1)) |
| 58 | return 1; |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | static ulong spl_romapi_read_seekable(struct spl_load_info *load, |
Sean Anderson | 7d8d613 | 2023-11-08 11:48:40 -0500 | [diff] [blame] | 64 | ulong offset, ulong byte, |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 65 | void *buf) |
| 66 | { |
Sean Anderson | 7d8d613 | 2023-11-08 11:48:40 -0500 | [diff] [blame] | 67 | return spl_romapi_raw_seekable_read(offset, byte, buf); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image, |
| 71 | struct spl_boot_device *bootdev, |
| 72 | u32 rom_bt_dev) |
| 73 | { |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 74 | int ret; |
| 75 | u32 offset; |
| 76 | u32 pagesize, size; |
Simon Glass | bb7d3bb | 2022-09-06 20:26:52 -0600 | [diff] [blame] | 77 | struct legacy_img_hdr *header; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 78 | u32 image_offset; |
| 79 | |
Rasmus Villemoes | 9bfb1ba | 2022-06-20 10:53:20 +0200 | [diff] [blame] | 80 | ret = rom_api_query_boot_infor(QUERY_IVT_OFF, &offset); |
Marek Vasut | 0063916 | 2023-07-02 03:03:51 +0200 | [diff] [blame] | 81 | if (ret != ROM_API_OKAY) |
| 82 | goto err; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 83 | |
Marek Vasut | 0063916 | 2023-07-02 03:03:51 +0200 | [diff] [blame] | 84 | ret = rom_api_query_boot_infor(QUERY_PAGE_SZ, &pagesize); |
| 85 | if (ret != ROM_API_OKAY) |
| 86 | goto err; |
| 87 | |
| 88 | ret = rom_api_query_boot_infor(QUERY_IMG_OFF, &image_offset); |
| 89 | if (ret != ROM_API_OKAY) |
| 90 | goto err; |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 91 | |
Simon Glass | bb7d3bb | 2022-09-06 20:26:52 -0600 | [diff] [blame] | 92 | header = (struct legacy_img_hdr *)(CONFIG_SPL_IMX_ROMAPI_LOADADDR); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 93 | |
| 94 | printf("image offset 0x%x, pagesize 0x%x, ivt offset 0x%x\n", |
| 95 | image_offset, pagesize, offset); |
| 96 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 97 | offset = spl_romapi_get_uboot_base(image_offset, rom_bt_dev); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 98 | |
Simon Glass | bb7d3bb | 2022-09-06 20:26:52 -0600 | [diff] [blame] | 99 | size = ALIGN(sizeof(struct legacy_img_hdr), pagesize); |
Rasmus Villemoes | 9bfb1ba | 2022-06-20 10:53:20 +0200 | [diff] [blame] | 100 | ret = rom_api_download_image((u8 *)header, offset, size); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 101 | |
| 102 | if (ret != ROM_API_OKAY) { |
| 103 | printf("ROMAPI: download failure offset 0x%x size 0x%x\n", |
| 104 | offset, size); |
| 105 | return -1; |
| 106 | } |
| 107 | |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 108 | if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) && image_get_magic(header) == FDT_MAGIC) { |
| 109 | struct spl_load_info load; |
| 110 | |
| 111 | memset(&load, 0, sizeof(load)); |
Sean Anderson | 35f15fe | 2023-11-08 11:48:43 -0500 | [diff] [blame] | 112 | spl_set_bl_len(&load, pagesize); |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 113 | load.read = spl_romapi_read_seekable; |
Sean Anderson | 7d8d613 | 2023-11-08 11:48:40 -0500 | [diff] [blame] | 114 | return spl_load_simple_fit(spl_image, &load, offset, header); |
Sean Anderson | 952ed67 | 2023-10-14 16:47:44 -0400 | [diff] [blame] | 115 | } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) && |
| 116 | valid_container_hdr((void *)header)) { |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 117 | struct spl_load_info load; |
| 118 | |
| 119 | memset(&load, 0, sizeof(load)); |
Sean Anderson | 35f15fe | 2023-11-08 11:48:43 -0500 | [diff] [blame] | 120 | spl_set_bl_len(&load, pagesize); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 121 | load.read = spl_romapi_read_seekable; |
Ye Li | 7a71c61 | 2021-08-07 16:00:39 +0800 | [diff] [blame] | 122 | |
Sean Anderson | 7d8d613 | 2023-11-08 11:48:40 -0500 | [diff] [blame] | 123 | ret = spl_load_imx_container(spl_image, &load, offset); |
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 | |
Marcel Ziswiler | 4bd847f | 2023-10-26 09:32:20 +0200 | [diff] [blame] | 165 | ss->end += bytes; |
Rasmus Villemoes | 51600f1 | 2023-09-19 15:49:31 +0200 | [diff] [blame] | 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) { |
Marcel Ziswiler | 0f38fef | 2023-10-26 09:32:19 +0200 | [diff] [blame] | 288 | puts("Stream(USB) download failure\n"); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 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) { |
Marcel Ziswiler | 0f38fef | 2023-10-26 09:32:19 +0200 | [diff] [blame] | 308 | puts("Stream(USB) download failure\n"); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 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)); |
Sean Anderson | 35f15fe | 2023-11-08 11:48:43 -0500 | [diff] [blame] | 345 | spl_set_bl_len(&load, 1); |
Rasmus Villemoes | 51600f1 | 2023-09-19 15:49:31 +0200 | [diff] [blame] | 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)); |
Sean Anderson | 35f15fe | 2023-11-08 11:48:43 -0500 | [diff] [blame] | 369 | spl_set_bl_len(&load, 1); |
Peng Fan | 3698679 | 2019-09-16 03:09:31 +0000 | [diff] [blame] | 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 | } |