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 <button.h>
12#include <bootstage.h>
13#include <bootstd.h>
14#include <cli.h>
15#include <command.h>
16#include <console.h>
17#include <env.h>
18#include <fdtdec.h>
19#include <init.h>
20#include <net.h>
21#include <version_string.h>
22#include <efi_loader.h>
23
24static void run_preboot_environment_command(void)
25{
26	char *p;
27
28	p = env_get("preboot");
29	if (p != NULL) {
30		int prev = 0;
31
32		if (IS_ENABLED(CONFIG_AUTOBOOT_KEYED))
33			prev = disable_ctrlc(1); /* disable Ctrl-C checking */
34
35		run_command_list(p, -1, 0);
36
37		if (IS_ENABLED(CONFIG_AUTOBOOT_KEYED))
38			disable_ctrlc(prev);	/* restore Ctrl-C checking */
39	}
40}
41
42/* We come here after U-Boot is initialised and ready to process commands */
43void main_loop(void)
44{
45	const char *s;
46
47	bootstage_mark_name(BOOTSTAGE_ID_MAIN_LOOP, "main_loop");
48
49	if (IS_ENABLED(CONFIG_VERSION_VARIABLE))
50		env_set("ver", version_string);  /* set version variable */
51
52	cli_init();
53
54	if (IS_ENABLED(CONFIG_USE_PREBOOT))
55		run_preboot_environment_command();
56
57	if (IS_ENABLED(CONFIG_UPDATE_TFTP))
58		update_tftp(0UL, NULL, NULL);
59
60	if (IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK_EARLY)) {
61		/* efi_init_early() already called */
62		if (efi_init_obj_list() == EFI_SUCCESS)
63			efi_launch_capsules();
64	}
65
66	process_button_cmds();
67
68	s = bootdelay_process();
69	if (cli_process_fdt(&s))
70		cli_secure_boot_cmd(s);
71
72	autoboot_command(s);
73
74	/* if standard boot if enabled, assume that it will be able to boot */
75	if (IS_ENABLED(CONFIG_BOOTSTD_PROG)) {
76		int ret;
77
78		ret = bootstd_prog_boot();
79		printf("Standard boot failed (err=%dE)\n", ret);
80		panic("Failed to boot");
81	}
82
83	cli_loop();
84
85	panic("No CLI available");
86}
87