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