1 #include <common.h>
2 #include <command.h>
3 #include "menu.h"
4 #include "bootselect_menu.h"
5 #include "creation.h"
6 #include "bios_menu.h"
7 #include <asm/processor.h>
8
9 static form_t *root = 0;
10 static form_t *bootselect = 0;
11
12 #define MAIN_MENU_NAME "U-BOOT Preferences Menu"
13 #define BOOT_MENU_NAME "U-Boot Boot Select"
14
15 static void establish_menu_settings(void);
16 static int do_menu_countdown(void);
17 static int fromsilent = 0;
18
19 DECLARE_GLOBAL_DATA_PTR;
20
show_and_do_boot_select(void)21 int show_and_do_boot_select(void)
22 {
23 unsigned long delta = TEXT_BASE - gd->relocaddr;
24
25 menu_item_relocate(delta);
26
27 bootselect = new_form(BOOT_MENU_NAME);
28 if (!bootselect) return 0;
29
30 make_bootselect_menu(bootselect);
31 menu_set_form(bootselect);
32 menu_form_switch_menu(bootselect, BOOT_MENU_NAME);
33 menu_do(false);
34
35 return return_value;
36 }
37
show_and_do_bios_menu(void)38 void show_and_do_bios_menu(void)
39 {
40 unsigned long delta = TEXT_BASE - gd->relocaddr;
41
42 menu_item_relocate(delta);
43
44 root = new_form("U-BOOT Setup Menu");
45 if (!root) return;
46
47 make_menus(root);
48 menu_set_form(root);
49 menu_form_switch_menu(root, MAIN_MENU_NAME);
50 menu_do(true);
51 }
52
do_menu_countdown(void)53 static int do_menu_countdown(void)
54 {
55 int bootdelay;
56 int current;
57 char *s, c;
58
59 bootdelay = 0;
60 s = GETENV("menuboot_delay");
61
62 if (s) bootdelay = atoi(s);
63
64 if (bootdelay == 0)
65 {
66 if (tstc() != -1) return 1;
67 else return 0;
68 }
69
70 putc('\n');
71 if (fromsilent) puts(" ");
72 puts("Press SPACE for prefs, ENTER for boot select, ESC for prompt\n");
73 if (fromsilent) puts(" ");
74 puts("Booting... ");
75
76 current = 0;
77 while (current < bootdelay)
78 {
79 int i;
80
81 printf("\b\b\b%2d ", bootdelay - current);
82
83 for (i=0; i<1000; i++)
84 {
85 if (tstc())
86 {
87 c = getc();
88
89 // ESC
90 if ((c == 5) || (c == 113)) return -10;
91
92 // ENTER
93 if (c == 13) return show_and_do_boot_select();
94
95 // SPACE
96 if (c == 32) return 1;
97 }
98 udelay(1000);
99 }
100 current++;
101 }
102
103 return 0;
104 }
105
106 extern u32 *fb_base_phys;
107 extern u32 *fb_base_phys_sm502;
108
do_menu(cmd_tbl_t * cmdtp,int flag,int argc,char * argv[])109 int do_menu( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] )
110 {
111 int ret = 0;
112
113 // if console was silent, revert it back
114 if (gd->flags & GD_FLG_SILENT) {
115 fromsilent = 1;
116 gd->flags &= ~GD_FLG_SILENT;
117 }
118
119 // only if there is an active vga -------------------------------
120 #ifdef CONFIG_SAM440EP
121 if (fb_base_phys)
122 #else
123 if ((fb_base_phys) || (fb_base_phys_sm502))
124 #endif
125 {
126 if (flag==0)
127 {
128 video_set_color(0);
129 show_and_do_bios_menu();
130 puts("\n");
131 video_set_color(0);
132 return 0;
133 }
134 else
135 {
136 ret = do_menu_countdown();
137
138 if (ret == -10)
139 {
140 puts("\b\b\b break..\n");
141 setenv("menuboot_cmd", " ");
142 return 0;
143 }
144
145 if (ret == 1)
146 {
147 video_set_color(0);
148 show_and_do_bios_menu();
149 }
150
151 video_clear_attr();
152 establish_menu_settings();
153 puts("\n");
154 video_set_color(0);
155 return 0;
156 }
157 }
158 else return -1;
159 }
160
161 /*
162 * This routine establishes all settings from the menu that aren't already done
163 * by the standard setup.
164 */
165
establish_menu_settings(void)166 static void establish_menu_settings(void)
167 {
168 boot_establish();
169
170 }
171
172 U_BOOT_CMD(
173 menu, 1, 1, do_menu,
174 "Show preferences menu",
175 "Show the preferences menu that is used to boot an OS\n"
176 );
177