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