1 /* ----------------------------------------------------------------------- *
3 * Copyright 2009 Pierre-Alexandre Meyer - 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 * -----------------------------------------------------------------------
32 #include <syslinux/config.h>
33 #include <syslinux/reboot.h>
37 #include "hdt-common.h"
40 * cli_clear_screen - clear (erase) the entire screen
42 static void cli_clear_screen(int argc __unused
, char **argv __unused
,
43 struct s_hardware
*hardware __unused
)
49 * main_show_modes - show availables modes
51 static void main_show_modes(int argc __unused
, char **argv __unused
,
52 struct s_hardware
*hardware __unused
)
57 printf("Available modes:\n");
58 while (list_modes
[i
]) {
59 printf("%s ", list_modes
[i
]->name
);
66 * cli_set_mode - set the mode of the cli, in the cli
68 * The mode number must be supplied in argv, position 0.
70 static void cli_set_mode(int argc
, char **argv
, struct s_hardware
*hardware
)
76 more_printf("Which mode?\n");
81 * Note! argv[0] is a string representing the mode, we need the
82 * equivalent cli_mode_t to pass it to set_mode.
84 new_mode
= mode_s_to_mode_t(argv
[0]);
85 set_mode(new_mode
, hardware
);
89 * do_exit - shared helper to exit a mode
91 static void do_exit(int argc __unused
, char **argv __unused
,
92 struct s_hardware
*hardware
)
94 int new_mode
= HDT_MODE
;
96 switch (hdt_cli
.mode
) {
105 dprintf("CLI DEBUG: Switching from mode %d to mode %d\n", hdt_cli
.mode
,
107 set_mode(new_mode
, hardware
);
111 * show_cli_help - shared helper to show available commands
113 static void show_cli_help(int argc __unused
, char **argv __unused
,
114 struct s_hardware
*hardware __unused
)
117 struct cli_mode_descr
*current_mode
;
118 struct cli_callback_descr
*associated_module
= NULL
;
120 find_cli_mode_descr(hdt_cli
.mode
, ¤t_mode
);
122 printf("Available commands are:\n");
124 /* List first default modules of the mode */
125 if (current_mode
->default_modules
&& current_mode
->default_modules
->modules
) {
126 while (current_mode
->default_modules
->modules
[j
].name
) {
127 printf("%s ", current_mode
->default_modules
->modules
[j
].name
);
133 /* List finally the default modules of the hdt mode */
134 if (current_mode
->mode
!= hdt_mode
.mode
&&
135 hdt_mode
.default_modules
&& hdt_mode
.default_modules
->modules
) {
137 while (hdt_mode
.default_modules
->modules
[j
].name
) {
139 * Any default command that is present in hdt mode but
140 * not in the current mode is available. A default
141 * command can be redefined in the current mode though.
142 * This next call test this use case: if it is
143 * overwritten, do not print it again.
145 find_cli_callback_descr(hdt_mode
.default_modules
->modules
[j
].name
,
146 current_mode
->default_modules
,
148 if (associated_module
== NULL
)
149 printf("%s ", hdt_mode
.default_modules
->modules
[j
].name
);
155 /* List secondly the show modules of the mode */
156 if (current_mode
->show_modules
&& current_mode
->show_modules
->modules
) {
157 printf("\nshow commands:\n");
159 while (current_mode
->show_modules
->modules
[j
].name
) {
160 printf("%s ", current_mode
->show_modules
->modules
[j
].name
);
166 /* List thirdly the set modules of the mode */
167 if (current_mode
->set_modules
&& current_mode
->set_modules
->modules
) {
168 printf("\nset commands:\n");
170 while (current_mode
->set_modules
->modules
[j
].name
) {
171 printf("%s ", current_mode
->set_modules
->modules
[j
].name
);
179 main_show_modes(argc
, argv
, hardware
);
183 * show_cli_help - shared helper to show available commands
185 static void goto_menu(int argc __unused
, char **argv __unused
,
186 struct s_hardware
*hardware
)
188 char version_string
[256];
189 snprintf(version_string
, sizeof version_string
, "%s %s (%s)",
190 PRODUCT_NAME
, VERSION
, CODENAME
);
191 start_menu_mode(hardware
, version_string
);
196 * main_show_summary - give an overview of the system
198 void main_show_summary(int argc __unused
, char **argv __unused
,
199 struct s_hardware
*hardware
)
203 main_show_cpu(argc
, argv
, hardware
);
204 if (hardware
->is_dmi_valid
) {
205 more_printf("System\n");
206 more_printf(" Manufacturer : %s\n", hardware
->dmi
.system
.manufacturer
);
207 more_printf(" Product Name : %s\n", hardware
->dmi
.system
.product_name
);
208 more_printf(" Serial : %s\n", hardware
->dmi
.system
.serial
);
209 more_printf("Bios\n");
210 more_printf(" Version : %s\n", hardware
->dmi
.bios
.version
);
211 more_printf(" Release : %s\n", hardware
->dmi
.bios
.release_date
);
212 more_printf("Memory Size : %lu MB (%lu KB)\n",
213 (hardware
->detected_memory_size
+ (1 << 9)) >> 10,
214 hardware
->detected_memory_size
);
216 main_show_pci(argc
, argv
, hardware
);
218 if (hardware
->is_pxe_valid
)
219 main_show_pxe(argc
, argv
, hardware
);
221 main_show_kernel(argc
, argv
, hardware
);
224 void main_show_hdt(int argc __unused
, char **argv __unused
,
225 struct s_hardware
*hardware __unused
)
228 more_printf("HDT\n");
229 more_printf(" Product : %s\n", PRODUCT_NAME
);
230 more_printf(" Version : %s (%s)\n", VERSION
, CODENAME
);
231 more_printf(" Website : %s\n", WEBSITE_URL
);
232 more_printf(" IRC Channel : %s\n", IRC_CHANNEL
);
233 more_printf(" Mailing List : %s\n", CONTACT
);
234 more_printf(" Project Leader : %s\n", AUTHOR
);
235 more_printf(" Core Developer : %s\n", CORE_DEVELOPER
);
236 char *contributors
[NB_CONTRIBUTORS
] = CONTRIBUTORS
;
237 for (int c
= 0; c
< NB_CONTRIBUTORS
; c
++) {
238 more_printf(" Contributor : %s\n", contributors
[c
]);
243 * do_reboot - reboot the system
245 static void do_reboot(int argc __unused
, char **argv __unused
,
246 struct s_hardware
*hardware
)
249 /* Let's call the internal rebooting call */
254 * do_dump - dump info
256 static void do_dump(int argc __unused
, char **argv __unused
,
257 struct s_hardware
*hardware
)
263 * do_display - display an image to user
265 static void do_display(int argc
, char **argv
,
266 struct s_hardware
*hardware
)
269 if ((argc
!= 1) || (vesamode
== false)) return;
270 printf("Display %s file\n",argv
[0]);
271 vesacon_load_background(argv
[0]);
275 * do_say - say message to user
277 static void do_say(int argc
, char **argv
,
278 struct s_hardware
*hardware
)
281 if (argc
== 0) return;
283 char text_to_say
[255]={0};
287 for (int i
=0; i
<argc
;i
++) dprintf("SAY: arg[%d]={%s}\n",i
,argv
[i
]);
289 char *argument
= strchr(argv
[arg
],'`');
290 if ( argument
!= NULL
) {
292 strcat(text_to_say
, argument
);
294 while ((strchr(argument
, '`') == NULL
) && (arg
+1<argc
)) {
296 argument
= (char *)argv
[arg
];
297 strcat(text_to_say
, " ");
298 strcat(text_to_say
, argument
);
301 /* Removing last ` if any */
302 char *last_quote
= strrchr(text_to_say
,'`');
303 if ( last_quote
!= NULL
) {
305 dprintf("SAY CMD = [%s]\n",text_to_say
);
308 /* The % char can be in the same argument, let's consider it again */
311 /* Searching for a % argument to determine the time to show the message */
312 char *time_to_display
= NULL
;
313 /* Search for a requested time to display */
314 while ( ((time_to_display
=strchr(argument
, '%')) == NULL
) && (arg
+1<argc
)) {
316 argument
= (char *)argv
[arg
];
319 if (time_to_display
!= NULL
) {
320 sleep_time
=atoi(time_to_display
+1);
321 dprintf("SAY CMD :Time to display = %d\n",sleep_time
);
324 printf("%s\n",text_to_say
);
329 /* Default hdt mode */
330 struct cli_callback_descr list_hdt_default_modules
[] = {
333 .exec
= cli_clear_screen
,
343 .exec
= show_cli_help
,
358 .exec
= print_history
,
382 struct cli_callback_descr list_hdt_show_modules
[] = {
385 .exec
= main_show_summary
,
390 .exec
= main_show_pci
,
395 .exec
= main_show_dmi
,
400 .exec
= main_show_cpu
,
405 .exec
= disks_summary
,
410 .exec
= main_show_pxe
,
414 .name
= CLI_SYSLINUX
,
415 .exec
= main_show_syslinux
,
420 .exec
= main_show_kernel
,
425 .exec
= main_show_vesa
,
430 .exec
= main_show_hdt
,
435 .exec
= main_show_vpd
,
440 .exec
= show_dmi_memory_modules
,
445 .exec
= main_show_acpi
,
450 .exec
= main_show_modes
,
460 struct cli_callback_descr list_hdt_set_modules
[] = {
463 .exec
= cli_set_mode
,
473 struct cli_module_descr hdt_default_modules
= {
474 .modules
= list_hdt_default_modules
,
477 struct cli_module_descr hdt_show_modules
= {
478 .modules
= list_hdt_show_modules
,
479 .default_callback
= main_show_summary
,
482 struct cli_module_descr hdt_set_modules
= {
483 .modules
= list_hdt_set_modules
,
486 struct cli_mode_descr hdt_mode
= {
489 .default_modules
= &hdt_default_modules
,
490 .show_modules
= &hdt_show_modules
,
491 .set_modules
= &hdt_set_modules
,