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