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