Merge git://git.denx.de/u-boot-sh
[oweals/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 <init.h>
17 #include <net.h>
18 #include <version.h>
19
20 static void run_preboot_environment_command(void)
21 {
22         char *p;
23
24         p = env_get("preboot");
25         if (p != NULL) {
26                 int prev = 0;
27
28                 if (IS_ENABLED(CONFIG_AUTOBOOT_KEYED))
29                         prev = disable_ctrlc(1); /* disable Ctrl-C checking */
30
31                 run_command_list(p, -1, 0);
32
33                 if (IS_ENABLED(CONFIG_AUTOBOOT_KEYED))
34                         disable_ctrlc(prev);    /* restore Ctrl-C checking */
35         }
36 }
37
38 /* We come here after U-Boot is initialised and ready to process commands */
39 void main_loop(void)
40 {
41         const char *s;
42
43         bootstage_mark_name(BOOTSTAGE_ID_MAIN_LOOP, "main_loop");
44
45         if (IS_ENABLED(CONFIG_VERSION_VARIABLE))
46                 env_set("ver", version_string);  /* set version variable */
47
48         cli_init();
49
50         if (IS_ENABLED(CONFIG_USE_PREBOOT))
51                 run_preboot_environment_command();
52
53         if (IS_ENABLED(CONFIG_UPDATE_TFTP))
54                 update_tftp(0UL, NULL, NULL);
55
56         s = bootdelay_process();
57         if (cli_process_fdt(&s))
58                 cli_secure_boot_cmd(s);
59
60         autoboot_command(s);
61
62         cli_loop();
63         panic("No CLI available");
64 }