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