xref: /rk3399_rockchip-uboot/common/main.c (revision 1364a0e48a64a29930a8b22620f420e8f4984cc7)
1 /*
2  * (C) Copyright 2000
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 /* #define	DEBUG	*/
9 
10 #include <common.h>
11 #include <autoboot.h>
12 #include <cli.h>
13 #include <cli_hush.h>
14 #include <malloc.h>
15 #include <version.h>
16 
17 DECLARE_GLOBAL_DATA_PTR;
18 
19 /*
20  * Board-specific Platform code can reimplement show_boot_progress () if needed
21  */
22 void inline __show_boot_progress (int val) {}
23 void show_boot_progress (int val) __attribute__((weak, alias("__show_boot_progress")));
24 
25 static void modem_init(void)
26 {
27 #ifdef CONFIG_MODEM_SUPPORT
28 	debug("DEBUG: main_loop:   gd->do_mdm_init=%lu\n", gd->do_mdm_init);
29 	if (gd->do_mdm_init) {
30 		char *str = strdup(getenv("mdm_cmd"));
31 		setenv("preboot", str);  /* set or delete definition */
32 		if (str != NULL)
33 			free(str);
34 		mdm_init(); /* wait for modem connection */
35 	}
36 #endif  /* CONFIG_MODEM_SUPPORT */
37 }
38 
39 static void run_preboot_environment_command(void)
40 {
41 #ifdef CONFIG_PREBOOT
42 	char *p;
43 
44 	p = getenv("preboot");
45 	if (p != NULL) {
46 # ifdef CONFIG_AUTOBOOT_KEYED
47 		int prev = disable_ctrlc(1);	/* disable Control C checking */
48 # endif
49 
50 		run_command_list(p, -1, 0);
51 
52 # ifdef CONFIG_AUTOBOOT_KEYED
53 		disable_ctrlc(prev);	/* restore Control C checking */
54 # endif
55 	}
56 #endif /* CONFIG_PREBOOT */
57 }
58 
59 void main_loop(void)
60 {
61 	bootstage_mark_name(BOOTSTAGE_ID_MAIN_LOOP, "main_loop");
62 
63 #ifndef CONFIG_SYS_GENERIC_BOARD
64 	puts("Warning: Your board does not use generic board. Please read\n");
65 	puts("doc/README.generic-board and take action. Boards not\n");
66 	puts("upgraded by the late 2014 may break or be removed.\n");
67 #endif
68 
69 	modem_init();
70 #ifdef CONFIG_VERSION_VARIABLE
71 	setenv("ver", version_string);  /* set version variable */
72 #endif /* CONFIG_VERSION_VARIABLE */
73 
74 #ifdef CONFIG_SYS_HUSH_PARSER
75 	u_boot_hush_start();
76 #endif
77 
78 #if defined(CONFIG_HUSH_INIT_VAR)
79 	hush_init_var();
80 #endif
81 
82 	run_preboot_environment_command();
83 
84 #if defined(CONFIG_UPDATE_TFTP)
85 	update_tftp(0UL);
86 #endif /* CONFIG_UPDATE_TFTP */
87 
88 	bootdelay_process();
89 	/*
90 	 * Main Loop for Monitor Command Processing
91 	 */
92 #ifdef CONFIG_SYS_HUSH_PARSER
93 	parse_file_outer();
94 	/* This point is never reached */
95 	for (;;);
96 #else
97 	cli_loop();
98 #endif /*CONFIG_SYS_HUSH_PARSER*/
99 }
100