aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Alexandre Meyer <pierre@mouraf.org>2009-04-18 11:39:09 -0700
committerPierre-Alexandre Meyer <pierre@mouraf.org>2009-04-18 11:39:09 -0700
commit796ac719ba031943201c5fc3cf740dea50315414 (patch)
treefabe9834ef542d9990d9b7af6acbd3e57e60509b
parent7f3b680fe2af99969da04c8fdd14966fdd1ce9f6 (diff)
parentd72bfe6108c5104bb095f1c3f9f35885ddf8da88 (diff)
downloadsyslinux-796ac719ba031943201c5fc3cf740dea50315414.tar.gz
syslinux-796ac719ba031943201c5fc3cf740dea50315414.tar.xz
syslinux-796ac719ba031943201c5fc3cf740dea50315414.zip
Merge commit 'origin/for-erwan' into disklib
-rw-r--r--com32/gplinclude/vpd/vpd.h33
-rw-r--r--com32/gpllib/Makefile2
-rw-r--r--com32/gpllib/vpd/vpd.c103
-rw-r--r--com32/hdt/hdt-ata.c10
-rw-r--r--com32/hdt/hdt-cli-cpu.c302
-rw-r--r--com32/hdt/hdt-cli-dmi.c156
-rw-r--r--com32/hdt/hdt-cli-hdt.c325
-rw-r--r--com32/hdt/hdt-cli-kernel.c237
-rw-r--r--com32/hdt/hdt-cli-pci.c485
-rw-r--r--com32/hdt/hdt-cli-pxe.c103
-rw-r--r--com32/hdt/hdt-cli-syslinux.c37
-rw-r--r--com32/hdt/hdt-cli-vesa.c112
-rw-r--r--com32/hdt/hdt-cli.c1176
-rw-r--r--com32/hdt/hdt-cli.h132
-rw-r--r--com32/hdt/hdt-common.c44
-rw-r--r--com32/hdt/hdt-common.h3
-rw-r--r--com32/hdt/lib-ansi.c97
-rw-r--r--com32/hdt/lib-ansi.h43
-rw-r--r--com32/modules/Makefile3
-rw-r--r--com32/modules/vpdtest.c68
20 files changed, 2228 insertions, 1243 deletions
diff --git a/com32/gplinclude/vpd/vpd.h b/com32/gplinclude/vpd/vpd.h
new file mode 100644
index 00000000..4bb1afc9
--- /dev/null
+++ b/com32/gplinclude/vpd/vpd.h
@@ -0,0 +1,33 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2006 Erwan Velu - All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
+ * Boston MA 02111-1307, USA; either version 2 of the License, or
+ * (at your option) any later version; incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+#ifndef VPD_H
+#define VPD_H
+#include <inttypes.h>
+#include <stdbool.h>
+
+enum {VPD_TABLE_PRESENT = 100, ENOVPDTABLE};
+
+typedef struct {
+ char bios_build_id[10];
+ char box_serial_number[8];
+ char motherboard_serial_number[12];
+ char machine_type_model[8];
+ char bios_release_date[9];
+ char default_flash_filename[13];
+ char bios_version[255];
+ char base_address[6];
+ bool filled;
+} s_vpd;
+
+int vpd_decode(s_vpd *vpd);
+#endif
diff --git a/com32/gpllib/Makefile b/com32/gpllib/Makefile
index 46ed42e3..8e47d93f 100644
--- a/com32/gpllib/Makefile
+++ b/com32/gpllib/Makefile
@@ -10,7 +10,7 @@ REQFLAGS += -I../gplinclude
LIBOBJS = dmi/dmi_battery.o dmi/dmi_chassis.o dmi/dmi_memory.o \
dmi/dmi_processor.o dmi/dmi.o dmi/dmi_bios.o dmi/dmi_base_board.o \
- dmi/dmi_ipmi.o cpuid.o
+ dmi/dmi_ipmi.o cpuid.o vpd/vpd.o
BINDIR = /usr/bin
LIBDIR = /usr/lib
diff --git a/com32/gpllib/vpd/vpd.c b/com32/gpllib/vpd/vpd.c
new file mode 100644
index 00000000..ff04b8bf
--- /dev/null
+++ b/com32/gpllib/vpd/vpd.c
@@ -0,0 +1,103 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2006 Erwan Velu - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * -----------------------------------------------------------------------
+*/
+
+#include <stdio.h>
+#include <string.h>
+#include "vpd/vpd.h"
+
+int vpd_checksum(char *buf, int len)
+{
+ uint8_t sum=0;
+ int a;
+
+ for(a=0; a<len; a++)
+ sum+=buf[a];
+ return (sum==0);
+}
+
+int vpd_decode(s_vpd *vpd) {
+ uint8_t buf[16];
+ char *p,*q;
+
+ /* Cleaning structures */
+ memset(&vpd->base_address,0,sizeof (vpd->base_address));
+ memset(&vpd->bios_build_id,0,sizeof (vpd->bios_build_id));
+ memset(&vpd->box_serial_number,0,sizeof (vpd->box_serial_number));
+ memset(&vpd->motherboard_serial_number,0,sizeof (vpd->motherboard_serial_number));
+ memset(&vpd->machine_type_model,0,sizeof (vpd->machine_type_model));
+ memset(&vpd->bios_release_date,0,sizeof (vpd->bios_release_date));
+ memset(&vpd->default_flash_filename,0,sizeof (vpd->default_flash_filename));
+ memset(&vpd->bios_version,0,sizeof (vpd->bios_version));
+
+ /* Until we found elements in the vpdtable, we consider them as not filled */
+ vpd->filled=false;
+
+ p=(char *)0xF0000; /* The start address to look at the dmi table */
+ for (q = p; q < p + 0x10000; q +=4) {
+ memcpy(buf, q, 5);
+ if(memcmp(buf, "\252\125VPD", 5)==0) {
+ snprintf(&vpd->base_address,5,"%X",q);
+ if (q[5] < 0x30)
+ return -ENOVPDTABLE;
+
+ vpd->filled=true;
+ /* XSeries have longer records, exact length seems to vary. */
+ if (!(q[5] >= 0x45 && vpd_checksum(q, q[5]))
+ /* Some Netvista seem to work with this. */
+ && !(vpd_checksum(q, 0x30))
+ /* The Thinkpad/Thinkcentre checksum does *not* include the first 13 bytes. */
+ && !(vpd_checksum(q + 0x0D, 0x30 - 0x0D)))
+ {
+ /* A few systems have a bad checksum (xSeries 325, 330, 335
+ and 345 with early BIOS) but the record is otherwise
+ valid. */
+ printf("VPD: Bad checksum!\n");
+ }
+
+ strncpy(vpd->bios_build_id,q+0x0D, 9);
+ strncpy(vpd->box_serial_number,q+0x16, 7);
+ strncpy(vpd->motherboard_serial_number,q+0x1D, 11);
+ strncpy(vpd->machine_type_model,q+0x28, 7);
+
+ if (q[5] < 0x44)
+ return VPD_TABLE_PRESENT;
+
+ strncpy(vpd->bios_release_date,q+0x30, 8);
+ strncpy(vpd->default_flash_filename,q+0x38, 12);
+
+ if (q[5] >= 0x46 && q[0x44] != 0x00) {
+ strncpy(vpd->bios_version,q+0x44, 255);
+ }
+
+ return VPD_TABLE_PRESENT;
+ }
+ }
+ return -ENOVPDTABLE;
+}
+
+
diff --git a/com32/hdt/hdt-ata.c b/com32/hdt/hdt-ata.c
index eb507d21..e0d6015c 100644
--- a/com32/hdt/hdt-ata.c
+++ b/com32/hdt/hdt-ata.c
@@ -30,8 +30,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <console.h>
+#include <getkey.h>
#include "com32io.h"
+#include "hdt-common.h"
#include "hdt-ata.h"
#ifdef ATA
@@ -217,7 +219,7 @@ int get_disk_params(int disk, struct diskinfo *disk_info)
memcpy(&dp, __com32.cs_bounce, sizeof(struct device_parameter));
if (outreg.eflags.l & EFLAGS_CF) {
- printf("Disk 0x%X doesn't supports EDD 3.0\n", disk);
+ more_printf("Disk 0x%X doesn't supports EDD 3.0\n", disk);
return -1;
}
@@ -260,7 +262,7 @@ int get_disk_params(int disk, struct diskinfo *disk_info)
memcpy(&aid, __com32.cs_bounce, sizeof(struct ata_identify_device));
if (outreg.eflags.l & EFLAGS_CF) {
- printf("Disk 0x%X: Failed to Identify Device\n", disk);
+ more_printf("Disk 0x%X: Failed to Identify Device\n", disk);
//FIXME
return 0;
}
@@ -270,8 +272,8 @@ int get_disk_params(int disk, struct diskinfo *disk_info)
char buff[sizeof(struct ata_identify_device)];
memcpy(buff, &aid, sizeof(struct ata_identify_device));
for (int j = 0; j < sizeof(struct ata_identify_device); j++)
- printf("model=|%c|\n", buff[j]);
- printf("Disk 0x%X : %s %s %s\n", disk, aid.model, aid.fw_rev,
+ more_printf("model=|%c|\n", buff[j]);
+ more_printf("Disk 0x%X : %s %s %s\n", disk, aid.model, aid.fw_rev,
aid.serial_no);
#endif
diff --git a/com32/hdt/hdt-cli-cpu.c b/com32/hdt/hdt-cli-cpu.c
index cfd66ef7..9aea1149 100644
--- a/com32/hdt/hdt-cli-cpu.c
+++ b/com32/hdt/hdt-cli-cpu.c
@@ -34,162 +34,162 @@
#include "hdt-cli.h"
#include "hdt-common.h"
-void show_cpu(struct s_hardware *hardware)
+void main_show_cpu(int argc __unused, char **argv __unused,
+ struct s_hardware *hardware)
{
- char buffer[81];
- char buffer1[81];
- clear_screen();
- more_printf("CPU\n");
- more_printf("Vendor : %s\n", hardware->cpu.vendor);
- more_printf("Model : %s\n", hardware->cpu.model);
- more_printf("Vendor ID : %d\n", hardware->cpu.vendor_id);
- more_printf("Family ID : %d\n", hardware->cpu.family);
- more_printf("Model ID : %d\n", hardware->cpu.model_id);
- more_printf("Stepping : %d\n", hardware->cpu.stepping);
- more_printf("FSB : %d MHz\n",
- hardware->dmi.processor.external_clock);
- more_printf("Cur. Speed: %d MHz\n",
- hardware->dmi.processor.current_speed);
- more_printf("Max Speed : %d MHz\n", hardware->dmi.processor.max_speed);
- more_printf("Upgrade : %s\n", hardware->dmi.processor.upgrade);
- if (hardware->cpu.flags.smp) {
- more_printf("SMP : yes\n");
- } else {
- more_printf("SMP : no\n");
- }
- if (hardware->cpu.flags.lm) {
- more_printf("x86_64 : yes\n");
- } else {
- more_printf("x86_64 : no\n");
- }
-
- memset(buffer, 0, sizeof(buffer));
- memset(buffer1, 0, sizeof(buffer1));
- if (hardware->cpu.flags.fpu)
- strcat(buffer1, "fpu ");
- if (hardware->cpu.flags.vme)
- strcat(buffer1, "vme ");
- if (hardware->cpu.flags.de)
- strcat(buffer1, "de ");
- if (hardware->cpu.flags.pse)
- strcat(buffer1, "pse ");
- if (hardware->cpu.flags.tsc)
- strcat(buffer1, "tsc ");
- if (hardware->cpu.flags.msr)
- strcat(buffer1, "msr ");
- if (hardware->cpu.flags.pae)
- strcat(buffer1, "pae ");
- if (hardware->cpu.flags.mce)
- strcat(buffer1, "mce ");
- if (hardware->cpu.flags.cx8)
- strcat(buffer1, "cx8 ");
- if (hardware->cpu.flags.apic)
- strcat(buffer1, "apic ");
- if (hardware->cpu.flags.sep)
- strcat(buffer1, "sep ");
- if (hardware->cpu.flags.mtrr)
- strcat(buffer1, "mtrr ");
- if (hardware->cpu.flags.pge)
- strcat(buffer1, "pge ");
- if (hardware->cpu.flags.mca)
- strcat(buffer1, "mca ");
- snprintf(buffer, sizeof buffer, "Flags : %s\n", buffer1);
- more_printf(buffer);
-
- memset(buffer, 0, sizeof(buffer));
- memset(buffer1, 0, sizeof(buffer1));
- if (hardware->cpu.flags.cmov)
- strcat(buffer1, "cmov ");
- if (hardware->cpu.flags.pat)
- strcat(buffer1, "pat ");
- if (hardware->cpu.flags.pse_36)
- strcat(buffer1, "pse_36 ");
- if (hardware->cpu.flags.psn)
- strcat(buffer1, "psn ");
- if (hardware->cpu.flags.clflsh)
- strcat(buffer1, "clflsh ");
- if (hardware->cpu.flags.dts)
- strcat(buffer1, "dts ");
- if (hardware->cpu.flags.acpi)
- strcat(buffer1, "acpi ");
- if (hardware->cpu.flags.mmx)
- strcat(buffer1, "mmx ");
- if (hardware->cpu.flags.sse)
- strcat(buffer1, "sse ");
- if (hardware->cpu.flags.sse2)
- strcat(buffer1, "sse2 ");
- if (hardware->cpu.flags.ss)
- strcat(buffer1, "ss ");
- snprintf(buffer, sizeof buffer, "Flags : %s\n", buffer1);
- more_printf(buffer);
-
- memset(buffer, 0, sizeof(buffer));
- memset(buffer1, 0, sizeof(buffer1));
- if (hardware->cpu.flags.htt)
- strcat(buffer1, "ht ");
- if (hardware->cpu.flags.acc)
- strcat(buffer1, "acc ");
- if (hardware->cpu.flags.syscall)
- strcat(buffer1, "syscall ");
- if (hardware->cpu.flags.mp)
- strcat(buffer1, "mp ");
- if (hardware->cpu.flags.nx)
- strcat(buffer1, "nx ");
- if (hardware->cpu.flags.mmxext)
- strcat(buffer1, "mmxext ");
- if (hardware->cpu.flags.lm)
- strcat(buffer1, "lm ");
- if (hardware->cpu.flags.nowext)
- strcat(buffer1, "3dnowext ");
- if (hardware->cpu.flags.now)
- strcat(buffer1, "3dnow! ");
- snprintf(buffer, sizeof buffer, "Flags : %s\n", buffer1);
- more_printf(buffer);
+ cpu_detect(hardware);
+ detect_dmi(hardware);
+ more_printf("CPU\n");
+ more_printf(" Manufacturer : %s \n", hardware->cpu.vendor);
+ more_printf(" Product : %s \n", hardware->cpu.model);
+ if ((hardware->cpu.flags.lm == false)
+ && (hardware->cpu.flags.smp == false)) {
+ more_printf(" Features : %d MhZ : x86 32bits\n",
+ hardware->dmi.processor.current_speed);
+ } else if ((hardware->cpu.flags.lm == false)
+ && (hardware->cpu.flags.smp == true)) {
+ more_printf(" Features : %d MhZ : x86 32bits SMP\n",
+ hardware->dmi.processor.current_speed);
+ } else if ((hardware->cpu.flags.lm == true)
+ && (hardware->cpu.flags.smp == false)) {
+ more_printf(" Features : %d MhZ : x86_64 64bits\n",
+ hardware->dmi.processor.current_speed);
+ } else {
+ more_printf(" Features : %d MhZ : x86_64 64bits SMP\n",
+ hardware->dmi.processor.current_speed);
+ }
}
-static void show_cpu_help()
+static void show_cpu(int argc __unused, char **argv __unused,
+ struct s_hardware *hardware)
{
- more_printf("Show supports the following commands : %s\n", CLI_CPU);
-}
+ char buffer[81];
+ char buffer1[81];
+ clear_screen();
+ more_printf("CPU\n");
+ more_printf("Vendor : %s\n", hardware->cpu.vendor);
+ more_printf("Model : %s\n", hardware->cpu.model);
+ more_printf("Vendor ID : %d\n", hardware->cpu.vendor_id);
+ more_printf("Family ID : %d\n", hardware->cpu.family);
+ more_printf("Model ID : %d\n", hardware->cpu.model_id);
+ more_printf("Stepping : %d\n", hardware->cpu.stepping);
+ more_printf("FSB : %d MHz\n",
+ hardware->dmi.processor.external_clock);
+ more_printf("Cur. Speed: %d MHz\n",
+ hardware->dmi.processor.current_speed);
+ more_printf("Max Speed : %d MHz\n", hardware->dmi.processor.max_speed);
+ more_printf("Upgrade : %s\n", hardware->dmi.processor.upgrade);
+ if (hardware->cpu.flags.smp) {
+ more_printf("SMP : yes\n");
+ } else {
+ more_printf("SMP : no\n");
+ }
+ if (hardware->cpu.flags.lm) {
+ more_printf("x86_64 : yes\n");
+ } else {
+ more_printf("x86_64 : no\n");
+ }
-static void cpu_show(char *item, struct s_hardware *hardware)
-{
- if (!strncmp(item, CLI_CPU, sizeof(CLI_CPU) - 1)) {
- show_cpu(hardware);
- return;
- }
- show_cpu_help();
-}
+ memset(buffer, 0, sizeof(buffer));
+ memset(buffer1, 0, sizeof(buffer1));
+ if (hardware->cpu.flags.fpu)
+ strcat(buffer1, "fpu ");
+ if (hardware->cpu.flags.vme)
+ strcat(buffer1, "vme ");
+ if (hardware->cpu.flags.de)
+ strcat(buffer1, "de ");
+ if (hardware->cpu.flags.pse)
+ strcat(buffer1, "pse ");
+ if (hardware->cpu.flags.tsc)
+ strcat(buffer1, "tsc ");
+ if (hardware->cpu.flags.msr)
+ strcat(buffer1, "msr ");
+ if (hardware->cpu.flags.pae)
+ strcat(buffer1, "pae ");
+ if (hardware->cpu.flags.mce)
+ strcat(buffer1, "mce ");
+ if (hardware->cpu.flags.cx8)
+ strcat(buffer1, "cx8 ");
+ if (hardware->cpu.flags.apic)
+ strcat(buffer1, "apic ");
+ if (hardware->cpu.flags.sep)
+ strcat(buffer1, "sep ");
+ if (hardware->cpu.flags.mtrr)
+ strcat(buffer1, "mtrr ");
+ if (hardware->cpu.flags.pge)
+ strcat(buffer1, "pge ");
+ if (hardware->cpu.flags.mca)
+ strcat(buffer1, "mca ");
+ if (buffer1[0]) {
+ snprintf(buffer, sizeof buffer, "Flags : %s\n", buffer1);
+ more_printf(buffer);
+ }
-void handle_cpu_commands(char *cli_line, struct s_hardware *hardware)
-{
- if (!strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1)) {
- cpu_show(strstr(cli_line, "show") + sizeof(CLI_SHOW), hardware);
- return;
- }
-}
+ memset(buffer, 0, sizeof(buffer));
+ memset(buffer1, 0, sizeof(buffer1));
+ if (hardware->cpu.flags.cmov)
+ strcat(buffer1, "cmov ");
+ if (hardware->cpu.flags.pat)
+ strcat(buffer1, "pat ");
+ if (hardware->cpu.flags.pse_36)
+ strcat(buffer1, "pse_36 ");
+ if (hardware->cpu.flags.psn)
+ strcat(buffer1, "psn ");
+ if (hardware->cpu.flags.clflsh)
+ strcat(buffer1, "clflsh ");
+ if (hardware->cpu.flags.dts)
+ strcat(buffer1, "dts ");
+ if (hardware->cpu.flags.acpi)
+ strcat(buffer1, "acpi ");
+ if (hardware->cpu.flags.mmx)
+ strcat(buffer1, "mmx ");
+ if (hardware->cpu.flags.sse)
+ strcat(buffer1, "sse ");
+ if (hardware->cpu.flags.sse2)
+ strcat(buffer1, "sse2 ");
+ if (hardware->cpu.flags.ss)
+ strcat(buffer1, "ss ");
+ if (buffer1[0]) {
+ snprintf(buffer, sizeof buffer, "Flags : %s\n", buffer1);
+ more_printf(buffer);
+ }
-void main_show_cpu(struct s_hardware *hardware)
-{
- cpu_detect(hardware);
- detect_dmi(hardware);
- more_printf("CPU\n");
- more_printf(" Manufacturer : %s \n", hardware->cpu.vendor);
- more_printf(" Product : %s \n", hardware->cpu.model);
- if ((hardware->cpu.flags.lm == false)
- && (hardware->cpu.flags.smp == false)) {
- more_printf(" Features : %d MhZ : x86 32bits\n",
- hardware->dmi.processor.current_speed);
- } else if ((hardware->cpu.flags.lm == false)
- && (hardware->cpu.flags.smp == true)) {
- more_printf(" Features : %d MhZ : x86 32bits SMP\n",
- hardware->dmi.processor.current_speed);
- } else if ((hardware->cpu.flags.lm == true)
- && (hardware->cpu.flags.smp == false)) {
- more_printf(" Features : %d MhZ : x86_64 64bits\n",
- hardware->dmi.processor.current_speed);
- } else {
- more_printf(" Features : %d MhZ : x86_64 64bits SMP\n",
- hardware->dmi.processor.current_speed);
- }
+ memset(buffer, 0, sizeof(buffer));
+ memset(buffer1, 0, sizeof(buffer1));
+ if (hardware->cpu.flags.htt)
+ strcat(buffer1, "ht ");
+ if (hardware->cpu.flags.acc)
+ strcat(buffer1, "acc ");
+ if (hardware->cpu.flags.syscall)
+ strcat(buffer1, "syscall ");
+ if (hardware->cpu.flags.mp)
+ strcat(buffer1, "mp ");
+ if (hardware->cpu.flags.nx)
+ strcat(buffer1, "nx ");
+ if (hardware->cpu.flags.mmxext)
+ strcat(buffer1, "mmxext ");
+ if (hardware->cpu.flags.lm)
+ strcat(buffer1, "lm ");
+ if (hardware->cpu.flags.nowext)
+ strcat(buffer1, "3dnowext ");
+ if (hardware->cpu.flags.now)
+ strcat(buffer1, "3dnow! ");
+ if (buffer1[0]) {
+ snprintf(buffer, sizeof buffer, "Flags : %s\n", buffer1);
+ more_printf(buffer);
+ }
}
+
+struct cli_module_descr cpu_show_modules = {
+ .modules = NULL,
+ .nb_modules = 0,
+ .default_callback = show_cpu,
+};
+
+struct cli_mode_descr cpu_mode = {
+ .mode = CPU_MODE,
+ .name = CLI_CPU,
+ .default_modules = NULL,
+ .show_modules = &cpu_show_modules,
+ .set_modules = NULL,
+};
diff --git a/com32/hdt/hdt-cli-dmi.c b/com32/hdt/hdt-cli-dmi.c
index a7ea872c..82b326d8 100644
--- a/com32/hdt/hdt-cli-dmi.c
+++ b/com32/hdt/hdt-cli-dmi.c
@@ -34,75 +34,41 @@
#include "hdt-cli.h"
#include "hdt-common.h"
-static void show_dmi_modules(int argc, char** argv,
+static void show_dmi_modules(int argc __unused, char** argv __unused,
struct s_hardware *hardware)
{
char available_dmi_commands[1024];
memset(available_dmi_commands, 0, sizeof(available_dmi_commands));
- if (hardware->dmi.base_board.filled == true) {
- strncat(available_dmi_commands, CLI_DMI_BASE_BOARD,
- sizeof(CLI_DMI_BASE_BOARD) - 1);
- strncat(available_dmi_commands, " ", 1);
- }
- if (hardware->dmi.battery.filled == true) {
- strncat(available_dmi_commands, CLI_DMI_BATTERY,
- sizeof(CLI_DMI_BATTERY) - 1);
- strncat(available_dmi_commands, " ", 1);
- }
- if (hardware->dmi.bios.filled == true) {
- strncat(available_dmi_commands, CLI_DMI_BIOS,
- sizeof(CLI_DMI_BIOS) - 1);
- strncat(available_dmi_commands, " ", 1);
- }
- if (hardware->dmi.chassis.filled == true) {
- strncat(available_dmi_commands, CLI_DMI_CHASSIS,
- sizeof(CLI_DMI_CHASSIS) - 1);
- strncat(available_dmi_commands, " ", 1);
- }
- for (int i = 0; i < hardware->dmi.memory_count; i++) {
- if (hardware->dmi.memory[i].filled == true) {
- strncat(available_dmi_commands, CLI_DMI_MEMORY,
- sizeof(CLI_DMI_MEMORY) - 1);
- strncat(available_dmi_commands, " bank<bank_number> ",
- 19);
- break;
- }
- }
- if (hardware->dmi.processor.filled == true) {
- strncat(available_dmi_commands, CLI_DMI_PROCESSOR,
- sizeof(CLI_DMI_PROCESSOR) - 1);
- strncat(available_dmi_commands, " ", 1);
- }
- if (hardware->dmi.system.filled == true) {
- strncat(available_dmi_commands, CLI_DMI_SYSTEM,
- sizeof(CLI_DMI_SYSTEM) - 1);
- strncat(available_dmi_commands, " ", 1);
- }
- if (hardware->dmi.ipmi.filled == true) {
- strncat(available_dmi_commands, CLI_DMI_IPMI,
- sizeof(CLI_DMI_IPMI) - 1);
- strncat(available_dmi_commands, " ", 1);
- }
-
- printf("Available DMI modules: %s\n", available_dmi_commands);
-}
-
-static void show_dmi_help(int argc, char** argv,
- struct s_hardware *hardware)
-{
- more_printf("Show supports the following commands : \n");
- more_printf(" %s\n", CLI_SHOW_LIST);
- more_printf(" <module_name>\n");
- more_printf(" -\n");
- show_dmi_modules(0, NULL, hardware);
+ more_printf("Available DMI modules on your system:\n");
+ if (hardware->dmi.base_board.filled == true)
+ more_printf("\t%s\n", CLI_DMI_BASE_BOARD);
+ if (hardware->dmi.battery.filled == true)
+ more_printf("\t%s\n", CLI_DMI_BATTERY);
+ if (hardware->dmi.bios.filled == true)
+ more_printf("\t%s\n", CLI_DMI_BIOS);
+ if (hardware->dmi.chassis.filled == true)
+ more_printf("\t%s\n", CLI_DMI_CHASSIS);
+ for (int i = 0; i < hardware->dmi.memory_count; i++) {
+ if (hardware->dmi.memory[i].filled == true) {
+ more_printf("\tbank <number>\n", CLI_DMI_MEMORY);
+ break;
+ }
+ }
+ if (hardware->dmi.processor.filled == true)
+ more_printf("\t%s\n", CLI_DMI_PROCESSOR);
+ if (hardware->dmi.system.filled == true)
+ more_printf("\t%s\n", CLI_DMI_SYSTEM);
+ if (hardware->dmi.ipmi.filled == true)
+ more_printf("\t%s\n", CLI_DMI_IPMI);
}
-static void show_dmi_base_board(int argc, char** argv,
+static void show_dmi_base_board(int argc __unused, char** argv __unused,
struct s_hardware *hardware)
{
if (hardware->dmi.base_board.filled == false) {
- printf("Base_board module not available\n");
+ more_printf("base_board information not found on your system, see "
+ "`show list' to see which module is available.\n");
return;
}
clear_screen();
@@ -123,11 +89,12 @@ static void show_dmi_base_board(int argc, char** argv,
}
}
-static void show_dmi_system(int argc, char** argv,
+static void show_dmi_system(int argc __unused, char** argv __unused,
struct s_hardware *hardware)
{
if (hardware->dmi.system.filled == false) {
- printf("System module not available\n");
+ more_printf("system information not found on your system, see "
+ "`show list' to see which module is available.\n");
return;
}
clear_screen();
@@ -142,11 +109,12 @@ static void show_dmi_system(int argc, char** argv,
more_printf(" Family : %s\n", hardware->dmi.system.family);
}
-static void show_dmi_bios(int argc, char** argv,
+static void show_dmi_bios(int argc __unused, char** argv __unused,
struct s_hardware *hardware)
{
if (hardware->dmi.bios.filled == false) {
- printf("Bios module not available\n");
+ more_printf("bios information not found on your system, see "
+ "`show list' to see which module is available.\n");
return;
}
clear_screen();
@@ -188,11 +156,12 @@ static void show_dmi_bios(int argc, char** argv,
}
-static void show_dmi_chassis(int argc, char** argv,
+static void show_dmi_chassis(int argc __unused, char** argv __unused,
struct s_hardware *hardware)
{
if (hardware->dmi.chassis.filled == false) {
- printf("Chassis module not available\n");
+ more_printf("chassis information not found on your system, see "
+ "`show list' to see which module is available.\n");
return;
}
clear_screen();
@@ -221,11 +190,11 @@ static void show_dmi_chassis(int argc, char** argv,
hardware->dmi.chassis.nb_power_cords);
}
-static void show_dmi_ipmi(int argc, char** argv,
+static void show_dmi_ipmi(int argc __unused, char **argv __unused,
struct s_hardware *hardware)
{
if (hardware->dmi.ipmi.filled == false) {
- printf("IPMI module not available\n");
+ more_printf("IPMI module not available\n");
return;
}
clear_screen();
@@ -247,11 +216,12 @@ static void show_dmi_ipmi(int argc, char** argv,
hardware->dmi.ipmi.irq);
}
-static void show_dmi_battery(int argc, char** argv,
+static void show_dmi_battery(int argc __unused, char** argv __unused,
struct s_hardware *hardware)
{
if (hardware->dmi.battery.filled == false) {
- printf("Battery module not available\n");
+ more_printf("battery information not found on your system, see "
+ "`show list' to see which module is available.\n");
return;
}
clear_screen();
@@ -279,11 +249,12 @@ static void show_dmi_battery(int argc, char** argv,
hardware->dmi.battery.oem_info);
}
-static void show_dmi_cpu(int argc, char** argv,
+static void show_dmi_cpu(int argc __unused, char** argv __unused,
struct s_hardware *hardware)
{
if (hardware->dmi.processor.filled == false) {
- printf("Processor module not available\n");
+ more_printf("processor information not found on your system, see "
+ "`show list' to see which module is available.\n");
return;
}
clear_screen();
@@ -346,20 +317,20 @@ static void show_dmi_memory_bank(int argc, char** argv,
bank = strtol(argv[0], (char **)NULL, 10);
if (errno == ERANGE || bank < 0) {
- printf("This bank number is incorrect\n");
+ more_printf("This bank number is incorrect\n");
return;
}
if ((bank >= hardware->dmi.memory_count) || (bank < 0)) {
- printf("Bank %d number doesn't exists\n", bank);
+ more_printf("Bank %d number doesn't exists\n", bank);
return;
}
if (hardware->dmi.memory[bank].filled == false) {
- printf("Bank %d doesn't contain any information\n", bank);
+ more_printf("Bank %d doesn't contain any information\n", bank);
return;
}
- printf("Memory Bank %d\n", bank);
+ more_printf("Memory Bank %d\n", bank);
more_printf(" Form Factor : %s\n",
hardware->dmi.memory[bank].form_factor);
more_printf(" Type : %s\n", hardware->dmi.memory[bank].type);
@@ -387,23 +358,24 @@ static void show_dmi_memory_bank(int argc, char** argv,
hardware->dmi.memory[bank].part_number);
}
-void main_show_dmi(struct s_hardware *hardware)
+void main_show_dmi(int argc __unused, char **argv __unused,
+ struct s_hardware *hardware)
{
detect_dmi(hardware);
if (hardware->is_dmi_valid == false) {
- printf("No valid DMI table found, exiting.\n");
+ more_printf("No valid DMI table found, exiting.\n");
return;
}
- printf("DMI Table version %d.%d found\n",
+ more_printf("DMI Table version %d.%d found\n",
hardware->dmi.dmitable.major_version,
hardware->dmi.dmitable.minor_version);
show_dmi_modules(0, NULL, hardware);
}
-void show_dmi_memory_modules(int argc, char** argv,
+void show_dmi_memory_modules(int argc __unused, char** argv __unused,
struct s_hardware *hardware)
{
int clear = 1, show_free_banks = 1;
@@ -426,7 +398,7 @@ void show_dmi_memory_modules(int argc, char** argv,
memset(available_dmi_commands, 0, sizeof(available_dmi_commands));
if (hardware->dmi.memory_count <= 0) {
- printf("No memory module found\n");
+ more_printf("No memory module found\n");
return;
}
@@ -445,12 +417,12 @@ void show_dmi_memory_modules(int argc, char** argv,
if (show_free_banks == false) {
if (strncmp
(hardware->dmi.memory[i].size, "Free", 4))
- printf(" bank %02d : %s %s@%s\n",
+ more_printf(" bank %02d : %s %s@%s\n",
i, hardware->dmi.memory[i].size,
hardware->dmi.memory[i].type,
hardware->dmi.memory[i].speed);
} else {
- printf(" bank %02d : %s %s@%s\n", i,
+ more_printf(" bank %02d : %s %s@%s\n", i,
hardware->dmi.memory[i].size,
hardware->dmi.memory[i].type,
hardware->dmi.memory[i].speed);
@@ -462,11 +434,11 @@ void show_dmi_memory_modules(int argc, char** argv,
//printf("Type 'show bank<bank_number>' for more details.\n");
usage:
- printf("show memory <clear screen? <show free banks?>>\n");
+ more_printf("show memory <clear screen? <show free banks?>>\n");
return;
}
-struct commands_module list_dmi_show_modules[] = {
+struct cli_callback_descr list_dmi_show_modules[] = {
{
.name = CLI_DMI_BASE_BOARD,
.exec = show_dmi_base_board,
@@ -509,12 +481,16 @@ struct commands_module list_dmi_show_modules[] = {
},
};
-struct commands_module_descr dmi_show_modules = {
- .modules = list_dmi_show_modules,
- .nb_modules = CLI_DMI_MAX_MODULES,
+struct cli_module_descr dmi_show_modules = {
+ .modules = list_dmi_show_modules,
+ .nb_modules = CLI_DMI_MAX_MODULES,
+ .default_callback = main_show_dmi,
};
-struct commands_mode dmi_mode = {
- .mode = DMI_MODE,
- .show_modules = &dmi_show_modules,
+struct cli_mode_descr dmi_mode = {
+ .mode = DMI_MODE,
+ .name = CLI_DMI,
+ .default_modules = NULL,
+ .show_modules = &dmi_show_modules,
+ .set_modules = NULL,
};
diff --git a/com32/hdt/hdt-cli-hdt.c b/com32/hdt/hdt-cli-hdt.c
new file mode 100644
index 00000000..cc7b30be
--- /dev/null
+++ b/com32/hdt/hdt-cli-hdt.c
@@ -0,0 +1,325 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2009 Pierre-Alexandre Meyer - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * -----------------------------------------------------------------------
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <syslinux/config.h>
+
+#include "hdt-menu.h"
+#include "hdt-cli.h"
+#include "hdt-common.h"
+
+/**
+ * cli_clear_screen - clear (erase) the entire screen
+ **/
+static void cli_clear_screen(int argc __unused, char** argv __unused,
+ struct s_hardware *hardware __unused)
+{
+ clear_screen();
+}
+
+/**
+ * main_show_modes - show availables modes
+ **/
+static void main_show_modes(int argc __unused, char** argv __unused,
+ struct s_hardware *hardware __unused)
+{
+ int i;
+
+ more_printf("Available modes:\n");
+ for (i = 0; i < MAX_MODES; i++)
+ more_printf("\t%s\n", list_modes[i]->name);
+}
+
+/**
+ * cli_set_mode - set the mode of the cli, in the cli
+ *
+ * The mode number must be supplied in argv, position 0.
+ **/
+static void cli_set_mode(int argc, char **argv,
+ struct s_hardware *hardware)
+{
+ cli_mode_t new_mode;
+
+ if (argc <= 0) {
+ more_printf("Which mode?\n");
+ return;
+ }
+
+ /*
+ * Note! argv[0] is a string representing the mode, we need the
+ * equivalent cli_mode_t to pass it to set_mode.
+ */
+ new_mode = mode_s_to_mode_t(argv[0]);
+ set_mode(new_mode, hardware);
+}
+
+/**
+ * do_exit - shared helper to exit a mode
+ **/
+static void do_exit(int argc __unused, char** argv __unused,
+ struct s_hardware *hardware)
+{
+ int new_mode = HDT_MODE;
+
+ switch (hdt_cli.mode) {
+ case HDT_MODE:
+ new_mode = EXIT_MODE;
+ break;
+ default:
+ new_mode = HDT_MODE;
+ break;
+ }
+
+ dprintf("CLI DEBUG: Switching from mode %d to mode %d\n", hdt_cli.mode,
+ new_mode);
+ set_mode(new_mode, hardware);
+}
+
+/**
+ * show_cli_help - shared helper to show available commands
+ **/
+static void show_cli_help(int argc __unused, char** argv __unused,
+ struct s_hardware *hardware __unused)
+{
+ int j;
+ struct cli_mode_descr *current_mode;
+ struct cli_callback_descr* associated_module = NULL;
+
+ find_cli_mode_descr(hdt_cli.mode, &current_mode);
+
+ more_printf("Available commands are:\n");
+
+ /* List first default modules of the mode */
+ if (current_mode->default_modules != NULL ) {
+ for (j = 0; j < current_mode->default_modules->nb_modules; j++) {
+ more_printf("%s ",
+ current_mode->default_modules->modules[j].name);
+ }
+ more_printf("\n");
+ }
+
+ /* List secondly the show modules of the mode */
+ if (current_mode->show_modules != NULL &&
+ current_mode->show_modules->nb_modules != 0) {
+ more_printf("show commands:\n");
+ for (j = 0; j < current_mode->show_modules->nb_modules; j++)
+ more_printf("\t%s\n",
+ current_mode->show_modules->modules[j].name);
+ }
+
+ /* List thirdly the set modules of the mode */
+ if (current_mode->set_modules != NULL &&
+ current_mode->set_modules->nb_modules != 0) {
+ more_printf("set commands:\n");
+ for (j = 0; j < current_mode->set_modules->nb_modules; j++)
+ more_printf("\t%s\n",
+ current_mode->set_modules->modules[j].name);
+ }
+
+ /* List finally the default modules of the hdt mode */
+ if (current_mode->mode != hdt_mode.mode &&
+ hdt_mode.default_modules != NULL ) {
+ for (j = 0; j < hdt_mode.default_modules->nb_modules; j++) {
+ /*
+ * Any default command that is present in hdt mode but
+ * not in the current mode is available. A default
+ * command can be redefined in the current mode though.
+ * This next call test this use case: if it is
+ * overwritten, do not print it again.
+ */
+ find_cli_callback_descr(hdt_mode.default_modules->modules[j].name,
+ current_mode->default_modules,
+ &associated_module);
+ if (associated_module == NULL)
+ more_printf("%s ",
+ hdt_mode.default_modules->modules[j].name);
+ }
+ more_printf("\n");
+ }
+
+ main_show_modes(argc, argv, hardware);
+}
+
+/**
+ * show_cli_help - shared helper to show available commands
+ **/
+static void goto_menu(int argc __unused, char** argv __unused,
+ struct s_hardware *hardware)
+{
+ char version_string[256];
+ snprintf(version_string, sizeof version_string, "%s %s by %s",
+ PRODUCT_NAME, VERSION, AUTHOR);
+ start_menu_mode(hardware, version_string);
+ return;
+}
+
+/**
+ * main_show_summary - give an overview of the system
+ **/
+void main_show_summary(int argc __unused, char **argv __unused,
+ struct s_hardware *hardware)
+{
+ detect_pci(hardware); /* pxe is detected in the pci */
+ detect_dmi(hardware);
+ cpu_detect(hardware);
+ clear_screen();
+ main_show_cpu(argc, argv, hardware);
+ if (hardware->is_dmi_valid) {
+ more_printf("System\n");
+ more_printf(" Manufacturer : %s\n",
+ hardware->dmi.system.manufacturer);
+ more_printf(" Product Name : %s\n",
+ hardware->dmi.system.product_name);
+ more_printf(" Serial : %s\n",
+ hardware->dmi.system.serial);
+ more_printf("Bios\n");
+ more_printf(" Version : %s\n", hardware->dmi.bios.version);
+ more_printf(" Release : %s\n",
+ hardware->dmi.bios.release_date);
+
+ int argc = 2;
+ char *argv[2] = { "0", "0" };
+ show_dmi_memory_modules(argc, argv, hardware);
+ }
+ main_show_pci(argc, argv, hardware);
+
+ if (hardware->is_pxe_valid)
+ main_show_pxe(argc, argv, hardware);
+
+ main_show_kernel(argc, argv, hardware);
+}
+
+void main_show_hdt(int argc __unused, char **argv __unused,
+ struct s_hardware *hardware __unused)
+{
+ more_printf("HDT\n");
+ more_printf(" Product : %s\n", PRODUCT_NAME);
+ more_printf(" Version : %s\n", VERSION);
+ more_printf(" Author : %s\n", AUTHOR);
+ more_printf(" Contact : %s\n", CONTACT);
+ char *contributors[NB_CONTRIBUTORS] = CONTRIBUTORS;
+ for (int c = 0; c < NB_CONTRIBUTORS; c++) {
+ more_printf(" Contributor : %s\n", contributors[c]);
+ }
+}
+
+/* Default hdt mode */
+struct cli_callback_descr list_hdt_default_modules[] = {
+ {
+ .name = CLI_CLEAR,
+ .exec = cli_clear_screen,
+ },
+ {
+ .name = CLI_EXIT,
+ .exec = do_exit,
+ },
+ {
+ .name = CLI_HELP,
+ .exec = show_cli_help,
+ },
+ {
+ .name = CLI_MENU,
+ .exec = goto_menu,
+ },
+};
+
+struct cli_callback_descr list_hdt_show_modules[] = {
+ {
+ .name = CLI_SUMMARY,
+ .exec = main_show_summary,
+ },
+ {
+ .name = CLI_PCI,
+ .exec = main_show_pci,
+ },
+ {
+ .name = CLI_DMI,
+ .exec = main_show_dmi,
+ },
+ {
+ .name = CLI_CPU,
+ .exec = main_show_cpu,
+ },
+ {
+ .name = CLI_PXE,
+ .exec = main_show_pxe,
+ },
+ {
+ .name = CLI_SYSLINUX,
+ .exec = main_show_syslinux,
+ },
+ {
+ .name = CLI_KERNEL,
+ .exec = main_show_kernel,
+ },
+ {
+ .name = CLI_VESA,
+ .exec = main_show_vesa,
+ },
+ {
+ .name = CLI_HDT,
+ .exec = main_show_hdt,
+ },
+ {
+ .name = "modes",
+ .exec = main_show_modes,
+ },
+};
+
+struct cli_callback_descr list_hdt_set_modules[] = {
+ {
+ .name = CLI_MODE,
+ .exec = cli_set_mode,
+ },
+};
+
+struct cli_module_descr hdt_default_modules = {
+ .modules = list_hdt_default_modules,
+ .nb_modules = 4,
+};
+
+struct cli_module_descr hdt_show_modules = {
+ .modules = list_hdt_show_modules,
+ .nb_modules = 10,
+ .default_callback = main_show_summary,
+};
+
+struct cli_module_descr hdt_set_modules = {
+ .modules = list_hdt_set_modules,
+ .nb_modules = 1,
+};
+
+struct cli_mode_descr hdt_mode = {
+ .mode = HDT_MODE,
+ .name = CLI_HDT,
+ .default_modules = &hdt_default_modules,
+ .show_modules = &hdt_show_modules,
+ .set_modules = &hdt_set_modules,
+};
diff --git a/com32/hdt/hdt-cli-kernel.c b/com32/hdt/hdt-cli-kernel.c
index 5b0df1d2..700f2381 100644
--- a/com32/hdt/hdt-cli-kernel.c
+++ b/com32/hdt/hdt-cli-kernel.c
@@ -34,137 +34,128 @@
#include "hdt-cli.h"
#include "hdt-common.h"
-void main_show_kernel(struct s_hardware *hardware)
+void main_show_kernel(int argc __unused, char **argv __unused,
+ struct s_hardware *hardware)
{
- char buffer[1024];
- struct pci_device *pci_device;
- bool found = false;
- char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
- MAX_KERNEL_MODULES_PER_PCI_DEVICE];
+ char buffer[1024];
+ struct pci_device *pci_device;
+ bool found = false;
+ char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
+ MAX_KERNEL_MODULES_PER_PCI_DEVICE];
- memset(buffer, 0, sizeof(buffer));
+ memset(buffer, 0, sizeof(buffer));
- detect_pci(hardware);
- more_printf("Kernel modules\n");
+ detect_pci(hardware);
+ more_printf("Kernel modules\n");
// more_printf(" PCI device no: %d \n", p->pci_device_pos);
- if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
- more_printf(" modules.pcimap is missing\n");
- return;
- }
-
- /* For every detected pci device, compute its submenu */
- for_each_pci_func(pci_device, hardware->pci_domain) {
- memset(kernel_modules, 0, sizeof kernel_modules);
-
- for (int kmod = 0;
- kmod < pci_device->dev_info->linux_kernel_module_count;
- kmod++) {
- if (kmod > 0) {
- strncat(kernel_modules, " | ", 3);
- }
- strncat(kernel_modules,
- pci_device->dev_info->linux_kernel_module[kmod],
- LINUX_KERNEL_MODULE_SIZE - 1);
- }
-
- if ((pci_device->dev_info->linux_kernel_module_count > 0)
- && (!strstr(buffer, kernel_modules))) {
- found = true;
- if (pci_device->dev_info->linux_kernel_module_count > 1)
- strncat(buffer, "(", 1);
- strncat(buffer, kernel_modules, sizeof(kernel_modules));
- if (pci_device->dev_info->linux_kernel_module_count > 1)
- strncat(buffer, ")", 1);
- strncat(buffer, " # ", 3);
- }
-
- }
- if (found == true) {
- strncat(buffer, "\n", 1);
- more_printf(buffer);
- }
+ if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
+ more_printf(" modules.pcimap is missing\n");
+ return;
+ }
+
+ /* For every detected pci device, compute its submenu */
+ for_each_pci_func(pci_device, hardware->pci_domain) {
+ memset(kernel_modules, 0, sizeof kernel_modules);
+
+ for (int kmod = 0;
+ kmod < pci_device->dev_info->linux_kernel_module_count;
+ kmod++) {
+ if (kmod > 0) {
+ strncat(kernel_modules, " | ", 3);
+ }
+ strncat(kernel_modules,
+ pci_device->dev_info->linux_kernel_module[kmod],
+ LINUX_KERNEL_MODULE_SIZE - 1);
+ }
+
+ if ((pci_device->dev_info->linux_kernel_module_count > 0)
+ && (!strstr(buffer, kernel_modules))) {
+ found = true;
+ if (pci_device->dev_info->linux_kernel_module_count > 1)
+ strncat(buffer, "(", 1);
+ strncat(buffer, kernel_modules, sizeof(kernel_modules));
+ if (pci_device->dev_info->linux_kernel_module_count > 1)
+ strncat(buffer, ")", 1);
+ strncat(buffer, " # ", 3);
+ }
+
+ }
+ if (found == true) {
+ strncat(buffer, "\n", 1);
+ more_printf(buffer);
+ }
}
-static void show_kernel_modules(struct s_hardware *hardware)
+static void show_kernel_modules(int argc __unused, char **argv __unused,
+ struct s_hardware *hardware)
{
- struct pci_device *pci_device;
- char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
- MAX_KERNEL_MODULES_PER_PCI_DEVICE];
- bool nopciids = false;
- bool nomodulespcimap = false;
- char modules[MAX_PCI_CLASSES][256];
- char category_name[MAX_PCI_CLASSES][256];
-
- detect_pci(hardware);
- memset(&modules, 0, sizeof(modules));
-
- if (hardware->pci_ids_return_code == -ENOPCIIDS) {
- nopciids = true;
- more_printf(" Missing pci.ids, we can't compute the list\n");
- return;
- }
-
- if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
- nomodulespcimap = true;
- more_printf
- (" Missing modules.pcimap, we can't compute the list\n");
- return;
- }
-
- clear_screen();
-
- for_each_pci_func(pci_device, hardware->pci_domain) {
- memset(kernel_modules, 0, sizeof kernel_modules);
-
- for (int kmod = 0;
- kmod < pci_device->dev_info->linux_kernel_module_count;
- kmod++) {
- strncat(kernel_modules,
- pci_device->dev_info->linux_kernel_module[kmod],
- LINUX_KERNEL_MODULE_SIZE - 1);
- strncat(kernel_modules, " ", 1);
- }
-
- if ((pci_device->dev_info->linux_kernel_module_count > 0)
- && (!strstr(modules[pci_device->class[2]], kernel_modules)))
- {
- strncat(modules[pci_device->class[2]], kernel_modules,
- sizeof(kernel_modules));
- snprintf(category_name[pci_device->class[2]],
- sizeof(category_name[pci_device->class[2]]),
- "%s", pci_device->dev_info->category_name);
- }
- }
- /* Print the found items */
- for (int i = 0; i < MAX_PCI_CLASSES; i++) {
- if (strlen(category_name[i]) > 1) {
- more_printf("%s : %s\n", category_name[i], modules[i]);
- }
- }
+ struct pci_device *pci_device;
+ char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
+ MAX_KERNEL_MODULES_PER_PCI_DEVICE];
+ bool nopciids = false;
+ bool nomodulespcimap = false;
+ char modules[MAX_PCI_CLASSES][256];
+ char category_name[MAX_PCI_CLASSES][256];
+
+ detect_pci(hardware);
+ memset(&modules, 0, sizeof(modules));
+
+ if (hardware->pci_ids_return_code == -ENOPCIIDS) {
+ nopciids = true;
+ more_printf(" Missing pci.ids, we can't compute the list\n");
+ return;
+ }
+
+ if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
+ nomodulespcimap = true;
+ more_printf
+ (" Missing modules.pcimap, we can't compute the list\n");
+ return;
+ }
+
+ clear_screen();
+
+ for_each_pci_func(pci_device, hardware->pci_domain) {
+ memset(kernel_modules, 0, sizeof kernel_modules);
+
+ for (int kmod = 0;
+ kmod < pci_device->dev_info->linux_kernel_module_count;
+ kmod++) {
+ strncat(kernel_modules,
+ pci_device->dev_info->linux_kernel_module[kmod],
+ LINUX_KERNEL_MODULE_SIZE - 1);
+ strncat(kernel_modules, " ", 1);
+ }
+
+ if ((pci_device->dev_info->linux_kernel_module_count > 0)
+ && (!strstr(modules[pci_device->class[2]], kernel_modules))) {
+ strncat(modules[pci_device->class[2]], kernel_modules,
+ sizeof(kernel_modules));
+ snprintf(category_name[pci_device->class[2]],
+ sizeof(category_name[pci_device->class[2]]),
+ "%s", pci_device->dev_info->category_name);
+ }
+ }
+ /* Print the found items */
+ for (int i = 0; i < MAX_PCI_CLASSES; i++) {
+ if (strlen(category_name[i]) > 1) {
+ more_printf("%s : %s\n", category_name[i], modules[i]);
+ }
+ }
}
-static void show_kernel_help()
-{
- more_printf("Show supports the following commands : %s\n",
- CLI_SHOW_LIST);
-}
-
-void kernel_show(char *item, struct s_hardware *hardware)
-{
- if (!strncmp(item, CLI_SHOW_LIST, sizeof(CLI_SHOW_LIST) - 1)) {
- show_kernel_modules(hardware);
- return;
- }
- show_kernel_help();
-}
-
-void handle_kernel_commands(char *cli_line, struct s_hardware *hardware)
-{
- if (!strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1)) {
- kernel_show(strstr(cli_line, "show") + sizeof(CLI_SHOW),
- hardware);
- return;
- }
-}
+struct cli_module_descr kernel_show_modules = {
+ .modules = NULL,
+ .nb_modules = 0,
+ .default_callback = show_kernel_modules,
+};
+
+struct cli_mode_descr kernel_mode = {
+ .mode = KERNEL_MODE,
+ .name = CLI_KERNEL,
+ .default_modules = NULL,
+ .show_modules = &kernel_show_modules,
+ .set_modules = NULL,
+};
diff --git a/com32/hdt/hdt-cli-pci.c b/com32/hdt/hdt-cli-pci.c
index 31cfe771..a1b64c4f 100644
--- a/com32/hdt/hdt-cli-pci.c
+++ b/com32/hdt/hdt-cli-pci.c
@@ -33,276 +33,281 @@
#include "hdt-cli.h"
#include "hdt-common.h"
-void show_pci_device(struct s_hardware *hardware, const char *item)
+void main_show_pci(int argc __unused, char **argv __unused,
+ struct s_hardware *hardware)
{
- int i = 0;
- struct pci_device *pci_device = NULL, *temp_pci_device;
- long pcidev = strtol(item, (char **)NULL, 10);
- bool nopciids = false;
- bool nomodulespcimap = false;
- char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
- MAX_KERNEL_MODULES_PER_PCI_DEVICE];
- int bus = 0, slot = 0, func = 0;
+ cli_detect_pci(hardware);
- if (errno == ERANGE) {
- printf("This PCI device number is incorrect\n");
- return;
- }
- if ((pcidev > hardware->nb_pci_devices) || (pcidev <= 0)) {
- printf("PCI device %d doesn't exists\n", pcidev);
- return;
- }
- if (hardware->pci_ids_return_code == -ENOPCIIDS) {
- nopciids = true;
- }
- if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
- nomodulespcimap = true;
- }
+ more_printf("PCI\n");
+ more_printf(" NB Devices : %d\n", hardware->nb_pci_devices);
+}
+
+static void show_pci_device(int argc, char **argv,
+ struct s_hardware *hardware)
+{
+ int i = 0;
+ struct pci_device *pci_device = NULL, *temp_pci_device;
+ long pcidev = -1;
+ bool nopciids = false;
+ bool nomodulespcimap = false;
+ char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
+ MAX_KERNEL_MODULES_PER_PCI_DEVICE];
+ int bus = 0, slot = 0, func = 0;
+
+ /* Sanitize arguments */
+ if (argc <= 0) {
+ more_printf("show device <number>\n");
+ return;
+ } else
+ pcidev = strtol(argv[0], (char **)NULL, 10);
- for_each_pci_func(temp_pci_device, hardware->pci_domain) {
- i++;
- if (i == pcidev) {
- bus = __pci_bus;
- slot = __pci_slot;
- func = __pci_func;
- pci_device = temp_pci_device;
- }
- }
+ if (errno == ERANGE) {
+ more_printf("This PCI device number is incorrect\n");
+ return;
+ }
+ if ((pcidev > hardware->nb_pci_devices) || (pcidev <= 0)) {
+ more_printf("PCI device %d doesn't exists\n", pcidev);
+ return;
+ }
+ if (hardware->pci_ids_return_code == -ENOPCIIDS) {
+ nopciids = true;
+ }
+ if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
+ nomodulespcimap = true;
+ }
- if (pci_device == NULL) {
- printf("We were enabled to find PCI device %d\n", pcidev);
- return;
- }
+ for_each_pci_func(temp_pci_device, hardware->pci_domain) {
+ i++;
+ if (i == pcidev) {
+ bus = __pci_bus;
+ slot = __pci_slot;
+ func = __pci_func;
+ pci_device = temp_pci_device;
+ }
+ }
- memset(kernel_modules, 0, sizeof kernel_modules);
- for (int kmod = 0;
- kmod < pci_device->dev_info->linux_kernel_module_count; kmod++) {
- if (kmod > 0) {
- strncat(kernel_modules, " | ", 3);
- }
- strncat(kernel_modules,
- pci_device->dev_info->linux_kernel_module[kmod],
- LINUX_KERNEL_MODULE_SIZE - 1);
- }
- if (pci_device->dev_info->linux_kernel_module_count == 0)
- strlcpy(kernel_modules, "unknown", 7);
+ if (pci_device == NULL) {
+ more_printf("We were enabled to find PCI device %d\n", pcidev);
+ return;
+ }
- clear_screen();
- printf("PCI Device %d\n", pcidev);
+ memset(kernel_modules, 0, sizeof kernel_modules);
+ for (int kmod = 0;
+ kmod < pci_device->dev_info->linux_kernel_module_count; kmod++) {
+ if (kmod > 0) {
+ strncat(kernel_modules, " | ", 3);
+ }
+ strncat(kernel_modules,
+ pci_device->dev_info->linux_kernel_module[kmod],
+ LINUX_KERNEL_MODULE_SIZE - 1);
+ }
+ if (pci_device->dev_info->linux_kernel_module_count == 0)
+ strlcpy(kernel_modules, "unknown", 7);
- if (nopciids == false) {
- more_printf("Vendor Name : %s\n",
- pci_device->dev_info->vendor_name);
- more_printf("Product Name : %s\n",
- pci_device->dev_info->product_name);
- more_printf("Class Name : %s\n",
- pci_device->dev_info->class_name);
- }
+ clear_screen();
+ more_printf("PCI Device %d\n", pcidev);
- if (nomodulespcimap == false) {
- more_printf("Kernel module : %s\n", kernel_modules);
- }
+ if (nopciids == false) {
+ more_printf("Vendor Name : %s\n",
+ pci_device->dev_info->vendor_name);
+ more_printf("Product Name : %s\n",
+ pci_device->dev_info->product_name);
+ more_printf("Class Name : %s\n",
+ pci_device->dev_info->class_name);
+ }
- more_printf("Vendor ID : %04x\n", pci_device->vendor);
- more_printf("Product ID : %04x\n", pci_device->product);
- more_printf("SubVendor ID : %04x\n", pci_device->sub_vendor);
- more_printf("SubProduct ID : %04x\n", pci_device->sub_product);
- more_printf("Class ID : %02x.%02x.%02x\n", pci_device->class[2],
- pci_device->class[1], pci_device->class[0]);
- more_printf("Revision : %02x\n", pci_device->revision);
- if ((pci_device->dev_info->irq > 0)
- && (pci_device->dev_info->irq < 255))
- more_printf("IRQ : %0d\n", pci_device->dev_info->irq);
- more_printf("Latency : %0d\n",pci_device->dev_info->latency);
- more_printf("PCI Bus : %02d\n", bus);
- more_printf("PCI Slot : %02d\n", slot);
- more_printf("PCI Func : %02d\n", func);
+ if (nomodulespcimap == false) {
+ more_printf("Kernel module : %s\n", kernel_modules);
+ }
- if (hardware->is_pxe_valid == true) {
- more_printf("Mac Address : %s\n", hardware->pxe.mac_addr);
- if ((hardware->pxe.pci_device != NULL)
- && (hardware->pxe.pci_device == pci_device))
- more_printf("PXE : Current boot device\n",
- func);
- }
+ more_printf("Vendor ID : %04x\n", pci_device->vendor);
+ more_printf("Product ID : %04x\n", pci_device->product);
+ more_printf("SubVendor ID : %04x\n", pci_device->sub_vendor);
+ more_printf("SubProduct ID : %04x\n", pci_device->sub_product);
+ more_printf("Class ID : %02x.%02x.%02x\n", pci_device->class[2],
+ pci_device->class[1], pci_device->class[0]);
+ more_printf("Revision : %02x\n", pci_device->revision);
+ if ((pci_device->dev_info->irq > 0)
+ && (pci_device->dev_info->irq < 255))
+ more_printf("IRQ : %0d\n", pci_device->dev_info->irq);
+ more_printf("Latency : %0d\n", pci_device->dev_info->latency);
+ more_printf("PCI Bus : %02d\n", bus);
+ more_printf("PCI Slot : %02d\n", slot);
+ more_printf("PCI Func : %02d\n", func);
+
+ if (hardware->is_pxe_valid == true) {
+ more_printf("Mac Address : %s\n", hardware->pxe.mac_addr);
+ if ((hardware->pxe.pci_device != NULL)
+ && (hardware->pxe.pci_device == pci_device))
+ more_printf("PXE : Current boot device\n",
+ func);
+ }
}
-static void show_pci_devices(struct s_hardware *hardware)
+static void show_pci_devices(int argc __unused, char **argv __unused,
+ struct s_hardware *hardware)
{
- int i = 1;
- struct pci_device *pci_device;
- char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
- MAX_KERNEL_MODULES_PER_PCI_DEVICE];
- bool nopciids = false;
- bool nomodulespcimap = false;
- char first_line[81];
- char second_line[81];
+ int i = 1;
+ struct pci_device *pci_device;
+ char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
+ MAX_KERNEL_MODULES_PER_PCI_DEVICE];
+ bool nopciids = false;
+ bool nomodulespcimap = false;
+ char first_line[81];
+ char second_line[81];
- clear_screen();
- more_printf("%d PCI devices detected\n", hardware->nb_pci_devices);
+ clear_screen();
+ more_printf("%d PCI devices detected\n", hardware->nb_pci_devices);
- if (hardware->pci_ids_return_code == -ENOPCIIDS) {
- nopciids = true;
- }
- if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
- nomodulespcimap = true;
- }
+ if (hardware->pci_ids_return_code == -ENOPCIIDS) {
+ nopciids = true;
+ }
+ if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
+ nomodulespcimap = true;
+ }
- /* For every detected pci device, compute its submenu */
- for_each_pci_func(pci_device, hardware->pci_domain) {
- memset(kernel_modules, 0, sizeof kernel_modules);
- for (int kmod = 0;
- kmod < pci_device->dev_info->linux_kernel_module_count;
- kmod++) {
- if (kmod > 0) {
- strncat(kernel_modules, " | ", 3);
- }
- strncat(kernel_modules,
- pci_device->dev_info->linux_kernel_module[kmod],
- LINUX_KERNEL_MODULE_SIZE - 1);
- }
- if (pci_device->dev_info->linux_kernel_module_count == 0)
- strlcpy(kernel_modules, "unknown", 7);
+ /* For every detected pci device, compute its submenu */
+ for_each_pci_func(pci_device, hardware->pci_domain) {
+ memset(kernel_modules, 0, sizeof kernel_modules);
+ for (int kmod = 0;
+ kmod < pci_device->dev_info->linux_kernel_module_count;
+ kmod++) {
+ if (kmod > 0) {
+ strncat(kernel_modules, " | ", 3);
+ }
+ strncat(kernel_modules,
+ pci_device->dev_info->linux_kernel_module[kmod],
+ LINUX_KERNEL_MODULE_SIZE - 1);
+ }
+ if (pci_device->dev_info->linux_kernel_module_count == 0)
+ strlcpy(kernel_modules, "unknown", 7);
- if (nopciids == false) {
- snprintf(first_line, sizeof(first_line),
- "%02d: %s %s \n", i,
- pci_device->dev_info->vendor_name,
- pci_device->dev_info->product_name);
- if (nomodulespcimap == false)
- snprintf(second_line, sizeof(second_line),
- " # %-25s # Kmod: %s\n",
- pci_device->dev_info->class_name,
- kernel_modules);
- else
- snprintf(second_line, sizeof(second_line),
- " # %-25s # ID:%04x:%04x[%04x:%04x]\n",
- pci_device->dev_info->class_name,
- pci_device->vendor,
- pci_device->product,
- pci_device->sub_vendor,
- pci_device->sub_product);
+ if (nopciids == false) {
+ snprintf(first_line, sizeof(first_line),
+ "%02d: %s %s \n", i,
+ pci_device->dev_info->vendor_name,
+ pci_device->dev_info->product_name);
+ if (nomodulespcimap == false)
+ snprintf(second_line, sizeof(second_line),
+ " # %-25s # Kmod: %s\n",
+ pci_device->dev_info->class_name,
+ kernel_modules);
+ else
+ snprintf(second_line, sizeof(second_line),
+ " # %-25s # ID:%04x:%04x[%04x:%04x]\n",
+ pci_device->dev_info->class_name,
+ pci_device->vendor,
+ pci_device->product,
+ pci_device->sub_vendor,
+ pci_device->sub_product);
- more_printf(first_line);
- more_printf(second_line);
- more_printf("\n");
- } else if (nopciids == true) {
- if (nomodulespcimap == true) {
- more_printf("%02d: %04x:%04x [%04x:%04x] \n",
- i, pci_device->vendor,
- pci_device->product,
- pci_device->sub_vendor,
- pci_device->sub_product);
- } else {
- more_printf
- ("%02d: %04x:%04x [%04x:%04x] Kmod:%s\n", i,
- pci_device->vendor, pci_device->product,
- pci_device->sub_vendor,
- pci_device->sub_product, kernel_modules,
- pci_device->sub_product, kernel_modules);
- }
- }
- i++;
- }
+ more_printf(first_line);
+ more_printf(second_line);
+ more_printf("\n");
+ } else if (nopciids == true) {
+ if (nomodulespcimap == true) {
+ more_printf("%02d: %04x:%04x [%04x:%04x] \n",
+ i, pci_device->vendor,
+ pci_device->product,
+ pci_device->sub_vendor,
+ pci_device->sub_product);
+ } else {
+ more_printf
+ ("%02d: %04x:%04x [%04x:%04x] Kmod:%s\n", i,
+ pci_device->vendor, pci_device->product,
+ pci_device->sub_vendor,
+ pci_device->sub_product, kernel_modules,
+ pci_device->sub_product, kernel_modules);
+ }
+ }
+ i++;
+ }
}
-static void show_pci_irq(struct s_hardware *hardware)
+static void show_pci_irq(int argc __unused, char **argv __unused,
+ struct s_hardware *hardware)
{
- struct pci_device *pci_device;
- bool nopciids = false;
+ struct pci_device *pci_device;
+ bool nopciids = false;
- clear_screen();
- more_printf("%d PCI devices detected\n", hardware->nb_pci_devices);
- more_printf("IRQ : product\n");
- more_printf("-------------\n");
+ clear_screen();
+ more_printf("%d PCI devices detected\n", hardware->nb_pci_devices);
+ more_printf("IRQ : product\n");
+ more_printf("-------------\n");
- if (hardware->pci_ids_return_code == -ENOPCIIDS) {
- nopciids = true;
- }
+ if (hardware->pci_ids_return_code == -ENOPCIIDS) {
+ nopciids = true;
+ }
- /* For every detected pci device, compute its submenu */
- for_each_pci_func(pci_device, hardware->pci_domain) {
- /* Only display valid IRQs */
- if ((pci_device->dev_info->irq > 0) && (pci_device->dev_info->irq < 255)) {
- if (nopciids == false) {
- more_printf("%02d : %s %s \n",
- pci_device->dev_info->irq,
- pci_device->dev_info->vendor_name,
- pci_device->dev_info->product_name);
- } else {
- more_printf("%02d : %04x:%04x [%04x:%04x] \n",
- pci_device->dev_info->irq, pci_device->vendor,
- pci_device->product,
- pci_device->sub_vendor,
- pci_device->sub_product);
- }
- }
- }
+ /* For every detected pci device, compute its submenu */
+ for_each_pci_func(pci_device, hardware->pci_domain) {
+ /* Only display valid IRQs */
+ if ((pci_device->dev_info->irq > 0)
+ && (pci_device->dev_info->irq < 255)) {
+ if (nopciids == false) {
+ more_printf("%02d : %s %s \n",
+ pci_device->dev_info->irq,
+ pci_device->dev_info->vendor_name,
+ pci_device->dev_info->product_name);
+ } else {
+ more_printf("%02d : %04x:%04x [%04x:%04x] \n",
+ pci_device->dev_info->irq,
+ pci_device->vendor,
+ pci_device->product,
+ pci_device->sub_vendor,
+ pci_device->sub_product);
+ }
+ }
+ }
}
-static void show_pci_help()
-{
- more_printf("Show supports the following commands : \n");
- more_printf(" %s\n", CLI_SHOW_LIST);
- more_printf(" %s <device_number>\n", CLI_PCI_DEVICE);
- more_printf(" %s\n",CLI_IRQ);
-}
+struct cli_callback_descr list_pci_show_modules[] = {
+ {
+ .name = CLI_IRQ,
+ .exec = show_pci_irq,
+ },
+ {
+ .name = CLI_PCI_DEVICE,
+ .exec = show_pci_device,
+ },
+};
-static void pci_show(char *item, struct s_hardware *hardware)
-{
- if (!strncmp(item, CLI_SHOW_LIST, sizeof(CLI_SHOW_LIST) - 1)) {
- show_pci_devices(hardware);
- return;
- }
- if (!strncmp(item, CLI_IRQ, sizeof(CLI_IRQ) - 1)) {
- show_pci_irq(hardware);
- return;
- }
- if (!strncmp(item, CLI_PCI_DEVICE, sizeof(CLI_PCI_DEVICE) - 1)) {
- show_pci_device(hardware, item + sizeof(CLI_PCI_DEVICE) - 1);
- return;
- }
- show_pci_help();
-}
+struct cli_module_descr pci_show_modules = {
+ .modules = list_pci_show_modules,
+ .nb_modules = 2,
+ .default_callback = show_pci_devices,
+};
-void handle_pci_commands(char *cli_line, struct s_hardware *hardware)
-{
- if (!strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1)) {
- pci_show(strstr(cli_line, "show") + sizeof(CLI_SHOW), hardware);
- return;
- }
-}
+struct cli_mode_descr pci_mode = {
+ .mode = PCI_MODE,
+ .name = CLI_PCI,
+ .default_modules = NULL,
+ .show_modules = &pci_show_modules,
+ .set_modules = NULL,
+};
void cli_detect_pci(struct s_hardware *hardware)
{
- bool error = false;
- if (hardware->pci_detection == false) {
- detect_pci(hardware);
- if (hardware->pci_ids_return_code == -ENOPCIIDS) {
- more_printf
- ("The pci.ids file is missing, device names can't be computed.\n");
- more_printf("Please put one in same dir as hdt\n");
- error = true;
- }
- if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
- more_printf
- ("The modules.pcimap file is missing, device names can't be computed.\n");
- more_printf("Please put one in same dir as hdt\n");
- error = true;
- }
- if (error == true) {
- char tempbuf[10];
- printf("Press enter to continue\n");
- fgets(tempbuf, sizeof(tempbuf), stdin);
- }
- }
-}
-
-void main_show_pci(struct s_hardware *hardware)
-{
- cli_detect_pci(hardware);
-
- more_printf("PCI\n");
- more_printf(" NB Devices : %d\n", hardware->nb_pci_devices);
+ bool error = false;
+ if (hardware->pci_detection == false) {
+ detect_pci(hardware);
+ if (hardware->pci_ids_return_code == -ENOPCIIDS) {
+ more_printf
+ ("The pci.ids file is missing, device names can't be computed.\n");
+ more_printf("Please put one in same dir as hdt\n");
+ error = true;
+ }
+ if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
+ more_printf
+ ("The modules.pcimap file is missing, device names can't be computed.\n");
+ more_printf("Please put one in same dir as hdt\n");
+ error = true;
+ }
+ if (error == true) {
+ char tempbuf[10];
+ more_printf("Press enter to continue\n");
+ fgets(tempbuf, sizeof(tempbuf), stdin);
+ }
+ }
}
diff --git a/com32/hdt/hdt-cli-pxe.c b/com32/hdt/hdt-cli-pxe.c
index 5c556645..601619c2 100644
--- a/com32/hdt/hdt-cli-pxe.c
+++ b/com32/hdt/hdt-cli-pxe.c
@@ -36,65 +36,58 @@
#include "hdt-cli.h"
#include "hdt-common.h"
-void main_show_pxe(struct s_hardware *hardware)
+void main_show_pxe(int argc __unused, char **argv __unused,
+ struct s_hardware *hardware)
{
- char buffer[81];
- memset(buffer, 0, sizeof(81));
- if (hardware->sv->filesystem != SYSLINUX_FS_PXELINUX) {
- more_printf("You are not currently using PXELINUX\n");
- return;
- }
+ char buffer[81];
+ memset(buffer, 0, sizeof(81));
+ if (hardware->sv->filesystem != SYSLINUX_FS_PXELINUX) {
+ more_printf("You are not currently using PXELINUX\n");
+ return;
+ }
- detect_pxe(hardware);
- more_printf("PXE\n");
- if (hardware->is_pxe_valid == false) {
- more_printf(" No valid PXE ROM found\n");
- return;
- }
+ detect_pxe(hardware);
+ more_printf("PXE\n");
+ if (hardware->is_pxe_valid == false) {
+ more_printf(" No valid PXE ROM found\n");
+ return;
+ }
- struct s_pxe *p = &hardware->pxe;
- more_printf(" PCI device no: %d \n", p->pci_device_pos);
+ struct s_pxe *p = &hardware->pxe;
+ more_printf(" PCI device no: %d \n", p->pci_device_pos);
- if ((hardware->pci_ids_return_code == -ENOPCIIDS) || (p->pci_device==NULL)) {
- snprintf(buffer, sizeof(buffer),
- " PCI ID : %04x:%04x[%04x:%04X] rev(%02x)\n",
- p->vendor_id, p->product_id, p->subvendor_id,
- p->subproduct_id, p->rev);
- snprintf(buffer, sizeof(buffer),
- " PCI Bus pos. : %02x:%02x.%02x\n", p->pci_bus,
- p->pci_dev, p->pci_func);
- more_printf(buffer);
- } else {
- snprintf(buffer, sizeof(buffer), " Manufacturer : %s \n",
- p->pci_device->dev_info->vendor_name);
- more_printf(buffer);
- snprintf(buffer, sizeof(buffer), " Product : %s \n",
- p->pci_device->dev_info->product_name);
- more_printf(buffer);
- }
- more_printf(" Addresses : %d.%d.%d.%d @ %s\n", p->ip_addr[0],
- p->ip_addr[1], p->ip_addr[2], p->ip_addr[3], p->mac_addr);
+ if (hardware->pci_ids_return_code == -ENOPCIIDS ||
+ (p->pci_device == NULL)) {
+ snprintf(buffer, sizeof(buffer),
+ " PCI ID : %04x:%04x[%04x:%04X] rev(%02x)\n",
+ p->vendor_id, p->product_id, p->subvendor_id,
+ p->subproduct_id, p->rev);
+ snprintf(buffer, sizeof(buffer),
+ " PCI Bus pos. : %02x:%02x.%02x\n", p->pci_bus,
+ p->pci_dev, p->pci_func);
+ more_printf(buffer);
+ } else {
+ snprintf(buffer, sizeof(buffer), " Manufacturer : %s \n",
+ p->pci_device->dev_info->vendor_name);
+ more_printf(buffer);
+ snprintf(buffer, sizeof(buffer), " Product : %s \n",
+ p->pci_device->dev_info->product_name);
+ more_printf(buffer);
+ }
+ more_printf(" Addresses : %d.%d.%d.%d @ %s\n", p->ip_addr[0],
+ p->ip_addr[1], p->ip_addr[2], p->ip_addr[3], p->mac_addr);
}
-static void show_pxe_help()
-{
- more_printf("Show supports the following commands : %s\n",
- CLI_SHOW_LIST);
-}
+struct cli_module_descr pxe_show_modules = {
+ .modules = NULL,
+ .nb_modules = 0,
+ .default_callback = main_show_pxe,
+};
-static void pxe_show(char *item, struct s_hardware *hardware)
-{
- if (!strncmp(item, CLI_SHOW_LIST, sizeof(CLI_SHOW_LIST) - 1)) {
- main_show_pxe(hardware);
- return;
- }
- show_pxe_help();
-}
-
-void handle_pxe_commands(char *cli_line, struct s_hardware *hardware)
-{
- if (!strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1)) {
- pxe_show(strstr(cli_line, "show") + sizeof(CLI_SHOW), hardware);
- return;
- }
-}
+struct cli_mode_descr pxe_mode = {
+ .mode = PXE_MODE,
+ .name = CLI_PXE,
+ .default_modules = NULL,
+ .show_modules = &pxe_show_modules,
+ .set_modules = NULL,
+};
diff --git a/com32/hdt/hdt-cli-syslinux.c b/com32/hdt/hdt-cli-syslinux.c
index 77a44f31..168a3d3a 100644
--- a/com32/hdt/hdt-cli-syslinux.c
+++ b/com32/hdt/hdt-cli-syslinux.c
@@ -36,7 +36,8 @@
#include "hdt-cli.h"
#include "hdt-common.h"
-void main_show_syslinux(struct s_hardware *hardware)
+void main_show_syslinux(int argc __unused, char **argv __unused,
+ struct s_hardware *hardware)
{
more_printf("SYSLINUX\n");
more_printf(" Bootloader : %s\n", hardware->syslinux_fs);
@@ -46,26 +47,16 @@ void main_show_syslinux(struct s_hardware *hardware)
more_printf(" Copyright : %s\n", hardware->sv->copyright_string + 1);
}
-static void show_syslinux_help()
-{
- more_printf("Show supports the following commands : %s\n",
- CLI_SHOW_LIST);
-}
+struct cli_module_descr syslinux_show_modules = {
+ .modules = NULL,
+ .nb_modules = 0,
+ .default_callback = main_show_syslinux,
+};
-static void syslinux_show(char *item, struct s_hardware *hardware)
-{
- if (!strncmp(item, CLI_SHOW_LIST, sizeof(CLI_SHOW_LIST) - 1)) {
- main_show_syslinux(hardware);
- return;
- }
- show_syslinux_help();
-}
-
-void handle_syslinux_commands(char *cli_line, struct s_hardware *hardware)
-{
- if (!strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1)) {
- syslinux_show(strstr(cli_line, "show") + sizeof(CLI_SHOW),
- hardware);
- return;
- }
-}
+struct cli_mode_descr syslinux_mode = {
+ .mode = SYSLINUX_MODE,
+ .name = CLI_SYSLINUX,
+ .default_modules = NULL,
+ .show_modules = &syslinux_show_modules,
+ .set_modules = NULL,
+};
diff --git a/com32/hdt/hdt-cli-vesa.c b/com32/hdt/hdt-cli-vesa.c
index 202b75f1..4234135d 100644
--- a/com32/hdt/hdt-cli-vesa.c
+++ b/com32/hdt/hdt-cli-vesa.c
@@ -33,62 +33,70 @@
#include <stdlib.h>
#include <errno.h>
-void main_show_vesa(struct s_hardware *hardware) {
- detect_vesa(hardware);
- if (hardware->is_vesa_valid==false) {
- more_printf("No VESA BIOS detected\n");
- return;
- }
- more_printf("VESA\n");
- more_printf(" Vesa version : %d.%d\n",hardware->vesa.major_version, hardware->vesa.minor_version);
- more_printf(" Vendor : %s\n",hardware->vesa.vendor);
- more_printf(" Product : %s\n",hardware->vesa.product);
- more_printf(" Product rev. : %s\n",hardware->vesa.product_revision);
- more_printf(" Software rev.: %d\n",hardware->vesa.software_rev);
- more_printf(" Memory (KB) : %d\n",hardware->vesa.total_memory*64);
- more_printf(" Modes : %d\n",hardware->vesa.vmi_count);
+void main_show_vesa(int argc __unused, char **argv __unused,
+ struct s_hardware *hardware)
+{
+ detect_vesa(hardware);
+ if (hardware->is_vesa_valid == false) {
+ more_printf("No VESA BIOS detected\n");
+ return;
+ }
+ more_printf("VESA\n");
+ more_printf(" Vesa version : %d.%d\n", hardware->vesa.major_version,
+ hardware->vesa.minor_version);
+ more_printf(" Vendor : %s\n", hardware->vesa.vendor);
+ more_printf(" Product : %s\n", hardware->vesa.product);
+ more_printf(" Product rev. : %s\n", hardware->vesa.product_revision);
+ more_printf(" Software rev.: %s\n", hardware->vesa.software_rev);
+ more_printf(" Memory (KB) : %d\n", hardware->vesa.total_memory * 64);
+ more_printf(" Modes : %d\n", hardware->vesa.vmi_count);
}
-void show_vesa_modes(struct s_hardware *hardware) {
- detect_vesa(hardware);
- if (hardware->is_vesa_valid==false) {
- more_printf("No VESA BIOS detected\n");
- return;
- }
- clear_screen();
- more_printf(" ResH. x ResV x Bits : vga= : Vesa Mode\n",hardware->vesa.vmi_count);
- more_printf("----------------------------------------\n",hardware->vesa.vmi_count);
+static void show_vesa_modes(int argc __unused, char **argv __unused,
+ struct s_hardware *hardware)
+{
+ detect_vesa(hardware);
+ if (hardware->is_vesa_valid == false) {
+ more_printf("No VESA BIOS detected\n");
+ return;
+ }
+ clear_screen();
+ more_printf(" ResH. x ResV x Bits : vga= : Vesa Mode\n",
+ hardware->vesa.vmi_count);
+ more_printf("----------------------------------------\n",
+ hardware->vesa.vmi_count);
- for (int i=0;i<hardware->vesa.vmi_count;i++) {
- struct vesa_mode_info *mi=&hardware->vesa.vmi[i].mi;
- /* Sometimes, vesa bios reports 0x0 modes
- * We don't need to display that ones */
- if ((mi->h_res==0) || (mi->v_res==0)) continue;
- more_printf("%5u %5u %3u %3d 0x%04x\n",
- mi->h_res, mi->v_res, mi->bpp, hardware->vesa.vmi[i].mode+0x200,hardware->vesa.vmi[i].mode);
- }
+ for (int i = 0; i < hardware->vesa.vmi_count; i++) {
+ struct vesa_mode_info *mi = &hardware->vesa.vmi[i].mi;
+ /*
+ * Sometimes, vesa bios reports 0x0 modes.
+ * We don't need to display that ones.
+ */
+ if ((mi->h_res == 0) || (mi->v_res == 0)) continue;
+ more_printf("%5u %5u %3u %3d 0x%04x\n",
+ mi->h_res, mi->v_res, mi->bpp,
+ hardware->vesa.vmi[i].mode + 0x200,
+ hardware->vesa.vmi[i].mode);
+ }
}
-static void show_vesa_help() {
- more_printf("Show supports the following commands : %s %s\n",CLI_SHOW_LIST, CLI_MODES);
-}
-
-static void vesa_show(char *item, struct s_hardware *hardware) {
- if ( !strncmp(item, CLI_SHOW_LIST, sizeof(CLI_SHOW_LIST) - 1) ) {
- main_show_vesa(hardware);
- return;
- }
- if ( !strncmp(item, CLI_MODES, sizeof(CLI_MODES) - 1) ) {
- show_vesa_modes(hardware);
- return;
- }
- show_vesa_help();
-}
+struct cli_callback_descr list_vesa_show_modules[] = {
+ {
+ .name = CLI_MODES,
+ .exec = show_vesa_modes,
+ },
+};
-void handle_vesa_commands(char *cli_line, struct s_hardware *hardware) {
- if ( !strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1) ) {
- vesa_show(strstr(cli_line,"show")+ sizeof(CLI_SHOW), hardware);
- return;
- }
-}
+struct cli_module_descr vesa_show_modules = {
+ .modules = list_vesa_show_modules,
+ .nb_modules = 1,
+ .default_callback = main_show_vesa,
+};
+struct cli_mode_descr vesa_mode = {
+ .mode = VESA_MODE,
+ .name = CLI_VESA,
+ .default_modules = NULL,
+ .show_modules = &vesa_show_modules,
+ .set_modules = NULL,
+};
diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c
index 8e716904..3fd7ce41 100644
--- a/com32/hdt/hdt-cli.c
+++ b/com32/hdt/hdt-cli.c
@@ -32,320 +32,686 @@
#include <getkey.h>
#include "hdt-cli.h"
#include "hdt-common.h"
+#include "lib-ansi.h"
-#define MAX_MODES 1
-struct commands_mode *list_modes[] = {
+struct cli_mode_descr *list_modes[] = {
+ &hdt_mode,
&dmi_mode,
+ &syslinux_mode,
+ &pxe_mode,
+ &kernel_mode,
+ &cpu_mode,
+ &pci_mode,
+ &vesa_mode,
};
-static void set_mode(struct s_cli *cli, cli_mode_t mode,
- struct s_hardware *hardware)
+/*
+ * .aliases = {"q", "quit"} won't work since it is an array of pointers, not an
+ * array of variables. There is no easy way around it besides declaring the arrays of
+ * strings first.
+ */
+char *exit_aliases[] = {"q", "quit"};
+char *help_aliases[] = {"h", "?"};
+
+/* List of aliases */
+struct cli_alias hdt_aliases[] = {
+ {
+ .command = CLI_EXIT,
+ .nb_aliases = 2,
+ .aliases = exit_aliases,
+ },
+ {
+ .command = CLI_HELP,
+ .nb_aliases = 2,
+ .aliases = help_aliases,
+ },
+};
+
+struct cli_mode_descr *current_mode;
+int autocomplete_backlog;
+
+struct autocomplete_list {
+ char autocomplete_token[MAX_LINE_SIZE];
+ struct autocomplete_list *next;
+};
+struct autocomplete_list* autocomplete_head = NULL;
+struct autocomplete_list* autocomplete_tail = NULL;
+struct autocomplete_list* autocomplete_last_seen = NULL;
+
+static void autocomplete_add_token_to_list(const char *token)
+{
+ struct autocomplete_list *new = malloc(sizeof(struct autocomplete_list));
+
+ strncpy(new->autocomplete_token, token, sizeof(new->autocomplete_token));
+ new->next = NULL;
+ autocomplete_backlog++;
+
+ if (autocomplete_tail != NULL)
+ autocomplete_tail->next = new;
+ if (autocomplete_head == NULL)
+ autocomplete_head = new;
+ autocomplete_tail = new;
+}
+
+static void autocomplete_destroy_list()
+{
+ struct autocomplete_list* tmp = NULL;
+
+ while (autocomplete_head != NULL) {
+ tmp = autocomplete_head->next;
+ free(autocomplete_head);
+ autocomplete_head = tmp;
+ }
+ autocomplete_backlog = 0;
+ autocomplete_tail = NULL;
+ autocomplete_last_seen = NULL;
+}
+
+/**
+ * set_mode - set the current mode of the cli
+ * @mode: mode to set
+ *
+ * Unlike cli_set_mode, this function is not used by the cli directly.
+ **/
+void set_mode(cli_mode_t mode, struct s_hardware* hardware)
{
+ int i;
+
switch (mode) {
case EXIT_MODE:
- cli->mode = mode;
+ hdt_cli.mode = mode;
break;
-
case HDT_MODE:
- cli->mode = mode;
- snprintf(cli->prompt, sizeof(cli->prompt), "%s> ", CLI_HDT);
+ hdt_cli.mode = mode;
+ snprintf(hdt_cli.prompt, sizeof(hdt_cli.prompt), "%s> ",
+ CLI_HDT);
break;
-
case PXE_MODE:
if (hardware->sv->filesystem != SYSLINUX_FS_PXELINUX) {
more_printf("You are not currently using PXELINUX\n");
break;
}
- cli->mode = mode;
- snprintf(cli->prompt, sizeof(cli->prompt), "%s> ", CLI_PXE);
+ hdt_cli.mode = mode;
+ snprintf(hdt_cli.prompt, sizeof(hdt_cli.prompt), "%s> ",
+ CLI_PXE);
break;
-
case KERNEL_MODE:
detect_pci(hardware);
- cli->mode = mode;
- snprintf(cli->prompt, sizeof(cli->prompt), "%s> ", CLI_KERNEL);
+ hdt_cli.mode = mode;
+ snprintf(hdt_cli.prompt, sizeof(hdt_cli.prompt), "%s> ",
+ CLI_KERNEL);
break;
-
case SYSLINUX_MODE:
- cli->mode = mode;
- snprintf(cli->prompt, sizeof(cli->prompt), "%s> ",
+ hdt_cli.mode = mode;
+ snprintf(hdt_cli.prompt, sizeof(hdt_cli.prompt), "%s> ",
CLI_SYSLINUX);
break;
-
case VESA_MODE:
- cli->mode = mode;
- snprintf(cli->prompt, sizeof(cli->prompt), "%s> ", CLI_VESA);
+ hdt_cli.mode = mode;
+ snprintf(hdt_cli.prompt, sizeof(hdt_cli.prompt), "%s> ",
+ CLI_VESA);
break;
-
case PCI_MODE:
- cli->mode = mode;
- snprintf(cli->prompt, sizeof(cli->prompt), "%s> ", CLI_PCI);
+ hdt_cli.mode = mode;
+ snprintf(hdt_cli.prompt, sizeof(hdt_cli.prompt), "%s> ",
+ CLI_PCI);
if (!hardware->pci_detection)
cli_detect_pci(hardware);
break;
-
case CPU_MODE:
- cli->mode = mode;
- snprintf(cli->prompt, sizeof(cli->prompt), "%s> ", CLI_CPU);
+ hdt_cli.mode = mode;
+ snprintf(hdt_cli.prompt, sizeof(hdt_cli.prompt), "%s> ",
+ CLI_CPU);
if (!hardware->dmi_detection)
detect_dmi(hardware);
if (!hardware->cpu_detection)
cpu_detect(hardware);
break;
-
case DMI_MODE:
detect_dmi(hardware);
if (!hardware->is_dmi_valid) {
more_printf("No valid DMI table found, exiting.\n");
break;
}
- cli->mode = mode;
- snprintf(cli->prompt, sizeof(cli->prompt), "%s> ", CLI_DMI);
+ hdt_cli.mode = mode;
+ snprintf(hdt_cli.prompt, sizeof(hdt_cli.prompt), "%s> ",
+ CLI_DMI);
break;
+ default:
+ /* Invalid mode */
+ more_printf("Unknown mode, please choose among:\n");
+ for (i = 0; i < MAX_MODES; i++)
+ more_printf("\t%s\n", list_modes[i]->name);
+ }
+
+ find_cli_mode_descr(hdt_cli.mode, &current_mode);
+ /* There is not cli_mode_descr struct for the exit mode */
+ if (current_mode == NULL && hdt_cli.mode != EXIT_MODE) {
+ /* Shouldn't get here... */
+ more_printf("!!! BUG: Mode '%d' unknown.\n", hdt_cli.mode);
}
}
-static void handle_hdt_commands(char *cli_line, struct s_hardware *hardware)
+/**
+ * mode_s_to_mode_t - given a mode string, return the cli_mode_t representation
+ **/
+cli_mode_t mode_s_to_mode_t(char *name)
{
- /* hdt cli mode specific commands */
- if (!strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1)) {
- main_show(strstr(cli_line, "show") + sizeof(CLI_SHOW),
- hardware);
- return;
- }
+ int i = 0;
+
+ for (i = 0; i < MAX_MODES; i++)
+ if (!strncmp(name, list_modes[i]->name,
+ sizeof(list_modes[i]->name)))
+ break;
+
+ if (i == MAX_MODES)
+ return INVALID_MODE;
+ else
+ return list_modes[i]->mode;
}
-static void show_cli_help(struct s_cli *cli)
+/**
+ * find_cli_mode_descr - find the cli_mode_descr struct associated to a mode
+ * @mode: mode to look for
+ * @mode_found: store the mode if found, NULL otherwise
+ *
+ * Given a mode name, return a pointer to the associated cli_mode_descr
+ * structure.
+ * Note: the current mode name is stored in hdt_cli.mode.
+ **/
+void find_cli_mode_descr(cli_mode_t mode, struct cli_mode_descr **mode_found)
{
- switch (cli->mode) {
- case HDT_MODE:
- more_printf("Available commands are :\n");
- more_printf
- ("%s %s %s %s %s %s %s %s %s %s %s\n",
- CLI_CLEAR, CLI_EXIT, CLI_HELP, CLI_SHOW, CLI_PCI, CLI_DMI,
- CLI_PXE, CLI_KERNEL, CLI_CPU, CLI_SYSLINUX, CLI_VESA);
- break;
- case SYSLINUX_MODE:
- case KERNEL_MODE:
- case PXE_MODE:
- case VESA_MODE:
- case CPU_MODE:
- case PCI_MODE:
- case DMI_MODE:
- printf("Available commands are : %s %s %s %s\n",
- CLI_CLEAR, CLI_EXIT, CLI_HELP, CLI_SHOW);
- break;
- case EXIT_MODE: /* Should not happen */
- break;
+ int modes_iter = 0;
+
+ while (modes_iter < MAX_MODES &&
+ list_modes[modes_iter]->mode != mode)
+ modes_iter++;
+
+ /* Shouldn't get here... */
+ if (modes_iter == MAX_MODES)
+ *mode_found = NULL;
+ else
+ *mode_found = list_modes[modes_iter];
+}
+
+/**
+ * expand_aliases - resolve aliases mapping
+ * @line: command line to parse
+ * @command: first token in the line
+ * @module: second token in the line
+ * @argc: number of arguments
+ * @argv: array of arguments
+ *
+ * We maintain a small list of static alises to enhance user experience.
+ * Only commands can be aliased (first token). Otherwise it can become really hairy...
+ **/
+static void expand_aliases(char *line __unused, char **command, char **module,
+ int *argc, char **argv)
+{
+ struct cli_mode_descr *mode;
+ int i, j;
+
+ find_cli_mode_descr(mode_s_to_mode_t(*command), &mode);
+ if (mode != NULL && *module == NULL) {
+ /*
+ * The user specified a mode instead of `set mode...', e.g.
+ * `dmi' instead of `set mode dmi'
+ */
+
+ /* *argv is NULL since *module is NULL */
+ *argc = 1;
+ *argv = malloc(*argc * sizeof(char *));
+ argv[0] = malloc((sizeof(*command) + 1) * sizeof(char));
+ strncpy(argv[0], *command, sizeof(*command) + 1);
+ dprintf("CLI DEBUG: ALIAS %s ", *command);
+
+ strncpy(*command, CLI_SET, sizeof(CLI_SET)); /* set */
+
+ *module = malloc(sizeof(CLI_MODE) * sizeof(char));
+ strncpy(*module, CLI_MODE, sizeof(CLI_MODE)); /* mode */
+
+ dprintf("--> %s %s %s\n", *command, *module, argv[0]);
+ goto out;
+ }
+
+ /* Simple aliases mapping a single command to another one */
+ for (i = 0; i < MAX_ALIASES; i++) {
+ for (j = 0; j < hdt_aliases[i].nb_aliases; j++) {
+ if (!strncmp(*command, hdt_aliases[i].aliases[j],
+ sizeof(hdt_aliases[i].aliases[j]))) {
+ dprintf("CLI DEBUG: ALIAS %s ", *command);
+ strncpy(*command, hdt_aliases[i].command,
+ sizeof(hdt_aliases[i].command) + 1);
+ dprintf("--> %s\n", *command);
+ goto out; /* Don't allow chaining aliases */
+ }
+ }
}
+ return;
+
+out:
+ dprintf("CLI DEBUG: New parameters:\n");
+ dprintf("CLI DEBUG: command = %s\n", *command);
+ dprintf("CLI DEBUG: module = %s\n", *module);
+ dprintf("CLI DEBUG: argc = %d\n", *argc);
+ for (i = 0; i < *argc; i++)
+ dprintf("CLI DEBUG: argv[%d] = %s\n", i, argv[0]);
+ return;
}
-static void exec_command(char *command, struct s_cli *cli,
- struct s_hardware *hardware)
+/**
+ * parse_command_line - low level parser for the command line
+ * @line: command line to parse
+ * @command: first token in the line
+ * @module: second token in the line
+ * @argc: number of arguments
+ * @argv: array of arguments
+ *
+ * The format of the command line is:
+ * <main command> [<module on which to operate> [<args>]]
+ **/
+static void parse_command_line(char *line, char **command, char **module,
+ int *argc, char **argv)
{
- /* We use sizeof BLAH - 1 to remove the last \0 */
-// command[strlen(command) - 1] = '\0';
+ int argc_iter = 0, args_pos = 0, token_found = 0, token_len = 0;
+ int args_len = 0;
+ char *pch = NULL, *pch_next = NULL, *tmp_pch_next = NULL;
- if (!strncmp(command, CLI_EXIT, sizeof(CLI_EXIT) - 1)) {
- int mode = do_exit(cli);
- set_mode(cli, mode, hardware);
- return;
+ *command = NULL;
+ *module = NULL;
+ *argc = 0;
+
+ pch = line;
+ while (pch != NULL) {
+ pch_next = strchr(pch + 1, ' ');
+ tmp_pch_next = pch_next;
+
+ /*
+ * Skip whitespaces if the user entered
+ * 'set mode foo' for 'set mode foo'
+ * ^ ^
+ * |___|___ pch
+ * |___ pch_next <- wrong!
+ *
+ * We still keep the position into tmp_pch_next to compute
+ * the lenght of the current token.
+ */
+ while (pch_next != NULL && !strncmp(pch_next, CLI_SPACE, 1))
+ pch_next++;
+
+ /* End of line guaranteed to be zeroed */
+ if (pch_next == NULL) {
+ token_len = (int) (strchr(pch + 1, '\0') - pch);
+ args_len = token_len;
+ }
+ else {
+ token_len = (int) (tmp_pch_next - pch);
+ args_len = (int) (pch_next - pch);
+ }
+
+ if (token_found == 0) {
+ /* Main command to execute */
+ *command = malloc((token_len + 1) * sizeof(char));
+ strncpy(*command, pch, token_len);
+ (*command)[token_len] = '\0';
+ dprintf("CLI DEBUG: command = %s\n", *command);
+ args_pos += args_len;
+ } else if (token_found == 1) {
+ /* Module */
+ *module = malloc((token_len + 1) * sizeof(char));
+ strncpy(*module, pch, token_len);
+ (*module)[token_len] = '\0';
+ dprintf("CLI DEBUG: module = %s\n", *module);
+ args_pos += args_len;
+ } else
+ (*argc)++;
+
+ token_found++;
+ pch = pch_next;
}
+ dprintf("CLI DEBUG: argc = %d\n", *argc);
- if (!strncmp(command, CLI_HELP, sizeof(CLI_HELP) - 1)) {
- show_cli_help(cli);
+ /* Skip arguments handling if none is supplied */
+ if (!*argc)
return;
+
+ /* Transform the arguments string into an array */
+ *argv = malloc(*argc * sizeof(char *));
+ pch = strtok(line + args_pos, CLI_SPACE);
+ while (pch != NULL) {
+ dprintf("CLI DEBUG: argv[%d] = %s\n", argc_iter, pch);
+ argv[argc_iter] = malloc(sizeof(pch) * sizeof(char));
+ strncpy(argv[argc_iter], pch, sizeof(pch));
+ argc_iter++;
+ pch = strtok(NULL, CLI_SPACE);
+ /*
+ * strtok(NULL, CLI_SPACE) over a stream of spaces
+ * will return an empty string
+ */
+ while (pch != NULL && !strncmp(pch, "", 1))
+ pch = strtok(NULL, CLI_SPACE);
}
+}
- if (!strncmp(command, CLI_PCI, sizeof(CLI_PCI) - 1)) {
- set_mode(cli, PCI_MODE, hardware);
+/**
+ * find_cli_callback_descr - find a callback in a list of modules
+ * @module_name: Name of the module to find
+ * @modules_list: Lits of modules among which to find @module_name
+ * @module_found: Pointer to the matched module, NULL if not found
+ *
+ * Given a module name and a list of possible modules, find the corresponding
+ * module structure that matches the module name and store it in @module_found.
+ **/
+void find_cli_callback_descr(const char* module_name,
+ struct cli_module_descr* modules_list,
+ struct cli_callback_descr** module_found)
+{
+ int modules_iter = 0;
+ int module_len = strlen(module_name);
+
+ if (modules_list == NULL)
+ goto not_found;
+
+ /* Find the callback to execute */
+ while (modules_iter < modules_list->nb_modules
+ && strncmp(module_name,
+ modules_list->modules[modules_iter].name,
+ module_len) != 0)
+ modules_iter++;
+
+ if (modules_iter != modules_list->nb_modules) {
+ *module_found = &(modules_list->modules[modules_iter]);
+ dprintf("CLI DEBUG: module %s found\n", (*module_found)->name);
return;
}
- if (!strncmp(command, CLI_CLEAR, sizeof(CLI_CLEAR) - 1)) {
- clear_screen();
- return;
+not_found:
+ *module_found = NULL;
+ return;
+}
+
+/**
+ * autocomplete_command - print matching commands
+ * @command: Beginning of the command
+ *
+ * Given a string @command, print all availables commands starting with
+ * @command. Commands are found within the list of commands for the current
+ * mode and the hdt mode (if the current mode is not hdt).
+ **/
+static void autocomplete_command(char *command)
+{
+ int j;
+ struct cli_callback_descr* associated_module = NULL;
+
+ /* First take care of the two special commands: 'show' and 'set' */
+ if (strncmp(CLI_SHOW, command, strlen(command)) == 0) {
+ more_printf("%s\n", CLI_SHOW);
+ autocomplete_add_token_to_list(CLI_SHOW);
+ }
+ if (strncmp(CLI_SET, command, strlen(command)) == 0) {
+ more_printf("%s\n", CLI_SET);
+ autocomplete_add_token_to_list(CLI_SET);
}
- if (!strncmp(command, CLI_CPU, sizeof(CLI_CPU) - 1)) {
- set_mode(cli, CPU_MODE, hardware);
- return;
+ /*
+ * Then, go through the modes for the special case
+ * '<mode>' -> 'set mode <mode>'
+ */
+ for (j = 0; j < MAX_MODES; j++) {
+ if (strncmp(list_modes[j]->name, command, strlen(command)) == 0) {
+ more_printf("%s\n", list_modes[j]->name);
+ autocomplete_add_token_to_list(list_modes[j]->name);
+ }
}
- if (!strncmp(command, CLI_DMI, sizeof(CLI_DMI) - 1)) {
- set_mode(cli, DMI_MODE, hardware);
- return;
+ /*
+ * Let's go now through the list of default_modules for the current mode
+ * (single token commands for the current_mode)
+ */
+ for (j = 0; j < current_mode->default_modules->nb_modules; j++) {
+ if (strncmp(current_mode->default_modules->modules[j].name,
+ command,
+ strlen(command)) == 0) {
+ more_printf("%s\n",
+ current_mode->default_modules->modules[j].name);
+ autocomplete_add_token_to_list(current_mode->default_modules->modules[j].name);
+ }
}
- if (!strncmp(command, CLI_PXE, sizeof(CLI_PXE) - 1)) {
- set_mode(cli, PXE_MODE, hardware);
+ /*
+ * Finally, if the current_mode is not hdt, list the available
+ * default_modules of hdt (these are always available from any mode).
+ */
+ if (current_mode->mode == HDT_MODE)
return;
+
+ for (j = 0; j < hdt_mode.default_modules->nb_modules; j++) {
+ /*
+ * Any default command that is present in hdt mode but
+ * not in the current mode is available. A default
+ * command can be redefined in the current mode though.
+ * This next call tests this use case: if it is
+ * overwritten, do not print it again.
+ */
+ find_cli_callback_descr(hdt_mode.default_modules->modules[j].name,
+ current_mode->default_modules,
+ &associated_module);
+ if (associated_module == NULL &&
+ strncmp(command,
+ hdt_mode.default_modules->modules[j].name,
+ strlen(command)) == 0) {
+ more_printf("%s\n",
+ hdt_mode.default_modules->modules[j].name);
+ autocomplete_add_token_to_list(hdt_mode.default_modules->modules[j].name);
+ }
}
+}
- if (!strncmp(command, CLI_KERNEL, sizeof(CLI_KERNEL) - 1)) {
- set_mode(cli, KERNEL_MODE, hardware);
- return;
+/**
+ * autocomplete_module - print matching modules
+ * @command: Command on the command line (not NULL)
+ * @module: Beginning of the module
+ *
+ * Given a command @command and a string @module, print all availables modules
+ * starting with @module for command @command. Commands are found within the
+ * list of commands for the current mode and the hdt mode (if the current mode
+ * is not hdt).
+ **/
+static void autocomplete_module(char *command, char* module)
+{
+ int j;
+ char autocomplete_full_line[MAX_LINE_SIZE];
+
+ if (strncmp(CLI_SHOW, command, strlen(command)) == 0) {
+ for (j = 0; j < current_mode->show_modules->nb_modules; j++) {
+ if (strncmp(current_mode->show_modules->modules[j].name,
+ module,
+ strlen(module)) == 0) {
+ more_printf("%s\n",
+ current_mode->show_modules->modules[j].name);
+ sprintf(autocomplete_full_line, "%s %s",
+ CLI_SHOW, current_mode->show_modules->modules[j].name);
+ autocomplete_add_token_to_list(autocomplete_full_line);
+ }
+ }
+ } else if (strncmp(CLI_SET, command, strlen(command)) == 0) {
+ for (j = 0; j < current_mode->set_modules->nb_modules; j++) {
+ if (strncmp(current_mode->set_modules->modules[j].name,
+ module,
+ strlen(module)) == 0) {
+ more_printf("%s\n",
+ current_mode->set_modules->modules[j].name);
+ sprintf(autocomplete_full_line, "%s %s",
+ CLI_SET, current_mode->set_modules->modules[j].name);
+ autocomplete_add_token_to_list(autocomplete_full_line);
+ }
+ }
}
+}
- if (!strncmp(command, CLI_SYSLINUX, sizeof(CLI_SYSLINUX) - 1)) {
- set_mode(cli, SYSLINUX_MODE, hardware);
- return;
+/**
+ * autocomplete - find possible matches for a command line
+ * @line: command line to parse
+ **/
+static void autocomplete(char *line)
+{
+ int i;
+ int argc = 0;
+ char *command = NULL, *module = NULL;
+ char **argv = NULL;
+
+ parse_command_line(line, &command, &module, &argc, argv);
+
+ /* If the user specified arguments, there is nothing we can complete */
+ if (argc != 0)
+ goto out;
+
+ /* No argument, (the start of) a module has been specified */
+ if (module != NULL) {
+ autocomplete_module(command, module);
+ goto out;
}
- if (!strncmp(command, CLI_VESA, sizeof(CLI_VESA) - 1)) {
- set_mode(cli, VESA_MODE, hardware);
- return;
+ /* No argument, no module, (the start of) a command has been specified */
+ if (command != NULL) {
+ autocomplete_command(command);
+ goto out;
}
- /*
- * All commands before that line are common for all cli modes.
- * The following will be specific for every mode.
- */
+ /* Nothing specified, list available commands */
+ //autocomplete_commands();
+
+out:
+ /* Let's not forget to clean ourselves */
+ free(command);
+ free(module);
+ for (i = 0; i < argc; i++)
+ free(argv[i]);
+ free(argv);
+ return;
+}
- int modes_iter = 0, modules_iter = 0;
- /* Find the mode selected */
- while (modes_iter < MAX_MODES &&
- list_modes[modes_iter]->mode != cli->mode)
- modes_iter++;
+/**
+ * exec_command - main logic to map the command line to callbacks
+ **/
+static void exec_command(char *line,
+ struct s_hardware *hardware)
+{
+ int argc, i = 0;
+ char *command = NULL, *module = NULL;
+ char **argv = NULL;
+ struct cli_callback_descr* current_module = NULL;
- if (modes_iter != MAX_MODES) {
- struct commands_mode *current_mode = list_modes[modes_iter];
+ /* This will allocate memory that will need to be freed */
+ parse_command_line(line, &command, &module, &argc, argv);
+ /* Expand shortcuts, if needed */
+ expand_aliases(line, &command, &module, &argc, argv);
+
+ if (module == NULL) {
+ dprintf("CLI DEBUG: single command detected\n", CLI_SHOW);
/*
- * Find the type of command.
- *
- * The syntax of the cli is the following:
- * <type of command> <module on which to operate> <args>
- * e.g.
- * dmi> show system
- * dmi> show bank 1
- * dmi> show memory 0 1
- * pci> show device 12
+ * A single word was specified: look at the list of default
+ * commands in the current mode to see if there is a match.
+ * If not, it may be a generic function (exit, help, ...). These
+ * are stored in the list of default commands of the hdt mode.
*/
- if (!strncmp(command, CLI_SHOW, sizeof(CLI_SHOW) - 1)) {
- int module_len = 0, args_len = 0;
- int argc = 0, args_iter = 0, argc_iter = 0;
- char *module = NULL, *args = NULL, *args_cpy = NULL;
- char **argv = NULL;
-
- /* Get the module name and args */
- while (strncmp
- (command + sizeof(CLI_SHOW) + module_len,
- CLI_SPACE, 1))
- module_len++;
-
- /* cli_line is filled with \0 when initialized */
- while (strncmp
- (command + sizeof(CLI_SHOW) + module_len + 1 +
- args_len, "\0", 1))
- args_len++;
-
- module = malloc(module_len + 1);
- strncpy(module, command + sizeof(CLI_SHOW), module_len);
- module[module_len] = '\0';
-
- /* Skip arguments handling if none is supplied */
- if (!args_len)
- goto find_callback;
-
- args = malloc(args_len + 1);
- strncpy(args,
- command + sizeof(CLI_SHOW) + module_len + 1,
- args_len);
- args[args_len] = '\0';
-
- /* Compute the number of arguments */
- args_cpy = args;
- read_argument:
- args_iter = 0;
- while (args_iter < args_len
- && strncmp(args_cpy + args_iter, CLI_SPACE, 1))
- args_iter++;
- argc++;
- args_iter++;
- args_cpy += args_iter;
- args_len -= args_iter;
- if (args_len > 0)
- goto read_argument;
-
- /* Transform the arguments string into an array */
- char *result = NULL;
- argv = malloc(argc * sizeof(char *));
- result = strtok(args, CLI_SPACE);
- while (result != NULL) {
- argv[argc_iter] = result;
- argc_iter++;
- result = strtok(NULL, CLI_SPACE);
- }
+ find_cli_callback_descr(command, current_mode->default_modules,
+ &current_module);
+ if (current_module != NULL)
+ return current_module->exec(argc, argv, hardware);
+ else if (!strncmp(command, CLI_SHOW, sizeof(CLI_SHOW) - 1) &&
+ current_mode->show_modules != NULL &&
+ current_mode->show_modules->default_callback != NULL)
+ return current_mode->show_modules
+ ->default_callback(argc,
+ argv,
+ hardware);
+ else if (!strncmp(command, CLI_SET, sizeof(CLI_SET) - 1) &&
+ current_mode->set_modules != NULL &&
+ current_mode->set_modules->default_callback != NULL)
+ return current_mode->set_modules
+ ->default_callback(argc,
+ argv,
+ hardware);
+ else {
+ find_cli_callback_descr(command, hdt_mode.default_modules,
+ &current_module);
+ if (current_module != NULL)
+ return current_module->exec(argc, argv, hardware);
+ }
- find_callback:
- /* Find the callback to execute */
- while (modules_iter <
- current_mode->show_modules->nb_modules
- && strncmp(module,
- current_mode->show_modules->
- modules[modules_iter].name,
- module_len + 1) != 0)
- modules_iter++;
-
- if (modules_iter !=
- current_mode->show_modules->nb_modules) {
- struct commands_module current_module =
- current_mode->show_modules->
- modules[modules_iter];
- /* Execute the callback */
- current_module.exec(argc, argv, hardware);
- } else
-// printf("Module %s unknown.\n", module);
- /* XXX Add a default help option for empty commands */
-
- free(module);
- if (args_len) {
- free(args);
- free(argv);
- }
+ more_printf("unknown command: '%s'\n", command);
+ return;
+ }
+
+ /*
+ * A module has been specified! We now need to find the type of command.
+ *
+ * The syntax of the cli is the following:
+ * <type of command> <module on which to operate> <args>
+ * e.g.
+ * dmi> show system
+ * dmi> show bank 1
+ * dmi> show memory 0 1
+ * pci> show device 12
+ * hdt> set mode dmi
+ */
+ if (!strncmp(command, CLI_SHOW, sizeof(CLI_SHOW) - 1)) {
+ dprintf("CLI DEBUG: %s command detected\n", CLI_SHOW);
+ find_cli_callback_descr(module, current_mode->show_modules,
+ &current_module);
+ /* Execute the callback */
+ if (current_module != NULL)
+ return current_module->exec(argc, argv, hardware);
+ else {
+ find_cli_callback_descr(module, hdt_mode.show_modules,
+ &current_module);
+ if (current_module != NULL)
+ return current_module->exec(argc, argv, hardware);
}
- /* Handle here other keywords such as 'set', ... */
- } else
-// printf("Mode '%s' unknown.\n", command);
- /* Legacy cli */
- switch (cli->mode) {
- case PCI_MODE:
- handle_pci_commands(command, hardware);
- break;
- case HDT_MODE:
- handle_hdt_commands(command, hardware);
- break;
- case CPU_MODE:
- handle_cpu_commands(command, hardware);
- break;
- case PXE_MODE:
- handle_pxe_commands(command, hardware);
- break;
- case VESA_MODE:
- handle_vesa_commands(command, hardware);
- break;
- case SYSLINUX_MODE:
- handle_syslinux_commands(command, hardware);
- break;
- case KERNEL_MODE:
- handle_kernel_commands(command, hardware);
- break;
- case EXIT_MODE:
- break; /* should not happen */
+ more_printf("unknown module: '%s'\n", module);
+ return;
+
+ } else if (!strncmp(command, CLI_SET, sizeof(CLI_SET) - 1)) {
+ dprintf("CLI DEBUG: %s command detected\n", CLI_SET);
+ find_cli_callback_descr(module, current_mode->set_modules,
+ &current_module);
+ /* Execute the callback */
+ if (current_module != NULL)
+ return current_module->exec(argc, argv, hardware);
+ else {
+ find_cli_callback_descr(module, hdt_mode.set_modules,
+ &current_module);
+ if (current_module != NULL)
+ return current_module->exec(argc, argv, hardware);
+ }
+
+ more_printf("unknown module: '%s'\n", module);
+ return;
+
}
+
+ more_printf("I don't understand: '%s'. Try 'help'.\n", line);
+
+ /* Let's not forget to clean ourselves */
+ free(command);
+ free(module);
+ for (i = 0; i < argc; i++)
+ free(argv[i]);
+ free(argv);
}
-static void reset_prompt(struct s_cli *cli)
+static void reset_prompt()
{
/* No need to display the prompt if we exit */
- if (cli->mode != EXIT_MODE) {
- printf("%s", cli->prompt);
+ if (hdt_cli.mode != EXIT_MODE) {
+ more_printf("%s", hdt_cli.prompt);
/* Reset the line */
- memset(cli->input, '\0', MAX_LINE_SIZE);
- cli->cursor_pos = 0;
+ memset(hdt_cli.input, '\0', MAX_LINE_SIZE);
+ hdt_cli.cursor_pos = 0;
}
}
@@ -357,55 +723,62 @@ void start_cli_mode(struct s_hardware *hardware)
bool display_history=true; /* Temp Variable*/
char temp_command[MAX_LINE_SIZE];
- struct s_cli cli;
- cli.cursor_pos=0;
- memset(cli.input, '\0', MAX_LINE_SIZE);
- memset(cli.history, '\0', sizeof(cli.history));
- cli.history_pos=1;
- cli.max_history_pos=1;
+ hdt_cli.cursor_pos=0;
+ memset(hdt_cli.input, '\0', MAX_LINE_SIZE);
+ memset(hdt_cli.history, '\0', sizeof(hdt_cli.history));
+ hdt_cli.history_pos=1;
+ hdt_cli.max_history_pos=1;
- set_mode(&cli, HDT_MODE, hardware);
+ /* Find the mode selected */
+ set_mode(HDT_MODE, hardware);
+ find_cli_mode_descr(hdt_cli.mode, &current_mode);
+ if (current_mode == NULL) {
+ /* Shouldn't get here... */
+ more_printf("!!! BUG: Mode '%d' unknown.\n", hdt_cli.mode);
+ return;
+ }
- printf("Entering CLI mode\n");
+ more_printf("Entering CLI mode\n");
/* Display the cursor */
- fputs("\033[?25h", stdout);
+ display_cursor(true);
- reset_prompt(&cli);
+ reset_prompt();
- while (cli.mode != EXIT_MODE) {
+ while (hdt_cli.mode != EXIT_MODE) {
//fgets(cli_line, sizeof cli_line, stdin);
current_key = get_key(stdin, 0);
+ /* Reset autocomplete buffer unless TAB is pressed */
+ if (current_key != KEY_TAB)
+ autocomplete_destroy_list();
+
switch (current_key) {
/* clear until then end of line */
case KEY_CTRL('k'):
/* Clear the end of the line */
- fputs("\033[0K", stdout);
- memset(&cli.input[cli.cursor_pos], 0,
- strlen(cli.input) - cli.cursor_pos);
+ clear_end_of_line();
+ memset(&hdt_cli.input[hdt_cli.cursor_pos], 0,
+ strlen(hdt_cli.input) - hdt_cli.cursor_pos);
break;
case KEY_CTRL('c'):
more_printf("\n");
- reset_prompt(&cli);
- break;
-
- case KEY_TAB:
+ reset_prompt();
break;
case KEY_LEFT:
- if (cli.cursor_pos > 0) {
- fputs("\033[1D", stdout);
- cli.cursor_pos--;
+ if (hdt_cli.cursor_pos > 0) {
+ move_cursor_left(1);
+ hdt_cli.cursor_pos--;
}
break;
case KEY_RIGHT:
- if (cli.cursor_pos < (int)strlen(cli.input)) {
- fputs("\033[1C", stdout);
- cli.cursor_pos++;
+ if (hdt_cli.cursor_pos < (int)strlen(hdt_cli.input)) {
+ move_cursor_right(1);
+ hdt_cli.cursor_pos++;
}
break;
@@ -413,13 +786,10 @@ void start_cli_mode(struct s_hardware *hardware)
case KEY_END:
/* Calling with a 0 value will make the cursor move */
/* So, let's move the cursor only if needed */
- if ((strlen(cli.input) - cli.cursor_pos) > 0) {
- memset(temp_command, 0, sizeof(temp_command));
- sprintf(temp_command, "\033[%dC",
- strlen(cli.input) - cli.cursor_pos);
+ if ((strlen(hdt_cli.input) - hdt_cli.cursor_pos) > 0) {
/* Return to the begining of line */
- fputs(temp_command, stdout);
- cli.cursor_pos = strlen(cli.input);
+ move_cursor_right(strlen(hdt_cli.input) - hdt_cli.cursor_pos);
+ hdt_cli.cursor_pos = strlen(hdt_cli.input);
}
break;
@@ -427,290 +797,204 @@ void start_cli_mode(struct s_hardware *hardware)
case KEY_HOME:
/* Calling with a 0 value will make the cursor move */
/* So, let's move the cursor only if needed */
- if (cli.cursor_pos > 0) {
- memset(temp_command, 0, sizeof(temp_command));
- sprintf(temp_command, "\033[%dD",
- cli.cursor_pos);
+ if (hdt_cli.cursor_pos > 0) {
/* Return to the begining of line */
- fputs(temp_command, stdout);
- cli.cursor_pos = 0;
+ move_cursor_left(hdt_cli.cursor_pos);
+ hdt_cli.cursor_pos = 0;
}
break;
case KEY_UP:
/* We have to compute the next position*/
- future_history_pos=cli.history_pos;
+ future_history_pos=hdt_cli.history_pos;
if (future_history_pos==1) {
future_history_pos=MAX_HISTORY_SIZE-1;
} else {
future_history_pos--;
}
/* Does the next position is valid */
- if (strlen(cli.history[future_history_pos])==0) break;
+ if (strlen(hdt_cli.history[future_history_pos])==0) break;
/* Let's make that future position the one we use*/
- cli.history_pos=future_history_pos;
+ hdt_cli.history_pos=future_history_pos;
/* Clear the line */
- fputs("\033[2K", stdout);
+ clear_line();
/* Move to the begining of line*/
- fputs("\033[0G", stdout);
+ move_cursor_to_column(0);
- reset_prompt(&cli);
- printf("%s",cli.history[cli.history_pos]);
- strncpy(cli.input,cli.history[cli.history_pos],sizeof(cli.input));
- cli.cursor_pos=strlen(cli.input);
+ reset_prompt();
+ printf("%s",hdt_cli.history[hdt_cli.history_pos]);
+ strncpy(hdt_cli.input,hdt_cli.history[hdt_cli.history_pos],sizeof(hdt_cli.input));
+ hdt_cli.cursor_pos=strlen(hdt_cli.input);
break;
case KEY_DOWN:
display_history=true;
/* We have to compute the next position*/
- future_history_pos=cli.history_pos;
+ future_history_pos=hdt_cli.history_pos;
if (future_history_pos==MAX_HISTORY_SIZE-1) {
future_history_pos=1;
} else {
future_history_pos++;
}
/* Does the next position is valid */
- if (strlen(cli.history[future_history_pos])==0) display_history = false;
+ if (strlen(hdt_cli.history[future_history_pos])==0) display_history = false;
/* An exception is made to reach the last empty line */
- if (future_history_pos==cli.max_history_pos) display_history=true;
+ if (future_history_pos==hdt_cli.max_history_pos) display_history=true;
if (display_history==false) break;
/* Let's make that future position the one we use*/
- cli.history_pos=future_history_pos;
+ hdt_cli.history_pos=future_history_pos;
/* Clear the line */
- fputs("\033[2K", stdout);
+ clear_line();
/* Move to the begining of line*/
- fputs("\033[0G", stdout);
+ move_cursor_to_column(0);
+
+ reset_prompt();
+ printf("%s",hdt_cli.history[hdt_cli.history_pos]);
+ strncpy(hdt_cli.input,hdt_cli.history[hdt_cli.history_pos],sizeof(hdt_cli.input));
+ hdt_cli.cursor_pos=strlen(hdt_cli.input);
+ break;
- reset_prompt(&cli);
- printf("%s",cli.history[cli.history_pos]);
- strncpy(cli.input,cli.history[cli.history_pos],sizeof(cli.input));
- cli.cursor_pos=strlen(cli.input);
+ case KEY_TAB:
+ if (autocomplete_backlog) {
+ clear_line();
+ /* Move to the begining of line*/
+ move_cursor_to_column(0);
+ reset_prompt();
+ printf("%s",autocomplete_last_seen->autocomplete_token);
+ strncpy(hdt_cli.input,autocomplete_last_seen->autocomplete_token,sizeof(hdt_cli.input));
+ hdt_cli.cursor_pos=strlen(hdt_cli.input);
+
+ /* Cycle through the list */
+ autocomplete_last_seen = autocomplete_last_seen->next;
+ if (autocomplete_last_seen == NULL)
+ autocomplete_last_seen = autocomplete_head;
+ } else {
+ more_printf("\n");
+ autocomplete(skip_spaces(hdt_cli.input));
+ autocomplete_last_seen = autocomplete_head;
+
+ more_printf("%s%s", hdt_cli.prompt, hdt_cli.input);
+ }
break;
case KEY_ENTER:
more_printf("\n");
-
- /* We have to skip empty lines */
- if (strlen(skipspace(cli.input))<1) {
- reset_prompt(&cli);
+ if (strlen(remove_spaces(hdt_cli.input)) < 1) {
+ reset_prompt();
break;
}
- if (cli.history_pos == MAX_HISTORY_SIZE-1) cli.history_pos=1;
- strncpy(cli.history[cli.history_pos],skipspace(cli.input),sizeof(cli.history[cli.history_pos]));
- cli.history_pos++;
- if (cli.history_pos>cli.max_history_pos) cli.max_history_pos=cli.history_pos;
- exec_command(skipspace(cli.input), &cli, hardware);
- reset_prompt(&cli);
+ if (hdt_cli.history_pos == MAX_HISTORY_SIZE-1) hdt_cli.history_pos=1;
+ strncpy(hdt_cli.history[hdt_cli.history_pos],remove_spaces(hdt_cli.input),sizeof(hdt_cli.history[hdt_cli.history_pos]));
+ hdt_cli.history_pos++;
+ if (hdt_cli.history_pos>hdt_cli.max_history_pos) hdt_cli.max_history_pos=hdt_cli.history_pos;
+ exec_command(remove_spaces(hdt_cli.input), hardware);
+ reset_prompt();
break;
+ case KEY_CTRL('d'):
+ case KEY_DELETE:
+ /* No need to delete when input is empty */
+ if (strlen(hdt_cli.input)==0) break;
+ /* Don't delete when cursor is at the end of the line */
+ if (hdt_cli.cursor_pos>=strlen(hdt_cli.input)) break;
+
+ for (int c = hdt_cli.cursor_pos;
+ c < (int)strlen(hdt_cli.input) - 1; c++)
+ hdt_cli.input[c] = hdt_cli.input[c + 1];
+ hdt_cli.input[strlen(hdt_cli.input) - 1] = '\0';
+
+ /* Clear the end of the line */
+ clear_end_of_line();
+
+ /* Print the resulting buffer */
+ printf("%s", hdt_cli.input + hdt_cli.cursor_pos);
+
+ /* Replace the cursor at the proper place */
+ if (strlen(hdt_cli.input + hdt_cli.cursor_pos)>0)
+ move_cursor_left(strlen(hdt_cli.input + hdt_cli.cursor_pos));
+ break;
+
+ case KEY_DEL:
case KEY_BACKSPACE:
/* Don't delete prompt */
- if (cli.cursor_pos == 0)
+ if (hdt_cli.cursor_pos == 0)
break;
- for (int c = cli.cursor_pos - 1;
- c < (int)strlen(cli.input) - 1; c++)
- cli.input[c] = cli.input[c + 1];
- cli.input[strlen(cli.input) - 1] = '\0';
+ for (int c = hdt_cli.cursor_pos - 1;
+ c < (int)strlen(hdt_cli.input) - 1; c++)
+ hdt_cli.input[c] = hdt_cli.input[c + 1];
+ hdt_cli.input[strlen(hdt_cli.input) - 1] = '\0';
/* Get one char back */
- fputs("\033[1D", stdout);
+ move_cursor_left(1);
+
/* Clear the end of the line */
- fputs("\033[0K", stdout);
+ clear_end_of_line();
/* Print the resulting buffer */
- printf("%s", cli.input + cli.cursor_pos - 1);
+ printf("%s", hdt_cli.input + hdt_cli.cursor_pos - 1);
/* Realing to the place we were */
- memset(temp_command, 0, sizeof(temp_command));
- sprintf(temp_command, "\033[%dD",
- strlen(cli.input + cli.cursor_pos - 1));
- fputs(temp_command, stdout);
- fputs("\033[1C", stdout);
+ move_cursor_left(strlen(hdt_cli.input + hdt_cli.cursor_pos - 1));
+ move_cursor_right(1);
+
/* Don't decrement the position unless
* if we are at then end of the line*/
- if (cli.cursor_pos > (int)strlen(cli.input))
- cli.cursor_pos--;
+ if (hdt_cli.cursor_pos > (int)strlen(hdt_cli.input))
+ hdt_cli.cursor_pos--;
break;
case KEY_F1:
more_printf("\n");
- exec_command(CLI_HELP, &cli, hardware);
- reset_prompt(&cli);
+ exec_command(CLI_HELP, hardware);
+ reset_prompt();
break;
default:
if ( ( current_key < 0x20 ) || ( current_key > 0x7e ) ) break;
/* Prevent overflow */
- if (cli.cursor_pos > MAX_LINE_SIZE - 2)
+ if (hdt_cli.cursor_pos > MAX_LINE_SIZE - 2)
break;
/* If we aren't at the end of the input line, let's insert */
- if (cli.cursor_pos < (int)strlen(cli.input)) {
+ if (hdt_cli.cursor_pos < (int)strlen(hdt_cli.input)) {
char key[2];
int trailing_chars =
- strlen(cli.input) - cli.cursor_pos;
+ strlen(hdt_cli.input) - hdt_cli.cursor_pos;
memset(temp_command, 0, sizeof(temp_command));
- strncpy(temp_command, cli.input,
- cli.cursor_pos);
+ strncpy(temp_command, hdt_cli.input,
+ hdt_cli.cursor_pos);
sprintf(key, "%c", current_key);
strncat(temp_command, key, 1);
strncat(temp_command,
- cli.input + cli.cursor_pos,
+ hdt_cli.input + hdt_cli.cursor_pos,
trailing_chars);
- memset(cli.input, 0, sizeof(cli.input));
- snprintf(cli.input, sizeof(cli.input), "%s",
+ memset(hdt_cli.input, 0, sizeof(hdt_cli.input));
+ snprintf(hdt_cli.input, sizeof(hdt_cli.input), "%s",
temp_command);
/* Clear the end of the line */
- fputs("\033[0K", stdout);
+ clear_end_of_line();
/* Print the resulting buffer */
- printf("%s", cli.input + cli.cursor_pos);
- sprintf(temp_command, "\033[%dD",
- trailing_chars);
+ printf("%s", hdt_cli.input + hdt_cli.cursor_pos);
+
/* Return where we must put the new char */
- fputs(temp_command, stdout);
+ move_cursor_left(trailing_chars);
} else {
putchar(current_key);
- cli.input[cli.cursor_pos] = current_key;
+ hdt_cli.input[hdt_cli.cursor_pos] = current_key;
}
- cli.cursor_pos++;
+ hdt_cli.cursor_pos++;
break;
}
}
}
-
-int do_exit(struct s_cli *cli)
-{
- switch (cli->mode) {
- case HDT_MODE:
- return EXIT_MODE;
- case KERNEL_MODE:
- case PXE_MODE:
- case SYSLINUX_MODE:
- case PCI_MODE:
- case DMI_MODE:
- case VESA_MODE:
- case CPU_MODE:
- return HDT_MODE;
- case EXIT_MODE:
- return EXIT_MODE; /* should not happen */
- }
- return HDT_MODE;
-}
-
-static void main_show_summary(struct s_hardware *hardware)
-{
- detect_pci(hardware); /* pxe is detected in the pci */
- detect_dmi(hardware);
- cpu_detect(hardware);
- clear_screen();
- main_show_cpu(hardware);
- if (hardware->is_dmi_valid) {
- more_printf("System\n");
- more_printf(" Manufacturer : %s\n",
- hardware->dmi.system.manufacturer);
- more_printf(" Product Name : %s\n",
- hardware->dmi.system.product_name);
- more_printf(" Serial : %s\n",
- hardware->dmi.system.serial);
- more_printf("Bios\n");
- more_printf(" Version : %s\n", hardware->dmi.bios.version);
- more_printf(" Release : %s\n",
- hardware->dmi.bios.release_date);
-
- int argc = 2;
- char *argv[2] = { "0", "0" };
- show_dmi_memory_modules(argc, argv, hardware);
- if (hardware->dmi.ipmi.filled==true) {
- more_printf("IPMI baseboard v%u.%u present\n",
- hardware->dmi.ipmi.major_specification_version,
- hardware->dmi.ipmi.minor_specification_version);
- }
- }
- main_show_pci(hardware);
-
- if (hardware->is_pxe_valid)
- main_show_pxe(hardware);
-
- main_show_kernel(hardware);
-}
-
-void show_main_help(struct s_hardware *hardware)
-{
- more_printf("Show supports the following commands : \n");
- more_printf(" %s\n", CLI_SUMMARY);
- more_printf(" %s\n", CLI_PCI);
- more_printf(" %s\n", CLI_DMI);
- more_printf(" %s\n", CLI_CPU);
- more_printf(" %s\n", CLI_KERNEL);
- more_printf(" %s\n", CLI_SYSLINUX);
- more_printf(" %s\n", CLI_VESA);
- more_printf(" %s\n", CLI_HDT);
- if (hardware->sv->filesystem == SYSLINUX_FS_PXELINUX)
- more_printf(" %s\n", CLI_PXE);
-}
-
-void main_show_hdt(struct s_hardware *hardware)
-{
- more_printf("HDT\n");
- more_printf(" Product : %s\n", PRODUCT_NAME);
- more_printf(" Version : %s\n", VERSION);
- more_printf(" Author : %s\n", AUTHOR);
- more_printf(" Contact : %s\n", CONTACT);
- char *contributors[NB_CONTRIBUTORS] = CONTRIBUTORS;
- for (int c=0; c<NB_CONTRIBUTORS; c++) {
- more_printf(" Contributor : %s\n", contributors[c]);
- }
-}
-
-
-void main_show(char *item, struct s_hardware *hardware)
-{
- if (!strncmp(item, CLI_SUMMARY, sizeof(CLI_SUMMARY))) {
- main_show_summary(hardware);
- return;
- }
- if (!strncmp(item, CLI_PCI, sizeof(CLI_PCI))) {
- main_show_pci(hardware);
- return;
- }
- if (!strncmp(item, CLI_DMI, sizeof(CLI_DMI))) {
- main_show_dmi(hardware);
- return;
- }
- if (!strncmp(item, CLI_CPU, sizeof(CLI_CPU))) {
- main_show_cpu(hardware);
- return;
- }
- if (!strncmp(item, CLI_PXE, sizeof(CLI_PXE))) {
- main_show_pxe(hardware);
- return;
- }
- if (!strncmp(item, CLI_SYSLINUX, sizeof(CLI_SYSLINUX))) {
- main_show_syslinux(hardware);
- return;
- }
- if (!strncmp(item, CLI_KERNEL, sizeof(CLI_KERNEL))) {
- main_show_kernel(hardware);
- return;
- }
- if (!strncmp(item, CLI_VESA, sizeof(CLI_VESA))) {
- main_show_vesa(hardware);
- return;
- }
- if (!strncmp(item, CLI_HDT, sizeof(CLI_HDT))) {
- main_show_hdt(hardware);
- return;
- }
- show_main_help(hardware);
-}
diff --git a/com32/hdt/hdt-cli.h b/com32/hdt/hdt-cli.h
index 34ff66e1..0b15fe97 100644
--- a/com32/hdt/hdt-cli.h
+++ b/com32/hdt/hdt-cli.h
@@ -33,14 +33,27 @@
#include "hdt-common.h"
+#define DEBUG 0
+#if DEBUG
+# define dprintf printf
+#else
+# define dprintf(f, ...) ((void)0)
+#endif
+
+/* Declare a variable or data structure as unused. */
+#define __unused __attribute__ (( unused ))
+
#define MAX_LINE_SIZE 256
#define CLI_SPACE " "
#define CLI_LF "\n"
+#define CLI_MENU "menu"
#define CLI_CLEAR "clear"
#define CLI_EXIT "exit"
#define CLI_HELP "help"
#define CLI_SHOW "show"
+#define CLI_SET "set"
+#define CLI_MODE "mode"
#define CLI_HDT "hdt"
#define CLI_PCI "pci"
#define CLI_PXE "pxe"
@@ -56,52 +69,86 @@
#define CLI_MODES "modes"
typedef enum {
- EXIT_MODE,
- HDT_MODE,
- PCI_MODE,
- DMI_MODE,
- CPU_MODE,
- PXE_MODE,
- KERNEL_MODE,
- SYSLINUX_MODE,
- VESA_MODE,
+ INVALID_MODE,
+ EXIT_MODE,
+ HDT_MODE,
+ PCI_MODE,
+ DMI_MODE,
+ CPU_MODE,
+ PXE_MODE,
+ KERNEL_MODE,
+ SYSLINUX_MODE,
+ VESA_MODE,
} cli_mode_t;
#define PROMPT_SIZE 32
#define MAX_HISTORY_SIZE 32
struct s_cli {
- cli_mode_t mode;
- char prompt[PROMPT_SIZE];
- char input[MAX_LINE_SIZE];
- int cursor_pos;
- char history[MAX_HISTORY_SIZE][MAX_LINE_SIZE];
- int history_pos;
- int max_history_pos;
+ cli_mode_t mode;
+ char prompt[PROMPT_SIZE];
+ char input[MAX_LINE_SIZE];
+ uint8_t cursor_pos;
+ char history[MAX_HISTORY_SIZE][MAX_LINE_SIZE];
+ int history_pos;
+ int max_history_pos;
};
-
-/* A command-line command */
-struct commands_mode {
- const unsigned int mode;
- struct commands_module_descr* show_modules;
- /* Future: set? */
+struct s_cli hdt_cli;
+
+/* Describe a cli mode */
+struct cli_mode_descr {
+ const unsigned int mode;
+ const char* name;
+ /* Handle 1-token commands */
+ struct cli_module_descr* default_modules;
+ /* Handle show <module> <args> */
+ struct cli_module_descr* show_modules;
+ /* Handle set <module> <args> */
+ struct cli_module_descr* set_modules;
};
-struct commands_module {
- const char *name;
- void ( * exec ) ( int argc, char** argv, struct s_hardware *hardware );
+/* Describe a subset of commands in a module (default, show, set, ...) */
+struct cli_module_descr {
+ struct cli_callback_descr* modules;
+ const int nb_modules;
+ void ( * default_callback ) ( int argc, char** argv, struct s_hardware *hardware );
};
-/* Describe 'show', 'set', ... commands in a module */
-struct commands_module_descr {
- struct commands_module* modules;
- const int nb_modules;
+/* Describe a callback (belongs to a mode and a module) */
+struct cli_callback_descr {
+ const char *name;
+ void ( * exec ) ( int argc, char** argv, struct s_hardware *hardware );
};
-struct commands_mode dmi_mode;
+/* Manage aliases */
+#define MAX_ALIASES 2
+struct cli_alias {
+ const char *command; /* Original command */
+ const int nb_aliases; /* Size of aliases array */
+ const char **aliases; /* List of aliases */
+};
+/* List of implemented modes */
+#define MAX_MODES 8
+struct cli_mode_descr *list_modes[MAX_MODES];
+struct cli_mode_descr hdt_mode;
+struct cli_mode_descr dmi_mode;
+struct cli_mode_descr syslinux_mode;
+struct cli_mode_descr pxe_mode;
+struct cli_mode_descr kernel_mode;
+struct cli_mode_descr cpu_mode;
+struct cli_mode_descr pci_mode;
+struct cli_mode_descr vesa_mode;
+
+/* cli helpers */
+void find_cli_mode_descr(cli_mode_t mode, struct cli_mode_descr **mode_found);
+void find_cli_callback_descr(const char *module_name,
+ struct cli_module_descr *modules_list,
+ struct cli_callback_descr **module_found);
+cli_mode_t mode_s_to_mode_t(char *name);
+
+void set_mode(cli_mode_t mode, struct s_hardware *hardware);
void start_cli_mode(struct s_hardware *hardware);
void main_show(char *item, struct s_hardware *hardware);
-int do_exit(struct s_cli *cli);
// DMI STUFF
#define CLI_DMI_BASE_BOARD "base_board"
@@ -112,36 +159,29 @@ int do_exit(struct s_cli *cli);
#define CLI_DMI_MEMORY_BANK "bank"
#define CLI_DMI_PROCESSOR "cpu"
#define CLI_DMI_SYSTEM "system"
-#define CLI_DMI_LIST CLI_SHOW_LIST
#define CLI_DMI_IPMI "ipmi"
+#define CLI_DMI_LIST CLI_SHOW_LIST
#define CLI_DMI_MAX_MODULES 10
-void main_show_dmi(struct s_hardware *hardware);
-void handle_dmi_commands(char *cli_line, struct s_hardware *hardware);
+void main_show_dmi(int argc, char **argv, struct s_hardware *hardware);
void show_dmi_memory_modules(int argc, char** argv, struct s_hardware *hardware);
// PCI STUFF
#define CLI_PCI_DEVICE "device"
-void main_show_pci(struct s_hardware *hardware);
-void handle_pci_commands(char *cli_line, struct s_hardware *hardware);
+void main_show_pci(int argc, char **argv, struct s_hardware *hardware);
void cli_detect_pci(struct s_hardware *hardware);
// CPU STUFF
-void main_show_cpu(struct s_hardware *hardware);
-void handle_cpu_commands(char *cli_line, struct s_hardware *hardware);
+void main_show_cpu(int argc, char **argv, struct s_hardware *hardware);
// PXE STUFF
-void main_show_pxe(struct s_hardware *hardware);
-void handle_pxe_commands(char *cli_line, struct s_hardware *hardware);
+void main_show_pxe(int argc, char **argv, struct s_hardware *hardware);
// KERNEL STUFF
-void main_show_kernel(struct s_hardware *hardware);
-void handle_kernel_commands(char *cli_line, struct s_hardware *hardware);
+void main_show_kernel(int argc, char **argv, struct s_hardware *hardware);
// SYSLINUX STUFF
-void main_show_syslinux(struct s_hardware *hardware);
-void handle_syslinux_commands(char *cli_line, struct s_hardware *hardware);
+void main_show_syslinux(int argc, char **argv, struct s_hardware *hardware);
// VESA STUFF
-void main_show_vesa(struct s_hardware *hardware);
-void handle_vesa_commands(char *cli_line, struct s_hardware *hardware);
+void main_show_vesa(int argc, char **argv, struct s_hardware *hardware);
#endif
diff --git a/com32/hdt/hdt-common.c b/com32/hdt/hdt-common.c
index 6c2e1e4c..d02533ce 100644
--- a/com32/hdt/hdt-common.c
+++ b/com32/hdt/hdt-common.c
@@ -29,10 +29,11 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <getkey.h>
#include "syslinux/config.h"
#include "../lib/sys/vesa/vesa.h"
-
#include "hdt-common.h"
+#include "lib-ansi.h"
void detect_parameters(const int argc, const char *argv[],
struct s_hardware *hardware)
@@ -200,7 +201,7 @@ void detect_disks(struct s_hardware *hardware)
continue;
struct diskinfo *d = &hardware->disk_info[drive];
hardware->disks_count++;
- printf
+ more_printf
(" DISK 0x%X: %s : %s %s: sectors=%d, s/t=%d head=%d : EDD=%s\n",
drive, d->aid.model, d->host_bus_type, d->interface_type,
d->sectors, d->sectors_per_track, d->heads,
@@ -377,19 +378,19 @@ void detect_pci(struct s_hardware *hardware)
hardware->nb_pci_devices++;
}
- printf("PCI: %d devices detected\n", hardware->nb_pci_devices);
- printf("PCI: Resolving names\n");
+ more_printf("PCI: %d devices detected\n", hardware->nb_pci_devices);
+ more_printf("PCI: Resolving names\n");
/* Assigning product & vendor name for each device */
hardware->pci_ids_return_code =
get_name_from_pci_ids(hardware->pci_domain, hardware->pciids_path);
- printf("PCI: Resolving class names\n");
+ more_printf("PCI: Resolving class names\n");
/* Assigning class name for each device */
hardware->pci_ids_return_code =
get_class_name_from_pci_ids(hardware->pci_domain,
hardware->pciids_path);
- printf("PCI: Resolving module names\n");
+ more_printf("PCI: Resolving module names\n");
/* Detecting which kernel module should match each device */
hardware->modules_pcimap_return_code =
get_module_name_from_pcimap(hardware->pci_domain,
@@ -427,15 +428,38 @@ const char *find_argument(const char **argv, const char *argument)
void clear_screen(void)
{
- fputs("\033e\033%@\033)0\033(B\1#0\033[?25l\033[2J", stdout);
+ move_cursor_to_next_line();
+ disable_utf8();
+ set_g1_special_char();
+ set_us_g0_charset();
+ display_cursor(false);
+ clear_entire_screen();
display_line_nb = 0;
}
-/* searching the next char that is not a space */
-char *skipspace(char *p)
+/* remove begining spaces */
+char *skip_spaces(char *p)
+{
+ while (*p && *p <= ' ') {
+ p++;
+ }
+
+ return p;
+}
+
+/* remove trailing & begining spaces */
+char *remove_spaces(char *p)
{
- while (*p && *p <= ' ')
+ char *save=p;
+ p+=strlen(p)-1;
+ while (*p && *p <= ' ') {
+ *p='\0';
+ p--;
+ }
+ p=save;
+ while (*p && *p <= ' ') {
p++;
+ }
return p;
}
diff --git a/com32/hdt/hdt-common.h b/com32/hdt/hdt-common.h
index dc783281..43347b4a 100644
--- a/com32/hdt/hdt-common.h
+++ b/com32/hdt/hdt-common.h
@@ -122,7 +122,8 @@ struct s_hardware {
};
const char *find_argument(const char **argv, const char *argument);
-char *skipspace(char *p);
+char *remove_spaces(char *p);
+char *skip_spaces(char *p);
int detect_dmi(struct s_hardware *hardware);
void detect_disks(struct s_hardware *hardware);
void detect_pci(struct s_hardware *hardware);
diff --git a/com32/hdt/lib-ansi.c b/com32/hdt/lib-ansi.c
new file mode 100644
index 00000000..12e5ecc7
--- /dev/null
+++ b/com32/hdt/lib-ansi.c
@@ -0,0 +1,97 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2009 Erwan Velu - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * -----------------------------------------------------------------------
+ * Ansi Sequences can be found here :
+ * http://ascii-table.com/ansi-escape-sequences-vt-100.php
+ * http://en.wikipedia.org/wiki/ANSI_escape_code
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+
+void display_cursor(bool status)
+{
+ if (status == true) {
+ fputs("\033[?25h", stdout);
+ } else {
+ fputs("\033[?25l", stdout);
+ }
+}
+
+void clear_end_of_line() {
+ fputs("\033[0K", stdout);
+}
+
+void move_cursor_left(int count) {
+ char buffer[10];
+ memset(buffer,0,sizeof(buffer));
+ sprintf(buffer,"\033[%dD",count);
+ fputs(buffer, stdout);
+}
+
+void move_cursor_right(int count) {
+ char buffer[10];
+ memset(buffer,0,sizeof(buffer));
+ sprintf(buffer,"\033[%dC",count);
+ fputs(buffer, stdout);
+}
+
+void clear_line() {
+ fputs("\033[2K", stdout);
+}
+
+void clear_beginning_of_line() {
+ fputs("\033[1K", stdout);
+}
+
+void move_cursor_to_column(int count) {
+ char buffer[10];
+ memset(buffer,0,sizeof(buffer));
+ sprintf(buffer,"\033[%dG",count);
+ fputs(buffer, stdout);
+}
+
+void move_cursor_to_next_line() {
+ fputs("\033e", stdout);
+}
+
+void disable_utf8() {
+ fputs("\033%@", stdout);
+}
+
+void set_g1_special_char(){
+ fputs("\033)0", stdout);
+}
+
+void set_us_g0_charset() {
+ fputs("\033(B\1#0", stdout);
+}
+
+void clear_entire_screen() {
+ fputs("\033[2J", stdout);
+}
diff --git a/com32/hdt/lib-ansi.h b/com32/hdt/lib-ansi.h
new file mode 100644
index 00000000..2a17766f
--- /dev/null
+++ b/com32/hdt/lib-ansi.h
@@ -0,0 +1,43 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2009 Erwan Velu - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * -----------------------------------------------------------------------
+ */
+
+#ifndef DEFINE_LIB_ANSI_H
+#define DEFINE_LIB_ANSI_H
+void display_cursor(bool status);
+void clear_end_of_line();
+void move_cursor_left(int count);
+void move_cursor_right(int count);
+void clear_line();
+void clear_beginning_of_line();
+void move_cursor_to_column(int count);
+void move_cursor_to_next_line();
+void disable_utf8();
+void set_g1_special_char();
+void set_us_g0_charset();
+void clear_entire_screen();
+#endif
diff --git a/com32/modules/Makefile b/com32/modules/Makefile
index f0089636..ba76268f 100644
--- a/com32/modules/Makefile
+++ b/com32/modules/Makefile
@@ -21,7 +21,8 @@ include ../MCONFIG
MODULES = chain.c32 config.c32 ethersel.c32 mboot.c32 dmitest.c32 \
cpuidtest.c32 \
pcitest.c32 elf.c32 linux.c32 reboot.c32 pmload.c32 meminfo.c32 \
- sdi.c32 sanboot.c32 ifcpu64.c32 vesainfo.c32 kbdmap.c32 cmd.c32
+ sdi.c32 sanboot.c32 ifcpu64.c32 vesainfo.c32 kbdmap.c32 cmd.c32 \
+ vpdtest.c32
TESTFILES =
diff --git a/com32/modules/vpdtest.c b/com32/modules/vpdtest.c
new file mode 100644
index 00000000..81a9faeb
--- /dev/null
+++ b/com32/modules/vpdtest.c
@@ -0,0 +1,68 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2009 Erwan Velu - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * -----------------------------------------------------------------------
+*/
+
+/*
+ * vpdtest.c
+ *
+ * VPD demo program using libcom32
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <console.h>
+#include "vpd/vpd.h"
+
+int main(void)
+{
+ char buffer[1024];
+ s_vpd vpd;
+ openconsole(&dev_stdcon_r, &dev_stdcon_w);
+
+ if (vpd_decode(&vpd) == -ENOVPDTABLE) {
+ printf("No VPD Structure found\n");
+ return -1;
+ } else {
+ printf("VPD present at address : 0x%s\n",vpd.base_address);
+ }
+ if (strlen(vpd.bios_build_id)>0)
+ printf("Bios Build ID : %s\n",vpd.bios_build_id);
+ if (strlen(vpd.bios_release_date)>0)
+ printf("Bios Release Date : %s\n",vpd.bios_release_date);
+ if (strlen(vpd.bios_version)>0)
+ printf("Bios Version : %s\n",vpd.bios_version);
+ if (strlen(vpd.default_flash_filename)>0)
+ printf("Default Flash Filename : %s\n",vpd.default_flash_filename);
+ if (strlen(vpd.box_serial_number)>0)
+ printf("Box Serial Number : %s\n",vpd.box_serial_number);
+ if (strlen(vpd.motherboard_serial_number)>0)
+ printf("Motherboard Serial Number : %s\n",vpd.motherboard_serial_number);
+ if (strlen(vpd.machine_type_model)>0)
+ printf("Machine Type/Model : %s\n",vpd.machine_type_model);
+
+ return 0;
+}