diff options
author | Erwan Velu <erwan.velu@free.fr> | 2009-02-20 22:13:33 +0100 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2009-02-25 20:58:42 -0800 |
commit | b8341ac72e822e7c618b40e73dc0c439fbc812f4 (patch) | |
tree | 10c0cd6636afa46dc042efdfb0f48b3f62cb4800 /com32 | |
parent | e592c65c6a40f0336974d3392623f203231e96a0 (diff) | |
download | syslinux-b8341ac72e822e7c618b40e73dc0c439fbc812f4.tar.gz |
hdt: Adding more dmi/pci support in cli mode
Diffstat (limited to 'com32')
-rw-r--r-- | com32/hdt/Makefile | 2 | ||||
-rw-r--r-- | com32/hdt/hdt-cli-dmi.c | 72 | ||||
-rw-r--r-- | com32/hdt/hdt-cli-pci.c | 71 | ||||
-rw-r--r-- | com32/hdt/hdt-cli.c | 75 | ||||
-rw-r--r-- | com32/hdt/hdt-cli.h | 18 | ||||
-rw-r--r-- | com32/hdt/hdt-common.c | 3 | ||||
-rw-r--r-- | com32/hdt/hdt-menu-pci.c | 6 | ||||
-rw-r--r-- | com32/hdt/hdt-menu.c | 1 | ||||
-rw-r--r-- | com32/hdt/hdt.h | 2 |
9 files changed, 225 insertions, 25 deletions
diff --git a/com32/hdt/Makefile b/com32/hdt/Makefile index 9589e540..c1487378 100644 --- a/com32/hdt/Makefile +++ b/com32/hdt/Makefile @@ -43,7 +43,7 @@ all: hdt.c32 $(LIB) hdt.elf: hdt.o hdt-ata.o hdt-menu.o hdt-menu-pci.o hdt-menu-kernel.o \ hdt-menu-disk.o hdt-menu-dmi.o hdt-menu-processor.o hdt-menu-syslinux.o hdt-menu-about.o \ - hdt-cli.o hdt-common.o \ + hdt-cli.o hdt-common.o hdt-cli-pci.o hdt-cli-dmi.o \ $(com32)/modules/cpuid.o $(com32)/modules/dmi.o $(topdir)/menu/libmenu/libmenu.a $(LIB) $(C_LIBS) $(LD) $(LDFLAGS) -o $@ $^ diff --git a/com32/hdt/hdt-cli-dmi.c b/com32/hdt/hdt-cli-dmi.c new file mode 100644 index 00000000..c5a169b5 --- /dev/null +++ b/com32/hdt/hdt-cli-dmi.c @@ -0,0 +1,72 @@ +/* ----------------------------------------------------------------------- * + * + * 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. + * + * ----------------------------------------------------------------------- +*/ + +#include "hdt-cli.h" +#include <string.h> + +void main_show_dmi(struct s_hardware *hardware) { + char available_dmi_commands[1024]; + memset(available_dmi_commands,0,sizeof available_dmi_commands); + + if (hardware->dmi_detection==false) { + detect_dmi(hardware); + } + + 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," ",1); + 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); + } + printf("Available commands: %s\n",available_dmi_commands); +} diff --git a/com32/hdt/hdt-cli-pci.c b/com32/hdt/hdt-cli-pci.c new file mode 100644 index 00000000..a521a387 --- /dev/null +++ b/com32/hdt/hdt-cli-pci.c @@ -0,0 +1,71 @@ +/* ----------------------------------------------------------------------- * + * + * 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. + * + * ----------------------------------------------------------------------- +*/ + +#include "hdt-cli.h" +#include "hdt-common.h" +#include <stdlib.h> +#include <string.h> + +void main_show_pci(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]; + + if (hardware->pci_detection==false) { + detect_pci(hardware); + } + printf("%d PCI devices detected\n",hardware->nb_pci_devices); + + if (hardware->pci_ids_return_code == -ENOPCIIDS) { + printf("The pci.ids file is missing, device names can't be computed. Please put one in same dir as hdt\n"); + } + + /* 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); + + printf("%02d: %02x:%02x.%01x %s %s \n", + i,__pci_bus, __pci_slot, __pci_func,pci_device->dev_info->vendor_name, + pci_device->dev_info->product_name); + printf(" # %s # ID:%04x:%04x[%04x:%04x] # Kmod:%s\n", + pci_device->dev_info->class_name, + pci_device->vendor, pci_device->product, + pci_device->sub_vendor, pci_device->sub_product,kernel_modules); + + i++; + } + + +} diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c index 2f6b6fa6..6c154b53 100644 --- a/com32/hdt/hdt-cli.c +++ b/com32/hdt/hdt-cli.c @@ -31,44 +31,85 @@ #include <stdlib.h> #include <string.h> +void set_mode(struct s_cli_mode *cli_mode, int mode) { + switch (mode) { + case EXIT_MODE: cli_mode->mode=mode; snprintf(cli_mode->prompt,sizeof cli_mode->prompt,"%s:",CLI_EXIT); break; + case HDT_MODE: cli_mode->mode=mode; snprintf(cli_mode->prompt,sizeof cli_mode->prompt,"%s:",CLI_HDT); break; + case PCI_MODE: cli_mode->mode=mode; snprintf(cli_mode->prompt,sizeof cli_mode->prompt,"%s:",CLI_PCI); break; + case DMI_MODE: cli_mode->mode=mode; snprintf(cli_mode->prompt,sizeof cli_mode->prompt,"%s:",CLI_DMI); break; + } +} + /* Code that manage the cli mode */ void start_cli_mode(int argc, char *argv[]) { char cli_line[256]; struct s_hardware hardware; + struct s_cli_mode cli_mode; /* Cleaning structures */ init_hardware(&hardware); + set_mode(&cli_mode,HDT_MODE); + printf("Entering CLI mode\n"); + for (;;) { memset(cli_line,0,sizeof cli_line); - printf("hdt:"); + printf("%s",cli_mode.prompt); + fgets(cli_line, sizeof cli_line, stdin); cli_line[strlen(cli_line)-1]='\0'; /* We use sizeof BLAH - 1 to remove the last \0 */ - if ( !strncmp(cli_line, CLI_EXIT, sizeof CLI_EXIT - 1) ) - break; - if ( !strncmp(cli_line, CLI_HELP, sizeof CLI_HELP - 1) ) - show_cli_help(); - if ( !strncmp(cli_line, CLI_SHOW, sizeof CLI_SHOW - 1) ) - main_show(strstr(cli_line,"show")+ sizeof CLI_SHOW, &hardware); + + if ( !strncmp(cli_line, CLI_EXIT, sizeof CLI_EXIT - 1) ) { + int mode=do_exit(&cli_mode); + if (mode == EXIT_MODE) + return; + set_mode(&cli_mode,mode); + continue; + } + + if ( !strncmp(cli_line, CLI_HELP, sizeof CLI_HELP - 1) ) { + show_cli_help(&cli_mode); + continue; + } + if ( !strncmp(cli_line, CLI_SHOW, sizeof CLI_SHOW - 1) ) { + main_show(strstr(cli_line,"show")+ sizeof CLI_SHOW, &hardware); + continue; + } + + if ( !strncmp(cli_line, CLI_PCI, sizeof CLI_PCI - 1) ) { + set_mode(&cli_mode,PCI_MODE); + continue; + } + if ( !strncmp(cli_line, CLI_DMI, sizeof CLI_DMI - 1) ) { + set_mode(&cli_mode,DMI_MODE); + continue; + } } } +int do_exit(struct s_cli_mode *cli_mode) { + switch (cli_mode->mode) { + case HDT_MODE: return EXIT_MODE; break; + case PCI_MODE: return HDT_MODE; break; + case DMI_MODE: return HDT_MODE; break; + } -void show_cli_help() { - printf("Available commands are : %s %s\n",CLI_EXIT,CLI_HELP); } -void main_show_dmi(struct s_hardware *hardware) { - printf("Let's show dmi stuff !\n"); +void show_cli_help(struct s_cli_mode *cli_mode) { +switch (cli_mode->mode) { + case HDT_MODE: + printf("Available commands are : %s %s %s %s %s\n",CLI_EXIT,CLI_HELP,CLI_SHOW, CLI_PCI, CLI_DMI); + break; + case PCI_MODE: + printf("Available commands are : %s %s %s\n",CLI_EXIT, CLI_HELP, CLI_SHOW); + break; + case DMI_MODE: + printf("Available commands are : %s %s %s\n",CLI_EXIT, CLI_HELP, CLI_SHOW); + break; } - -void main_show_pci(struct s_hardware *hardware) { - if (hardware->pci_detection==false) { - detect_pci(hardware); - } - printf("%d PCI devices detected\n",hardware->nb_pci_devices); } void main_show(char *item, struct s_hardware *hardware) { diff --git a/com32/hdt/hdt-cli.h b/com32/hdt/hdt-cli.h index 48bfa546..6651f533 100644 --- a/com32/hdt/hdt-cli.h +++ b/com32/hdt/hdt-cli.h @@ -34,10 +34,26 @@ #define CLI_EXIT "exit" #define CLI_HELP "help" #define CLI_SHOW "show" +#define CLI_HDT "hdt" #define CLI_PCI "pci" #define CLI_DMI "dmi" +#define CLI_DMI_BASE_BOARD "base_board" +#define CLI_DMI_BATTERY "battery" +#define CLI_DMI_BIOS "bios" +#define CLI_DMI_CHASSIS "chassis" +#define CLI_DMI_MEMORY "memory" +#define CLI_DMI_PROCESSOR "processor" +#define CLI_DMI_SYSTEM "system" -void show_cli_help(); +struct s_cli_mode { + int mode; + char prompt[32]; +}; + +enum { EXIT_MODE, HDT_MODE, PCI_MODE, DMI_MODE }; + +void show_cli_help(struct s_cli_mode *cli_mode); void start_cli_mode(int argc, char *argv[]); void main_show(char *item, struct s_hardware *hardware); +int do_exit(struct s_cli_mode *cli_mode); #endif diff --git a/com32/hdt/hdt-common.c b/com32/hdt/hdt-common.c index 2c98d6ec..eaa18df9 100644 --- a/com32/hdt/hdt-common.c +++ b/com32/hdt/hdt-common.c @@ -75,6 +75,7 @@ void detect_disks(struct s_hardware *hardware) { void detect_pci(struct s_hardware *hardware) { hardware->pci_detection=true; printf("PCI: Detecting Devices\n"); + /* Scanning to detect pci buses and devices */ hardware->pci_domain = pci_scan(); @@ -83,8 +84,6 @@ void detect_pci(struct s_hardware *hardware) { hardware->nb_pci_devices++; } - printf("PCI: %d Devices Found\n",hardware->nb_pci_devices); - 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); diff --git a/com32/hdt/hdt-menu-pci.c b/com32/hdt/hdt-menu-pci.c index c37cdd1b..477ba4aa 100644 --- a/com32/hdt/hdt-menu-pci.c +++ b/com32/hdt/hdt-menu-pci.c @@ -91,11 +91,11 @@ int compute_PCI(struct s_hdt_menu *hdt_menu, struct s_hardware *hardware) { /* 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 i=0; i<pci_device->dev_info->linux_kernel_module_count;i++) { - if (i>0) { + 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[i],LINUX_KERNEL_MODULE_SIZE-1); + 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); diff --git a/com32/hdt/hdt-menu.c b/com32/hdt/hdt-menu.c index 64787f60..df6a5b55 100644 --- a/com32/hdt/hdt-menu.c +++ b/com32/hdt/hdt-menu.c @@ -208,5 +208,6 @@ void detect_hardware(struct s_hardware *hardware) { } #ifdef WITH_PCI detect_pci(hardware); + printf("PCI: %d Devices Found\n",hardware->nb_pci_devices); #endif } diff --git a/com32/hdt/hdt.h b/com32/hdt/hdt.h index 8d898c78..3079b306 100644 --- a/com32/hdt/hdt.h +++ b/com32/hdt/hdt.h @@ -32,7 +32,7 @@ #define PRODUCT_NAME "Hardware Detection Tool" #define AUTHOR "Erwan Velu" #define CONTACT "erwan(dot)velu(point)free(dot)fr" -#define VERSION "0.1.5" +#define VERSION "0.1.6" #define ATTR_PACKED __attribute__((packed)) |