Prepare v2023.10
[platform/kernel/u-boot.git] / common / main.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2000
4  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5  */
6
7 /* #define      DEBUG   */
8
9 #include <common.h>
10 #include <autoboot.h>
11 #include <bootstage.h>
12 #include <cli.h>
13 #include <command.h>
14 #include <console.h>
15 #include <env.h>
16 #include <fdtdec.h>
17 #include <init.h>
18 #include <net.h>
19 #include <version_string.h>
20 #include <efi_loader.h>
21
22 static void run_preboot_environment_command(void)
23 {
24         char *p;
25
26         p = env_get("preboot");
27         if (p != NULL) {
28                 int prev = 0;
29
30                 if (IS_ENABLED(CONFIG_AUTOBOOT_KEYED))
31                         prev = disable_ctrlc(1); /* disable Ctrl-C checking */
32
33                 run_command_list(p, -1, 0);
34
35                 if (IS_ENABLED(CONFIG_AUTOBOOT_KEYED))
36                         disable_ctrlc(prev);    /* restore Ctrl-C checking */
37         }
38 }
39
40 /* We come here after U-Boot is initialised and ready to process commands */
41 void main_loop(void)
42 {
43         const char *s;
44
45         bootstage_mark_name(BOOTSTAGE_ID_MAIN_LOOP, "main_loop");
46
47         if (IS_ENABLED(CONFIG_VERSION_VARIABLE))
48                 env_set("ver", version_string);  /* set version variable */
49
50         cli_init();
51
52         if (IS_ENABLED(CONFIG_USE_PREBOOT))
53                 run_preboot_environment_command();
54
55         if (IS_ENABLED(CONFIG_UPDATE_TFTP))
56                 update_tftp(0UL, NULL, NULL);
57
58         if (IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK_EARLY)) {
59                 /* efi_init_early() already called */
60                 if (efi_init_obj_list() == EFI_SUCCESS)
61                         efi_launch_capsules();
62         }
63
64         s = bootdelay_process();
65         if (cli_process_fdt(&s))
66                 cli_secure_boot_cmd(s);
67
68         autoboot_command(s);
69
70         cli_loop();
71         panic("No CLI available");
72 }