X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=common%2Fbootm_os.c;h=1d58462509cc07111c0eeadcd0029ffcee2b9705;hb=548ce227d3d852455c6395c0cec30af0cda77b09;hp=d9e6e937f7ca627852d595ff23496b8d5af86fce;hpb=ebba9d1daf7745483c8078bdae18875a84df5bc1;p=oweals%2Fu-boot.git diff --git a/common/bootm_os.c b/common/bootm_os.c index d9e6e937f7..1d58462509 100644 --- a/common/bootm_os.c +++ b/common/bootm_os.c @@ -1,16 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * (C) Copyright 2000-2009 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * SPDX-License-Identifier: GPL-2.0+ */ #include #include +#include +#include +#include #include -#include +#include #include +#include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -21,9 +25,9 @@ static int do_bootm_standalone(int flag, int argc, char * const argv[], int (*appl)(int, char *const[]); /* Don't start if "autostart" is set to "no" */ - s = getenv("autostart"); + s = env_get("autostart"); if ((s != NULL) && !strcmp(s, "no")) { - setenv_hex("filesize", images->os.image_len); + env_set_hex("filesize", images->os.image_len); return 0; } appl = (int (*)(int, char * const []))images->ep; @@ -96,7 +100,7 @@ static int do_bootm_netbsd(int flag, int argc, char * const argv[], cmdline = malloc(len); copy_args(cmdline, argc, argv, ' '); } else { - cmdline = getenv("bootargs"); + cmdline = env_get("bootargs"); if (cmdline == NULL) cmdline = ""; } @@ -227,14 +231,14 @@ static int do_bootm_plan9(int flag, int argc, char * const argv[], #endif /* See README.plan9 */ - s = getenv("confaddr"); + s = env_get("confaddr"); if (s != NULL) { char *confaddr = (char *)simple_strtoul(s, NULL, 16); if (argc > 0) { copy_args(confaddr, argc, argv, '\n'); } else { - s = getenv("bootargs"); + s = env_get("bootargs"); if (s != NULL) strcpy(confaddr, s); } @@ -260,7 +264,7 @@ static int do_bootm_plan9(int flag, int argc, char * const argv[], #if defined(CONFIG_BOOTM_VXWORKS) && \ (defined(CONFIG_PPC) || defined(CONFIG_ARM)) -void do_bootvx_fdt(bootm_headers_t *images) +static void do_bootvx_fdt(bootm_headers_t *images) { #if defined(CONFIG_OF_LIBFDT) int ret; @@ -276,9 +280,12 @@ void do_bootvx_fdt(bootm_headers_t *images) if (ret) return; + /* Update ethernet nodes */ + fdt_fixup_ethernet(*of_flat_tree); + ret = fdt_add_subnode(*of_flat_tree, 0, "chosen"); if ((ret >= 0 || ret == -FDT_ERR_EXISTS)) { - bootline = getenv("bootargs"); + bootline = env_get("bootargs"); if (bootline) { ret = fdt_find_and_setprop(*of_flat_tree, "/chosen", "bootargs", @@ -314,8 +321,8 @@ void do_bootvx_fdt(bootm_headers_t *images) puts("## vxWorks terminated\n"); } -static int do_bootm_vxworks(int flag, int argc, char * const argv[], - bootm_headers_t *images) +static int do_bootm_vxworks_legacy(int flag, int argc, char * const argv[], + bootm_headers_t *images) { if (flag != BOOTM_STATE_OS_GO) return 0; @@ -331,6 +338,41 @@ static int do_bootm_vxworks(int flag, int argc, char * const argv[], return 1; } + +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\n"); + return do_bootm_linux(flag, argc, argv, images); + } else { + if (flag & BOOTM_STATE_OS_PREP) + printf(" !!! WARNING !!! Using legacy DTB\n"); + return do_bootm_vxworks_legacy(flag, argc, argv, images); + } +} #endif #if defined(CONFIG_CMD_ELF) @@ -430,6 +472,85 @@ static int do_bootm_openrtos(int flag, int argc, char * const argv[], } #endif +#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 + +#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\n", + 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\n", + efi_ret & ~EFI_ERROR_MASK); + return 1; + } + + /* Run EFI image */ + printf("## Transferring control to EFI (at address %08lx) ...\n", + 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\n", + efi_ret & ~EFI_ERROR_MASK); + return 1; + } + + return 0; +} +#endif + static boot_os_fn *boot_os[] = { [IH_OS_U_BOOT] = do_bootm_standalone, #ifdef CONFIG_BOOTM_LINUX @@ -451,7 +572,7 @@ static boot_os_fn *boot_os[] = { [IH_OS_PLAN9] = do_bootm_plan9, #endif #if defined(CONFIG_BOOTM_VXWORKS) && \ - (defined(CONFIG_PPC) || defined(CONFIG_ARM)) + (defined(CONFIG_PPC) || defined(CONFIG_ARM) || defined(CONFIG_RISCV)) [IH_OS_VXWORKS] = do_bootm_vxworks, #endif #if defined(CONFIG_CMD_ELF) @@ -463,6 +584,12 @@ static boot_os_fn *boot_os[] = { #ifdef CONFIG_BOOTM_OPENRTOS [IH_OS_OPENRTOS] = do_bootm_openrtos, #endif +#ifdef CONFIG_BOOTM_OPTEE + [IH_OS_TEE] = do_bootm_tee, +#endif +#ifdef CONFIG_BOOTM_EFI + [IH_OS_EFI] = do_bootm_efi, +#endif }; /* Allow for arch specific config before we boot */ @@ -471,10 +598,17 @@ __weak void arch_preboot_os(void) /* please define platform specific arch_preboot_os() */ } +/* Allow for board specific config before we boot */ +__weak void board_preboot_os(void) +{ + /* please define board specific board_preboot_os() */ +} + int boot_selected_os(int argc, char * const argv[], int state, bootm_headers_t *images, boot_os_fn *boot_fn) { arch_preboot_os(); + board_preboot_os(); boot_fn(state, argc, argv, images); /* Stand-alone may return when 'autostart' is 'no' */