diff options
Diffstat (limited to 'com32/hdt')
37 files changed, 2559 insertions, 105 deletions
diff --git a/com32/hdt/.gitignore b/com32/hdt/.gitignore index 98927943..82d5b472 100644 --- a/com32/hdt/.gitignore +++ b/com32/hdt/.gitignore @@ -5,3 +5,4 @@ floppy/syslinux.cfg *.iso iso/ *gz +hdt*checksums diff --git a/com32/hdt/Makefile b/com32/hdt/Makefile index 40ea3ac4..add640a7 100644 --- a/com32/hdt/Makefile +++ b/com32/hdt/Makefile @@ -16,11 +16,11 @@ ## topdir = ../.. -include ../MCONFIG +MAKEDIR = $(topdir)/mk +include $(MAKEDIR)/com32.mk -LIBS = ../cmenu/libmenu/libmenu.a ../libutil/libutil_com.a \ - ../lib/libcom32.a $(LIBGCC) -CFLAGS += -I$(com32)/cmenu/libmenu +LIBS = ../cmenu/libmenu/libmenu.a ../libupload/libcom32upload.a +CFLAGS += -I$(com32)/cmenu/libmenu -I$(com32) MODULES = hdt.c32 TESTFILES = @@ -28,7 +28,8 @@ TESTFILES = OBJS = $(patsubst %.c,%.o,$(wildcard *.c)) VERSION = $(shell $(SED) -n 's/\#define VERSION \"\(.*\)\"/\1/p' hdt.h) CODENAME = $(shell $(SED) -n 's/\#define CODENAME \"\(.*\)\"/\1/p' hdt.h) -VERSION_C32 = $(shell echo $(VERSION) | $(SED) -e 's/-/_/g' | $(SED) -e 's/\./_/g') +NODASH_VERSION = $(shell echo $(VERSION) | $(SED) -e 's/-/_/g' | $(SED) -e 's/\./_/g') +SUM_FILE = hdt-$(VERSION).checksums MEMTEST_URL = http://memtest.org/download/4.20/memtest86+-4.20.bin MEMTEST = memtest.bin @@ -44,6 +45,7 @@ FLOPPY_DIR ?= floppy PCI_IDS_FILE ?= $(PWD)/$(FLOPPY_DIR)/pci.ids GZ_PCI_IDS_FILE ?= $(PCI_IDS_FILE).gz MENU_COM32 ?= $(com32)/menu/menu.c32 +CHAIN_COM32 ?= $(com32)/chain/chain.c32 ART_DIR ?= art/ QEMU ?= qemu-kvm @@ -55,11 +57,11 @@ hdt.elf : $(OBJS) $(LIBS) $(C_LIBS) memtest: -[ ! -f $(FLOPPY_DIR)/$(MEMTEST) ] && $(WGET) $(MEMTEST_URL) -O $(FLOPPY_DIR)/$(MEMTEST) -hdt.img: hdt.c32 $(FLOPPY_DIR)/hdt.cfg $(FLOPPY_DIR)/mtools.conf $(topdir)/mtools/syslinux $(MENU_COM32) memtest +hdt.img: hdt.c32 $(FLOPPY_DIR)/hdt.cfg $(FLOPPY_DIR)/mtools.conf $(topdir)/mtools/syslinux $(MENU_COM32) memtest $(CHAIN_COM32) rm -f hdt*.img $(SED) -e 's/%VERSION%/$(VERSION)/g' $(FLOPPY_DIR)/hdt.cfg |\ $(SED) -e 's/%CODENAME%/$(CODENAME)/g' > $(FLOPPY_DIR)/syslinux.cfg - MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MFORMAT) -v HDT_$(VERSION) -f 1440 -C a: + MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MFORMAT) -v HDT_$(NODASH_VERSION) -f 1440 -C a: $(topdir)/mtools/syslinux hdt.img -[ ! -f $(GZ_PCI_IDS_FILE) ] && cp /usr/share/hwdata/pci.ids $(PCI_IDS_FILE) && $(GZIPPROG) $(PCI_IDS_FILE) -[ ! -f $(GZ_PCI_IDS_FILE) ] && cp /usr/share/pci.ids $(PCI_IDS_FILE) && $(GZIPPROG) $(PCI_IDS_FILE) @@ -67,10 +69,13 @@ hdt.img: hdt.c32 $(FLOPPY_DIR)/hdt.cfg $(FLOPPY_DIR)/mtools.conf $(topdir)/mtool -[ -f $(MODULES_PCIMAP_FILE) ] && cat $(MODULES_PCIMAP_FILE) | $(GZIPPROG) - -f | MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MCOPY) - a:modules.pcimap MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MCOPY) hdt.c32 a: MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MCOPY) $(MENU_COM32) a: + MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MCOPY) $(CHAIN_COM32) a: @ [ -f $(GZ_PCI_IDS_FILE) ] && MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MCOPY) $(GZ_PCI_IDS_FILE) a:pci.ids || printf "\nThe $(GZ_PCI_IDS_FILE) file is missing and can be downloaded from http://pciids.sourceforge.net and gzipped in\nthe ./com32/hdt/$(FLOPPY_DIR) directory of the extracted Syslinux source.\n\n" MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MCOPY) $(FLOPPY_DIR)/syslinux.cfg a: MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MCOPY) $(FLOPPY_DIR)/$(MEMTEST) a: MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MCOPY) $(ART_DIR)/backgnd.png a: + MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MCOPY) $(ART_DIR)/display.png a: + MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MCOPY) $(ART_DIR)/red.png a: mv hdt.img hdt-$(VERSION).img ln -sf hdt-$(VERSION).img hdt.img @@ -89,7 +94,10 @@ hdt.iso: hdt.c32 $(topdir)/core/isolinux.bin $(FLOPPY_DIR)/hdt.cfg memtest cp hdt.c32 $(ISO_DIR)/$(ISOLINUX_DIR) cp $(FLOPPY_DIR)/$(MEMTEST) $(ISO_DIR)/$(ISOLINUX_DIR) cp $(MENU_COM32) $(ISO_DIR)/$(ISOLINUX_DIR) + cp $(CHAIN_COM32) $(ISO_DIR)/$(ISOLINUX_DIR) cp -av $(ART_DIR)/backgnd.png $(ISO_DIR)/$(ISOLINUX_DIR) + cp -av $(ART_DIR)/display.png $(ISO_DIR)/$(ISOLINUX_DIR) + cp -av $(ART_DIR)/red.png $(ISO_DIR)/$(ISOLINUX_DIR) -[ ! -f $(GZ_PCI_IDS_FILE) ] && cp /usr/share/hwdata/pci.ids $(PCI_IDS_FILE) && $(GZIPPROG) $(PCI_IDS_FILE) -[ ! -f $(GZ_PCI_IDS_FILE) ] && cp /usr/share/pci.ids $(PCI_IDS_FILE) && $(GZIPPROG) $(PCI_IDS_FILE) -[ -f $(MODULES_ALIAS_FILE) ] && cp $(MODULES_ALIAS_FILE) $(ISO_DIR)/$(ISOLINUX_DIR)\ @@ -106,8 +114,18 @@ hdt.iso: hdt.c32 $(topdir)/core/isolinux.bin $(FLOPPY_DIR)/hdt.cfg memtest mv hdt.iso hdt-$(VERSION).iso ln -sf hdt-$(VERSION).iso hdt.iso -release: spotless hdt.c32 hdt.img hdt.img.gz hdt.iso - mv hdt.c32 hdt_$(VERSION_C32).c32 +hdt-hybrid.iso: hdt.iso ../../utils/isohybrid + cp hdt-$(VERSION).iso hdt-hybrid-$(VERSION).iso + ../../utils/isohybrid --partok hdt-hybrid-$(VERSION).iso + ln -sf hdt-hybrid-$(VERSION).iso hdt-hybrid.iso + +release: spotless hdt.c32 hdt.img hdt.img.gz hdt.iso hdt-hybrid.iso + mv hdt.c32 hdt_$(NODASH_VERSION).c32 + md5sum hdt_$(NODASH_VERSION).c32 >$(SUM_FILE) + md5sum hdt-$(VERSION).iso >>$(SUM_FILE) + md5sum hdt-hybrid-$(VERSION).iso >>$(SUM_FILE) + md5sum hdt-$(VERSION).img >>$(SUM_FILE) + md5sum hdt-$(VERSION).img.gz >>$(SUM_FILE) test: hdt.img $(QEMU) -fda hdt.img @@ -123,6 +141,7 @@ spotless: clean rm -rf $(ISO_DIR) rm -rf $(FLOPPY_DIR)/$(MEMTEST) rm -rf $(FLOPPY_DIR)/pci.ids* + rm -rf hdt-*checksums rm -f *~ \#* install: diff --git a/com32/hdt/art/display.png b/com32/hdt/art/display.png Binary files differnew file mode 100644 index 00000000..31fabef6 --- /dev/null +++ b/com32/hdt/art/display.png diff --git a/com32/hdt/art/red.png b/com32/hdt/art/red.png Binary files differnew file mode 100644 index 00000000..c5616ac2 --- /dev/null +++ b/com32/hdt/art/red.png diff --git a/com32/hdt/floppy/hdt.cfg b/com32/hdt/floppy/hdt.cfg index f72a2134..524c4e06 100644 --- a/com32/hdt/floppy/hdt.cfg +++ b/com32/hdt/floppy/hdt.cfg @@ -77,6 +77,34 @@ ENDTEXT COM32 hdt.c32 APPEND modules_pcimap=modules.pcimap modules_alias=modules.alias pciids=pci.ids verbose nomenu +LABEL dump +MENU LABEL Dump hardware config to TFTP server +TEXT HELP + Starts HDT using the Command Line Interface (CLI) and run 'dump' + VESA mode is enabled +ENDTEXT +COM32 hdt.c32 +APPEND modules_pcimap=modules.pcimap modules_alias=modules.alias pciids=pci.ids quiet vesa nomenu auto='dump' + +LABEL postexec +MENU LABEL Dump memory info, sleep 5 and start memtest entry +TEXT HELP + Starts HDT using the Command Line Interface (CLI), show an item, say a message reboot and start memtest + VESA mode is enabled +ENDTEXT +COM32 hdt.c32 +APPEND modules_pcimap=modules.pcimap modules_alias=modules.alias pciids=pci.ids quiet vesa nomenu auto='show memory;say `########`;say `Starting memtest in 5 sec`;sleep 5;exit' postexec='memtest' + +LABEL display +MENU LABEL Display feature (VESA mode) +TEXT HELP + Starts HDT using the Command Line Interface (CLI) + VESA mode is enabled + A Picture is shown by using the display command +ENDTEXT +COM32 hdt.c32 +APPEND modules_pcimap=modules.pcimap modules_alias=modules.alias pciids=pci.ids silent nomenu vesa auto='display display.png; sleep 5000; display red.png' + MENU SEPARATOR LABEL memtest diff --git a/com32/hdt/hdt-cli-acpi.c b/com32/hdt/hdt-cli-acpi.c index 1b608c26..55b0c3c7 100644 --- a/com32/hdt/hdt-cli-acpi.c +++ b/com32/hdt/hdt-cli-acpi.c @@ -37,7 +37,7 @@ /* Print ACPI's table header in a defined formating */ static void show_header(void *address, s_acpi_description_header * h) { - more_printf("%-4s v%03x %-6s %-7s 0x%08x %-4s 0x%08x @ 0x%p\n", + more_printf("%-4s v%03x %-6s %-8s 0x%08x %-7s 0x%08x @ 0x%p\n", h->signature, h->revision, h->oem_id, h->oem_table_id, h->oem_revision, h->creator_id, h->creator_revision, address) } @@ -158,25 +158,6 @@ static void show_local_apic(s_madt * madt) } } -/* M1PS flags have to be interpreted as strings */ -static char *flags_to_string(char *buffer, uint16_t flags) -{ - memset(buffer, 0, sizeof(buffer)); - strcpy(buffer, "default"); - if ((flags & POLARITY_ACTIVE_HIGH) == POLARITY_ACTIVE_HIGH) - strcpy(buffer, "high"); - else if ((flags & POLARITY_ACTIVE_LOW) == POLARITY_ACTIVE_LOW) - strcpy(buffer, "low"); - if ((flags & TRIGGER_EDGE) == TRIGGER_EDGE) - strncat(buffer, " edge", 5); - else if ((flags & TRIGGER_LEVEL) == TRIGGER_LEVEL) - strncat(buffer, " level", 6); - else - strncat(buffer, " default", 8); - - return buffer; -} - /* Display the local apic NMI configuration */ static void show_local_apic_nmi(s_madt * madt) { @@ -225,7 +206,7 @@ static void show_io_apic(s_madt * madt) break; } - more_printf("IO_APIC[%d] : apic_id[0x%02x] adress[0x%08x] %s\n", + more_printf("IO_APIC[%d] : apic_id[0x%02x] address[0x%08x] %s\n", i, sio->io_apic_id, sio->io_apic_address, buffer); } } @@ -286,10 +267,12 @@ struct cli_callback_descr list_acpi_show_modules[] = { { .name = "apic", .exec = show_acpi_apic, + .nomodule = false, }, { .name = NULL, .exec = NULL, + .nomodule = false, }, }; diff --git a/com32/hdt/hdt-cli-disk.c b/com32/hdt/hdt-cli-disk.c index 24fce676..10c95d7d 100644 --- a/com32/hdt/hdt-cli-disk.c +++ b/com32/hdt/hdt-cli-disk.c @@ -225,14 +225,17 @@ struct cli_callback_descr list_disk_show_modules[] = { { .name = "disks", .exec = main_show_disks, + .nomodule = false, }, { .name = "disk", .exec = main_show_disk, + .nomodule = false, }, { .name = NULL, .exec = NULL, + .nomodule = false, }, }; diff --git a/com32/hdt/hdt-cli-dmi.c b/com32/hdt/hdt-cli-dmi.c index 45cbb240..02bea0f7 100644 --- a/com32/hdt/hdt-cli-dmi.c +++ b/com32/hdt/hdt-cli-dmi.c @@ -617,62 +617,77 @@ struct cli_callback_descr list_dmi_show_modules[] = { { .name = CLI_DMI_BASE_BOARD, .exec = show_dmi_base_board, + .nomodule = false, }, { .name = CLI_DMI_BIOS, .exec = show_dmi_bios, + .nomodule = false, }, { .name = CLI_DMI_BATTERY, .exec = show_dmi_battery, + .nomodule = false, }, { .name = CLI_DMI_CHASSIS, .exec = show_dmi_chassis, + .nomodule = false, }, { .name = CLI_DMI_MEMORY, .exec = show_dmi_memory_modules, + .nomodule = false, }, { .name = CLI_DMI_MEMORY_BANK, .exec = show_dmi_memory_bank, + .nomodule = false, }, { .name = "module", .exec = show_dmi_memory_module, + .nomodule = false, }, { .name = CLI_DMI_PROCESSOR, .exec = show_dmi_cpu, + .nomodule = false, }, { .name = CLI_DMI_SYSTEM, .exec = show_dmi_system, + .nomodule = false, }, { .name = CLI_DMI_OEM, .exec = show_dmi_oem_strings, + .nomodule = false, }, { .name = CLI_DMI_SECURITY, .exec = show_dmi_hardware_security, + .nomodule = false, }, { .name = CLI_DMI_IPMI, .exec = show_dmi_ipmi, + .nomodule = false, }, { .name = CLI_DMI_CACHE, .exec = show_dmi_cache, + .nomodule = false, }, { .name = CLI_DMI_LIST, .exec = show_dmi_modules, + .nomodule = false, }, { .name = NULL, .exec = NULL, + .nomodule = false, }, }; diff --git a/com32/hdt/hdt-cli-hdt.c b/com32/hdt/hdt-cli-hdt.c index 65068232..3c571d60 100644 --- a/com32/hdt/hdt-cli-hdt.c +++ b/com32/hdt/hdt-cli-hdt.c @@ -54,12 +54,12 @@ static void main_show_modes(int argc __unused, char **argv __unused, int i = 0; reset_more_printf(); - printf("Available modes:\n"); + more_printf("Available modes:\n"); while (list_modes[i]) { printf("%s ", list_modes[i]->name); i++; } - printf("\n"); + more_printf("\n"); } /** @@ -119,7 +119,7 @@ static void show_cli_help(int argc __unused, char **argv __unused, find_cli_mode_descr(hdt_cli.mode, ¤t_mode); - printf("Available commands are:\n"); + more_printf("Available commands are:\n"); /* List first default modules of the mode */ if (current_mode->default_modules && current_mode->default_modules->modules) { @@ -154,7 +154,7 @@ static void show_cli_help(int argc __unused, char **argv __unused, /* List secondly the show modules of the mode */ if (current_mode->show_modules && current_mode->show_modules->modules) { - printf("\nshow commands:\n"); + more_printf("\nshow commands:\n"); j = 0; while (current_mode->show_modules->modules[j].name) { printf("%s ", current_mode->show_modules->modules[j].name); @@ -165,7 +165,7 @@ static void show_cli_help(int argc __unused, char **argv __unused, /* List thirdly the set modules of the mode */ if (current_mode->set_modules && current_mode->set_modules->modules) { - printf("\nset commands:\n"); + more_printf("\nset commands:\n"); j = 0; while (current_mode->set_modules->modules[j].name) { printf("%s ", current_mode->set_modules->modules[j].name); @@ -250,97 +250,209 @@ static void do_reboot(int argc __unused, char **argv __unused, syslinux_reboot(1); } +/** + * do_dump - dump info + **/ +static void do_dump(int argc __unused, char **argv __unused, + struct s_hardware *hardware) +{ + dump(hardware); +} + +/** + * do_sleep - sleep a number of milliseconds + **/ +static void do_sleep(int argc , char **argv , + struct s_hardware *hardware) +{ + (void) hardware; + if (argc != 1) return; + more_printf("Sleep %d milliseconds\n",atoi(argv[0])); + msleep(atoi(argv[0])); +} + +/** + * do_display - display an image to user + **/ +static void do_display(int argc , char **argv , + struct s_hardware *hardware) +{ + (void) hardware; + if ((argc != 1) || (vesamode == false)) return; + more_printf("Display %s file\n",argv[0]); + vesacon_load_background(argv[0]); +} + +/** + * do_say - say message to user + **/ +static void do_say(int argc , char **argv , + struct s_hardware *hardware) +{ + (void) hardware; + if (argc == 0) return; + + char text_to_say[255]={0}; + int arg=0; +#if DEBUG + for (int i=0; i<argc;i++) dprintf("SAY: arg[%d]={%s}\n",i,argv[i]); +#endif + char *argument = strchr(argv[arg],'`'); + if ( argument != NULL) { + argument++; + strcat(text_to_say, argument); + + while ((strchr(argument, '`') == NULL) && (arg+1<argc)) { + arg++; + argument = (char *)argv[arg]; + strcat(text_to_say, " "); + strcat(text_to_say, argument); + } + + /* Removing last ` if any */ + char *last_quote = strrchr(text_to_say,'`'); + if ( last_quote != NULL ) { + *last_quote='\0'; + dprintf("SAY CMD = [%s]\n",text_to_say); + } + + more_printf("%s\n",text_to_say); + } +} + /* Default hdt mode */ struct cli_callback_descr list_hdt_default_modules[] = { { .name = CLI_CLEAR, .exec = cli_clear_screen, + .nomodule = false, }, { .name = CLI_EXIT, .exec = do_exit, + .nomodule = false, }, { .name = CLI_HELP, .exec = show_cli_help, + .nomodule = false, }, { .name = CLI_MENU, .exec = goto_menu, + .nomodule = false, }, { .name = CLI_REBOOT, .exec = do_reboot, + .nomodule = false, }, { .name = CLI_HISTORY, .exec = print_history, + .nomodule = false, + }, + { + .name = CLI_DUMP, + .exec = do_dump, + .nomodule = false, + }, + { + .name = CLI_SAY, + .exec = do_say, + .nomodule = true, + }, + { + .name = CLI_DISPLAY, + .exec = do_display, + .nomodule = true, + }, + { + .name = CLI_SLEEP, + .exec = do_sleep, + .nomodule = true, }, { .name = NULL, - .exec = NULL}, + .exec = NULL, + .nomodule = false}, }; struct cli_callback_descr list_hdt_show_modules[] = { { .name = CLI_SUMMARY, .exec = main_show_summary, + .nomodule = false, }, { .name = CLI_PCI, .exec = main_show_pci, + .nomodule = false, }, { .name = CLI_DMI, .exec = main_show_dmi, + .nomodule = false, }, { .name = CLI_CPU, .exec = main_show_cpu, + .nomodule = false, }, { .name = CLI_DISK, .exec = disks_summary, + .nomodule = false, }, { .name = CLI_PXE, .exec = main_show_pxe, + .nomodule = false, }, { .name = CLI_SYSLINUX, .exec = main_show_syslinux, + .nomodule = false, }, { .name = CLI_KERNEL, .exec = main_show_kernel, + .nomodule = false, }, { .name = CLI_VESA, .exec = main_show_vesa, + .nomodule = false, }, { .name = CLI_HDT, .exec = main_show_hdt, + .nomodule = false, }, { .name = CLI_VPD, .exec = main_show_vpd, + .nomodule = false, }, { .name = CLI_MEMORY, .exec = show_dmi_memory_modules, + .nomodule = false, }, { .name = CLI_ACPI, .exec = main_show_acpi, + .nomodule = false, }, { .name = "modes", .exec = main_show_modes, + .nomodule = false, }, { .name = NULL, .exec = NULL, + .nomodule = false, }, }; @@ -348,10 +460,12 @@ struct cli_callback_descr list_hdt_set_modules[] = { { .name = CLI_MODE, .exec = cli_set_mode, + .nomodule = false, }, { .name = NULL, .exec = NULL, + .nomodule = false, }, }; diff --git a/com32/hdt/hdt-cli-memory.c b/com32/hdt/hdt-cli-memory.c index 51d087e8..c05b7cd6 100644 --- a/com32/hdt/hdt-cli-memory.c +++ b/com32/hdt/hdt-cli-memory.c @@ -101,22 +101,27 @@ struct cli_callback_descr list_memory_show_modules[] = { { .name = "e820", .exec = show_memory_e820, + .nomodule=false, }, { .name = "e801", .exec = show_memory_e801, + .nomodule=false, }, { .name = "88", .exec = show_memory_88, + .nomodule=false, }, { .name = CLI_DMI_MEMORY_BANK, .exec = show_dmi_memory_bank, + .nomodule=false, }, { .name = NULL, .exec = NULL, + .nomodule=false, }, }; diff --git a/com32/hdt/hdt-cli-pci.c b/com32/hdt/hdt-cli-pci.c index 07c079d5..75fc0011 100644 --- a/com32/hdt/hdt-cli-pci.c +++ b/com32/hdt/hdt-cli-pci.c @@ -266,14 +266,17 @@ struct cli_callback_descr list_pci_show_modules[] = { { .name = CLI_IRQ, .exec = show_pci_irq, + .nomodule=false, }, { .name = CLI_PCI_DEVICE, .exec = show_pci_device, + .nomodule=false, }, { .name = NULL, .exec = NULL, + .nomodule=false, }, }; diff --git a/com32/hdt/hdt-cli-vesa.c b/com32/hdt/hdt-cli-vesa.c index 702f8bd6..ca44987a 100644 --- a/com32/hdt/hdt-cli-vesa.c +++ b/com32/hdt/hdt-cli-vesa.c @@ -98,10 +98,12 @@ struct cli_callback_descr list_vesa_show_modules[] = { { .name = CLI_MODES, .exec = show_vesa_modes, + .nomodule=false, }, { .name = NULL, .exec = NULL, + .nomodule=false, }, }; @@ -109,15 +111,18 @@ struct cli_callback_descr list_vesa_commands[] = { { .name = CLI_ENABLE, .exec = enable_vesa, + .nomodule=false, }, { .name = CLI_DISABLE, .exec = disable_vesa, + .nomodule=false, }, { .name = NULL, .exec = NULL, + .nomodule=false, }, }; diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c index 8b5335eb..7542da83 100644 --- a/com32/hdt/hdt-cli.c +++ b/com32/hdt/hdt-cli.c @@ -132,7 +132,7 @@ void set_mode(cli_mode_t mode, struct s_hardware *hardware) break; case PXE_MODE: if (hardware->sv->filesystem != SYSLINUX_FS_PXELINUX) { - printf("You are not currently using PXELINUX\n"); + more_printf("You are not currently using PXELINUX\n"); break; } hdt_cli.mode = mode; @@ -160,7 +160,7 @@ void set_mode(cli_mode_t mode, struct s_hardware *hardware) break; case DMI_MODE: if (!hardware->is_dmi_valid) { - printf("No valid DMI table found, exiting.\n"); + more_printf("No valid DMI table found, exiting.\n"); break; } hdt_cli.mode = mode; @@ -172,7 +172,7 @@ void set_mode(cli_mode_t mode, struct s_hardware *hardware) break; case VPD_MODE: if (!hardware->is_vpd_valid) { - printf("No valid VPD table found, exiting.\n"); + more_printf("No valid VPD table found, exiting.\n"); break; } hdt_cli.mode = mode; @@ -188,9 +188,9 @@ void set_mode(cli_mode_t mode, struct s_hardware *hardware) break; default: /* Invalid mode */ - printf("Unknown mode, please choose among:\n"); + more_printf("Unknown mode, please choose among:\n"); while (list_modes[i]) { - printf("\t%s\n", list_modes[i]->name); + more_printf("\t%s\n", list_modes[i]->name); i++; } } @@ -199,7 +199,7 @@ void set_mode(cli_mode_t mode, struct s_hardware *hardware) /* There is not cli_mode_descr struct for the exit mode */ if (current_mode == NULL && hdt_cli.mode != EXIT_MODE) { /* Shouldn't get here... */ - printf("!!! BUG: Mode '%d' unknown.\n", hdt_cli.mode); + more_printf("!!! BUG: Mode '%d' unknown.\n", hdt_cli.mode); } } @@ -365,14 +365,14 @@ static void parse_command_line(char *line, char **command, char **module, *command = malloc((token_len + 1) * sizeof(char)); strlcpy(*command, pch, token_len); (*command)[token_len] = '\0'; - dprintf("CLI DEBUG: command = %s\n", *command); + dprintf("CLI DEBUG parse: command = %s\n", *command); args_pos += args_len; } else if (token_found == 1) { /* Module */ *module = malloc((token_len + 1) * sizeof(char)); strlcpy(*module, pch, token_len); (*module)[token_len] = '\0'; - dprintf("CLI DEBUG: module = %s\n", *module); + dprintf("CLI DEBUG parse: module = %s\n", *module); args_pos += args_len; } else (*argc)++; @@ -380,7 +380,7 @@ static void parse_command_line(char *line, char **command, char **module, token_found++; pch = pch_next; } - dprintf("CLI DEBUG: argc = %d\n", *argc); + dprintf("CLI DEBUG parse: argc = %d\n", *argc); /* Skip arguments handling if none is supplied */ if (!*argc) @@ -390,9 +390,9 @@ static void parse_command_line(char *line, char **command, char **module, *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)); - strlcpy(argv[argc_iter], pch, sizeof(pch)); + dprintf("CLI DEBUG parse: argv[%d] = %s\n", argc_iter, pch); + argv[argc_iter] = malloc(strlen(pch) * sizeof(char)); + strlcpy(argv[argc_iter], pch, strlen(pch)); argc_iter++; pch = strtok(NULL, CLI_SPACE); /* @@ -585,6 +585,7 @@ static void autocomplete(char *line) parse_command_line(line, &command, &module, &argc, argv); + dprintf("CLI DEBUG autocomplete: before checking args\n"); /* If the user specified arguments, there is nothing we can complete */ if (argc != 0) goto out; @@ -625,22 +626,43 @@ static void exec_command(char *line, struct s_hardware *hardware) /* This will allocate memory for command and module */ parse_command_line(line, &command, &module, &argc, argv); + dprintf("CLI DEBUG exec: Checking for aliases\n"); /* * Expand shortcuts, if needed * This will allocate memory for argc/argv */ expand_aliases(line, &command, &module, &argc, argv); + + find_cli_callback_descr(command, current_mode->default_modules, + ¤t_module); - if (module == NULL) { - dprintf("CLI DEBUG: single command detected\n"); + if ((module == NULL) || (current_module->nomodule == true)) { + dprintf("CLI DEBUG exec : single command detected\n"); /* * 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. */ - find_cli_callback_descr(command, current_mode->default_modules, - ¤t_module); + + /* First of all it the command doesn't need module, let's rework the arguments */ + if ((current_module->nomodule == true) && ( module != NULL)) { + dprintf("CLI_DEBUG exec: Reworking arguments with argc=%d\n",argc); + char **new_argv=NULL; + new_argv=malloc((argc + 2)*sizeof(char)); + for (int argc_iter=0; argc_iter<argc; argc_iter++) { + dprintf("CLI_DEBUG exec rework : copy %d to %d (%s)\n",argc_iter,argc_iter+1,argv[argc_iter]); + new_argv[argc_iter+1] = malloc(strlen(argv[argc_iter])); + strlcpy(new_argv[argc_iter+1], argv[argc_iter], strlen(argv[argc_iter])); + free(argv[argc_iter]); + } + new_argv[0] = malloc(strlen(module)*sizeof(char)); + strlcpy(new_argv[0], module, strlen(module)); + argc++; + free(argv); + argv=new_argv; + } + if (current_module != NULL) current_module->exec(argc, argv, hardware); else if (!strncmp(command, CLI_SHOW, sizeof(CLI_SHOW) - 1) && @@ -657,7 +679,7 @@ static void exec_command(char *line, struct s_hardware *hardware) if (current_module != NULL) current_module->exec(argc, argv, hardware); else - printf("unknown command: '%s'\n", command); + more_printf("unknown command: '%s'\n", command); } } else { /* @@ -673,7 +695,7 @@ static void exec_command(char *line, struct s_hardware *hardware) * hdt> set mode dmi */ if (!strncmp(command, CLI_SHOW, sizeof(CLI_SHOW) - 1)) { - dprintf("CLI DEBUG: %s command detected\n", CLI_SHOW); + dprintf("CLI DEBUG exec: %s command detected\n", CLI_SHOW); /* Look first for a 'show' callback in the current mode */ find_cli_callback_descr(module, current_mode->show_modules, ¤t_module); @@ -681,6 +703,7 @@ static void exec_command(char *line, struct s_hardware *hardware) if (current_module != NULL) current_module->exec(argc, argv, hardware); else { + dprintf("CLI DEBUG exec: Looking for callback\n"); /* Look now for a 'show' callback in the hdt mode */ find_cli_callback_descr(module, hdt_mode.show_modules, ¤t_module); @@ -691,7 +714,7 @@ static void exec_command(char *line, struct s_hardware *hardware) printf("unknown module: '%s'\n", module); } } else if (!strncmp(command, CLI_SET, sizeof(CLI_SET) - 1)) { - dprintf("CLI DEBUG: %s command detected\n", CLI_SET); + dprintf("CLI DEBUG exec : %s command detected\n", CLI_SET); /* Look now for a 'set' callback in the hdt mode */ find_cli_callback_descr(module, current_mode->set_modules, ¤t_module); @@ -738,8 +761,7 @@ void start_auto_mode(struct s_hardware *hardware) int nb_commands = 0; char *commands[MAX_NB_AUTO_COMMANDS]; - if (!quiet) - more_printf("\nEntering Auto mode\n"); + more_printf("\nEntering Auto mode\n"); /* Protecting the auto_label from the strtok modifications */ char *temp = strdup(hardware->auto_label); @@ -811,7 +833,7 @@ void start_cli_mode(struct s_hardware *hardware) find_cli_mode_descr(hdt_cli.mode, ¤t_mode); if (current_mode == NULL) { /* Shouldn't get here... */ - printf("!!! BUG: Mode '%d' unknown.\n", hdt_cli.mode); + more_printf("!!! BUG: Mode '%d' unknown.\n", hdt_cli.mode); return; } @@ -820,7 +842,7 @@ void start_cli_mode(struct s_hardware *hardware) start_auto_mode(hardware); } - printf("Entering CLI mode\n"); + more_printf("Entering CLI mode\n"); reset_prompt(); diff --git a/com32/hdt/hdt-cli.h b/com32/hdt/hdt-cli.h index 13291092..82a4fc99 100644 --- a/com32/hdt/hdt-cli.h +++ b/com32/hdt/hdt-cli.h @@ -65,6 +65,10 @@ #define CLI_ACPI "acpi" #define CLI_ENABLE "enable" #define CLI_DISABLE "disable" +#define CLI_DUMP "dump" +#define CLI_SAY "say" +#define CLI_DISPLAY "display" +#define CLI_SLEEP "sleep" typedef enum { INVALID_MODE, @@ -119,6 +123,7 @@ struct cli_module_descr { struct cli_callback_descr { const char *name; void (*exec) (int argc, char **argv, struct s_hardware * hardware); + bool nomodule; }; /* Manage aliases */ diff --git a/com32/hdt/hdt-common.c b/com32/hdt/hdt-common.c index f1557b86..dcad28cd 100644 --- a/com32/hdt/hdt-common.c +++ b/com32/hdt/hdt-common.c @@ -63,6 +63,9 @@ void detect_parameters(const int argc, const char *argv[], /* Quiet mode - make the output more quiet */ quiet = true; + /* Silent mode - make not output at all */ + silent = false; + /* Vesa mode isn't set until we explictly call it */ vesamode = false; @@ -75,6 +78,8 @@ void detect_parameters(const int argc, const char *argv[], for (int i = 1; i < argc; i++) { if (!strncmp(argv[i], "quiet", 5)) { quiet = true; + } else if (!strncmp(argv[i], "silent", 6)) { + silent = true; } else if (!strncmp(argv[i], "verbose", 7)) { quiet = false; } else if (!strncmp(argv[i], "modules_pcimap=", 15)) { @@ -106,6 +111,36 @@ void detect_parameters(const int argc, const char *argv[], max_console_lines = MAX_CLI_LINES; } else if (!strncmp(argv[i], "nomenu", 6)) { menumode = false; + } else if (!strncmp(argv[i], "dump_filename=", 14)) { + strlcpy(hardware->dump_filename, argv[i] + 14, + sizeof(hardware->dump_filename)); + } else if (!strncmp(argv[i], "dump_path=", 10)) { + strlcpy(hardware->dump_path, argv[i] + 10, + sizeof(hardware->dump_path)); + } else if (!strncmp(argv[i], "tftp_ip=", 8)) { + strlcpy(hardware->tftp_ip, argv[i] + 8, + sizeof(hardware->tftp_ip)); + } else if (!strncmp(argv[i], "postexec=", 9)) { + /* The postexec= parameter is separated in several argv[] + * as it can contains spaces. + * We use the AUTO_DELIMITER char to define the limits + * of this parameter. + * i.e postexec='linux memtest.bin' + */ + + char *argument = (char*)argv[i]+10; + /* Extracting the first parameter */ + strcpy(hardware->postexec, argument); + + /* While we can't find the other AUTO_DELIMITER, let's process the argv[] */ + while ((strchr(argument, AUTO_DELIMITER) == NULL) && (i+1<argc)) { + i++; + argument = (char *)argv[i]; + strcat(hardware->postexec, " "); + strcat(hardware->postexec, argument); + } + + hardware->postexec[strlen(hardware->postexec) - 1] = 0; } else if (!strncmp(argv[i], "auto=", 5)) { /* The auto= parameter is separated in several argv[] * as it can contains spaces. @@ -115,25 +150,19 @@ void detect_parameters(const int argc, const char *argv[], */ automode=true; + char *argument = (char*)argv[i]+6; /* Extracting the first parameter */ - strcpy(hardware->auto_label, argv[i] + 6); - strcat(hardware->auto_label, " "); - char *pos; - i++; + strcpy(hardware->auto_label, argument); /* While we can't find the other AUTO_DELIMITER, let's process the argv[] */ - while (((pos = strstr(argv[i], AUTO_DELIMITER)) == NULL) - && (i < argc)) { - strcat(hardware->auto_label, argv[i]); - strcat(hardware->auto_label, " "); + while ((strchr(argument, AUTO_DELIMITER) == NULL) && (i+1<argc)) { i++; - } + argument = (char *)argv[i]; + strcat(hardware->auto_label, " "); + strcat(hardware->auto_label, argument); + } - /* If we didn't reach the end of the line, let's grab the last item */ - if (i < argc) { - strcat(hardware->auto_label, argv[i]); - hardware->auto_label[strlen(hardware->auto_label) - 1] = 0; - } + hardware->auto_label[strlen(hardware->auto_label) - 1] = 0; } } } @@ -203,7 +232,13 @@ void init_hardware(struct s_hardware *hardware) sizeof hardware->modules_alias_path); memset(hardware->memtest_label, 0, sizeof hardware->memtest_label); memset(hardware->auto_label, 0, sizeof hardware->auto_label); + memset(hardware->dump_path, 0, sizeof hardware->dump_path); + memset(hardware->dump_filename, 0, sizeof hardware->dump_filename); memset(hardware->vesa_background, 0, sizeof hardware->vesa_background); + memset(hardware->tftp_ip, 0, sizeof hardware->tftp_ip); + memset(hardware->postexec, 0, sizeof hardware->postexec); + strcat(hardware->dump_path, "hdt"); + strcat(hardware->dump_filename, "%{m}+%{p}+%{v}"); strcat(hardware->pciids_path, "pci.ids"); strcat(hardware->modules_pcimap_path, "modules.pcimap"); strcat(hardware->modules_alias_path, "modules.alias"); @@ -652,7 +687,7 @@ char *del_multi_spaces(char *p) * As we search for a double spacing * we have to be sure then string is * long enough to be processed */ - while (*p && *p + 1) { + while (*p && *(p + 1)) { /* If we have two consecutive spaces */ if ((*p == ' ') && (*(p + 1) == ' ')) { @@ -709,8 +744,8 @@ void detect_hardware(struct s_hardware *hardware) if (!quiet) more_printf("DMI: Detecting Table\n"); if (detect_dmi(hardware) == -ENODMITABLE) { - printf("DMI: ERROR ! Table not found ! \n"); - printf("DMI: Many hardware components will not be detected ! \n"); + more_printf("DMI: ERROR ! Table not found ! \n"); + more_printf("DMI: Many hardware components will not be detected ! \n"); } else { if (!quiet) more_printf("DMI: Table found ! (version %u.%u)\n", diff --git a/com32/hdt/hdt-common.h b/com32/hdt/hdt-common.h index df7d2c98..c2299b48 100644 --- a/com32/hdt/hdt-common.h +++ b/com32/hdt/hdt-common.h @@ -48,16 +48,18 @@ #include "cpuid.h" #include "dmi/dmi.h" #include "hdt-ata.h" -#include "../lib/sys/vesa/vesa.h" +#include <lib/sys/vesa/vesa.h> #include <vpd/vpd.h> #include <libansi.h> #include <acpi/acpi.h> +#include <libupload/upload_backend.h> /* Declare a variable or data structure as unused. */ #define __unused __attribute__ (( unused )) /* This two values are used for switching for the menu to the CLI mode */ #define HDT_SWITCH_TO_CLI "hdt_switch_to_cli" +#define HDT_DUMP "hdt_dump" #define HDT_RETURN_TO_CLI 100 #define MAX_VESA_MODES 255 @@ -71,7 +73,7 @@ /* The char that separate two commands */ #define AUTO_SEPARATOR ";" /* The char that surround the list of commands */ -#define AUTO_DELIMITER "'" +#define AUTO_DELIMITER '\'' /* Graphic to load in background when using the vesa mode */ #define CLI_DEFAULT_BACKGROUND "backgnd.png" @@ -80,9 +82,14 @@ #define MAX_CLI_LINES 20 #define MAX_VESA_CLI_LINES 24 +struct upload_backend *upload; + /* Defines if the cli is quiet*/ bool quiet; +/* Defines if the cli is totally silent*/ +bool silent; + /* Defines if we must use the vesa mode */ bool vesamode; @@ -110,16 +117,18 @@ extern bool disable_more_printf; * one \n (and only one) */ #define more_printf(...) do {\ - if (__likely(!disable_more_printf)) {\ - if (display_line_nb == max_console_lines) {\ - display_line_nb=0;\ - printf("\n--More--");\ - get_key(stdin, 0);\ - printf("\033[2K\033[1G\033[1F");\ + if (__likely(!silent)) {\ + if (__likely(!disable_more_printf)) {\ + if (display_line_nb == max_console_lines) {\ + display_line_nb=0;\ + printf("\n--More--");\ + get_key(stdin, 0);\ + printf("\033[2K\033[1G\033[1F");\ + }\ + display_line_nb++;\ }\ - display_line_nb++;\ + printf(__VA_ARGS__);\ }\ - printf(__VA_ARGS__);\ } while (0); /* Display CPU registers for debugging purposes */ @@ -209,9 +218,13 @@ struct s_hardware { char modules_pcimap_path[255]; char modules_alias_path[255]; char pciids_path[255]; + char dump_path[255]; /* Dump path on the tftp server */ + char dump_filename[255]; /* Dump filename on the tftp server */ + char tftp_ip[255]; /* IP address of tftp server (dump mode) */ char memtest_label[255]; char auto_label[AUTO_COMMAND_SIZE]; char vesa_background[255]; + char postexec[255]; }; void reset_more_printf(void); @@ -236,4 +249,5 @@ int detect_vesa(struct s_hardware *hardware); void detect_memory(struct s_hardware *hardware); void init_console(struct s_hardware *hardware); void detect_hardware(struct s_hardware *hardware); +void dump(struct s_hardware *hardware); #endif diff --git a/com32/hdt/hdt-dump-acpi.c b/com32/hdt/hdt-dump-acpi.c new file mode 100644 index 00000000..4cbaf66f --- /dev/null +++ b/com32/hdt/hdt-dump-acpi.c @@ -0,0 +1,600 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2011 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-common.h" +#include "hdt-dump.h" + +void show_header(char *name, void *address, s_acpi_description_header *h, ZZJSON_CONFIG *config, ZZJSON **item) +{ + char signature[10]={0}; + char revision[10]={0}; + char s_address[16]={0}; + char oem_id[16]={0}; + char oem_table_id[16]={0}; + char oem_revision[16]={0}; + char creator_revision[16]={0}; + char creator_id[16]={0}; + snprintf(signature,sizeof(signature),"%s",h->signature); + snprintf(revision,sizeof(revision),"0x%03x",h->revision); + snprintf(oem_id,sizeof(oem_id),"%s",h->oem_id); + snprintf(oem_table_id,sizeof(oem_table_id),"%s",h->oem_table_id); + snprintf(creator_id,sizeof(creator_id),"%s",h->creator_id); + snprintf(oem_revision,sizeof(oem_revision),"0x%08x",h->oem_revision); + snprintf(creator_revision,sizeof(creator_revision),"0x%08x",h->creator_revision); + snprintf(s_address,sizeof(s_address),"%p",address); + + char address_name[32]={0}; + char signature_name[32]={0}; + char revision_name[32]={0}; + char oem_id_name[32]={0}; + char oem_table_id_name[32]={0}; + char oem_revision_name[32]={0}; + char creator_revision_name[32]={0}; + char creator_id_name[32]={0}; + snprintf(signature_name,sizeof(signature_name),"acpi.%s.signature",name); + snprintf(revision_name,sizeof(revision_name),"acpi.%s.revision",name); + snprintf(address_name,sizeof(address_name),"acpi.%s.address",name); + snprintf(oem_id_name,sizeof(oem_id_name),"acpi.%s.oem_id",name); + snprintf(oem_table_id_name,sizeof(oem_table_id_name),"acpi.%s.oem_table_id",name); + snprintf(oem_revision_name,sizeof(oem_revision_name),"acpi.%s.oem_revision",name); + snprintf(creator_revision_name,sizeof(creator_revision_name),"acpi.%s.creator_revision",name); + snprintf(creator_id_name,sizeof(creator_id_name),"acpi.%s.creator_id",name); + + APPEND_ARRAY + add_as(signature_name,signature) + add_as(revision_name,revision) + add_as(oem_id_name,oem_id) + add_as(oem_table_id_name,oem_table_id) + add_as(oem_revision_name,oem_revision) + add_as(creator_id_name,creator_id) + add_as(creator_revision_name,creator_revision) + add_as(address_name,s_address) + END_OF_APPEND; + + FLUSH_OBJECT; + +} + +void dump_rsdt(s_acpi * acpi, ZZJSON_CONFIG * config, ZZJSON ** item) +{ + char valid[8]={0}; + snprintf(valid,sizeof(valid),"%s","false"); + if (acpi->rsdt.valid) { + snprintf(valid,sizeof(valid),"%s","true"); + } + CREATE_ARRAY + add_as("acpi.item","rsdt") + add_as("acpi.rsdt.is_valid",valid) + END_OF_ARRAY; + + if (acpi->rsdt.valid==false) { + FLUSH_OBJECT; + return; + } + + show_header("rsdt",acpi->rsdt.address, &acpi->rsdt.header, config, item); +} + +void dump_xsdt(s_acpi * acpi, ZZJSON_CONFIG * config, ZZJSON ** item) +{ + char valid[8]={0}; + snprintf(valid,sizeof(valid),"%s","false"); + if (acpi->xsdt.valid) { + snprintf(valid,sizeof(valid),"%s","true"); + } + CREATE_ARRAY + add_as("acpi.item","xsdt") + add_as("acpi.xsdt.is_valid",valid) + END_OF_ARRAY; + + if (acpi->xsdt.valid==false) { + FLUSH_OBJECT; + return; + } + + show_header("xsdt",acpi->xsdt.address, &acpi->xsdt.header, config, item); +} + +void dump_fadt(s_acpi * acpi, ZZJSON_CONFIG * config, ZZJSON ** item) +{ + char valid[8]={0}; + snprintf(valid,sizeof(valid),"%s","false"); + if (acpi->rsdt.valid) { + snprintf(valid,sizeof(valid),"%s","true"); + } + CREATE_ARRAY + add_as("acpi.item","fadt") + add_as("acpi.fadt.is_valid",valid) + END_OF_ARRAY; + + if (acpi->fadt.valid==false) { + FLUSH_OBJECT; + return; + } + + show_header("fadt",acpi->fadt.address, &acpi->fadt.header, config, item); +} + +void dump_dsdt(s_acpi * acpi, ZZJSON_CONFIG * config, ZZJSON ** item) +{ + char valid[8]={0}; + snprintf(valid,sizeof(valid),"%s","false"); + if (acpi->dsdt.valid) { + snprintf(valid,sizeof(valid),"%s","true"); + } + CREATE_ARRAY + add_as("acpi.item","dsdt") + add_as("acpi.dsdt.is_valid",valid) + END_OF_ARRAY; + + if (acpi->dsdt.valid==false) { + FLUSH_OBJECT; + return; + } + + show_header("dsdt",acpi->dsdt.address, &acpi->dsdt.header, config, item); +} + +void dump_sbst(s_acpi * acpi, ZZJSON_CONFIG * config, ZZJSON ** item) +{ + char valid[8]={0}; + snprintf(valid,sizeof(valid),"%s","false"); + if (acpi->sbst.valid) { + snprintf(valid,sizeof(valid),"%s","true"); + } + CREATE_ARRAY + add_as("acpi.item","sbst") + add_as("acpi.sbst.is_valid",valid) + END_OF_ARRAY; + + if (acpi->sbst.valid==false) { + FLUSH_OBJECT; + return; + } + + show_header("sbst",acpi->sbst.address, &acpi->sbst.header, config, item); +} + +void dump_ecdt(s_acpi * acpi, ZZJSON_CONFIG * config, ZZJSON ** item) +{ + char valid[8]={0}; + snprintf(valid,sizeof(valid),"%s","false"); + if (acpi->ecdt.valid) { + snprintf(valid,sizeof(valid),"%s","true"); + } + CREATE_ARRAY + add_as("acpi.item","ecdt") + add_as("acpi.ecdt.is_valid",valid) + END_OF_ARRAY; + + if (acpi->ecdt.valid==false) { + FLUSH_OBJECT; + return; + } + + show_header("ecdt",acpi->ecdt.address, &acpi->ecdt.header, config, item); +} + +void dump_hpet(s_acpi * acpi, ZZJSON_CONFIG * config, ZZJSON ** item) +{ + char valid[8]={0}; + snprintf(valid,sizeof(valid),"%s","false"); + if (acpi->hpet.valid) { + snprintf(valid,sizeof(valid),"%s","true"); + } + CREATE_ARRAY + add_as("acpi.item","hpet") + add_as("acpi.hpet.is_valid",valid) + END_OF_ARRAY; + + if (acpi->hpet.valid==false) { + FLUSH_OBJECT; + return; + } + + show_header("hpet",acpi->hpet.address, &acpi->hpet.header, config, item); +} + +void dump_tcpa(s_acpi * acpi, ZZJSON_CONFIG * config, ZZJSON ** item) +{ + char valid[8]={0}; + snprintf(valid,sizeof(valid),"%s","false"); + if (acpi->tcpa.valid) { + snprintf(valid,sizeof(valid),"%s","true"); + } + CREATE_ARRAY + add_as("acpi.item","tcpa") + add_as("acpi.tcpa.is_valid",valid) + END_OF_ARRAY; + + if (acpi->tcpa.valid==false) { + FLUSH_OBJECT; + return; + } + + show_header("tcpa",acpi->tcpa.address, &acpi->tcpa.header, config, item); +} + +void dump_mcfg(s_acpi * acpi, ZZJSON_CONFIG * config, ZZJSON ** item) +{ + char valid[8]={0}; + snprintf(valid,sizeof(valid),"%s","false"); + if (acpi->mcfg.valid) { + snprintf(valid,sizeof(valid),"%s","true"); + } + CREATE_ARRAY + add_as("acpi.item","mcfg") + add_as("acpi.mcfg.is_valid",valid) + END_OF_ARRAY; + + if (acpi->mcfg.valid==false) { + FLUSH_OBJECT; + return; + } + + show_header("mcfg",acpi->mcfg.address, &acpi->mcfg.header, config, item); +} + +void dump_slic(s_acpi * acpi, ZZJSON_CONFIG * config, ZZJSON ** item) +{ + char valid[8]={0}; + snprintf(valid,sizeof(valid),"%s","false"); + if (acpi->slic.valid) { + snprintf(valid,sizeof(valid),"%s","true"); + } + CREATE_ARRAY + add_as("acpi.item","slic") + add_as("acpi.slic.is_valid",valid) + END_OF_ARRAY; + + if (acpi->slic.valid==false) { + FLUSH_OBJECT; + return; + } + + show_header("slic",acpi->slic.address, &acpi->slic.header, config, item); +} + + +void dump_boot(s_acpi * acpi, ZZJSON_CONFIG * config, ZZJSON ** item) +{ + char valid[8]={0}; + snprintf(valid,sizeof(valid),"%s","false"); + if (acpi->boot.valid) { + snprintf(valid,sizeof(valid),"%s","true"); + } + CREATE_ARRAY + add_as("acpi.item","boot") + add_as("acpi.boot.is_valid",valid) + END_OF_ARRAY; + + if (acpi->boot.valid==false) { + FLUSH_OBJECT; + return; + } + + show_header("boot",acpi->boot.address, &acpi->boot.header, config, item); +} + +void dump_madt(s_acpi * acpi, ZZJSON_CONFIG * config, ZZJSON ** item) +{ + char valid[8]={0}; + snprintf(valid,sizeof(valid),"%s","false"); + if (acpi->madt.valid) { + snprintf(valid,sizeof(valid),"%s","true"); + } + CREATE_ARRAY + add_as("acpi.item","madt") + add_as("acpi.madt.is_valid",valid) + END_OF_ARRAY; + + if (acpi->madt.valid==false) { + FLUSH_OBJECT; + return; + } + + show_header("madt",acpi->madt.address, &acpi->madt.header, config, item); +} + +void dump_ssdt(s_ssdt *ssdt, ZZJSON_CONFIG * config, ZZJSON ** item) +{ + char valid[8]={0}; + snprintf(valid,sizeof(valid),"%s","false"); + if (ssdt->valid) { + snprintf(valid,sizeof(valid),"%s","true"); + } + CREATE_ARRAY + add_as("acpi.item","ssdt") + add_as("acpi.ssdt.is_valid",valid) + END_OF_ARRAY; + + if (ssdt->valid==false) { + FLUSH_OBJECT; + return; + } + + show_header("ssdt",ssdt->address, &ssdt->header, config, item); +} + +void dump_rsdp(s_acpi * acpi, ZZJSON_CONFIG * config, ZZJSON ** item) +{ + char valid[8]={0}; + snprintf(valid,sizeof(valid),"%s","false"); + if (acpi->rsdp.valid) { + snprintf(valid,sizeof(valid),"%s","true"); + } + CREATE_ARRAY + add_as("acpi.item","rsdp") + add_as("acpi.rsdp.is_valid",valid) + END_OF_ARRAY; + + if (acpi->rsdp.valid==false) { + FLUSH_OBJECT; + return; + } + + s_rsdp *r = &acpi->rsdp; + char revision[10]={0}; + char address[16]={0}; + char oem_id[16]={0}; + snprintf(revision,sizeof(revision),"0x%03x",r->revision); + snprintf(address,sizeof(address),"%p",r->address); + snprintf(oem_id,sizeof(oem_id),"%s",r->oem_id); + APPEND_ARRAY + add_as("acpi.rsdp.revision",revision) + add_as("acpi.rsdp.oem_id",oem_id) + add_as("acpi.rsdp.address",address) + END_OF_APPEND; + + FLUSH_OBJECT; + +} + +void dump_facs(s_acpi * acpi, ZZJSON_CONFIG * config, ZZJSON ** item) +{ + char valid[8]={0}; + snprintf(valid,sizeof(valid),"%s","false"); + if (acpi->facs.valid) { + snprintf(valid,sizeof(valid),"%s","true"); + } + CREATE_ARRAY + add_as("acpi.item","facs") + add_as("acpi.facs.is_valid",valid) + END_OF_ARRAY; + + if (acpi->facs.valid==false) { + FLUSH_OBJECT; + return; + } + + s_facs *fa = &acpi->facs; + char address[16]={0}; + snprintf(address,sizeof(address),"%p",fa->address); + APPEND_ARRAY + add_as("acpi.facs.address",address) + END_OF_APPEND; + + FLUSH_OBJECT; + +} + +void dump_interrupt_source_override(s_madt * madt, ZZJSON_CONFIG * config, ZZJSON ** item) +{ + CREATE_ARRAY + add_as("acpi.item","interrupt_source_override") + add_ai("acpi.interrupt_source_override.count", madt->interrupt_source_override_count) + END_OF_ARRAY; + + if (madt->interrupt_source_override_count == 0) { + FLUSH_OBJECT; + return; + } + + /* Let's process each interrupt source override */ + for (int i = 0; i < madt->interrupt_source_override_count; i++) { + s_interrupt_source_override *siso = &madt->interrupt_source_override[i]; + char buffer[20] = {0}; + char bus_type[10]= {0}; + + /* Spec report bus type 0 as ISA */ + if (siso->bus == 0) + strcpy(bus_type, "ISA"); + else + strcpy(bus_type, "unknown"); + + APPEND_ARRAY + add_as("acpi.interrupt_source_override.bus_type",bus_type) + add_ai("acpi.interrupt_source_override.bus",siso->bus) + add_ai("acpi.interrupt_source_override.bus_irq",siso->source) + add_ai("acpi.interrupt_source_override.global_irq",siso->global_system_interrupt) + add_as("acpi.interrupt_source_override.flags",flags_to_string(buffer,siso->flags)) + END_OF_APPEND; + } + FLUSH_OBJECT; +} + +void dump_io_apic(s_madt * madt, ZZJSON_CONFIG * config, ZZJSON ** item) +{ + CREATE_ARRAY + add_as("acpi.item","io_apic") + add_ai("acpi.io_apic.count", madt->io_apic_count) + END_OF_ARRAY; + + if (madt->io_apic_count == 0) { + FLUSH_OBJECT; + return; + } + + /* For all IO APICS */ + for (int i = 0; i < madt->io_apic_count; i++) { + s_io_apic *sio = &madt->io_apic[i]; + char buffer[15]={0}; + memset(buffer, 0, sizeof(buffer)); + /* GSI base reports the GSI configuration + * Let's interpret it as string */ + switch (sio->global_system_interrupt_base) { + case 0: + strcpy(buffer, "0-23"); + break; + case 24: + strcpy(buffer,"24-39"); + break; + case 40: + strcpy(buffer, "40-55"); + break; + default: + strcpy(buffer,"Unknown"); + break; + } + + char apic_id[16] = { 0 }; + char address[16] = { 0 }; + snprintf(apic_id,sizeof(apic_id),"0x%02x",sio->io_apic_id); + snprintf(address,sizeof(address),"0x%08x",sio->io_apic_address); + APPEND_ARRAY + add_ai("acpi.io_apic.number",i) + add_as("acpi.io_apic.apic_id",apic_id) + add_as("acpi.io_apic.adress",address) + add_as("acpi.io_apic.gsi",buffer) + END_OF_APPEND; + } + FLUSH_OBJECT; +} + +void dump_local_apic_nmi(s_madt * madt, ZZJSON_CONFIG * config, ZZJSON ** item) +{ + CREATE_ARRAY + add_as("acpi.item","local_apic_nmi") + add_ai("acpi.local_apic_nmi.count", madt->local_apic_nmi_count) + END_OF_ARRAY; + + if (madt->local_apic_nmi_count == 0) { + FLUSH_OBJECT; + return; + } + + for (int i = 0; i < madt->local_apic_nmi_count; i++) { + s_local_apic_nmi *slan = &madt->local_apic_nmi[i]; + char buffer[20]={0}; + char acpi_id[16] = { 0 }; + char local_apic_lint[16] = { 0 }; + snprintf(acpi_id, sizeof(acpi_id), "0x%02x", slan->acpi_processor_id); + snprintf(local_apic_lint, sizeof(local_apic_lint), "0x%02x", slan->local_apic_lint); + APPEND_ARRAY + add_as("acpi.processor_id", acpi_id) + add_as("acpi.local_apic_nmi.flags", flags_to_string(buffer,slan->flags)) + add_as("acpi.local_apic_nmi.lint",local_apic_lint) + END_OF_APPEND; + } + + FLUSH_OBJECT; +} + +void dump_local_apic(s_madt * madt, ZZJSON_CONFIG * config, ZZJSON ** item) +{ + char buffer[16] = { 0 }; + snprintf(buffer, sizeof(buffer), "0x%08x", madt->local_apic_address); + + CREATE_ARRAY + add_as("acpi.item","local_apic") + add_as("acpi.local_apic.address", buffer) + add_ai("acpi.processor_local_apic.count", madt->processor_local_apic_count) + END_OF_ARRAY; + + if (madt->processor_local_apic_count ==0) { + FLUSH_OBJECT; + return; + } + + /* For all detected logical CPU */ + for (int i = 0; i < madt->processor_local_apic_count; i++) { + s_processor_local_apic *sla = &madt->processor_local_apic[i]; + char lapic_status[16] = { 0 }; + char acpi_id[16] = { 0 }; + char apic_id[16] = { 0 }; + + snprintf(lapic_status,sizeof(lapic_status),"%s","disabled"); + /* Let's check if the flags reports the cpu as enabled */ + if ((sla->flags & PROCESSOR_LOCAL_APIC_ENABLE) == + PROCESSOR_LOCAL_APIC_ENABLE) + snprintf(lapic_status,sizeof(lapic_status),"%s","enabled"); + snprintf(acpi_id, sizeof(acpi_id), "0x%02x", sla->acpi_id); + snprintf(apic_id, sizeof(apic_id), "0x%02x", sla->apic_id); + APPEND_ARRAY + add_ai("acpi.cpu.apic_id", sla->apic_id) + add_as("acpi.cpu.apic_id (hex)", apic_id) + add_as("acpi.cpu.acpi_id (hex)", acpi_id) + add_as("acpi.lapic.enabled", lapic_status) + END_OF_APPEND; + } + FLUSH_OBJECT; +} + +void dump_acpi(struct s_hardware *hardware, ZZJSON_CONFIG * config, + ZZJSON ** item) +{ + CREATE_NEW_OBJECT; + add_hb(is_acpi_valid); + if (hardware->is_acpi_valid == false) + goto exit; + + s_madt *madt = &hardware->acpi.madt; + add_b("acpi.apic.detected", madt->valid); + if (madt->valid == false) { + goto exit; + } + + FLUSH_OBJECT; + + dump_local_apic(madt, config, item); + dump_local_apic_nmi(madt, config, item); + dump_io_apic(madt, config, item); + dump_interrupt_source_override(madt, config, item); + + dump_rsdp(&hardware->acpi,config,item); + dump_rsdt(&hardware->acpi,config,item); + dump_xsdt(&hardware->acpi,config,item); + dump_fadt(&hardware->acpi,config,item); + dump_dsdt(&hardware->acpi,config,item); + dump_sbst(&hardware->acpi,config,item); + dump_ecdt(&hardware->acpi,config,item); + dump_hpet(&hardware->acpi,config,item); + dump_tcpa(&hardware->acpi,config,item); + dump_mcfg(&hardware->acpi,config,item); + dump_slic(&hardware->acpi,config,item); + dump_boot(&hardware->acpi,config,item); + dump_madt(&hardware->acpi,config,item); + for (int i = 0; i < hardware->acpi.ssdt_count; i++) { + if ((hardware->acpi.ssdt[i] != NULL) && (hardware->acpi.ssdt[i]->valid)) + dump_ssdt(hardware->acpi.ssdt[i], config, item); + } + dump_facs(&hardware->acpi,config,item); + +exit: + to_cpio("acpi"); +} diff --git a/com32/hdt/hdt-dump-cpu.c b/com32/hdt/hdt-dump-cpu.c new file mode 100644 index 00000000..33d561c8 --- /dev/null +++ b/com32/hdt/hdt-dump-cpu.c @@ -0,0 +1,53 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2011 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-common.h" +#include "hdt-dump.h" + +void dump_cpu(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + + CREATE_NEW_OBJECT; + add_hs(cpu.vendor); + add_hs(cpu.model); + add_hi(cpu.vendor_id); + add_hi(cpu.family); + add_hi(cpu.model_id); + add_hi(cpu.stepping); + add_hi(cpu.num_cores); + add_hi(cpu.l1_data_cache_size); + add_hi(cpu.l1_instruction_cache_size); + add_hi(cpu.l2_cache_size); + size_t i; + for (i = 0; i < cpu_flags_count; i++) { + char temp[128]={0}; + snprintf(temp,sizeof(temp),"cpu.flags.%s",cpu_flags_names[i]); + add_b(temp,get_cpu_flag_value_from_name(&hardware->cpu,cpu_flags_names[i])); + } + FLUSH_OBJECT; + to_cpio("cpu"); +} diff --git a/com32/hdt/hdt-dump-disks.c b/com32/hdt/hdt-dump-disks.c new file mode 100644 index 00000000..ff744b30 --- /dev/null +++ b/com32/hdt/hdt-dump-disks.c @@ -0,0 +1,145 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2011 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-common.h" +#include "hdt-dump.h" +#include "hdt-util.h" + +ZZJSON_CONFIG *config; +ZZJSON **item; + +static void show_partition_information(struct driveinfo *drive_info, + struct part_entry *ptab, + int partition_offset, + int nb_partitions_seen) { + char size[11] = {0}; + char bootloader_name[9] = {0}; + char ostype[64]={0}; + char *parttype; + unsigned int start, end; + char bootable[6] = {0}; + + int i = nb_partitions_seen; + start = partition_offset; + end = start + ptab->length - 1; + + if (ptab->length > 0) + sectors_to_size(ptab->length, size); + + get_label(ptab->ostype, &parttype); + get_bootloader_string(drive_info, ptab, bootloader_name, 9); + if (ptab->active_flag == 0x80) + snprintf(bootable,sizeof(bootable),"%s","true"); + else + snprintf(bootable,sizeof(bootable),"%s","false"); + + snprintf(ostype,sizeof(ostype),"%02X",ptab->ostype); + + APPEND_ARRAY + add_ai("partition->number",i) + add_ai("partition->sector_start",start) + add_ai("partition->sector_end",end) + add_as("partition->size",size) + add_as("partition->type",parttype) + add_as("partition->os_type",ostype) + add_as("partition->boot_flag",bootable) + END_OF_APPEND; + free(parttype); +} + + + +void show_disk(struct s_hardware *hardware, ZZJSON_CONFIG *conf, ZZJSON **it, int drive) { + config=conf; + item=it; + int i = drive - 0x80; + struct driveinfo *d = &hardware->disk_info[i]; + char mbr_name[50]={0}; + char disk_size[11]={0}; + + get_mbr_string(hardware->mbr_ids[i], &mbr_name,sizeof(mbr_name)); + if ((int)d->edd_params.sectors > 0) + sectors_to_size((int)d->edd_params.sectors, disk_size); + + char disk[5]={0}; + char edd_version[5]={0}; + snprintf(disk,sizeof(disk),"0x%X",d->disk); + snprintf(edd_version,sizeof(edd_version),"%X",d->edd_version); + zzjson_print(config, *item); + zzjson_free(config, *item); + + CREATE_ARRAY + add_as("disk->number",disk) + add_ai("disk->cylinders",d->legacy_max_cylinder +1) + add_ai("disk->heads",d->legacy_max_head +1) + add_ai("disk->sectors_per_track",d->legacy_sectors_per_track) + add_as("disk->edd_version",edd_version) + add_as("disk->size",disk_size) + add_ai("disk->bytes_per_sector",(int)d->edd_params.bytes_per_sector) + add_ai("disk->sectors_per_track",(int)d->edd_params.sectors_per_track) + add_as("disk->host_bus",remove_spaces((char *)d->edd_params.host_bus_type)) + add_as("disk->interface_type",remove_spaces((char *)d->edd_params.interface_type)) + add_as("disk->mbr_name",mbr_name) + add_ai("disk->mbr_id",hardware->mbr_ids[i]) + END_OF_ARRAY; + + if (parse_partition_table(d, &show_partition_information)) { + if (errno_disk) { + APPEND_ARRAY + add_as("disk->error", "IO Error") + END_OF_APPEND; + } else { + APPEND_ARRAY + add_as("disk->error", "Unrecognized Partition Layout") + END_OF_APPEND; + } + } +} + +void dump_disks(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + bool found=false; + + if (hardware->disks_count > 0) + for (int drive = 0x80; drive < 0xff; drive++) { + if (hardware->disk_info[drive - 0x80].cbios) { + if (found==false) { + CREATE_NEW_OBJECT; + add_b("disks->is_valid",true); + found=true; + } + show_disk(hardware, config, item, drive); + } + } + + if (found==false) { + CREATE_NEW_OBJECT; + add_b("disks->is_valid",false); + } + FLUSH_OBJECT; + to_cpio("disks"); +} diff --git a/com32/hdt/hdt-dump-dmi.c b/com32/hdt/hdt-dump-dmi.c new file mode 100644 index 00000000..6e5c1ce8 --- /dev/null +++ b/com32/hdt/hdt-dump-dmi.c @@ -0,0 +1,447 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2011 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-common.h" +#include "hdt-dump.h" + +void dump_hardware_security(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + if (!hardware->dmi.hardware_security.filled) { + CREATE_NEW_OBJECT; + add_s("dmi.warning","No hardware security structure found"); + FLUSH_OBJECT; + return; + } + + CREATE_NEW_OBJECT; + add_s("dmi.item","hardware_security"); + add_hs(dmi.hardware_security.power_on_passwd_status); + add_hs(dmi.hardware_security.keyboard_passwd_status); + add_hs(dmi.hardware_security.administrator_passwd_status); + add_hs(dmi.hardware_security.front_panel_reset_status); + FLUSH_OBJECT; +} + +void dump_oem_strings(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + if (strlen(hardware->dmi.oem_strings) == 0) { + CREATE_NEW_OBJECT; + add_s("dmi.warning","No OEM structure found"); + FLUSH_OBJECT; + return; + } + CREATE_NEW_OBJECT; + add_s("dmi.item","OEM"); + add_hs(dmi.oem_strings); + FLUSH_OBJECT; +} + +void dump_memory_size(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + CREATE_NEW_OBJECT; + add_s("dmi.item","memory size"); + add_i("dmi.memory_size (KB)",hardware->detected_memory_size); + add_i("dmi.memory_size (MB)",(hardware->detected_memory_size + (1 << 9)) >> 10); + FLUSH_OBJECT; +} + +void dump_memory_modules(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + + if (hardware->dmi.memory_module_count == 0) { + CREATE_NEW_OBJECT; + add_s("dmi.warning","No memory module structure found"); + FLUSH_OBJECT; + return; + } + + for (int module=0; module<hardware->dmi.memory_module_count;module++) { + if (hardware->dmi.memory_module[module].filled == false) { + char msg[64]={0}; + snprintf(msg,sizeof(msg),"Module %d doesn't contain any information", module); + + CREATE_NEW_OBJECT; + add_s("dmi.warning",msg); + FLUSH_OBJECT; + continue; + } + + CREATE_NEW_OBJECT; + add_i("Memory module", module); + add_s("dmi.memory_module.socket_designation", hardware->dmi.memory_module[module].socket_designation); + add_s("dmi.memory_module.bank_connections", hardware->dmi.memory_module[module].bank_connections); + add_s("dmi.memory_module.speed", hardware->dmi.memory_module[module].speed); + add_s("dmi.memory_module.type", hardware->dmi.memory_module[module].type); + add_s("dmi.memory_module.installed_size", hardware->dmi.memory_module[module].installed_size); + add_s("dmi.memory_module.enabled_size", hardware->dmi.memory_module[module].enabled_size); + add_s("dmi.memory_module.error_status", hardware->dmi.memory_module[module].error_status); + FLUSH_OBJECT; + } +} + +void dump_cache(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + + if (hardware->dmi.cache_count == 0) { + CREATE_NEW_OBJECT; + add_s("dmi.warning","No cache structure found"); + FLUSH_OBJECT; + return; + } + + for (int cache=0; cache<hardware->dmi.cache_count;cache++) { + CREATE_NEW_OBJECT; + add_i("Cache", cache); + add_s("dmi.cache.socket_designation", hardware->dmi.cache[cache].socket_designation); + add_s("dmi.cache.configuration", hardware->dmi.cache[cache].configuration); + add_s("dmi.cache.mode", hardware->dmi.cache[cache].mode); + add_s("dmi.cache.location", hardware->dmi.cache[cache].location); + add_i("dmi.cache.installed_size (KB)", hardware->dmi.cache[cache].installed_size); + add_i("dmi.cache.max_size (KB)", hardware->dmi.cache[cache].max_size); + add_s("dmi.cache.supported_sram_types", hardware->dmi.cache[cache].supported_sram_types); + add_s("dmi.cache.installed_sram_types", hardware->dmi.cache[cache].installed_sram_types); + add_i("dmi.cache.speed (ns)", hardware->dmi.cache[cache].speed); + add_s("dmi.cache.error_correction_type", hardware->dmi.cache[cache].error_correction_type); + add_s("dmi.cache.system_type", hardware->dmi.cache[cache].system_type); + add_s("dmi.cache.associativity", hardware->dmi.cache[cache].associativity); + FLUSH_OBJECT; + } +} +void dump_memory_banks(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + + if (hardware->dmi.memory_count == 0) { + CREATE_NEW_OBJECT; + add_s("dmi.warning","No memory bank structure found"); + FLUSH_OBJECT; + return; + } + + for (int bank=0; bank<hardware->dmi.memory_count;bank++) { + + if (hardware->dmi.memory[bank].filled == false) { + char msg[64]={0}; + snprintf(msg,sizeof(msg),"Bank %d doesn't contain any information", bank); + + CREATE_NEW_OBJECT; + add_s("dmi.warning",msg); + FLUSH_OBJECT; + continue; + } + + CREATE_NEW_OBJECT; + add_i("Memory Bank", bank); + add_s("dmi.memory.form_factor", hardware->dmi.memory[bank].form_factor); + add_s("dmi.memory.type", hardware->dmi.memory[bank].type); + add_s("dmi.memory.type_detail", hardware->dmi.memory[bank].type_detail); + add_s("dmi.memory.speed", hardware->dmi.memory[bank].speed); + add_s("dmi.memory.size", hardware->dmi.memory[bank].size); + add_s("dmi.memory.device_set", hardware->dmi.memory[bank].device_set); + add_s("dmi.memory.device_locator", hardware->dmi.memory[bank].device_locator); + add_s("dmi.memory.bank_locator", hardware->dmi.memory[bank].bank_locator); + add_s("dmi.memory.total_width", hardware->dmi.memory[bank].total_width); + add_s("dmi.memory.data_width", hardware->dmi.memory[bank].data_width); + add_s("dmi.memory.error", hardware->dmi.memory[bank].error); + add_s("dmi.memory.vendor", hardware->dmi.memory[bank].manufacturer); + add_s("dmi.memory.serial", hardware->dmi.memory[bank].serial); + add_s("dmi.memory.asset_tag", hardware->dmi.memory[bank].asset_tag); + add_s("dmi.memory.part_number", hardware->dmi.memory[bank].part_number); + FLUSH_OBJECT; + } +} + +void dump_processor(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + if (hardware->dmi.processor.filled == false) { + CREATE_NEW_OBJECT; + add_s("dmi.warning","no processor structure found"); + FLUSH_OBJECT; + return; + } + + char voltage[16]={0}; + snprintf(voltage,sizeof(voltage),"%d.%02d", + hardware->dmi.processor.voltage_mv / 1000, + hardware->dmi.processor.voltage_mv - ((hardware->dmi.processor.voltage_mv / 1000) * 1000)); + + CREATE_NEW_OBJECT; + add_s("dmi.item","processor"); + add_hs(dmi.processor.socket_designation); + add_hs(dmi.processor.type); + add_hs(dmi.processor.family); + add_hs(dmi.processor.manufacturer); + add_hs(dmi.processor.version); + add_hi(dmi.processor.external_clock); + add_hi(dmi.processor.max_speed); + add_hi(dmi.processor.current_speed); + add_hi(dmi.processor.signature.type); + add_hi(dmi.processor.signature.family); + add_hi(dmi.processor.signature.model); + add_hi(dmi.processor.signature.stepping); + add_hi(dmi.processor.signature.minor_stepping); + add_s("dmi.processor.voltage",voltage); + add_hs(dmi.processor.status); + add_hs(dmi.processor.upgrade); + add_hs(dmi.processor.cache1); + add_hs(dmi.processor.cache2); + add_hs(dmi.processor.cache3); + add_hs(dmi.processor.serial); + add_hs(dmi.processor.part_number); + add_hi(dmi.processor.core_count); + add_hi(dmi.processor.core_enabled); + add_hi(dmi.processor.thread_count); + add_hs(dmi.processor.id); + for (int i = 0; i < PROCESSOR_FLAGS_ELEMENTS; i++) { + if (((bool *) (&hardware->dmi.processor.cpu_flags))[i] == true) { + add_s("dmi.processor.flag",(char *)cpu_flags_strings[i]); + } + } + FLUSH_OBJECT; +} + +void dump_battery(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + if (hardware->dmi.battery.filled == false) { + CREATE_NEW_OBJECT; + add_s("dmi.warning","no battery structure found"); + FLUSH_OBJECT; + return; + } + + CREATE_NEW_OBJECT; + add_s("dmi.item","battery"); + add_hs(dmi.battery.manufacturer); + add_hs(dmi.battery.manufacture_date); + add_hs(dmi.battery.serial); + add_hs(dmi.battery.name); + add_hs(dmi.battery.chemistry); + add_hs(dmi.battery.design_capacity); + add_hs(dmi.battery.design_voltage); + add_hs(dmi.battery.sbds); + add_hs(dmi.battery.sbds_manufacture_date); + add_hs(dmi.battery.sbds_chemistry); + add_hs(dmi.battery.maximum_error); + add_hs(dmi.battery.oem_info); + FLUSH_OBJECT; +} + +void dump_ipmi(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + if (hardware->dmi.ipmi.filled == false) { + CREATE_NEW_OBJECT; + add_s("dmi.warning","no IPMI structure found"); + FLUSH_OBJECT; + return; + } + + char spec_ver[16]={0}; + char i2c[16]={0}; + char base[16]={0}; + snprintf(spec_ver,sizeof(spec_ver),"%u.%u", + hardware->dmi.ipmi.major_specification_version, + hardware->dmi.ipmi.minor_specification_version); + + snprintf(i2c,sizeof(i2c),"0x%02x", hardware->dmi.ipmi.I2C_slave_address); + snprintf(base,sizeof(base),"%08X%08X", + (uint32_t)(hardware->dmi.ipmi.base_address >> 32), + (uint32_t)((hardware->dmi.ipmi.base_address & 0xFFFF) & ~1)); + + CREATE_NEW_OBJECT; + add_s("dmi.item","ipmi"); + add_hs(dmi.ipmi.interface_type); + add_s("dmi.ipmi.spec_version",spec_ver); + add_hi(dmi.ipmi.I2C_slave_address); + add_hi(dmi.ipmi.nv_address); + add_s("dmi.ipmi.base_address",base); + add_hi(dmi.ipmi.irq); + FLUSH_OBJECT; +} + +void dump_chassis(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + if (hardware->dmi.chassis.filled == false) { + CREATE_NEW_OBJECT; + add_s("dmi.warning","no chassis structure found"); + FLUSH_OBJECT; + return; + } + + CREATE_NEW_OBJECT; + add_s("dmi.item","bios"); + add_hs(dmi.chassis.manufacturer); + add_hs(dmi.chassis.type); + add_hs(dmi.chassis.lock); + add_hs(dmi.chassis.version); + add_hs(dmi.chassis.serial); + add_s("dmi.chassis.asset_tag",del_multi_spaces(hardware->dmi.chassis.asset_tag)); + add_hs(dmi.chassis.boot_up_state); + add_hs(dmi.chassis.power_supply_state); + add_hs(dmi.chassis.thermal_state); + add_hs(dmi.chassis.security_status); + add_hs(dmi.chassis.oem_information); + add_hi(dmi.chassis.height); + add_hi(dmi.chassis.nb_power_cords); + FLUSH_OBJECT; +} + +void dump_bios(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + if (hardware->dmi.bios.filled == false) { + CREATE_NEW_OBJECT; + add_s("dmi.warning","no bios structure found"); + FLUSH_OBJECT; + return; + } + char address[16]={0}; + char runtime[16]={0}; + char rom[16]={0}; + snprintf(address,sizeof(address),"0x%04X0",hardware->dmi.bios.address); + snprintf(runtime,sizeof(runtime),"%u %s",hardware->dmi.bios.runtime_size, hardware->dmi.bios.runtime_size_unit); + snprintf(rom,sizeof(rom),"%u %s",hardware->dmi.bios.rom_size, hardware->dmi.bios.rom_size_unit); + + CREATE_NEW_OBJECT; + add_s("dmi.item","bios"); + add_hs(dmi.bios.vendor); + add_hs(dmi.bios.version); + add_hs(dmi.bios.release_date); + add_hs(dmi.bios.bios_revision); + add_hs(dmi.bios.firmware_revision); + add_s("dmi.bios.address",address); + add_s("dmi.bios.runtime_size",runtime); + add_s("dmi.bios.rom_size",rom); + for (int i = 0; i < BIOS_CHAR_NB_ELEMENTS; i++) { + if (((bool *) (&hardware->dmi.bios.characteristics))[i] == true) { + add_s("dmi.bios.characteristics",(char *)bios_charac_strings[i]); + } + } + + for (int i = 0; i < BIOS_CHAR_X1_NB_ELEMENTS; i++) { + if (((bool *) (&hardware->dmi.bios.characteristics_x1))[i] == true) { + add_s("dmi.bios.characteristics",(char *)bios_charac_x1_strings[i]); + } + } + + for (int i = 0; i < BIOS_CHAR_X2_NB_ELEMENTS; i++) { + if (((bool *) (&hardware->dmi.bios.characteristics_x2))[i] == true) { + add_s("dmi.bios.characteristics",(char *)bios_charac_x2_strings[i]); + } + } + FLUSH_OBJECT; +} + +void dump_system(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + + if (hardware->dmi.system.filled == false) { + CREATE_NEW_OBJECT; + add_s("dmi.warning","no system structure found"); + FLUSH_OBJECT; + return; + } + char system_reset_status[10]={0}; + char watchdog_timer[15]={0}; + snprintf(system_reset_status,sizeof(system_reset_status),"%s", (hardware->dmi.system.system_reset.status ? "Enabled" :"Disabled")); + snprintf(watchdog_timer,sizeof(watchdog_timer),"%s", (hardware->dmi.system.system_reset.watchdog ? "Present" :"Not Present")); + + CREATE_NEW_OBJECT; + add_s("dmi.item","system"); + add_hs(dmi.system.manufacturer); + add_hs(dmi.system.product_name); + add_hs(dmi.system.version); + add_hs(dmi.system.serial); + add_hs(dmi.system.uuid); + add_hs(dmi.system.wakeup_type); + add_hs(dmi.system.sku_number); + add_hs(dmi.system.family); + add_hs(dmi.system.configuration_options); + add_s("dmi.system.system_reset.status",system_reset_status); + add_s("dmi.system.system_reset.watchdog",watchdog_timer); + add_hs(dmi.system.system_reset.boot_option); + add_hs(dmi.system.system_reset.boot_option_on_limit); + add_hs(dmi.system.system_reset.reset_count); + add_hs(dmi.system.system_reset.reset_limit); + add_hs(dmi.system.system_reset.timer_interval); + add_hs(dmi.system.system_reset.timeout); + add_hs(dmi.system.system_boot_status); + FLUSH_OBJECT; +} + +void dump_base_board(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + + if (hardware->dmi.base_board.filled == false) { + CREATE_NEW_OBJECT; + add_s("dmi.warning","no base_board structure found"); + FLUSH_OBJECT; + return; + } + + CREATE_NEW_OBJECT; + add_s("dmi.item","base_board"); + add_hs(dmi.base_board.manufacturer); + add_hs(dmi.base_board.product_name); + add_hs(dmi.base_board.version); + add_hs(dmi.base_board.serial); + add_hs(dmi.base_board.asset_tag); + add_hs(dmi.base_board.location); + add_hs(dmi.base_board.type); + for (int i = 0; i < BASE_BOARD_NB_ELEMENTS; i++) { + if (((bool *) (&hardware->dmi.base_board.features))[i] == true) { + add_s("dmi.base_board.features",(char *)base_board_features_strings[i]); + } + } + + for (unsigned int i = 0; i < sizeof hardware->dmi.base_board.devices_information / + sizeof *hardware->dmi.base_board.devices_information; i++) { + if (strlen(hardware->dmi.base_board.devices_information[i].type)) { + add_s("dmi.base_board.devices_information.type", hardware->dmi.base_board.devices_information[i].type); + add_i("dmi.base_board.devices_information.status", hardware->dmi.base_board.devices_information[i].status); + add_s("dmi.base_board.devices_information.description", hardware->dmi.base_board.devices_information[i].description); + } + } + FLUSH_OBJECT; +} + +void dump_dmi(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + + CREATE_NEW_OBJECT; + add_hb(is_dmi_valid); + + if (hardware->is_dmi_valid == false) { + FLUSH_OBJECT; + goto exit; + } else { + char buffer[8]={0}; + snprintf(buffer,sizeof(buffer),"%d.%d",hardware->dmi.dmitable.major_version, hardware->dmi.dmitable.minor_version); + add_s("dmi.version",buffer); + FLUSH_OBJECT; + } + + dump_base_board(hardware,config,item); + dump_system(hardware,config,item); + dump_bios(hardware,config,item); + dump_chassis(hardware,config,item); + dump_ipmi(hardware,config,item); + dump_battery(hardware,config,item); + dump_processor(hardware,config,item); + dump_cache(hardware,config,item); + dump_memory_banks(hardware,config,item); + dump_memory_modules(hardware,config,item); + dump_memory_size(hardware,config,item); + dump_oem_strings(hardware,config,item); + dump_hardware_security(hardware,config,item); +exit: + to_cpio("dmi"); +} diff --git a/com32/hdt/hdt-dump-hdt.c b/com32/hdt/hdt-dump-hdt.c new file mode 100644 index 00000000..d081ebdb --- /dev/null +++ b/com32/hdt/hdt-dump-hdt.c @@ -0,0 +1,50 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2011 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-common.h" +#include "hdt-dump.h" +#include <syslinux/config.h> + +void dump_hdt(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + + (void) hardware; + CREATE_NEW_OBJECT; + add_s("hdt.product_name",PRODUCT_NAME); + add_s("hdt.version",VERSION); + add_s("hdt.code_name",CODENAME); + add_s("hdt.author", AUTHOR); + add_s("hdt.core_developer", CORE_DEVELOPER); + char *contributors[NB_CONTRIBUTORS] = CONTRIBUTORS; + for (int c = 0; c < NB_CONTRIBUTORS; c++) { + add_s("hdt.contributor", contributors[c]); + } + add_s("hdt.website",WEBSITE_URL); + add_s("hdt.irc_channel",IRC_CHANNEL); + FLUSH_OBJECT + to_cpio("hdt"); +} diff --git a/com32/hdt/hdt-dump-kernel.c b/com32/hdt/hdt-dump-kernel.c new file mode 100644 index 00000000..e0df8320 --- /dev/null +++ b/com32/hdt/hdt-dump-kernel.c @@ -0,0 +1,69 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2011 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-common.h" +#include "hdt-dump.h" + +void dump_kernel(struct s_hardware *hardware, ZZJSON_CONFIG * config, + ZZJSON ** item) +{ + struct pci_device *pci_device = NULL; + CREATE_ARRAY + add_as("Linux Kernel modules", "") + END_OF_ARRAY; + + if (hardware->pci_ids_return_code == -ENOPCIIDS) { + APPEND_ARRAY + add_as("Error", "No pci.ids file") + END_OF_APPEND FLUSH_OBJECT; + return; + } + + if ((hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) + &&(hardware->modules_pcimap_return_code == -ENOMODULESALIAS)) { + APPEND_ARRAY + add_as("Error", "No modules.pcimap or modules.alias file") + END_OF_APPEND FLUSH_OBJECT; + return; + + } + + /* For every detected pci device, compute its submenu */ + for_each_pci_func(pci_device, hardware->pci_domain) { + if (pci_device == NULL) + continue; + for (int kmod = 0; + kmod < pci_device->dev_info->linux_kernel_module_count; kmod++) { + APPEND_ARRAY + add_as(pci_device->dev_info->category_name, pci_device->dev_info->linux_kernel_module[kmod]) + END_OF_APPEND; + } + } + FLUSH_OBJECT; + to_cpio("kernel"); +} diff --git a/com32/hdt/hdt-dump-memory.c b/com32/hdt/hdt-dump-memory.c new file mode 100644 index 00000000..5095d3c2 --- /dev/null +++ b/com32/hdt/hdt-dump-memory.c @@ -0,0 +1,133 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2011 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 <memory.h> +#include "hdt-common.h" +#include "hdt-dump.h" + +void dump_88(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + + (void) hardware; + int mem_size = 0; + CREATE_NEW_OBJECT; + if (detect_memory_88(&mem_size)) { + add_s("memory.error","8800h memory configuration is invalid"); + FLUSH_OBJECT + return; + } + + add_s("dmi.item","memory via 88"); + add_i("memory.size (KiB)", mem_size); + add_i("memory.size (MiB)", mem_size >> 10); + FLUSH_OBJECT; +} + +void dump_e801(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + + (void) hardware; + int mem_low, mem_high = 0; + CREATE_NEW_OBJECT; + if (detect_memory_e801(&mem_low,&mem_high)) { + add_s("memory.error","e801 memory configuration is invalid"); + FLUSH_OBJECT; + return; + } + + add_s("dmi.item","memory via e801"); + add_i("memory.total.size (KiB)", mem_low + (mem_high << 6)); + add_i("memory.total.size (MiB)", (mem_low >> 10) + (mem_high >> 4)); + add_i("memory.low.size (KiB)", mem_low ); + add_i("memory.low.size (MiB)", mem_low >> 10); + add_i("memory.high.size (KiB)", mem_high << 6); + add_i("memory.high.size (MiB)", mem_high >> 4); + FLUSH_OBJECT; + +} +void dump_e820(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + + (void) hardware; + struct e820entry map[E820MAX]; + struct e820entry nm[E820MAX]; + unsigned long memsize = 0; + int count = 0; + char type[14] = {0}; + + detect_memory_e820(map, E820MAX, &count); + memsize = memsize_e820(map, count); + + CREATE_NEW_OBJECT; + add_s("dmi.item","memory via e820"); + add_i("memory.total.size (KiB)", memsize); + add_i("memory.total.size (MiB)", (memsize + (1 << 9)) >> 10); + FLUSH_OBJECT; + + for (int i = 0; i < count; i++) { + get_type(map[i].type, type, sizeof(type)); + char begin[24]={0}; + char size[24]={0}; + char end[24]={0}; + snprintf(begin,sizeof(begin),"0x%016llx",map[i].addr); + snprintf(size,sizeof(size),"0x%016llx",map[i].size); + snprintf(end,sizeof(end),"0x%016llx",map[i].addr+map[i].size); + CREATE_NEW_OBJECT; + add_s("memory.segment.start",begin); + add_s("memory.segment.size ",size); + add_s("memory.segment.end ",end); + add_s("memory.segment.type ",remove_spaces(type)); + FLUSH_OBJECT; + } + + int nr = sanitize_e820_map(map, nm, count); + for (int i = 0; i < nr; i++) { + get_type(nm[i].type, type, sizeof(type)); + char begin[24]={0}; + char size[24]={0}; + char end[24]={0}; + snprintf(begin,sizeof(begin),"0x%016llx",nm[i].addr); + snprintf(size,sizeof(size),"0x%016llx",nm[i].size); + snprintf(end,sizeof(end),"0x%016llx",nm[i].addr+nm[i].size); + CREATE_NEW_OBJECT; + add_s("sanitized_memory.segment.start",begin); + add_s("sanitized_memory.segment.size ",size); + add_s("sanitized_memory.segment.end ",end); + add_s("sanitized_memory.segment.type ",remove_spaces(type)); + FLUSH_OBJECT; + } +} + +void dump_memory(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + + CREATE_NEW_OBJECT; + add_s("Memory configuration","true"); + FLUSH_OBJECT; + + dump_88(hardware,config,item); + dump_e801(hardware,config,item); + dump_e820(hardware,config,item); + to_cpio("memory"); +} diff --git a/com32/hdt/hdt-dump-pci.c b/com32/hdt/hdt-dump-pci.c new file mode 100644 index 00000000..b1f18fdf --- /dev/null +++ b/com32/hdt/hdt-dump-pci.c @@ -0,0 +1,136 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2011 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-common.h" +#include "hdt-dump.h" + +void dump_pci(struct s_hardware *hardware, ZZJSON_CONFIG * config, + ZZJSON ** item) +{ + int i = 1; + struct pci_device *pci_device=NULL; + char kernel_modules[LINUX_KERNEL_MODULE_SIZE * + MAX_KERNEL_MODULES_PER_PCI_DEVICE]; + bool nopciids = false; + bool nomodulespcimap = false; + bool nomodulesalias = false; + bool nomodulesfile = false; + int bus = 0, slot = 0, func = 0; + + if (hardware->pci_ids_return_code == -ENOPCIIDS) { + nopciids = true; + } + if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) { + nomodulespcimap = true; + } + if (hardware->modules_pcimap_return_code == -ENOMODULESALIAS) { + nomodulesalias = true; + } + + nomodulesfile = nomodulespcimap && nomodulesalias; + + CREATE_NEW_OBJECT; + + add_i("pci_device.count", hardware->nb_pci_devices); + + FLUSH_OBJECT; + /* For every detected pci device, compute its submenu */ + for_each_pci_func(pci_device, hardware->pci_domain) { + if (pci_device == NULL) + continue; + char v[10] = { 0 }; + char sv[10] = { 0 }; + char p[10] = { 0 }; + char sp[10] = { 0 }; + char c[10] = { 0 }; + char r[10] = { 0 }; + + CREATE_NEW_OBJECT; + bus = __pci_bus; + slot = __pci_slot; + func = __pci_func; + + 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); + + add_i("pci_device.number", i); + if (nopciids == false) { + add_s("pci_device.vendor_name", pci_device->dev_info->vendor_name); + add_s("pci_device.product_name", + pci_device->dev_info->product_name); + } + if (nomodulesfile == false) { + add_s("pci_device.class_name", pci_device->dev_info->class_name); + add_s("pci_device.kernel_module", kernel_modules); + } + + snprintf(v, sizeof(v), "%04x", pci_device->vendor); + snprintf(p, sizeof(p), "%04x", pci_device->product); + snprintf(sv, sizeof(sv), "%04x", pci_device->sub_vendor); + snprintf(sp, sizeof(sp), "%04x", pci_device->sub_product); + snprintf(c, sizeof(c), "%02x.%02x.%02x", + pci_device->class[2], + pci_device->class[1], pci_device->class[0]); + snprintf(r, sizeof(r), "%02x", pci_device->revision); + add_s("pci_device.vendor_id", v); + add_s("pci_device.product_id", p); + add_s("pci_device.sub_vendor_id", sv); + add_s("pci_device.sub_product_id", sp); + add_s("pci_device.class_id", c); + add_s("pci_device.revision", r); + if ((pci_device->dev_info->irq > 0) + && (pci_device->dev_info->irq < 255)) + add_i("pci_device.irq", pci_device->dev_info->irq); + + add_i("pci_device.latency", pci_device->dev_info->latency); + add_i("pci_device.bus", bus); + add_i("pci_device.slot", slot); + add_i("pci_device.func", func); + + if (hardware->is_pxe_valid == true) { + if ((hardware->pxe.pci_device != NULL) + && (hardware->pxe.pci_device == pci_device)) { + add_hs(pxe.mac_addr); + add_s("pxe", "Current boot device"); + } + } + i++; + FLUSH_OBJECT; + } + to_cpio("pci"); +} diff --git a/com32/hdt/hdt-dump-pxe.c b/com32/hdt/hdt-dump-pxe.c new file mode 100644 index 00000000..4e25c943 --- /dev/null +++ b/com32/hdt/hdt-dump-pxe.c @@ -0,0 +1,80 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2011 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-common.h" +#include "hdt-dump.h" +#include <sys/gpxe.h> +#include <netinet/in.h> + +void dump_pxe(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + struct in_addr in; + + CREATE_NEW_OBJECT; + add_hb(is_pxe_valid); + if (hardware->is_pxe_valid) { + char buffer[32] = {0}; + snprintf(buffer,sizeof(buffer),"0x%x",hardware->pxe.vendor_id); + add_s("pxe.vendor_id",buffer); + snprintf(buffer,sizeof(buffer),"0x%x",hardware->pxe.product_id); + add_s("pxe.product_id",buffer); + snprintf(buffer,sizeof(buffer),"0x%x",hardware->pxe.subvendor_id); + add_s("pxe.subvendor_id",buffer); + snprintf(buffer,sizeof(buffer),"0x%x",hardware->pxe.subproduct_id); + add_s("pxe.subproduct_id",buffer); + + if (hardware->pci_ids_return_code == -ENOPCIIDS || (hardware->pxe.pci_device == NULL)) { + add_s("Manufacturer_name","no_pci_ids_file or no device found"); + add_s("Product_name","no_pci_ids_file or no device found"); + } else { + add_s("Manufacturer_name", hardware->pxe.pci_device->dev_info->vendor_name); + add_s("Product_name", hardware->pxe.pci_device->dev_info->product_name); + } + + add_hi(pxe.rev); + add_hi(pxe.pci_bus); + add_hi(pxe.pci_dev); + add_hi(pxe.pci_func); + add_hi(pxe.base_class); + add_hi(pxe.sub_class); + add_hi(pxe.prog_intf); + add_hi(pxe.nictype); + add_hs(pxe.mac_addr); + + in.s_addr = hardware->pxe.dhcpdata.cip; + add_s("pxe.client_ip", inet_ntoa(in)); + in.s_addr = hardware->pxe.dhcpdata.sip; + add_s("pxe.next_server_ip",inet_ntoa(in)); + in.s_addr = hardware->pxe.dhcpdata.gip; + add_s("pxe.relay_agent_ip",inet_ntoa(in)); + memcpy(&in, hardware->pxe.ip_addr, sizeof in); + add_s("pxe.ipaddr",inet_ntoa(in)); + add_b("gpxe_detected",is_gpxe()); + } + FLUSH_OBJECT; + to_cpio("pxe"); +} diff --git a/com32/hdt/hdt-dump-syslinux.c b/com32/hdt/hdt-dump-syslinux.c new file mode 100644 index 00000000..7cef925f --- /dev/null +++ b/com32/hdt/hdt-dump-syslinux.c @@ -0,0 +1,43 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2011 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-common.h" +#include "hdt-dump.h" +#include <syslinux/config.h> + +void dump_syslinux(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + + CREATE_NEW_OBJECT; + add_hs(syslinux_fs); + add_hs(sv->version_string); + add_hi(sv->version); + add_hi(sv->max_api); + add_hs(sv->copyright_string); + FLUSH_OBJECT + to_cpio("syslinux"); +} diff --git a/com32/hdt/hdt-dump-vesa.c b/com32/hdt/hdt-dump-vesa.c new file mode 100644 index 00000000..97d56c95 --- /dev/null +++ b/com32/hdt/hdt-dump-vesa.c @@ -0,0 +1,67 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2011 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-common.h" +#include "hdt-dump.h" +#include <syslinux/config.h> + +void dump_vesa(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + + CREATE_NEW_OBJECT; + add_hb(is_vesa_valid); + if (hardware->is_vesa_valid) { + char buffer[64]={0}; + snprintf(buffer,sizeof(buffer),"%d.%d", hardware->vesa.major_version, hardware->vesa.minor_version); + add_s("vesa.version",buffer); + add_hs(vesa.vendor); + add_hs(vesa.product); + add_hs(vesa.product_revision); + add_hi(vesa.software_rev); + memset(buffer,0,sizeof(buffer)); + snprintf(buffer,sizeof(buffer),"%d KB",hardware->vesa.total_memory*64); + add_s("vesa.memory",buffer); + add_i("vesa.modes",hardware->vesa.vmi_count); + FLUSH_OBJECT; + for (int i = 0; i < hardware->vesa.vmi_count; i++) { + struct vesa_mode_info *mi = &hardware->vesa.vmi[i].mi; + if ((mi->h_res == 0) || (mi->v_res == 0)) + continue; + CREATE_NEW_OBJECT; + memset(buffer,0,sizeof(buffer)); + snprintf(buffer,sizeof(buffer),"0x%04x",hardware->vesa.vmi[i].mode + 0x200); + add_s("vesa.kernel_mode",buffer); + add_i("vesa.hres",mi->h_res); + add_i("vesa.vres",mi->v_res); + add_i("vesa.bpp",mi->bpp); + FLUSH_OBJECT; + } + } else { + FLUSH_OBJECT; + } + to_cpio("vesa"); +} diff --git a/com32/hdt/hdt-dump-vpd.c b/com32/hdt/hdt-dump-vpd.c new file mode 100644 index 00000000..36451c8a --- /dev/null +++ b/com32/hdt/hdt-dump-vpd.c @@ -0,0 +1,47 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2011 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-common.h" +#include "hdt-dump.h" + +void dump_vpd(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) { + + CREATE_NEW_OBJECT; + add_hb(is_vpd_valid); + if (hardware->is_vpd_valid) { + add_hs(vpd.bios_build_id); + add_hs(vpd.bios_release_date); + add_hs(vpd.bios_version); + add_hs(vpd.default_flash_filename); + add_hs(vpd.box_serial_number); + add_hs(vpd.motherboard_serial_number); + add_hs(vpd.machine_type_model); + } + FLUSH_OBJECT; + to_cpio("vpd"); +} diff --git a/com32/hdt/hdt-dump.c b/com32/hdt/hdt-dump.c new file mode 100644 index 00000000..b1748c8e --- /dev/null +++ b/com32/hdt/hdt-dump.c @@ -0,0 +1,229 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2011 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 <stdlib.h> +#include <ctype.h> +#include <getkey.h> +#include <syslinux/config.h> +#include "hdt-common.h" +#include "hdt-dump.h" + +struct print_buf p_buf; + +struct dump_option { + char *flag; + char *item; +}; + +char *get_value_from_option(struct s_hardware *hardware, char *option) +{ + struct dump_option dump_options[10]; + dump_options[0].flag = "%{m}"; + dump_options[0].item = hardware->pxe.mac_addr; + + dump_options[1].flag = "%{v}"; + dump_options[1].item = hardware->dmi.system.manufacturer; + + dump_options[2].flag = "%{p}"; + dump_options[2].item = hardware->dmi.system.product_name; + + dump_options[3].flag = "%{ba}"; + dump_options[3].item = hardware->dmi.base_board.asset_tag; + + dump_options[4].flag = "%{bs}"; + dump_options[4].item = hardware->dmi.base_board.serial; + + dump_options[5].flag = "%{ca}"; + dump_options[5].item = hardware->dmi.chassis.asset_tag; + + dump_options[6].flag = "%{cs}"; + dump_options[6].item = hardware->dmi.chassis.serial; + + dump_options[7].flag = "%{sk}"; + dump_options[7].item = hardware->dmi.system.sku_number; + + dump_options[8].flag = "%{ss}"; + dump_options[8].item = hardware->dmi.system.serial; + + dump_options[9].flag = NULL; + dump_options[9].item = NULL; + + for (int i = 0; i < 9; i++) { + if (strcmp(option, dump_options[i].flag) == 0) { + return remove_spaces(dump_options[i].item); + } + } + + return NULL; +} + +char *compute_filename(struct s_hardware *hardware) +{ + + char *filename = malloc(512); + snprintf(filename, 512, "%s/%s", hardware->dump_path, + hardware->dump_filename); + + /* Until we found some dump parameters */ + char *buffer; + while ((buffer = strstr(filename, "%{"))) { + // Find the end of the parameter + char *buffer_end = strstr(buffer, "}"); + + // Extracting the parameter between %{ and } + char option[8] = { 0 }; + strncpy(option, buffer, buffer_end - buffer + 1); + + /* Replace this option by its value in the filename + * Filename is longer than the previous filename we had + * so let's restart from the beginning */ + filename = + strreplace(filename, option, + get_value_from_option(hardware, option)); + } + + /* We replace the ":" in the filename by some "-" + * This will avoid Microsoft FS turning crazy */ + chrreplace(filename, ':', '-'); + + /* Avoid space to make filename easier to manipulate */ + chrreplace(filename, ' ', '_'); + + return filename; +} + +int dumpprintf(FILE * p, const char *format, ...) +{ + va_list ap; + int rv; + + (void)p; + va_start(ap, format); + rv = vbufprintf(&p_buf, format, ap); + va_end(ap); + return rv; +} + +void to_cpio(char *filename) +{ + cpio_writefile(upload, filename, p_buf.buf, p_buf.len); + if ((p_buf.buf) && (p_buf.len > 0)) { + memset(p_buf.buf, 0, p_buf.len); + free(p_buf.buf); + p_buf.buf = NULL; + p_buf.size = 0; + p_buf.len = 0; + } +} + +void flush(ZZJSON_CONFIG * config, ZZJSON ** item) +{ + zzjson_print(config, *item); + zzjson_free(config, *item); + *item = NULL; +} + +/** + * dump - dump info + **/ +void dump(struct s_hardware *hardware) +{ + if (hardware->is_pxe_valid == false) { + more_printf("PXE stack was not detected, Dump feature is not available\n"); + return; + } + + const union syslinux_derivative_info *sdi = syslinux_derivative_info(); + int err = 0; + ZZJSON *json = NULL; + ZZJSON_CONFIG config = { ZZJSON_VERY_STRICT, NULL, + (int (*)(void *))fgetc, + NULL, + malloc, calloc, free, realloc, + stderr, NULL, stdout, + (int (*)(void *, const char *,...))dumpprintf, + (int (*)(int, void *))fputc + }; + + memset(&p_buf, 0, sizeof(p_buf)); + + /* By now, we only support TFTP reporting */ + upload = &upload_tftp; + upload->name = "tftp"; + + /* The following defines the behavior of the reporting */ + char *arg[64]; + char *filename = compute_filename(hardware); + + /* The filename */ + arg[0] = filename; + /* The server to upload the file */ + if (strlen(hardware->tftp_ip) != 0) { + arg[1] = hardware->tftp_ip; + arg[2] = NULL; + } else { + arg[1] = NULL; + snprintf(hardware->tftp_ip, sizeof(hardware->tftp_ip), + "%u.%u.%u.%u", + ((uint8_t *) & sdi->pxe.ipinfo->serverip)[0], + ((uint8_t *) & sdi->pxe.ipinfo->serverip)[1], + ((uint8_t *) & sdi->pxe.ipinfo->serverip)[2], + ((uint8_t *) & sdi->pxe.ipinfo->serverip)[3]); + + } + + /* We initiate the cpio to send */ + cpio_init(upload, (const char **)arg); + + dump_cpu(hardware, &config, &json); + dump_pxe(hardware, &config, &json); + dump_syslinux(hardware, &config, &json); + dump_vpd(hardware, &config, &json); + dump_vesa(hardware, &config, &json); + dump_disks(hardware, &config, &json); + dump_dmi(hardware, &config, &json); + dump_memory(hardware, &config, &json); + dump_pci(hardware, &config, &json); + dump_acpi(hardware, &config, &json); + dump_kernel(hardware, &config, &json); + dump_hdt(hardware, &config, &json); + + /* We close & flush the file to send */ + cpio_close(upload); + + if ((err = flush_data(upload)) != TFTP_OK) { + /* As we manage a tftp connection, let's display the associated error message */ + more_printf("Dump failed !\n"); + more_printf("TFTP ERROR on : %s:/%s \n", hardware->tftp_ip, filename); + more_printf("TFTP ERROR msg : %s \n", tftp_string_error_message[-err]); + } else { + more_printf("Dump file sent at %s:/%s\n", hardware->tftp_ip, filename); + } +} diff --git a/com32/hdt/hdt-dump.h b/com32/hdt/hdt-dump.h new file mode 100644 index 00000000..f9669dac --- /dev/null +++ b/com32/hdt/hdt-dump.h @@ -0,0 +1,85 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 20011 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 <stdlib.h> +#include <ctype.h> +#include <bufprintf.h> +#include <zzjson/zzjson.h> +#include "hdt-common.h" + +// Macros to manipulate Arrays +#define APPEND_ARRAY ZZJSON *temp_array; temp_array = zzjson_array_append(config, *item, zzjson_create_object(config, +#define APPEND_OBJECT_ARRAY(value) ZZJSON *temp_ar; temp_ar = zzjson_array_append(config, *item, value); *item=temp_ar; +#define CREATE_ARRAY *item = zzjson_create_array(config, zzjson_create_object(config, +#define add_ai(name,value) name,zzjson_create_number_i(config,value), +#define add_ahi(value) add_ai(#value,hardware->value) +#define add_as(name,value) name,zzjson_create_string(config,value), +#define add_ahs(value) add_as(#value,hardware->value) +#define END_OF_ARRAY NULL),NULL) +#define END_OF_APPEND NULL)); *item=temp_array; + +// Macros to manipulate objects +#define CREATE_NEW_OBJECT *item = zzjson_create_object(config, NULL); +#define FLUSH_OBJECT flush(config, item); + +// Macros to manipulate integers as objects +#define add_i(name,value) *item = zzjson_object_append(config, *item, name, zzjson_create_number_i(config, value)) +#define add_hi(value) add_i(#value,hardware->value) + +// Macros to manipulate strings as objects +#define add_s(name,value) *item = zzjson_object_append(config, *item, name, zzjson_create_string(config, value)) +#define add_hs(value) add_s(#value,(char *)hardware->value) + +// Macros to manipulate bool as objects +#define add_bool_true(name) *item = zzjson_object_append(config, *item, (char *)name, zzjson_create_true(config)) +#define add_bool_false(name) *item = zzjson_object_append(config, *item, (char*)name, zzjson_create_false(config)) +#define add_b(name,value) if (value==true) {add_bool_true(name);} else {add_bool_false(name);} +#define add_hb(value) add_b(#value,hardware->value) + +extern struct print_buf p_buf; + +void print_and_flush(ZZJSON_CONFIG *config, ZZJSON **item); +int dumpprintf(FILE *p, const char *format, ...); +void flush (ZZJSON_CONFIG *config, ZZJSON ** item); +void to_cpio(char *filename); + +void dump_cpu(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item); +void dump_pxe(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item); +void dump_syslinux(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item); +void dump_vpd(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item); +void dump_vesa(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item); +void dump_disks(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item); +void dump_dmi(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item); +void dump_memory(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item); +void dump_pci(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item); +void dump_acpi(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item); +void dump_kernel(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item); +void dump_hdt(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item); +void dump(struct s_hardware *hardware); diff --git a/com32/hdt/hdt-menu-acpi.c b/com32/hdt/hdt-menu-acpi.c index 16bcf73a..8e0ba18f 100644 --- a/com32/hdt/hdt-menu-acpi.c +++ b/com32/hdt/hdt-menu-acpi.c @@ -32,7 +32,7 @@ void compute_table(struct s_my_menu *menu, void *address, s_acpi_description_hea char buffer[SUBMENULEN + 1] = { 0 }; char statbuffer[STATLEN + 1] = { 0 }; - snprintf(buffer, sizeof buffer, "%-4s v%03x %-6s %-7s %-7s %08x", + snprintf(buffer, sizeof buffer, "%-4s v%03x %-6s %-8s %-7s %08x", h->signature, h->revision, h->oem_id, h->oem_table_id, h->creator_id, h->creator_revision); snprintf(statbuffer, sizeof statbuffer, "%-4s v%03x %-6s %-7s 0x%08x %-4s 0x%08x @ 0x%p", h->signature, h->revision, h->oem_id, h->oem_table_id, @@ -52,7 +52,7 @@ static void compute_acpi_tables(struct s_my_menu *menu, char buffer[SUBMENULEN + 1] = { 0 }; - snprintf(buffer, sizeof buffer, "%-4s %-4s %-6s %-7s %-7s %-8s", + snprintf(buffer, sizeof buffer, "%-4s %-4s %-6s %-8s %-7s %-8s", "ACPI", "rev", "oem", "table_id", "creator", "creator_rev"); add_item(buffer, "Description", OPT_INACTIVE, NULL, 0); menu->items_count++; diff --git a/com32/hdt/hdt-menu-disk.c b/com32/hdt/hdt-menu-disk.c index b0b4a5ac..0716b435 100644 --- a/com32/hdt/hdt-menu-disk.c +++ b/com32/hdt/hdt-menu-disk.c @@ -120,9 +120,9 @@ static void compute_partition_information(struct driveinfo *drive_info, add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0); } - snprintf(buffer, sizeof buffer, "Bootable : %s", + snprintf(buffer, sizeof buffer, "Boot Flag : %s", (ptab->active_flag == 0x80) ? "Yes" : "No"); - snprintf(statbuffer, sizeof statbuffer, "Bootable: %s", + snprintf(statbuffer, sizeof statbuffer, "Boot Flag: %s", (ptab->active_flag == 0x80) ? "Yes" : "No"); add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0); @@ -243,12 +243,12 @@ void compute_disks(struct s_hdt_menu *menu, struct s_hardware *hardware) if (hardware->disks_count == 0) return; - for (int i = 0; i < hardware->disks_count; i++) { - if (!hardware->disk_info[i].cbios) + for (int drive = 0x80; drive < 0xff; drive++) { + if (!hardware->disk_info[drive - 0x80].cbios) continue; /* Invalid geometry */ compute_disk_module ((struct s_my_menu *)&(menu->disk_sub_menu), nb_sub_disk_menu, - hardware, i); + hardware, drive - 0x80); nb_sub_disk_menu++; } diff --git a/com32/hdt/hdt-menu-pxe.c b/com32/hdt/hdt-menu-pxe.c index 426bfe07..12d8b116 100644 --- a/com32/hdt/hdt-menu-pxe.c +++ b/com32/hdt/hdt-menu-pxe.c @@ -34,7 +34,7 @@ void compute_PXE(struct s_my_menu *menu, struct s_hardware *hardware) { char buffer[SUBMENULEN + 1]; char infobar[STATLEN + 1]; - char gpxe[4]; + char gpxe[4]={0}; if (hardware->is_pxe_valid == false) return; @@ -113,8 +113,8 @@ void compute_PXE(struct s_my_menu *menu, struct s_hardware *hardware) add_item(buffer, infobar, OPT_INACTIVE, NULL, 0); menu->items_count++; - if (is_gpxe()) strcat(gpxe,"Yes"); - else strcat (gpxe,"No"); + if (is_gpxe()) snprintf(gpxe,sizeof(gpxe),"%s","Yes"); + else snprintf (gpxe, sizeof(gpxe), "%s", "No"); snprintf(buffer, sizeof buffer, "gPXE Detected: %s", gpxe); snprintf(infobar, sizeof infobar, "gPXE Detected: %s", gpxe); diff --git a/com32/hdt/hdt-menu-summary.c b/com32/hdt/hdt-menu-summary.c index ad87c299..cef7e69e 100644 --- a/com32/hdt/hdt-menu-summary.c +++ b/com32/hdt/hdt-menu-summary.c @@ -52,8 +52,7 @@ void compute_summarymenu(struct s_my_menu *menu, struct s_hardware *hardware) add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0); menu->items_count++; - char features[SUBMENULEN + 1]; - memset(features, 0, sizeof(features)); + char features[255]={0}; if (hardware->dmi.processor.thread_count != 0) sprintf(buffer, ", %d thread", hardware->dmi.processor.thread_count); else diff --git a/com32/hdt/hdt-menu.c b/com32/hdt/hdt-menu.c index 0fdee039..50b3eaa8 100644 --- a/com32/hdt/hdt-menu.c +++ b/com32/hdt/hdt-menu.c @@ -62,6 +62,12 @@ int start_menu_mode(struct s_hardware *hardware, char *version_string) (curr->data, HDT_SWITCH_TO_CLI, sizeof(HDT_SWITCH_TO_CLI))) { return HDT_RETURN_TO_CLI; } + /* Tweak, we want to start the dump mode */ + if (!strncmp + (curr->data, HDT_DUMP, sizeof(HDT_DUMP))) { + dump(hardware); + return 0; + } if (!strncmp (curr->data, HDT_REBOOT, sizeof(HDT_REBOOT))) { syslinux_reboot(1); @@ -289,6 +295,12 @@ void compute_main_menu(struct s_hdt_menu *hdt_menu, struct s_hardware *hardware) add_item("S<w>itch to CLI", "Switch to Command Line", OPT_RUN, HDT_SWITCH_TO_CLI, 0); + + if (hardware->is_pxe_valid == true) { + add_item("<D>ump to tftp", "Dump to tftp", OPT_RUN, + HDT_DUMP, 0); + } + add_item("<A>bout", "About Menu", OPT_SUBMENU, NULL, hdt_menu->about_menu.menu); add_item("<R>eboot", "Reboot", OPT_RUN, HDT_REBOOT, 0); diff --git a/com32/hdt/hdt.c b/com32/hdt/hdt.c index a1e3923c..653995d0 100644 --- a/com32/hdt/hdt.c +++ b/com32/hdt/hdt.c @@ -72,16 +72,23 @@ int main(const int argc, const char *argv[]) clear_screen(); printf("\033[1;1H"); - printf("%s\n", version_string); + more_printf("%s\n", version_string); + + int return_code = 0; if (!menumode || automode) start_cli_mode(&hardware); else { - int return_code = start_menu_mode(&hardware, version_string); + return_code = start_menu_mode(&hardware, version_string); if (return_code == HDT_RETURN_TO_CLI) start_cli_mode(&hardware); - else - return return_code; } - return 0; + + /* Do we got request to do something at exit time ? */ + if (strlen(hardware.postexec)>0) { + more_printf("Executing postexec instructions : %s\n",hardware.postexec); + runsyslinuxcmd(hardware.postexec); + } + + return return_code; } diff --git a/com32/hdt/hdt.h b/com32/hdt/hdt.h index dd489480..e385417a 100644 --- a/com32/hdt/hdt.h +++ b/com32/hdt/hdt.h @@ -33,8 +33,8 @@ #define AUTHOR "Erwan Velu" #define CORE_DEVELOPER "Pierre-Alexandre Meyer" #define CONTACT "hdt@zytor.com" -#define VERSION "0.4.1" -#define CODENAME "chouffe" +#define VERSION "0.5.2" +#define CODENAME "Manon" #define NB_CONTRIBUTORS 3 #define CONTRIBUTORS {"Sebastien Gonzalve (Patches)", "Gert Hulselmans (Tests)", "Alexander Andino (Design)"} #define WEBSITE_URL "http://hdt-project.org" |