Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 7 | /* #define DEBUG */ |
| 8 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame^] | 9 | #include <common.h> |
Simon Glass | 7b6a95a | 2014-04-10 20:01:28 -0600 | [diff] [blame] | 10 | #include <autoboot.h> |
Caleb Connolly | 2259c29 | 2024-01-09 11:51:09 +0000 | [diff] [blame] | 11 | #include <button.h> |
Simon Glass | 1ea9789 | 2020-05-10 11:40:00 -0600 | [diff] [blame] | 12 | #include <bootstage.h> |
Simon Glass | 9236852 | 2023-11-18 14:05:19 -0700 | [diff] [blame] | 13 | #include <bootstd.h> |
Simon Glass | dec3c01 | 2014-04-10 20:01:25 -0600 | [diff] [blame] | 14 | #include <cli.h> |
Simon Glass | adaaa48 | 2019-11-14 12:57:43 -0700 | [diff] [blame] | 15 | #include <command.h> |
Simon Glass | a73bda4 | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 16 | #include <console.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 17 | #include <env.h> |
Ivan Mikhaylov | 8a80386 | 2023-03-08 01:13:39 +0000 | [diff] [blame] | 18 | #include <fdtdec.h> |
Simon Glass | a5037e2 | 2019-12-28 10:44:39 -0700 | [diff] [blame] | 19 | #include <init.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 20 | #include <net.h> |
Pali Rohár | ba87ddf | 2021-08-02 15:18:31 +0200 | [diff] [blame] | 21 | #include <version_string.h> |
AKASHI Takahiro | 45b81954 | 2020-11-17 09:27:56 +0900 | [diff] [blame] | 22 | #include <efi_loader.h> |
wdenk | 0a65855 | 2003-08-05 17:43:17 +0000 | [diff] [blame] | 23 | |
Simon Glass | 9f6bb18 | 2014-04-10 20:01:33 -0600 | [diff] [blame] | 24 | static void run_preboot_environment_command(void) |
| 25 | { |
Simon Glass | 9f6bb18 | 2014-04-10 20:01:33 -0600 | [diff] [blame] | 26 | char *p; |
| 27 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 28 | p = env_get("preboot"); |
Simon Glass | de6f0c4 | 2013-05-15 06:23:56 +0000 | [diff] [blame] | 29 | if (p != NULL) { |
Simon Glass | 9afb462 | 2018-11-25 20:05:54 -0700 | [diff] [blame] | 30 | int prev = 0; |
| 31 | |
| 32 | if (IS_ENABLED(CONFIG_AUTOBOOT_KEYED)) |
| 33 | prev = disable_ctrlc(1); /* disable Ctrl-C checking */ |
Simon Glass | de6f0c4 | 2013-05-15 06:23:56 +0000 | [diff] [blame] | 34 | |
| 35 | run_command_list(p, -1, 0); |
| 36 | |
Simon Glass | 9afb462 | 2018-11-25 20:05:54 -0700 | [diff] [blame] | 37 | if (IS_ENABLED(CONFIG_AUTOBOOT_KEYED)) |
| 38 | disable_ctrlc(prev); /* restore Ctrl-C checking */ |
Simon Glass | de6f0c4 | 2013-05-15 06:23:56 +0000 | [diff] [blame] | 39 | } |
Simon Glass | 9f6bb18 | 2014-04-10 20:01:33 -0600 | [diff] [blame] | 40 | } |
| 41 | |
Simon Glass | 5b47e30 | 2014-04-10 20:01:35 -0600 | [diff] [blame] | 42 | /* We come here after U-Boot is initialised and ready to process commands */ |
Simon Glass | 9f6bb18 | 2014-04-10 20:01:33 -0600 | [diff] [blame] | 43 | void main_loop(void) |
| 44 | { |
Simon Glass | 5b47e30 | 2014-04-10 20:01:35 -0600 | [diff] [blame] | 45 | const char *s; |
| 46 | |
Simon Glass | 9f6bb18 | 2014-04-10 20:01:33 -0600 | [diff] [blame] | 47 | bootstage_mark_name(BOOTSTAGE_ID_MAIN_LOOP, "main_loop"); |
| 48 | |
Simon Glass | 9afb462 | 2018-11-25 20:05:54 -0700 | [diff] [blame] | 49 | if (IS_ENABLED(CONFIG_VERSION_VARIABLE)) |
| 50 | env_set("ver", version_string); /* set version variable */ |
Simon Glass | 9f6bb18 | 2014-04-10 20:01:33 -0600 | [diff] [blame] | 51 | |
Simon Glass | 33f7913 | 2014-04-10 20:01:34 -0600 | [diff] [blame] | 52 | cli_init(); |
Simon Glass | 9f6bb18 | 2014-04-10 20:01:33 -0600 | [diff] [blame] | 53 | |
Simon Glass | 675cfaf | 2019-07-20 20:51:11 -0600 | [diff] [blame] | 54 | if (IS_ENABLED(CONFIG_USE_PREBOOT)) |
| 55 | run_preboot_environment_command(); |
Simon Glass | de6f0c4 | 2013-05-15 06:23:56 +0000 | [diff] [blame] | 56 | |
Simon Glass | 9afb462 | 2018-11-25 20:05:54 -0700 | [diff] [blame] | 57 | if (IS_ENABLED(CONFIG_UPDATE_TFTP)) |
| 58 | update_tftp(0UL, NULL, NULL); |
Simon Glass | de6f0c4 | 2013-05-15 06:23:56 +0000 | [diff] [blame] | 59 | |
AKASHI Takahiro | a36dc25 | 2022-04-19 10:05:11 +0900 | [diff] [blame] | 60 | if (IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK_EARLY)) { |
| 61 | /* efi_init_early() already called */ |
| 62 | if (efi_init_obj_list() == EFI_SUCCESS) |
| 63 | efi_launch_capsules(); |
| 64 | } |
AKASHI Takahiro | 45b81954 | 2020-11-17 09:27:56 +0900 | [diff] [blame] | 65 | |
Caleb Connolly | 2259c29 | 2024-01-09 11:51:09 +0000 | [diff] [blame] | 66 | process_button_cmds(); |
| 67 | |
Simon Glass | 5b47e30 | 2014-04-10 20:01:35 -0600 | [diff] [blame] | 68 | s = bootdelay_process(); |
| 69 | if (cli_process_fdt(&s)) |
| 70 | cli_secure_boot_cmd(s); |
| 71 | |
| 72 | autoboot_command(s); |
Simon Glass | 33f7913 | 2014-04-10 20:01:34 -0600 | [diff] [blame] | 73 | |
Simon Glass | 9236852 | 2023-11-18 14:05:19 -0700 | [diff] [blame] | 74 | /* if standard boot if enabled, assume that it will be able to boot */ |
| 75 | if (IS_ENABLED(CONFIG_BOOTSTD_PROG)) { |
| 76 | int ret; |
| 77 | |
| 78 | ret = bootstd_prog_boot(); |
| 79 | printf("Standard boot failed (err=%dE)\n", ret); |
| 80 | panic("Failed to boot"); |
| 81 | } |
| 82 | |
Simon Glass | 66b8c8b | 2014-04-10 20:01:26 -0600 | [diff] [blame] | 83 | cli_loop(); |
Simon Glass | 9236852 | 2023-11-18 14:05:19 -0700 | [diff] [blame] | 84 | |
Simon Glass | 2833290 | 2016-03-13 19:07:32 -0600 | [diff] [blame] | 85 | panic("No CLI available"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 86 | } |