Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000-2009 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <bootm.h> |
Simon Glass | 1ea9789 | 2020-05-10 11:40:00 -0600 | [diff] [blame] | 9 | #include <bootstage.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 10 | #include <cpu_func.h> |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 11 | #include <efi_loader.h> |
Simon Glass | 313112a | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 12 | #include <env.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 13 | #include <fdt_support.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 14 | #include <image.h> |
| 15 | #include <lmb.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 16 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame^] | 17 | #include <asm/global_data.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 18 | #include <linux/libfdt.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 19 | #include <malloc.h> |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 20 | #include <mapmem.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 21 | #include <vxworks.h> |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 22 | #include <tee/optee.h> |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 26 | static int do_bootm_standalone(int flag, int argc, char *const argv[], |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 27 | bootm_headers_t *images) |
| 28 | { |
| 29 | char *s; |
| 30 | int (*appl)(int, char *const[]); |
| 31 | |
| 32 | /* Don't start if "autostart" is set to "no" */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 33 | s = env_get("autostart"); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 34 | if ((s != NULL) && !strcmp(s, "no")) { |
Simon Glass | 4d949a2 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 35 | env_set_hex("filesize", images->os.image_len); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 36 | return 0; |
| 37 | } |
| 38 | appl = (int (*)(int, char * const []))images->ep; |
| 39 | appl(argc, argv); |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | /*******************************************************************/ |
| 44 | /* OS booting routines */ |
| 45 | /*******************************************************************/ |
| 46 | |
| 47 | #if defined(CONFIG_BOOTM_NETBSD) || defined(CONFIG_BOOTM_PLAN9) |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 48 | static void copy_args(char *dest, int argc, char *const argv[], char delim) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 49 | { |
| 50 | int i; |
| 51 | |
| 52 | for (i = 0; i < argc; i++) { |
| 53 | if (i > 0) |
| 54 | *dest++ = delim; |
| 55 | strcpy(dest, argv[i]); |
| 56 | dest += strlen(argv[i]); |
| 57 | } |
| 58 | } |
| 59 | #endif |
| 60 | |
| 61 | #ifdef CONFIG_BOOTM_NETBSD |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 62 | static int do_bootm_netbsd(int flag, int argc, char *const argv[], |
| 63 | bootm_headers_t *images) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 64 | { |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 65 | void (*loader)(struct bd_info *, image_header_t *, char *, char *); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 66 | image_header_t *os_hdr, *hdr; |
| 67 | ulong kernel_data, kernel_len; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 68 | char *cmdline; |
| 69 | |
| 70 | if (flag != BOOTM_STATE_OS_GO) |
| 71 | return 0; |
| 72 | |
| 73 | #if defined(CONFIG_FIT) |
| 74 | if (!images->legacy_hdr_valid) { |
| 75 | fit_unsupported_reset("NetBSD"); |
| 76 | return 1; |
| 77 | } |
| 78 | #endif |
| 79 | hdr = images->legacy_hdr_os; |
| 80 | |
| 81 | /* |
| 82 | * Booting a (NetBSD) kernel image |
| 83 | * |
| 84 | * This process is pretty similar to a standalone application: |
| 85 | * The (first part of an multi-) image must be a stage-2 loader, |
| 86 | * which in turn is responsible for loading & invoking the actual |
| 87 | * kernel. The only differences are the parameters being passed: |
| 88 | * besides the board info strucure, the loader expects a command |
| 89 | * line, the name of the console device, and (optionally) the |
| 90 | * address of the original image header. |
| 91 | */ |
| 92 | os_hdr = NULL; |
| 93 | if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) { |
| 94 | image_multi_getimg(hdr, 1, &kernel_data, &kernel_len); |
| 95 | if (kernel_len) |
| 96 | os_hdr = hdr; |
| 97 | } |
| 98 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 99 | if (argc > 0) { |
| 100 | ulong len; |
| 101 | int i; |
| 102 | |
| 103 | for (i = 0, len = 0; i < argc; i += 1) |
| 104 | len += strlen(argv[i]) + 1; |
| 105 | cmdline = malloc(len); |
| 106 | copy_args(cmdline, argc, argv, ' '); |
| 107 | } else { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 108 | cmdline = env_get("bootargs"); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 109 | if (cmdline == NULL) |
| 110 | cmdline = ""; |
| 111 | } |
| 112 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 113 | loader = (void (*)(struct bd_info *, image_header_t *, char *, char *))images->ep; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 114 | |
| 115 | printf("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n", |
| 116 | (ulong)loader); |
| 117 | |
| 118 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 119 | |
| 120 | /* |
| 121 | * NetBSD Stage-2 Loader Parameters: |
| 122 | * arg[0]: pointer to board info data |
| 123 | * arg[1]: image load address |
| 124 | * arg[2]: char pointer to the console device to use |
| 125 | * arg[3]: char pointer to the boot arguments |
| 126 | */ |
Heiko Schocher | 65d94db | 2017-06-07 17:33:09 +0200 | [diff] [blame] | 127 | (*loader)(gd->bd, os_hdr, "", cmdline); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 128 | |
| 129 | return 1; |
| 130 | } |
| 131 | #endif /* CONFIG_BOOTM_NETBSD*/ |
| 132 | |
| 133 | #ifdef CONFIG_LYNXKDI |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 134 | static int do_bootm_lynxkdi(int flag, int argc, char *const argv[], |
| 135 | bootm_headers_t *images) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 136 | { |
| 137 | image_header_t *hdr = &images->legacy_hdr_os_copy; |
| 138 | |
| 139 | if (flag != BOOTM_STATE_OS_GO) |
| 140 | return 0; |
| 141 | |
| 142 | #if defined(CONFIG_FIT) |
| 143 | if (!images->legacy_hdr_valid) { |
| 144 | fit_unsupported_reset("Lynx"); |
| 145 | return 1; |
| 146 | } |
| 147 | #endif |
| 148 | |
| 149 | lynxkdi_boot((image_header_t *)hdr); |
| 150 | |
| 151 | return 1; |
| 152 | } |
| 153 | #endif /* CONFIG_LYNXKDI */ |
| 154 | |
| 155 | #ifdef CONFIG_BOOTM_RTEMS |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 156 | static int do_bootm_rtems(int flag, int argc, char *const argv[], |
| 157 | bootm_headers_t *images) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 158 | { |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 159 | void (*entry_point)(struct bd_info *); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 160 | |
| 161 | if (flag != BOOTM_STATE_OS_GO) |
| 162 | return 0; |
| 163 | |
| 164 | #if defined(CONFIG_FIT) |
| 165 | if (!images->legacy_hdr_valid) { |
| 166 | fit_unsupported_reset("RTEMS"); |
| 167 | return 1; |
| 168 | } |
| 169 | #endif |
| 170 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 171 | entry_point = (void (*)(struct bd_info *))images->ep; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 172 | |
| 173 | printf("## Transferring control to RTEMS (at address %08lx) ...\n", |
| 174 | (ulong)entry_point); |
| 175 | |
| 176 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 177 | |
| 178 | /* |
| 179 | * RTEMS Parameters: |
| 180 | * r3: ptr to board info data |
| 181 | */ |
| 182 | (*entry_point)(gd->bd); |
| 183 | |
| 184 | return 1; |
| 185 | } |
| 186 | #endif /* CONFIG_BOOTM_RTEMS */ |
| 187 | |
| 188 | #if defined(CONFIG_BOOTM_OSE) |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 189 | static int do_bootm_ose(int flag, int argc, char *const argv[], |
| 190 | bootm_headers_t *images) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 191 | { |
| 192 | void (*entry_point)(void); |
| 193 | |
| 194 | if (flag != BOOTM_STATE_OS_GO) |
| 195 | return 0; |
| 196 | |
| 197 | #if defined(CONFIG_FIT) |
| 198 | if (!images->legacy_hdr_valid) { |
| 199 | fit_unsupported_reset("OSE"); |
| 200 | return 1; |
| 201 | } |
| 202 | #endif |
| 203 | |
| 204 | entry_point = (void (*)(void))images->ep; |
| 205 | |
| 206 | printf("## Transferring control to OSE (at address %08lx) ...\n", |
| 207 | (ulong)entry_point); |
| 208 | |
| 209 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 210 | |
| 211 | /* |
| 212 | * OSE Parameters: |
| 213 | * None |
| 214 | */ |
| 215 | (*entry_point)(); |
| 216 | |
| 217 | return 1; |
| 218 | } |
| 219 | #endif /* CONFIG_BOOTM_OSE */ |
| 220 | |
| 221 | #if defined(CONFIG_BOOTM_PLAN9) |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 222 | static int do_bootm_plan9(int flag, int argc, char *const argv[], |
| 223 | bootm_headers_t *images) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 224 | { |
| 225 | void (*entry_point)(void); |
| 226 | char *s; |
| 227 | |
| 228 | if (flag != BOOTM_STATE_OS_GO) |
| 229 | return 0; |
| 230 | |
| 231 | #if defined(CONFIG_FIT) |
| 232 | if (!images->legacy_hdr_valid) { |
| 233 | fit_unsupported_reset("Plan 9"); |
| 234 | return 1; |
| 235 | } |
| 236 | #endif |
| 237 | |
| 238 | /* See README.plan9 */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 239 | s = env_get("confaddr"); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 240 | if (s != NULL) { |
| 241 | char *confaddr = (char *)simple_strtoul(s, NULL, 16); |
| 242 | |
| 243 | if (argc > 0) { |
| 244 | copy_args(confaddr, argc, argv, '\n'); |
| 245 | } else { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 246 | s = env_get("bootargs"); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 247 | if (s != NULL) |
| 248 | strcpy(confaddr, s); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | entry_point = (void (*)(void))images->ep; |
| 253 | |
| 254 | printf("## Transferring control to Plan 9 (at address %08lx) ...\n", |
| 255 | (ulong)entry_point); |
| 256 | |
| 257 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 258 | |
| 259 | /* |
| 260 | * Plan 9 Parameters: |
| 261 | * None |
| 262 | */ |
| 263 | (*entry_point)(); |
| 264 | |
| 265 | return 1; |
| 266 | } |
| 267 | #endif /* CONFIG_BOOTM_PLAN9 */ |
| 268 | |
| 269 | #if defined(CONFIG_BOOTM_VXWORKS) && \ |
| 270 | (defined(CONFIG_PPC) || defined(CONFIG_ARM)) |
| 271 | |
Bin Meng | b43c322 | 2018-12-21 07:13:39 -0800 | [diff] [blame] | 272 | static void do_bootvx_fdt(bootm_headers_t *images) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 273 | { |
| 274 | #if defined(CONFIG_OF_LIBFDT) |
| 275 | int ret; |
| 276 | char *bootline; |
| 277 | ulong of_size = images->ft_len; |
| 278 | char **of_flat_tree = &images->ft_addr; |
| 279 | struct lmb *lmb = &images->lmb; |
| 280 | |
| 281 | if (*of_flat_tree) { |
| 282 | boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree); |
| 283 | |
| 284 | ret = boot_relocate_fdt(lmb, of_flat_tree, &of_size); |
| 285 | if (ret) |
| 286 | return; |
| 287 | |
Hannes Schmelzer | 51962ee | 2017-08-25 14:27:37 +0200 | [diff] [blame] | 288 | /* Update ethernet nodes */ |
| 289 | fdt_fixup_ethernet(*of_flat_tree); |
| 290 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 291 | ret = fdt_add_subnode(*of_flat_tree, 0, "chosen"); |
| 292 | if ((ret >= 0 || ret == -FDT_ERR_EXISTS)) { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 293 | bootline = env_get("bootargs"); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 294 | if (bootline) { |
| 295 | ret = fdt_find_and_setprop(*of_flat_tree, |
| 296 | "/chosen", "bootargs", |
| 297 | bootline, |
| 298 | strlen(bootline) + 1, 1); |
| 299 | if (ret < 0) { |
| 300 | printf("## ERROR: %s : %s\n", __func__, |
| 301 | fdt_strerror(ret)); |
| 302 | return; |
| 303 | } |
| 304 | } |
| 305 | } else { |
| 306 | printf("## ERROR: %s : %s\n", __func__, |
| 307 | fdt_strerror(ret)); |
| 308 | return; |
| 309 | } |
| 310 | } |
| 311 | #endif |
| 312 | |
| 313 | boot_prep_vxworks(images); |
| 314 | |
| 315 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 316 | |
| 317 | #if defined(CONFIG_OF_LIBFDT) |
| 318 | printf("## Starting vxWorks at 0x%08lx, device tree at 0x%08lx ...\n", |
| 319 | (ulong)images->ep, (ulong)*of_flat_tree); |
| 320 | #else |
| 321 | printf("## Starting vxWorks at 0x%08lx\n", (ulong)images->ep); |
| 322 | #endif |
| 323 | |
| 324 | boot_jump_vxworks(images); |
| 325 | |
| 326 | puts("## vxWorks terminated\n"); |
| 327 | } |
| 328 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 329 | static int do_bootm_vxworks_legacy(int flag, int argc, char *const argv[], |
Lihua Zhao | dcda76e | 2019-11-15 00:21:17 -0800 | [diff] [blame] | 330 | bootm_headers_t *images) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 331 | { |
| 332 | if (flag != BOOTM_STATE_OS_GO) |
| 333 | return 0; |
| 334 | |
| 335 | #if defined(CONFIG_FIT) |
| 336 | if (!images->legacy_hdr_valid) { |
| 337 | fit_unsupported_reset("VxWorks"); |
| 338 | return 1; |
| 339 | } |
| 340 | #endif |
| 341 | |
| 342 | do_bootvx_fdt(images); |
| 343 | |
| 344 | return 1; |
| 345 | } |
Lihua Zhao | dcda76e | 2019-11-15 00:21:17 -0800 | [diff] [blame] | 346 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 347 | int do_bootm_vxworks(int flag, int argc, char *const argv[], |
Lihua Zhao | dcda76e | 2019-11-15 00:21:17 -0800 | [diff] [blame] | 348 | bootm_headers_t *images) |
| 349 | { |
| 350 | char *bootargs; |
| 351 | int pos; |
| 352 | unsigned long vxflags; |
| 353 | bool std_dtb = false; |
| 354 | |
| 355 | /* get bootargs env */ |
| 356 | bootargs = env_get("bootargs"); |
| 357 | |
| 358 | if (bootargs != NULL) { |
| 359 | for (pos = 0; pos < strlen(bootargs); pos++) { |
| 360 | /* find f=0xnumber flag */ |
| 361 | if ((bootargs[pos] == '=') && (pos >= 1) && |
| 362 | (bootargs[pos - 1] == 'f')) { |
| 363 | vxflags = simple_strtoul(&bootargs[pos + 1], |
| 364 | NULL, 16); |
| 365 | if (vxflags & VXWORKS_SYSFLG_STD_DTB) |
| 366 | std_dtb = true; |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | if (std_dtb) { |
| 372 | if (flag & BOOTM_STATE_OS_PREP) |
| 373 | printf(" Using standard DTB\n"); |
| 374 | return do_bootm_linux(flag, argc, argv, images); |
| 375 | } else { |
| 376 | if (flag & BOOTM_STATE_OS_PREP) |
| 377 | printf(" !!! WARNING !!! Using legacy DTB\n"); |
| 378 | return do_bootm_vxworks_legacy(flag, argc, argv, images); |
| 379 | } |
| 380 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 381 | #endif |
| 382 | |
| 383 | #if defined(CONFIG_CMD_ELF) |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 384 | static int do_bootm_qnxelf(int flag, int argc, char *const argv[], |
| 385 | bootm_headers_t *images) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 386 | { |
| 387 | char *local_args[2]; |
| 388 | char str[16]; |
Emmanuel Vadot | 9a922b4 | 2017-01-19 10:23:56 +0100 | [diff] [blame] | 389 | int dcache; |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 390 | |
| 391 | if (flag != BOOTM_STATE_OS_GO) |
| 392 | return 0; |
| 393 | |
| 394 | #if defined(CONFIG_FIT) |
| 395 | if (!images->legacy_hdr_valid) { |
| 396 | fit_unsupported_reset("QNX"); |
| 397 | return 1; |
| 398 | } |
| 399 | #endif |
| 400 | |
| 401 | sprintf(str, "%lx", images->ep); /* write entry-point into string */ |
| 402 | local_args[0] = argv[0]; |
| 403 | local_args[1] = str; /* and provide it via the arguments */ |
Emmanuel Vadot | 9a922b4 | 2017-01-19 10:23:56 +0100 | [diff] [blame] | 404 | |
| 405 | /* |
| 406 | * QNX images require the data cache is disabled. |
| 407 | */ |
| 408 | dcache = dcache_status(); |
| 409 | if (dcache) |
| 410 | dcache_disable(); |
| 411 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 412 | do_bootelf(NULL, 0, 2, local_args); |
| 413 | |
Emmanuel Vadot | 9a922b4 | 2017-01-19 10:23:56 +0100 | [diff] [blame] | 414 | if (dcache) |
| 415 | dcache_enable(); |
| 416 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 417 | return 1; |
| 418 | } |
| 419 | #endif |
| 420 | |
| 421 | #ifdef CONFIG_INTEGRITY |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 422 | static int do_bootm_integrity(int flag, int argc, char *const argv[], |
| 423 | bootm_headers_t *images) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 424 | { |
| 425 | void (*entry_point)(void); |
| 426 | |
| 427 | if (flag != BOOTM_STATE_OS_GO) |
| 428 | return 0; |
| 429 | |
| 430 | #if defined(CONFIG_FIT) |
| 431 | if (!images->legacy_hdr_valid) { |
| 432 | fit_unsupported_reset("INTEGRITY"); |
| 433 | return 1; |
| 434 | } |
| 435 | #endif |
| 436 | |
| 437 | entry_point = (void (*)(void))images->ep; |
| 438 | |
| 439 | printf("## Transferring control to INTEGRITY (at address %08lx) ...\n", |
| 440 | (ulong)entry_point); |
| 441 | |
| 442 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 443 | |
| 444 | /* |
| 445 | * INTEGRITY Parameters: |
| 446 | * None |
| 447 | */ |
| 448 | (*entry_point)(); |
| 449 | |
| 450 | return 1; |
| 451 | } |
| 452 | #endif |
| 453 | |
Marek Vasut | 0e3b512 | 2014-12-16 14:07:21 +0100 | [diff] [blame] | 454 | #ifdef CONFIG_BOOTM_OPENRTOS |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 455 | static int do_bootm_openrtos(int flag, int argc, char *const argv[], |
| 456 | bootm_headers_t *images) |
Marek Vasut | 0e3b512 | 2014-12-16 14:07:21 +0100 | [diff] [blame] | 457 | { |
| 458 | void (*entry_point)(void); |
| 459 | |
| 460 | if (flag != BOOTM_STATE_OS_GO) |
| 461 | return 0; |
| 462 | |
| 463 | entry_point = (void (*)(void))images->ep; |
| 464 | |
| 465 | printf("## Transferring control to OpenRTOS (at address %08lx) ...\n", |
| 466 | (ulong)entry_point); |
| 467 | |
| 468 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 469 | |
| 470 | /* |
| 471 | * OpenRTOS Parameters: |
| 472 | * None |
| 473 | */ |
| 474 | (*entry_point)(); |
| 475 | |
| 476 | return 1; |
| 477 | } |
| 478 | #endif |
| 479 | |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 480 | #ifdef CONFIG_BOOTM_OPTEE |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 481 | static int do_bootm_tee(int flag, int argc, char *const argv[], |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 482 | bootm_headers_t *images) |
| 483 | { |
| 484 | int ret; |
| 485 | |
| 486 | /* Verify OS type */ |
| 487 | if (images->os.os != IH_OS_TEE) { |
| 488 | return 1; |
| 489 | }; |
| 490 | |
| 491 | /* Validate OPTEE header */ |
| 492 | ret = optee_verify_bootm_image(images->os.image_start, |
| 493 | images->os.load, |
| 494 | images->os.image_len); |
| 495 | if (ret) |
| 496 | return ret; |
| 497 | |
| 498 | /* Locate FDT etc */ |
Tero Kristo | 0608694 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 499 | ret = bootm_find_images(flag, argc, argv, 0, 0); |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 500 | if (ret) |
| 501 | return ret; |
| 502 | |
| 503 | /* From here we can run the regular linux boot path */ |
| 504 | return do_bootm_linux(flag, argc, argv, images); |
| 505 | } |
| 506 | #endif |
| 507 | |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 508 | #ifdef CONFIG_BOOTM_EFI |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 509 | static int do_bootm_efi(int flag, int argc, char *const argv[], |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 510 | bootm_headers_t *images) |
| 511 | { |
| 512 | int ret; |
| 513 | efi_status_t efi_ret; |
| 514 | void *image_buf; |
| 515 | |
| 516 | if (flag != BOOTM_STATE_OS_GO) |
| 517 | return 0; |
| 518 | |
| 519 | /* Locate FDT, if provided */ |
Tero Kristo | 0608694 | 2020-06-12 15:41:20 +0300 | [diff] [blame] | 520 | ret = bootm_find_images(flag, argc, argv, 0, 0); |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 521 | if (ret) |
| 522 | return ret; |
| 523 | |
| 524 | /* Initialize EFI drivers */ |
| 525 | efi_ret = efi_init_obj_list(); |
| 526 | if (efi_ret != EFI_SUCCESS) { |
| 527 | printf("## Failed to initialize UEFI sub-system: r = %lu\n", |
| 528 | efi_ret & ~EFI_ERROR_MASK); |
| 529 | return 1; |
| 530 | } |
| 531 | |
| 532 | /* Install device tree */ |
| 533 | efi_ret = efi_install_fdt(images->ft_len |
| 534 | ? images->ft_addr : EFI_FDT_USE_INTERNAL); |
| 535 | if (efi_ret != EFI_SUCCESS) { |
| 536 | printf("## Failed to install device tree: r = %lu\n", |
| 537 | efi_ret & ~EFI_ERROR_MASK); |
| 538 | return 1; |
| 539 | } |
| 540 | |
| 541 | /* Run EFI image */ |
| 542 | printf("## Transferring control to EFI (at address %08lx) ...\n", |
| 543 | images->ep); |
| 544 | bootstage_mark(BOOTSTAGE_ID_RUN_OS); |
| 545 | |
Heinrich Schuchardt | c663fa4 | 2020-07-18 10:54:26 +0200 | [diff] [blame] | 546 | /* We expect to return */ |
| 547 | images->os.type = IH_TYPE_STANDALONE; |
| 548 | |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 549 | image_buf = map_sysmem(images->ep, images->os.image_len); |
| 550 | |
| 551 | efi_ret = efi_run_image(image_buf, images->os.image_len); |
Heinrich Schuchardt | c663fa4 | 2020-07-18 10:54:26 +0200 | [diff] [blame] | 552 | if (efi_ret != EFI_SUCCESS) |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 553 | return 1; |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 554 | return 0; |
| 555 | } |
| 556 | #endif |
| 557 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 558 | static boot_os_fn *boot_os[] = { |
| 559 | [IH_OS_U_BOOT] = do_bootm_standalone, |
| 560 | #ifdef CONFIG_BOOTM_LINUX |
| 561 | [IH_OS_LINUX] = do_bootm_linux, |
| 562 | #endif |
| 563 | #ifdef CONFIG_BOOTM_NETBSD |
| 564 | [IH_OS_NETBSD] = do_bootm_netbsd, |
| 565 | #endif |
| 566 | #ifdef CONFIG_LYNXKDI |
| 567 | [IH_OS_LYNXOS] = do_bootm_lynxkdi, |
| 568 | #endif |
| 569 | #ifdef CONFIG_BOOTM_RTEMS |
| 570 | [IH_OS_RTEMS] = do_bootm_rtems, |
| 571 | #endif |
| 572 | #if defined(CONFIG_BOOTM_OSE) |
| 573 | [IH_OS_OSE] = do_bootm_ose, |
| 574 | #endif |
| 575 | #if defined(CONFIG_BOOTM_PLAN9) |
| 576 | [IH_OS_PLAN9] = do_bootm_plan9, |
| 577 | #endif |
| 578 | #if defined(CONFIG_BOOTM_VXWORKS) && \ |
Bin Meng | e63488f | 2018-12-21 07:13:41 -0800 | [diff] [blame] | 579 | (defined(CONFIG_PPC) || defined(CONFIG_ARM) || defined(CONFIG_RISCV)) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 580 | [IH_OS_VXWORKS] = do_bootm_vxworks, |
| 581 | #endif |
| 582 | #if defined(CONFIG_CMD_ELF) |
| 583 | [IH_OS_QNX] = do_bootm_qnxelf, |
| 584 | #endif |
| 585 | #ifdef CONFIG_INTEGRITY |
| 586 | [IH_OS_INTEGRITY] = do_bootm_integrity, |
| 587 | #endif |
Marek Vasut | 0e3b512 | 2014-12-16 14:07:21 +0100 | [diff] [blame] | 588 | #ifdef CONFIG_BOOTM_OPENRTOS |
| 589 | [IH_OS_OPENRTOS] = do_bootm_openrtos, |
| 590 | #endif |
Bryan O'Donoghue | 04ca815 | 2018-03-13 16:50:36 +0000 | [diff] [blame] | 591 | #ifdef CONFIG_BOOTM_OPTEE |
| 592 | [IH_OS_TEE] = do_bootm_tee, |
| 593 | #endif |
Cristian Ciocaltea | 6aca598 | 2019-12-24 18:05:39 +0200 | [diff] [blame] | 594 | #ifdef CONFIG_BOOTM_EFI |
| 595 | [IH_OS_EFI] = do_bootm_efi, |
| 596 | #endif |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 597 | }; |
| 598 | |
| 599 | /* Allow for arch specific config before we boot */ |
Jeroen Hofstee | f7d4a49 | 2014-07-10 23:06:25 +0200 | [diff] [blame] | 600 | __weak void arch_preboot_os(void) |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 601 | { |
| 602 | /* please define platform specific arch_preboot_os() */ |
| 603 | } |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 604 | |
Marek Vasut | 5b9fbd9 | 2018-10-04 21:16:31 +0200 | [diff] [blame] | 605 | /* Allow for board specific config before we boot */ |
| 606 | __weak void board_preboot_os(void) |
| 607 | { |
| 608 | /* please define board specific board_preboot_os() */ |
| 609 | } |
| 610 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 611 | int boot_selected_os(int argc, char *const argv[], int state, |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 612 | bootm_headers_t *images, boot_os_fn *boot_fn) |
| 613 | { |
| 614 | arch_preboot_os(); |
Marek Vasut | 5b9fbd9 | 2018-10-04 21:16:31 +0200 | [diff] [blame] | 615 | board_preboot_os(); |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 616 | boot_fn(state, argc, argv, images); |
| 617 | |
| 618 | /* Stand-alone may return when 'autostart' is 'no' */ |
| 619 | if (images->os.type == IH_TYPE_STANDALONE || |
Simon Glass | 43cdb79 | 2016-07-03 09:40:35 -0600 | [diff] [blame] | 620 | IS_ENABLED(CONFIG_SANDBOX) || |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 621 | state == BOOTM_STATE_OS_FAKE_GO) /* We expect to return */ |
| 622 | return 0; |
| 623 | bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED); |
Lukasz Majewski | 9167e10 | 2016-05-08 08:52:21 +0200 | [diff] [blame] | 624 | debug("\n## Control returned to monitor - resetting...\n"); |
| 625 | |
Simon Glass | 3b5866d | 2014-06-12 07:24:46 -0600 | [diff] [blame] | 626 | return BOOTM_ERR_RESET; |
| 627 | } |
| 628 | |
| 629 | boot_os_fn *bootm_os_get_boot_func(int os) |
| 630 | { |
| 631 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
| 632 | static bool relocated; |
| 633 | |
| 634 | if (!relocated) { |
| 635 | int i; |
| 636 | |
| 637 | /* relocate boot function table */ |
| 638 | for (i = 0; i < ARRAY_SIZE(boot_os); i++) |
| 639 | if (boot_os[i] != NULL) |
| 640 | boot_os[i] += gd->reloc_off; |
| 641 | |
| 642 | relocated = true; |
| 643 | } |
| 644 | #endif |
| 645 | return boot_os[os]; |
| 646 | } |