1 /* ----------------------------------------------------------------------- *
3 * Copyright 2009 Erwan Velu - All Rights Reserved
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use,
9 * copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following
14 * The above copyright notice and this permission notice shall
15 * be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
26 * -----------------------------------------------------------------------
31 #include <syslinux/reboot.h>
34 int start_menu_mode(struct s_hardware
*hardware
, char *version_string
)
36 struct s_hdt_menu hdt_menu
;
38 memset(&hdt_menu
, 0, sizeof(hdt_menu
));
40 /* Detect every kind of hardware */
41 detect_hardware(hardware
);
43 /* Setup the menu system */
44 setup_menu(version_string
);
46 /* Compute all submenus */
47 compute_submenus(&hdt_menu
, hardware
);
49 /* Compute the main menu */
50 compute_main_menu(&hdt_menu
, hardware
);
52 #ifdef WITH_MENU_DISPLAY
57 more_printf("Starting Menu (%d menus)\n", hdt_menu
.total_menu_count
);
58 curr
= showmenus(hdt_menu
.main_menu
.menu
);
59 /* When we exit the menu, do we have something to do? */
61 /* When want to execute something */
62 if (curr
->action
== OPT_RUN
) {
63 /* Tweak, we want to switch to the cli */
65 (curr
->data
, HDT_SWITCH_TO_CLI
, sizeof(HDT_SWITCH_TO_CLI
))) {
66 return HDT_RETURN_TO_CLI
;
69 (curr
->data
, HDT_REBOOT
, sizeof(HDT_REBOOT
))) {
72 strcpy(cmd
, curr
->data
);
74 /* Use specific syslinux call if needed */
79 return 1; // Should not happen when run from SYSLINUX
86 /* In the menu system, what to do on keyboard timeout */
87 TIMEOUTCODE
ontimeout(void)
93 /* Keyboard handler for the menu system */
94 void keys_handler(t_menusystem
* ms
95 __attribute__ ((unused
)), t_menuitem
* mi
, int scancode
)
99 /* 0xFFFF is an invalid helpid */
100 if (scancode
== KEY_F1
&& mi
->helpid
!= 0xFFFF) {
101 runhelpsystem(mi
->helpid
);
105 * If user hit TAB, and item is an "executable" item
106 * and user has privileges to edit it, edit it in place.
108 if ((scancode
== KEY_TAB
) && (mi
->action
== OPT_RUN
)) {
109 //(isallowed(username,"editcmd") || isallowed(username,"root"))) {
110 if (getscreensize(1, &nr
, &nc
)) {
111 /* Unknown screen size? */
115 /* User typed TAB and has permissions to edit command line */
116 gotoxy(EDITPROMPT
, 1);
117 csprint("Command line:", 0x07);
118 editstring(mi
->data
, ACTIONLEN
);
119 gotoxy(EDITPROMPT
, 1);
120 cprint(' ', 0x07, nc
- 1);
124 /* Setup the Menu system */
125 void setup_menu(char *version
)
127 /* Creating the menu */
128 init_menusystem(version
);
129 set_window_size(0, 0, 25, 80);
131 /* Do not use inactive attributes - they make little sense for HDT */
132 set_normal_attr(-1, -1, 0x17, 0x1F);
134 /* Register the menusystem handler */
135 // reg_handler(HDLR_SCREEN,&msys_handler);
136 reg_handler(HDLR_KEYS
, &keys_handler
);
138 /* Register the ontimeout handler, with a time out of 10 seconds */
139 reg_ontimeout(ontimeout
, 1000, 0);
142 /* Compute Main' submenus */
143 void compute_submenus(struct s_hdt_menu
*hdt_menu
, struct s_hardware
*hardware
)
146 /* Compute this menu if a DMI table exists */
147 if (hardware
->is_dmi_valid
) {
148 if (hardware
->dmi
.ipmi
.filled
== true)
149 compute_ipmi(&hdt_menu
->ipmi_menu
, &hardware
->dmi
);
150 if (hardware
->dmi
.base_board
.filled
== true)
151 compute_motherboard(&(hdt_menu
->mobo_menu
), &(hardware
->dmi
));
152 if (hardware
->dmi
.chassis
.filled
== true)
153 compute_chassis(&(hdt_menu
->chassis_menu
), &(hardware
->dmi
));
154 if (hardware
->dmi
.system
.filled
== true)
155 compute_system(&(hdt_menu
->system_menu
), &(hardware
->dmi
));
156 compute_memory(hdt_menu
, &(hardware
->dmi
), hardware
);
157 if (hardware
->dmi
.bios
.filled
== true)
158 compute_bios(&(hdt_menu
->bios_menu
), &(hardware
->dmi
));
159 if (hardware
->dmi
.battery
.filled
== true)
160 compute_battery(&(hdt_menu
->battery_menu
), &(hardware
->dmi
));
163 compute_processor(&(hdt_menu
->cpu_menu
), hardware
);
164 compute_vpd(&(hdt_menu
->vpd_menu
), hardware
);
165 compute_disks(hdt_menu
, hardware
);
168 compute_PCI(hdt_menu
, hardware
);
169 compute_PXE(&(hdt_menu
->pxe_menu
), hardware
);
170 compute_kernel(&(hdt_menu
->kernel_menu
), hardware
);
172 compute_summarymenu(&(hdt_menu
->summary_menu
), hardware
);
173 compute_syslinuxmenu(&(hdt_menu
->syslinux_menu
), hardware
);
174 compute_VESA(hdt_menu
, hardware
);
175 compute_aboutmenu(&(hdt_menu
->about_menu
));
178 void compute_main_menu(struct s_hdt_menu
*hdt_menu
, struct s_hardware
*hardware
)
181 /* Let's count the number of menus we have */
182 hdt_menu
->total_menu_count
= 0;
183 hdt_menu
->main_menu
.items_count
= 0;
185 hdt_menu
->main_menu
.menu
= add_menu(" Main Menu ", -1);
186 set_item_options(-1, 24);
189 snprintf(menu_item
, sizeof(menu_item
), "PC<I> Devices(%2d)\n",
190 hardware
->nb_pci_devices
);
191 add_item(menu_item
, "PCI Devices Menu", OPT_SUBMENU
, NULL
,
192 hdt_menu
->pci_menu
.menu
);
193 hdt_menu
->main_menu
.items_count
++;
194 hdt_menu
->total_menu_count
+= hdt_menu
->pci_menu
.items_count
;
196 if (hdt_menu
->disk_menu
.items_count
> 0) {
197 snprintf(menu_item
, sizeof(menu_item
), "<D>isks (%2d)\n",
198 hdt_menu
->disk_menu
.items_count
);
199 add_item(menu_item
, "Disks Menu", OPT_SUBMENU
, NULL
,
200 hdt_menu
->disk_menu
.menu
);
201 hdt_menu
->main_menu
.items_count
++;
202 hdt_menu
->total_menu_count
+= hdt_menu
->disk_menu
.items_count
;
205 snprintf(menu_item
, sizeof(menu_item
), "<M>emory\n");
206 add_item(menu_item
, "Memory Menu", OPT_SUBMENU
, NULL
,
207 hdt_menu
->memory_menu
.menu
);
208 hdt_menu
->main_menu
.items_count
++;
209 hdt_menu
->total_menu_count
+= hdt_menu
->memory_menu
.items_count
;
211 add_item("<P>rocessor", "Main Processor Menu", OPT_SUBMENU
, NULL
,
212 hdt_menu
->cpu_menu
.menu
);
213 hdt_menu
->main_menu
.items_count
++;
215 if (hardware
->is_dmi_valid
) {
216 if (hardware
->dmi
.base_board
.filled
== true) {
217 add_item("M<o>therboard", "Motherboard Menu",
218 OPT_SUBMENU
, NULL
, hdt_menu
->mobo_menu
.menu
);
219 hdt_menu
->main_menu
.items_count
++;
222 if (hardware
->dmi
.bios
.filled
== true) {
223 add_item("<B>ios", "Bios Menu", OPT_SUBMENU
, NULL
,
224 hdt_menu
->bios_menu
.menu
);
225 hdt_menu
->main_menu
.items_count
++;
228 if (hardware
->dmi
.chassis
.filled
== true) {
229 add_item("<C>hassis", "Chassis Menu", OPT_SUBMENU
, NULL
,
230 hdt_menu
->chassis_menu
.menu
);
231 hdt_menu
->main_menu
.items_count
++;
234 if (hardware
->dmi
.system
.filled
== true) {
235 add_item("<S>ystem", "System Menu", OPT_SUBMENU
, NULL
,
236 hdt_menu
->system_menu
.menu
);
237 hdt_menu
->main_menu
.items_count
++;
240 if (hardware
->dmi
.battery
.filled
== true) {
241 add_item("Ba<t>tery", "Battery Menu", OPT_SUBMENU
, NULL
,
242 hdt_menu
->battery_menu
.menu
);
243 hdt_menu
->main_menu
.items_count
++;
245 if (hardware
->dmi
.ipmi
.filled
== true) {
246 add_item("I<P>MI", "IPMI Menu", OPT_SUBMENU
, NULL
,
247 hdt_menu
->ipmi_menu
.menu
);
248 hdt_menu
->main_menu
.items_count
++;
252 if (hardware
->is_vpd_valid
== true) {
253 add_item("<V>PD", "VPD Information Menu", OPT_SUBMENU
, NULL
,
254 hdt_menu
->vpd_menu
.menu
);
255 hdt_menu
->main_menu
.items_count
++;
258 if (hardware
->is_pxe_valid
== true) {
259 add_item("P<X>E", "PXE Information Menu", OPT_SUBMENU
, NULL
,
260 hdt_menu
->pxe_menu
.menu
);
261 hdt_menu
->main_menu
.items_count
++;
264 if (hardware
->is_vesa_valid
== true) {
265 add_item("<V>ESA", "VESA Information Menu", OPT_SUBMENU
, NULL
,
266 hdt_menu
->vesa_menu
.menu
);
267 hdt_menu
->main_menu
.items_count
++;
270 add_item("", "", OPT_SEP
, "", 0);
272 if ((hardware
->modules_pcimap_return_code
!= -ENOMODULESPCIMAP
) ||
273 (hardware
->modules_alias_return_code
!= -ENOMODULESALIAS
)) {
274 add_item("<K>ernel Modules", "Kernel Modules Menu", OPT_SUBMENU
,
275 NULL
, hdt_menu
->kernel_menu
.menu
);
276 hdt_menu
->main_menu
.items_count
++;
279 add_item("S<y>slinux", "Syslinux Information Menu", OPT_SUBMENU
, NULL
,
280 hdt_menu
->syslinux_menu
.menu
);
281 hdt_menu
->main_menu
.items_count
++;
282 add_item("S<u>mmary", "Summary Information Menu", OPT_SUBMENU
, NULL
,
283 hdt_menu
->summary_menu
.menu
);
284 hdt_menu
->main_menu
.items_count
++;
286 add_item("", "", OPT_SEP
, "", 0);
288 add_item("S<w>itch to CLI", "Switch to Command Line", OPT_RUN
,
289 HDT_SWITCH_TO_CLI
, 0);
290 add_item("<A>bout", "About Menu", OPT_SUBMENU
, NULL
,
291 hdt_menu
->about_menu
.menu
);
292 add_item("<R>eboot", "Reboot", OPT_RUN
, HDT_REBOOT
, 0);
293 add_item("E<x>it", "Exit", OPT_EXITMENU
, NULL
, 0);
294 hdt_menu
->main_menu
.items_count
++;
296 hdt_menu
->total_menu_count
+= hdt_menu
->main_menu
.items_count
;
299 void detect_hardware(struct s_hardware
*hardware
)
302 more_printf("MEMORY: Detecting\n");
303 detect_memory(hardware
);
306 more_printf("DMI: Detecting Table\n");
307 if (detect_dmi(hardware
) == -ENODMITABLE
) {
308 printf("DMI: ERROR ! Table not found ! \n");
309 printf("DMI: Many hardware components will not be detected ! \n");
312 more_printf("DMI: Table found ! (version %u.%u)\n",
313 hardware
->dmi
.dmitable
.major_version
,
314 hardware
->dmi
.dmitable
.minor_version
);
318 more_printf("CPU: Detecting\n");
319 cpu_detect(hardware
);
322 more_printf("DISKS: Detecting\n");
323 detect_disks(hardware
);
326 more_printf("VPD: Detecting\n");
327 detect_vpd(hardware
);
330 detect_pci(hardware
);
332 more_printf("PCI: %d Devices Found\n", hardware
->nb_pci_devices
);
335 more_printf("VESA: Detecting\n");
336 detect_vesa(hardware
);